Author: centic
Date: Fri Jul  3 10:32:53 2015
New Revision: 1688993

URL: http://svn.apache.org/r1688993
Log:
Bug 57678: Apply patch to better handle years in mail-messages between 1980 and 
1999.

Added:
    
poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java
    poi/trunk/test-data/hsmf/message_1979.msg   (with props)
    poi/trunk/test-data/hsmf/message_1980.msg   (with props)
    poi/trunk/test-data/hsmf/message_1981.msg   (with props)
Modified:
    
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/AllHSMFTests.java

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java?rev=1688993&r1=1688992&r2=1688993&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java
 (original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java
 Fri Jul  3 10:32:53 2015
@@ -77,7 +77,11 @@ public class MessageSubmissionChunk exte
                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)));

Modified: 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/AllHSMFTests.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/AllHSMFTests.java?rev=1688993&r1=1688992&r2=1688993&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/AllHSMFTests.java 
(original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/AllHSMFTests.java 
Fri Jul  3 10:32:53 2015
@@ -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;
    }

Added: 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java?rev=1688993&view=auto
==============================================================================
--- 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java
 (added)
+++ 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java
 Fri Jul  3 10:32:53 2015
@@ -0,0 +1,67 @@
+/* ====================================================================
+   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;
+
+import java.io.IOException;
+
+import org.apache.poi.hsmf.MAPIMessage;
+import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
+import org.apache.poi.POIDataSamples;
+
+import java.util.Calendar;
+
+import junit.framework.TestCase;
+
+public final class TestMessageSubmissionChunkY2KRead extends TestCase {
+    
+    private MAPIMessage mapiMessage1979;
+    private MAPIMessage mapiMessage1980;
+    private MAPIMessage mapiMessage1981;
+
+    /**
+     * Initialise this test, load up the three test messages.
+     * @throws Exception
+     */
+    public TestMessageSubmissionChunkY2KRead() throws IOException {
+        POIDataSamples samples = POIDataSamples.getHSMFInstance();
+        this.mapiMessage1979 = new 
MAPIMessage(samples.openResourceAsStream("message_1979.msg"));
+        this.mapiMessage1980 = new 
MAPIMessage(samples.openResourceAsStream("message_1980.msg"));
+        this.mapiMessage1981 = new 
MAPIMessage(samples.openResourceAsStream("message_1981.msg"));
+    }
+
+    // 1979 is one year before our pivot year (so this is an expected 
"failure")
+    public void testReadMessageDate1979() throws ChunkNotFoundException {
+        final Calendar date = mapiMessage1979.getMessageDate();
+        final int year = date.get(Calendar.YEAR);
+        TestCase.assertEquals(2079, year);
+    }
+
+    // 1980 is our pivot year (so this is an expected "failure")
+    public void testReadMessageDate1980() throws ChunkNotFoundException {
+        final Calendar date = mapiMessage1980.getMessageDate();
+        final int year = date.get(Calendar.YEAR);
+        TestCase.assertEquals(2080, year);
+    }
+
+    // 1981 is one year after our pivot year (so this starts working)
+    public void testReadMessageDate1981() throws ChunkNotFoundException {
+        final Calendar date = mapiMessage1981.getMessageDate();
+        final int year = date.get(Calendar.YEAR);
+        TestCase.assertEquals(1981, year);
+    }
+}

Added: poi/trunk/test-data/hsmf/message_1979.msg
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/hsmf/message_1979.msg?rev=1688993&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/hsmf/message_1979.msg
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: poi/trunk/test-data/hsmf/message_1980.msg
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/hsmf/message_1980.msg?rev=1688993&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/hsmf/message_1980.msg
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: poi/trunk/test-data/hsmf/message_1981.msg
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/hsmf/message_1981.msg?rev=1688993&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/hsmf/message_1981.msg
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to