james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [20/50] [abbrv] james-project git commit: MAILET-115 Use MailAddressUtils and use List instead of arrays/sets
Date Wed, 11 Jan 2017 09:26:08 GMT
MAILET-115 Use MailAddressUtils and use List instead of arrays/sets


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

Branch: refs/heads/master
Commit: 3ed6770cf949ad385ff2d539b19dc2d14151822b
Parents: 3a3c925
Author: Antoine Duprat <aduprat@apache.org>
Authored: Wed Nov 9 16:27:26 2016 +0100
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Jan 11 10:03:29 2017 +0700

----------------------------------------------------------------------
 .../apache/james/transport/mailets/Bounce.java  |  4 +-
 .../james/transport/mailets/DSNBounce.java      |  4 +-
 .../apache/james/transport/mailets/Forward.java |  4 +-
 .../transport/mailets/NotifyPostmaster.java     |  6 +--
 .../james/transport/mailets/NotifySender.java   |  6 +--
 .../james/transport/mailets/Redirect.java       | 18 +++----
 .../apache/james/transport/mailets/Resend.java  | 17 +++---
 .../mailets/redirect/AbstractRedirect.java      | 28 +++++-----
 .../transport/util/SpecialAddressesUtils.java   | 31 +++++------
 .../james/transport/mailets/ForwardTest.java    |  5 +-
 .../util/SpecialAddressesUtilsTest.java         | 57 ++++++++++----------
 11 files changed, 87 insertions(+), 93 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/3ed6770c/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 4ffac44..a161d08 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
@@ -114,7 +114,7 @@ public class Bounce extends AbstractRedirect {
     private static final String[] CONFIGURABLE_PARAMETERS = new String[] {
             "debug", "passThrough", "fakeDomainCheck", "inline", "attachment", "message",
"notice", "sender", "sendingAddress", "prefix", "attachError" };
     private static final List<MailAddress> RECIPIENTS = ImmutableList.of(SpecialAddress.REVERSE_PATH);
-    private static final InternetAddress[] TO = new InternetAddress[] { SpecialAddress.REVERSE_PATH.toInternetAddress()
};
+    private static final List<InternetAddress> TO = ImmutableList.of(SpecialAddress.REVERSE_PATH.toInternetAddress());
 
     @Override
     public String getMailetInfo() {
@@ -142,7 +142,7 @@ public class Bounce extends AbstractRedirect {
     }
 
     @Override
-    protected InternetAddress[] getTo() {
+    protected List<InternetAddress> getTo() {
         return TO;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/3ed6770c/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 9790b5d..ccdc43b 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
@@ -92,7 +92,7 @@ public class DSNBounce extends AbstractRedirect {
 
     private static final String[] CONFIGURABLE_PARAMETERS = new String[]{ "debug", "passThrough",
"messageString", "attachment", "sender", "prefix" };
     private static final List<MailAddress> RECIPIENT_MAIL_ADDRESSES = ImmutableList.of(SpecialAddress.REVERSE_PATH);
-    private static final InternetAddress[] TO_INTERNET_ADDRESSES = new InternetAddress[]
{ SpecialAddress.REVERSE_PATH.toInternetAddress() };
+    private static final List<InternetAddress> TO_INTERNET_ADDRESSES = ImmutableList.of(SpecialAddress.REVERSE_PATH.toInternetAddress());
 
     private static final String LOCALHOST = "127.0.0.1";
     private static final Pattern DIAG_PATTERN = Patterns.compilePatternUncheckedException("^\\d{3}\\s.*$");
@@ -134,7 +134,7 @@ public class DSNBounce extends AbstractRedirect {
     }
 
     @Override
-    protected InternetAddress[] getTo() {
+    protected List<InternetAddress> getTo() {
         return TO_INTERNET_ADDRESSES;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/3ed6770c/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 9d1f9e0..b61fa4e 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
@@ -149,8 +149,8 @@ public class Forward extends AbstractRedirect {
     }
 
     @Override
-    protected InternetAddress[] getTo() throws MessagingException {
-        return null;
+    protected List<InternetAddress> getTo() throws MessagingException {
+        return ImmutableList.of();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/3ed6770c/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 fc8620a..f00b6ac 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
@@ -150,17 +150,17 @@ public class NotifyPostmaster extends AbstractRedirect {
     }
 
     @Override
-    protected InternetAddress[] getTo() throws MessagingException {
+    protected List<InternetAddress> getTo() throws MessagingException {
         if (to.isPresent()) {
             Optional<MailAddress> specialAddress = AddressExtractor.withContext(getMailetContext())
                     .allowedSpecials(ALLOWED_SPECIALS)
                     .getSpecialAddress(to.get());
             if (specialAddress.isPresent()) {
-                return new InternetAddress[] { specialAddress.get().toInternetAddress() };
+                return ImmutableList.of(specialAddress.get().toInternetAddress());
             }
             log("\"to\" parameter ignored, set to postmaster");
         }
-        return new InternetAddress[] { getMailetContext().getPostmaster().toInternetAddress()
};
+        return ImmutableList.of(getMailetContext().getPostmaster().toInternetAddress());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/3ed6770c/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 3165dc9..421475c 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
@@ -150,17 +150,17 @@ public class NotifySender extends AbstractRedirect {
     }
 
     @Override
-    protected InternetAddress[] getTo() throws MessagingException {
+    protected List<InternetAddress> getTo() throws MessagingException {
         if (to.isPresent()) {
             Optional<MailAddress> specialAddress = AddressExtractor.withContext(getMailetContext())
                     .allowedSpecials(ALLOWED_SPECIALS)
                     .getSpecialAddress(to.get());
             if (specialAddress.isPresent()) {
-                return new InternetAddress[] { specialAddress.get().toInternetAddress() };
+                return ImmutableList.of(specialAddress.get().toInternetAddress());
             }
             log("\"to\" parameter ignored, set to sender");
         }
-        return new InternetAddress[] { SpecialAddress.SENDER.toInternetAddress() };
+        return ImmutableList.of(SpecialAddress.SENDER.toInternetAddress());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/3ed6770c/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 f20c2b4..fc53c6b 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
@@ -30,13 +30,13 @@ import org.apache.james.transport.mailets.redirect.InitParameters;
 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.MailAddressUtils;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
 
 /**
  * <p>
@@ -340,22 +340,18 @@ public class Redirect extends AbstractRedirect {
     }
 
     @Override
-    protected InternetAddress[] getTo() throws MessagingException {
+    protected List<InternetAddress> getTo() throws MessagingException {
         String toOrRecipients = getToOrRecipients();
         if (toOrRecipients == null) {
-            return null;
+            return ImmutableList.of();
         }
         if (toOrRecipients.isEmpty()) {
             throw new MessagingException("Failed to initialize \"recipients\" list; empty
<recipients> init parameter found.");
         }
-        List<InternetAddress> list = Lists.newArrayList();
-        List<MailAddress> mailAddresses = AddressExtractor.withContext(getMailetContext())
-                .allowedSpecials(ALLOWED_SPECIALS)
-                .extract(toOrRecipients);
-        for (MailAddress address : mailAddresses) {
-            list.add(address.toInternetAddress());
-        }
-        return list.toArray(new InternetAddress[list.size()]);
+        return MailAddressUtils.toInternetAddresses(
+                AddressExtractor.withContext(getMailetContext())
+                    .allowedSpecials(ALLOWED_SPECIALS)
+                    .extract(toOrRecipients));
     }
 
     private String getToOrRecipients() throws MessagingException {

http://git-wip-us.apache.org/repos/asf/james-project/blob/3ed6770c/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 f46e8c2..a9ee36c 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
@@ -29,10 +29,10 @@ import org.apache.james.transport.mailets.redirect.AddressExtractor;
 import org.apache.james.transport.mailets.redirect.InitParameters;
 import org.apache.james.transport.mailets.redirect.RedirectMailetInitParameters;
 import org.apache.james.transport.mailets.utils.MimeMessageModifier;
+import org.apache.james.transport.util.MailAddressUtils;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 
-import com.google.common.base.Optional;
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
 
@@ -309,16 +309,11 @@ public class Resend extends AbstractRedirect {
     }
 
     @Override
-    protected InternetAddress[] getTo() throws MessagingException {
-      ImmutableList.Builder<InternetAddress> builder = ImmutableList.builder();
-      List<MailAddress> mailAddresses = AddressExtractor.withContext(getMailetContext())
-              .allowedSpecials(ImmutableList.of("postmaster", "sender", "from", "replyTo",
"reversePath", "unaltered", "recipients", "to", "null"))
-              .extract(getInitParameters().getTo());
-      for (MailAddress address : mailAddresses) {
-          builder.add(address.toInternetAddress());
-      }
-      ImmutableList<InternetAddress> addresses = builder.build();
-      return addresses.toArray(new InternetAddress[addresses.size()]);
+    protected List<InternetAddress> getTo() throws MessagingException {
+      return MailAddressUtils.toInternetAddresses(
+              AddressExtractor.withContext(getMailetContext())
+                  .allowedSpecials(ImmutableList.of("postmaster", "sender", "from", "replyTo",
"reversePath", "unaltered", "recipients", "to", "null"))
+                  .extract(getInitParameters().getTo()));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/3ed6770c/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 4f646e1..760990f 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
@@ -40,6 +40,7 @@ import org.apache.james.core.MailImpl;
 import org.apache.james.core.MimeMessageUtil;
 import org.apache.james.dnsservice.api.DNSService;
 import org.apache.james.transport.mailets.Redirect;
+import org.apache.james.transport.util.MailAddressUtils;
 import org.apache.james.transport.util.SpecialAddressesUtils;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
@@ -244,7 +245,7 @@ public abstract class AbstractRedirect extends GenericMailet {
      *         <code>SpecialAddress.UNALTERED</code> or
      *         <code>SpecialAddress.TO</code> or <code>null</code>
if missing
      */
-    protected abstract InternetAddress[] getTo() throws MessagingException;
+    protected abstract List<InternetAddress> getTo() throws MessagingException;
 
     /**
      * Gets the <code>to</code> property, built dynamically using the original
@@ -254,33 +255,34 @@ public abstract class AbstractRedirect extends GenericMailet {
      *
      * @return {@link #replaceInternetAddresses} on {@link #getRecipients()},
      */
-    protected InternetAddress[] getTo(Mail originalMail) throws MessagingException {
-        InternetAddress[] apparentlyTo = getTo();
-        if (apparentlyTo != null) {
+    protected List<MailAddress> getTo(Mail originalMail) throws MessagingException
{
+        List<InternetAddress> apparentlyTo = getTo();
+        if (!apparentlyTo.isEmpty()) {
             if (containsOnlyUnalteredOrTo(apparentlyTo)) {
                 return null;
             }
-            Collection<InternetAddress> addresses = SpecialAddressesUtils.from(this).replaceInternetAddresses(originalMail,
ImmutableList.copyOf(apparentlyTo));
-            return addresses.toArray(new InternetAddress[addresses.size()]);
+            return SpecialAddressesUtils.from(this).replaceInternetAddresses(originalMail,
apparentlyTo);
         }
 
         return null;
     }
 
-    private boolean containsOnlyUnalteredOrTo(InternetAddress[] to) {
-        return to.length == 1 && 
-                (to[0].equals(SpecialAddress.UNALTERED.toInternetAddress()) || to[0].equals(SpecialAddress.RECIPIENTS.toInternetAddress()));
+    private boolean containsOnlyUnalteredOrTo(List<InternetAddress> apparentlyTo) {
+        return apparentlyTo.size() == 1 && 
+                (apparentlyTo.get(0).equals(SpecialAddress.UNALTERED.toInternetAddress())

+                        || apparentlyTo.get(0).equals(SpecialAddress.RECIPIENTS.toInternetAddress()));
     }
 
     /**
      * Sets the "To:" header of <i>newMail</i> to <i>to</i>. If the
requested
      * value is null does nothing. Is a "setX(Mail, Tx, Mail)" method.
      */
-    protected void setTo(Mail newMail, InternetAddress[] to, Mail originalMail) throws MessagingException
{
-        if (to != null) {
-            newMail.getMessage().setRecipients(Message.RecipientType.TO, to);
+    protected void setTo(Mail newMail, List<MailAddress> mailAddresses, Mail originalMail)
throws MessagingException {
+        if (mailAddresses != null) {
+            InternetAddress[] internetAddresses = MailAddressUtils.toInternetAddressArray(mailAddresses);
+            newMail.getMessage().setRecipients(Message.RecipientType.TO, internetAddresses);
             if (getInitParameters().isDebug()) {
-                log("apparentlyTo set to: " + arrayToString(to));
+                log("apparentlyTo set to: " + internetAddresses);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/3ed6770c/server/mailet/mailets/src/main/java/org/apache/james/transport/util/SpecialAddressesUtils.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/util/SpecialAddressesUtils.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/util/SpecialAddressesUtils.java
index 0fd9c7d..a6e6dbe 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/util/SpecialAddressesUtils.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/util/SpecialAddressesUtils.java
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.Set;
 
 import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.ParseException;
 
@@ -163,18 +164,18 @@ public class SpecialAddressesUtils {
      * <code>SpecialAddress.UNALTERED</code> is ignored.<br>
      * Any other address is not replaced.<br>
      */
-    public List<InternetAddress> replaceInternetAddresses(Mail mailWithReplacementAddresses,
List<InternetAddress> internetAddresses) throws MessagingException {
-        ImmutableList.Builder<InternetAddress> builder = ImmutableList.builder();
+    public List<MailAddress> replaceInternetAddresses(Mail mailWithReplacementAddresses,
List<InternetAddress> internetAddresses) throws MessagingException {
+        ImmutableList.Builder<MailAddress> builder = ImmutableList.builder();
         for (InternetAddress internetAddress : internetAddresses) {
             MailAddress mailAddress = new MailAddress(internetAddress);
             if (!SpecialAddress.isSpecialAddress(mailAddress)) {
-                builder.add(internetAddress);
+                builder.add(new MailAddress(internetAddress));
                 continue;
             }
 
             SpecialAddressKind specialAddressKind = SpecialAddressKind.forValue(mailAddress.getLocalPart());
             if (specialAddressKind == null) {
-                builder.add(mailAddress.toInternetAddress());
+                builder.add(mailAddress);
                 continue;
             }
 
@@ -182,13 +183,13 @@ public class SpecialAddressesUtils {
             case SENDER:
                 MailAddress sender = mailWithReplacementAddresses.getSender();
                 if (sender != null) {
-                    builder.add(sender.toInternetAddress());
+                    builder.add(sender);
                 }
                 break;
             case REVERSE_PATH:
                 MailAddress reversePath = mailWithReplacementAddresses.getSender();
                 if (reversePath != null) {
-                    builder.add(reversePath.toInternetAddress());
+                    builder.add(reversePath);
                 }
                 break;
             case FROM:
@@ -215,42 +216,42 @@ public class SpecialAddressesUtils {
             case UNALTERED:
                 break;
             case DELETE:
-                builder.add(internetAddress);
+                builder.add(new MailAddress(internetAddress));
                 break;
             }
         }
         return builder.build();
     }
 
-    private ImmutableSet<InternetAddress> allOrSender(Mail mail, InternetAddress[]
addresses) {
+    private List<MailAddress> allOrSender(Mail mail, InternetAddress[] addresses) throws
AddressException {
         if (addresses != null) {
-            return ImmutableSet.copyOf(addresses);
+            return MailAddressUtils.from(addresses);
         } else {
             MailAddress reversePath = mail.getSender();
             if (reversePath != null) {
-                return ImmutableSet.of(reversePath.toInternetAddress());
+                return ImmutableList.of(reversePath);
             }
         }
-        return ImmutableSet.of();
+        return ImmutableList.of();
     }
 
-    private ImmutableSet<InternetAddress> toHeaders(Mail mail) {
+    private List<MailAddress> toHeaders(Mail mail) {
         try {
             String[] toHeaders = mail.getMessage().getHeader(RFC2822Headers.TO);
             if (toHeaders != null) {
                 for (String toHeader : toHeaders) {
                     try {
                         InternetAddress[] originalToInternetAddresses = InternetAddress.parse(toHeader,
false);
-                        return ImmutableSet.copyOf(originalToInternetAddresses);
+                        return MailAddressUtils.from(originalToInternetAddresses);
                     } catch (MessagingException ae) {
                         genericMailet.log("Unable to parse a \"TO\" header address in the
original message: " + toHeader + "; ignoring.");
                     }
                 }
             }
-            return ImmutableSet.of();
+            return ImmutableList.of();
         } catch (MessagingException ae) {
             genericMailet.log("Unable to parse the \"TO\" header  in the original message;
ignoring.");
-            return ImmutableSet.of();
+            return ImmutableList.of();
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/3ed6770c/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 658978b..9037db2 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
@@ -29,7 +29,6 @@ import java.util.Collection;
 import javax.mail.MessagingException;
 
 import org.apache.james.dnsservice.api.DNSService;
-import org.apache.james.transport.mailets.redirect.TypeCode;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.base.MailAddressFixture;
 import org.apache.mailet.base.test.FakeMailContext;
@@ -119,8 +118,8 @@ public class ForwardTest {
     }
 
     @Test
-    public void getToShouldReturnNull() throws Exception {
-        assertThat(forward.getTo()).isNull();
+    public void getToShouldReturnEmpty() throws Exception {
+        assertThat(forward.getTo()).isEmpty();
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/3ed6770c/server/mailet/mailets/src/test/java/org/apache/james/transport/util/SpecialAddressesUtilsTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/util/SpecialAddressesUtilsTest.java
b/server/mailet/mailets/src/test/java/org/apache/james/transport/util/SpecialAddressesUtilsTest.java
index a68dd8f..78b724c 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/util/SpecialAddressesUtilsTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/util/SpecialAddressesUtilsTest.java
@@ -21,6 +21,7 @@ package org.apache.james.transport.util;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.util.Collection;
+import java.util.List;
 import java.util.Properties;
 
 import javax.mail.MessagingException;
@@ -245,7 +246,7 @@ public class SpecialAddressesUtilsTest {
         FakeMail mail = FakeMail.builder()
                 .build();
 
-        Collection<InternetAddress> addresses = testee.replaceInternetAddresses(mail,
ImmutableList.<InternetAddress> of());
+        List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.<InternetAddress>
of());
 
         assertThat(addresses).isEmpty();
     }
@@ -259,9 +260,9 @@ public class SpecialAddressesUtilsTest {
         InternetAddress internetAddress2 = new InternetAddress("user2@address.mar");
         ImmutableList<InternetAddress> list = ImmutableList.of(internetAddress, internetAddress2);
 
-        Collection<InternetAddress> addresses = testee.replaceInternetAddresses(mail,
list);
+        List<MailAddress> addresses = testee.replaceInternetAddresses(mail, list);
 
-        assertThat(addresses).containsOnly(internetAddress, internetAddress2);
+        assertThat(addresses).containsOnly(new MailAddress(internetAddress), new MailAddress(internetAddress2));
     }
 
     @Test
@@ -271,9 +272,9 @@ public class SpecialAddressesUtilsTest {
                 .sender(sender)
                 .build();
 
-        Collection<InternetAddress> addresses = testee.replaceInternetAddresses(mail,
ImmutableList.of(SpecialAddress.SENDER.toInternetAddress()));
+        List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.SENDER.toInternetAddress()));
 
-        assertThat(addresses).containsOnly(sender.toInternetAddress());
+        assertThat(addresses).containsOnly(sender);
     }
 
     @Test
@@ -284,9 +285,9 @@ public class SpecialAddressesUtilsTest {
         message.addFrom(new InternetAddress[] { from.toInternetAddress(), from2.toInternetAddress()
});
         FakeMail mail = FakeMail.from(message);
 
-        Collection<InternetAddress> addresses = testee.replaceInternetAddresses(mail,
ImmutableList.of(SpecialAddress.FROM.toInternetAddress()));
+        List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.FROM.toInternetAddress()));
 
-        assertThat(addresses).containsOnly(from.toInternetAddress(), from2.toInternetAddress());
+        assertThat(addresses).containsOnly(from, from2);
     }
 
     @Test
@@ -297,9 +298,9 @@ public class SpecialAddressesUtilsTest {
                 .sender(sender)
                 .build();
 
-        Collection<InternetAddress> addresses = testee.replaceInternetAddresses(mail,
ImmutableList.of(SpecialAddress.FROM.toInternetAddress()));
+        List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.FROM.toInternetAddress()));
 
-        assertThat(addresses).containsOnly(sender.toInternetAddress());
+        assertThat(addresses).containsOnly(sender);
     }
 
     @Test
@@ -307,7 +308,7 @@ public class SpecialAddressesUtilsTest {
         FakeMail mail = FakeMail.builder()
                 .build();
 
-        Collection<InternetAddress> addresses = testee.replaceInternetAddresses(mail,
ImmutableList.of(SpecialAddress.SENDER.toInternetAddress()));
+        List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.SENDER.toInternetAddress()));
 
         assertThat(addresses).isEmpty();
     }
@@ -317,7 +318,7 @@ public class SpecialAddressesUtilsTest {
         MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()));
         FakeMail mail = FakeMail.from(message);
 
-        Collection<InternetAddress> addresses = testee.replaceInternetAddresses(mail,
ImmutableList.of(SpecialAddress.REPLY_TO.toInternetAddress()));
+        List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.REPLY_TO.toInternetAddress()));
 
         assertThat(addresses).isEmpty();
     }
@@ -331,9 +332,9 @@ public class SpecialAddressesUtilsTest {
         MailAddress expectedReplyTo = MailAddressFixture.ANY_AT_JAMES;
         MailAddress expectedReplyTo2 = MailAddressFixture.OTHER_AT_JAMES;
 
-        Collection<InternetAddress> addresses = testee.replaceInternetAddresses(mail,
ImmutableList.of(SpecialAddress.REPLY_TO.toInternetAddress()));
+        List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.REPLY_TO.toInternetAddress()));
 
-        assertThat(addresses).containsOnly(expectedReplyTo.toInternetAddress(), expectedReplyTo2.toInternetAddress());
+        assertThat(addresses).containsOnly(expectedReplyTo, expectedReplyTo2);
     }
 
     @Test
@@ -344,9 +345,9 @@ public class SpecialAddressesUtilsTest {
                 .mimeMessage(new MimeMessage(Session.getDefaultInstance(new Properties())))
                 .build();
 
-        Collection<InternetAddress> addresses = testee.replaceInternetAddresses(mail,
ImmutableList.of(SpecialAddress.REPLY_TO.toInternetAddress()));
+        List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.REPLY_TO.toInternetAddress()));
 
-        assertThat(addresses).containsOnly(sender.toInternetAddress());
+        assertThat(addresses).containsOnly(sender);
     }
 
     @Test
@@ -356,9 +357,9 @@ public class SpecialAddressesUtilsTest {
                 .sender(sender)
                 .build();
 
-        Collection<InternetAddress> addresses = testee.replaceInternetAddresses(mail,
ImmutableList.of(SpecialAddress.REVERSE_PATH.toInternetAddress()));
+        List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.REVERSE_PATH.toInternetAddress()));
 
-        assertThat(addresses).containsOnly(sender.toInternetAddress());
+        assertThat(addresses).containsOnly(sender);
     }
 
     @Test
@@ -366,7 +367,7 @@ public class SpecialAddressesUtilsTest {
         FakeMail mail = FakeMail.builder()
                 .build();
 
-        Collection<InternetAddress> addresses = testee.replaceInternetAddresses(mail,
ImmutableList.of(SpecialAddress.REVERSE_PATH.toInternetAddress()));
+        List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.REVERSE_PATH.toInternetAddress()));
 
         assertThat(addresses).isEmpty();
     }
@@ -379,9 +380,9 @@ public class SpecialAddressesUtilsTest {
         message.addHeader(RFC2822Headers.TO, MailAddressFixture.ANY_AT_JAMES.toString() +
", " + MailAddressFixture.OTHER_AT_JAMES.toString());
         FakeMail mail = FakeMail.from(message);
 
-        Collection<InternetAddress> addresses = testee.replaceInternetAddresses(mail,
ImmutableList.of(SpecialAddress.RECIPIENTS.toInternetAddress()));
+        List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.RECIPIENTS.toInternetAddress()));
 
-        assertThat(addresses).containsOnly(to.toInternetAddress(), to2.toInternetAddress());
+        assertThat(addresses).containsOnly(to, to2);
     }
 
     @Test
@@ -392,9 +393,9 @@ public class SpecialAddressesUtilsTest {
         message.addHeader(RFC2822Headers.TO, MailAddressFixture.ANY_AT_JAMES.toString() +
", " + MailAddressFixture.OTHER_AT_JAMES);
         FakeMail mail = FakeMail.from(message);
 
-        Collection<InternetAddress> addresses = testee.replaceInternetAddresses(mail,
ImmutableList.of(SpecialAddress.TO.toInternetAddress()));
+        List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.TO.toInternetAddress()));
 
-        assertThat(addresses).containsOnly(to.toInternetAddress(), to2.toInternetAddress());
+        assertThat(addresses).containsOnly(to, to2);
     }
 
     @Test
@@ -402,7 +403,7 @@ public class SpecialAddressesUtilsTest {
         FakeMail mail = FakeMail.builder()
                 .build();
 
-        Collection<InternetAddress> addresses = testee.replaceInternetAddresses(mail,
ImmutableList.of(SpecialAddress.UNALTERED.toInternetAddress()));
+        List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.UNALTERED.toInternetAddress()));
 
         assertThat(addresses).isEmpty();
     }
@@ -412,7 +413,7 @@ public class SpecialAddressesUtilsTest {
         FakeMail mail = FakeMail.builder()
                 .build();
 
-        Collection<InternetAddress> addresses = testee.replaceInternetAddresses(mail,
ImmutableList.of(SpecialAddress.NULL.toInternetAddress()));
+        List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.NULL.toInternetAddress()));
 
         assertThat(addresses).isEmpty();
     }
@@ -424,9 +425,9 @@ public class SpecialAddressesUtilsTest {
 
         MailAddress address = new MailAddress("user", "address.marker");
         MailAddress address2 = new MailAddress("user2", "address.marker");
-        Collection<InternetAddress> addresses = testee.replaceInternetAddresses(mail,
ImmutableList.of(address.toInternetAddress(), address2.toInternetAddress()));
+        List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(address.toInternetAddress(),
address2.toInternetAddress()));
 
-        assertThat(addresses).containsOnly(address.toInternetAddress(), address2.toInternetAddress());
+        assertThat(addresses).containsOnly(address, address2);
     }
 
     @Test
@@ -434,9 +435,9 @@ public class SpecialAddressesUtilsTest {
         FakeMail mail = FakeMail.builder()
                 .build();
 
-        Collection<InternetAddress> addresses = testee.replaceInternetAddresses(mail,
ImmutableList.of(SpecialAddress.DELETE.toInternetAddress()));
+        List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.DELETE.toInternetAddress()));
 
-        InternetAddress expected = new InternetAddress("delete@address.marker");
+        MailAddress expected = new MailAddress("delete@address.marker");
         assertThat(addresses).containsOnly(expected);
     }
 }


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