james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [24/24] james-project git commit: JAMES-2361 send the right Content-Type for MDN
Date Tue, 03 Apr 2018 10:03:10 GMT
JAMES-2361 send the right Content-Type for MDN


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

Branch: refs/heads/master
Commit: de8f7b2f42e46619f4e61af1ebbf7d25189cac92
Parents: b1fb022
Author: Matthieu Baechler <matthieu@apache.org>
Authored: Tue Mar 27 17:36:27 2018 +0200
Committer: benwa <btellier@linagora.com>
Committed: Tue Apr 3 17:01:39 2018 +0700

----------------------------------------------------------------------
 mdn/pom.xml                                     |  4 +++
 mdn/src/main/java/org/apache/james/mdn/MDN.java |  4 ++-
 .../test/java/org/apache/james/mdn/MDNTest.java | 33 ++++++++++++++++++++
 3 files changed, 40 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/de8f7b2f/mdn/pom.xml
----------------------------------------------------------------------
diff --git a/mdn/pom.xml b/mdn/pom.xml
index 0c9a3bd..68e155e 100644
--- a/mdn/pom.xml
+++ b/mdn/pom.xml
@@ -42,6 +42,10 @@
             <artifactId>james-server-util-java8</artifactId>
         </dependency>
         <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>javax-mail-extension</artifactId>
+        </dependency>
+        <dependency>
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/de8f7b2f/mdn/src/main/java/org/apache/james/mdn/MDN.java
----------------------------------------------------------------------
diff --git a/mdn/src/main/java/org/apache/james/mdn/MDN.java b/mdn/src/main/java/org/apache/james/mdn/MDN.java
index 9b7b22c..1e4e542 100644
--- a/mdn/src/main/java/org/apache/james/mdn/MDN.java
+++ b/mdn/src/main/java/org/apache/james/mdn/MDN.java
@@ -31,6 +31,7 @@ import javax.mail.internet.MimeBodyPart;
 import javax.mail.internet.MimeMessage;
 import javax.mail.internet.MimeMultipart;
 
+import org.apache.james.javax.MimeMultipartReport;
 import org.apache.james.mime4j.Charsets;
 import org.apache.james.mime4j.dom.Message;
 import org.apache.james.mime4j.dom.Multipart;
@@ -93,8 +94,9 @@ public class MDN {
     }
 
     public MimeMultipart asMultipart() throws MessagingException {
-        MimeMultipart multipart = new MimeMultipart();
+        MimeMultipartReport multipart = new MimeMultipartReport();
         multipart.setSubType(REPORT_SUB_TYPE);
+        multipart.setReportType("disposition-notification");
         multipart.addBodyPart(computeHumanReadablePart());
         multipart.addBodyPart(computeReportPart());
         // The optional third part, the original message is omitted.

http://git-wip-us.apache.org/repos/asf/james-project/blob/de8f7b2f/mdn/src/test/java/org/apache/james/mdn/MDNTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/MDNTest.java b/mdn/src/test/java/org/apache/james/mdn/MDNTest.java
index 15aab74..6decac0 100644
--- a/mdn/src/test/java/org/apache/james/mdn/MDNTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/MDNTest.java
@@ -23,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.ByteArrayOutputStream;
 import java.nio.charset.StandardCharsets;
+import java.util.regex.Pattern;
 
 import javax.mail.internet.MimeMessage;
 
@@ -32,6 +33,7 @@ import org.apache.james.mdn.sending.mode.DispositionSendingMode;
 import org.apache.james.mdn.type.DispositionType;
 import org.apache.james.mime4j.dom.Message;
 import org.apache.james.mime4j.message.DefaultMessageWriter;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -59,6 +61,22 @@ public class MDNTest {
     }
 
     @Test
+    public void asMimeMessageShouldGenerateExpectedContentType() throws Exception {
+        MimeMessage mimeMessage = MDN.builder()
+            .humanReadableText("Explanation")
+            .report(MINIMAL_REPORT)
+            .build()
+            .asMimeMessage();
+
+        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+        mimeMessage.writeTo(byteArrayOutputStream);
+
+        assertThat(new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8))
+            .containsPattern(
+                Pattern.compile("Content-Type: multipart/report;.*report-type=disposition-notification",
Pattern.DOTALL));
+    }
+
+    @Test
     public void asMimeMessageShouldComportExplanationPartAndReportPart() throws Exception
{
         MimeMessage mimeMessage = MDN.builder()
             .humanReadableText("Explanation")
@@ -192,6 +210,21 @@ public class MDNTest {
             "Disposition: automatic-action/MDN-sent-automatically;deleted");
     }
 
+
+    @Ignore("Content-Type Parameters are not supported by mime4j")
+    @Test
+    public void mime4JMessageExportShouldGenerateExpectedContentType() throws Exception {
+        Message message = MDN.builder()
+            .humanReadableText("RFCs are not funny")
+            .report(MINIMAL_REPORT)
+            .build()
+            .asMime4JMessageBuilder()
+            .build();
+
+        assertThat(asString(message))
+            .containsPattern(Pattern.compile("Content-Type: multipart/report;.*report-type=disposition-notification",
Pattern.DOTALL));
+    }
+
     private String asString(Message message) throws Exception {
         return new String(DefaultMessageWriter.asBytes(message), StandardCharsets.UTF_8);
     }


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