You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2020/12/21 07:29:30 UTC

[james-project] 05/17: JAMES-3431 DSN RET parameter should be taken into account when specified

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

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

commit 5c8d248d548bf393f260b2d5d93e5302f62d10be
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Dec 16 17:52:54 2020 +0700

    JAMES-3431 DSN RET parameter should be taken into account when specified
---
 .../apache/james/transport/mailets/DSNBounce.java   | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

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 916c736..a5eb82e 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
@@ -20,6 +20,7 @@
 package org.apache.james.transport.mailets;
 
 import static org.apache.james.transport.mailets.remote.delivery.Bouncer.DELIVERY_ERROR;
+import static org.apache.mailet.DsnParameters.Ret.HDRS;
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;
@@ -42,6 +43,7 @@ import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeBodyPart;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.commons.lang3.NotImplementedException;
 import org.apache.james.core.MailAddress;
 import org.apache.james.core.MaybeSender;
 import org.apache.james.dnsservice.api.DNSService;
@@ -63,6 +65,7 @@ import org.apache.james.transport.util.SenderUtils;
 import org.apache.james.transport.util.SpecialAddressesUtils;
 import org.apache.james.transport.util.TosUtils;
 import org.apache.mailet.AttributeUtils;
+import org.apache.mailet.DsnParameters;
 import org.apache.mailet.Mail;
 import org.apache.mailet.base.DateFormats;
 import org.apache.mailet.base.GenericMailet;
@@ -384,11 +387,27 @@ public class DSNBounce extends GenericMailet implements RedirectNotify {
         multipart.addBodyPart(createTextMsg(originalMail));
         multipart.addBodyPart(createDSN(originalMail));
         if (!getInitParameters().getAttachmentType().equals(TypeCode.NONE)) {
-            multipart.addBodyPart(createAttachedOriginal(originalMail, getInitParameters().getAttachmentType()));
+            multipart.addBodyPart(createAttachedOriginal(originalMail, getAttachmentType(originalMail)));
         }
         return multipart;
     }
 
+    private TypeCode getAttachmentType(Mail originalMail) {
+        return originalMail.dsnParameters()
+            .flatMap(DsnParameters::getRetParameter)
+            .map(ret -> {
+                switch (ret) {
+                    case HDRS:
+                        return TypeCode.HEADS;
+                    case FULL:
+                        return TypeCode.MESSAGE;
+                    default:
+                        throw new NotImplementedException("Unknown RET parameter: " + ret);
+                }
+            })
+            .orElse(getInitParameters().getAttachmentType());
+    }
+
     private MimeBodyPart createTextMsg(Mail originalMail) throws MessagingException {
         StringBuilder builder = new StringBuilder();
 


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