From: Nick Burch Date: Mon, 4 Jul 2016 22:41:46 +0000 (+0000) Subject: Fix HMEFMessage to allow fetching attributes by custom MAPI Properties X-Git-Tag: REL_3_15_BETA3~189 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=815309d3bf97efdcb76dddaf5667fb3d69f17f9e;p=poi.git Fix HMEFMessage to allow fetching attributes by custom MAPI Properties git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751385 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hmef/HMEFMessage.java b/src/scratchpad/src/org/apache/poi/hmef/HMEFMessage.java index 840de3e1e2..5dd7a827f5 100644 --- a/src/scratchpad/src/org/apache/poi/hmef/HMEFMessage.java +++ b/src/scratchpad/src/org/apache/poi/hmef/HMEFMessage.java @@ -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; } } diff --git a/src/scratchpad/testcases/org/apache/poi/hmef/TestHMEFMessage.java b/src/scratchpad/testcases/org/apache/poi/hmef/TestHMEFMessage.java index d9344b1bda..25f0d07be3 100644 --- a/src/scratchpad/testcases/org/apache/poi/hmef/TestHMEFMessage.java +++ b/src/scratchpad/testcases/org/apache/poi/hmef/TestHMEFMessage.java @@ -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) + ); + } }