]> source.dussan.org Git - poi.git/commitdiff
Bug 57744: Fix parsing the email submission data when id contains a hyphen
authorDominik Stadler <centic@apache.org>
Fri, 3 Jul 2015 11:04:52 +0000 (11:04 +0000)
committerDominik Stadler <centic@apache.org>
Fri, 3 Jul 2015 11:04:52 +0000 (11:04 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1688998 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java
src/scratchpad/testcases/org/apache/poi/hsmf/AllHSMFTests.java
src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunk.java [new file with mode: 0644]
test-data/hsmf/message_extra_hyphen_submission_chunk.msg [new file with mode: 0644]
test-data/hsmf/message_normal_submission_chunk.msg [new file with mode: 0644]

index 985e58fce61355e06a2259afcb1b10e34fe207ff..dd9ab9a5f035b67a24920a32c7919bfb5d070018 100644 (file)
@@ -69,10 +69,19 @@ public class MessageSubmissionChunk extends Chunk {
       for(String part : parts) {
          if(part.startsWith("l=")) {
             // Format of this bit appears to be l=<id>-<time>-<number>
-            if(part.indexOf('-') != -1 && 
-                  part.indexOf('-') != part.lastIndexOf('-')) {
-               String dateS = part.substring(part.indexOf('-')+1, part.lastIndexOf('-'));
-               
+            // ID may contain hyphens.
+
+            String dateS = null;
+            final int numberPartBegin = part.lastIndexOf('-');
+            if (numberPartBegin != -1) {
+                final int datePartBegin = part.lastIndexOf('-', numberPartBegin-1);
+                if (datePartBegin != -1 && 
+                        // cannot extract date if only one hyphen is in the string...
+                        numberPartBegin > datePartBegin) {
+                    dateS = part.substring(datePartBegin + 1, numberPartBegin);
+                }
+            }
+            if (dateS != null) {
                // Should be yymmddhhmmssZ
                Matcher m = datePatern.matcher(dateS);
                if(m.matches()) {
index fe8cb112430b5471ae46f55a387b5d074d87b833..7664bddec3b3a35359691bfc9f6e5cac44c19c2f 100644 (file)
@@ -39,6 +39,7 @@ public final class AllHSMFTests {
       suite.addTestSuite(TestOutlookTextExtractor.class);
       suite.addTestSuite(TestPOIFSChunkParser.class);
       suite.addTestSuite(TestMessageSubmissionChunkY2KRead.class);
+      suite.addTestSuite(TestMessageSubmissionChunk.class);
 
       return suite;
    }
diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunk.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunk.java
new file mode 100644 (file)
index 0000000..0cbad21
--- /dev/null
@@ -0,0 +1,58 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.hsmf;\r
+\r
+import java.io.IOException;\r
+\r
+import org.apache.poi.hsmf.MAPIMessage;\r
+import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;\r
+import org.apache.poi.POIDataSamples;\r
+\r
+import java.util.Calendar;\r
+\r
+import junit.framework.TestCase;\r
+\r
+public final class TestMessageSubmissionChunk extends TestCase {\r
+    \r
+    private MAPIMessage mapiMessageExtraHyphenSubmissionChunk;\r
+    private MAPIMessage mapiMessageNormalSubmissionChunk;\r
+\r
+    /**\r
+     * Initialise this test, load up the test messages.\r
+     * @throws Exception\r
+     */\r
+    public TestMessageSubmissionChunk() throws IOException {\r
+        POIDataSamples samples = POIDataSamples.getHSMFInstance();\r
+        this.mapiMessageExtraHyphenSubmissionChunk = new MAPIMessage(samples.openResourceAsStream("message_extra_hyphen_submission_chunk.msg"));\r
+        this.mapiMessageNormalSubmissionChunk = new MAPIMessage(samples.openResourceAsStream("message_normal_submission_chunk.msg"));\r
+    }\r
+\r
+    public void testReadMessageDateExtraHyphenSubmissionChunk() throws ChunkNotFoundException {\r
+        final Calendar date = mapiMessageExtraHyphenSubmissionChunk.getMessageDate();\r
+        TestCase.assertNotNull(date);\r
+        final int year = date.get(Calendar.YEAR);\r
+        TestCase.assertEquals(2007, year);\r
+    }\r
+\r
+    public void testReadMessageDateNormalSubmissionChunk() throws ChunkNotFoundException {\r
+        final Calendar date = mapiMessageNormalSubmissionChunk.getMessageDate();\r
+        TestCase.assertNotNull(date);\r
+        final int year = date.get(Calendar.YEAR);\r
+        TestCase.assertEquals(2007, year);\r
+    }\r
+}\r
diff --git a/test-data/hsmf/message_extra_hyphen_submission_chunk.msg b/test-data/hsmf/message_extra_hyphen_submission_chunk.msg
new file mode 100644 (file)
index 0000000..3bcb8d3
Binary files /dev/null and b/test-data/hsmf/message_extra_hyphen_submission_chunk.msg differ
diff --git a/test-data/hsmf/message_normal_submission_chunk.msg b/test-data/hsmf/message_normal_submission_chunk.msg
new file mode 100644 (file)
index 0000000..bb15d27
Binary files /dev/null and b/test-data/hsmf/message_normal_submission_chunk.msg differ