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

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


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

commit e4bbc04be00e411477660c374b0d6865a8d17896
Author: Karsten Otto <karsten.o...@akquinet.de>
AuthorDate: Wed Feb 28 09:03:28 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 c073d0a043..d5528934f7 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 86b7e9c1b3..531192dfa5 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
@@ -330,7 +330,7 @@ class BouncerTest {
     }
 
     @Test
-    void bounceShouldNotBounceWhenNoSenderWhenProcessorSpecified() throws 
Exception {
+    void bounceShouldWorkWhenProcessorSpecifiedAndNoSender() throws Exception {
         RemoteDeliveryConfiguration configuration = new 
RemoteDeliveryConfiguration(
             FakeMailetConfig.builder()
                 .setProperty(RemoteDeliveryConfiguration.HELO_NAME, HELLO_NAME)
@@ -341,9 +341,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-unsubscr...@james.apache.org
For additional commands, e-mail: notifications-h...@james.apache.org

Reply via email to