]> source.dussan.org Git - poi.git/commitdiff
Complete chunk parser tests, and make more chunk groups available
authorNick Burch <nick@apache.org>
Fri, 8 Jan 2010 11:37:37 +0000 (11:37 +0000)
committerNick Burch <nick@apache.org>
Fri, 8 Jan 2010 11:37:37 +0000 (11:37 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@897172 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java

index 6e6cee08cdcc2feaf4b708ac5aad3240c7637c86..790669032cc5f297ecc7c5099893f1e65288799a 100644 (file)
@@ -190,6 +190,27 @@ public class MAPIMessage {
                return getStringFromChunk(mainChunks.messageClass);
        }
 
+       
+       /**
+        * Gets the main, core details chunks
+        */
+       public Chunks getMainChunks() {
+          return mainChunks;
+       }
+       /**
+        * Gets the recipient details chunks, or
+        *  null if there aren't any
+        */
+       public RecipientChunks getRecipientDetailsChunks() {
+          return recipientChunks;
+       }
+       /**
+        * Gets the Name ID chunks, or
+    *  null if there aren't any
+        */
+       public NameIdChunks getNameIdChunks() {
+          return nameIdChunks;
+       }
        /**
         * Gets the message attachments.
         */
index a86a4cec540efd792522ad93d2107182564d7d0a..f379d8b2b4d6b9018698cf8eba95aa22bba47c03 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.poi.hsmf.parsers;
 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;
@@ -27,6 +28,8 @@ import org.apache.poi.hsmf.datatypes.ChunkGroup;
 import org.apache.poi.hsmf.datatypes.Chunks;
 import org.apache.poi.hsmf.datatypes.NameIdChunks;
 import org.apache.poi.hsmf.datatypes.RecipientChunks;
+import org.apache.poi.hsmf.datatypes.StringChunk;
+import org.apache.poi.hsmf.datatypes.Types;
 import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.POIDataSamples;
@@ -43,8 +46,76 @@ public final class TestPOIFSChunkParser extends TestCase {
         samples = POIDataSamples.getHSMFInstance();
        }
        
+   public void testFindsCore() throws IOException {
+      POIFSFileSystem simple = new POIFSFileSystem(
+            new FileInputStream(samples.getFile("quick.msg"))
+      );
+      
+      // Check a few core things are present
+      simple.getRoot().getEntry(
+            (new StringChunk(Chunks.SUBJECT, Types.ASCII_STRING)).getEntryName()
+      );
+      simple.getRoot().getEntry(
+            (new StringChunk(Chunks.DISPLAY_FROM, Types.ASCII_STRING)).getEntryName()
+      );
+      
+      // Now load the file
+      MAPIMessage msg = new MAPIMessage(simple);
+      try {
+         assertEquals("Kevin Roast", msg.getDisplayTo());
+         assertEquals("Kevin Roast", msg.getDisplayFrom());
+         assertEquals("Test the content transformer", msg.getSubject());
+      } catch(ChunkNotFoundException e) {
+         fail();
+      }
+   }
+   
    public void testFindsRecips() throws IOException {
+      POIFSFileSystem simple = new POIFSFileSystem(
+            new FileInputStream(samples.getFile("quick.msg"))
+      );
+      
+      simple.getRoot().getEntry("__recip_version1.0_#00000000");
+
+      ChunkGroup[] groups = POIFSChunkParser.parse(simple.getRoot());
+      assertEquals(3, groups.length);
+      assertTrue(groups[0] instanceof Chunks);
+      assertTrue(groups[1] instanceof RecipientChunks);
+      assertTrue(groups[2] instanceof NameIdChunks);
+      
+      RecipientChunks recips = (RecipientChunks)groups[1];
+      assertEquals("kevin.roast@alfresco.org", recips.recipientEmailChunk.getValue());
+      
+      String search = new String(recips.recipientSearchChunk.getValue(), "ASCII");
+      assertEquals("CN=KEVIN.ROAST@BEN\0", search.substring(search.length()-19));
+      
+      // Now via MAPIMessage
+      MAPIMessage msg = new MAPIMessage(simple);
+      assertNotNull(msg.getRecipientDetailsChunks());
+      
+      assertEquals("kevin.roast@alfresco.org", msg.getRecipientDetailsChunks().recipientEmailChunk.getValue());
+   }
+   
+   public void testFindsNameId() throws IOException {
+      POIFSFileSystem simple = new POIFSFileSystem(
+            new FileInputStream(samples.getFile("quick.msg"))
+      );
+      
+      simple.getRoot().getEntry("__nameid_version1.0");
+
+      ChunkGroup[] groups = POIFSChunkParser.parse(simple.getRoot());
+      assertEquals(3, groups.length);
+      assertTrue(groups[0] instanceof Chunks);
+      assertTrue(groups[1] instanceof RecipientChunks);
+      assertTrue(groups[2] instanceof NameIdChunks);
+      
+      NameIdChunks nameId = (NameIdChunks)groups[2];
+      assertEquals(10, nameId.getAll().length);
       
+      // Now via MAPIMessage
+      MAPIMessage msg = new MAPIMessage(simple);
+      assertNotNull(msg.getNameIdChunks());
+      assertEquals(10, msg.getNameIdChunks().getAll().length);
    }
    
        public void testFindsAttachments() throws IOException {