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 ro...@apache.org on 2016/09/08 14:37:17 UTC

james-project git commit: MAILET-132 Use existing thread safe DateFormat implementation

Repository: james-project
Updated Branches:
  refs/heads/master e17d56791 -> e0e8581a8


MAILET-132 Use existing thread safe DateFormat implementation


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

Branch: refs/heads/master
Commit: e0e8581a8e30323e26fc532d5a125e55aa37ba25
Parents: e17d567
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Thu Sep 8 15:45:15 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Thu Sep 8 16:36:11 2016 +0200

----------------------------------------------------------------------
 mailet/base/pom.xml                             |  23 +--
 .../org/apache/mailet/base/DateFormats.java     |  33 ++++
 .../apache/mailet/base/RFC2980DateFormat.java   |  38 -----
 .../apache/mailet/base/RFC822DateFormat.java    |  64 -------
 .../apache/mailet/base/RFC977DateFormat.java    | 157 -----------------
 .../mailet/base/SimplifiedDateFormat.java       |  86 ----------
 .../mailet/base/SynchronizedDateFormat.java     | 167 -------------------
 mailet/pom.xml                                  |   1 +
 .../transport/mailets/AbstractRedirect.java     |  44 +++--
 .../james/transport/mailets/DSNBounce.java      |  37 ++--
 .../transport/mailets/WhiteListManager.java     |   7 +-
 11 files changed, 84 insertions(+), 573 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/e0e8581a/mailet/base/pom.xml
----------------------------------------------------------------------
diff --git a/mailet/base/pom.xml b/mailet/base/pom.xml
index 38bf3da..d67639f 100644
--- a/mailet/base/pom.xml
+++ b/mailet/base/pom.xml
@@ -45,9 +45,17 @@
             <artifactId>apache-mailet-api</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.james</groupId>
+            <artifactId>apache-mime4j-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+            <version>${commons-lang.version}</version>
+        </dependency>
+        <dependency>
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
-            <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>javax.activation</groupId>
@@ -63,24 +71,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.james</groupId>
-            <artifactId>apache-mime4j-core</artifactId>
-        </dependency>
-        <dependency>
             <groupId>org.assertj</groupId>
             <artifactId>assertj-core</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>com.google.guava</groupId>
-            <artifactId>guava</artifactId>
-        </dependency>
-        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/james-project/blob/e0e8581a/mailet/base/src/main/java/org/apache/mailet/base/DateFormats.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/main/java/org/apache/mailet/base/DateFormats.java b/mailet/base/src/main/java/org/apache/mailet/base/DateFormats.java
new file mode 100644
index 0000000..0120a81
--- /dev/null
+++ b/mailet/base/src/main/java/org/apache/mailet/base/DateFormats.java
@@ -0,0 +1,33 @@
+/****************************************************************
+ * 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.mailet.base;
+
+import java.util.Locale;
+
+import org.apache.commons.lang.time.FastDateFormat;
+
+public interface DateFormats {
+    FastDateFormat RFC822_DATE_FORMAT = FastDateFormat.getInstance("EEE, d MMM yyyy HH:mm:ss 'XXXXX' (z)", Locale.US);
+    FastDateFormat RFC977_SHORT_DATE_FORMAT = FastDateFormat.getInstance("yyMMdd HHmmss", Locale.US);
+    FastDateFormat RFC977_LONG_DATE_FORMAT = FastDateFormat.getInstance("yyyyMMdd HHmmss", Locale.US);
+    FastDateFormat RFC2980_LONG_DATE_FORMAT = FastDateFormat.getInstance("yyyyMMddHHmmss", Locale.US);
+}
+

http://git-wip-us.apache.org/repos/asf/james-project/blob/e0e8581a/mailet/base/src/main/java/org/apache/mailet/base/RFC2980DateFormat.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/main/java/org/apache/mailet/base/RFC2980DateFormat.java b/mailet/base/src/main/java/org/apache/mailet/base/RFC2980DateFormat.java
deleted file mode 100644
index 1e8e751..0000000
--- a/mailet/base/src/main/java/org/apache/mailet/base/RFC2980DateFormat.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/****************************************************************
- * 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.mailet.base;
-
-import java.util.Locale;
-
-/**
- * A thread-safe date formatting class to produce dates formatted in accord with the
- * specifications of section 3.2 of RFC 2980.
- *
- */
-public class RFC2980DateFormat extends SynchronizedDateFormat {
-
-    /**
-     * Constructor for RFC2980DateFormat
-     */
-    public RFC2980DateFormat() {
-        super("yyyyMMddHHmmss", Locale.ENGLISH);
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/e0e8581a/mailet/base/src/main/java/org/apache/mailet/base/RFC822DateFormat.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/main/java/org/apache/mailet/base/RFC822DateFormat.java b/mailet/base/src/main/java/org/apache/mailet/base/RFC822DateFormat.java
deleted file mode 100644
index d66929c..0000000
--- a/mailet/base/src/main/java/org/apache/mailet/base/RFC822DateFormat.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/****************************************************************
- * 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.mailet.base;
-
-import java.util.Date;
-
-import javax.mail.internet.MailDateFormat;
-
-
-/**
- * A thread safe wrapper for the <code>javax.mail.internet.MailDateFormat</code> class.
- *
- */
-public class RFC822DateFormat extends SynchronizedDateFormat {
-    /**
-     * A static instance of the RFC822DateFormat, used by toString
-     */
-    private static final RFC822DateFormat instance;
-
-    static {
-        instance = new RFC822DateFormat();
-    }
-
-    /**
-     * This static method allows us to format RFC822 dates without
-     * explicitly instantiating an RFC822DateFormat object.
-     *
-     * @return java.lang.String
-     * @param d Date
-     *
-     * @deprecated This method is not necessary and is preserved for API
-     *             backwards compatibility.  Users of this class should
-     *             instantiate an instance and use it as they would any
-     *             other DateFormat object.
-     */
-    public static String toString(Date d) {
-        return instance.format(d);
-    }
-
-    /**
-     * Constructor for RFC822DateFormat
-     */
-    public RFC822DateFormat() {
-        super(new MailDateFormat());
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/e0e8581a/mailet/base/src/main/java/org/apache/mailet/base/RFC977DateFormat.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/main/java/org/apache/mailet/base/RFC977DateFormat.java b/mailet/base/src/main/java/org/apache/mailet/base/RFC977DateFormat.java
deleted file mode 100644
index 8668603..0000000
--- a/mailet/base/src/main/java/org/apache/mailet/base/RFC977DateFormat.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/****************************************************************
- * 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.mailet.base;
-
-import java.text.ParseException;
-import java.util.Date;
-import java.util.Locale;
-import java.util.TimeZone;
-
-/**
- * A thread-safe date formatting class to produce dates formatted in accord with the
- * specifications of RFC 977.
- *
- */
-public class RFC977DateFormat implements SimplifiedDateFormat {
-
-    /**
-     * Internal date formatter for long date formats
-     */
-    private final SynchronizedDateFormat internalLongDateFormat;
-
-    /**
-     * Internal date formatter for short date formats
-     */
-    private final SynchronizedDateFormat internalShortDateFormat;
-
-    /**
-     * Constructor for RFC977DateFormat
-     */
-    public RFC977DateFormat() {
-        internalLongDateFormat = new SynchronizedDateFormat("yyyyMMdd HHmmss", Locale.ENGLISH);
-        internalShortDateFormat = new SynchronizedDateFormat("yyMMdd HHmmss", Locale.ENGLISH);
-    }
-
-    /**
-     * This method returns the long form of the RFC977 Date
-     *
-     * @return java.lang.String
-     * @param d Date
-     */
-    public String format(Date d) {
-        return internalLongDateFormat.format(d);
-    }
-
-    /**
-     * Parses text from the beginning of the given string to produce a date.
-     * The method may not use the entire text of the given string.
-     * <p>
-     * This method is designed to be thread safe, so we wrap our delegated
-     * parse method in an appropriate synchronized block.
-     *
-     * @param source A <code>String</code> whose beginning should be parsed.
-     * @return A <code>Date</code> parsed from the string.
-     * @throws ParseException if the beginning of the specified string
-     *         cannot be parsed.
-     */
-    public Date parse(String source) throws ParseException {
-        source = source.trim();
-        if (source.indexOf(' ') == 6) {
-            return internalShortDateFormat.parse(source);
-        } else {
-            return internalLongDateFormat.parse(source);
-        }
-    }
-
-    /**
-     * Sets the time zone of this SynchronizedDateFormat object.
-     * @param zone the given new time zone.
-     */
-    public void setTimeZone(TimeZone zone) {
-        synchronized(this) {
-            internalShortDateFormat.setTimeZone(zone);
-            internalLongDateFormat.setTimeZone(zone);
-        }
-    }
-
-    /**
-     * Gets the time zone.
-     * @return the time zone associated with this SynchronizedDateFormat.
-     */
-    public TimeZone getTimeZone() {
-        synchronized(this) {
-            return internalShortDateFormat.getTimeZone();
-        }
-    }
-
-    /**
-     * Specify whether or not date/time parsing is to be lenient.  With
-     * lenient parsing, the parser may use heuristics to interpret inputs that
-     * do not precisely match this object's format.  With strict parsing,
-     * inputs must match this object's format.
-     * @param lenient when true, parsing is lenient
-     * @see java.util.Calendar#setLenient
-     */
-    public void setLenient(boolean lenient)
-    {
-        synchronized(this) {
-            internalShortDateFormat.setLenient(lenient);
-            internalLongDateFormat.setLenient(lenient);
-        }
-    }
-
-    /**
-     * Tell whether date/time parsing is to be lenient.
-     * @return whether this SynchronizedDateFormat is lenient.
-     */
-    public boolean isLenient()
-    {
-        synchronized(this) {
-            return internalShortDateFormat.isLenient();
-        }
-    }
-
-
-    /**
-     * Overrides equals
-     */
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!(obj instanceof RFC977DateFormat)) {
-            return false;
-        }
-        RFC977DateFormat theOtherRFC977DateFormat = (RFC977DateFormat)obj;
-        synchronized (this) {
-            return ((internalShortDateFormat.equals(theOtherRFC977DateFormat.internalShortDateFormat)) &&
-                    (internalLongDateFormat.equals(theOtherRFC977DateFormat.internalLongDateFormat)));
-        }
-    }
-
-    /**
-     * Overrides hashCode
-     */
-    public int hashCode() {
-        return internalLongDateFormat.hashCode() & internalShortDateFormat.hashCode();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/e0e8581a/mailet/base/src/main/java/org/apache/mailet/base/SimplifiedDateFormat.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/main/java/org/apache/mailet/base/SimplifiedDateFormat.java b/mailet/base/src/main/java/org/apache/mailet/base/SimplifiedDateFormat.java
deleted file mode 100644
index 7d0e975..0000000
--- a/mailet/base/src/main/java/org/apache/mailet/base/SimplifiedDateFormat.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/****************************************************************
- * 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.mailet.base;
-
-import java.text.ParseException;
-import java.util.Date;
-import java.util.TimeZone;
-
-/**
- * <p>This interface is designed to provide a simplified subset of the
- * methods provided by the <code>java.text.DateFormat</code> class.</p>
- *
- * <p>This interface is necessary because of the difficulty in writing
- * thread safe classes that inherit from <code>java.text.DateFormat</code>.
- * This difficulty leads us to approach the problem using composition
- * rather than inheritance.  In general classes that implement this
- * interface will delegate these calls to an internal DateFormat object.</p>
- *
- */
-public interface SimplifiedDateFormat {
-
-    /**
-     * Formats a Date into a date/time string.
-     * @param d the time value to be formatted into a time string.
-     * @return the formatted time string.
-     */
-    String format(Date d);
-
-    /**
-     * Parses text from the beginning of the given string to produce a date.
-     * The method may not use the entire text of the given string.
-     *
-     * @param source A <code>String</code> whose beginning should be parsed.
-     * @return A <code>Date</code> parsed from the string.
-     * @throws ParseException if the beginning of the specified string
-     *         cannot be parsed.
-     */
-    Date parse(String source) throws ParseException;
-
-    /**
-     * Sets the time zone of this SimplifiedDateFormat object.
-     * @param zone the given new time zone.
-     */
-    void setTimeZone(TimeZone zone);
-
-    /**
-     * Gets the time zone.
-     * @return the time zone associated with this SimplifiedDateFormat.
-     */
-    TimeZone getTimeZone();
-
-    /**
-     * Specify whether or not date/time parsing is to be lenient.  With
-     * lenient parsing, the parser may use heuristics to interpret inputs that
-     * do not precisely match this object's format.  With strict parsing,
-     * inputs must match this object's format.
-     * @param lenient when true, parsing is lenient
-     * @see java.util.Calendar#setLenient
-     */
-    void setLenient(boolean lenient);
-
-    /**
-     * Tell whether date/time parsing is to be lenient.
-     * @return whether this SimplifiedDateFormat is lenient.
-     */
-    boolean isLenient();
-}
-

http://git-wip-us.apache.org/repos/asf/james-project/blob/e0e8581a/mailet/base/src/main/java/org/apache/mailet/base/SynchronizedDateFormat.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/main/java/org/apache/mailet/base/SynchronizedDateFormat.java b/mailet/base/src/main/java/org/apache/mailet/base/SynchronizedDateFormat.java
deleted file mode 100644
index f9fc2ad..0000000
--- a/mailet/base/src/main/java/org/apache/mailet/base/SynchronizedDateFormat.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/****************************************************************
- * 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.mailet.base;
-
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.TimeZone;
-
-
-/**
- * This class is designed to be a synchronized wrapper for a
- * <code>java.text.DateFormat</code> subclass.  In general,
- * these subclasses (most notably the <code>java.text.SimpleDateFormat</code>
- * classes are not thread safe, so we need to synchronize on the
- * internal DateFormat for all delegated calls.
- *
- */
-public class SynchronizedDateFormat implements SimplifiedDateFormat {
-    private final DateFormat internalDateFormat;
-
-    /**
-     * Public constructor that mimics that of SimpleDateFormat.  See
-     * java.text.SimpleDateFormat for more details.
-     *
-     * @param pattern the pattern that defines this DateFormat
-     * @param locale the locale
-     */
-    public SynchronizedDateFormat(String pattern, Locale locale) {
-        internalDateFormat = new SimpleDateFormat(pattern, locale);
-    }
-
-    /**
-     * <p>Wrapper method to allow child classes to synchronize a preexisting
-     * DateFormat.</p>
-     *
-     * <p>TODO: Investigate replacing this with a factory method.</p>
-     *
-     * @param theDateFormat the DateFormat to synchronize
-     */
-    protected SynchronizedDateFormat(DateFormat theDateFormat) {
-        internalDateFormat = theDateFormat;
-    }
-
-    /**
-     * SimpleDateFormat will handle most of this for us, but we
-     * want to ensure thread safety, so we wrap the call in a
-     * synchronized block.
-     *
-     * @return java.lang.String
-     * @param d Date
-     */
-    public String format(Date d) {
-        synchronized (internalDateFormat) {
-           return internalDateFormat.format(d);
-        }
-    }
-
-    /**
-     * Parses text from the beginning of the given string to produce a date.
-     * The method may not use the entire text of the given string.
-     * <p>
-     * This method is designed to be thread safe, so we wrap our delegated
-     * parse method in an appropriate synchronized block.
-     *
-     * @param source A <code>String</code> whose beginning should be parsed.
-     * @return A <code>Date</code> parsed from the string.
-     * @throws ParseException if the beginning of the specified string
-     *         cannot be parsed.
-     */
-    public Date parse(String source) throws ParseException {
-        synchronized (internalDateFormat) {
-            return internalDateFormat.parse(source);
-        }
-    }
-
-    /**
-     * Sets the time zone of this SynchronizedDateFormat object.
-     * @param zone the given new time zone.
-     */
-    public void setTimeZone(TimeZone zone) {
-        synchronized(internalDateFormat) {
-            internalDateFormat.setTimeZone(zone);
-        }
-    }
-
-    /**
-     * Gets the time zone.
-     * @return the time zone associated with this SynchronizedDateFormat.
-     */
-    public TimeZone getTimeZone() {
-        synchronized(internalDateFormat) {
-            return internalDateFormat.getTimeZone();
-        }
-    }
-
-    /**
-     * Specify whether or not date/time parsing is to be lenient.  With
-     * lenient parsing, the parser may use heuristics to interpret inputs that
-     * do not precisely match this object's format.  With strict parsing,
-     * inputs must match this object's format.
-     * @param lenient when true, parsing is lenient
-     * @see java.util.Calendar#setLenient
-     */
-    public void setLenient(boolean lenient)
-    {
-        synchronized(internalDateFormat) {
-            internalDateFormat.setLenient(lenient);
-        }
-    }
-
-    /**
-     * Tell whether date/time parsing is to be lenient.
-     * @return whether this SynchronizedDateFormat is lenient.
-     */
-    public boolean isLenient()
-    {
-        synchronized(internalDateFormat) {
-            return internalDateFormat.isLenient();
-        }
-    }
-
-    /**
-     * Overrides hashCode
-     */
-    public int hashCode() {
-        synchronized(internalDateFormat) {
-            return internalDateFormat.hashCode();
-        }
-    }
-
-    /**
-     * Overrides equals
-     */
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null || getClass() != obj.getClass()) {
-            return false;
-        }
-        synchronized(internalDateFormat) {
-            return internalDateFormat.equals(obj);
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/e0e8581a/mailet/pom.xml
----------------------------------------------------------------------
diff --git a/mailet/pom.xml b/mailet/pom.xml
index f1ac89e..8ddde4a 100644
--- a/mailet/pom.xml
+++ b/mailet/pom.xml
@@ -47,6 +47,7 @@
         <bcmail-jdk16.version>1.46</bcmail-jdk16.version>
         <commons-collections.version>3.2.1</commons-collections.version>
         <commons-io.version>2.4</commons-io.version>
+        <commons-lang.version>2.6</commons-lang.version>
         <httpclient-osgi.version>4.5.1</httpclient-osgi.version>
         <!-- maven-mailetdocs-plugin artifacts -->
         <maven-artifact.version>3.0-alpha-1</maven-artifact.version>

http://git-wip-us.apache.org/repos/asf/james-project/blob/e0e8581a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/AbstractRedirect.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/AbstractRedirect.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/AbstractRedirect.java
index 8c97c57..34c3b4e 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/AbstractRedirect.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/AbstractRedirect.java
@@ -19,16 +19,16 @@
 
 package org.apache.james.transport.mailets;
 
-import com.google.common.base.Throwables;
-
-import org.apache.james.core.MailImpl;
-import org.apache.james.core.MimeMessageUtil;
-import org.apache.james.dnsservice.api.DNSService;
-import org.apache.mailet.Mail;
-import org.apache.mailet.MailAddress;
-import org.apache.mailet.base.GenericMailet;
-import org.apache.mailet.base.RFC2822Headers;
-import org.apache.mailet.base.RFC822DateFormat;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Locale;
 
 import javax.inject.Inject;
 import javax.mail.Message;
@@ -40,16 +40,16 @@ import javax.mail.internet.MimeMessage;
 import javax.mail.internet.MimeMultipart;
 import javax.mail.internet.ParseException;
 
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Locale;
+import org.apache.james.core.MailImpl;
+import org.apache.james.core.MimeMessageUtil;
+import org.apache.james.dnsservice.api.DNSService;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.base.GenericMailet;
+import org.apache.mailet.base.RFC2822Headers;
+import org.apache.mailet.base.DateFormats;
+
+import com.google.common.base.Throwables;
 
 /**
  * <p>
@@ -238,8 +238,6 @@ public abstract class AbstractRedirect extends GenericMailet {
     private boolean attachError = false;
     private boolean isReply = false;
 
-    private final RFC822DateFormat rfc822DateFormat = new RFC822DateFormat();
-
     protected DNSService dns;
 
     @Inject
@@ -1013,7 +1011,7 @@ public abstract class AbstractRedirect extends GenericMailet {
             setSubjectPrefix(newMail, getSubjectPrefix(originalMail), originalMail);
 
             if (newMail.getMessage().getHeader(RFC2822Headers.DATE) == null) {
-                newMail.getMessage().setHeader(RFC2822Headers.DATE, rfc822DateFormat.format(new Date()));
+                newMail.getMessage().setHeader(RFC2822Headers.DATE, DateFormats.RFC822_DATE_FORMAT.format(new Date()));
             }
 
             setReplyTo(newMail, getReplyTo(originalMail), originalMail);

http://git-wip-us.apache.org/repos/asf/james-project/blob/e0e8581a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
index 360ef32..d0a28e4 100755
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
@@ -19,21 +19,6 @@
 
 package org.apache.james.transport.mailets;
 
-import org.apache.james.core.MailImpl;
-import org.apache.james.protocols.smtp.dsn.DSNStatus;
-import org.apache.james.transport.util.Patterns;
-import org.apache.mailet.Mail;
-import org.apache.mailet.MailAddress;
-import org.apache.mailet.base.RFC2822Headers;
-import org.apache.mailet.base.RFC822DateFormat;
-import org.apache.mailet.base.mail.MimeMultipartReport;
-
-import javax.mail.MessagingException;
-import javax.mail.SendFailedException;
-import javax.mail.Session;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeBodyPart;
-import javax.mail.internet.MimeMessage;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.net.ConnectException;
@@ -46,6 +31,22 @@ import java.util.HashSet;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import javax.mail.MessagingException;
+import javax.mail.SendFailedException;
+import javax.mail.Session;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.james.core.MailImpl;
+import org.apache.james.protocols.smtp.dsn.DSNStatus;
+import org.apache.james.transport.util.Patterns;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.base.RFC2822Headers;
+import org.apache.mailet.base.DateFormats;
+import org.apache.mailet.base.mail.MimeMultipartReport;
+
 /**
  * <p>
  * Generates a Delivery Status Notification (DSN) Note that this is different
@@ -88,8 +89,6 @@ import java.util.regex.Pattern;
 
 public class DSNBounce extends AbstractNotify {
 
-    private static final RFC822DateFormat rfc822DateFormat = new RFC822DateFormat();
-
     public static final String STATUS_PATTERN_STRING = ".*\\s*([245]\\.\\d{1,3}\\.\\d{1,3}).*\\s*";
     public static final String DIAG_PATTERN_STRING = "^\\d{3}\\s.*$";
 
@@ -193,7 +192,7 @@ public class DSNBounce extends AbstractNotify {
             setTo(newMail, getTo(originalMail), originalMail);
             setSubjectPrefix(newMail, getSubjectPrefix(originalMail), originalMail);
             if (newMail.getMessage().getHeader(RFC2822Headers.DATE) == null) {
-                newMail.getMessage().setHeader(RFC2822Headers.DATE, rfc822DateFormat.format(new Date()));
+                newMail.getMessage().setHeader(RFC2822Headers.DATE, DateFormats.RFC822_DATE_FORMAT.format(new Date()));
             }
             setReplyTo(newMail, getReplyTo(originalMail), originalMail);
             setReversePath(newMail, getReversePath(originalMail), originalMail);
@@ -355,7 +354,7 @@ public class DSNBounce extends AbstractNotify {
             out.println("Diagnostic-Code: " + diagnosticType + "; " + diagnosticCode);
 
             // optional: last attempt
-            out.println("Last-Attempt-Date: " + rfc822DateFormat.format(originalMail.getLastUpdated()));
+            out.println("Last-Attempt-Date: " + DateFormats.RFC822_DATE_FORMAT.format(originalMail.getLastUpdated()));
 
             // optional: retry until
             // only for 'delayed' reports .. but we don't report this (at least

http://git-wip-us.apache.org/repos/asf/james-project/blob/e0e8581a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/WhiteListManager.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/WhiteListManager.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/WhiteListManager.java
index feecb95..511e511 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/WhiteListManager.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/WhiteListManager.java
@@ -54,7 +54,7 @@ import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.base.GenericMailet;
 import org.apache.mailet.base.RFC2822Headers;
-import org.apache.mailet.base.RFC822DateFormat;
+import org.apache.mailet.base.DateFormats;
 
 /**
  * <p>
@@ -132,9 +132,6 @@ public class WhiteListManager extends GenericMailet {
     private String insert;
     private String deleteByPK;
 
-    /** The date format object used to generate RFC 822 compliant date headers. */
-    private final RFC822DateFormat rfc822DateFormat = new RFC822DateFormat();
-
     private DataSource datasource;
 
     /**
@@ -701,7 +698,7 @@ public class WhiteListManager extends GenericMailet {
 
             // Set additional headers
             if (reply.getHeader(RFC2822Headers.DATE) == null) {
-                reply.setHeader(RFC2822Headers.DATE, rfc822DateFormat.format(new java.util.Date()));
+                reply.setHeader(RFC2822Headers.DATE, DateFormats.RFC822_DATE_FORMAT.format(new java.util.Date()));
             }
             String subject = message.getSubject();
             if (subject == null) {


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