james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [02/13] james-project git commit: JAMES-2526 Bounce should not fail for "nullSender"
Date Fri, 14 Sep 2018 03:19:26 GMT
JAMES-2526 Bounce should not fail for "nullSender"


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

Branch: refs/heads/master
Commit: 01738f69cb1552f3b44b0237c52aef394f8d9fd4
Parents: 808e04a
Author: Benoit Tellier <btellier@linagora.com>
Authored: Wed Sep 12 18:24:59 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Fri Sep 14 10:17:04 2018 +0700

----------------------------------------------------------------------
 .../mailets/redirect/MailModifier.java          |  8 ++++++--
 .../mailets/redirect/ProcessRedirectNotify.java |  5 ++++-
 .../transport/util/SpecialAddressesUtils.java   |  7 ++++++-
 .../james/transport/mailets/BounceTest.java     | 21 ++++++++++++++++++++
 .../james/transport/mailets/RedirectTest.java   | 15 ++++++++------
 5 files changed, 46 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/01738f69/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 5345a6e..2ffc92b 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
@@ -38,6 +38,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
 
 public class MailModifier {
     private static final Logger LOGGER = LoggerFactory.getLogger(MailModifier.class);
@@ -108,7 +109,10 @@ public class MailModifier {
 
     public void setRecipients(List<MailAddress> recipients) {
         if (!recipients.isEmpty()) {
-            mail.setRecipients(recipients);
+            mail.setRecipients(recipients
+                .stream()
+                .filter(address -> !address.isNullSender())
+                .collect(ImmutableList.toImmutableList()));
             if (mailet.getInitParameters().isDebug()) {
                 if (LOGGER.isDebugEnabled()) {
                     LOGGER.debug("recipients set to: {}", (Object) recipients.toArray());
@@ -142,7 +146,7 @@ public class MailModifier {
     public void setReplyTo(Optional<MailAddress> optionalReplyTo) throws MessagingException
{
         if (optionalReplyTo.isPresent()) {
             MailAddress replyTo = optionalReplyTo.get();
-            if (replyTo.equals(SpecialAddress.NULL)) {
+            if (replyTo.isNullSender() || replyTo.equals(SpecialAddress.NULL)) {
                 mail.getMessage().setReplyTo(null);
                 if (mailet.getInitParameters().isDebug()) {
                     LOGGER.debug("replyTo set to: null");

http://git-wip-us.apache.org/repos/asf/james-project/blob/01738f69/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/ProcessRedirectNotify.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/ProcessRedirectNotify.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/ProcessRedirectNotify.java
index bcec3e4..c66881f 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/ProcessRedirectNotify.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/ProcessRedirectNotify.java
@@ -72,6 +72,7 @@ public class ProcessRedirectNotify {
             // Set additional headers
 
             mailModifier.setRecipients(mailet.getRecipients(originalMail));
+
             mailModifier.setTo(mailet.getTo(originalMail));
             mailModifier.setSubjectPrefix(originalMail);
             mailModifier.setReplyTo(mailet.getReplyTo(originalMail));
@@ -86,7 +87,9 @@ public class ProcessRedirectNotify {
 
             if (senderDomainIsValid(newMail)) {
                 // Send it off...
-                mailet.getMailetContext().sendMail(newMail);
+                if (!newMail.getRecipients().isEmpty()) {
+                    mailet.getMailetContext().sendMail(newMail);
+                }
             } else {
                 throw new MessagingException(mailet.getMailetName() + " mailet cannot forward
" + originalMail.getName() + ". " +
                         "Invalid sender domain for " + newMail.getSender() + ". " +

http://git-wip-us.apache.org/repos/asf/james-project/blob/01738f69/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 7cd8bcc..e80f8b6 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
@@ -86,6 +86,10 @@ public class SpecialAddressesUtils {
             return ImmutableSet.of(mailAddress);
         }
 
+        if (mailAddress.isNullSender()) {
+            return ImmutableList.of();
+        }
+
         SpecialAddressKind specialAddressKind = SpecialAddressKind.forValue(mailAddress.getLocalPart());
         if (specialAddressKind == null) {
             return ImmutableSet.of(mailAddress);
@@ -95,7 +99,7 @@ public class SpecialAddressesUtils {
             case FROM:
             case REVERSE_PATH:
                 return Optional.ofNullable(mail.getSender())
-                    .map(sender -> ImmutableSet.of(sender))
+                    .map(ImmutableSet::of)
                     .orElse(ImmutableSet.of());
             case REPLY_TO:
                 return getReplyTosFromMail(mail);
@@ -186,6 +190,7 @@ public class SpecialAddressesUtils {
             case SENDER:
             case REVERSE_PATH:
                 return Optional.ofNullable(mail.getSender())
+                    .filter(address -> !address.isNullSender())
                     .map(ImmutableSet::of)
                     .orElse(ImmutableSet.of());
             case FROM:

http://git-wip-us.apache.org/repos/asf/james-project/blob/01738f69/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/BounceTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/BounceTest.java
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/BounceTest.java
index cdde96b..2aa4ada 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/BounceTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/BounceTest.java
@@ -124,6 +124,27 @@ public class BounceTest {
     }
 
     @Test
+    public void bounceShouldNotSendEmailToNullSender() throws Exception {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+                .mailetName(MAILET_NAME)
+                .mailetContext(fakeMailContext)
+                .build();
+        bounce.init(mailetConfig);
+
+        FakeMail mail = FakeMail.builder()
+            .name(MAILET_NAME)
+            .sender(MailAddress.nullSender())
+            .recipient(MailAddressFixture.ANY_AT_JAMES)
+            .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
+                .setText("My content"))
+            .build();
+
+        bounce.service(mail);
+
+        assertThat(fakeMailContext.getSentMails()).isEmpty();
+    }
+
+    @Test
     public void bounceShouldChangeTheStateWhenNoSenderAndPassThroughEqualsFalse() throws
Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName(MAILET_NAME)

http://git-wip-us.apache.org/repos/asf/james-project/blob/01738f69/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RedirectTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RedirectTest.java
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RedirectTest.java
index ef490b3..4875680 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RedirectTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RedirectTest.java
@@ -385,12 +385,13 @@ public class RedirectTest {
 
 
         FakeMail mail = FakeMail.builder()
-                .name(MAILET_NAME)
-                .sender(MailAddressFixture.ANY_AT_JAMES)
-                .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
-                    .setSubject("My subject")
-                    .setText("content"))
-                .build();
+            .name(MAILET_NAME)
+            .recipient(MailAddressFixture.RECIPIENT1)
+            .sender(MailAddressFixture.ANY_AT_JAMES)
+            .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
+                .setSubject("My subject")
+                .setText("content"))
+            .build();
 
         redirect.service(mail);
 
@@ -411,6 +412,7 @@ public class RedirectTest {
         FakeMail mail = FakeMail.builder()
             .name(MAILET_NAME)
             .sender(MailAddressFixture.ANY_AT_JAMES)
+            .recipient(MailAddressFixture.RECIPIENT1)
             .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
                 .addHeader("Message-ID", messageId)
                 .setSubject("My subject")
@@ -437,6 +439,7 @@ public class RedirectTest {
         FakeMail mail = FakeMail.builder()
             .name(MAILET_NAME)
             .sender(MailAddressFixture.ANY_AT_JAMES)
+            .recipient(MailAddressFixture.RECIPIENT1)
             .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
                 .addHeader("Message-ID", messageId)
                 .setSubject("My subject")


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