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 2010/01/08 13:08:38 UTC
svn commit: r897185 - in /poi/trunk/src/scratchpad: src/org/apache/poi/hsmf/
src/org/apache/poi/hsmf/datatypes/ testcases/org/apache/poi/hsmf/
testcases/org/apache/poi/hsmf/parsers/
Author: nick
Date: Fri Jan 8 12:08:35 2010
New Revision: 897185
URL: http://svn.apache.org/viewvc?rev=897185&view=rev
Log:
Tweak a few tests, and add in a few more chunk types
Modified:
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestFileWithAttachmentsRead.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java
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=897185&r1=897184&r2=897185&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 Jan 8 12:08:35 2010
@@ -35,8 +35,11 @@
/**
* Reads an Outlook MSG File in and provides hooks into its data structure.
- *
- * @author Travis Ferguson
+ *
+ * If you want to develop with HSMF, you might find it worth getting
+ * some of the microsoft public documentation, such as:
+ *
+ * [MS-OXCMSG]: Message and Attachment Object Protocol Specification
*/
public class MAPIMessage {
private POIFSFileSystem fs;
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java?rev=897185&r1=897184&r2=897185&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java Fri Jan 8 12:08:35 2010
@@ -27,9 +27,13 @@
/* String parts of Outlook Messages Attachments that are currently known */
public static final int ATTACH_DATA = 0x3701;
+ // 0x3702 might be "attach encoding"
public static final int ATTACH_EXTENSION = 0x3703;
public static final int ATTACH_FILENAME = 0x3704;
+ // 0x3705 might be "attach method"
public static final int ATTACH_LONG_FILENAME = 0x3707;
+ public static final int ATTACH_RENDERING_WMF = 0x3709;
+ // 0x370B might be "rendering position"
public static final int ATTACH_MIME_TAG = 0x370E;
public ByteChunk attachData;
@@ -37,6 +41,12 @@
public StringChunk attachFileName;
public StringChunk attachLongFileName;
public StringChunk attachMimeTag;
+ /**
+ * This is in WMF Format. You'll probably want to pass it
+ * to Apache Batik to turn it into a SVG that you can
+ * then display.
+ */
+ public ByteChunk attachRenderingWMF;
/**
* What the POIFS name of this attachment is.
@@ -82,6 +92,8 @@
case ATTACH_MIME_TAG:
attachMimeTag = (StringChunk)chunk;
break;
+ case ATTACH_RENDERING_WMF:
+ attachRenderingWMF = (ByteChunk)chunk;
}
// And add to the main list
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=897185&r1=897184&r2=897185&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 Jan 8 12:08:35 2010
@@ -86,6 +86,7 @@
subjectChunk = (StringChunk)chunk;
break;
case DATE:
+ // TODO - parse
dateChunk = (ByteChunk)chunk;
break;
case CONVERSATION_TOPIC:
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java?rev=897185&r1=897184&r2=897185&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java Fri Jan 8 12:08:35 2010
@@ -53,6 +53,7 @@
public void record(Chunk chunk) {
switch(chunk.getChunkId()) {
case RECIPIENT_SEARCH:
+ // TODO - parse
recipientSearchChunk = (ByteChunk)chunk;
break;
case RECIPIENT_EMAIL:
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestFileWithAttachmentsRead.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestFileWithAttachmentsRead.java?rev=897185&r1=897184&r2=897185&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestFileWithAttachmentsRead.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestFileWithAttachmentsRead.java Fri Jan 8 12:08:35 2010
@@ -17,18 +17,13 @@
package org.apache.poi.hsmf;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.util.Iterator;
-import java.util.Map;
import junit.framework.TestCase;
-import org.apache.poi.hsmf.MAPIMessage;
+import org.apache.poi.POIDataSamples;
import org.apache.poi.hsmf.datatypes.AttachmentChunks;
import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
-import org.apache.poi.POIDataSamples;
/**
* Tests to verify that we can read attachments from msg file
@@ -36,50 +31,63 @@
* @author Nicolas Bureau
*/
public class TestFileWithAttachmentsRead extends TestCase {
- private MAPIMessage mapiMessage;
+ private MAPIMessage mapiMessage;
+
+ /**
+ * Initialize this test, load up the attachment_test_msg.msg mapi message.
+ *
+ * @throws Exception
+ */
+ public TestFileWithAttachmentsRead() throws IOException {
+ POIDataSamples samples = POIDataSamples.getHSMFInstance();
+ this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("attachment_test_msg.msg"));
+ }
+
+ /**
+ * Test to see if we can retrieve attachments.
+ *
+ * @throws ChunkNotFoundException
+ *
+ */
+ public void testRetrieveAttachments() {
+ AttachmentChunks[] attachments = mapiMessage.getAttachmentFiles();
+ int obtained = attachments.length;
+ int expected = 2;
+
+ TestCase.assertEquals(obtained, expected);
+ }
- /**
- * Initialize this test, load up the attachment_test_msg.msg mapi message.
- *
- * @throws Exception
- */
- public TestFileWithAttachmentsRead() throws IOException {
- POIDataSamples samples = POIDataSamples.getHSMFInstance();
- this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("attachment_test_msg.msg"));
- }
-
- /**
- * Test to see if we can retrieve attachments.
- *
- * @throws ChunkNotFoundException
- *
- */
- // public void testReadDisplayCC() throws ChunkNotFoundException {
- public void testRetrieveAttachments() {
- AttachmentChunks[] attachments = mapiMessage.getAttachmentFiles();
- int obtained = attachments.length;
- int expected = 2;
-
- TestCase.assertEquals(obtained, expected);
- }
-
- /**
- * Test to see if attachments are not empty.
- *
- * @throws ChunkNotFoundException
- *
- */
- public void testReadAttachments() throws IOException {
+ /**
+ * Test to see if attachments are not empty.
+ */
+ public void testReadAttachments() throws IOException {
AttachmentChunks[] attachments = mapiMessage.getAttachmentFiles();
- for (AttachmentChunks attachment : attachments) {
- assertTrue(attachment.attachFileName.getValue().length() > 0);
+ // Basic checks
+ for (AttachmentChunks attachment : attachments) {
+ assertTrue(attachment.attachFileName.getValue().length() > 0);
assertTrue(attachment.attachLongFileName.getValue().length() > 0);
assertTrue(attachment.attachExtension.getValue().length() > 0);
- assertTrue(attachment.attachMimeTag.getValue().length() > 0);
- }
-
- // TODO better checking
- }
-
+ if(attachment.attachMimeTag != null) {
+ assertTrue(attachment.attachMimeTag.getValue().length() > 0);
+ }
+ }
+
+ AttachmentChunks attachment;
+
+ // Now check in detail
+ attachment = mapiMessage.getAttachmentFiles()[0];
+ assertEquals("TEST-U~1.DOC", attachment.attachFileName.toString());
+ assertEquals("test-unicode.doc", attachment.attachLongFileName.toString());
+ assertEquals(".doc", attachment.attachExtension.getValue());
+ assertEquals(null, attachment.attachMimeTag);
+ assertEquals(24064, attachment.attachData.getValue().length);
+
+ attachment = mapiMessage.getAttachmentFiles()[1];
+ assertEquals("pj1.txt", attachment.attachFileName.toString());
+ assertEquals("pj1.txt", attachment.attachLongFileName.toString());
+ assertEquals(".txt", attachment.attachExtension.getValue());
+ assertEquals(null, attachment.attachMimeTag);
+ assertEquals(89, attachment.attachData.getValue().length);
+ }
}
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java?rev=897185&r1=897184&r2=897185&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java Fri Jan 8 12:08:35 2010
@@ -20,7 +20,6 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.nio.charset.Charset;
import org.apache.poi.hsmf.MAPIMessage;
import org.apache.poi.hsmf.datatypes.AttachmentChunks;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org