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();
}
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();
}
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;
}
Aggregations