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