From dae37b8632b449b330c6f1c6504014c17369adc6 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Fri, 21 Dec 2007 12:16:54 +0000 Subject: [PATCH] Patch from bug #44055 - support reading the from field from HSMF messages git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@606169 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/changes.xml | 1 + src/documentation/content/xdocs/status.xml | 1 + .../src/org/apache/poi/hsmf/MAPIMessage.java | 23 +++++++++++++++++-- .../org/apache/poi/hsmf/datatypes/Chunks.java | 1 + .../poi/hsmf/model/TestBlankFileRead.java | 15 ++++++++++++ .../poi/hsmf/model/TestSimpleFileRead.java | 12 ++++++++++ 6 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index d0364a01c6..21f1187d19 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -36,6 +36,7 @@ + 44055 - [PATCH] Support for getting the from field from HSMF messages 43551 - [PATCH] Support for 1904 date windowing in HSSF (previously only supported 1900 date windowing) 41064 - [PATCH] Support for String continue records 27511 - [PATCH] Support for data validation, via DVRecord and DVALRecord diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 37beccd250..b40122763e 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -33,6 +33,7 @@ + 44055 - [PATCH] Support for getting the from field from HSMF messages 43551 - [PATCH] Support for 1904 date windowing in HSSF (previously only supported 1900 date windowing) 41064 - [PATCH] Support for String continue records 27511 - [PATCH] Support for data validation, via DVRecord and DVALRecord diff --git a/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java b/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java index ed215f6382..eb915160b3 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java @@ -48,15 +48,24 @@ public class MAPIMessage { /** - * Constructor for reading MSG Files. + * Constructor for reading MSG Files from the file system. * @param filename * @throws IOException */ public MAPIMessage(String filename) throws IOException { - InputStream in = new FileInputStream(new File(filename)); + this(new FileInputStream(new File(filename))); + } + + /** + * Constructor for reading MSG Files from an input stream. + * @param in + * @throws IOException + */ + public MAPIMessage(InputStream in) throws IOException { this.fs = new POIFSFileSystem(in); chunkParser = new POIFSChunkParser(this.fs); } + /** * Gets a string value based on the passed chunk. @@ -101,6 +110,16 @@ public class MAPIMessage { return getStringFromChunk(Chunks.getInstance().displayToChunk); } + /** + * Gets the display value of the "FROM" line of the outlook message + * This is not the actual address that was sent from but the formated display of the user name. + * @return + * @throws ChunkNotFoundException + */ + public String getDisplayFrom() throws ChunkNotFoundException { + return getStringFromChunk(Chunks.getInstance().displayFromChunk); + } + /** * Gets the display value of the "TO" line of the outlook message * This is not the actual list of addresses/values that will be sent to if you click Reply in the email. diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java index 309efeac9d..6a3936d964 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java @@ -29,6 +29,7 @@ public class Chunks { public StringChunk textBodyChunk = new StringChunk(0x1000); //BODY Chunk, for plain/text messages public StringChunk subjectChunk = new StringChunk(0x0037); //Subject link chunk, in plain/text public StringChunk displayToChunk = new StringChunk(0x0E04); //Value that is in the TO field (not actually the addresses as they are stored in recip directory nodes + public StringChunk displayFromChunk = new StringChunk(0x0C1A); //Value that is in the FROM field public StringChunk displayCCChunk = new StringChunk(0x0E03); //value that shows in the CC field public StringChunk displayBCCChunk = new StringChunk(0x0E02); //Value that shows in the BCC field public StringChunk conversationTopic = new StringChunk(0x0070); //Sort of like the subject line, but without the RE: and FWD: parts. diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestBlankFileRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestBlankFileRead.java index 05735870b4..314cc506c4 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestBlankFileRead.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestBlankFileRead.java @@ -83,6 +83,21 @@ public class TestBlankFileRead extends TestCase { TestCase.assertEquals(obtained, expected); } + /** + * Test to see if we can read the FROM Chunk. + * @throws ChunkNotFoundException + * + */ + public void testReadDisplayFrom() throws ChunkNotFoundException { + 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. * @throws ChunkNotFoundException diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestSimpleFileRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestSimpleFileRead.java index 0ede68965a..925685218d 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestSimpleFileRead.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestSimpleFileRead.java @@ -66,6 +66,18 @@ private MAPIMessage mapiMessage; 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