You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2011/04/01 17:20:07 UTC

svn commit: r1087746 - in /poi/trunk/src: documentation/content/xdocs/status.xml scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java

Author: nick
Date: Fri Apr  1 15:20:07 2011
New Revision: 1087746

URL: http://svn.apache.org/viewvc?rev=1087746&view=rev
Log:
Add new method to HSMF of MAPIMessage.has7BitEncodingStrings() to make it easier to decide when encoding guessing is needed

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1087746&r1=1087745&r2=1087746&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Fri Apr  1 15:20:07 2011
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta3" date="2011-??-??">
+           <action dev="poi-developers" type="add">Add new method to HSMF of MAPIMessage.has7BitEncodingStrings() to make it easier to decide when encoding guessing is needed</action>
            <action dev="poi-developers" type="fix">OutlookTextExtractor now requests 7 bit encoding guessing</action>
            <action dev="poi-developers" type="add">Improve HSMF encoding guessing for 7 bit fields in MAPIMessage</action>
            <action dev="poi-developers" type="add">Allow HSMF access to the HTML body contents in MAPIMessage</action>

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java?rev=1087746&r1=1087745&r2=1087746&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java Fri Apr  1 15:20:07 2011
@@ -36,6 +36,7 @@ import org.apache.poi.hsmf.datatypes.Chu
 import org.apache.poi.hsmf.datatypes.Chunks;
 import org.apache.poi.hsmf.datatypes.NameIdChunks;
 import org.apache.poi.hsmf.datatypes.RecipientChunks;
+import org.apache.poi.hsmf.datatypes.Types;
 import org.apache.poi.hsmf.datatypes.RecipientChunks.RecipientChunksSorter;
 import org.apache.poi.hsmf.datatypes.StringChunk;
 import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
@@ -397,6 +398,37 @@ public class MAPIMessage extends POIDocu
    }
    
    /**
+    * Does this file contain any strings that
+    *  are stored as 7 bit rather than unicode?
+    */
+   public boolean has7BitEncodingStrings() {
+      for(Chunk c : mainChunks.getAll()) {
+         if(c instanceof StringChunk) {
+            if( ((StringChunk)c).getType() == Types.ASCII_STRING ) {
+               return true;
+            }
+         }
+      }
+      for(Chunk c : nameIdChunks.getAll()) {
+         if(c instanceof StringChunk) {
+            if( ((StringChunk)c).getType() == Types.ASCII_STRING ) {
+               return true;
+            }
+         }
+      }
+      for(RecipientChunks rc : recipientChunks) {
+         for(Chunk c : rc.getAll()) {
+            if(c instanceof StringChunk) {
+               if( ((StringChunk)c).getType() == Types.ASCII_STRING ) {
+                  return true;
+               }
+            }
+         }
+      }
+      return false;
+   }
+   
+   /**
     * Returns all the headers, one entry per line
     */
    public String[] getHeaders() throws ChunkNotFoundException {

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java?rev=1087746&r1=1087745&r2=1087746&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java Fri Apr  1 15:20:07 2011
@@ -34,6 +34,7 @@ public final class TestBasics extends Te
    private MAPIMessage outlook30;
    private MAPIMessage attachments;
    private MAPIMessage noRecipientAddress;
+   private MAPIMessage unicode;
    private MAPIMessage cyrillic;
    private MAPIMessage chinese;
 
@@ -48,6 +49,7 @@ public final class TestBasics extends Te
       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"));
+      unicode = new MAPIMessage(samples.openResourceAsStream("example_received_unicode.msg"));
       cyrillic = new MAPIMessage(samples.openResourceAsStream("cyrillic_message.msg"));
       chinese = new MAPIMessage(samples.openResourceAsStream("chinese-traditional.msg"));
 	}
@@ -182,6 +184,16 @@ public final class TestBasics extends Te
       noRecipientAddress.setReturnNullOnMissingChunk(false);
 	}
 	
+	/**
+	 * Test the 7 bit detection
+	 */
+	public void test7BitDetection() throws Exception {
+	   assertEquals(false, unicode.has7BitEncodingStrings());
+      assertEquals(true, simple.has7BitEncodingStrings());
+      assertEquals(true, chinese.has7BitEncodingStrings());
+      assertEquals(true, cyrillic.has7BitEncodingStrings());
+	}
+	
    /**
     * We default to CP1252, but can sometimes do better
     *  if needed.



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