for(String part : parts) {
if(part.startsWith("l=")) {
// Format of this bit appears to be l=<id>-<time>-<number>
- if(part.indexOf('-') != -1 &&
- part.indexOf('-') != part.lastIndexOf('-')) {
- String dateS = part.substring(part.indexOf('-')+1, part.lastIndexOf('-'));
-
+ // ID may contain hyphens.
+
+ String dateS = null;
+ final int numberPartBegin = part.lastIndexOf('-');
+ if (numberPartBegin != -1) {
+ final int datePartBegin = part.lastIndexOf('-', numberPartBegin-1);
+ if (datePartBegin != -1 &&
+ // cannot extract date if only one hyphen is in the string...
+ numberPartBegin > datePartBegin) {
+ dateS = part.substring(datePartBegin + 1, numberPartBegin);
+ }
+ }
+ if (dateS != null) {
// Should be yymmddhhmmssZ
Matcher m = datePatern.matcher(dateS);
if(m.matches()) {
--- /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 TestMessageSubmissionChunk extends TestCase {\r
+ \r
+ private MAPIMessage mapiMessageExtraHyphenSubmissionChunk;\r
+ private MAPIMessage mapiMessageNormalSubmissionChunk;\r
+\r
+ /**\r
+ * Initialise this test, load up the test messages.\r
+ * @throws Exception\r
+ */\r
+ public TestMessageSubmissionChunk() throws IOException {\r
+ POIDataSamples samples = POIDataSamples.getHSMFInstance();\r
+ this.mapiMessageExtraHyphenSubmissionChunk = new MAPIMessage(samples.openResourceAsStream("message_extra_hyphen_submission_chunk.msg"));\r
+ this.mapiMessageNormalSubmissionChunk = new MAPIMessage(samples.openResourceAsStream("message_normal_submission_chunk.msg"));\r
+ }\r
+\r
+ public void testReadMessageDateExtraHyphenSubmissionChunk() throws ChunkNotFoundException {\r
+ final Calendar date = mapiMessageExtraHyphenSubmissionChunk.getMessageDate();\r
+ TestCase.assertNotNull(date);\r
+ final int year = date.get(Calendar.YEAR);\r
+ TestCase.assertEquals(2007, year);\r
+ }\r
+\r
+ public void testReadMessageDateNormalSubmissionChunk() throws ChunkNotFoundException {\r
+ final Calendar date = mapiMessageNormalSubmissionChunk.getMessageDate();\r
+ TestCase.assertNotNull(date);\r
+ final int year = date.get(Calendar.YEAR);\r
+ TestCase.assertEquals(2007, year);\r
+ }\r
+}\r