james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [1/3] james-mime4j git commit: JAMES-2045 Add century when parsing dates without
Date Mon, 05 Jun 2017 03:21:27 GMT
Repository: james-mime4j
Updated Branches:
  refs/heads/master 5c5830375 -> 5acd2cf3c


JAMES-2045 Add century when parsing dates without


Project: http://git-wip-us.apache.org/repos/asf/james-mime4j/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-mime4j/commit/7829f79a
Tree: http://git-wip-us.apache.org/repos/asf/james-mime4j/tree/7829f79a
Diff: http://git-wip-us.apache.org/repos/asf/james-mime4j/diff/7829f79a

Branch: refs/heads/master
Commit: 7829f79a69bd3f07bfea324edbb30ab850b8c886
Parents: 5c58303
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Fri Jun 2 15:29:50 2017 +0200
Committer: benwa <btellier@linagora.com>
Committed: Mon Jun 5 10:15:47 2017 +0700

----------------------------------------------------------------------
 .../mime4j/field/datetime/DateTimeParser.jj     | 10 ++-
 .../mime4j/field/DateTimeFieldImplTest.java     | 73 ++++++++++++++++++++
 2 files changed, 82 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-mime4j/blob/7829f79a/dom/src/main/javacc/org/apache/james/mime4j/field/datetime/DateTimeParser.jj
----------------------------------------------------------------------
diff --git a/dom/src/main/javacc/org/apache/james/mime4j/field/datetime/DateTimeParser.jj
b/dom/src/main/javacc/org/apache/james/mime4j/field/datetime/DateTimeParser.jj
index ff1adf6..7b9b490 100644
--- a/dom/src/main/javacc/org/apache/james/mime4j/field/datetime/DateTimeParser.jj
+++ b/dom/src/main/javacc/org/apache/james/mime4j/field/datetime/DateTimeParser.jj
@@ -225,7 +225,15 @@ int month() :
 String year() :
 {Token t;}
 {
-    t=<DIGITS> { return t.image; }
+    t=<DIGITS> 
+    {
+      String year = (String) t.image;
+      if (year.length() == 2) 
+      {
+        return "20" + year;
+      }
+      return year;
+    }
 }
 
 Time time() :

http://git-wip-us.apache.org/repos/asf/james-mime4j/blob/7829f79a/dom/src/test/java/org/apache/james/mime4j/field/DateTimeFieldImplTest.java
----------------------------------------------------------------------
diff --git a/dom/src/test/java/org/apache/james/mime4j/field/DateTimeFieldImplTest.java b/dom/src/test/java/org/apache/james/mime4j/field/DateTimeFieldImplTest.java
new file mode 100644
index 0000000..0e13b2d
--- /dev/null
+++ b/dom/src/test/java/org/apache/james/mime4j/field/DateTimeFieldImplTest.java
@@ -0,0 +1,73 @@
+/****************************************************************
+ * 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.james.mime4j.field;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.TimeZone;
+
+import org.apache.james.mime4j.MimeException;
+import org.apache.james.mime4j.dom.field.DateTimeField;
+import org.apache.james.mime4j.stream.RawField;
+import org.apache.james.mime4j.stream.RawFieldParser;
+import org.apache.james.mime4j.util.ByteSequence;
+import org.apache.james.mime4j.util.ContentUtil;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class DateTimeFieldImplTest {
+
+    private TimeZone timeZone;
+
+    @Before
+    public void setup() {
+        timeZone = TimeZone.getDefault();
+        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+    }
+    
+    @After
+    public void tearDown() {
+        TimeZone.setDefault(timeZone);
+    }
+    
+    @Test
+    public void parseShouldReturnYearWhen4Digits() throws Exception {
+        DateTimeField field = parse("Date: Sun, 13 May 1917 14:18:52Z");
+        assertEquals("Sun May 13 14:18:52 UTC 1917", field.getDate().toString());
+    }
+
+    @Test
+    public void parseShouldAddCenturyWhen2Digits() throws Exception {
+        DateTimeField field = parse("Date: Sat, 13 May 17 14:18:52Z");
+        assertEquals("Sat May 13 14:18:52 UTC 2017", field.getDate().toString());
+    }
+
+    @Test
+    public void dayIsDependentFromTheDateNotFromTheGivenDay() throws Exception {
+        DateTimeField field = parse("Date: Mon, 13 May 17 14:18:52Z");
+        assertEquals("Sat May 13 14:18:52 UTC 2017", field.getDate().toString());
+    }
+
+    private DateTimeField parse(final String s) throws MimeException {
+        ByteSequence raw = ContentUtil.encode(s);
+        RawField rawField = RawFieldParser.DEFAULT.parseField(raw);
+        return DateTimeFieldImpl.PARSER.parse(rawField, null);
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message