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();
}
}
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);
}
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);
}
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));
}
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());
}
Aggregations