]> source.dussan.org Git - poi.git/commitdiff
Patch from bug #44055 - support reading the from field from HSMF messages
authorNick Burch <nick@apache.org>
Fri, 21 Dec 2007 12:16:54 +0000 (12:16 +0000)
committerNick Burch <nick@apache.org>
Fri, 21 Dec 2007 12:16:54 +0000 (12:16 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@606169 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java
src/scratchpad/testcases/org/apache/poi/hsmf/model/TestBlankFileRead.java
src/scratchpad/testcases/org/apache/poi/hsmf/model/TestSimpleFileRead.java

index d0364a01c620cc21a0fcb996ac6495ae29abd013..21f1187d19dea4360d90c2f913373dd8ab1be2e8 100644 (file)
@@ -36,6 +36,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.0.2-FINAL" date="2007-??-??">
+            <action dev="POI-DEVELOPERS" type="add">44055 - [PATCH] Support for getting the from field from HSMF messages</action>
             <action dev="POI-DEVELOPERS" type="add">43551 - [PATCH] Support for 1904 date windowing in HSSF (previously only supported 1900 date windowing)</action>
             <action dev="POI-DEVELOPERS" type="add">41064 - [PATCH] Support for String continue records</action>
             <action dev="POI-DEVELOPERS" type="add">27511 - [PATCH] Support for data validation, via DVRecord and DVALRecord</action>
index 37beccd250239ef4efe0cd2428cfb0213c6bc84e..b40122763e3874e5f781f9764c225f04e83d7930 100644 (file)
@@ -33,6 +33,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.0.2-FINAL" date="2007-??-??">
+            <action dev="POI-DEVELOPERS" type="add">44055 - [PATCH] Support for getting the from field from HSMF messages</action>
             <action dev="POI-DEVELOPERS" type="add">43551 - [PATCH] Support for 1904 date windowing in HSSF (previously only supported 1900 date windowing)</action>
             <action dev="POI-DEVELOPERS" type="add">41064 - [PATCH] Support for String continue records</action>
             <action dev="POI-DEVELOPERS" type="add">27511 - [PATCH] Support for data validation, via DVRecord and DVALRecord</action>
index ed215f6382569ce047d9695ac5655c8d558df023..eb915160b35d7b546eecb67b14b7a2ebdcfc9823 100644 (file)
@@ -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.
index 309efeac9db499d5bd88f612a1af18dd4a93dca4..6a3936d964c8e6662c6509d38bf15987b255442c 100644 (file)
@@ -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.
index 05735870b4ecf5a0267cb6ae4ac2b8f6a65ccca2..314cc506c4c1ef6c727012ded3852a0eb6083e30 100644 (file)
@@ -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 
index 0ede68965a8cd45fddbfb32212d4491c5afb1a6c..925685218d5d98662fab0487a384fd277efaf472 100644 (file)
@@ -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