]> source.dussan.org Git - poi.git/commitdiff
Better handling of Outlook messages in HSMF when there's no recipient email address
authorNick Burch <nick@apache.org>
Mon, 14 Jun 2010 13:47:22 +0000 (13:47 +0000)
committerNick Burch <nick@apache.org>
Mon, 14 Jun 2010 13:47:22 +0000 (13:47 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@954476 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java
test-data/hsmf/no_recipient_address.msg [new file with mode: 0644]

index 71f08391563429b0ccc8c2bdda7f0efd57ad393a..0529403be2a503e37dfde18bbe7446c5f9f630bb 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-beta2" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">Better handling of Outlook messages in HSMF when there's no recipient email address</action>
            <action dev="POI-DEVELOPERS" type="fix">When formatting numbers with DataFormatter, handle brackets following colours</action>
         </release>
         <release version="3.7-beta1" date="2010-06-16">
index 8d84b1627a4ea3c9d08440901530643245e55033..e04d299b136e944ef459edaf6c5e3d968166ee38 100644 (file)
@@ -239,7 +239,11 @@ public class MAPIMessage extends POIDocument {
          if(email != null) {
             emails[i] = email;
          } else {
-            throw new ChunkNotFoundException("No email address holding chunks found for the " + (i+1) + "th recipient");
+            if(returnNullOnMissingChunk) {
+               emails[i] = null;
+            } else {
+               throw new ChunkNotFoundException("No email address holding chunks found for the " + (i+1) + "th recipient");
+            }
          }
       }
 
@@ -393,6 +397,7 @@ public class MAPIMessage extends POIDocument {
       boolean first = true;
 
       for(String s : l) {
+         if(s == null) continue;
          if(first) {
             first = false;
          } else {
index 6e958c193f6609a8cd9c42a331c7858a7cdccec3..18a316491f929854576d177b6cf117f610d1c59f 100644 (file)
@@ -33,6 +33,7 @@ public final class TestBasics extends TestCase {
    private MAPIMessage quick;
    private MAPIMessage outlook30;
    private MAPIMessage attachments;
+   private MAPIMessage noRecipientAddress;
 
        /**
         * Initialize this test, load up the blank.msg mapi message.
@@ -44,6 +45,7 @@ public final class TestBasics extends TestCase {
       quick  = new MAPIMessage(samples.openResourceAsStream("quick.msg"));
       outlook30  = new MAPIMessage(samples.openResourceAsStream("outlook_30_msg.msg"));
       attachments = new MAPIMessage(samples.openResourceAsStream("attachment_test_msg.msg"));
+      noRecipientAddress = new MAPIMessage(samples.openResourceAsStream("no_recipient_address.msg"));
        }
        
        /**
@@ -140,4 +142,39 @@ public final class TestBasics extends TestCase {
          // Good
       }
        }
+       
+       /**
+        * More missing chunk testing, this time for
+        *  missing recipient email address
+        */
+       public void testMissingAddressChunk() throws Exception {
+      assertEquals(false, noRecipientAddress.isReturnNullOnMissingChunk());
+
+      try {
+         noRecipientAddress.getRecipientEmailAddress();
+         fail();
+      } catch(ChunkNotFoundException e) {
+         // Good
+      }
+      try {
+         noRecipientAddress.getRecipientEmailAddressList();
+         fail();
+      } catch(ChunkNotFoundException e) {
+         // Good
+      }
+      
+      noRecipientAddress.setReturnNullOnMissingChunk(true);
+      
+      noRecipientAddress.getRecipientEmailAddress();
+      noRecipientAddress.getRecipientEmailAddressList();
+      assertEquals("", noRecipientAddress.getRecipientEmailAddress());
+      assertEquals(1, noRecipientAddress.getRecipientEmailAddressList().length);
+      assertEquals(null, noRecipientAddress.getRecipientEmailAddressList()[0]);
+      
+      // Check a few other bits too
+      assertEquals("Microsoft Outlook 2003 Team", noRecipientAddress.getDisplayFrom());
+      assertEquals("New Outlook User", noRecipientAddress.getDisplayTo());
+      
+      noRecipientAddress.setReturnNullOnMissingChunk(false);
+       }
 }
diff --git a/test-data/hsmf/no_recipient_address.msg b/test-data/hsmf/no_recipient_address.msg
new file mode 100644 (file)
index 0000000..e88d503
Binary files /dev/null and b/test-data/hsmf/no_recipient_address.msg differ