You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2022/05/27 07:05:57 UTC

[james-mime4j] branch master updated (7e23d5e1 -> 16d6c56c)

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-mime4j.git


    from 7e23d5e1 MIME4J-316 Parts missing in case of a specific combination of boundaries
     new d79c2ecc MIME4J-315 Add a convenient method to transform DateTime into a java date
     new dc15857d MIME4J-315 Add a convenient method to parse DateTime
     new 16d6c56c MIME4J-315 Test suite for DateTime

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/james/mime4j/dom/datetime/DateTime.java | 12 +++++
 ...entDateTimeFieldTest.java => DateTimeTest.java} | 60 ++++++++++++----------
 2 files changed, 45 insertions(+), 27 deletions(-)
 copy dom/src/test/java/org/apache/james/mime4j/field/{LenientDateTimeFieldTest.java => DateTimeTest.java} (57%)


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


[james-mime4j] 02/03: MIME4J-315 Add a convenient method to parse DateTime

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-mime4j.git

commit dc15857d4b999c0f095b4e00aee5d89e1e0047aa
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed May 18 11:13:35 2022 +0700

    MIME4J-315 Add a convenient method to parse DateTime
    
    THis enables building DateTime without knowledge of its parser
---
 .../main/java/org/apache/james/mime4j/dom/datetime/DateTime.java  | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/dom/src/main/java/org/apache/james/mime4j/dom/datetime/DateTime.java b/dom/src/main/java/org/apache/james/mime4j/dom/datetime/DateTime.java
index e76a82c1..98e20808 100644
--- a/dom/src/main/java/org/apache/james/mime4j/dom/datetime/DateTime.java
+++ b/dom/src/main/java/org/apache/james/mime4j/dom/datetime/DateTime.java
@@ -19,12 +19,20 @@
 
 package org.apache.james.mime4j.dom.datetime;
 
+import java.io.InputStream;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.TimeZone;
 
+import org.apache.james.mime4j.field.datetime.parser.DateTimeParser;
+import org.apache.james.mime4j.field.datetime.parser.ParseException;
+
 public class DateTime {
+    public static DateTime parse(InputStream inputStream) throws ParseException {
+        return new DateTimeParser(inputStream).parseAll();
+    }
+
     private final Date date;
     private final int year;
     private final int month;


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


[james-mime4j] 03/03: MIME4J-315 Test suite for DateTime

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-mime4j.git

commit 16d6c56cf6a16bfed7aaedf6024c154c00093032
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed May 18 11:14:47 2022 +0700

    MIME4J-315 Test suite for DateTime
    
    This is a copy of LenientDateTimeFieldTest
---
 .../apache/james/mime4j/field/DateTimeTest.java    | 115 +++++++++++++++++++++
 1 file changed, 115 insertions(+)

diff --git a/dom/src/test/java/org/apache/james/mime4j/field/DateTimeTest.java b/dom/src/test/java/org/apache/james/mime4j/field/DateTimeTest.java
new file mode 100644
index 00000000..ca217db1
--- /dev/null
+++ b/dom/src/test/java/org/apache/james/mime4j/field/DateTimeTest.java
@@ -0,0 +1,115 @@
+/****************************************************************
+ * 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.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Date;
+
+import org.apache.james.mime4j.MimeException;
+import org.apache.james.mime4j.dom.datetime.DateTime;
+import org.apache.james.mime4j.dom.field.DateTimeField;
+import org.apache.james.mime4j.field.datetime.parser.DateTimeParser;
+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.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class DateTimeTest {
+
+    static Date parse(final String s) throws MimeException {
+        ByteArrayInputStream stream = new ByteArrayInputStream(s.getBytes(StandardCharsets.US_ASCII));
+        return DateTime.parse(stream).asDate();
+    }
+
+    @Test
+    public void testDateDST() throws Exception {
+        Date f = parse("Wed, 16 Jul 2008 17:12:33 +0200");
+        Assert.assertEquals(new Date(1216221153000L), f);
+    }
+
+    @Test
+    public void extraPDTShouldBeTolerated() throws Exception {
+        Date f = parse("Wed, 16 Jul 2008 17:12:33 +0200 (PDT)");
+        Assert.assertEquals(new Date(1216221153000L), f);
+    }
+
+    @Ignore
+    @Test
+    public void extraCharsShouldBeTolerated() throws Exception {
+        Date f = parse("Thu, 4 Oct 2001 20:12:26 -0700 (PDT),Thu, 4 Oct 2001 20:12:26 -0700");
+        Assert.assertEquals(new Date(1002251546000L), f);
+    }
+
+    @Test
+    public void parseShouldSupportPartialYears() throws Exception {
+        Date f = parse("Wed, 16 Jul 08 17:12:33 +0200");
+        Assert.assertEquals(new Date(1216221153000L), f);
+    }
+
+    @Test
+    public void parseShouldSupportPartialYearsFromLastCentury() throws Exception {
+        Date field1 = parse("16 Jul 99 17:12:33 +0200");
+        Date field2 = parse("16 Jul 1999 17:12:33 +0200");
+        Assert.assertEquals(field2.getDate(), field1.getDate());
+    }
+
+    @Test
+    public void testDateDSTNoDayOfWeek() throws Exception {
+        Date f = parse("16 Jul 2008 17:12:33 +0200");
+        Assert.assertEquals(new Date(1216221153000L), f);
+    }
+
+    @Test
+    public void testdd() throws Exception {
+        Date f = parse("Thu, 01 Jan 1970 12:00:00 +0000");
+        Assert.assertEquals(43200000L, f.getTime());
+    }
+
+    @Test
+    public void parseShouldAcceptWrongDayOfWeek() throws Exception {
+        // Should be Thu
+        Date f = parse("Fri, 01 Jan 1970 12:00:00 +0000");
+        Assert.assertEquals(43200000L, f.getTime());
+    }
+
+    @Ignore
+    @Test
+    public void testMime4j219() throws Exception {
+        Date f = parse("Tue, 17 Jul 2012 22:23:35.882 0000");
+        Assert.assertEquals(1342563815882L, f.getTime());
+    }
+
+    @Test
+    public void testDateWithExtraLeadingWhiteSpace() throws Exception {
+        Date f = parse(" Wed, 28 Mar 2007 13:32:39 +1000");
+        Assert.assertEquals(1175052759000L, f.getTime());
+    }
+
+    @Test
+    public void testDateWhenGeneralTimezone() throws Exception {
+        Date f = parse("Fri, 05 Jan 2018 16:18:28 Z");
+        Assert.assertEquals(1515169108000L, f.getTime());
+    }
+
+}


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


[james-mime4j] 01/03: MIME4J-315 Add a convenient method to transform DateTime into a java date

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-mime4j.git

commit d79c2eccb9733ddbf13c7749071fba72d1948db7
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed May 18 11:10:59 2022 +0700

    MIME4J-315 Add a convenient method to transform DateTime into a java date
---
 dom/src/main/java/org/apache/james/mime4j/dom/datetime/DateTime.java | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/dom/src/main/java/org/apache/james/mime4j/dom/datetime/DateTime.java b/dom/src/main/java/org/apache/james/mime4j/dom/datetime/DateTime.java
index 83914676..e76a82c1 100644
--- a/dom/src/main/java/org/apache/james/mime4j/dom/datetime/DateTime.java
+++ b/dom/src/main/java/org/apache/james/mime4j/dom/datetime/DateTime.java
@@ -74,6 +74,10 @@ public class DateTime {
         return c.getTime();
     }
 
+    public Date asDate() {
+        return DateTime.convertToDate(year, month, day, hour, minute, second, timeZone);
+    }
+
     public Date getDate() {
         return date;
     }


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