Search in sources :

Example 1 with MAPIAttribute

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

the class TestBugs method test52400ReadAttachedTNEF.

@Test
public void test52400ReadAttachedTNEF() throws Exception {
    POIDataSamples samples = POIDataSamples.getHMEFInstance();
    String testFile = "bug52400-winmail-with-attachments.dat";
    HMEFMessage tnefDat = new HMEFMessage(samples.openResourceAsStream(testFile));
    MAPIAttribute bodyHtml = tnefDat.getMessageMAPIAttribute(MAPIProperty.BODY_HTML);
    String bodyStr = new String(bodyHtml.getData(), getEncoding(tnefDat));
    assertTrue(bodyStr.contains("There are also two attachments."));
    assertEquals(2, tnefDat.getAttachments().size());
}
Also used : POIDataSamples(org.apache.poi.POIDataSamples) MAPIAttribute(org.apache.poi.hmef.attribute.MAPIAttribute) Test(org.junit.Test)

Example 2 with MAPIAttribute

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

the class TestBugs method test52400ReadSimpleTNEF.

@Test
public void test52400ReadSimpleTNEF() throws Exception {
    POIDataSamples samples = POIDataSamples.getHMEFInstance();
    String testFile = "bug52400-winmail-simple.dat";
    HMEFMessage tnefDat = new HMEFMessage(samples.openResourceAsStream(testFile));
    MAPIAttribute bodyHtml = tnefDat.getMessageMAPIAttribute(MAPIProperty.BODY_HTML);
    String bodyStr = new String(bodyHtml.getData(), getEncoding(tnefDat));
    assertTrue(bodyStr.contains("This is the message body."));
}
Also used : POIDataSamples(org.apache.poi.POIDataSamples) MAPIAttribute(org.apache.poi.hmef.attribute.MAPIAttribute) Test(org.junit.Test)

Example 3 with MAPIAttribute

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

the class TestBugs method getEncoding.

private String getEncoding(HMEFMessage tnefDat) {
    TNEFAttribute oemCP = tnefDat.getMessageAttribute(TNEFProperty.ID_OEMCODEPAGE);
    MAPIAttribute cpId = tnefDat.getMessageMAPIAttribute(MAPIProperty.INTERNET_CPID);
    int codePage = 1252;
    if (oemCP != null) {
        codePage = LittleEndian.getInt(oemCP.getData());
    } else if (cpId != null) {
        codePage = LittleEndian.getInt(cpId.getData());
    }
    switch(codePage) {
        // see http://en.wikipedia.org/wiki/Code_page for more
        case 1252:
            return "Windows-1252";
        case 20127:
            return "US-ASCII";
        default:
            return "cp" + codePage;
    }
}
Also used : TNEFAttribute(org.apache.poi.hmef.attribute.TNEFAttribute) MAPIAttribute(org.apache.poi.hmef.attribute.MAPIAttribute)

Example 4 with MAPIAttribute

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

the class TestCompressedRTF method testFull.

/**
     * Check that we can correctly decode the whole file
     * TODO Fix what looks like a padding issue
     */
public void testFull() throws Exception {
    HMEFMessage msg = new HMEFMessage(_samples.openResourceAsStream("quick-winmail.dat"));
    MAPIAttribute attr = msg.getMessageMAPIAttribute(MAPIProperty.RTF_COMPRESSED);
    assertNotNull(attr);
    MAPIRtfAttribute rtfAttr = (MAPIRtfAttribute) attr;
    InputStream stream = _samples.openResourceAsStream("quick-contents/message.rtf");
    try {
        byte[] expected = IOUtils.toByteArray(stream);
        CompressedRTF comp = new CompressedRTF();
        byte[] data = rtfAttr.getRawData();
        byte[] decomp = comp.decompress(new ByteArrayInputStream(data));
        // Check the length was as expected
        assertEquals(data.length, comp.getCompressedSize() + 16);
        assertEquals(expected.length, comp.getDeCompressedSize());
        // Will have been padded though
        assertEquals(expected.length + 2, decomp.length);
        byte[] tmp = new byte[expected.length];
        System.arraycopy(decomp, 0, tmp, 0, tmp.length);
        decomp = tmp;
        // By byte
        assertEquals(expected.length, decomp.length);
        for (int i = 0; i < expected.length; i++) {
            assertEquals(expected[i], decomp[i]);
        }
        // By String
        String expString = new String(expected, "ASCII");
        String decompStr = rtfAttr.getDataString();
        assertEquals(expString.length(), decompStr.length());
        assertEquals(expString, decompStr);
    } finally {
        stream.close();
    }
}
Also used : MAPIRtfAttribute(org.apache.poi.hmef.attribute.MAPIRtfAttribute) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MAPIAttribute(org.apache.poi.hmef.attribute.MAPIAttribute)

Example 5 with MAPIAttribute

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

the class TestCompressedRTF method testFirstTwoBlocks.

/**
     * Check that we can decode the first 16 codes
     * (flag + 8 codes, flag + 8 codes)  
     */
public void testFirstTwoBlocks() throws Exception {
    HMEFMessage msg = new HMEFMessage(_samples.openResourceAsStream("quick-winmail.dat"));
    MAPIAttribute attr = msg.getMessageMAPIAttribute(MAPIProperty.RTF_COMPRESSED);
    assertNotNull(attr);
    MAPIRtfAttribute rtfAttr = (MAPIRtfAttribute) attr;
    // Truncate to header + flag + data for flag + flag + data
    byte[] data = new byte[16 + 12 + 13];
    System.arraycopy(rtfAttr.getRawData(), 0, data, 0, data.length);
    // Decompress it
    CompressedRTF comp = new CompressedRTF();
    byte[] decomp = comp.decompress(new ByteArrayInputStream(data));
    String decompStr = new String(decomp, "ASCII");
    // Test
    assertEquals(block2.length(), decomp.length);
    assertEquals(block2, decompStr);
}
Also used : MAPIRtfAttribute(org.apache.poi.hmef.attribute.MAPIRtfAttribute) ByteArrayInputStream(java.io.ByteArrayInputStream) MAPIAttribute(org.apache.poi.hmef.attribute.MAPIAttribute)

Aggregations

MAPIAttribute (org.apache.poi.hmef.attribute.MAPIAttribute)13 MAPIRtfAttribute (org.apache.poi.hmef.attribute.MAPIRtfAttribute)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 POIDataSamples (org.apache.poi.POIDataSamples)2 HMEFMessage (org.apache.poi.hmef.HMEFMessage)2 MAPIStringAttribute (org.apache.poi.hmef.attribute.MAPIStringAttribute)2 TNEFAttribute (org.apache.poi.hmef.attribute.TNEFAttribute)2 MAPIProperty (org.apache.poi.hsmf.datatypes.MAPIProperty)2 Test (org.junit.Test)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Attachment (org.apache.poi.hmef.Attachment)1 TNEFDateAttribute (org.apache.poi.hmef.attribute.TNEFDateAttribute)1 TNEFStringAttribute (org.apache.poi.hmef.attribute.TNEFStringAttribute)1 EmbeddedDocumentExtractor (org.apache.tika.extractor.EmbeddedDocumentExtractor)1