james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [09/27] james-project git commit: JAMES-2132 adding MDN-Gateway field
Date Fri, 01 Sep 2017 01:18:22 GMT
JAMES-2132 adding MDN-Gateway field

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

   The MDN-Gateway field indicates the name of the gateway or MTA that
   translated a foreign (non-Internet) message disposition notification
   into this MDN.  This field MUST appear in any MDN that was translated
   by a gateway from a foreign system into MDN format and MUST NOT
   appear otherwise.

   mdn-gateway-field = "MDN-Gateway" ":" OWS mta-name-type OWS
                       ";" OWS mta-name OWS

   mta-name = *text

   For gateways into Internet Mail, the MTA-name-type will normally be
   "dns", and the mta-name will be the Internet domain name of the
   gateway.


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

Branch: refs/heads/master
Commit: bbc128a1c488ccc3e47ae69ea4993ef1063b6066
Parents: 860489c
Author: benwa <btellier@linagora.com>
Authored: Mon Aug 28 17:12:15 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Thu Aug 31 18:00:19 2017 +0700

----------------------------------------------------------------------
 .../java/org/apache/james/mdn/MDNReport.java    | 21 ++++++-
 .../org/apache/james/mdn/fields/Gateway.java    | 53 ++++++++++++++++
 .../org/apache/james/mdn/MDNFactoryTest.java    | 63 ++++++++++++++++++++
 3 files changed, 134 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/bbc128a1/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 0b429da..9dce948 100644
--- a/mdn/src/main/java/org/apache/james/mdn/MDNReport.java
+++ b/mdn/src/main/java/org/apache/james/mdn/MDNReport.java
@@ -23,6 +23,7 @@ import java.util.Optional;
 
 import org.apache.james.mdn.fields.Disposition;
 import org.apache.james.mdn.fields.FinalRecipient;
+import org.apache.james.mdn.fields.Gateway;
 import org.apache.james.mdn.fields.OriginalMessageId;
 import org.apache.james.mdn.fields.OriginalRecipient;
 import org.apache.james.mdn.fields.ReportingUserAgent;
@@ -33,6 +34,7 @@ public class MDNReport {
 
     public static class Builder {
         private Optional<ReportingUserAgent> reportingUserAgentField = Optional.empty();
+        private Optional<Gateway> gatewayField = Optional.empty();
         private Optional<OriginalRecipient> originalRecipientField = Optional.empty();
         private Optional<FinalRecipient> finalRecipientField = Optional.empty();
         private Optional<OriginalMessageId> originalMessageIdField = Optional.empty();
@@ -53,6 +55,16 @@ public class MDNReport {
             return this;
         }
 
+        public Builder gatewayField(Optional<Gateway> gatewayField) {
+            this.gatewayField = gatewayField;
+            return this;
+        }
+
+        public Builder gatewayField(Gateway gatewayField) {
+            this.gatewayField = Optional.of(gatewayField);
+            return this;
+        }
+
         public Builder finalRecipientField(FinalRecipient finalRecipientField) {
             this.finalRecipientField = Optional.of(finalRecipientField);
             return this;
@@ -74,7 +86,7 @@ public class MDNReport {
             Preconditions.checkState(dispositionField.isPresent());
 
             return new MDNReport(reportingUserAgentField,
-                originalRecipientField,
+                gatewayField, originalRecipientField,
                 finalRecipientField.get(),
                 originalMessageIdField.get(),
                 dispositionField.get());
@@ -89,14 +101,16 @@ public class MDNReport {
     public static final String LINE_END = "\r\n";
 
     private final Optional<ReportingUserAgent> reportingUserAgentField;
+    private final Optional<Gateway> gatewayField;
     private final Optional<OriginalRecipient> originalRecipientField;
     private final FinalRecipient finalRecipientField;
     private final OriginalMessageId originalMessageIdField;
     private final Disposition dispositionField;
 
-    private MDNReport(Optional<ReportingUserAgent> reportingUserAgentField, Optional<OriginalRecipient>
originalRecipientField,
-                     FinalRecipient finalRecipientField, OriginalMessageId originalMessageIdField,
Disposition dispositionField) {
+    private MDNReport(Optional<ReportingUserAgent> reportingUserAgentField, Optional<Gateway>
gatewayField, Optional<OriginalRecipient> originalRecipientField,
+                      FinalRecipient finalRecipientField, OriginalMessageId originalMessageIdField,
Disposition dispositionField) {
         this.reportingUserAgentField = reportingUserAgentField;
+        this.gatewayField = gatewayField;
         this.originalRecipientField = originalRecipientField;
         this.finalRecipientField = finalRecipientField;
         this.originalMessageIdField = originalMessageIdField;
@@ -125,6 +139,7 @@ public class MDNReport {
 
     public String formattedValue() {
         return reportingUserAgentField.map(value -> value.formattedValue() + LINE_END).orElse("")
+            + gatewayField.map(value -> value.formattedValue() + LINE_END).orElse("")
             + originalRecipientField.map(value -> value.formattedValue() + LINE_END).orElse("")
             + finalRecipientField.formattedValue() + LINE_END
             + originalMessageIdField.formattedValue() + LINE_END

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbc128a1/mdn/src/main/java/org/apache/james/mdn/fields/Gateway.java
----------------------------------------------------------------------
diff --git a/mdn/src/main/java/org/apache/james/mdn/fields/Gateway.java b/mdn/src/main/java/org/apache/james/mdn/fields/Gateway.java
new file mode 100644
index 0000000..4647c99
--- /dev/null
+++ b/mdn/src/main/java/org/apache/james/mdn/fields/Gateway.java
@@ -0,0 +1,53 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mdn.fields;
+
+/**
+ * MDN-Gateway field as specified in https://tools.ietf.org/html/rfc8098#section-3.2.2
+ */
+public class Gateway implements Field {
+    private static final String DNS = "dns";
+    public static final String FIELD_NAME = "MDN-Gateway";
+
+    private final String nameType;
+    private final String name;
+
+    public Gateway(String nameType, String name) {
+        this.nameType = nameType;
+        this.name = name;
+    }
+
+    public Gateway(String name) {
+        this(DNS, name);
+    }
+
+    @Override
+    public String formattedValue() {
+        return FIELD_NAME + ": " + nameType + ";" + name;
+    }
+
+    public String getNameType() {
+        return nameType;
+    }
+
+    public String getName() {
+        return name;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbc128a1/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 41d6c4a..5fd3cee 100644
--- a/mdn/src/test/java/org/apache/james/mdn/MDNFactoryTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/MDNFactoryTest.java
@@ -26,6 +26,7 @@ import java.util.Optional;
 import org.apache.james.mdn.action.mode.DispositionActionMode;
 import org.apache.james.mdn.fields.Disposition;
 import org.apache.james.mdn.fields.FinalRecipient;
+import org.apache.james.mdn.fields.Gateway;
 import org.apache.james.mdn.fields.OriginalMessageId;
 import org.apache.james.mdn.fields.OriginalRecipient;
 import org.apache.james.mdn.fields.ReportingUserAgent;
@@ -537,4 +538,66 @@ public class MDNFactoryTest {
             .originalRecipientField(new OriginalRecipient("originalRecipient"))
             .build();
     }
+
+    @Test
+    public void generateMDNReportShouldFormatGateway() {
+        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")))
+            .gatewayField(new Gateway("host.com"))
+            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
+            .dispositionField(disposition)
+            .build()
+            .formattedValue();
+
+        assertThat(report)
+            .isEqualTo("Reporting-UA: UA_name; UA_product\r\n" +
+                "MDN-Gateway: dns;host.com\r\n" +
+                "Original-Recipient: rfc822; originalRecipient\r\n" +
+                "Final-Recepient: rfc822; final_recipient\r\n" +
+                "Original-Message-ID: original_message_id\r\n" +
+                "Disposition: automatic-action/MDN-sent-automatically;processed/error,failed\r\n");
+    }
+    
+    @Test
+    public void generateMDNReportShouldFormatGatewayWithExoticNameType() {
+        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")))
+            .gatewayField(new Gateway("postal", "5 rue Charles mercier"))
+            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
+            .dispositionField(disposition)
+            .build()
+            .formattedValue();
+
+        assertThat(report)
+            .isEqualTo("Reporting-UA: UA_name; UA_product\r\n" +
+                "MDN-Gateway: postal;5 rue Charles mercier\r\n" +
+                "Original-Recipient: rfc822; originalRecipient\r\n" +
+                "Final-Recepient: rfc822; final_recipient\r\n" +
+                "Original-Message-ID: original_message_id\r\n" +
+                "Disposition: automatic-action/MDN-sent-automatically;processed/error,failed\r\n");
+    }
 }


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