james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [16/50] [abbrv] james-project git commit: MAILET-115 Extract isUnalteredOrReversePathOrSender from AbstractRedirect to MailAddressesUtils
Date Wed, 11 Jan 2017 09:26:04 GMT
MAILET-115 Extract isUnalteredOrReversePathOrSender from AbstractRedirect to MailAddressesUtils


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

Branch: refs/heads/master
Commit: ee14bc12d40e874f4dec1a9a98aebf5332a018e9
Parents: 95f1b56
Author: Antoine Duprat <aduprat@apache.org>
Authored: Mon Nov 14 16:26:06 2016 +0100
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Jan 11 10:03:29 2017 +0700

----------------------------------------------------------------------
 .../james/transport/mailets/Redirect.java       |  2 +-
 .../apache/james/transport/mailets/Resend.java  |  2 +-
 .../mailets/redirect/AbstractRedirect.java      |  6 --
 .../james/transport/util/MailAddressUtils.java  |  7 ++
 .../transport/util/MailAddressUtilsTest.java    | 71 ++++++++++++++++++++
 5 files changed, 80 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/ee14bc12/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 d64b96c..1de0a9f 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
@@ -399,7 +399,7 @@ public class Redirect extends AbstractRedirect {
     private MailAddress retrieveReversePath() throws MessagingException {
         MailAddress reversePath = getReversePath();
         if (reversePath != null) {
-            if (isUnalteredOrReversePathOrSender(reversePath)) {
+            if (MailAddressUtils.isUnalteredOrReversePathOrSender(reversePath)) {
                 return null;
             }
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/ee14bc12/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 64c3bda..afa41e2 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
@@ -354,7 +354,7 @@ public class Resend extends AbstractRedirect {
     protected MailAddress getReversePath(Mail originalMail) throws MessagingException {
         MailAddress reversePath = getReversePath();
         if (reversePath != null) {
-            if (isUnalteredOrReversePathOrSender(reversePath)) {
+            if (MailAddressUtils.isUnalteredOrReversePathOrSender(reversePath)) {
                 return null;
             }
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/ee14bc12/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 3aaa405..97ccdbc 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
@@ -357,12 +357,6 @@ public abstract class AbstractRedirect extends GenericMailet {
      */
     protected abstract MailAddress getReversePath(Mail originalMail) throws MessagingException;
 
-    protected boolean isUnalteredOrReversePathOrSender(MailAddress reversePath) {
-        return reversePath.equals(SpecialAddress.UNALTERED)
-                || reversePath.equals(SpecialAddress.REVERSE_PATH)
-                || reversePath.equals(SpecialAddress.SENDER);
-    }
-
     /**
      * Sets the "reverse-path" of <i>newMail</i> to <i>reversePath</i>.
If the
      * requested value is <code>SpecialAddress.NULL</code> sets it to "<>".
If

http://git-wip-us.apache.org/repos/asf/james-project/blob/ee14bc12/server/mailet/mailets/src/main/java/org/apache/james/transport/util/MailAddressUtils.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/util/MailAddressUtils.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/util/MailAddressUtils.java
index cbd529b..89e1d4a 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/util/MailAddressUtils.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/util/MailAddressUtils.java
@@ -23,6 +23,7 @@ import java.util.List;
 import javax.mail.internet.AddressException;
 import javax.mail.internet.InternetAddress;
 
+import org.apache.james.transport.mailets.redirect.SpecialAddress;
 import org.apache.mailet.MailAddress;
 
 import com.google.common.base.Function;
@@ -63,4 +64,10 @@ public class MailAddressUtils {
                 }
             });
     }
+
+    public static boolean isUnalteredOrReversePathOrSender(MailAddress mailAddress) {
+        return mailAddress.equals(SpecialAddress.UNALTERED) 
+                || mailAddress.equals(SpecialAddress.REVERSE_PATH) 
+                || mailAddress.equals(SpecialAddress.SENDER);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/ee14bc12/server/mailet/mailets/src/test/java/org/apache/james/transport/util/MailAddressUtilsTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/util/MailAddressUtilsTest.java
b/server/mailet/mailets/src/test/java/org/apache/james/transport/util/MailAddressUtilsTest.java
index 820e1d3..651c19c 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/util/MailAddressUtilsTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/util/MailAddressUtilsTest.java
@@ -24,6 +24,7 @@ import java.util.List;
 
 import javax.mail.internet.InternetAddress;
 
+import org.apache.james.transport.mailets.redirect.SpecialAddress;
 import org.apache.mailet.MailAddress;
 import org.junit.Rule;
 import org.junit.Test;
@@ -98,4 +99,74 @@ public class MailAddressUtilsTest {
 
         assertThat(internetAddresses).containsOnly(new InternetAddress("user@james.org"),
new InternetAddress("user2@apache.org"));
     }
+
+    @Test
+    public void isUnalteredOrReversePathOrSenderShouldReturnTrueWhenMailAddressIsSpecialUnaltered()
{
+        boolean unalteredOrReversePathOrSender = MailAddressUtils.isUnalteredOrReversePathOrSender(SpecialAddress.UNALTERED);
+
+        assertThat(unalteredOrReversePathOrSender).isTrue();
+    }
+
+    @Test
+    public void isUnalteredOrReversePathOrSenderShouldReturnTrueWhenMailAddressIsSpecialReversePath()
{
+        boolean unalteredOrReversePathOrSender = MailAddressUtils.isUnalteredOrReversePathOrSender(SpecialAddress.REVERSE_PATH);
+
+        assertThat(unalteredOrReversePathOrSender).isTrue();
+    }
+
+    @Test
+    public void isUnalteredOrReversePathOrSenderShouldReturnTrueWhenMailAddressIsSpecialSender()
{
+        boolean unalteredOrReversePathOrSender = MailAddressUtils.isUnalteredOrReversePathOrSender(SpecialAddress.SENDER);
+
+        assertThat(unalteredOrReversePathOrSender).isTrue();
+    }
+
+    @Test
+    public void isUnalteredOrReversePathOrSenderShouldReturnFalseWhenMailAddressIsSpecialDelete()
{
+        boolean unalteredOrReversePathOrSender = MailAddressUtils.isUnalteredOrReversePathOrSender(SpecialAddress.DELETE);
+
+        assertThat(unalteredOrReversePathOrSender).isFalse();
+    }
+
+    @Test
+    public void isUnalteredOrReversePathOrSenderShouldReturnFalseWhenMailAddressIsSpecialFrom()
{
+        boolean unalteredOrReversePathOrSender = MailAddressUtils.isUnalteredOrReversePathOrSender(SpecialAddress.FROM);
+
+        assertThat(unalteredOrReversePathOrSender).isFalse();
+    }
+
+    @Test
+    public void isUnalteredOrReversePathOrSenderShouldReturnFalseWhenMailAddressIsSpecialNull()
{
+        boolean unalteredOrReversePathOrSender = MailAddressUtils.isUnalteredOrReversePathOrSender(SpecialAddress.NULL);
+
+        assertThat(unalteredOrReversePathOrSender).isFalse();
+    }
+
+    @Test
+    public void isUnalteredOrReversePathOrSenderShouldReturnFalseWhenMailAddressIsSpecialRecipients()
{
+        boolean unalteredOrReversePathOrSender = MailAddressUtils.isUnalteredOrReversePathOrSender(SpecialAddress.RECIPIENTS);
+
+        assertThat(unalteredOrReversePathOrSender).isFalse();
+    }
+
+    @Test
+    public void isUnalteredOrReversePathOrSenderShouldReturnFalseWhenMailAddressIsSpecialReplyTo()
{
+        boolean unalteredOrReversePathOrSender = MailAddressUtils.isUnalteredOrReversePathOrSender(SpecialAddress.REPLY_TO);
+
+        assertThat(unalteredOrReversePathOrSender).isFalse();
+    }
+
+    @Test
+    public void isUnalteredOrReversePathOrSenderShouldReturnFalseWhenMailAddressIsSpecialTo()
{
+        boolean unalteredOrReversePathOrSender = MailAddressUtils.isUnalteredOrReversePathOrSender(SpecialAddress.TO);
+
+        assertThat(unalteredOrReversePathOrSender).isFalse();
+    }
+
+    @Test
+    public void isUnalteredOrReversePathOrSenderShouldReturnFalseWhenMailAddressIsNotSpecial()
throws Exception {
+        boolean unalteredOrReversePathOrSender = MailAddressUtils.isUnalteredOrReversePathOrSender(new
MailAddress("common", "james.org"));
+
+        assertThat(unalteredOrReversePathOrSender).isFalse();
+    }
 }


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