james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1177733 - in /james/mime4j/trunk/dom/src: main/java/org/apache/james/mime4j/field/DateTimeFieldLenientImpl.java test/java/org/apache/james/mime4j/field/LenientDateTimeFieldTest.java
Date Fri, 30 Sep 2011 17:02:59 GMT
Author: olegk
Date: Fri Sep 30 17:02:58 2011
New Revision: 1177733

URL: http://svn.apache.org/viewvc?rev=1177733&view=rev
Log:
MIME4J-204: accept date-time fields without day of the week attribute when in lenient mode

Added:
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientDateTimeFieldTest.java
  (with props)
Modified:
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldLenientImpl.java

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldLenientImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldLenientImpl.java?rev=1177733&r1=1177732&r2=1177733&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldLenientImpl.java
(original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DateTimeFieldLenientImpl.java
Fri Sep 30 17:02:58 2011
@@ -38,7 +38,9 @@ import org.apache.james.mime4j.stream.Fi
  */
 public class DateTimeFieldLenientImpl extends AbstractField implements DateTimeField {
 
-    private static final String DEFAULT_DATE_FORMAT = "EEE, dd MMM yyyy hh:mm:ss ZZZZ";
+    private static final String[] DEFAULT_DATE_FORMATS =  { 
+        "EEE, dd MMM yyyy hh:mm:ss ZZZZ", 
+        "dd MMM yyyy hh:mm:ss ZZZZ"};
 
     private final List<String> datePatterns;
 
@@ -52,7 +54,9 @@ public class DateTimeFieldLenientImpl ex
         if (dateParsers != null) {
             this.datePatterns.addAll(dateParsers);
         } else {
-            this.datePatterns.add(DEFAULT_DATE_FORMAT);
+            for (String pattern: DEFAULT_DATE_FORMATS) {
+                this.datePatterns.add(pattern);
+            }
         }
     }
 
@@ -86,4 +90,17 @@ public class DateTimeFieldLenientImpl ex
         }
 
     };
+    
+    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);
+            }
+
+        };
+        
+    }
+    
 }

Added: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientDateTimeFieldTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientDateTimeFieldTest.java?rev=1177733&view=auto
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientDateTimeFieldTest.java
(added)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientDateTimeFieldTest.java
Fri Sep 30 17:02:58 2011
@@ -0,0 +1,51 @@
+/****************************************************************
+ * 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 java.util.Date;
+
+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 junit.framework.TestCase;
+
+public class LenientDateTimeFieldTest extends TestCase {
+
+    static DateTimeField parse(final String s) throws MimeException {
+        ByteSequence raw = ContentUtil.encode(s);
+        RawField rawField = RawFieldParser.DEFAULT.parseField(raw);
+        return DateTimeFieldLenientImpl.PARSER.parse(rawField, null);
+    }
+
+    public void testDateDST() throws Exception  {
+        DateTimeField f = parse("Date: Wed, 16 Jul 2008 17:12:33 +0200");
+        assertEquals(new Date(1216221153000L), f.getDate());
+    }
+
+    public void testDateDSTNoDayOfWeek() throws Exception  {
+        DateTimeField f = parse("Date: 16 Jul 2008 17:12:33 +0200");
+        assertEquals(new Date(1216221153000L), f.getDate());
+    }
+
+}

Propchange: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientDateTimeFieldTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientDateTimeFieldTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientDateTimeFieldTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message