import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
-import java.util.Map;
import org.apache.poi.hsmf.datatypes.AttachmentChunks;
-import org.apache.poi.hsmf.datatypes.Chunk;
import org.apache.poi.hsmf.datatypes.ChunkGroup;
import org.apache.poi.hsmf.datatypes.Chunks;
import org.apache.poi.hsmf.datatypes.NameIdChunks;
public StringChunk attachFileName;
public StringChunk attachLongFileName;
public StringChunk attachMimeTag;
+
+ /**
+ * What the POIFS name of this attachment is.
+ */
+ private String poifsName;
/** Holds all the chunks that were found. */
private List<Chunk> allChunks = new ArrayList<Chunk>();
+
+ public AttachmentChunks(String poifsName) {
+ this.poifsName = poifsName;
+ }
+
public Chunk[] getAll() {
return allChunks.toArray(new Chunk[allChunks.size()]);
}
return getAll();
}
+ public String getPOIFSName() {
+ return poifsName;
+ }
+
/**
* Called by the parser whenever a chunk is found.
*/
// Do we know what to do with it?
if(dir.getName().startsWith(AttachmentChunks.PREFIX)) {
- group = new AttachmentChunks();
+ group = new AttachmentChunks(dir.getName());
}
if(dir.getName().startsWith(NameIdChunks.PREFIX)) {
group = new NameIdChunks();
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.apache.poi.hsmf.model.*;
+import org.apache.poi.hsmf.datatypes.*;
+import org.apache.poi.hsmf.parsers.*;
public final class AllHSMFTests {
suite.addTestSuite(TestBlankFileRead.class);
suite.addTestSuite(TestSimpleFileRead.class);
suite.addTestSuite(TestOutlook30FileRead.class);
- suite.addTestSuite(TestChunkData.class);
suite.addTestSuite(TestFileWithAttachmentsRead.class);
+
+ suite.addTestSuite(TestChunkData.class);
+ suite.addTestSuite(TestTypes.class);
+ suite.addTestSuite(TestPOIFSChunkParser.class);
+
return suite;
}
}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hsmf;
+
+import java.io.IOException;
+
+import org.apache.poi.hsmf.MAPIMessage;
+import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
+import org.apache.poi.POIDataSamples;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Tests to verify that the library can read blank msg files.
+ *
+ * @author Travis Ferguson
+ *
+ */
+public final class TestBlankFileRead extends TestCase {
+ private MAPIMessage mapiMessage;
+
+ /**
+ * Initialize this test, load up the blank.msg mapi message.
+ */
+ public TestBlankFileRead() throws IOException {
+ POIDataSamples samples = POIDataSamples.getHSMFInstance();
+ this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("blank.msg"));
+ }
+
+ /**
+ * Check if we can read the body of the blank message, we expect "".
+ */
+ public void testReadBody() {
+ try {
+ mapiMessage.getTextBody();
+ } catch(ChunkNotFoundException exp) {
+ return;
+ }
+
+ TestCase.fail("Should have thrown a ChunkNotFoundException but didn't");
+ }
+
+
+ /**
+ * Test to see if we can read the CC Chunk.
+ */
+ public void testReadDisplayCC() throws ChunkNotFoundException {
+ String obtained = mapiMessage.getDisplayCC();
+ String expected = "";
+
+ TestCase.assertEquals(expected, obtained);
+ }
+
+ /**
+ * Test to see if we can read the CC Chunk.
+ */
+ public void testReadDisplayTo() throws ChunkNotFoundException {
+ String obtained = mapiMessage.getDisplayTo();
+ String expected = "";
+
+ TestCase.assertEquals(expected, obtained);
+ }
+
+ /**
+ * Test to see if we can read the FROM Chunk.
+ */
+ public void testReadDisplayFrom() {
+ try {
+ mapiMessage.getDisplayFrom();
+ } catch(ChunkNotFoundException exp) {
+ return;
+ }
+
+ TestCase.fail("Should have thrown a ChunkNotFoundException but didn't");
+ }
+
+ /**
+ * Test to see if we can read the CC Chunk.
+ */
+ public void testReadDisplayBCC() throws ChunkNotFoundException {
+ String obtained = mapiMessage.getDisplayBCC();
+ String expected = "";
+
+ TestCase.assertEquals(expected, obtained);
+ }
+
+
+ /**
+ * Check if we can read the subject line of the blank message, we expect ""
+ */
+ public void testReadSubject() throws Exception {
+ String obtained = mapiMessage.getSubject();
+ TestCase.assertEquals("", obtained);
+ }
+
+
+ /**
+ * Check if we can read the subject line of the blank message, we expect ""
+ */
+ public void testReadConversationTopic() {
+ try {
+ mapiMessage.getConversationTopic();
+ } catch(ChunkNotFoundException exp) {
+ return;
+ }
+ TestCase.fail("We shouldn't have a ConversationTopic node on the blank.msg file.");
+ }
+
+
+}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hsmf;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hsmf.MAPIMessage;
+import org.apache.poi.hsmf.datatypes.AttachmentChunks;
+import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
+import org.apache.poi.POIDataSamples;
+
+/**
+ * Tests to verify that we can read attachments from msg file
+ *
+ * @author Nicolas Bureau
+ */
+public class TestFileWithAttachmentsRead extends TestCase {
+ private MAPIMessage mapiMessage;
+
+ /**
+ * Initialize this test, load up the attachment_test_msg.msg mapi message.
+ *
+ * @throws Exception
+ */
+ public TestFileWithAttachmentsRead() throws IOException {
+ POIDataSamples samples = POIDataSamples.getHSMFInstance();
+ this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("attachment_test_msg.msg"));
+ }
+
+ /**
+ * Test to see if we can retrieve attachments.
+ *
+ * @throws ChunkNotFoundException
+ *
+ */
+ // public void testReadDisplayCC() throws ChunkNotFoundException {
+ public void testRetrieveAttachments() {
+ AttachmentChunks[] attachments = mapiMessage.getAttachmentFiles();
+ int obtained = attachments.length;
+ int expected = 2;
+
+ TestCase.assertEquals(obtained, expected);
+ }
+
+ /**
+ * Test to see if attachments are not empty.
+ *
+ * @throws ChunkNotFoundException
+ *
+ */
+ public void testReadAttachments() throws IOException {
+ AttachmentChunks[] attachments = mapiMessage.getAttachmentFiles();
+
+ for (AttachmentChunks attachment : attachments) {
+ assertTrue(attachment.attachFileName.getValue().length() > 0);
+ assertTrue(attachment.attachLongFileName.getValue().length() > 0);
+ assertTrue(attachment.attachExtension.getValue().length() > 0);
+ assertTrue(attachment.attachMimeTag.getValue().length() > 0);
+ }
+
+ // TODO better checking
+ }
+
+}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hsmf;
+
+import java.io.IOException;
+
+import org.apache.poi.hsmf.MAPIMessage;
+import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
+import org.apache.poi.POIDataSamples;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests to verify that we can still work on the newer Outlook 3.0 files.
+ */
+public final class TestOutlook30FileRead extends TestCase {
+private MAPIMessage mapiMessage;
+
+ /**
+ * Initialize this test, load up the blank.msg mapi message.
+ * @throws Exception
+ */
+ public TestOutlook30FileRead() throws IOException {
+ POIDataSamples samples = POIDataSamples.getHSMFInstance();
+ this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("outlook_30_msg.msg"));
+ }
+
+ /**
+ * Test to see if we can read the CC Chunk.
+ * @throws ChunkNotFoundException
+ *
+ */
+ public void testReadDisplayCC() throws ChunkNotFoundException {
+ String obtained = mapiMessage.getDisplayCC();
+ String expected = "";
+
+ TestCase.assertEquals(obtained, expected);
+ }
+
+ /**
+ * Test to see if we can read the CC Chunk.
+ * @throws ChunkNotFoundException
+ *
+ */
+ public void testReadDisplayTo() throws ChunkNotFoundException {
+ String obtained = mapiMessage.getDisplayTo();
+
+ assertTrue(obtained.startsWith("Bohn, Shawn"));
+ }
+
+ /**
+ * Test to see if we can read the From Chunk.
+ * @throws ChunkNotFoundException
+ *
+ */
+ public void testReadDisplayFrom() throws ChunkNotFoundException {
+ String obtained = mapiMessage.getDisplayFrom();
+ String expected = "Cramer, Nick";
+
+ TestCase.assertEquals(obtained, expected);
+ }
+
+ /**
+ * Test to see if we can read the CC Chunk.
+ * @throws ChunkNotFoundException
+ *
+ */
+ public void testReadDisplayBCC() throws ChunkNotFoundException {
+ String obtained = mapiMessage.getDisplayBCC();
+ String expected = "";
+
+ TestCase.assertEquals(obtained, expected);
+ }
+
+
+ /**
+ * Check if we can read the body of the blank message, we expect "".
+ *
+ * @throws Exception
+ */
+ public void testReadBody() throws Exception {
+ String obtained = mapiMessage.getTextBody();
+ assertTrue(obtained.startsWith("I am shutting down"));
+ }
+
+ /**
+ * Check if we can read the subject line of the blank message, we expect ""
+ *
+ * @throws Exception
+ */
+ public void testReadSubject() throws Exception {
+ String obtained = mapiMessage.getSubject();
+ String expected = "IN-SPIRE servers going down for a bit, back up around 8am";
+
+ TestCase.assertEquals(expected, obtained);
+ }
+
+ /**
+ * Check if we can read the subject line of the blank message, we expect ""
+ *
+ * @throws Exception
+ */
+ public void testReadConversationTopic() throws Exception {
+ String obtained = mapiMessage.getConversationTopic();
+ TestCase.assertEquals("IN-SPIRE servers going down for a bit, back up around 8am", obtained);
+ }
+
+
+ /**
+ * Check if we can read the subject line of the blank message, we expect ""
+ *
+ * @throws Exception
+ */
+ public void testReadMessageClass() throws Exception {
+ String obtained = mapiMessage.getMessageClass();
+ TestCase.assertEquals("IPM.Note", obtained);
+ }
+
+
+
+}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hsmf;
+
+import java.io.IOException;
+
+import org.apache.poi.hsmf.MAPIMessage;
+import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
+import org.apache.poi.POIDataSamples;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests to verify that we can read a simple msg file, that is in plain/text format with no attachments
+ * or extra recipents.
+ *
+ * @author Travis Ferguson
+ */
+public final class TestSimpleFileRead extends TestCase {
+private MAPIMessage mapiMessage;
+
+ /**
+ * Initialize this test, load up the blank.msg mapi message.
+ * @throws Exception
+ */
+ public TestSimpleFileRead() throws IOException {
+ POIDataSamples samples = POIDataSamples.getHSMFInstance();
+ this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("simple_test_msg.msg"));
+ }
+
+ /**
+ * Test to see if we can read the CC Chunk.
+ * @throws ChunkNotFoundException
+ *
+ */
+ public void testReadDisplayCC() throws ChunkNotFoundException {
+ String obtained = mapiMessage.getDisplayCC();
+ String expected = "";
+
+ TestCase.assertEquals(obtained, expected);
+ }
+
+ /**
+ * Test to see if we can read the CC Chunk.
+ * @throws ChunkNotFoundException
+ *
+ */
+ public void testReadDisplayTo() throws ChunkNotFoundException {
+ String obtained = mapiMessage.getDisplayTo();
+ String expected = "travis@overwrittenstack.com";
+
+ TestCase.assertEquals(obtained, expected);
+ }
+
+ /**
+ * Test to see if we can read the From Chunk.
+ * @throws ChunkNotFoundException
+ *
+ */
+ public void testReadDisplayFrom() throws ChunkNotFoundException {
+ String obtained = mapiMessage.getDisplayFrom();
+ String expected = "Travis Ferguson";
+
+ TestCase.assertEquals(obtained, expected);
+ }
+
+ /**
+ * Test to see if we can read the CC Chunk.
+ * @throws ChunkNotFoundException
+ *
+ */
+ public void testReadDisplayBCC() throws ChunkNotFoundException {
+ String obtained = mapiMessage.getDisplayBCC();
+ String expected = "";
+
+ TestCase.assertEquals(obtained, expected);
+ }
+
+
+ /**
+ * Check if we can read the body of the blank message, we expect "".
+ *
+ * @throws Exception
+ */
+ public void testReadBody() throws Exception {
+ String obtained = mapiMessage.getTextBody();
+ String expected = "This is a test message.";
+
+ TestCase.assertEquals(obtained, expected);
+ }
+
+ /**
+ * Check if we can read the subject line of the blank message, we expect ""
+ *
+ * @throws Exception
+ */
+ public void testReadSubject() throws Exception {
+ String obtained = mapiMessage.getSubject();
+ String expected = "test message";
+
+ TestCase.assertEquals(expected, obtained);
+ }
+
+ /**
+ * Check if we can read the subject line of the blank message, we expect ""
+ *
+ * @throws Exception
+ */
+ public void testReadConversationTopic() throws Exception {
+ String obtained = mapiMessage.getConversationTopic();
+ TestCase.assertEquals("test message", obtained);
+ }
+
+
+ /**
+ * Check if we can read the subject line of the blank message, we expect ""
+ *
+ * @throws Exception
+ */
+ public void testReadMessageClass() throws Exception {
+ String obtained = mapiMessage.getMessageClass();
+ TestCase.assertEquals("IPM.Note", obtained);
+ }
+
+
+
+}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hsmf.datatypes;
+
+import org.apache.poi.hsmf.datatypes.Chunk;
+import org.apache.poi.hsmf.datatypes.Chunks;
+import org.apache.poi.hsmf.datatypes.StringChunk;
+import org.apache.poi.hsmf.datatypes.Types;
+
+import junit.framework.TestCase;
+
+/**
+ * Verifies that the Chunks class is actually setup properly and hasn't been changed in ways
+ * that will break the library.
+ *
+ * @author Travis Ferguson
+ *
+ */
+public final class TestChunkData extends TestCase {
+ public void testChunkCreate() {
+ Chunk chunk;
+
+ chunk = new StringChunk(0x0200, 0x001E);
+ assertEquals("__substg1.0_0200001E", chunk.getEntryName());
+ assertEquals(0x0200, chunk.getChunkId());
+ assertEquals(0x001E, chunk.getType());
+
+ chunk = new StringChunk("__substg1.0_0200001E");
+ assertEquals("__substg1.0_0200001E", chunk.getEntryName());
+ assertEquals(0x0200, chunk.getChunkId());
+ assertEquals(0x001E, chunk.getType());
+
+ /* test the lower and upper limits of the chunk ids */
+ chunk = new StringChunk(0x0000, 0x001E);
+ assertEquals("__substg1.0_0000001E", chunk.getEntryName());
+
+ chunk = new StringChunk(0xFFFF, 0x001E);
+ assertEquals("__substg1.0_FFFF001E", chunk.getEntryName());
+
+ chunk = new StringChunk(0xFFFF, 0x001F);
+ assertEquals("__substg1.0_FFFF001F", chunk.getEntryName());
+ }
+
+ public void testTextBodyChunk() {
+ StringChunk chunk = new StringChunk(0x1000, Types.UNICODE_STRING);
+ assertEquals(chunk.getChunkId(), Chunks.TEXT_BODY);
+ }
+
+ public void testDisplayToChunk() {
+ StringChunk chunk = new StringChunk(0x0E04, Types.UNICODE_STRING);
+ assertEquals(chunk.getChunkId(), Chunks.DISPLAY_TO);
+ }
+
+
+ public void testDisplayCCChunk() {
+ StringChunk chunk = new StringChunk(0x0E03, Types.UNICODE_STRING);
+ assertEquals(chunk.getChunkId(), Chunks.DISPLAY_CC);
+ }
+
+ public void testDisplayBCCChunk() {
+ StringChunk chunk = new StringChunk(0x0E02, Types.UNICODE_STRING);
+ assertEquals(chunk.getChunkId(), Chunks.DISPLAY_BCC);
+ }
+
+ public void testSubjectChunk() {
+ Chunk chunk = new StringChunk(0x0037, Types.UNICODE_STRING);
+ assertEquals(chunk.getChunkId(), Chunks.SUBJECT);
+ }
+
+}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hsmf.datatypes;
+
+import org.apache.poi.hsmf.datatypes.Types;
+
+import junit.framework.TestCase;
+
+/**
+ * Verifies that the Types class is behaving properly.
+ * Also check that no changes have been made that will
+ * break the library.
+ */
+public final class TestTypes extends TestCase {
+ public void testTypeIds() {
+ assertEquals(0x1e, Types.ASCII_STRING);
+ assertEquals(0x1f, Types.UNICODE_STRING);
+
+ assertEquals(0x0102, Types.BINARY);
+ assertEquals(0x000B, Types.BOOLEAN);
+ assertEquals(0x0003, Types.LONG);
+ assertEquals(0x0040, Types.TIME);
+ }
+
+ public void testTypeFormatting() {
+ assertEquals("0000", Types.asFileEnding(0x0000));
+ assertEquals("0020", Types.asFileEnding(0x0020));
+ assertEquals("0102", Types.asFileEnding(0x0102));
+ assertEquals("FEDC", Types.asFileEnding(0xfedc));
+ }
+}
+++ /dev/null
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hsmf.model;
-
-import java.io.IOException;
-
-import org.apache.poi.hsmf.MAPIMessage;
-import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
-import org.apache.poi.POIDataSamples;
-
-import junit.framework.TestCase;
-
-
-/**
- * Tests to verify that the library can read blank msg files.
- *
- * @author Travis Ferguson
- *
- */
-public final class TestBlankFileRead extends TestCase {
- private MAPIMessage mapiMessage;
-
- /**
- * Initialize this test, load up the blank.msg mapi message.
- */
- public TestBlankFileRead() throws IOException {
- POIDataSamples samples = POIDataSamples.getHSMFInstance();
- this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("blank.msg"));
- }
-
- /**
- * Check if we can read the body of the blank message, we expect "".
- */
- public void testReadBody() {
- try {
- mapiMessage.getTextBody();
- } catch(ChunkNotFoundException exp) {
- return;
- }
-
- TestCase.fail("Should have thrown a ChunkNotFoundException but didn't");
- }
-
-
- /**
- * Test to see if we can read the CC Chunk.
- */
- public void testReadDisplayCC() throws ChunkNotFoundException {
- String obtained = mapiMessage.getDisplayCC();
- String expected = "";
-
- TestCase.assertEquals(expected, obtained);
- }
-
- /**
- * Test to see if we can read the CC Chunk.
- */
- public void testReadDisplayTo() throws ChunkNotFoundException {
- String obtained = mapiMessage.getDisplayTo();
- String expected = "";
-
- TestCase.assertEquals(expected, obtained);
- }
-
- /**
- * Test to see if we can read the FROM Chunk.
- */
- public void testReadDisplayFrom() {
- try {
- mapiMessage.getDisplayFrom();
- } catch(ChunkNotFoundException exp) {
- return;
- }
-
- TestCase.fail("Should have thrown a ChunkNotFoundException but didn't");
- }
-
- /**
- * Test to see if we can read the CC Chunk.
- */
- public void testReadDisplayBCC() throws ChunkNotFoundException {
- String obtained = mapiMessage.getDisplayBCC();
- String expected = "";
-
- TestCase.assertEquals(expected, obtained);
- }
-
-
- /**
- * Check if we can read the subject line of the blank message, we expect ""
- */
- public void testReadSubject() throws Exception {
- String obtained = mapiMessage.getSubject();
- TestCase.assertEquals("", obtained);
- }
-
-
- /**
- * Check if we can read the subject line of the blank message, we expect ""
- */
- public void testReadConversationTopic() {
- try {
- mapiMessage.getConversationTopic();
- } catch(ChunkNotFoundException exp) {
- return;
- }
- TestCase.fail("We shouldn't have a ConversationTopic node on the blank.msg file.");
- }
-
-
-}
+++ /dev/null
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hsmf.model;
-
-import org.apache.poi.hsmf.datatypes.Chunk;
-import org.apache.poi.hsmf.datatypes.Chunks;
-import org.apache.poi.hsmf.datatypes.StringChunk;
-import org.apache.poi.hsmf.datatypes.Types;
-
-import junit.framework.TestCase;
-
-/**
- * Verifies that the Chunks class is actually setup properly and hasn't been changed in ways
- * that will break the library.
- *
- * @author Travis Ferguson
- *
- */
-public final class TestChunkData extends TestCase {
- public void testChunkCreate() {
- Chunk chunk;
-
- chunk = new StringChunk(0x0200, 0x001E);
- assertEquals("__substg1.0_0200001E", chunk.getEntryName());
- assertEquals(0x0200, chunk.getChunkId());
- assertEquals(0x001E, chunk.getType());
-
- chunk = new StringChunk("__substg1.0_0200001E");
- assertEquals("__substg1.0_0200001E", chunk.getEntryName());
- assertEquals(0x0200, chunk.getChunkId());
- assertEquals(0x001E, chunk.getType());
-
- /* test the lower and upper limits of the chunk ids */
- chunk = new StringChunk(0x0000, 0x001E);
- assertEquals("__substg1.0_0000001E", chunk.getEntryName());
-
- chunk = new StringChunk(0xFFFF, 0x001E);
- assertEquals("__substg1.0_FFFF001E", chunk.getEntryName());
-
- chunk = new StringChunk(0xFFFF, 0x001F);
- assertEquals("__substg1.0_FFFF001F", chunk.getEntryName());
- }
-
- public void testTextBodyChunk() {
- StringChunk chunk = new StringChunk(0x1000, Types.UNICODE_STRING);
- assertEquals(chunk.getChunkId(), Chunks.TEXT_BODY);
- }
-
- public void testDisplayToChunk() {
- StringChunk chunk = new StringChunk(0x0E04, Types.UNICODE_STRING);
- assertEquals(chunk.getChunkId(), Chunks.DISPLAY_TO);
- }
-
-
- public void testDisplayCCChunk() {
- StringChunk chunk = new StringChunk(0x0E03, Types.UNICODE_STRING);
- assertEquals(chunk.getChunkId(), Chunks.DISPLAY_CC);
- }
-
- public void testDisplayBCCChunk() {
- StringChunk chunk = new StringChunk(0x0E02, Types.UNICODE_STRING);
- assertEquals(chunk.getChunkId(), Chunks.DISPLAY_BCC);
- }
-
- public void testSubjectChunk() {
- Chunk chunk = new StringChunk(0x0037, Types.UNICODE_STRING);
- assertEquals(chunk.getChunkId(), Chunks.SUBJECT);
- }
-
-}
+++ /dev/null
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hsmf.model;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.hsmf.MAPIMessage;
-import org.apache.poi.hsmf.datatypes.AttachmentChunks;
-import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
-import org.apache.poi.POIDataSamples;
-
-/**
- * Tests to verify that we can read attachments from msg file
- *
- * @author Nicolas Bureau
- */
-public class TestFileWithAttachmentsRead extends TestCase {
- private MAPIMessage mapiMessage;
-
- /**
- * Initialize this test, load up the attachment_test_msg.msg mapi message.
- *
- * @throws Exception
- */
- public TestFileWithAttachmentsRead() throws IOException {
- POIDataSamples samples = POIDataSamples.getHSMFInstance();
- this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("attachment_test_msg.msg"));
- }
-
- /**
- * Test to see if we can retrieve attachments.
- *
- * @throws ChunkNotFoundException
- *
- */
- // public void testReadDisplayCC() throws ChunkNotFoundException {
- public void testRetrieveAttachments() {
- AttachmentChunks[] attachments = mapiMessage.getAttachmentFiles();
- int obtained = attachments.length;
- int expected = 2;
-
- TestCase.assertEquals(obtained, expected);
- }
-
- /**
- * Test to see if attachments are not empty.
- *
- * @throws ChunkNotFoundException
- *
- */
- public void testReadAttachments() throws IOException {
- AttachmentChunks[] attachments = mapiMessage.getAttachmentFiles();
-
- for (AttachmentChunks attachment : attachments) {
- assertTrue(attachment.attachFileName.getValue().length() > 0);
- assertTrue(attachment.attachLongFileName.getValue().length() > 0);
- assertTrue(attachment.attachExtension.getValue().length() > 0);
- assertTrue(attachment.attachMimeTag.getValue().length() > 0);
- }
-
- // TODO better checking
- }
-
-}
+++ /dev/null
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hsmf.model;
-
-import java.io.IOException;
-
-import org.apache.poi.hsmf.MAPIMessage;
-import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
-import org.apache.poi.POIDataSamples;
-
-import junit.framework.TestCase;
-
-/**
- * Tests to verify that we can still work on the newer Outlook 3.0 files.
- */
-public final class TestOutlook30FileRead extends TestCase {
-private MAPIMessage mapiMessage;
-
- /**
- * Initialize this test, load up the blank.msg mapi message.
- * @throws Exception
- */
- public TestOutlook30FileRead() throws IOException {
- POIDataSamples samples = POIDataSamples.getHSMFInstance();
- this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("outlook_30_msg.msg"));
- }
-
- /**
- * Test to see if we can read the CC Chunk.
- * @throws ChunkNotFoundException
- *
- */
- public void testReadDisplayCC() throws ChunkNotFoundException {
- String obtained = mapiMessage.getDisplayCC();
- String expected = "";
-
- TestCase.assertEquals(obtained, expected);
- }
-
- /**
- * Test to see if we can read the CC Chunk.
- * @throws ChunkNotFoundException
- *
- */
- public void testReadDisplayTo() throws ChunkNotFoundException {
- String obtained = mapiMessage.getDisplayTo();
-
- assertTrue(obtained.startsWith("Bohn, Shawn"));
- }
-
- /**
- * Test to see if we can read the From Chunk.
- * @throws ChunkNotFoundException
- *
- */
- public void testReadDisplayFrom() throws ChunkNotFoundException {
- String obtained = mapiMessage.getDisplayFrom();
- String expected = "Cramer, Nick";
-
- TestCase.assertEquals(obtained, expected);
- }
-
- /**
- * Test to see if we can read the CC Chunk.
- * @throws ChunkNotFoundException
- *
- */
- public void testReadDisplayBCC() throws ChunkNotFoundException {
- String obtained = mapiMessage.getDisplayBCC();
- String expected = "";
-
- TestCase.assertEquals(obtained, expected);
- }
-
-
- /**
- * Check if we can read the body of the blank message, we expect "".
- *
- * @throws Exception
- */
- public void testReadBody() throws Exception {
- String obtained = mapiMessage.getTextBody();
- assertTrue(obtained.startsWith("I am shutting down"));
- }
-
- /**
- * Check if we can read the subject line of the blank message, we expect ""
- *
- * @throws Exception
- */
- public void testReadSubject() throws Exception {
- String obtained = mapiMessage.getSubject();
- String expected = "IN-SPIRE servers going down for a bit, back up around 8am";
-
- TestCase.assertEquals(expected, obtained);
- }
-
- /**
- * Check if we can read the subject line of the blank message, we expect ""
- *
- * @throws Exception
- */
- public void testReadConversationTopic() throws Exception {
- String obtained = mapiMessage.getConversationTopic();
- TestCase.assertEquals("IN-SPIRE servers going down for a bit, back up around 8am", obtained);
- }
-
-
- /**
- * Check if we can read the subject line of the blank message, we expect ""
- *
- * @throws Exception
- */
- public void testReadMessageClass() throws Exception {
- String obtained = mapiMessage.getMessageClass();
- TestCase.assertEquals("IPM.Note", obtained);
- }
-
-
-
-}
+++ /dev/null
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hsmf.model;
-
-import java.io.IOException;
-
-import org.apache.poi.hsmf.MAPIMessage;
-import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
-import org.apache.poi.POIDataSamples;
-
-import junit.framework.TestCase;
-
-/**
- * Tests to verify that we can read a simple msg file, that is in plain/text format with no attachments
- * or extra recipents.
- *
- * @author Travis Ferguson
- */
-public final class TestSimpleFileRead extends TestCase {
-private MAPIMessage mapiMessage;
-
- /**
- * Initialize this test, load up the blank.msg mapi message.
- * @throws Exception
- */
- public TestSimpleFileRead() throws IOException {
- POIDataSamples samples = POIDataSamples.getHSMFInstance();
- this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("simple_test_msg.msg"));
- }
-
- /**
- * Test to see if we can read the CC Chunk.
- * @throws ChunkNotFoundException
- *
- */
- public void testReadDisplayCC() throws ChunkNotFoundException {
- String obtained = mapiMessage.getDisplayCC();
- String expected = "";
-
- TestCase.assertEquals(obtained, expected);
- }
-
- /**
- * Test to see if we can read the CC Chunk.
- * @throws ChunkNotFoundException
- *
- */
- public void testReadDisplayTo() throws ChunkNotFoundException {
- String obtained = mapiMessage.getDisplayTo();
- String expected = "travis@overwrittenstack.com";
-
- TestCase.assertEquals(obtained, expected);
- }
-
- /**
- * Test to see if we can read the From Chunk.
- * @throws ChunkNotFoundException
- *
- */
- public void testReadDisplayFrom() throws ChunkNotFoundException {
- String obtained = mapiMessage.getDisplayFrom();
- String expected = "Travis Ferguson";
-
- TestCase.assertEquals(obtained, expected);
- }
-
- /**
- * Test to see if we can read the CC Chunk.
- * @throws ChunkNotFoundException
- *
- */
- public void testReadDisplayBCC() throws ChunkNotFoundException {
- String obtained = mapiMessage.getDisplayBCC();
- String expected = "";
-
- TestCase.assertEquals(obtained, expected);
- }
-
-
- /**
- * Check if we can read the body of the blank message, we expect "".
- *
- * @throws Exception
- */
- public void testReadBody() throws Exception {
- String obtained = mapiMessage.getTextBody();
- String expected = "This is a test message.";
-
- TestCase.assertEquals(obtained, expected);
- }
-
- /**
- * Check if we can read the subject line of the blank message, we expect ""
- *
- * @throws Exception
- */
- public void testReadSubject() throws Exception {
- String obtained = mapiMessage.getSubject();
- String expected = "test message";
-
- TestCase.assertEquals(expected, obtained);
- }
-
- /**
- * Check if we can read the subject line of the blank message, we expect ""
- *
- * @throws Exception
- */
- public void testReadConversationTopic() throws Exception {
- String obtained = mapiMessage.getConversationTopic();
- TestCase.assertEquals("test message", obtained);
- }
-
-
- /**
- * Check if we can read the subject line of the blank message, we expect ""
- *
- * @throws Exception
- */
- public void testReadMessageClass() throws Exception {
- String obtained = mapiMessage.getMessageClass();
- TestCase.assertEquals("IPM.Note", obtained);
- }
-
-
-
-}
+++ /dev/null
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hsmf.model;
-
-import org.apache.poi.hsmf.datatypes.Types;
-
-import junit.framework.TestCase;
-
-/**
- * Verifies that the Types class is behaving properly.
- * Also check that no changes have been made that will
- * break the library.
- */
-public final class TestTypes extends TestCase {
- public void testTypeIds() {
- assertEquals(0x1e, Types.ASCII_STRING);
- assertEquals(0x1f, Types.UNICODE_STRING);
-
- assertEquals(0x0102, Types.BINARY);
- assertEquals(0x000B, Types.BOOLEAN);
- assertEquals(0x0003, Types.LONG);
- assertEquals(0x0040, Types.TIME);
- }
-
- public void testTypeFormatting() {
- assertEquals("0000", Types.asFileEnding(0x0000));
- assertEquals("0020", Types.asFileEnding(0x0020));
- assertEquals("0102", Types.asFileEnding(0x0102));
- assertEquals("FEDC", Types.asFileEnding(0xfedc));
- }
-}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hsmf.parsers;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.POIDataSamples;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests to verify that the chunk parser works properly
+ */
+public final class TestPOIFSChunkParser extends TestCase {
+ private POIDataSamples samples;
+
+ public TestPOIFSChunkParser() throws IOException {
+ samples = POIDataSamples.getHSMFInstance();
+ }
+
+ public void testFindsRecips() throws IOException {
+
+ }
+
+ public void testFindsAttachments() throws IOException {
+ POIFSFileSystem with = new POIFSFileSystem(
+ new FileInputStream(samples.getFile("attachment_test_msg.msg"))
+ );
+ POIFSFileSystem without = new POIFSFileSystem(
+ new FileInputStream(samples.getFile("simple_test_msg.msg"))
+ );
+
+ // Check details on the one with
+
+ // One with, from the top
+
+ // One without, from the top
+ }
+}