From: Nick Burch Date: Tue, 10 Jul 2012 09:43:49 +0000 (+0000) Subject: Add some helper methods for working with attachments X-Git-Tag: 3.10-beta1~173 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=062959aae1e94df3188e8f2649a0d206c01f4249;p=poi.git Add some helper methods for working with attachments git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1359542 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java index af2ea642a5..55f8a5f254 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java @@ -31,10 +31,13 @@ import static org.apache.poi.hsmf.datatypes.MAPIProperty.ATTACH_MIME_TAG; import static org.apache.poi.hsmf.datatypes.MAPIProperty.ATTACH_RENDERING; import static org.apache.poi.hsmf.datatypes.MAPIProperty.ATTACH_SIZE; +import java.io.IOException; import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import org.apache.poi.hsmf.MAPIMessage; + /** * Collection of convenence chunks for standard parts of the MSG file attachment. */ @@ -68,6 +71,36 @@ public class AttachmentChunks implements ChunkGroup { this.poifsName = poifsName; } + + /** + * Is this Attachment an embedded MAPI message? + */ + public boolean isEmbeddedMessage() { + return (attachmentDirectory != null); + } + /** + * Returns the embedded MAPI message, if the attachment + * is an embedded message, or null otherwise + */ + public MAPIMessage getEmbeddedMessage() throws IOException { + if (attachmentDirectory != null) { + return attachmentDirectory.getAsEmbededMessage(); + } + return null; + } + + /** + * Returns the embedded object, if the attachment is an + * object based embedding (image, document etc), or null + * if it's an embedded message + */ + public byte[] getEmbeddedAttachmentObject() { + if (attachData != null) { + return attachData.getValue(); + } + return null; + } + public Chunk[] getAll() { return allChunks.toArray(new Chunk[allChunks.size()]); }