Search in sources :

Example 1 with MAPIRtfAttribute

use of org.apache.poi.hmef.attribute.MAPIRtfAttribute 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 2 with MAPIRtfAttribute

use of org.apache.poi.hmef.attribute.MAPIRtfAttribute 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)

Example 3 with MAPIRtfAttribute

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

the class TestCompressedRTF method testFirstBlock.

/**
     * Check that we can decode the first 8 codes
     * (1 flag byte + 8 codes)  
     */
public void testFirstBlock() 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
    byte[] data = new byte[16 + 12];
    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(block1.length(), decomp.length);
    assertEquals(block1, decompStr);
}
Also used : MAPIRtfAttribute(org.apache.poi.hmef.attribute.MAPIRtfAttribute) ByteArrayInputStream(java.io.ByteArrayInputStream) MAPIAttribute(org.apache.poi.hmef.attribute.MAPIAttribute)

Example 4 with MAPIRtfAttribute

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

the class TestHMEFMessage method testMessageContents.

/**
    * Checks that the compressed RTF message contents
    *  can be correctly extracted
    */
public void testMessageContents() throws Exception {
    HMEFMessage msg = new HMEFMessage(_samples.openResourceAsStream("quick-winmail.dat"));
    // Firstly by byte
    MAPIRtfAttribute rtf = (MAPIRtfAttribute) msg.getMessageMAPIAttribute(MAPIProperty.RTF_COMPRESSED);
    assertContents("message.rtf", rtf.getData());
    // Then by String
    String contents = msg.getBody();
    // It's all low bytes
    byte[] contentsBytes = contents.getBytes("ASCII");
    assertContents("message.rtf", contentsBytes);
    // try to get a message id that does not exist
    assertNull(msg.getMessageMAPIAttribute(MAPIProperty.AB_DEFAULT_DIR));
}
Also used : MAPIRtfAttribute(org.apache.poi.hmef.attribute.MAPIRtfAttribute)

Example 5 with MAPIRtfAttribute

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

the class TestHMEFMessage method testMessageSample1.

public void testMessageSample1() throws Exception {
    HMEFMessage msg = new HMEFMessage(_samples.openResourceAsStream("winmail-sample1.dat"));
    // Firstly by byte
    MAPIRtfAttribute rtf = (MAPIRtfAttribute) msg.getMessageMAPIAttribute(MAPIProperty.RTF_COMPRESSED);
    // assertContents("message.rtf", rtf.getData());
    assertNotNull(rtf);
    // Then by String
    String contents = msg.getBody();
    //System.out.println(contents);
    // It's all low bytes
    byte[] contentsBytes = contents.getBytes("ASCII");
    // assertContents("message.rtf", contentsBytes);
    assertNotNull(contentsBytes);
    assertNotNull(msg.getSubject());
    assertNotNull(msg.getBody());
}
Also used : MAPIRtfAttribute(org.apache.poi.hmef.attribute.MAPIRtfAttribute)

Aggregations

MAPIRtfAttribute (org.apache.poi.hmef.attribute.MAPIRtfAttribute)8 MAPIAttribute (org.apache.poi.hmef.attribute.MAPIAttribute)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Attachment (org.apache.poi.hmef.Attachment)1 HMEFMessage (org.apache.poi.hmef.HMEFMessage)1 AttachmentChunks (org.apache.poi.hsmf.datatypes.AttachmentChunks)1 ByteChunk (org.apache.poi.hsmf.datatypes.ByteChunk)1 Chunk (org.apache.poi.hsmf.datatypes.Chunk)1 StringChunk (org.apache.poi.hsmf.datatypes.StringChunk)1 ChunkNotFoundException (org.apache.poi.hsmf.exceptions.ChunkNotFoundException)1 TikaException (org.apache.tika.exception.TikaException)1 EmbeddedDocumentExtractor (org.apache.tika.extractor.EmbeddedDocumentExtractor)1 Metadata (org.apache.tika.metadata.Metadata)1 Parser (org.apache.tika.parser.Parser)1 HtmlParser (org.apache.tika.parser.html.HtmlParser)1