]> source.dussan.org Git - poi.git/commitdiff
When dumping a HMEF body that is a string not RTF, use a predictable encoding rather...
authorNick Burch <nick@apache.org>
Mon, 4 Jul 2016 22:47:17 +0000 (22:47 +0000)
committerNick Burch <nick@apache.org>
Mon, 4 Jul 2016 22:47:17 +0000 (22:47 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751386 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hmef/extractor/HMEFContentsExtractor.java

index e649fd154edd55b28da037844a7988e5127fac0a..e945cbae4b003000c3072f334f9773184f68c31c 100644 (file)
@@ -31,6 +31,7 @@ import org.apache.poi.hmef.attribute.MAPIRtfAttribute;
 import org.apache.poi.hmef.attribute.MAPIStringAttribute;
 import org.apache.poi.hsmf.datatypes.MAPIProperty;
 import org.apache.poi.hsmf.datatypes.Types;
+import org.apache.poi.util.StringUtil;
 
 /**
  * A utility for extracting out the message body, and all attachments
@@ -95,7 +96,14 @@ public final class HMEFContentsExtractor {
         
         OutputStream fout = new FileOutputStream(dest);
         try {
-            fout.write(body.getData());
+            if (body instanceof MAPIStringAttribute) {
+                // Save in a predictable encoding, not raw bytes
+                String text = ((MAPIStringAttribute)body).getDataString();
+                fout.write(text.getBytes(StringUtil.UTF8));
+            } else {
+                // Save the raw bytes, should be raw RTF
+                fout.write(body.getData());
+            }
         } finally {
             fout.close();
         }