Try (as best as possible with no test file) to extract uncompressed HMEF test when that is there instead of Compressed RTF
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751361 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
eb6488585a
commit
4a438b1bbd
@ -26,8 +26,11 @@ import java.io.OutputStream;
|
|||||||
|
|
||||||
import org.apache.poi.hmef.Attachment;
|
import org.apache.poi.hmef.Attachment;
|
||||||
import org.apache.poi.hmef.HMEFMessage;
|
import org.apache.poi.hmef.HMEFMessage;
|
||||||
|
import org.apache.poi.hmef.attribute.MAPIAttribute;
|
||||||
import org.apache.poi.hmef.attribute.MAPIRtfAttribute;
|
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.MAPIProperty;
|
||||||
|
import org.apache.poi.hsmf.datatypes.Types;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A utility for extracting out the message body, and all attachments
|
* A utility for extracting out the message body, and all attachments
|
||||||
@ -77,16 +80,43 @@ public final class HMEFContentsExtractor {
|
|||||||
* Extracts the RTF message body to the supplied file
|
* Extracts the RTF message body to the supplied file
|
||||||
*/
|
*/
|
||||||
public void extractMessageBody(File dest) throws IOException {
|
public void extractMessageBody(File dest) throws IOException {
|
||||||
|
MAPIAttribute body = getBodyAttribute();
|
||||||
|
if (body == null) {
|
||||||
|
System.err.println("No message body found, " + dest + " not created");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (body instanceof MAPIStringAttribute) {
|
||||||
|
String name = dest.toString();
|
||||||
|
if (name.endsWith(".rtf")) {
|
||||||
|
name = name.substring(0, name.length()-4);
|
||||||
|
}
|
||||||
|
dest = new File(name + ".txt");
|
||||||
|
}
|
||||||
|
|
||||||
OutputStream fout = new FileOutputStream(dest);
|
OutputStream fout = new FileOutputStream(dest);
|
||||||
try {
|
try {
|
||||||
extractMessageBody(fout);
|
fout.write(body.getData());
|
||||||
} finally {
|
} finally {
|
||||||
fout.close();
|
fout.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected MAPIAttribute getBodyAttribute() {
|
||||||
|
MAPIAttribute body = message.getMessageMAPIAttribute(MAPIProperty.RTF_COMPRESSED);
|
||||||
|
if (body != null) return body;
|
||||||
|
|
||||||
|
// See bug #59786 - we'd really like a test file to confirm if this
|
||||||
|
// is the right properties + if this is truely general or not!
|
||||||
|
MAPIProperty uncompressedBody =
|
||||||
|
MAPIProperty.createCustom(0x3fd9, Types.ASCII_STRING, "Uncompressed Body");
|
||||||
|
// Return this uncompressed one, or null if that isn't their either
|
||||||
|
return message.getMessageMAPIAttribute(uncompressedBody);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts the RTF message body to the supplied stream
|
* Extracts the RTF message body to the supplied stream. If there is no
|
||||||
|
* RTF message body, nothing will be written to the stream, but no
|
||||||
|
* errors or exceptions will be raised.
|
||||||
*/
|
*/
|
||||||
public void extractMessageBody(OutputStream out) throws IOException {
|
public void extractMessageBody(OutputStream out) throws IOException {
|
||||||
MAPIRtfAttribute body = (MAPIRtfAttribute)
|
MAPIRtfAttribute body = (MAPIRtfAttribute)
|
||||||
|
@ -40,7 +40,7 @@ import org.apache.poi.hsmf.datatypes.Types.MAPIType;
|
|||||||
* by friendly name, ID and MAPI Property Name.
|
* by friendly name, ID and MAPI Property Name.
|
||||||
*
|
*
|
||||||
* These are taken from the following MSDN resources:
|
* These are taken from the following MSDN resources:
|
||||||
* http://msdn.microsoft.com/en-us/library/microsoft.exchange.data.contenttypes.tnef.tnefpropertyid%28v=EXCHG.140%29.aspx
|
* https://msdn.microsoft.com/en-us/library/microsoft.exchange.data.contenttypes.tnef.tnefpropertyid(v=exchg.150).aspx
|
||||||
* http://msdn.microsoft.com/en-us/library/ms526356%28v=exchg.10%29.aspx
|
* http://msdn.microsoft.com/en-us/library/ms526356%28v=exchg.10%29.aspx
|
||||||
*/
|
*/
|
||||||
public class MAPIProperty {
|
public class MAPIProperty {
|
||||||
|
Loading…
Reference in New Issue
Block a user