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
This commit is contained in:
parent
90e4babfc1
commit
28c437531e
@ -165,7 +165,8 @@ public final class HMEFMessage {
|
|||||||
*/
|
*/
|
||||||
public MAPIAttribute getMessageMAPIAttribute(MAPIProperty id) {
|
public MAPIAttribute getMessageMAPIAttribute(MAPIProperty id) {
|
||||||
for (MAPIAttribute attr : mapiAttributes) {
|
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;
|
return attr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,12 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import org.apache.poi.hmef.attribute.MAPIAttribute;
|
||||||
import org.apache.poi.hmef.attribute.MAPIRtfAttribute;
|
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.hmef.attribute.TNEFProperty;
|
||||||
import org.apache.poi.hsmf.datatypes.MAPIProperty;
|
import org.apache.poi.hsmf.datatypes.MAPIProperty;
|
||||||
|
import org.apache.poi.hsmf.datatypes.Types;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
|
||||||
public final class TestHMEFMessage extends HMEFTest {
|
public final class TestHMEFMessage extends HMEFTest {
|
||||||
@ -198,5 +201,33 @@ public final class TestHMEFMessage extends HMEFTest {
|
|||||||
assertTrue(e.getMessage().contains("Unhandled level 90"));
|
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)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user