james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [37/50] [abbrv] james-project git commit: MAILET-115 Remove abstract getSender with original mail implementation
Date Wed, 11 Jan 2017 09:26:25 GMT
MAILET-115 Remove abstract getSender 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/6a87096d
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/6a87096d
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/6a87096d

Branch: refs/heads/master
Commit: 6a87096da675bf1f173bf737f62467890f2e585b
Parents: 86c61d5
Author: Antoine Duprat <aduprat@apache.org>
Authored: Thu Nov 17 15:04:01 2016 +0100
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Jan 11 10:03:31 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     | 10 ++-
 .../james/transport/mailets/NotifySender.java   | 10 ++-
 .../james/transport/mailets/Redirect.java       | 10 ++-
 .../apache/james/transport/mailets/Resend.java  |  8 ++-
 .../mailets/redirect/AbstractRedirect.java      | 23 ++----
 .../mailets/redirect/MailModifier.java          |  7 +-
 .../james/transport/util/SenderUtils.java       | 53 ++++++++++++++
 .../james/transport/util/SenderUtilsTest.java   | 76 ++++++++++++++++++++
 11 files changed, 190 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/6a87096d/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 1e53e7d..d3c8595 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
@@ -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.RecipientsUtils;
 import org.apache.james.transport.util.ReplyToUtils;
+import org.apache.james.transport.util.SenderUtils;
 import org.apache.james.transport.util.SpecialAddressesUtils;
 import org.apache.james.transport.util.TosUtils;
 import org.apache.mailet.Mail;
@@ -184,12 +185,17 @@ public class Bounce extends AbstractRedirect {
     }
 
     @Override
-    protected MailAddress getSender() throws MessagingException {
+    public MailAddress getSender() throws MessagingException {
         return SpecialAddressesUtils.from(this)
                 .getFirstSpecialAddressIfMatchingOrGivenAddress(getInitParameters().getSender(),
AbstractRedirect.SENDER_ALLOWED_SPECIALS);
     }
 
     @Override
+    protected Optional<MailAddress> getSender(Mail originalMail) throws MessagingException
{
+        return SenderUtils.from(getSender()).getSender(originalMail);
+    }
+
+    @Override
     protected Optional<String> getSubjectPrefix(Mail newMail, String subjectPrefix,
Mail originalMail) throws MessagingException {
         return new MimeMessageUtils(originalMail.getMessage()).subjectWithPrefix(subjectPrefix);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/6a87096d/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 3a388ca..3fba468 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
@@ -44,6 +44,7 @@ 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.SenderUtils;
 import org.apache.james.transport.util.SpecialAddressesUtils;
 import org.apache.james.transport.util.TosUtils;
 import org.apache.mailet.Mail;
@@ -177,12 +178,17 @@ public class DSNBounce extends AbstractRedirect {
     }
 
     @Override
-    protected MailAddress getSender() throws MessagingException {
+    public MailAddress getSender() throws MessagingException {
         return SpecialAddressesUtils.from(this)
                 .getFirstSpecialAddressIfMatchingOrGivenAddress(getInitParameters().getSender(),
AbstractRedirect.SENDER_ALLOWED_SPECIALS);
     }
 
     @Override
+    protected Optional<MailAddress> getSender(Mail originalMail) throws MessagingException
{
+        return SenderUtils.from(getSender()).getSender(originalMail);
+    }
+
+    @Override
     protected Optional<String> getSubjectPrefix(Mail newMail, String subjectPrefix,
Mail originalMail) throws MessagingException {
         return new MimeMessageUtils(originalMail.getMessage()).subjectWithPrefix(subjectPrefix);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/6a87096d/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 ef7dfe8..97bd62b 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
@@ -33,6 +33,7 @@ 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.SenderUtils;
 import org.apache.james.transport.util.TosUtils;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
@@ -187,11 +188,16 @@ public class Forward extends AbstractRedirect {
     }
 
     @Override
-    protected MailAddress getSender() throws MessagingException {
+    public MailAddress getSender() throws MessagingException {
         return null;
     }
 
     @Override
+    protected Optional<MailAddress> getSender(Mail originalMail) throws MessagingException
{
+        return SenderUtils.from(getSender()).getSender(originalMail);
+    }
+
+    @Override
     protected Optional<String> getSubjectPrefix(Mail newMail, String subjectPrefix,
Mail originalMail) throws MessagingException {
         return Optional.absent();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/6a87096d/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 2fa826e..8059811 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
@@ -34,6 +34,7 @@ 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.SenderUtils;
 import org.apache.james.transport.util.SpecialAddressesUtils;
 import org.apache.james.transport.util.TosUtils;
 import org.apache.mailet.Mail;
@@ -196,16 +197,21 @@ public class NotifyPostmaster extends AbstractRedirect {
 
     @Override
     protected MailAddress getReversePath(Mail originalMail) throws MessagingException {
-        return getSender(originalMail);
+        return getSender(originalMail).orNull();
     }
 
     @Override
-    protected MailAddress getSender() throws MessagingException {
+    public MailAddress getSender() throws MessagingException {
         return SpecialAddressesUtils.from(this)
                 .getFirstSpecialAddressIfMatchingOrGivenAddress(getInitParameters().getSender(),
AbstractRedirect.SENDER_ALLOWED_SPECIALS);
     }
 
     @Override
+    protected Optional<MailAddress> getSender(Mail originalMail) throws MessagingException
{
+        return SenderUtils.from(getSender()).getSender(originalMail);
+    }
+
+    @Override
     protected Optional<String> getSubjectPrefix(Mail newMail, String subjectPrefix,
Mail originalMail) throws MessagingException {
         return new MimeMessageUtils(originalMail.getMessage()).subjectWithPrefix(subjectPrefix);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/6a87096d/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 da8ccae..3db3d39 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
@@ -34,6 +34,7 @@ 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.SenderUtils;
 import org.apache.james.transport.util.SpecialAddressesUtils;
 import org.apache.james.transport.util.TosUtils;
 import org.apache.mailet.Mail;
@@ -196,16 +197,21 @@ public class NotifySender extends AbstractRedirect {
 
     @Override
     protected MailAddress getReversePath(Mail originalMail) throws MessagingException {
-        return getSender(originalMail);
+        return getSender(originalMail).orNull();
     }
 
     @Override
-    protected MailAddress getSender() throws MessagingException {
+    public MailAddress getSender() throws MessagingException {
         return SpecialAddressesUtils.from(this)
                 .getFirstSpecialAddressIfMatchingOrGivenAddress(getInitParameters().getSender(),
AbstractRedirect.SENDER_ALLOWED_SPECIALS);
     }
 
     @Override
+    protected Optional<MailAddress> getSender(Mail originalMail) throws MessagingException
{
+        return SenderUtils.from(getSender()).getSender(originalMail);
+    }
+
+    @Override
     protected Optional<String> getSubjectPrefix(Mail newMail, String subjectPrefix,
Mail originalMail) throws MessagingException {
         return new MimeMessageUtils(originalMail.getMessage()).subjectWithPrefix(subjectPrefix);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/6a87096d/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 1632a65..43e4e98 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
@@ -34,6 +34,7 @@ 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.SenderUtils;
 import org.apache.james.transport.util.SpecialAddressesUtils;
 import org.apache.james.transport.util.TosUtils;
 import org.apache.mailet.Mail;
@@ -406,7 +407,7 @@ public class Redirect extends AbstractRedirect {
         if (reversePath != null) {
             return reversePath;
         }
-        return getSender(originalMail);
+        return getSender(originalMail).orNull();
     }
 
     private MailAddress retrieveReversePath() throws MessagingException {
@@ -420,12 +421,17 @@ public class Redirect extends AbstractRedirect {
     }
 
     @Override
-    protected MailAddress getSender() throws MessagingException {
+    public MailAddress getSender() throws MessagingException {
         return SpecialAddressesUtils.from(this)
                 .getFirstSpecialAddressIfMatchingOrGivenAddress(getInitParameters().getSender(),
AbstractRedirect.SENDER_ALLOWED_SPECIALS);
     }
 
     @Override
+    protected Optional<MailAddress> getSender(Mail originalMail) throws MessagingException
{
+        return SenderUtils.from(getSender()).getSender(originalMail);
+    }
+
+    @Override
     protected Optional<String> getSubjectPrefix(Mail newMail, String subjectPrefix,
Mail originalMail) throws MessagingException {
         return new MimeMessageUtils(newMail.getMessage()).subjectWithPrefix(subjectPrefix,
originalMail, getInitParameters().getSubject());
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/6a87096d/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 c5929bc..a5869d5 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
@@ -33,6 +33,7 @@ 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.SenderUtils;
 import org.apache.james.transport.util.SpecialAddressesUtils;
 import org.apache.james.transport.util.TosUtils;
 import org.apache.mailet.Mail;
@@ -383,12 +384,17 @@ public class Resend extends AbstractRedirect {
     }
 
     @Override
-    protected MailAddress getSender() throws MessagingException {
+    public MailAddress getSender() throws MessagingException {
         return SpecialAddressesUtils.from(this)
                 .getFirstSpecialAddressIfMatchingOrGivenAddress(getInitParameters().getSender(),
AbstractRedirect.SENDER_ALLOWED_SPECIALS);
     }
 
     @Override
+    protected Optional<MailAddress> getSender(Mail originalMail) throws MessagingException
{
+        return SenderUtils.from(getSender()).getSender(originalMail);
+    }
+
+    @Override
     protected Optional<String> getSubjectPrefix(Mail newMail, String subjectPrefix,
Mail originalMail) throws MessagingException {
         return new MimeMessageUtils(newMail.getMessage()).subjectWithPrefix(subjectPrefix,
originalMail, getInitParameters().getSubject());
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/6a87096d/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 1a58133..528e604 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
@@ -264,7 +264,7 @@ public abstract class AbstractRedirect extends GenericMailet {
      *         <code>SpecialAddress.UNALTERED</code> or <code>null</code>
if
      *         missing
      */
-    protected abstract MailAddress getSender() throws MessagingException; 
+    public abstract MailAddress getSender() throws MessagingException; 
 
     /**
      * Gets the <code>sender</code> property, built dynamically using the
@@ -274,19 +274,7 @@ public abstract class AbstractRedirect extends GenericMailet {
      *         <code>SpecialAddress.UNALTERED</code> and
      *         <code>SpecialAddress.SENDER</code> if applicable with null
      */
-    protected MailAddress getSender(Mail originalMail) throws MessagingException {
-        MailAddress sender = getSender();
-        if (sender != null) {
-            if (isUnalteredOrSender(sender)) {
-                return null;
-            }
-        }
-        return sender;
-    }
-
-    private boolean isUnalteredOrSender(MailAddress sender) {
-        return sender.equals(SpecialAddress.UNALTERED) || sender.equals(SpecialAddress.SENDER);
-    }
+    protected abstract Optional<MailAddress> getSender(Mail originalMail) throws MessagingException;
 
     /**
      * Builds the subject of <i>newMail</i> appending the subject of
@@ -354,11 +342,10 @@ public abstract class AbstractRedirect extends GenericMailet {
                 newMail.setMessage(new MimeMessage(Session.getDefaultInstance(System.getProperties(),
null)));
 
                 // handle the new message if altered
-                AlteredMailUtils.builder()
-                    .mailet(this)
+                MailMessageAlteringUtils.from(this)
                     .originalMail(originalMail)
-                    .build()
-                    .buildAlteredMessage(newMail);
+                    .newMail(newMail)
+                    .alterNewMessage();
 
             } else {
                 // if we need the original, create a copy of this message to

http://git-wip-us.apache.org/repos/asf/james-project/blob/6a87096d/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java
index bc2b78f..12312e9 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java
@@ -34,6 +34,7 @@ import org.apache.mailet.MailAddress;
 import org.apache.mailet.base.DateFormats;
 import org.apache.mailet.base.RFC2822Headers;
 
+import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 
 public class MailModifier {
@@ -186,9 +187,9 @@ public class MailModifier {
         }
     }
 
-    public void setSender(MailAddress sender, Mail originalMail) throws MessagingException
{
-        if (sender != null) {
-            mail.getMessage().setFrom(sender.toInternetAddress());
+    public void setSender(Optional<MailAddress> sender, Mail originalMail) throws MessagingException
{
+        if (sender.isPresent()) {
+            mail.getMessage().setFrom(sender.get().toInternetAddress());
 
             if (mailet.getInitParameters().isDebug()) {
                 mailet.log("sender set to: " + sender);

http://git-wip-us.apache.org/repos/asf/james-project/blob/6a87096d/server/mailet/mailets/src/main/java/org/apache/james/transport/util/SenderUtils.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/util/SenderUtils.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/util/SenderUtils.java
new file mode 100644
index 0000000..301617d
--- /dev/null
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/util/SenderUtils.java
@@ -0,0 +1,53 @@
+/****************************************************************
+ * 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;
+
+import com.google.common.base.Optional;
+
+public class SenderUtils {
+
+    public static SenderUtils from(MailAddress sender) {
+        return new SenderUtils(sender);
+    }
+
+    private final MailAddress sender;
+
+    private SenderUtils(MailAddress sender) {
+        this.sender = sender;
+    }
+
+    public Optional<MailAddress> getSender(Mail originalMail) throws MessagingException
{
+        if (sender != null) {
+            if (isUnalteredOrSender(sender)) {
+                return Optional.absent();
+            }
+        }
+        return Optional.fromNullable(sender);
+    }
+
+    private boolean isUnalteredOrSender(MailAddress sender) {
+        return sender.equals(SpecialAddress.UNALTERED) || sender.equals(SpecialAddress.SENDER);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/6a87096d/server/mailet/mailets/src/test/java/org/apache/james/transport/util/SenderUtilsTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/util/SenderUtilsTest.java
b/server/mailet/mailets/src/test/java/org/apache/james/transport/util/SenderUtilsTest.java
new file mode 100644
index 0000000..5fc4d3b
--- /dev/null
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/util/SenderUtilsTest.java
@@ -0,0 +1,76 @@
+/****************************************************************
+ * 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.guava.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;
+
+import com.google.common.base.Optional;
+
+public class SenderUtilsTest {
+
+    @Test
+    public void getSenderShouldReturnAbsentWhenSenderIsNull() throws Exception {
+        SenderUtils testee = SenderUtils.from(null);
+
+        FakeMail fakeMail = FakeMail.defaultFakeMail();
+
+        Optional<MailAddress> sender = testee.getSender(fakeMail);
+
+        assertThat(sender).isAbsent();
+    }
+
+    @Test
+    public void getSenderShouldReturnAbsentWhenSenderEqualsToUnaltered() throws Exception
{
+        SenderUtils testee = SenderUtils.from(SpecialAddress.UNALTERED);
+
+        FakeMail fakeMail = FakeMail.defaultFakeMail();
+
+        Optional<MailAddress> sender = testee.getSender(fakeMail);
+
+        assertThat(sender).isAbsent();
+    }
+
+    @Test
+    public void getSenderShouldReturnAbsentWhenSenderEqualsToSender() throws Exception {
+        SenderUtils testee = SenderUtils.from(SpecialAddress.SENDER);
+
+        FakeMail fakeMail = FakeMail.defaultFakeMail();
+
+        Optional<MailAddress> sender = testee.getSender(fakeMail);
+
+        assertThat(sender).isAbsent();
+    }
+
+    @Test
+    public void getSenderShouldReturnSenderWhenSenderIsCommon() throws Exception {
+        MailAddress expectedMailAddress = new MailAddress("sender", "james.org");
+        SenderUtils testee = SenderUtils.from(expectedMailAddress);
+
+        FakeMail fakeMail = FakeMail.defaultFakeMail();
+
+        Optional<MailAddress> sender = testee.getSender(fakeMail);
+
+        assertThat(sender).contains(expectedMailAddress);
+    }
+}


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