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 2017/01/11 09:26:09 UTC

[21/50] [abbrv] james-project git commit: MAILET-115 Remove abstract getReplyTo with original mail implementation

MAILET-115 Remove abstract getReplyTo with original mail 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/86c61d5b
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/86c61d5b
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/86c61d5b

Branch: refs/heads/master
Commit: 86c61d5bb0068b9c29233caea7868e3af40bd76a
Parents: 63cb323
Author: Antoine Duprat <ad...@apache.org>
Authored: Thu Nov 17 14:58:06 2016 +0100
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Jan 11 10:03:30 2017 +0700

----------------------------------------------------------------------
 .../apache/james/transport/mailets/Bounce.java  |  8 ++-
 .../james/transport/mailets/DSNBounce.java      |  8 ++-
 .../apache/james/transport/mailets/Forward.java |  8 ++-
 .../transport/mailets/NotifyPostmaster.java     |  8 ++-
 .../james/transport/mailets/NotifySender.java   |  8 ++-
 .../james/transport/mailets/Redirect.java       |  8 ++-
 .../apache/james/transport/mailets/Resend.java  |  8 ++-
 .../mailets/redirect/AbstractRedirect.java      | 13 +---
 .../james/transport/util/ReplyToUtils.java      | 48 ++++++++++++++
 .../james/transport/util/ReplyToUtilsTest.java  | 66 ++++++++++++++++++++
 10 files changed, 165 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/86c61d5b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Bounce.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Bounce.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Bounce.java
index 529465f..1e53e7d 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Bounce.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Bounce.java
@@ -32,6 +32,7 @@ import org.apache.james.transport.mailets.redirect.SpecialAddress;
 import org.apache.james.transport.mailets.utils.MimeMessageModifier;
 import org.apache.james.transport.mailets.utils.MimeMessageUtils;
 import org.apache.james.transport.util.RecipientsUtils;
+import org.apache.james.transport.util.ReplyToUtils;
 import org.apache.james.transport.util.SpecialAddressesUtils;
 import org.apache.james.transport.util.TosUtils;
 import org.apache.mailet.Mail;
@@ -162,11 +163,16 @@ public class Bounce extends AbstractRedirect {
     }
 
     @Override
-    protected MailAddress getReplyTo() throws MessagingException {
+    public MailAddress getReplyTo() throws MessagingException {
         return SpecialAddress.NULL;
     }
 
     @Override
+    protected MailAddress getReplyTo(Mail originalMail) throws MessagingException {
+        return ReplyToUtils.from(getReplyTo()).getReplyTo(originalMail);
+    }
+
+    @Override
     protected MailAddress getReversePath(Mail originalMail) {
         return SpecialAddress.NULL;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/86c61d5b/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 1086497..3a388ca 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
@@ -43,6 +43,7 @@ import org.apache.james.transport.mailets.utils.MimeMessageModifier;
 import org.apache.james.transport.mailets.utils.MimeMessageUtils;
 import org.apache.james.transport.util.Patterns;
 import org.apache.james.transport.util.RecipientsUtils;
+import org.apache.james.transport.util.ReplyToUtils;
 import org.apache.james.transport.util.SpecialAddressesUtils;
 import org.apache.james.transport.util.TosUtils;
 import org.apache.mailet.Mail;
@@ -155,11 +156,16 @@ public class DSNBounce extends AbstractRedirect {
     }
 
     @Override
-    protected MailAddress getReplyTo() throws MessagingException {
+    public MailAddress getReplyTo() throws MessagingException {
         return SpecialAddress.NULL;
     }
 
     @Override
+    protected MailAddress getReplyTo(Mail originalMail) throws MessagingException {
+        return ReplyToUtils.from(getReplyTo()).getReplyTo(originalMail);
+    }
+
+    @Override
     protected MailAddress getReversePath() throws MessagingException {
         return SpecialAddressesUtils.from(this)
                 .getFirstSpecialAddressIfMatchingOrGivenAddress(getInitParameters().getReversePath(), AbstractRedirect.REVERSE_PATH_ALLOWED_SPECIALS);

http://git-wip-us.apache.org/repos/asf/james-project/blob/86c61d5b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Forward.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Forward.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Forward.java
index 414d441..ef7dfe8 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Forward.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Forward.java
@@ -32,6 +32,7 @@ import org.apache.james.transport.mailets.redirect.RedirectMailetInitParameters;
 import org.apache.james.transport.mailets.redirect.TypeCode;
 import org.apache.james.transport.mailets.utils.MimeMessageModifier;
 import org.apache.james.transport.util.RecipientsUtils;
+import org.apache.james.transport.util.ReplyToUtils;
 import org.apache.james.transport.util.TosUtils;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
@@ -166,11 +167,16 @@ public class Forward extends AbstractRedirect {
     }
 
     @Override
-    protected MailAddress getReplyTo() throws MessagingException {
+    public MailAddress getReplyTo() throws MessagingException {
         return null;
     }
 
     @Override
+    protected MailAddress getReplyTo(Mail originalMail) throws MessagingException {
+        return ReplyToUtils.from(getReplyTo()).getReplyTo(originalMail);
+    }
+
+    @Override
     protected MailAddress getReversePath() throws MessagingException {
         return null;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/86c61d5b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifyPostmaster.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifyPostmaster.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifyPostmaster.java
index dce678c..2fa826e 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifyPostmaster.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifyPostmaster.java
@@ -33,6 +33,7 @@ import org.apache.james.transport.mailets.redirect.SpecialAddress;
 import org.apache.james.transport.mailets.utils.MimeMessageModifier;
 import org.apache.james.transport.mailets.utils.MimeMessageUtils;
 import org.apache.james.transport.util.RecipientsUtils;
+import org.apache.james.transport.util.ReplyToUtils;
 import org.apache.james.transport.util.SpecialAddressesUtils;
 import org.apache.james.transport.util.TosUtils;
 import org.apache.mailet.Mail;
@@ -178,11 +179,16 @@ public class NotifyPostmaster extends AbstractRedirect {
     }
 
     @Override
-    protected MailAddress getReplyTo() throws MessagingException {
+    public MailAddress getReplyTo() throws MessagingException {
         return SpecialAddress.NULL;
     }
 
     @Override
+    protected MailAddress getReplyTo(Mail originalMail) throws MessagingException {
+        return ReplyToUtils.from(getReplyTo()).getReplyTo(originalMail);
+    }
+
+    @Override
     protected MailAddress getReversePath() throws MessagingException {
         return SpecialAddressesUtils.from(this)
                 .getFirstSpecialAddressIfMatchingOrGivenAddress(getInitParameters().getReversePath(), AbstractRedirect.REVERSE_PATH_ALLOWED_SPECIALS);

http://git-wip-us.apache.org/repos/asf/james-project/blob/86c61d5b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifySender.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifySender.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifySender.java
index e21de99..da8ccae 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifySender.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/NotifySender.java
@@ -33,6 +33,7 @@ import org.apache.james.transport.mailets.redirect.SpecialAddress;
 import org.apache.james.transport.mailets.utils.MimeMessageModifier;
 import org.apache.james.transport.mailets.utils.MimeMessageUtils;
 import org.apache.james.transport.util.RecipientsUtils;
+import org.apache.james.transport.util.ReplyToUtils;
 import org.apache.james.transport.util.SpecialAddressesUtils;
 import org.apache.james.transport.util.TosUtils;
 import org.apache.mailet.Mail;
@@ -178,11 +179,16 @@ public class NotifySender extends AbstractRedirect {
     }
 
     @Override
-    protected MailAddress getReplyTo() throws MessagingException {
+    public MailAddress getReplyTo() throws MessagingException {
         return SpecialAddress.NULL;
     }
 
     @Override
+    protected MailAddress getReplyTo(Mail originalMail) throws MessagingException {
+        return ReplyToUtils.from(getReplyTo()).getReplyTo(originalMail);
+    }
+
+    @Override
     protected MailAddress getReversePath() throws MessagingException {
         return SpecialAddressesUtils.from(this)
                 .getFirstSpecialAddressIfMatchingOrGivenAddress(getInitParameters().getReversePath(), AbstractRedirect.REVERSE_PATH_ALLOWED_SPECIALS);

http://git-wip-us.apache.org/repos/asf/james-project/blob/86c61d5b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java
index 7d78742..1632a65 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java
@@ -33,6 +33,7 @@ import org.apache.james.transport.mailets.utils.MimeMessageModifier;
 import org.apache.james.transport.mailets.utils.MimeMessageUtils;
 import org.apache.james.transport.util.MailAddressUtils;
 import org.apache.james.transport.util.RecipientsUtils;
+import org.apache.james.transport.util.ReplyToUtils;
 import org.apache.james.transport.util.SpecialAddressesUtils;
 import org.apache.james.transport.util.TosUtils;
 import org.apache.mailet.Mail;
@@ -373,7 +374,7 @@ public class Redirect extends AbstractRedirect {
     }
 
     @Override
-    protected MailAddress getReplyTo() throws MessagingException {
+    public MailAddress getReplyTo() throws MessagingException {
         String replyTo = getInitParameters().getReplyTo();
         if (Strings.isNullOrEmpty(replyTo)) {
             return null;
@@ -389,6 +390,11 @@ public class Redirect extends AbstractRedirect {
     }
 
     @Override
+    protected MailAddress getReplyTo(Mail originalMail) throws MessagingException {
+        return ReplyToUtils.from(getReplyTo()).getReplyTo(originalMail);
+    }
+
+    @Override
     protected MailAddress getReversePath() throws MessagingException {
         return SpecialAddressesUtils.from(this)
                 .getFirstSpecialAddressIfMatchingOrGivenAddress(getInitParameters().getReversePath(), ImmutableList.of("postmaster", "sender", "null"));

http://git-wip-us.apache.org/repos/asf/james-project/blob/86c61d5b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Resend.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Resend.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Resend.java
index 7d7afb4..c5929bc 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Resend.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Resend.java
@@ -32,6 +32,7 @@ import org.apache.james.transport.mailets.utils.MimeMessageModifier;
 import org.apache.james.transport.mailets.utils.MimeMessageUtils;
 import org.apache.james.transport.util.MailAddressUtils;
 import org.apache.james.transport.util.RecipientsUtils;
+import org.apache.james.transport.util.ReplyToUtils;
 import org.apache.james.transport.util.SpecialAddressesUtils;
 import org.apache.james.transport.util.TosUtils;
 import org.apache.mailet.Mail;
@@ -327,7 +328,7 @@ public class Resend extends AbstractRedirect {
     }
 
     @Override
-    protected MailAddress getReplyTo() throws MessagingException {
+    public MailAddress getReplyTo() throws MessagingException {
         String replyTo = getInitParameters().getReplyTo();
         if (Strings.isNullOrEmpty(replyTo)) {
             return null;
@@ -343,6 +344,11 @@ public class Resend extends AbstractRedirect {
     }
 
     @Override
+    protected MailAddress getReplyTo(Mail originalMail) throws MessagingException {
+        return ReplyToUtils.from(getReplyTo()).getReplyTo(originalMail);
+    }
+
+    @Override
     public List<MailAddress> getRecipients() throws MessagingException {
           ImmutableList.Builder<MailAddress> builder = ImmutableList.builder();
           List<MailAddress> mailAddresses = AddressExtractor.withContext(getMailetContext())

http://git-wip-us.apache.org/repos/asf/james-project/blob/86c61d5b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AbstractRedirect.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AbstractRedirect.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AbstractRedirect.java
index b52ce40..1a58133 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AbstractRedirect.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AbstractRedirect.java
@@ -218,7 +218,7 @@ public abstract class AbstractRedirect extends GenericMailet {
      *         <code>SpecialAddress.UNALTERED</code> or
      *         <code>SpecialAddress.NULL</code> or <code>null</code> if missing
      */
-    protected abstract MailAddress getReplyTo() throws MessagingException;
+    public abstract MailAddress getReplyTo() throws MessagingException;
 
     /**
      * Gets the <code>replyTo</code> property, built dynamically using the
@@ -228,16 +228,7 @@ public abstract class AbstractRedirect extends GenericMailet {
      *         <code>SpecialAddress.UNALTERED</code> if applicable with null and
      *         <code>SpecialAddress.SENDER</code> with the original mail sender
      */
-    protected MailAddress getReplyTo(Mail originalMail) throws MessagingException {
-        MailAddress replyTo = getReplyTo();
-        if (replyTo != null) {
-            if (replyTo.equals(SpecialAddress.UNALTERED)) {
-                return null;
-            }
-            return originalMail.getSender();
-        }
-        return null;
-    }
+    protected abstract MailAddress getReplyTo(Mail originalMail) throws MessagingException;
 
     /**
      * Gets the <code>reversePath</code> property. Returns the reverse-path of

http://git-wip-us.apache.org/repos/asf/james-project/blob/86c61d5b/server/mailet/mailets/src/main/java/org/apache/james/transport/util/ReplyToUtils.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/util/ReplyToUtils.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/util/ReplyToUtils.java
new file mode 100644
index 0000000..d06269d
--- /dev/null
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/util/ReplyToUtils.java
@@ -0,0 +1,48 @@
+/****************************************************************
+ * 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.transport.util;
+
+import javax.mail.MessagingException;
+
+import org.apache.james.transport.mailets.redirect.SpecialAddress;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+
+public class ReplyToUtils {
+
+    public static ReplyToUtils from(MailAddress replyTo) {
+        return new ReplyToUtils(replyTo);
+    }
+
+    private final MailAddress replyTo;
+
+    private ReplyToUtils(MailAddress replyTo) {
+        this.replyTo = replyTo;
+    }
+
+    public MailAddress getReplyTo(Mail originalMail) throws MessagingException {
+        if (replyTo != null) {
+            if (replyTo.equals(SpecialAddress.UNALTERED)) {
+                return null;
+            }
+            return originalMail.getSender();
+        }
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/86c61d5b/server/mailet/mailets/src/test/java/org/apache/james/transport/util/ReplyToUtilsTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/util/ReplyToUtilsTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/util/ReplyToUtilsTest.java
new file mode 100644
index 0000000..9bfa637
--- /dev/null
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/util/ReplyToUtilsTest.java
@@ -0,0 +1,66 @@
+/****************************************************************
+ * 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.transport.util;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.transport.mailets.redirect.SpecialAddress;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.base.test.FakeMail;
+import org.junit.Test;
+
+public class ReplyToUtilsTest {
+
+    @Test
+    public void getReplyToShouldReturnNullWhenReplyToIsNull() throws Exception {
+        ReplyToUtils testee = ReplyToUtils.from(null);
+
+        FakeMail fakeMail = FakeMail.defaultFakeMail();
+
+        MailAddress replyTo = testee.getReplyTo(fakeMail);
+
+        assertThat(replyTo).isNull();
+    }
+
+    @Test
+    public void getReplyToShouldReturnNullWhenReplyToEqualsToUnaltered() throws Exception {
+        ReplyToUtils testee = ReplyToUtils.from(SpecialAddress.UNALTERED);
+
+        FakeMail fakeMail = FakeMail.defaultFakeMail();
+
+        MailAddress replyTo = testee.getReplyTo(fakeMail);
+
+        assertThat(replyTo).isNull();
+    }
+
+    @Test
+    public void getReplyToShouldReturnSenderWhenReplyToIsCommon() throws Exception {
+        MailAddress mailAddress = new MailAddress("test", "james.org");
+        ReplyToUtils testee = ReplyToUtils.from(mailAddress);
+
+        MailAddress expectedMailAddress = new MailAddress("sender", "james.org");
+        FakeMail fakeMail = FakeMail.builder()
+                .sender(expectedMailAddress)
+                .build();
+
+        MailAddress replyTo = testee.getReplyTo(fakeMail);
+
+        assertThat(replyTo).isEqualTo(expectedMailAddress);
+    }
+}


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