diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java index c8867a6c75..985e58fce6 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java @@ -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))); diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/AllHSMFTests.java b/src/scratchpad/testcases/org/apache/poi/hsmf/AllHSMFTests.java index 710d991d96..fe8cb11243 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/AllHSMFTests.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/AllHSMFTests.java @@ -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 index 0000000000..c10ba0b65f --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestMessageSubmissionChunkY2KRead.java @@ -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); + } +} diff --git a/test-data/hsmf/message_1979.msg b/test-data/hsmf/message_1979.msg new file mode 100644 index 0000000000..10083c8e49 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 index 0000000000..bb295404d0 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 index 0000000000..6833d54347 Binary files /dev/null and b/test-data/hsmf/message_1981.msg differ