From e4d673ddc39337abe47f0dbdd12c829d5a474540 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Mon, 4 Jul 2016 22:47:17 +0000 Subject: [PATCH] When dumping a HMEF body that is a string not RTF, use a predictable encoding rather than whatever the property happened to have in the original file git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751386 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hmef/extractor/HMEFContentsExtractor.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/scratchpad/src/org/apache/poi/hmef/extractor/HMEFContentsExtractor.java b/src/scratchpad/src/org/apache/poi/hmef/extractor/HMEFContentsExtractor.java index e649fd154..e945cbae4 100644 --- a/src/scratchpad/src/org/apache/poi/hmef/extractor/HMEFContentsExtractor.java +++ b/src/scratchpad/src/org/apache/poi/hmef/extractor/HMEFContentsExtractor.java @@ -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(); }