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)));
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;
}
--- /dev/null
+/* ====================================================================\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