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:17 UTC
[29/50] [abbrv] james-project git commit: MAILET-115 Remove abstract
getTo with original mail implementation
MAILET-115 Remove abstract getTo 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/63cb3237
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/63cb3237
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/63cb3237
Branch: refs/heads/master
Commit: 63cb3237508162e7ff9928343cd6348ca61cb3c8
Parents: 6bffadb
Author: Antoine Duprat <ad...@apache.org>
Authored: Wed Nov 16 09:46:54 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 | 21 +---
.../mailets/redirect/MailModifier.java | 2 +-
.../apache/james/transport/util/TosUtils.java | 61 +++++++++
.../james/transport/util/TosUtilsTest.java | 125 +++++++++++++++++++
11 files changed, 238 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/63cb3237/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 ef770dc..529465f 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.SpecialAddressesUtils;
+import org.apache.james.transport.util.TosUtils;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
@@ -151,11 +152,16 @@ public class Bounce extends AbstractRedirect {
}
@Override
- protected List<InternetAddress> getTo() {
+ public List<InternetAddress> getTo() {
return TO;
}
@Override
+ protected List<MailAddress> getTo(Mail originalMail) throws MessagingException {
+ return TosUtils.from(this).getTo(originalMail);
+ }
+
+ @Override
protected MailAddress getReplyTo() throws MessagingException {
return SpecialAddress.NULL;
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/63cb3237/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 36c099d..1086497 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.SpecialAddressesUtils;
+import org.apache.james.transport.util.TosUtils;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
import org.apache.mailet.base.DateFormats;
@@ -144,11 +145,16 @@ public class DSNBounce extends AbstractRedirect {
}
@Override
- protected List<InternetAddress> getTo() {
+ public List<InternetAddress> getTo() {
return TO_INTERNET_ADDRESSES;
}
@Override
+ protected List<MailAddress> getTo(Mail originalMail) throws MessagingException {
+ return TosUtils.from(this).getTo(originalMail);
+ }
+
+ @Override
protected MailAddress getReplyTo() throws MessagingException {
return SpecialAddress.NULL;
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/63cb3237/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 1d62f6a..414d441 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.TosUtils;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
@@ -155,11 +156,16 @@ public class Forward extends AbstractRedirect {
}
@Override
- protected List<InternetAddress> getTo() throws MessagingException {
+ public List<InternetAddress> getTo() throws MessagingException {
return ImmutableList.of();
}
@Override
+ protected List<MailAddress> getTo(Mail originalMail) throws MessagingException {
+ return TosUtils.from(this).getTo(originalMail);
+ }
+
+ @Override
protected MailAddress getReplyTo() throws MessagingException {
return null;
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/63cb3237/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 0c3b1a2..dce678c 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.SpecialAddressesUtils;
+import org.apache.james.transport.util.TosUtils;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
import org.apache.mailet.MailetConfig;
@@ -158,7 +159,7 @@ public class NotifyPostmaster extends AbstractRedirect {
}
@Override
- protected List<InternetAddress> getTo() throws MessagingException {
+ public List<InternetAddress> getTo() throws MessagingException {
if (to.isPresent()) {
Optional<MailAddress> specialAddress = AddressExtractor.withContext(getMailetContext())
.allowedSpecials(ALLOWED_SPECIALS)
@@ -172,6 +173,11 @@ public class NotifyPostmaster extends AbstractRedirect {
}
@Override
+ protected List<MailAddress> getTo(Mail originalMail) throws MessagingException {
+ return TosUtils.from(this).getTo(originalMail);
+ }
+
+ @Override
protected MailAddress getReplyTo() throws MessagingException {
return SpecialAddress.NULL;
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/63cb3237/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 ed4c0ae..e21de99 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.SpecialAddressesUtils;
+import org.apache.james.transport.util.TosUtils;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
import org.apache.mailet.MailetConfig;
@@ -158,7 +159,7 @@ public class NotifySender extends AbstractRedirect {
}
@Override
- protected List<InternetAddress> getTo() throws MessagingException {
+ public List<InternetAddress> getTo() throws MessagingException {
if (to.isPresent()) {
Optional<MailAddress> specialAddress = AddressExtractor.withContext(getMailetContext())
.allowedSpecials(ALLOWED_SPECIALS)
@@ -172,6 +173,11 @@ public class NotifySender extends AbstractRedirect {
}
@Override
+ protected List<MailAddress> getTo(Mail originalMail) throws MessagingException {
+ return TosUtils.from(this).getTo(originalMail);
+ }
+
+ @Override
protected MailAddress getReplyTo() throws MessagingException {
return SpecialAddress.NULL;
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/63cb3237/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 4cb7295..7d78742 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.SpecialAddressesUtils;
+import org.apache.james.transport.util.TosUtils;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
@@ -348,7 +349,7 @@ public class Redirect extends AbstractRedirect {
}
@Override
- protected List<InternetAddress> getTo() throws MessagingException {
+ public List<InternetAddress> getTo() throws MessagingException {
String toOrRecipients = getToOrRecipients();
if (toOrRecipients == null) {
return ImmutableList.of();
@@ -367,6 +368,11 @@ public class Redirect extends AbstractRedirect {
}
@Override
+ protected List<MailAddress> getTo(Mail originalMail) throws MessagingException {
+ return TosUtils.from(this).getTo(originalMail);
+ }
+
+ @Override
protected MailAddress getReplyTo() throws MessagingException {
String replyTo = getInitParameters().getReplyTo();
if (Strings.isNullOrEmpty(replyTo)) {
http://git-wip-us.apache.org/repos/asf/james-project/blob/63cb3237/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 d1b0b78..7d7afb4 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.SpecialAddressesUtils;
+import org.apache.james.transport.util.TosUtils;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
@@ -313,7 +314,7 @@ public class Resend extends AbstractRedirect {
}
@Override
- protected List<InternetAddress> getTo() throws MessagingException {
+ public List<InternetAddress> getTo() throws MessagingException {
return MailAddressUtils.toInternetAddresses(
AddressExtractor.withContext(getMailetContext())
.allowedSpecials(ImmutableList.of("postmaster", "sender", "from", "replyTo", "reversePath", "unaltered", "recipients", "to", "null"))
@@ -321,6 +322,11 @@ public class Resend extends AbstractRedirect {
}
@Override
+ protected List<MailAddress> getTo(Mail originalMail) throws MessagingException {
+ return TosUtils.from(this).getTo(originalMail);
+ }
+
+ @Override
protected MailAddress getReplyTo() throws MessagingException {
String replyTo = getInitParameters().getReplyTo();
if (Strings.isNullOrEmpty(replyTo)) {
http://git-wip-us.apache.org/repos/asf/james-project/blob/63cb3237/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 393cbf8..b52ce40 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
@@ -31,7 +31,6 @@ import org.apache.james.core.MailImpl;
import org.apache.james.dnsservice.api.DNSService;
import org.apache.james.transport.mailets.Redirect;
import org.apache.james.transport.mailets.utils.MimeMessageModifier;
-import org.apache.james.transport.util.SpecialAddressesUtils;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
import org.apache.mailet.base.GenericMailet;
@@ -198,7 +197,7 @@ public abstract class AbstractRedirect extends GenericMailet {
* <code>SpecialAddress.UNALTERED</code> or
* <code>SpecialAddress.TO</code> or <code>null</code> if missing
*/
- protected abstract List<InternetAddress> getTo() throws MessagingException;
+ public abstract List<InternetAddress> getTo() throws MessagingException;
/**
* Gets the <code>to</code> property, built dynamically using the original
@@ -208,23 +207,7 @@ public abstract class AbstractRedirect extends GenericMailet {
*
* @return {@link #replaceInternetAddresses} on {@link #getRecipients()},
*/
- protected List<MailAddress> getTo(Mail originalMail) throws MessagingException {
- List<InternetAddress> apparentlyTo = getTo();
- if (!apparentlyTo.isEmpty()) {
- if (containsOnlyUnalteredOrTo(apparentlyTo)) {
- return null;
- }
- return SpecialAddressesUtils.from(this).replaceInternetAddresses(originalMail, apparentlyTo);
- }
-
- return null;
- }
-
- private boolean containsOnlyUnalteredOrTo(List<InternetAddress> apparentlyTo) {
- return apparentlyTo.size() == 1 &&
- (apparentlyTo.get(0).equals(SpecialAddress.UNALTERED.toInternetAddress())
- || apparentlyTo.get(0).equals(SpecialAddress.RECIPIENTS.toInternetAddress()));
- }
+ protected abstract List<MailAddress> getTo(Mail originalMail) throws MessagingException;
/**
* Gets the <code>replyto</code> property. Returns the Reply-To address of
http://git-wip-us.apache.org/repos/asf/james-project/blob/63cb3237/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 407836c..bc2b78f 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
@@ -112,7 +112,7 @@ public class MailModifier {
}
public void setTo(List<MailAddress> mailAddresses) throws MessagingException {
- if (mailAddresses != null) {
+ if (!mailAddresses.isEmpty()) {
InternetAddress[] internetAddresses = MailAddressUtils.toInternetAddressArray(mailAddresses);
mail.getMessage().setRecipients(Message.RecipientType.TO, internetAddresses);
if (mailet.getInitParameters().isDebug()) {
http://git-wip-us.apache.org/repos/asf/james-project/blob/63cb3237/server/mailet/mailets/src/main/java/org/apache/james/transport/util/TosUtils.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/util/TosUtils.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/util/TosUtils.java
new file mode 100644
index 0000000..db31c87
--- /dev/null
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/util/TosUtils.java
@@ -0,0 +1,61 @@
+/****************************************************************
+ * 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 java.util.List;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.InternetAddress;
+
+import org.apache.james.transport.mailets.redirect.AbstractRedirect;
+import org.apache.james.transport.mailets.redirect.SpecialAddress;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+
+import com.google.common.collect.ImmutableList;
+
+public class TosUtils {
+
+ public static TosUtils from(AbstractRedirect mailet) {
+ return new TosUtils(mailet);
+ }
+
+ private final AbstractRedirect mailet;
+
+ private TosUtils(AbstractRedirect mailet) {
+ this.mailet = mailet;
+ }
+
+ public List<MailAddress> getTo(Mail originalMail) throws MessagingException {
+ List<InternetAddress> apparentlyTo = mailet.getTo();
+ if (!apparentlyTo.isEmpty()) {
+ if (containsOnlyUnalteredOrTo(apparentlyTo)) {
+ return ImmutableList.of();
+ }
+ return SpecialAddressesUtils.from(mailet).replaceInternetAddresses(originalMail, apparentlyTo);
+ }
+
+ return ImmutableList.of();
+ }
+
+ private boolean containsOnlyUnalteredOrTo(List<InternetAddress> apparentlyTo) {
+ return apparentlyTo.size() == 1 &&
+ (apparentlyTo.get(0).equals(SpecialAddress.UNALTERED.toInternetAddress()) || apparentlyTo.get(0).equals(SpecialAddress.RECIPIENTS.toInternetAddress()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/63cb3237/server/mailet/mailets/src/test/java/org/apache/james/transport/util/TosUtilsTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/util/TosUtilsTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/util/TosUtilsTest.java
new file mode 100644
index 0000000..f8fc000
--- /dev/null
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/util/TosUtilsTest.java
@@ -0,0 +1,125 @@
+/****************************************************************
+ * 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 static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
+import java.util.Properties;
+
+import javax.mail.Session;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMessage.RecipientType;
+
+import org.apache.james.transport.mailets.redirect.AbstractRedirect;
+import org.apache.james.transport.mailets.redirect.SpecialAddress;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.base.test.FakeMail;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+public class TosUtilsTest {
+
+ private AbstractRedirect mailet;
+ private TosUtils testee;
+
+ @Before
+ public void setup() {
+ mailet = mock(AbstractRedirect.class);
+ testee = TosUtils.from(mailet);
+ }
+
+ @Test
+ public void getToShouldReturnEmptyWhenMailetToIsEmpty() throws Exception {
+ when(mailet.getTo())
+ .thenReturn(ImmutableList.<InternetAddress> of());
+
+ FakeMail fakeMail = FakeMail.defaultFakeMail();
+
+ List<MailAddress> to = testee.getTo(fakeMail);
+
+ assertThat(to).isEmpty();
+ }
+
+ @Test
+ public void getToShouldReturnEmptyWhenMailetToContainsOnlyUnaltered() throws Exception {
+ when(mailet.getTo())
+ .thenReturn(ImmutableList.of(SpecialAddress.UNALTERED.toInternetAddress()));
+
+ FakeMail fakeMail = FakeMail.defaultFakeMail();
+
+ List<MailAddress> to = testee.getTo(fakeMail);
+
+ assertThat(to).isEmpty();
+ }
+
+ @Test
+ public void getToShouldReturnEmptyWhenMailetToContainsOnlyRecipients() throws Exception {
+ when(mailet.getTo())
+ .thenReturn(ImmutableList.of(SpecialAddress.RECIPIENTS.toInternetAddress()));
+
+ FakeMail fakeMail = FakeMail.defaultFakeMail();
+
+ List<MailAddress> to = testee.getTo(fakeMail);
+
+ assertThat(to).isEmpty();
+ }
+
+ @Test
+ public void getToShouldReturnToWhenMailetToAreCommon() throws Exception {
+ MailAddress mailAddress = new MailAddress("test", "james.org");
+ MailAddress mailAddress2 = new MailAddress("test2", "james.org");
+ when(mailet.getTo())
+ .thenReturn(ImmutableList.of(mailAddress.toInternetAddress(), mailAddress2.toInternetAddress()));
+
+ FakeMail fakeMail = FakeMail.defaultFakeMail();
+
+ List<MailAddress> to = testee.getTo(fakeMail);
+
+ ImmutableList<MailAddress> expectedTo = ImmutableList.of(mailAddress, mailAddress2);
+ assertThat(to).containsOnlyElementsOf(expectedTo);
+ }
+
+ @Test
+ public void getToShouldReturnAddressesFromOriginalMailWhenMailetToAreSpecialAddresses() throws Exception {
+ when(mailet.getTo())
+ .thenReturn(ImmutableList.of(SpecialAddress.FROM.toInternetAddress(), SpecialAddress.TO.toInternetAddress()));
+
+ MimeMessage mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties()));
+ mimeMessage.setRecipients(RecipientType.TO, "to@james.org, to2@james.org");
+ MailAddress from = new MailAddress("from", "james.org");
+ MailAddress toMailAddress = new MailAddress("to", "james.org");
+ MailAddress toMailAddress2 = new MailAddress("to2", "james.org");
+ FakeMail fakeMail = FakeMail.builder()
+ .sender(from)
+ .recipients(toMailAddress, toMailAddress2)
+ .mimeMessage(mimeMessage)
+ .build();
+
+ List<MailAddress> to = testee.getTo(fakeMail);
+
+ ImmutableList<MailAddress> expectedTo = ImmutableList.of(from, toMailAddress, toMailAddress2);
+ assertThat(to).containsOnlyElementsOf(expectedTo);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org