poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1694255 - in /poi/trunk/src: scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java scratchpad/testcases/org/apache/poi/hsmf/extractor/TestOutlookTextExtractor.java testcases/org/apache/poi/POITestCase.java
Date Wed, 05 Aug 2015 15:58:43 GMT
Author: nick
Date: Wed Aug  5 15:58:43 2015
New Revision: 1694255

URL: http://svn.apache.org/r1694255
Log:
NPE fix for text extraction from MSG files with only a short name

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/extractor/TestOutlookTextExtractor.java
    poi/trunk/src/testcases/org/apache/poi/POITestCase.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java?rev=1694255&r1=1694254&r2=1694255&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java Wed
Aug  5 15:58:43 2015
@@ -25,6 +25,7 @@ import java.util.TimeZone;
 import org.apache.poi.POIOLE2TextExtractor;
 import org.apache.poi.hsmf.MAPIMessage;
 import org.apache.poi.hsmf.datatypes.AttachmentChunks;
+import org.apache.poi.hsmf.datatypes.StringChunk;
 import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
@@ -65,6 +66,7 @@ public class OutlookTextExtactor extends
                new NPOIFSFileSystem(new File(filename))
          );
          System.out.println( extractor.getText() );
+         extractor.close();
       }
    }
 
@@ -146,12 +148,15 @@ public class OutlookTextExtactor extends
       // Display attachment names
       // To get the attachments, use ExtractorFactory
       for(AttachmentChunks att : msg.getAttachmentFiles()) {
-         String ats = att.attachLongFileName.getValue();
+         StringChunk name = att.attachLongFileName;
+         if (name == null) name = att.attachFileName;
+         String attName = name.getValue();
+          
          if(att.attachMimeTag != null && 
                att.attachMimeTag.getValue() != null) {
-            ats = att.attachMimeTag.getValue() + " = " + ats; 
+             attName = att.attachMimeTag.getValue() + " = " + attName; 
          }
-         s.append("Attachment: " + ats + "\n");
+         s.append("Attachment: " + attName + "\n");
       }
       
       try {

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/extractor/TestOutlookTextExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/extractor/TestOutlookTextExtractor.java?rev=1694255&r1=1694254&r2=1694255&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/extractor/TestOutlookTextExtractor.java
(original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/extractor/TestOutlookTextExtractor.java
Wed Aug  5 15:58:43 2015
@@ -209,6 +209,25 @@ public final class TestOutlookTextExtrac
       ext.close();
    }
    
+   public void testWithAttachedMessage() throws Exception {
+       POIFSFileSystem simple = new POIFSFileSystem(
+               new FileInputStream(samples.getFile("58214_with_attachment.msg"))
+         );
+         MAPIMessage msg = new MAPIMessage(simple);
+         OutlookTextExtactor ext = new OutlookTextExtactor(msg);
+         String text = ext.getText();
+         
+         // Check we got bits from the main message
+         assertContains(text, "Master mail");
+         assertContains(text, "ante in lacinia euismod");
+         
+         // But not the attached message
+         assertNotContained(text, "Test mail attachment");
+         assertNotContained(text, "Lorem ipsum dolor sit");
+         
+         ext.close();
+   }
+   
    public void testEncodings() throws Exception {
       POIFSFileSystem simple = new POIFSFileSystem(
             new FileInputStream(samples.getFile("chinese-traditional.msg"))

Modified: poi/trunk/src/testcases/org/apache/poi/POITestCase.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/POITestCase.java?rev=1694255&r1=1694254&r2=1694255&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/POITestCase.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/POITestCase.java Wed Aug  5 15:58:43 2015
@@ -33,6 +33,12 @@ public class POITestCase extends TestCas
               haystack.contains(needle)
         );
      }
+    public static void assertNotContained(String haystack, String needle) {
+        assertFalse(
+              "Unexpectedly found text '" + needle + "' in text:\n" + haystack,
+              haystack.contains(needle)
+        );
+     }
     
     public static <T> void assertEquals(T[] expected, T[] actual)
     {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message