You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2024/02/23 04:05:08 UTC

(james-project) branch master updated: JAMES-4006 Bouncer should pass DSN to bounce processor

This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/master by this push:
     new 75e5b1e2ea JAMES-4006 Bouncer should pass DSN to bounce processor
75e5b1e2ea is described below

commit 75e5b1e2eaff5df156dd2dd888424180e265d832
Author: Karsten Otto <ka...@akquinet.de>
AuthorDate: Wed Feb 21 10:51:01 2024 +0100

    JAMES-4006 Bouncer should pass DSN to bounce processor
---
 .../transport/mailets/remote/delivery/Bouncer.java | 44 +++++++++++-----------
 .../mailets/remote/delivery/BouncerTest.java       | 12 ++++--
 2 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/Bouncer.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/Bouncer.java
index e562f5a882..7ba6556218 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/Bouncer.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/Bouncer.java
@@ -54,21 +54,17 @@ public class Bouncer {
     }
 
     public void bounce(Mail mail, Exception ex) {
-        if (!mail.hasSender()) {
-            LOGGER.debug("Null Sender: no bounce will be generated for {}", mail.getName());
-        } else {
-            configuration.getBounceProcessor().ifPresentOrElse(
-                bounceProcessor -> {
-                    computeErrorCode(ex).ifPresent(mail::setAttribute);
-                    mail.setAttribute(new Attribute(DELIVERY_ERROR, AttributeValue.of(getErrorMsg(ex))));
-                    try {
-                        mailetContext.sendMail(mail, bounceProcessor.getValue());
-                    } catch (MessagingException e) {
-                        LOGGER.warn("Exception re-inserting failed mail: ", e);
-                    }
-                },
-                () -> bounceWithMailetContext(mail, ex));
-        }
+        configuration.getBounceProcessor().ifPresentOrElse(
+            bounceProcessor -> {
+                computeErrorCode(ex).ifPresent(mail::setAttribute);
+                mail.setAttribute(new Attribute(DELIVERY_ERROR, AttributeValue.of(getErrorMsg(ex))));
+                try {
+                    mailetContext.sendMail(mail, bounceProcessor.getValue());
+                } catch (MessagingException e) {
+                    LOGGER.warn("Exception re-inserting failed mail: ", e);
+                }
+            },
+            () -> bounceWithMailetContext(mail, ex));
     }
 
     private Optional<Attribute> computeErrorCode(Exception ex) {
@@ -81,13 +77,17 @@ public class Bouncer {
     }
 
     private void bounceWithMailetContext(Mail mail, Exception ex) {
-        LOGGER.debug("Sending failure message {}", mail.getName());
-        try {
-            mailetContext.bounce(mail, explanationText(mail, ex));
-        } catch (MessagingException me) {
-            LOGGER.warn("Encountered unexpected messaging exception while bouncing message", me);
-        } catch (Exception e) {
-            LOGGER.warn("Encountered unexpected exception while bouncing message", e);
+        if (!mail.hasSender()) {
+            LOGGER.debug("Null Sender: no bounce will be generated for {}", mail.getName());
+        } else {
+            LOGGER.debug("Sending failure message {}", mail.getName());
+            try {
+                mailetContext.bounce(mail, explanationText(mail, ex));
+            } catch (MessagingException me) {
+                LOGGER.warn("Encountered unexpected messaging exception while bouncing message", me);
+            } catch (Exception e) {
+                LOGGER.warn("Encountered unexpected exception while bouncing message", e);
+            }
         }
     }
 
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remote/delivery/BouncerTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remote/delivery/BouncerTest.java
index 3ea6e312b7..8827ef7174 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remote/delivery/BouncerTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remote/delivery/BouncerTest.java
@@ -329,7 +329,7 @@ class BouncerTest {
     }
 
     @Test
-    void bounceShouldNotBounceWhenNoSenderWhenProcessorSpecified() throws Exception {
+    void bounceShouldWorkWhenProcessorSpecifiedAndNoSender() throws Exception {
         RemoteDeliveryConfiguration configuration = new RemoteDeliveryConfiguration(
             FakeMailetConfig.builder()
                 .setProperty(RemoteDeliveryConfiguration.HELO_NAME, HELLO_NAME)
@@ -340,9 +340,15 @@ class BouncerTest {
 
         Mail mail = FakeMail.builder().name("name").state(Mail.DEFAULT)
             .build();
-        testee.bounce(mail, new MessagingException("message"));
+        String errorMessage = "message";
+        testee.bounce(mail, new MessagingException(errorMessage));
 
-        assertThat(mailetContext.getSentMails()).isEmpty();
+        FakeMailContext.SentMail expected = FakeMailContext.sentMailBuilder()
+            .attribute(new Attribute(DELIVERY_ERROR, AttributeValue.of(errorMessage)))
+            .state(BOUNCE_PROCESSOR)
+            .fromMailet()
+            .build();
+        assertThat(mailetContext.getSentMails()).containsOnly(expected);
         assertThat(mailetContext.getBouncedMails()).isEmpty();
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org