Author: nick
Date: Fri Jan 8 11:37:37 2010
New Revision: 897172
URL: http://svn.apache.org/viewvc?rev=897172&view=rev
Log:
Complete chunk parser tests, and make more chunk groups available
Modified:
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java?rev=897172&r1=897171&r2=897172&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java Fri Jan
8 11:37:37 2010
@@ -190,6 +190,27 @@
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.
*/
Modified:
poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java?rev=897172&r1=897171&r2=897172&view=diff
==============================================================================
---
poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java
(original)
+++
poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java
Fri Jan 8 11:37:37 2010
@@ -20,6 +20,7 @@
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.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 @@
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("[email protected]",
recips.recipientEmailChunk.getValue());
+
+ String search = new String(recips.recipientSearchChunk.getValue(),
"ASCII");
+ assertEquals("cn=kevin.ro...@ben\0",
search.substring(search.length()-19));
+
+ // Now via MAPIMessage
+ MAPIMessage msg = new MAPIMessage(simple);
+ assertNotNull(msg.getRecipientDetailsChunks());
+
+ assertEquals("[email protected]",
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 {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]