From: Nick Burch Date: Fri, 8 Jan 2010 13:42:53 +0000 (+0000) Subject: Support fetching the message date from the submission id X-Git-Tag: REL_3_7_BETA1~158 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=363f50e17ad52077ef3ed917422d1e2ac5c1fc35;p=poi.git Support fetching the message date from the submission id git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@897201 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java b/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java index 936715f2b5..d69ce00269 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java @@ -22,6 +22,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.Calendar; import org.apache.poi.hsmf.datatypes.AttachmentChunks; import org.apache.poi.hsmf.datatypes.ChunkGroup; @@ -192,6 +193,17 @@ public class MAPIMessage { public String getMessageClass() throws ChunkNotFoundException { return getStringFromChunk(mainChunks.messageClass); } + + /** + * Gets the date that the message was accepted by the + * server on. + */ + public Calendar getMessageDate() throws ChunkNotFoundException { + if(mainChunks.submissionChunk != null) { + return mainChunks.submissionChunk.getAcceptedAtTime(); + } + throw new ChunkNotFoundException(); + } /** diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ByteChunk.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ByteChunk.java index e3c4bd08bd..166a5feef4 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ByteChunk.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ByteChunk.java @@ -23,7 +23,11 @@ import java.io.OutputStream; import org.apache.poi.util.IOUtils; /** - * A Chunk made up of a ByteArrayOutputStream. + * A Chunk that holds binary data, normally + * unparsed. + * Generally as we know how to make sense of the + * contents, we create a new Chunk class and add + * a special case in the parser for them. */ public class ByteChunk extends Chunk { diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java index d6b433c157..36b5202099 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java @@ -30,7 +30,9 @@ public final class Chunks implements ChunkGroup { /* String parts of Outlook Messages that are currently known */ public static final int MESSAGE_CLASS = 0x001A; public static final int SUBJECT = 0x0037; - public static final int DATE = 0x0047; + // "PidTagMessageSubmissionId" as given by accepting server + public static final int SUBMISSION_ID_DATE = 0x0047; + // 0x0050 -> 0x006F seem to be routing info or similar public static final int CONVERSATION_TOPIC = 0x0070; public static final int SENT_BY_SERVER_TYPE = 0x0075; // RECEIVEDEMAIL = 76 @@ -39,7 +41,9 @@ public final class Chunks implements ChunkGroup { public static final int EMAIL_FROM = 0x0C1F; public static final int DISPLAY_CC = 0x0E03; public static final int DISPLAY_BCC = 0x0E02; + // 0x0E1D seems a duplicate of 0x0070 ! public static final int TEXT_BODY = 0x1000; + public static final int MESSAGE_ID = 0x1035; /** Holds all the chunks that were found. */ private List allChunks = new ArrayList(); @@ -63,9 +67,11 @@ public final class Chunks implements ChunkGroup { /** Type of server that the message originated from (SMTP, etc). */ public StringChunk sentByServerType; /** TODO */ - public ByteChunk dateChunk; + public MessageSubmissionChunk submissionChunk; /** TODO */ public StringChunk emailFromChunk; + /** The message ID */ + public StringChunk messageId; public Chunk[] getAll() { return allChunks.toArray(new Chunk[allChunks.size()]); @@ -82,12 +88,15 @@ public final class Chunks implements ChunkGroup { case MESSAGE_CLASS: messageClass = (StringChunk)chunk; break; + case MESSAGE_ID: + messageId = (StringChunk)chunk; + break; case SUBJECT: subjectChunk = (StringChunk)chunk; break; - case DATE: + case SUBMISSION_ID_DATE: // TODO - parse - dateChunk = (ByteChunk)chunk; + submissionChunk = (MessageSubmissionChunk)chunk; break; case CONVERSATION_TOPIC: conversationTopic = (StringChunk)chunk; diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java new file mode 100644 index 0000000000..01793aba59 --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java @@ -0,0 +1,121 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.hsmf.datatypes; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.util.Calendar; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.poi.util.IOUtils; + +/** + * A Chunk that holds the details given back by the + * server at submission time. + * This includes the date the message was given to the + * server, and an ID that's used if you want to cancel + * a message or similar + */ + +public class MessageSubmissionChunk extends Chunk { + private String rawId; + private Calendar date; + + private static final Pattern datePatern = + Pattern.compile("(\\d\\d)(\\d\\d)(\\d\\d)(\\d\\d)(\\d\\d)(\\d\\d)Z?"); + + /** + * Creates a Byte Chunk. + */ + public MessageSubmissionChunk(String entryName) { + super(entryName); + } + + /** + * Create a Byte Chunk, with the specified + * type. + */ + public MessageSubmissionChunk(int chunkId, int type) { + super(chunkId, type); + } + + public void readValue(InputStream value) throws IOException { + // Stored in the file as us-ascii + try { + byte[] data = IOUtils.toByteArray(value); + rawId = new String(data, "ASCII"); + } catch(UnsupportedEncodingException e) { + throw new RuntimeException("Core encoding not found, JVM broken?", e); + } + + // Now process the date + String[] parts = rawId.split(";"); + for(String part : parts) { + if(part.startsWith("l=")) { + // Format of this bit appears to be l=-