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
This commit is contained in:
Nick Burch 2016-07-04 22:47:17 +00:00
parent 28c437531e
commit e4d673ddc3
1 changed files with 9 additions and 1 deletions

View 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();
}