]> source.dussan.org Git - poi.git/commitdiff
Bug 57678: Apply patch to better handle years in mail-messages between 1980 and 1999.
authorDominik Stadler <centic@apache.org>
Fri, 3 Jul 2015 10:32:53 +0000 (10:32 +0000)
committerDominik Stadler <centic@apache.org>
Fri, 3 Jul 2015 10:32:53 +0000 (10:32 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1688993 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/TestMessageSubmissionChunkY2KRead.java [new file with mode: 0644]
test-data/hsmf/message_1979.msg [new file with mode: 0644]
test-data/hsmf/message_1980.msg [new file with mode: 0644]
test-data/hsmf/message_1981.msg [new file with mode: 0644]

index c8867a6c7530b35aab5be756ae7f7f16a44985e6..985e58fce61355e06a2259afcb1b10e34fe207ff 100644 (file)
@@ -77,7 +77,11 @@ public class MessageSubmissionChunk extends Chunk {
                Matcher m = datePatern.matcher(dateS);
                if(m.matches()) {
                   date = Calendar.getInstance();
-                  date.set(Calendar.YEAR,  Integer.parseInt(m.group(1)) + 2000);
+
+                  // work around issues with dates like 1989, which appear as "89" here
+                  int year = Integer.parseInt(m.group(1));
+                  date.set(Calendar.YEAR,  year + (year > 80 ? 1900 : 2000));
+
                   date.set(Calendar.MONTH, Integer.parseInt(m.group(2)) - 1); // Java is 0 based
                   date.set(Calendar.DATE,  Integer.parseInt(m.group(3)));
                   date.set(Calendar.HOUR_OF_DAY, Integer.parseInt(m.group(4)));
index 710d991d96ce04c7026744172bb34c07a7e9eba5..fe8cb112430b5471ae46f55a387b5d074d87b833 100644 (file)
@@ -27,19 +27,18 @@ import org.apache.poi.hsmf.parsers.*;
 public final class AllHSMFTests {
    public static Test suite() {
       TestSuite suite = new TestSuite(AllHSMFTests.class.getName());
+
       suite.addTestSuite(TestBasics.class);
       suite.addTestSuite(TestBlankFileRead.class);
       suite.addTestSuite(TestSimpleFileRead.class);
       suite.addTestSuite(TestOutlook30FileRead.class);
       suite.addTestSuite(TestFileWithAttachmentsRead.class);
-
       suite.addTestSuite(TestChunkData.class);
       suite.addTestSuite(TestTypes.class);
       suite.addTestSuite(TestSorters.class);
-
       suite.addTestSuite(TestOutlookTextExtractor.class);
-      
       suite.addTestSuite(TestPOIFSChunkParser.class);
+      suite.addTestSuite(TestMessageSubmissionChunkY2KRead.class);
 
       return suite;
    }
diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java
new file mode 100644 (file)
index 0000000..c10ba0b
--- /dev/null
@@ -0,0 +1,67 @@
+/* ====================================================================\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 TestMessageSubmissionChunkY2KRead extends TestCase {\r
+    \r
+    private MAPIMessage mapiMessage1979;\r
+    private MAPIMessage mapiMessage1980;\r
+    private MAPIMessage mapiMessage1981;\r
+\r
+    /**\r
+     * Initialise this test, load up the three test messages.\r
+     * @throws Exception\r
+     */\r
+    public TestMessageSubmissionChunkY2KRead() throws IOException {\r
+        POIDataSamples samples = POIDataSamples.getHSMFInstance();\r
+        this.mapiMessage1979 = new MAPIMessage(samples.openResourceAsStream("message_1979.msg"));\r
+        this.mapiMessage1980 = new MAPIMessage(samples.openResourceAsStream("message_1980.msg"));\r
+        this.mapiMessage1981 = new MAPIMessage(samples.openResourceAsStream("message_1981.msg"));\r
+    }\r
+\r
+    // 1979 is one year before our pivot year (so this is an expected "failure")\r
+    public void testReadMessageDate1979() throws ChunkNotFoundException {\r
+        final Calendar date = mapiMessage1979.getMessageDate();\r
+        final int year = date.get(Calendar.YEAR);\r
+        TestCase.assertEquals(2079, year);\r
+    }\r
+\r
+    // 1980 is our pivot year (so this is an expected "failure")\r
+    public void testReadMessageDate1980() throws ChunkNotFoundException {\r
+        final Calendar date = mapiMessage1980.getMessageDate();\r
+        final int year = date.get(Calendar.YEAR);\r
+        TestCase.assertEquals(2080, year);\r
+    }\r
+\r
+    // 1981 is one year after our pivot year (so this starts working)\r
+    public void testReadMessageDate1981() throws ChunkNotFoundException {\r
+        final Calendar date = mapiMessage1981.getMessageDate();\r
+        final int year = date.get(Calendar.YEAR);\r
+        TestCase.assertEquals(1981, year);\r
+    }\r
+}\r
diff --git a/test-data/hsmf/message_1979.msg b/test-data/hsmf/message_1979.msg
new file mode 100644 (file)
index 0000000..10083c8
Binary files /dev/null and b/test-data/hsmf/message_1979.msg differ
diff --git a/test-data/hsmf/message_1980.msg b/test-data/hsmf/message_1980.msg
new file mode 100644 (file)
index 0000000..bb29540
Binary files /dev/null and b/test-data/hsmf/message_1980.msg differ
diff --git a/test-data/hsmf/message_1981.msg b/test-data/hsmf/message_1981.msg
new file mode 100644 (file)
index 0000000..6833d54
Binary files /dev/null and b/test-data/hsmf/message_1981.msg differ