Search in sources :

Example 6 with ChunkGroup

use of org.apache.poi.hsmf.datatypes.ChunkGroup in project poi by apache.

the class TestPOIFSChunkParser method testFindsRecips.

@Test
public void testFindsRecips() throws IOException, ChunkNotFoundException {
    NPOIFSFileSystem simple = new NPOIFSFileSystem(samples.getFile("quick.msg"), true);
    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.recipientSMTPChunk.getValue());
    assertEquals("/O=HOSTEDSERVICE2/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=Kevin.roast@ben", 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(1, msg.getRecipientDetailsChunks().length);
    assertEquals("kevin.roast@alfresco.org", msg.getRecipientDetailsChunks()[0].recipientSMTPChunk.getValue());
    assertEquals("kevin.roast@alfresco.org", msg.getRecipientDetailsChunks()[0].getRecipientEmailAddress());
    assertEquals("Kevin Roast", msg.getRecipientDetailsChunks()[0].getRecipientName());
    assertEquals("kevin.roast@alfresco.org", msg.getRecipientEmailAddress());
    // Try both SMTP and EX files for recipient
    assertEquals("EX", msg.getRecipientDetailsChunks()[0].deliveryTypeChunk.getValue());
    assertEquals("kevin.roast@alfresco.org", msg.getRecipientDetailsChunks()[0].recipientSMTPChunk.getValue());
    assertEquals("/O=HOSTEDSERVICE2/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=Kevin.roast@ben", msg.getRecipientDetailsChunks()[0].recipientEmailChunk.getValue());
    msg.close();
    simple.close();
    // Now look at another message
    simple = new NPOIFSFileSystem(samples.getFile("simple_test_msg.msg"), true);
    msg = new MAPIMessage(simple);
    assertNotNull(msg.getRecipientDetailsChunks());
    assertEquals(1, msg.getRecipientDetailsChunks().length);
    assertEquals("SMTP", msg.getRecipientDetailsChunks()[0].deliveryTypeChunk.getValue());
    assertEquals(null, msg.getRecipientDetailsChunks()[0].recipientSMTPChunk);
    assertEquals(null, msg.getRecipientDetailsChunks()[0].recipientNameChunk);
    assertEquals("travis@overwrittenstack.com", msg.getRecipientDetailsChunks()[0].recipientEmailChunk.getValue());
    assertEquals("travis@overwrittenstack.com", msg.getRecipientEmailAddress());
    msg.close();
    simple.close();
}
Also used : MAPIMessage(org.apache.poi.hsmf.MAPIMessage) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) ChunkGroup(org.apache.poi.hsmf.datatypes.ChunkGroup) Chunks(org.apache.poi.hsmf.datatypes.Chunks) RecipientChunks(org.apache.poi.hsmf.datatypes.RecipientChunks) NameIdChunks(org.apache.poi.hsmf.datatypes.NameIdChunks) AttachmentChunks(org.apache.poi.hsmf.datatypes.AttachmentChunks) RecipientChunks(org.apache.poi.hsmf.datatypes.RecipientChunks) NameIdChunks(org.apache.poi.hsmf.datatypes.NameIdChunks) Test(org.junit.Test)

Aggregations

ChunkGroup (org.apache.poi.hsmf.datatypes.ChunkGroup)6 AttachmentChunks (org.apache.poi.hsmf.datatypes.AttachmentChunks)5 Chunks (org.apache.poi.hsmf.datatypes.Chunks)5 NameIdChunks (org.apache.poi.hsmf.datatypes.NameIdChunks)5 RecipientChunks (org.apache.poi.hsmf.datatypes.RecipientChunks)5 MAPIMessage (org.apache.poi.hsmf.MAPIMessage)4 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)1 Chunk (org.apache.poi.hsmf.datatypes.Chunk)1 MAPIProperty (org.apache.poi.hsmf.datatypes.MAPIProperty)1 PropertiesChunk (org.apache.poi.hsmf.datatypes.PropertiesChunk)1 PropertyValue (org.apache.poi.hsmf.datatypes.PropertyValue)1 RecipientChunksSorter (org.apache.poi.hsmf.datatypes.RecipientChunks.RecipientChunksSorter)1 DirectoryNode (org.apache.poi.poifs.filesystem.DirectoryNode)1 Entry (org.apache.poi.poifs.filesystem.Entry)1