Author: nick
Date: Wed Jun 26 17:03:26 2013
New Revision: 1497006

URL: http://svn.apache.org/r1497006
Log:
Make the fixed sized properties parser more flexible in the face of slightly 
duff data

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
    
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java

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=1497006&r1=1497005&r2=1497006&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 Wed Jun 
26 17:03:26 2013
@@ -364,6 +364,9 @@ public class MAPIMessage extends POIDocu
     *  tries to use these to guess the correct encoding for
     *  your file.
     * Bug #49441 has more on why this is needed
+    * 
+    * TODO Try to also use PR_MESSAGE_CODEPAGE and PR_INTERNET_CPID
+    * Would need to refactor some of the codepage support in HPSF first
     */
    public void guess7BitEncoding() {
       try {

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java?rev=1497006&r1=1497005&r2=1497006&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java 
(original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java 
Wed Jun 26 17:03:26 2013
@@ -146,11 +146,36 @@ public abstract class PropertiesChunk ex
             // Turn the Type and ID into helper objects
             MAPIType type = Types.getById(typeID);
             MAPIProperty prop = MAPIProperty.get(id);
+            
+            // Wrap properties we don't know about as custom ones
+            if (prop == MAPIProperty.UNKNOWN) {
+                prop = MAPIProperty.createCustom(id, type, "Unknown " + id);
+            }
+            if (type == null) {
+                logger.log(POILogger.WARN, "Invalid type found, expected ", 
prop.usualType, 
+                        " but got ", typeID, " for property ", prop);
+                going = false;
+                break;
+            }
+            
+            // Sanity check the property's type against the value's type
             if (prop.usualType != type) {
-               // Oh dear, something has gone wrong...
-               logger.log(POILogger.WARN, "Type mismatch, expected ", type, " 
but got ", prop.usualType);
-               going = false;
-               break;
+                // Is it an allowed substitution?
+                if (type == Types.ASCII_STRING && prop.usualType == 
Types.UNICODE_STRING ||
+                    type == Types.UNICODE_STRING && prop.usualType == 
Types.ASCII_STRING) {
+                    // It's fine to go with the specified instead of the normal
+                } else if (prop.usualType == Types.UNKNOWN) {
+                    // We don't know what this property normally is, but it 
has come
+                    // through with a valid type, so use that
+                    logger.log(POILogger.INFO, "Property definition for ", 
prop, 
+                            " is missing a type definition, found a value with 
type ", type);
+                } else {
+                   // Oh dear, something has gone wrong...
+                   logger.log(POILogger.WARN, "Type mismatch, expected ", 
prop.usualType, 
+                              " but got ", type, " for property ", prop);
+                   going = false;
+                   break;
+                }
             }
             
             // Work out how long the "data" is



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to