whitespace
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751183 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b6fe670114
commit
0dc4d4fbbf
@ -40,159 +40,159 @@ import org.apache.poi.util.LittleEndian;
|
|||||||
* http://search.cpan.org/dist/Convert-TNEF/
|
* http://search.cpan.org/dist/Convert-TNEF/
|
||||||
*/
|
*/
|
||||||
public final class HMEFMessage {
|
public final class HMEFMessage {
|
||||||
public static final int HEADER_SIGNATURE = 0x223e9f78;
|
public static final int HEADER_SIGNATURE = 0x223e9f78;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private int fileId;
|
private int fileId;
|
||||||
private final List<TNEFAttribute> messageAttributes = new ArrayList<TNEFAttribute>();
|
private final List<TNEFAttribute> messageAttributes = new ArrayList<TNEFAttribute>();
|
||||||
private final List<MAPIAttribute> mapiAttributes = new ArrayList<MAPIAttribute>();
|
private final List<MAPIAttribute> mapiAttributes = new ArrayList<MAPIAttribute>();
|
||||||
private final List<Attachment> attachments = new ArrayList<Attachment>();
|
private final List<Attachment> attachments = new ArrayList<Attachment>();
|
||||||
|
|
||||||
public HMEFMessage(InputStream inp) throws IOException {
|
public HMEFMessage(InputStream inp) throws IOException {
|
||||||
try {
|
try {
|
||||||
// Check the signature matches
|
// Check the signature matches
|
||||||
int sig = LittleEndian.readInt(inp);
|
int sig = LittleEndian.readInt(inp);
|
||||||
if(sig != HEADER_SIGNATURE) {
|
if (sig != HEADER_SIGNATURE) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"TNEF signature not detected in file, " +
|
"TNEF signature not detected in file, " +
|
||||||
"expected " + HEADER_SIGNATURE + " but got " + sig
|
"expected " + HEADER_SIGNATURE + " but got " + sig
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the File ID
|
// Read the File ID
|
||||||
fileId = LittleEndian.readUShort(inp);
|
fileId = LittleEndian.readUShort(inp);
|
||||||
|
|
||||||
// Now begin processing the contents
|
// Now begin processing the contents
|
||||||
process(inp);
|
process(inp);
|
||||||
} finally {
|
} finally {
|
||||||
inp.close();
|
inp.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void process(InputStream inp) throws IOException {
|
private void process(InputStream inp) throws IOException {
|
||||||
int level;
|
int level;
|
||||||
do {
|
do {
|
||||||
// Fetch the level
|
// Fetch the level
|
||||||
level = inp.read();
|
level = inp.read();
|
||||||
|
|
||||||
// Decide what to attach it to, based on the levels and IDs
|
// Decide what to attach it to, based on the levels and IDs
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case TNEFProperty.LEVEL_MESSAGE:
|
case TNEFProperty.LEVEL_MESSAGE:
|
||||||
processMessage(inp);
|
processMessage(inp);
|
||||||
break;
|
break;
|
||||||
case TNEFProperty.LEVEL_ATTACHMENT:
|
case TNEFProperty.LEVEL_ATTACHMENT:
|
||||||
processAttachment(inp);
|
processAttachment(inp);
|
||||||
break;
|
break;
|
||||||
// ignore trailing newline
|
// ignore trailing newline
|
||||||
case '\r':
|
case '\r':
|
||||||
case '\n':
|
case '\n':
|
||||||
case TNEFProperty.LEVEL_END_OF_FILE:
|
case TNEFProperty.LEVEL_END_OF_FILE:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unhandled level " + level);
|
throw new IllegalStateException("Unhandled level " + level);
|
||||||
}
|
}
|
||||||
} while (level != TNEFProperty.LEVEL_END_OF_FILE);
|
} while (level != TNEFProperty.LEVEL_END_OF_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void processMessage(InputStream inp) throws IOException {
|
void processMessage(InputStream inp) throws IOException {
|
||||||
// Build the attribute
|
// Build the attribute
|
||||||
TNEFAttribute attr = TNEFAttribute.create(inp);
|
TNEFAttribute attr = TNEFAttribute.create(inp);
|
||||||
|
|
||||||
messageAttributes.add(attr);
|
messageAttributes.add(attr);
|
||||||
|
|
||||||
if (attr instanceof TNEFMAPIAttribute) {
|
if (attr instanceof TNEFMAPIAttribute) {
|
||||||
TNEFMAPIAttribute tnefMAPI = (TNEFMAPIAttribute) attr;
|
TNEFMAPIAttribute tnefMAPI = (TNEFMAPIAttribute) attr;
|
||||||
mapiAttributes.addAll(tnefMAPI.getMAPIAttributes());
|
mapiAttributes.addAll(tnefMAPI.getMAPIAttributes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void processAttachment(InputStream inp) throws IOException {
|
void processAttachment(InputStream inp) throws IOException {
|
||||||
// Build the attribute
|
// Build the attribute
|
||||||
TNEFAttribute attr = TNEFAttribute.create(inp);
|
TNEFAttribute attr = TNEFAttribute.create(inp);
|
||||||
|
|
||||||
// Previous attachment or a new one?
|
// Previous attachment or a new one?
|
||||||
if (attachments.isEmpty()
|
if (attachments.isEmpty()
|
||||||
|| attr.getProperty() == TNEFProperty.ID_ATTACHRENDERDATA) {
|
|| attr.getProperty() == TNEFProperty.ID_ATTACHRENDERDATA) {
|
||||||
attachments.add(new Attachment());
|
attachments.add(new Attachment());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the attribute for it
|
// Save the attribute for it
|
||||||
Attachment attach = attachments.get(attachments.size() - 1);
|
Attachment attach = attachments.get(attachments.size() - 1);
|
||||||
attach.addAttribute(attr);
|
attach.addAttribute(attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all HMEF/TNEF attributes of the message.
|
* Returns all HMEF/TNEF attributes of the message.
|
||||||
* Note - In a typical message, most of the interesting properties
|
* Note - In a typical message, most of the interesting properties
|
||||||
* are stored as {@link MAPIAttribute}s - see {@link #getMessageMAPIAttributes()}
|
* are stored as {@link MAPIAttribute}s - see {@link #getMessageMAPIAttributes()}
|
||||||
*/
|
*/
|
||||||
public List<TNEFAttribute> getMessageAttributes() {
|
public List<TNEFAttribute> getMessageAttributes() {
|
||||||
return Collections.unmodifiableList(messageAttributes);
|
return Collections.unmodifiableList(messageAttributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all MAPI attributes of the message.
|
* Returns all MAPI attributes of the message.
|
||||||
* Note - A small number of HMEF/TNEF specific attributes normally
|
* Note - A small number of HMEF/TNEF specific attributes normally
|
||||||
* apply to most messages, see {@link #getMessageAttributes()}
|
* apply to most messages, see {@link #getMessageAttributes()}
|
||||||
*/
|
*/
|
||||||
public List<MAPIAttribute> getMessageMAPIAttributes() {
|
public List<MAPIAttribute> getMessageMAPIAttributes() {
|
||||||
return Collections.unmodifiableList(mapiAttributes);
|
return Collections.unmodifiableList(mapiAttributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all the Attachments of the message.
|
* Returns all the Attachments of the message.
|
||||||
*/
|
*/
|
||||||
public List<Attachment> getAttachments() {
|
public List<Attachment> getAttachments() {
|
||||||
return Collections.unmodifiableList(attachments);
|
return Collections.unmodifiableList(attachments);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the message attribute with the given ID,
|
* Return the message attribute with the given ID,
|
||||||
* or null if there isn't one.
|
* or null if there isn't one.
|
||||||
*/
|
*/
|
||||||
public TNEFAttribute getMessageAttribute(TNEFProperty id) {
|
public TNEFAttribute getMessageAttribute(TNEFProperty id) {
|
||||||
for(TNEFAttribute attr : messageAttributes) {
|
for (TNEFAttribute attr : messageAttributes) {
|
||||||
if(attr.getProperty() == id) {
|
if (attr.getProperty() == id) {
|
||||||
return attr;
|
return attr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the message MAPI Attribute with the given ID,
|
* Return the message MAPI Attribute with the given ID,
|
||||||
* or null if there isn't one.
|
* or null if there isn't one.
|
||||||
*/
|
*/
|
||||||
public MAPIAttribute getMessageMAPIAttribute(MAPIProperty id) {
|
public MAPIAttribute getMessageMAPIAttribute(MAPIProperty id) {
|
||||||
for(MAPIAttribute attr : mapiAttributes) {
|
for (MAPIAttribute attr : mapiAttributes) {
|
||||||
if(attr.getProperty() == id) {
|
if (attr.getProperty() == id) {
|
||||||
return attr;
|
return attr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the string value of the mapi property, or null
|
* Return the string value of the mapi property, or null
|
||||||
* if it isn't set
|
* if it isn't set
|
||||||
*/
|
*/
|
||||||
private String getString(MAPIProperty id) {
|
private String getString(MAPIProperty id) {
|
||||||
return MAPIStringAttribute.getAsString( getMessageMAPIAttribute(id) );
|
return MAPIStringAttribute.getAsString( getMessageMAPIAttribute(id) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Message Subject, or null if the mapi property
|
* Returns the Message Subject, or null if the mapi property
|
||||||
* for this isn't set
|
* for this isn't set
|
||||||
*/
|
*/
|
||||||
public String getSubject() {
|
public String getSubject() {
|
||||||
return getString(MAPIProperty.CONVERSATION_TOPIC);
|
return getString(MAPIProperty.CONVERSATION_TOPIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Message Body, as RTF, or null if the mapi property
|
* Returns the Message Body, as RTF, or null if the mapi property
|
||||||
* for this isn't set
|
* for this isn't set
|
||||||
*/
|
*/
|
||||||
public String getBody() {
|
public String getBody() {
|
||||||
return getString(MAPIProperty.RTF_COMPRESSED);
|
return getString(MAPIProperty.RTF_COMPRESSED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user