aboutsummaryrefslogtreecommitdiffstats
path: root/src/integrationtest/org/apache/poi
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2020-01-08 23:49:31 +0000
committerAndreas Beeker <kiwiwings@apache.org>2020-01-08 23:49:31 +0000
commit11b2c7e8985294679eb315da9d78cf17c87bcca3 (patch)
tree504c073d9cd8ae92a350f3aa9e29ea0d81e0aeed /src/integrationtest/org/apache/poi
parentf7fe4b0d59b8030f16400ea064e7826da835e078 (diff)
downloadpoi-11b2c7e8985294679eb315da9d78cf17c87bcca3.tar.gz
poi-11b2c7e8985294679eb315da9d78cf17c87bcca3.zip
#63955 - HMEFContentsExtractor fails to extract content from winmail.dat
fixed integration test git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872523 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/integrationtest/org/apache/poi')
-rw-r--r--src/integrationtest/org/apache/poi/stress/HMEFFileHandler.java56
1 files changed, 48 insertions, 8 deletions
diff --git a/src/integrationtest/org/apache/poi/stress/HMEFFileHandler.java b/src/integrationtest/org/apache/poi/stress/HMEFFileHandler.java
index c61a001376..908600979f 100644
--- a/src/integrationtest/org/apache/poi/stress/HMEFFileHandler.java
+++ b/src/integrationtest/org/apache/poi/stress/HMEFFileHandler.java
@@ -18,35 +18,57 @@ package org.apache.poi.stress;
import static org.junit.Assert.assertNotNull;
+import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
+import java.util.Arrays;
import org.apache.poi.hmef.HMEFMessage;
import org.apache.poi.hmef.attribute.MAPIAttribute;
import org.apache.poi.hmef.attribute.MAPIStringAttribute;
+import org.apache.poi.hmef.attribute.TNEFAttribute;
+import org.apache.poi.hmef.attribute.TNEFProperty;
+import org.apache.poi.hsmf.datatypes.MAPIProperty;
+import org.apache.poi.poifs.filesystem.FileMagic;
+import org.apache.poi.util.LittleEndian;
import org.junit.Test;
public class HMEFFileHandler extends AbstractFileHandler {
@Override
+ public void handleExtracting(File file) throws Exception {
+ FileMagic fm = FileMagic.valueOf(file);
+ if (fm == FileMagic.OLE2) {
+ super.handleExtracting(file);
+ }
+ }
+
+ @Override
public void handleFile(InputStream stream, String path) throws Exception {
HMEFMessage msg = new HMEFMessage(stream);
-
+
// list all properties
StringBuilder props = new StringBuilder();
for(MAPIAttribute att : msg.getMessageMAPIAttributes()) {
props.append(att.getType()).append(": ").append(MAPIStringAttribute.getAsString( att)).append("\n");
}
-
+
// there are two test-files that have no body...
- if(!msg.getSubject().equals("Testing TNEF Message") && !msg.getSubject().equals("TNEF test message with attachments")) {
- assertNotNull("Had: " + msg.getBody() + ", " + msg.getSubject() + ", " + msg.getAttachments() + ": " + props,
- msg.getBody());
+ String[] HTML_BODY = {
+ "Testing TNEF Message", "TNEF test message with attachments", "Test"
+ };
+ String bodyStr;
+ if(Arrays.asList(HTML_BODY).contains(msg.getSubject())) {
+ MAPIAttribute bodyHtml = msg.getMessageMAPIAttribute(MAPIProperty.BODY_HTML);
+ assertNotNull(bodyHtml);
+ bodyStr = new String(bodyHtml.getData(), getEncoding(msg));
+ } else {
+ bodyStr = msg.getBody();
}
- assertNotNull("Had: " + msg.getBody() + ", " + msg.getSubject() + ", " + msg.getAttachments() + ": " + props,
- msg.getSubject());
+ assertNotNull("Body is not set", bodyStr);
+ assertNotNull("Subject is not set", msg.getSubject());
}
-
+
// a test-case to test this locally without executing the full TestAllFiles
@Test
public void test() throws Exception {
@@ -55,4 +77,22 @@ public class HMEFFileHandler extends AbstractFileHandler {
handleFile(stream, path);
}
}
+
+ private String getEncoding(HMEFMessage tnefDat) {
+ TNEFAttribute oemCP = tnefDat.getMessageAttribute(TNEFProperty.ID_OEMCODEPAGE);
+ MAPIAttribute cpId = tnefDat.getMessageMAPIAttribute(MAPIProperty.INTERNET_CPID);
+ int codePage = 1252;
+ if (oemCP != null) {
+ codePage = LittleEndian.getInt(oemCP.getData());
+ } else if (cpId != null) {
+ codePage = LittleEndian.getInt(cpId.getData());
+ }
+ switch (codePage) {
+ // see http://en.wikipedia.org/wiki/Code_page for more
+ case 1252: return "Windows-1252";
+ case 20127: return "US-ASCII";
+ default: return "cp"+codePage;
+ }
+ }
+
}