james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject james-mime4j git commit: JAMES-2045 LenientDateTimeField should support partial years
Date Mon, 05 Jun 2017 09:58:34 GMT
Repository: james-mime4j
Updated Branches:
  refs/heads/master 5acd2cf3c -> e32e83fbc


JAMES-2045 LenientDateTimeField should support partial years


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

Branch: refs/heads/master
Commit: e32e83fbc6980e278e268007187d5a6be69bf2d2
Parents: 5acd2cf
Author: benwa <btellier@linagora.com>
Authored: Mon Jun 5 13:54:26 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Mon Jun 5 14:03:58 2017 +0700

----------------------------------------------------------------------
 .../mime4j/field/DateTimeFieldLenientImpl.java  | 46 +++++++-------------
 .../mime4j/field/LenientDateTimeFieldTest.java  | 13 ++++++
 2 files changed, 28 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-mime4j/blob/e32e83fb/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldLenientImpl.java
----------------------------------------------------------------------
diff --git a/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldLenientImpl.java
b/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldLenientImpl.java
index 86600e2..9076171 100644
--- a/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldLenientImpl.java
+++ b/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldLenientImpl.java
@@ -19,45 +19,41 @@
 
 package org.apache.james.mime4j.field;
 
-import org.apache.james.mime4j.codec.DecodeMonitor;
-import org.apache.james.mime4j.dom.FieldParser;
-import org.apache.james.mime4j.dom.field.DateTimeField;
-import org.apache.james.mime4j.stream.Field;
-
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Collection;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Locale;
 import java.util.TimeZone;
 
+import org.apache.james.mime4j.codec.DecodeMonitor;
+import org.apache.james.mime4j.dom.FieldParser;
+import org.apache.james.mime4j.dom.field.DateTimeField;
+import org.apache.james.mime4j.stream.Field;
+
 /**
  * Date-time field such as <code>Date</code> or <code>Resent-Date</code>.
  */
 public class DateTimeFieldLenientImpl extends AbstractField implements DateTimeField {
 
     private static final String[] DEFAULT_DATE_FORMATS = {
-            "EEE, dd MMM yyyy HH:mm:ss ZZZZ",
-            "dd MMM yyyy HH:mm:ss ZZZZ",
-            "EEE, dd MMM yyyy HH:mm:ss.SSS 0000"};
+        "EEE, dd MMM yy HH:mm:ss ZZZZ",
+        "dd MMM yy HH:mm:ss ZZZZ",
+        "EEE, dd MMM yy HH:mm:ss.SSS 0000",
+        "EEE, dd MMM yyyy HH:mm:ss ZZZZ",
+        "dd MMM yyyy HH:mm:ss ZZZZ",
+        "EEE, dd MMM yyyy HH:mm:ss.SSS 0000"};
 
     private final List<String> datePatterns;
 
     private boolean parsed = false;
     private Date date;
 
-    DateTimeFieldLenientImpl(final Field rawField,
-                             final Collection<String> dateParsers, final DecodeMonitor
monitor) {
+    private DateTimeFieldLenientImpl(Field rawField, DecodeMonitor monitor) {
         super(rawField, monitor);
-        this.datePatterns = new ArrayList<String>();
-        if (dateParsers != null) {
-            this.datePatterns.addAll(dateParsers);
-        } else {
-            Collections.addAll(this.datePatterns, DEFAULT_DATE_FORMATS);
-        }
+        this.datePatterns = Collections.unmodifiableList(Arrays.asList(DEFAULT_DATE_FORMATS));
     }
 
     public Date getDate() {
@@ -89,21 +85,9 @@ public class DateTimeFieldLenientImpl extends AbstractField implements
DateTimeF
     public static final FieldParser<DateTimeField> PARSER = new FieldParser<DateTimeField>()
{
 
         public DateTimeField parse(final Field rawField, final DecodeMonitor monitor) {
-            return new DateTimeFieldLenientImpl(rawField, null, monitor);
+            return new DateTimeFieldLenientImpl(rawField, monitor);
         }
 
     };
 
-    public static FieldParser<DateTimeField> createParser(final Collection<String>
dateParsers) {
-
-        return new FieldParser<DateTimeField>() {
-
-            public DateTimeField parse(final Field rawField, final DecodeMonitor monitor)
{
-                return new DateTimeFieldLenientImpl(rawField, dateParsers, monitor);
-            }
-
-        };
-
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/james-mime4j/blob/e32e83fb/dom/src/test/java/org/apache/james/mime4j/field/LenientDateTimeFieldTest.java
----------------------------------------------------------------------
diff --git a/dom/src/test/java/org/apache/james/mime4j/field/LenientDateTimeFieldTest.java
b/dom/src/test/java/org/apache/james/mime4j/field/LenientDateTimeFieldTest.java
index 489a297..6cd2307 100644
--- a/dom/src/test/java/org/apache/james/mime4j/field/LenientDateTimeFieldTest.java
+++ b/dom/src/test/java/org/apache/james/mime4j/field/LenientDateTimeFieldTest.java
@@ -45,6 +45,19 @@ public class LenientDateTimeFieldTest {
     }
 
     @Test
+    public void parseShouldSupportPartialYears() throws Exception {
+        DateTimeField f = parse("Date: Wed, 16 Jul 08 17:12:33 +0200");
+        Assert.assertEquals(new Date(1216221153000L), f.getDate());
+    }
+
+    @Test
+    public void parseShouldSupportPartialYearsFromLastCentury() throws Exception {
+        DateTimeField field1 = parse("Date: 16 Jul 99 17:12:33 +0200");
+        DateTimeField field2 = parse("Date: 16 Jul 1999 17:12:33 +0200");
+        Assert.assertEquals(field2.getDate(), field1.getDate());
+    }
+
+    @Test
     public void testDateDSTNoDayOfWeek() throws Exception {
         DateTimeField f = parse("Date: 16 Jul 2008 17:12:33 +0200");
         Assert.assertEquals(new Date(1216221153000L), f.getDate());


---------------------------------------------------------------------
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