You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2011/04/01 18:01:29 UTC
svn commit: r1087782 - in /poi/trunk/src: documentation/content/xdocs/
scratchpad/src/org/apache/poi/hsmf/
scratchpad/src/org/apache/poi/hsmf/datatypes/
scratchpad/testcases/org/apache/poi/hsmf/
Author: nick
Date: Fri Apr 1 16:01:29 2011
New Revision: 1087782
URL: http://svn.apache.org/viewvc?rev=1087782&view=rev
Log:
Improve HSMF MAPIMessage access to the HTML and RTF versions of the message body (where available)
Modified:
poi/trunk/src/documentation/content/xdocs/status.xml
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java
Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1087782&r1=1087781&r2=1087782&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Fri Apr 1 16:01:29 2011
@@ -34,6 +34,7 @@
<changes>
<release version="3.8-beta3" date="2011-??-??">
+ <action dev="poi-developers" type="add">Improve HSMF MAPIMessage access to the HTML and RTF versions of the message body (where available)</action>
<action dev="poi-developers" type="add">Add new method to HSMF of MAPIMessage.has7BitEncodingStrings() to make it easier to decide when encoding guessing is needed</action>
<action dev="poi-developers" type="fix">OutlookTextExtractor now requests 7 bit encoding guessing</action>
<action dev="poi-developers" type="add">Improve HSMF encoding guessing for 7 bit fields in MAPIMessage</action>
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java?rev=1087782&r1=1087781&r2=1087782&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java Fri Apr 1 16:01:29 2011
@@ -29,11 +29,14 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.poi.POIDocument;
+import org.apache.poi.hmef.attribute.MAPIRtfAttribute;
import org.apache.poi.hsmf.datatypes.AttachmentChunks;
import org.apache.poi.hsmf.datatypes.AttachmentChunks.AttachmentChunksSorter;
+import org.apache.poi.hsmf.datatypes.ByteChunk;
import org.apache.poi.hsmf.datatypes.Chunk;
import org.apache.poi.hsmf.datatypes.ChunkGroup;
import org.apache.poi.hsmf.datatypes.Chunks;
+import org.apache.poi.hsmf.datatypes.MAPIProperty;
import org.apache.poi.hsmf.datatypes.NameIdChunks;
import org.apache.poi.hsmf.datatypes.RecipientChunks;
import org.apache.poi.hsmf.datatypes.Types;
@@ -184,7 +187,36 @@ public class MAPIMessage extends POIDocu
* @throws ChunkNotFoundException
*/
public String getHmtlBody() throws ChunkNotFoundException {
- return getStringFromChunk(mainChunks.htmlBodyChunk);
+ if(mainChunks.htmlBodyChunkBinary != null) {
+ return mainChunks.htmlBodyChunkBinary.getAs7bitString();
+ }
+ return getStringFromChunk(mainChunks.htmlBodyChunkString);
+ }
+
+ /**
+ * Gets the RTF Rich Message body of this Outlook Message, if this email
+ * contains a RTF (rich) version.
+ * @return The string representation of the 'RTF' version of the body, if available.
+ * @throws ChunkNotFoundException
+ */
+ public String getRtfBody() throws ChunkNotFoundException {
+ ByteChunk chunk = mainChunks.rtfBodyChunk;
+ if(chunk == null) {
+ if(returnNullOnMissingChunk) {
+ return null;
+ } else {
+ throw new ChunkNotFoundException();
+ }
+ }
+
+ try {
+ MAPIRtfAttribute rtf = new MAPIRtfAttribute(
+ MAPIProperty.RTF_COMPRESSED, Types.BINARY, chunk.getValue()
+ );
+ return rtf.getDataString();
+ } catch(IOException e) {
+ throw new RuntimeException("Shouldn't happen", e);
+ }
}
/**
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java?rev=1087782&r1=1087781&r2=1087782&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java Fri Apr 1 16:01:29 2011
@@ -38,7 +38,10 @@ public final class Chunks implements Chu
/** BODY Chunk, for plain/text messages */
public StringChunk textBodyChunk;
/** BODY Html Chunk, for html messages */
- public StringChunk htmlBodyChunk;
+ public StringChunk htmlBodyChunkString;
+ public ByteChunk htmlBodyChunkBinary;
+ /** BODY Rtf Chunk, for Rtf (Rich) messages */
+ public ByteChunk rtfBodyChunk;
/** Subject link chunk, in plain/text */
public StringChunk subjectChunk;
/** Value that is in the TO field (not actually the addresses as they are stored in recip directory nodes */
@@ -119,9 +122,16 @@ public final class Chunks implements Chu
else if(chunk.getChunkId() == MAPIProperty.BODY.id) {
textBodyChunk = (StringChunk)chunk;
}
- else if(chunk.getChunkId() == MAPIProperty.BODY_HTML.id &&
- chunk instanceof StringChunk) {
- htmlBodyChunk = (StringChunk)chunk;
+ else if(chunk.getChunkId() == MAPIProperty.BODY_HTML.id) {
+ if(chunk instanceof StringChunk) {
+ htmlBodyChunkString = (StringChunk)chunk;
+ }
+ if(chunk instanceof ByteChunk) {
+ htmlBodyChunkBinary = (ByteChunk)chunk;
+ }
+ }
+ else if(chunk.getChunkId() == MAPIProperty.RTF_COMPRESSED.id) {
+ rtfBodyChunk = (ByteChunk)chunk;
}
// And add to the main list
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java?rev=1087782&r1=1087781&r2=1087782&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java Fri Apr 1 16:01:29 2011
@@ -120,7 +120,6 @@ private MAPIMessage mapiMessage;
TestCase.assertEquals("IN-SPIRE servers going down for a bit, back up around 8am", obtained);
}
-
/**
* Check if we can read the subject line of the blank message, we expect ""
*
@@ -130,7 +129,17 @@ private MAPIMessage mapiMessage;
String obtained = mapiMessage.getMessageClass();
TestCase.assertEquals("IPM.Note", obtained);
}
-
-
-
+
+ /**
+ * Ensure we can get the HTML and RTF versions
+ */
+ public void testReadBodyContents() throws Exception {
+ String html = mapiMessage.getHmtlBody();
+ String rtf = mapiMessage.getRtfBody();
+ assertNotNull(html);
+ assertNotNull(rtf);
+
+ assertTrue("Wrong text:\n" + html, html.startsWith("<!DOCTYPE"));
+ assertTrue("Wrong text:\n" + rtf, rtf.startsWith("{\\rtf1"));
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org