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;
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;
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 {