james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [04/27] james-project git commit: JAMES-2132 support various Address type
Date Fri, 01 Sep 2017 01:18:17 GMT
JAMES-2132 support various Address type

The address-type field indicates the type of the original recipient
   address.  If the message originated within the Internet, the address-
   type field will normally be "rfc822", and the address will be
   according to the syntax specified in RFC-MSGFMT [RFC5322].  The value
   "unknown" should be used if the Reporting MUA cannot determine the
   type of the original recipient address from the message envelope.


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

Branch: refs/heads/master
Commit: eb1670891c34efd17a08ec99edaf8bea83af9ffa
Parents: bbc128a
Author: benwa <btellier@linagora.com>
Authored: Mon Aug 28 17:21:33 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Thu Aug 31 18:00:19 2017 +0700

----------------------------------------------------------------------
 .../apache/james/mdn/fields/FinalRecipient.java |  20 ++-
 .../james/mdn/fields/OriginalRecipient.java     |  24 ++-
 .../org/apache/james/mdn/MDNFactoryTest.java    | 167 ++++++++++++++-----
 3 files changed, 159 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/eb167089/mdn/src/main/java/org/apache/james/mdn/fields/FinalRecipient.java
----------------------------------------------------------------------
diff --git a/mdn/src/main/java/org/apache/james/mdn/fields/FinalRecipient.java b/mdn/src/main/java/org/apache/james/mdn/fields/FinalRecipient.java
index a9799d2..5d0772e 100644
--- a/mdn/src/main/java/org/apache/james/mdn/fields/FinalRecipient.java
+++ b/mdn/src/main/java/org/apache/james/mdn/fields/FinalRecipient.java
@@ -19,25 +19,33 @@
 
 package org.apache.james.mdn.fields;
 
-import java.util.Optional;
-
 import org.apache.james.mdn.Constants;
 
+import com.google.common.base.Preconditions;
+
 public class FinalRecipient implements Field {
     public static final String FIELD_NAME = "Final-Recepient";
 
-    private final Optional<String> finalRecipient;
+    private final String finalRecipient;
+    private final String addressType;
 
-    public FinalRecipient(Optional<String> finalRecipient) {
+    public FinalRecipient(String addressType, String finalRecipient) {
+        Preconditions.checkNotNull(finalRecipient);
+        Preconditions.checkNotNull(addressType);
         this.finalRecipient = finalRecipient;
+        this.addressType = addressType;
+    }
+
+    public FinalRecipient(String finalRecipient) {
+        this(Constants.RFC_822, finalRecipient);
     }
 
-    public Optional<String> getFinalRecipient() {
+    public String getFinalRecipient() {
         return finalRecipient;
     }
 
     @Override
     public String formattedValue() {
-        return FIELD_NAME + ": " + Constants.RFC_822 + "; " + finalRecipient.orElse("");
+        return FIELD_NAME + ": " + addressType + "; " + finalRecipient;
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/eb167089/mdn/src/main/java/org/apache/james/mdn/fields/OriginalRecipient.java
----------------------------------------------------------------------
diff --git a/mdn/src/main/java/org/apache/james/mdn/fields/OriginalRecipient.java b/mdn/src/main/java/org/apache/james/mdn/fields/OriginalRecipient.java
index a44c055..9c399ff 100644
--- a/mdn/src/main/java/org/apache/james/mdn/fields/OriginalRecipient.java
+++ b/mdn/src/main/java/org/apache/james/mdn/fields/OriginalRecipient.java
@@ -21,19 +21,39 @@ package org.apache.james.mdn.fields;
 
 import org.apache.james.mdn.Constants;
 
+import com.google.common.base.Preconditions;
+
 public class OriginalRecipient implements Field{
+    private static final String UNKNOWN = "unknown";
+
+    public static OriginalRecipient ofUnknown(String address) {
+        return new OriginalRecipient(UNKNOWN, address);
+    }
+
     private final String originalRecipient;
+    private final String addressType;
 
-    public OriginalRecipient(String originalRecipient) {
+    public OriginalRecipient(String addressType, String originalRecipient) {
+        Preconditions.checkNotNull(addressType);
+        Preconditions.checkNotNull(originalRecipient);
+        this.addressType = addressType;
         this.originalRecipient = originalRecipient;
     }
 
+    public OriginalRecipient(String originalRecipient) {
+        this(Constants.RFC_822, originalRecipient);
+    }
+
     public String getOriginalRecipient() {
         return originalRecipient;
     }
 
+    public String getAddressType() {
+        return addressType;
+    }
+
     @Override
     public String formattedValue() {
-        return "Original-Recipient: " + Constants.RFC_822 + "; " + originalRecipient;
+        return "Original-Recipient: " + addressType + "; " + originalRecipient;
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/eb167089/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 5fd3cee..0cd3cde 100644
--- a/mdn/src/test/java/org/apache/james/mdn/MDNFactoryTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/MDNFactoryTest.java
@@ -56,7 +56,7 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .finalRecipientField(new FinalRecipient("final_recipient"))
             .originalRecipientField(new OriginalRecipient("originalRecipient"))
             .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
             .dispositionField(disposition)
@@ -85,7 +85,7 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .finalRecipientField(new FinalRecipient("final_recipient"))
             .originalRecipientField(new OriginalRecipient("originalRecipient"))
             .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
             .dispositionField(disposition)
@@ -114,7 +114,7 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .finalRecipientField(new FinalRecipient("final_recipient"))
             .originalRecipientField(new OriginalRecipient("originalRecipient"))
             .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
             .dispositionField(disposition)
@@ -143,7 +143,7 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .finalRecipientField(new FinalRecipient("final_recipient"))
             .originalRecipientField(new OriginalRecipient("originalRecipient"))
             .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
             .dispositionField(disposition)
@@ -172,7 +172,7 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .finalRecipientField(new FinalRecipient("final_recipient"))
             .originalRecipientField(new OriginalRecipient("originalRecipient"))
             .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
             .dispositionField(disposition)
@@ -201,7 +201,7 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .finalRecipientField(new FinalRecipient("final_recipient"))
             .originalRecipientField(new OriginalRecipient("originalRecipient"))
             .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
             .dispositionField(disposition)
@@ -230,7 +230,7 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .finalRecipientField(new FinalRecipient("final_recipient"))
             .originalRecipientField(new OriginalRecipient("originalRecipient"))
             .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
             .dispositionField(disposition)
@@ -259,7 +259,7 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .finalRecipientField(new FinalRecipient("final_recipient"))
             .originalRecipientField(new OriginalRecipient("originalRecipient"))
             .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
             .dispositionField(disposition)
@@ -287,7 +287,7 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .finalRecipientField(new FinalRecipient("final_recipient"))
             .originalRecipientField(new OriginalRecipient("originalRecipient"))
             .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
             .dispositionField(disposition)
@@ -314,7 +314,7 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .finalRecipientField(new FinalRecipient("final_recipient"))
             .originalRecipientField(new OriginalRecipient("originalRecipient"))
             .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
             .dispositionField(disposition)
@@ -340,7 +340,7 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .finalRecipientField(new FinalRecipient("final_recipient"))
             .originalRecipientField(new OriginalRecipient("originalRecipient"))
             .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
             .dispositionField(disposition)
@@ -368,7 +368,7 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .finalRecipientField(new FinalRecipient("final_recipient"))
             .originalRecipientField(new OriginalRecipient("originalRecipient"))
             .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
             .dispositionField(disposition)
@@ -396,7 +396,7 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .finalRecipientField(new FinalRecipient("final_recipient"))
             .originalRecipientField(new OriginalRecipient("originalRecipient"))
             .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
             .dispositionField(disposition)
@@ -425,7 +425,7 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.empty()))
-            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .finalRecipientField(new FinalRecipient("final_recipient"))
             .originalRecipientField(new OriginalRecipient("originalRecipient"))
             .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
             .dispositionField(disposition)
@@ -454,7 +454,7 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .finalRecipientField(new FinalRecipient("final_recipient"))
             .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
             .dispositionField(disposition)
             .build()
@@ -468,7 +468,7 @@ public class MDNFactoryTest {
     }
 
     @Test
-    public void generateMDNReportShouldFormatNullFinalRecipient() {
+    public void generateMDNReportShouldFormatNullOriginalMessageId() {
         Disposition disposition = Disposition.builder()
             .actionMode(DispositionActionMode.Manual)
             .sendingMode(DispositionSendingMode.Automatic)
@@ -481,9 +481,9 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient(Optional.empty()))
+            .finalRecipientField(new FinalRecipient("final_recipient"))
             .originalRecipientField(new OriginalRecipient("originalRecipient"))
-            .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
+            .originalMessageIdField(new OriginalMessageId(Optional.empty()))
             .dispositionField(disposition)
             .build()
             .formattedValue();
@@ -491,17 +491,30 @@ public class MDNFactoryTest {
         assertThat(report)
             .isEqualTo("Reporting-UA: UA_name; UA_product\r\n" +
                 "Original-Recipient: rfc822; originalRecipient\r\n" +
-                "Final-Recepient: rfc822; \r\n" +
-                "Original-Message-ID: original_message_id\r\n" +
+                "Final-Recepient: rfc822; final_recipient\r\n" +
+                "Original-Message-ID: \r\n" +
                 "Disposition: manual-action/MDN-sent-automatically;deleted/error,failed\r\n");
     }
 
     @Test
-    public void generateMDNReportShouldFormatNullOriginalMessageId() {
+    public void generateMDNReportThrowOnNullDisposition() {
+        expectedException.expect(IllegalStateException.class);
+
+        MDNReport.builder()
+            .reportingUserAgentField(new ReportingUserAgent(
+                "UA_name",
+                Optional.of("UA_product")))
+            .finalRecipientField(new FinalRecipient("final_recipient"))
+            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .build();
+    }
+
+    @Test
+    public void generateMDNReportShouldFormatGateway() {
         Disposition disposition = Disposition.builder()
-            .actionMode(DispositionActionMode.Manual)
+            .actionMode(DispositionActionMode.Automatic)
             .sendingMode(DispositionSendingMode.Automatic)
-            .type(DispositionType.Deleted)
+            .type(DispositionType.Processed)
             .addModifier(DispositionModifier.Error)
             .addModifier(DispositionModifier.Failed)
             .build();
@@ -510,37 +523,85 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .gatewayField(new Gateway("host.com"))
+            .finalRecipientField(new FinalRecipient("final_recipient"))
             .originalRecipientField(new OriginalRecipient("originalRecipient"))
-            .originalMessageIdField(new OriginalMessageId(Optional.empty()))
+            .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: \r\n" +
-                "Disposition: manual-action/MDN-sent-automatically;deleted/error,failed\r\n");
+                "Original-Message-ID: original_message_id\r\n" +
+                "Disposition: automatic-action/MDN-sent-automatically;processed/error,failed\r\n");
     }
 
     @Test
-    public void generateMDNReportThrowOnNullDisposition() {
-        Disposition disposition = null;
-        expectedException.expect(IllegalStateException.class);
+    public void generateMDNReportShouldFormatGatewayWithExoticNameType() {
+        Disposition disposition = Disposition.builder()
+            .actionMode(DispositionActionMode.Automatic)
+            .sendingMode(DispositionSendingMode.Automatic)
+            .type(DispositionType.Processed)
+            .addModifier(DispositionModifier.Error)
+            .addModifier(DispositionModifier.Failed)
+            .build();
 
-        MDNReport.builder()
+        String report = MDNReport.builder()
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .gatewayField(new Gateway("postal", "5 rue Charles mercier"))
+            .finalRecipientField(new FinalRecipient("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");
+    }
+
+    @Test
+    public void generateMDNReportShouldFormatExoticAddressTypeForOriginalRecipient() {
+        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("final_recipient"))
+            .originalRecipientField(new OriginalRecipient("roomNumber", "385"))
+            .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
+            .dispositionField(disposition)
+            .build()
+            .formattedValue();
+
+        assertThat(report)
+            .isEqualTo("Reporting-UA: UA_name; UA_product\r\n" +
+                "Original-Recipient: roomNumber; 385\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 generateMDNReportShouldFormatGateway() {
+    public void generateMDNReportShouldFormatUnknownAddressTypeForOriginalRecipient() {
         Disposition disposition = Disposition.builder()
             .actionMode(DispositionActionMode.Automatic)
             .sendingMode(DispositionSendingMode.Automatic)
@@ -553,9 +614,8 @@ public class MDNFactoryTest {
             .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"))
+            .finalRecipientField(new FinalRecipient("final_recipient"))
+            .originalRecipientField(OriginalRecipient.ofUnknown("#$%*"))
             .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
             .dispositionField(disposition)
             .build()
@@ -563,15 +623,14 @@ public class MDNFactoryTest {
 
         assertThat(report)
             .isEqualTo("Reporting-UA: UA_name; UA_product\r\n" +
-                "MDN-Gateway: dns;host.com\r\n" +
-                "Original-Recipient: rfc822; originalRecipient\r\n" +
+                "Original-Recipient: unknown; #$%*\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() {
+    public void generateMDNReportShouldFormatExoticFinalRecipientAddressType() {
         Disposition disposition = Disposition.builder()
             .actionMode(DispositionActionMode.Automatic)
             .sendingMode(DispositionSendingMode.Automatic)
@@ -584,8 +643,7 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .gatewayField(new Gateway("postal", "5 rue Charles mercier"))
-            .finalRecipientField(new FinalRecipient(Optional.of("final_recipient")))
+            .finalRecipientField(new FinalRecipient("roomNumber", "781"))
             .originalRecipientField(new OriginalRecipient("originalRecipient"))
             .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
             .dispositionField(disposition)
@@ -594,10 +652,31 @@ public class MDNFactoryTest {
 
         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" +
+                "Final-Recepient: roomNumber; 781\r\n" +
                 "Original-Message-ID: original_message_id\r\n" +
                 "Disposition: automatic-action/MDN-sent-automatically;processed/error,failed\r\n");
     }
+
+    @Test
+    public void generateMDNReportShouldThrowWhenMissingFinalField() {
+        Disposition disposition = Disposition.builder()
+            .actionMode(DispositionActionMode.Automatic)
+            .sendingMode(DispositionSendingMode.Automatic)
+            .type(DispositionType.Processed)
+            .addModifier(DispositionModifier.Error)
+            .addModifier(DispositionModifier.Failed)
+            .build();
+
+        expectedException.expect(IllegalStateException.class);
+
+        MDNReport.builder()
+            .reportingUserAgentField(new ReportingUserAgent(
+                "UA_name",
+                Optional.of("UA_product")))
+            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .originalMessageIdField(new OriginalMessageId(Optional.of("original_message_id")))
+            .dispositionField(disposition)
+            .build();
+    }
 }


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