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 2016/07/04 22:41:46 UTC

svn commit: r1751385 - in /poi/trunk/src/scratchpad: src/org/apache/poi/hmef/HMEFMessage.java testcases/org/apache/poi/hmef/TestHMEFMessage.java

Author: nick
Date: Mon Jul  4 22:41:46 2016
New Revision: 1751385

URL: http://svn.apache.org/viewvc?rev=1751385&view=rev
Log:
Fix HMEFMessage to allow fetching attributes by custom MAPI Properties

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hmef/HMEFMessage.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hmef/TestHMEFMessage.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hmef/HMEFMessage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hmef/HMEFMessage.java?rev=1751385&r1=1751384&r2=1751385&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hmef/HMEFMessage.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hmef/HMEFMessage.java Mon Jul  4 22:41:46 2016
@@ -165,7 +165,8 @@ public final class HMEFMessage {
      */
     public MAPIAttribute getMessageMAPIAttribute(MAPIProperty id) {
         for (MAPIAttribute attr : mapiAttributes) {
-            if (attr.getProperty() == id) {
+            // Because of custom properties, match on ID not literal property object
+            if (attr.getProperty().id == id.id) {
                 return attr;
             }
         }

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hmef/TestHMEFMessage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hmef/TestHMEFMessage.java?rev=1751385&r1=1751384&r2=1751385&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hmef/TestHMEFMessage.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hmef/TestHMEFMessage.java Mon Jul  4 22:41:46 2016
@@ -21,9 +21,12 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 
+import org.apache.poi.hmef.attribute.MAPIAttribute;
 import org.apache.poi.hmef.attribute.MAPIRtfAttribute;
+import org.apache.poi.hmef.attribute.MAPIStringAttribute;
 import org.apache.poi.hmef.attribute.TNEFProperty;
 import org.apache.poi.hsmf.datatypes.MAPIProperty;
+import org.apache.poi.hsmf.datatypes.Types;
 import org.apache.poi.util.LittleEndian;
 
 public final class TestHMEFMessage extends HMEFTest {
@@ -198,5 +201,33 @@ public final class TestHMEFMessage exten
 		   assertTrue(e.getMessage().contains("Unhandled level 90"));
 	   }
    }
+   
+   public void testCustomProperty() throws Exception {
+       HMEFMessage msg = new HMEFMessage(
+               _samples.openResourceAsStream("quick-winmail.dat")
+       );
+       
+       // Should have non-standard properties with IDs 0xE28 and 0xE29
+       boolean hasE28 = false;
+       boolean hasE29 = false;
+       for (MAPIAttribute attr : msg.getMessageMAPIAttributes()) {
+           if (attr.getProperty().id == 0xe28) hasE28 = true;
+           if (attr.getProperty().id == 0xe29) hasE29 = true;
+       }
+       assertEquals(true, hasE28);
+       assertEquals(true, hasE29);
+       
+       // Ensure we can fetch those as custom ones
+       MAPIProperty propE28 = MAPIProperty.createCustom(0xe28, Types.ASCII_STRING, "Custom E28");
+       MAPIProperty propE29 = MAPIProperty.createCustom(0xe29, Types.ASCII_STRING, "Custom E29");
+       assertNotNull(msg.getMessageMAPIAttribute(propE28));
+       assertNotNull(msg.getMessageMAPIAttribute(propE29));
+       
+       assertEquals(MAPIStringAttribute.class, msg.getMessageMAPIAttribute(propE28).getClass());
+       assertEquals(
+            "Zimbra - Mark Rogers", 
+            ((MAPIStringAttribute)msg.getMessageMAPIAttribute(propE28)).getDataString().substring(10)
+       );
+   }
 }
 



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