james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [47/50] [abbrv] james-project git commit: MAILET-115 GetReplyTo should not return null but rather Optional
Date Wed, 11 Jan 2017 09:26:35 GMT
MAILET-115 GetReplyTo should not return null but rather Optional


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

Branch: refs/heads/master
Commit: 3fe5e06d7df8880ad67f4a557ee644e418abe52b
Parents: b43cb05
Author: Benoit Tellier <btellier@linagora.com>
Authored: Wed Jan 11 10:45:05 2017 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Jan 11 11:02:15 2017 +0700

----------------------------------------------------------------------
 .../org/apache/james/transport/mailets/Bounce.java    |  4 ++--
 .../org/apache/james/transport/mailets/DSNBounce.java |  4 ++--
 .../org/apache/james/transport/mailets/Forward.java   |  4 ++--
 .../james/transport/mailets/NotifyPostmaster.java     |  4 ++--
 .../apache/james/transport/mailets/NotifySender.java  |  4 ++--
 .../org/apache/james/transport/mailets/Redirect.java  |  5 ++---
 .../org/apache/james/transport/mailets/Resend.java    | 14 ++++++--------
 .../transport/mailets/redirect/RedirectNotify.java    |  2 +-
 .../org/apache/james/transport/util/ReplyToUtils.java | 14 +++++++++-----
 .../apache/james/transport/mailets/ForwardTest.java   |  2 +-
 .../apache/james/transport/util/ReplyToUtilsTest.java |  4 ++--
 11 files changed, 31 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/3fe5e06d/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 b964618..d3565b9 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
@@ -196,8 +196,8 @@ public class Bounce extends GenericMailet implements RedirectNotify {
     }
 
     @Override
-    public MailAddress getReplyTo() throws MessagingException {
-        return SpecialAddress.NULL;
+    public Optional<MailAddress> getReplyTo() throws MessagingException {
+        return Optional.of(SpecialAddress.NULL);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/3fe5e06d/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 4b39e7d..abce80b 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
@@ -184,8 +184,8 @@ public class DSNBounce extends GenericMailet implements RedirectNotify
{
     }
 
     @Override
-    public MailAddress getReplyTo() throws MessagingException {
-        return SpecialAddress.NULL;
+    public Optional<MailAddress> getReplyTo() throws MessagingException {
+        return Optional.of(SpecialAddress.NULL);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/3fe5e06d/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 2b57c0a..018ef9e 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
@@ -201,8 +201,8 @@ public class Forward extends GenericMailet implements RedirectNotify {
     }
 
     @Override
-    public MailAddress getReplyTo() throws MessagingException {
-        return null;
+    public Optional<MailAddress> getReplyTo() throws MessagingException {
+        return Optional.absent();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/3fe5e06d/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 3cfc7b2..f10cf9e 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
@@ -212,8 +212,8 @@ public class NotifyPostmaster extends GenericMailet implements RedirectNotify
{
     }
 
     @Override
-    public MailAddress getReplyTo() throws MessagingException {
-        return SpecialAddress.NULL;
+    public Optional<MailAddress> getReplyTo() throws MessagingException {
+        return Optional.of(SpecialAddress.NULL);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/3fe5e06d/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 b8b4e38..74b12c3 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
@@ -212,8 +212,8 @@ public class NotifySender extends GenericMailet implements RedirectNotify
{
     }
 
     @Override
-    public MailAddress getReplyTo() throws MessagingException {
-        return SpecialAddress.NULL;
+    public Optional<MailAddress> getReplyTo() throws MessagingException {
+        return Optional.of(SpecialAddress.NULL);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/3fe5e06d/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 5992559..e2c769e 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
@@ -407,14 +407,13 @@ public class Redirect extends GenericMailet implements RedirectNotify
{
     }
 
     @Override
-    public MailAddress getReplyTo() throws MessagingException {
+    public Optional<MailAddress> getReplyTo() throws MessagingException {
         Optional<String> replyTo = getInitParameters().getReplyTo();
         List<MailAddress> extractAddresses = AddressExtractor.withContext(getMailetContext())
                 .allowedSpecials(ImmutableList.of("postmaster", "sender", "null", "unaltered"))
                 .extract(replyTo);
         return FluentIterable.from(extractAddresses)
-                .first()
-                .orNull();
+                .first();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/3fe5e06d/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 d282c46..0f78641 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
@@ -44,6 +44,7 @@ import org.apache.mailet.MailAddress;
 import org.apache.mailet.base.GenericMailet;
 
 import com.google.common.base.Optional;
+import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableList;
 
 /**
@@ -360,19 +361,16 @@ public class Resend extends GenericMailet implements RedirectNotify
{
     }
 
     @Override
-    public MailAddress getReplyTo() throws MessagingException {
+    public Optional<MailAddress> getReplyTo() throws MessagingException {
         Optional<String> replyTo = getInitParameters().getReplyTo();
         if (!replyTo.isPresent()) {
-            return null;
+            return Optional.absent();
         }
 
-        List<MailAddress> extractAddresses = AddressExtractor.withContext(getMailetContext())
+        return FluentIterable.from(AddressExtractor.withContext(getMailetContext())
                 .allowedSpecials(ImmutableList.of("postmaster", "sender", "null", "unaltered"))
-                .extract(replyTo);
-        if (extractAddresses.isEmpty()) {
-            return null;
-        }
-        return extractAddresses.get(0);
+                .extract(replyTo))
+            .first();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/3fe5e06d/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/RedirectNotify.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/RedirectNotify.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/RedirectNotify.java
index 27cac14..b5fb65a 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/RedirectNotify.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/RedirectNotify.java
@@ -213,7 +213,7 @@ public interface RedirectNotify extends Mailet, MailetConfig {
      *         <code>SpecialAddress.UNALTERED</code> or
      *         <code>SpecialAddress.NULL</code> or <code>null</code>
if missing
      */
-    MailAddress getReplyTo() throws MessagingException;
+    Optional<MailAddress> getReplyTo() throws MessagingException;
 
     /**
      * Gets the <code>replyTo</code> property, built dynamically using the

http://git-wip-us.apache.org/repos/asf/james-project/blob/3fe5e06d/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
index 0704192..24a7eb6 100644
--- 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
@@ -28,19 +28,23 @@ import com.google.common.base.Optional;
 
 public class ReplyToUtils {
 
-    public static ReplyToUtils from(MailAddress replyTo) {
+    public static ReplyToUtils from(Optional<MailAddress> replyTo) {
         return new ReplyToUtils(replyTo);
     }
 
-    private final MailAddress replyTo;
+    public static ReplyToUtils from(MailAddress replyTo) {
+        return new ReplyToUtils(Optional.fromNullable(replyTo));
+    }
+
+    private final Optional<MailAddress> replyTo;
 
-    private ReplyToUtils(MailAddress replyTo) {
+    private ReplyToUtils(Optional<MailAddress> replyTo) {
         this.replyTo = replyTo;
     }
 
     public Optional<MailAddress> getReplyTo(Mail originalMail) throws MessagingException
{
-        if (replyTo != null) {
-            if (replyTo.equals(SpecialAddress.UNALTERED)) {
+        if (replyTo.isPresent()) {
+            if (replyTo.get().equals(SpecialAddress.UNALTERED)) {
                 return Optional.absent();
             }
             return Optional.fromNullable(originalMail.getSender());

http://git-wip-us.apache.org/repos/asf/james-project/blob/3fe5e06d/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/ForwardTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/ForwardTest.java
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/ForwardTest.java
index 46bfa08..8e7f193 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/ForwardTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/ForwardTest.java
@@ -143,7 +143,7 @@ public class ForwardTest {
 
     @Test
     public void getReplyToShouldReturnNull() throws Exception {
-        assertThat(forward.getReplyTo()).isNull();
+        assertThat(forward.getReplyTo()).isAbsent();
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/3fe5e06d/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
index 74c5440..8b5502f 100644
--- 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
@@ -30,8 +30,8 @@ import com.google.common.base.Optional;
 public class ReplyToUtilsTest {
 
     @Test
-    public void getReplyToShouldReturnNullWhenReplyToIsNull() throws Exception {
-        ReplyToUtils testee = ReplyToUtils.from(null);
+    public void getReplyToShouldReturnAbsentWhenReplyToIsNull() throws Exception {
+        ReplyToUtils testee = ReplyToUtils.from((MailAddress) null);
 
         FakeMail fakeMail = FakeMail.defaultFakeMail();
 


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