james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [19/27] james-project git commit: JAMES-2132 MultipleError fields can be added to a MDN report
Date Fri, 01 Sep 2017 01:18:32 GMT
JAMES-2132 MultipleError fields can be added to a MDN report

https://tools.ietf.org/html/rfc8098#section-3.1

Describes the MDN structure as:

   disposition-notification-content = [ reporting-ua-field CRLF ]
             [ mdn-gateway-field CRLF ]
             [ original-recipient-field CRLF ]
             final-recipient-field CRLF
             [ original-message-id-field CRLF ]
             disposition-field CRLF
             *( error-field CRLF )
             *( extension-field CRLF )


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

Branch: refs/heads/master
Commit: 6643ef28e70044bf61bc89ffcd39bff0c0e67d46
Parents: 633d2eb
Author: benwa <btellier@linagora.com>
Authored: Mon Aug 28 21:30:08 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Sep 1 08:14:40 2017 +0700

----------------------------------------------------------------------
 .../java/org/apache/james/mdn/MDNReport.java    | 36 ++++++++++++------
 .../org/apache/james/mdn/MDNFactoryTest.java    | 40 ++++++++++++++++++--
 2 files changed, 62 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/6643ef28/mdn/src/main/java/org/apache/james/mdn/MDNReport.java
----------------------------------------------------------------------
diff --git a/mdn/src/main/java/org/apache/james/mdn/MDNReport.java b/mdn/src/main/java/org/apache/james/mdn/MDNReport.java
index 1d3beee..72eade2 100644
--- a/mdn/src/main/java/org/apache/james/mdn/MDNReport.java
+++ b/mdn/src/main/java/org/apache/james/mdn/MDNReport.java
@@ -19,6 +19,7 @@
 
 package org.apache.james.mdn;
 
+import java.util.List;
 import java.util.Optional;
 import java.util.stream.Collectors;
 
@@ -46,7 +47,7 @@ public class MDNReport {
         private Optional<FinalRecipient> finalRecipientField = Optional.empty();
         private Optional<OriginalMessageId> originalMessageIdField = Optional.empty();
         private Optional<Disposition> dispositionField = Optional.empty();
-        private Optional<Error> errorField = Optional.empty();
+        private ImmutableList.Builder<Error> errorField = ImmutableList.builder();
         private ImmutableList.Builder<ExtensionField> extensionFields = ImmutableList.builder();
 
         public Builder reportingUserAgentField(ReportingUserAgent reportingUserAgentField)
{
@@ -74,9 +75,13 @@ public class MDNReport {
             return this;
         }
 
+        public Builder addErrorField(Error errorField) {
+            this.errorField.add(errorField);
+            return this;
+        }
 
-        public Builder errorField(Error errorField) {
-            this.errorField = Optional.of(errorField);
+        public Builder addErrorFields(Error... errorField) {
+            this.errorField.add(errorField);
             return this;
         }
 
@@ -114,7 +119,7 @@ public class MDNReport {
                 finalRecipientField.get(),
                 originalMessageIdField,
                 dispositionField.get(),
-                errorField,
+                errorField.build(),
                 extensionFields.build());
         }
 
@@ -130,19 +135,19 @@ public class MDNReport {
     private final FinalRecipient finalRecipientField;
     private final Optional<OriginalMessageId> originalMessageIdField;
     private final Disposition dispositionField;
-    private final Optional<Error> errorField;
+    private final ImmutableList<Error> errorFields;
     private final ImmutableList<ExtensionField> extensionFields;
 
     private MDNReport(Optional<ReportingUserAgent> reportingUserAgentField, Optional<Gateway>
gatewayField, Optional<OriginalRecipient> originalRecipientField,
-                      FinalRecipient finalRecipientField, Optional<OriginalMessageId>
originalMessageIdField, Disposition dispositionField, Optional<Error> errorField,
-                      ImmutableList<ExtensionField> extensionFields) {
+                      FinalRecipient finalRecipientField, Optional<OriginalMessageId>
originalMessageIdField, Disposition dispositionField,
+                      ImmutableList<Error> errorFields, ImmutableList<ExtensionField>
extensionFields) {
         this.reportingUserAgentField = reportingUserAgentField;
         this.gatewayField = gatewayField;
         this.originalRecipientField = originalRecipientField;
         this.finalRecipientField = finalRecipientField;
         this.originalMessageIdField = originalMessageIdField;
         this.dispositionField = dispositionField;
-        this.errorField = errorField;
+        this.errorFields = errorFields;
         this.extensionFields = extensionFields;
     }
 
@@ -170,8 +175,8 @@ public class MDNReport {
         return gatewayField;
     }
 
-    public Optional<Error> getErrorField() {
-        return errorField;
+    public List<Error> getErrorFields() {
+        return errorFields;
     }
 
     public String formattedValue() {
@@ -181,10 +186,19 @@ public class MDNReport {
             + finalRecipientField.formattedValue() + LINE_END
             + originalMessageIdField.map(value -> value.formattedValue() + LINE_END).orElse("")
             + dispositionField.formattedValue() + LINE_END
-            + errorField.map(value -> value.formattedValue() + LINE_END).orElse("")
+            + formatErrors()
             + formattedExtensionValue();
     }
 
+    private String formatErrors() {
+        if (errorFields.isEmpty()) {
+            return "";
+        }
+        return errorFields.stream()
+            .map(Error::formattedValue)
+            .collect(Collectors.joining(LINE_END)) + LINE_END;
+    }
+
     private String formattedExtensionValue() {
         if (extensionFields.isEmpty()) {
             return "";

http://git-wip-us.apache.org/repos/asf/james-project/blob/6643ef28/mdn/src/test/java/org/apache/james/mdn/MDNFactoryTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/MDNFactoryTest.java b/mdn/src/test/java/org/apache/james/mdn/MDNFactoryTest.java
index 7d7ac83..c9235a8 100644
--- a/mdn/src/test/java/org/apache/james/mdn/MDNFactoryTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/MDNFactoryTest.java
@@ -607,7 +607,7 @@ public class MDNFactoryTest {
     }
 
     @Test
-    public void generateMDNReportShouldFormatErrorFields() {
+    public void generateMDNReportShouldFormatErrorField() {
         Disposition disposition = Disposition.builder()
             .actionMode(DispositionActionMode.Automatic)
             .sendingMode(DispositionSendingMode.Automatic)
@@ -624,7 +624,7 @@ public class MDNFactoryTest {
             .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
-            .errorField(new Error(Text.fromRawText("An error message")))
+            .addErrorField(new Error(Text.fromRawText("An error message")))
             .build()
             .formattedValue();
 
@@ -638,6 +638,40 @@ public class MDNFactoryTest {
     }
 
     @Test
+    public void generateMDNReportShouldFormatErrorFields() {
+        Disposition disposition = Disposition.builder()
+            .actionMode(DispositionActionMode.Automatic)
+            .sendingMode(DispositionSendingMode.Automatic)
+            .type(DispositionType.Processed)
+            .addModifier(DispositionModifier.Error)
+            .addModifier(DispositionModifier.Failed)
+            .build();
+
+        String report = MDNReport.builder()
+            .reportingUserAgentField(new ReportingUserAgent(
+                "UA_name",
+                Optional.of("UA_product")))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
+            .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
+            .originalMessageIdField(new OriginalMessageId("original_message_id"))
+            .dispositionField(disposition)
+            .addErrorFields(
+                new Error(Text.fromRawText("An error message")),
+                new Error(Text.fromRawText("A second error message")))
+            .build()
+            .formattedValue();
+
+        assertThat(report)
+            .isEqualTo("Reporting-UA: UA_name; UA_product\r\n" +
+                "Original-Recipient: rfc822; originalRecipient\r\n" +
+                "Final-Recipient: rfc822; final_recipient\r\n" +
+                "Original-Message-ID: original_message_id\r\n" +
+                "Disposition: automatic-action/MDN-sent-automatically;processed/error,failed\r\n"
+
+                "Error: An error message\r\n" +
+                "Error: A second error message\r\n");
+    }
+
+    @Test
     public void generateMDNReportShouldFormatErrorFieldsOnSeveralLines() {
         Disposition disposition = Disposition.builder()
             .actionMode(DispositionActionMode.Automatic)
@@ -655,7 +689,7 @@ public class MDNFactoryTest {
             .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
-            .errorField(new Error(Text.fromRawText("An error message\non several lines")))
+            .addErrorField(new Error(Text.fromRawText("An error message\non several lines")))
             .build()
             .formattedValue();
 


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