From: Nick Burch Date: Fri, 8 Jan 2010 11:37:37 +0000 (+0000) Subject: Complete chunk parser tests, and make more chunk groups available X-Git-Tag: REL_3_7_BETA1~161 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4c002588af162762bc6b309904683c43d2895887;p=poi.git Complete chunk parser tests, and make more chunk groups available git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@897172 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java b/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java index 6e6cee08cd..790669032c 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java @@ -190,6 +190,27 @@ public class MAPIMessage { return getStringFromChunk(mainChunks.messageClass); } + + /** + * Gets the main, core details chunks + */ + public Chunks getMainChunks() { + return mainChunks; + } + /** + * Gets the recipient details chunks, or + * null if there aren't any + */ + public RecipientChunks getRecipientDetailsChunks() { + return recipientChunks; + } + /** + * Gets the Name ID chunks, or + * null if there aren't any + */ + public NameIdChunks getNameIdChunks() { + return nameIdChunks; + } /** * Gets the message attachments. */ diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java b/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java index a86a4cec54..f379d8b2b4 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java @@ -20,6 +20,7 @@ package org.apache.poi.hsmf.parsers; 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; @@ -27,6 +28,8 @@ import org.apache.poi.hsmf.datatypes.ChunkGroup; 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; @@ -43,8 +46,76 @@ public final class TestPOIFSChunkParser extends TestCase { 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 {