use of org.apache.poi.hsmf.datatypes.RecipientChunks.RecipientChunksSorter in project poi by apache.
the class TestPOIFSChunkParser method testFindsMultipleRecipients.
@Test
public void testFindsMultipleRecipients() throws IOException, ChunkNotFoundException {
NPOIFSFileSystem multiple = new NPOIFSFileSystem(samples.getFile("example_received_unicode.msg"), true);
multiple.getRoot().getEntry("__recip_version1.0_#00000000");
multiple.getRoot().getEntry("__recip_version1.0_#00000001");
multiple.getRoot().getEntry("__recip_version1.0_#00000002");
multiple.getRoot().getEntry("__recip_version1.0_#00000003");
multiple.getRoot().getEntry("__recip_version1.0_#00000004");
multiple.getRoot().getEntry("__recip_version1.0_#00000005");
ChunkGroup[] groups = POIFSChunkParser.parse(multiple.getRoot());
assertEquals(9, groups.length);
assertTrue(groups[0] instanceof Chunks);
assertTrue(groups[1] instanceof RecipientChunks);
assertTrue(groups[2] instanceof RecipientChunks);
assertTrue(groups[3] instanceof RecipientChunks);
assertTrue(groups[4] instanceof RecipientChunks);
assertTrue(groups[5] instanceof AttachmentChunks);
assertTrue(groups[6] instanceof RecipientChunks);
assertTrue(groups[7] instanceof RecipientChunks);
assertTrue(groups[8] instanceof NameIdChunks);
// In FS order initially
RecipientChunks[] chunks = new RecipientChunks[] { (RecipientChunks) groups[1], (RecipientChunks) groups[2], (RecipientChunks) groups[3], (RecipientChunks) groups[4], (RecipientChunks) groups[6], (RecipientChunks) groups[7] };
assertEquals(6, chunks.length);
assertEquals(0, chunks[0].recipientNumber);
assertEquals(2, chunks[1].recipientNumber);
assertEquals(4, chunks[2].recipientNumber);
assertEquals(5, chunks[3].recipientNumber);
assertEquals(3, chunks[4].recipientNumber);
assertEquals(1, chunks[5].recipientNumber);
// Check
assertEquals("'Ashutosh Dandavate'", chunks[0].getRecipientName());
assertEquals("ashutosh.dandavate@alfresco.com", chunks[0].getRecipientEmailAddress());
assertEquals("'Mike Farman'", chunks[1].getRecipientName());
assertEquals("mikef@alfresco.com", chunks[1].getRecipientEmailAddress());
assertEquals("nick.burch@alfresco.com", chunks[2].getRecipientName());
assertEquals("nick.burch@alfresco.com", chunks[2].getRecipientEmailAddress());
assertEquals("'Roy Wetherall'", chunks[3].getRecipientName());
assertEquals("roy.wetherall@alfresco.com", chunks[3].getRecipientEmailAddress());
assertEquals("nickb@alfresco.com", chunks[4].getRecipientName());
assertEquals("nickb@alfresco.com", chunks[4].getRecipientEmailAddress());
assertEquals("'Paul Holmes-Higgin'", chunks[5].getRecipientName());
assertEquals("paul.hh@alfresco.com", chunks[5].getRecipientEmailAddress());
// Now sort, and re-check
Arrays.sort(chunks, new RecipientChunksSorter());
assertEquals("'Ashutosh Dandavate'", chunks[0].getRecipientName());
assertEquals("ashutosh.dandavate@alfresco.com", chunks[0].getRecipientEmailAddress());
assertEquals("'Paul Holmes-Higgin'", chunks[1].getRecipientName());
assertEquals("paul.hh@alfresco.com", chunks[1].getRecipientEmailAddress());
assertEquals("'Mike Farman'", chunks[2].getRecipientName());
assertEquals("mikef@alfresco.com", chunks[2].getRecipientEmailAddress());
assertEquals("nickb@alfresco.com", chunks[3].getRecipientName());
assertEquals("nickb@alfresco.com", chunks[3].getRecipientEmailAddress());
assertEquals("nick.burch@alfresco.com", chunks[4].getRecipientName());
assertEquals("nick.burch@alfresco.com", chunks[4].getRecipientEmailAddress());
assertEquals("'Roy Wetherall'", chunks[5].getRecipientName());
assertEquals("roy.wetherall@alfresco.com", chunks[5].getRecipientEmailAddress());
// Finally check on message
MAPIMessage msg = new MAPIMessage(multiple);
assertEquals(6, msg.getRecipientEmailAddressList().length);
assertEquals(6, msg.getRecipientNamesList().length);
assertEquals("'Ashutosh Dandavate'", msg.getRecipientNamesList()[0]);
assertEquals("'Paul Holmes-Higgin'", msg.getRecipientNamesList()[1]);
assertEquals("'Mike Farman'", msg.getRecipientNamesList()[2]);
assertEquals("nickb@alfresco.com", msg.getRecipientNamesList()[3]);
assertEquals("nick.burch@alfresco.com", msg.getRecipientNamesList()[4]);
assertEquals("'Roy Wetherall'", msg.getRecipientNamesList()[5]);
assertEquals("ashutosh.dandavate@alfresco.com", msg.getRecipientEmailAddressList()[0]);
assertEquals("paul.hh@alfresco.com", msg.getRecipientEmailAddressList()[1]);
assertEquals("mikef@alfresco.com", msg.getRecipientEmailAddressList()[2]);
assertEquals("nickb@alfresco.com", msg.getRecipientEmailAddressList()[3]);
assertEquals("nick.burch@alfresco.com", msg.getRecipientEmailAddressList()[4]);
assertEquals("roy.wetherall@alfresco.com", msg.getRecipientEmailAddressList()[5]);
msg.close();
multiple.close();
}
use of org.apache.poi.hsmf.datatypes.RecipientChunks.RecipientChunksSorter in project poi by apache.
the class TestSorters method testRecipientChunksSorter.
public void testRecipientChunksSorter() {
RecipientChunks[] chunks;
// Simple
chunks = new RecipientChunks[] { new RecipientChunks("__recip_version1.0_#00000001"), new RecipientChunks("__recip_version1.0_#00000000") };
Arrays.sort(chunks, new RecipientChunksSorter());
assertEquals(0, chunks[0].recipientNumber);
assertEquals(1, chunks[1].recipientNumber);
// Lots, with gaps
chunks = new RecipientChunks[] { new RecipientChunks("__recip_version1.0_#00020001"), new RecipientChunks("__recip_version1.0_#000000FF"), new RecipientChunks("__recip_version1.0_#00000205"), new RecipientChunks("__recip_version1.0_#00000001"), new RecipientChunks("__recip_version1.0_#00000005"), new RecipientChunks("__recip_version1.0_#00000009"), new RecipientChunks("__recip_version1.0_#00000404"), new RecipientChunks("__recip_version1.0_#00000000") };
Arrays.sort(chunks, new RecipientChunksSorter());
assertEquals(0, chunks[0].recipientNumber);
assertEquals(1, chunks[1].recipientNumber);
assertEquals(5, chunks[2].recipientNumber);
assertEquals(9, chunks[3].recipientNumber);
assertEquals(0xFF, chunks[4].recipientNumber);
assertEquals(0x205, chunks[5].recipientNumber);
assertEquals(0x404, chunks[6].recipientNumber);
assertEquals(0x20001, chunks[7].recipientNumber);
}
Aggregations