]> source.dussan.org Git - poi.git/commitdiff
Fix HMEFMessage to allow fetching attributes by custom MAPI Properties
authorNick Burch <nick@apache.org>
Mon, 4 Jul 2016 22:41:46 +0000 (22:41 +0000)
committerNick Burch <nick@apache.org>
Mon, 4 Jul 2016 22:41:46 +0000 (22:41 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751385 13f79535-47bb-0310-9956-ffa450edef68

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

index 840de3e1e26d5a1a3de6343a594549c11c9cc9f8..5dd7a827f537d46f94989717b508014148fe2cc8 100644 (file)
@@ -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;
             }
         }
index d9344b1bdaafb61c0b9c13b9eebe7107882c74d4..25f0d07be3d8e4edffe1e58dafc0800bf46852f3 100644 (file)
@@ -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 extends HMEFTest {
                   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)
+       );
+   }
 }