From 062959aae1e94df3188e8f2649a0d206c01f4249 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 10 Jul 2012 09:43:49 +0000 Subject: [PATCH] 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 --- .../poi/hsmf/datatypes/AttachmentChunks.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) 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()]); } -- 2.39.5