use of org.apache.poi.hmef.attribute.TNEFAttribute 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.TNEFAttribute in project poi by apache.
the class HMEFMessage method processAttachment.
void processAttachment(InputStream inp) throws IOException {
// Build the attribute
TNEFAttribute attr = TNEFAttribute.create(inp);
// Previous attachment or a new one?
if (attachments.isEmpty() || attr.getProperty() == TNEFProperty.ID_ATTACHRENDERDATA) {
attachments.add(new Attachment());
}
// Save the attribute for it
Attachment attach = attachments.get(attachments.size() - 1);
attach.addAttribute(attr);
}
use of org.apache.poi.hmef.attribute.TNEFAttribute 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.TNEFAttribute in project poi by apache.
the class HMEFMessage method processMessage.
void processMessage(InputStream inp) throws IOException {
// Build the attribute
TNEFAttribute attr = TNEFAttribute.create(inp);
messageAttributes.add(attr);
if (attr instanceof TNEFMAPIAttribute) {
TNEFMAPIAttribute tnefMAPI = (TNEFMAPIAttribute) attr;
mapiAttributes.addAll(tnefMAPI.getMAPIAttributes());
}
}
Aggregations