Search in sources :

Example 1 with MAPIStringAttribute

use of org.apache.poi.hmef.attribute.MAPIStringAttribute in project poi by apache.

the class TestHMEFMessage method testCustomProperty.

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));
}
Also used : MAPIStringAttribute(org.apache.poi.hmef.attribute.MAPIStringAttribute) MAPIAttribute(org.apache.poi.hmef.attribute.MAPIAttribute) MAPIProperty(org.apache.poi.hsmf.datatypes.MAPIProperty)

Example 2 with MAPIStringAttribute

use of org.apache.poi.hmef.attribute.MAPIStringAttribute in project poi by apache.

the class HMEFContentsExtractor method extractMessageBody.

/**
     * Extracts the RTF message body to the supplied file
     */
public void extractMessageBody(File dest) throws IOException {
    MAPIAttribute body = getBodyAttribute();
    if (body == null) {
        System.err.println("No message body found, " + dest + " not created");
        return;
    }
    if (body instanceof MAPIStringAttribute) {
        String name = dest.toString();
        if (name.endsWith(".rtf")) {
            name = name.substring(0, name.length() - 4);
        }
        dest = new File(name + ".txt");
    }
    OutputStream fout = new FileOutputStream(dest);
    try {
        if (body instanceof MAPIStringAttribute) {
            // Save in a predictable encoding, not raw bytes
            String text = ((MAPIStringAttribute) body).getDataString();
            fout.write(text.getBytes(StringUtil.UTF8));
        } else {
            // Save the raw bytes, should be raw RTF
            fout.write(body.getData());
        }
    } finally {
        fout.close();
    }
}
Also used : MAPIStringAttribute(org.apache.poi.hmef.attribute.MAPIStringAttribute) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) MAPIAttribute(org.apache.poi.hmef.attribute.MAPIAttribute) File(java.io.File)

Aggregations

MAPIAttribute (org.apache.poi.hmef.attribute.MAPIAttribute)2 MAPIStringAttribute (org.apache.poi.hmef.attribute.MAPIStringAttribute)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 MAPIProperty (org.apache.poi.hsmf.datatypes.MAPIProperty)1