Search in sources :

Example 6 with RecipientChunks

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

the class TestPOIFSChunkParser method testFindsNameId.

@Test
public void testFindsNameId() throws IOException {
    NPOIFSFileSystem simple = new NPOIFSFileSystem(samples.getFile("quick.msg"), true);
    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);
    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)

Example 7 with RecipientChunks

use of org.apache.poi.hsmf.datatypes.RecipientChunks 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)

Example 8 with RecipientChunks

use of org.apache.poi.hsmf.datatypes.RecipientChunks in project tika by apache.

the class OutlookExtractor method buildRecipients.

private List<Recipient> buildRecipients() {
    RecipientChunks[] recipientChunks = msg.getRecipientDetailsChunks();
    if (recipientChunks == null) {
        return Collections.EMPTY_LIST;
    }
    List<Recipient> recipients = new LinkedList<>();
    for (RecipientChunks chunks : recipientChunks) {
        Recipient r = new Recipient();
        r.displayName = (chunks.recipientDisplayNameChunk != null) ? chunks.recipientDisplayNameChunk.toString() : null;
        r.name = (chunks.recipientNameChunk != null) ? chunks.recipientNameChunk.toString() : null;
        r.emailAddress = chunks.getRecipientEmailAddress();
        List<PropertyValue> vals = chunks.getProperties().get(MAPIProperty.RECIPIENT_TYPE);
        RECIPIENT_TYPE recipientType = RECIPIENT_TYPE.UNSPECIFIED;
        if (vals != null && vals.size() > 0) {
            Object val = vals.get(0).getValue();
            if (val instanceof Integer) {
                recipientType = RECIPIENT_TYPE.getTypeFromVal((int) val);
            }
        }
        r.recipientType = recipientType;
        vals = chunks.getProperties().get(MAPIProperty.ADDRTYPE);
        if (vals != null && vals.size() > 0) {
            String val = vals.get(0).toString();
            if (val != null) {
                val = val.toLowerCase(Locale.US);
                //need to find example of this for testing
                if (val.equals("ex")) {
                    r.addressType = ADDRESS_TYPE.EX;
                } else if (val.equals("smtp")) {
                    r.addressType = ADDRESS_TYPE.SMTP;
                }
            }
        }
        recipients.add(r);
    }
    return recipients;
}
Also used : RecipientChunks(org.apache.poi.hsmf.datatypes.RecipientChunks) PropertyValue(org.apache.poi.hsmf.datatypes.PropertyValue) LinkedList(java.util.LinkedList)

Aggregations

RecipientChunks (org.apache.poi.hsmf.datatypes.RecipientChunks)8 AttachmentChunks (org.apache.poi.hsmf.datatypes.AttachmentChunks)5 ChunkGroup (org.apache.poi.hsmf.datatypes.ChunkGroup)5 Chunks (org.apache.poi.hsmf.datatypes.Chunks)5 NameIdChunks (org.apache.poi.hsmf.datatypes.NameIdChunks)5 MAPIMessage (org.apache.poi.hsmf.MAPIMessage)4 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)4 Test (org.junit.Test)4 ChunkNotFoundException (org.apache.poi.hsmf.exceptions.ChunkNotFoundException)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)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