Bug 57678: Apply patch to better handle years in mail-messages between 1980 and 1999.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1688993 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
305d31a998
commit
8942828a8f
@ -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)));
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
BIN
test-data/hsmf/message_1979.msg
Normal file
BIN
test-data/hsmf/message_1979.msg
Normal file
Binary file not shown.
BIN
test-data/hsmf/message_1980.msg
Normal file
BIN
test-data/hsmf/message_1980.msg
Normal file
Binary file not shown.
BIN
test-data/hsmf/message_1981.msg
Normal file
BIN
test-data/hsmf/message_1981.msg
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user