use of org.apache.poi.hmef.attribute.MAPIAttribute 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.MAPIAttribute in project poi by apache.
the class HMEFDumper method dump.
private void dump() throws IOException {
int level;
int attachments = 0;
while (true) {
// Fetch the level
level = inp.read();
if (level == TNEFProperty.LEVEL_END_OF_FILE) {
break;
}
// Build the attribute
TNEFAttribute attr = TNEFAttribute.create(inp);
// Is it a new attachment?
if (level == TNEFProperty.LEVEL_ATTACHMENT && attr.getProperty() == TNEFProperty.ID_ATTACHRENDERDATA) {
attachments++;
System.out.println();
System.out.println("Attachment # " + attachments);
System.out.println();
}
// Print the attribute into
System.out.println("Level " + level + " : Type " + attr.getType() + " : ID " + attr.getProperty());
// Print the contents
String indent = " ";
if (attr instanceof TNEFStringAttribute) {
System.out.println(indent + indent + indent + ((TNEFStringAttribute) attr).getString());
}
if (attr instanceof TNEFDateAttribute) {
System.out.println(indent + indent + indent + ((TNEFDateAttribute) attr).getDate());
}
System.out.println(indent + "Data of length " + attr.getData().length);
if (attr.getData().length > 0) {
int len = attr.getData().length;
if (truncatePropertyData) {
len = Math.min(attr.getData().length, 48);
}
int loops = len / 16;
if (loops == 0)
loops = 1;
for (int i = 0; i < loops; i++) {
int thisLen = 16;
int offset = i * 16;
if (i == loops - 1) {
thisLen = len - offset;
}
byte[] data = new byte[thisLen];
System.arraycopy(attr.getData(), offset, data, 0, thisLen);
System.out.print(indent + HexDump.dump(data, 0, 0));
}
}
System.out.println();
if (attr.getProperty() == TNEFProperty.ID_MAPIPROPERTIES || attr.getProperty() == TNEFProperty.ID_ATTACHMENT) {
List<MAPIAttribute> attrs = MAPIAttribute.create(attr);
for (MAPIAttribute ma : attrs) {
System.out.println(indent + indent + ma);
}
System.out.println();
}
}
}
use of org.apache.poi.hmef.attribute.MAPIAttribute in project poi by apache.
the class HMEFFileHandler method handleFile.
@Override
public void handleFile(InputStream stream, String path) throws Exception {
HMEFMessage msg = new HMEFMessage(stream);
// list all properties
StringBuilder props = new StringBuilder();
for (MAPIAttribute att : msg.getMessageMAPIAttributes()) {
props.append(att.getType()).append(": ").append(MAPIStringAttribute.getAsString(att)).append("\n");
}
// there are two test-files that have no body...
if (!msg.getSubject().equals("Testing TNEF Message") && !msg.getSubject().equals("TNEF test message with attachments")) {
assertNotNull("Had: " + msg.getBody() + ", " + msg.getSubject() + ", " + msg.getAttachments() + ": " + props, msg.getBody());
}
assertNotNull("Had: " + msg.getBody() + ", " + msg.getSubject() + ", " + msg.getAttachments() + ": " + props, msg.getSubject());
}
use of org.apache.poi.hmef.attribute.MAPIAttribute in project poi by apache.
the class TestCompressedRTF method testQuickBasics.
/**
* Check that things are as we expected. If this fails,
* then decoding has no hope...
*/
public void testQuickBasics() throws Exception {
HMEFMessage msg = new HMEFMessage(_samples.openResourceAsStream("quick-winmail.dat"));
MAPIAttribute rtfAttr = msg.getMessageMAPIAttribute(MAPIProperty.RTF_COMPRESSED);
assertNotNull(rtfAttr);
assertTrue(rtfAttr instanceof MAPIRtfAttribute);
// Check the start of the compressed version
byte[] data = ((MAPIRtfAttribute) rtfAttr).getRawData();
assertEquals(5907, data.length);
// First 16 bytes is header stuff
// Check it has the length + compressed marker
assertEquals(5907 - 4, LittleEndian.getShort(data));
assertEquals("LZFu", StringUtil.getFromCompressedUnicode(data, 8, 4));
// Now Look at the code
// Flag: cccUUUUU
assertEquals((byte) 0x07, data[16 + 0]);
// c1a: offset 0 / 0x000
assertEquals((byte) 0x00, data[16 + 1]);
// c1b: length 6+2 -> {\rtf1\a
assertEquals((byte) 0x06, data[16 + 2]);
// c2a: offset 16 / 0x010
assertEquals((byte) 0x01, data[16 + 3]);
// c2b: length 1+2 -> def
assertEquals((byte) 0x01, data[16 + 4]);
// c3a: offset 182 / 0xb6
assertEquals((byte) 0x0b, data[16 + 5]);
// c3b: length 0+2 -> la
assertEquals((byte) 0x60, data[16 + 6]);
// n
assertEquals((byte) 0x6e, data[16 + 7]);
// g
assertEquals((byte) 0x67, data[16 + 8]);
// 1
assertEquals((byte) 0x31, data[16 + 9]);
// 0
assertEquals((byte) 0x30, data[16 + 10]);
// 2
assertEquals((byte) 0x32, data[16 + 11]);
// Flag: UccUUccU
assertEquals((byte) 0x66, data[16 + 12]);
// 5
assertEquals((byte) 0x35, data[16 + 13]);
// c2a: offset 6 / 0x006
assertEquals((byte) 0x00, data[16 + 14]);
// c2b: length 4+2 -> \ansi\a
assertEquals((byte) 0x64, data[16 + 15]);
// c3a: offset 7 / 0x007
assertEquals((byte) 0x00, data[16 + 16]);
// c3b: length 2+2 -> nsi
assertEquals((byte) 0x72, data[16 + 17]);
// c
assertEquals((byte) 0x63, data[16 + 18]);
// p
assertEquals((byte) 0x70, data[16 + 19]);
// c6a: offset 221 / 0x0dd
assertEquals((byte) 0x0d, data[16 + 20]);
// c6b: length 0+2 -> g1
assertEquals((byte) 0xd0, data[16 + 21]);
// c7a: offset 224 / 0x0e0
assertEquals((byte) 0x0e, data[16 + 22]);
// c7b: length 0+2 -> 25
assertEquals((byte) 0x00, data[16 + 23]);
// 2
assertEquals((byte) 0x32, data[16 + 24]);
}
use of org.apache.poi.hmef.attribute.MAPIAttribute 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));
}
Aggregations