Author: onealj
Date: Thu Jan  5 07:59:27 2017
New Revision: 1777428

URL: http://svn.apache.org/viewvc?rev=1777428&view=rev
Log:
bug 60550: read ContentID chunks from mail attachments

Added:
    poi/trunk/test-data/hsmf/attachment_msg_inlineImg.msg   (with props)
Modified:
    
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunk.java
    
poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestFileWithAttachmentsRead.java

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=1777428&r1=1777427&r2=1777428&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
 Thu Jan  5 07:59:27 2017
@@ -16,6 +16,7 @@
 ==================================================================== */
 package org.apache.poi.hsmf.datatypes;
 
+import static org.apache.poi.hsmf.datatypes.MAPIProperty.ATTACH_CONTENT_ID;
 import static org.apache.poi.hsmf.datatypes.MAPIProperty.ATTACH_DATA;
 import static org.apache.poi.hsmf.datatypes.MAPIProperty.ATTACH_EXTENSION;
 import static org.apache.poi.hsmf.datatypes.MAPIProperty.ATTACH_FILENAME;
@@ -47,6 +48,7 @@ public class AttachmentChunks implements
     private StringChunk attachLongFileName;
     private StringChunk attachMimeTag;
     private DirectoryChunk attachmentDirectory;
+    private StringChunk attachContentId;
 
     /**
      * This is in WMF Format. You'll probably want to pass it to Apache Batik 
to
@@ -158,6 +160,13 @@ public class AttachmentChunks implements
     }
 
     /**
+     * @return the attachment content ID
+     */
+    public StringChunk getAttachContentId() {
+        return attachContentId;
+    }
+
+    /**
      * Called by the parser whenever a chunk is found.
      */
     @Override
@@ -178,7 +187,7 @@ public class AttachmentChunks implements
             } else if (chunk instanceof DirectoryChunk) {
                 attachmentDirectory = (DirectoryChunk) chunk;
             } else {
-                LOG.log(POILogger.ERROR, "Unexpected data chunk of type " + 
chunk);
+                LOG.log(POILogger.ERROR, "Unexpected data chunk of type " + 
chunk.getEntryName());
             }
         } else if (chunkId == ATTACH_EXTENSION.id) {
             attachExtension = (StringChunk) chunk;
@@ -190,6 +199,10 @@ public class AttachmentChunks implements
             attachMimeTag = (StringChunk) chunk;
         } else if (chunkId == ATTACH_RENDERING.id) {
             attachRenderingWMF = (ByteChunk) chunk;
+        } else if (chunkId == ATTACH_CONTENT_ID.id) {
+            attachContentId = (StringChunk) chunk;
+        } else {
+            LOG.log(POILogger.WARN, "Currently unsupported attachment chunk 
property will be ignored. " + chunk.getEntryName());
         }
 
         // And add to the main list

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunk.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunk.java?rev=1777428&r1=1777427&r2=1777428&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunk.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunk.java Thu 
Jan  5 07:59:27 2017
@@ -27,9 +27,9 @@ import org.apache.poi.hsmf.datatypes.Typ
 public abstract class Chunk {
     public static final String DEFAULT_NAME_PREFIX = "__substg1.0_";
 
-    private int chunkId;
-    private MAPIType type;
-    private String namePrefix;
+    private final int chunkId;
+    private final MAPIType type;
+    private final String namePrefix;
 
     protected Chunk(String namePrefix, int chunkId, MAPIType type) {
         this.namePrefix = namePrefix;

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=1777428&r1=1777427&r2=1777428&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
 Thu Jan  5 07:59:27 2017
@@ -31,6 +31,7 @@ import org.apache.poi.hsmf.exceptions.Ch
 public class TestFileWithAttachmentsRead extends TestCase {
     private final MAPIMessage twoSimpleAttachments;
     private final MAPIMessage pdfMsgAttachments;
+    private final MAPIMessage inlineImgMsgAttachments;
 
     /**
      * Initialize this test, load up the attachment_test_msg.msg mapi message.
@@ -41,6 +42,7 @@ public class TestFileWithAttachmentsRead
         POIDataSamples samples = POIDataSamples.getHSMFInstance();
         this.twoSimpleAttachments = new 
MAPIMessage(samples.openResourceAsStream("attachment_test_msg.msg"));
         this.pdfMsgAttachments = new 
MAPIMessage(samples.openResourceAsStream("attachment_msg_pdf.msg"));
+        this.inlineImgMsgAttachments = new 
MAPIMessage(samples.openResourceAsStream("attachment_msg_inlineImg.msg"));
     }
 
     /**
@@ -60,6 +62,37 @@ public class TestFileWithAttachmentsRead
     }
 
     /**
+     * Test to see if we get the correct Content-IDs of inline images.
+     */
+    public void testReadContentIDField() throws IOException {
+        AttachmentChunks[] attachments = 
inlineImgMsgAttachments.getAttachmentFiles();
+
+        AttachmentChunks attachment;
+
+        // Check in Content-ID field
+        attachment = inlineImgMsgAttachments.getAttachmentFiles()[0];
+        assertEquals("image001.png", 
attachment.getAttachFileName().getValue());
+        assertEquals(".png", attachment.getAttachExtension().getValue());
+        assertEquals("[email protected]", 
attachment.getAttachContentId().getValue());
+
+        attachment = inlineImgMsgAttachments.getAttachmentFiles()[1];
+        assertEquals("image002.png", 
attachment.getAttachFileName().getValue());
+        assertEquals(".png", attachment.getAttachExtension().getValue());
+        assertEquals("[email protected]", 
attachment.getAttachContentId().getValue());
+
+        attachment = inlineImgMsgAttachments.getAttachmentFiles()[2];
+        assertEquals("image003.png", 
attachment.getAttachFileName().getValue());
+        assertEquals(".png", attachment.getAttachExtension().getValue());
+        assertEquals("[email protected]", 
attachment.getAttachContentId().getValue());
+
+        attachment = inlineImgMsgAttachments.getAttachmentFiles()[3];
+        assertEquals("image006.jpg", 
attachment.getAttachFileName().getValue());
+        assertEquals(".jpg", attachment.getAttachExtension().getValue());
+        assertEquals("[email protected]", 
attachment.getAttachContentId().getValue());
+    }
+
+
+    /**
      * Test to see if attachments are not empty.
      */
     public void testReadAttachments() throws IOException {
@@ -83,14 +116,14 @@ public class TestFileWithAttachmentsRead
         assertEquals("test-unicode.doc", 
attachment.getAttachLongFileName().getValue());
         assertEquals(".doc", attachment.getAttachExtension().getValue());
         assertNull(attachment.getAttachMimeTag());
-        assertEquals(24064, attachment.getAttachData().getValue().length);
+        assertEquals(24064, attachment.getAttachData().getValue().length); // 
or compare the hashes of the attachment data
 
         attachment = twoSimpleAttachments.getAttachmentFiles()[1];
         assertEquals("pj1.txt", attachment.getAttachFileName().getValue());
         assertEquals("pj1.txt", attachment.getAttachLongFileName().getValue());
         assertEquals(".txt", attachment.getAttachExtension().getValue());
         assertNull(attachment.getAttachMimeTag());
-        assertEquals(89, attachment.getAttachData().getValue().length);
+        assertEquals(89, attachment.getAttachData().getValue().length); // or 
compare the hashes of the attachment data
     }
     
     /**
@@ -109,7 +142,7 @@ public class TestFileWithAttachmentsRead
         assertEquals(".pdf", attachment.getAttachExtension().getValue());
         assertNull(attachment.getAttachMimeTag());
         assertNull(attachment.getAttachmentDirectory());
-        assertEquals(13539, attachment.getAttachData().getValue().length);
+        assertEquals(13539, attachment.getAttachData().getValue().length); 
//or compare the hashes of the attachment data
         
         // First in a nested message
         attachment = pdfMsgAttachments.getAttachmentFiles()[0];

Added: poi/trunk/test-data/hsmf/attachment_msg_inlineImg.msg
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/hsmf/attachment_msg_inlineImg.msg?rev=1777428&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/hsmf/attachment_msg_inlineImg.msg
------------------------------------------------------------------------------
    svn:mime-type = application/vnd.ms-outlook



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to