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
This commit is contained in:
Nick Burch 2010-01-08 11:37:37 +00:00
parent 0e368a23da
commit 795ed3ce55
2 changed files with 93 additions and 1 deletions

View File

@ -190,6 +190,27 @@ public class MAPIMessage {
return getStringFromChunk(mainChunks.messageClass); 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. * Gets the message attachments.
*/ */

View File

@ -20,6 +20,7 @@ package org.apache.poi.hsmf.parsers;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset;
import org.apache.poi.hsmf.MAPIMessage; import org.apache.poi.hsmf.MAPIMessage;
import org.apache.poi.hsmf.datatypes.AttachmentChunks; 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.Chunks;
import org.apache.poi.hsmf.datatypes.NameIdChunks; import org.apache.poi.hsmf.datatypes.NameIdChunks;
import org.apache.poi.hsmf.datatypes.RecipientChunks; 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.hsmf.exceptions.ChunkNotFoundException;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
@ -43,8 +46,76 @@ public final class TestPOIFSChunkParser extends TestCase {
samples = POIDataSamples.getHSMFInstance(); samples = POIDataSamples.getHSMFInstance();
} }
public void testFindsRecips() throws IOException { 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 { public void testFindsAttachments() throws IOException {