james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [15/27] james-project git commit: JAMES-2132 Address should be Text
Date Fri, 01 Sep 2017 01:18:28 GMT
JAMES-2132 Address should be Text


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

Branch: refs/heads/master
Commit: beae701acd50bb8ffc7249386e7be87c70fbef82
Parents: c576fd1
Author: benwa <btellier@linagora.com>
Authored: Mon Aug 28 18:04:50 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Thu Aug 31 18:00:20 2017 +0700

----------------------------------------------------------------------
 .../apache/james/mdn/fields/FinalRecipient.java |  10 +-
 .../org/apache/james/mdn/fields/Gateway.java    |  10 +-
 .../james/mdn/fields/OriginalRecipient.java     |  12 +-
 .../org/apache/james/mdn/MDNFactoryTest.java    | 121 ++++++++++++-------
 .../transport/mailets/jsieve/RejectAction.java  |   7 +-
 5 files changed, 99 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/beae701a/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 5d0772e..fa4cd42 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
@@ -26,26 +26,26 @@ import com.google.common.base.Preconditions;
 public class FinalRecipient implements Field {
     public static final String FIELD_NAME = "Final-Recepient";
 
-    private final String finalRecipient;
+    private final Text finalRecipient;
     private final String addressType;
 
-    public FinalRecipient(String addressType, String finalRecipient) {
+    public FinalRecipient(String addressType, Text finalRecipient) {
         Preconditions.checkNotNull(finalRecipient);
         Preconditions.checkNotNull(addressType);
         this.finalRecipient = finalRecipient;
         this.addressType = addressType;
     }
 
-    public FinalRecipient(String finalRecipient) {
+    public FinalRecipient(Text finalRecipient) {
         this(Constants.RFC_822, finalRecipient);
     }
 
-    public String getFinalRecipient() {
+    public Text getFinalRecipient() {
         return finalRecipient;
     }
 
     @Override
     public String formattedValue() {
-        return FIELD_NAME + ": " + addressType + "; " + finalRecipient;
+        return FIELD_NAME + ": " + addressType + "; " + finalRecipient.formatted();
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/beae701a/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
index 4647c99..493aa6b 100644
--- a/mdn/src/main/java/org/apache/james/mdn/fields/Gateway.java
+++ b/mdn/src/main/java/org/apache/james/mdn/fields/Gateway.java
@@ -27,27 +27,27 @@ public class Gateway implements Field {
     public static final String FIELD_NAME = "MDN-Gateway";
 
     private final String nameType;
-    private final String name;
+    private final Text name;
 
-    public Gateway(String nameType, String name) {
+    public Gateway(String nameType, Text name) {
         this.nameType = nameType;
         this.name = name;
     }
 
-    public Gateway(String name) {
+    public Gateway(Text name) {
         this(DNS, name);
     }
 
     @Override
     public String formattedValue() {
-        return FIELD_NAME + ": " + nameType + ";" + name;
+        return FIELD_NAME + ": " + nameType + ";" + name.formatted();
     }
 
     public String getNameType() {
         return nameType;
     }
 
-    public String getName() {
+    public Text getName() {
         return name;
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/beae701a/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 9c399ff..f8e084d 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
@@ -26,25 +26,25 @@ import com.google.common.base.Preconditions;
 public class OriginalRecipient implements Field{
     private static final String UNKNOWN = "unknown";
 
-    public static OriginalRecipient ofUnknown(String address) {
+    public static OriginalRecipient ofUnknown(Text address) {
         return new OriginalRecipient(UNKNOWN, address);
     }
 
-    private final String originalRecipient;
+    private final Text originalRecipient;
     private final String addressType;
 
-    public OriginalRecipient(String addressType, String originalRecipient) {
+    public OriginalRecipient(String addressType, Text originalRecipient) {
         Preconditions.checkNotNull(addressType);
         Preconditions.checkNotNull(originalRecipient);
         this.addressType = addressType;
         this.originalRecipient = originalRecipient;
     }
 
-    public OriginalRecipient(String originalRecipient) {
+    public OriginalRecipient(Text originalRecipient) {
         this(Constants.RFC_822, originalRecipient);
     }
 
-    public String getOriginalRecipient() {
+    public Text getOriginalRecipient() {
         return originalRecipient;
     }
 
@@ -54,6 +54,6 @@ public class OriginalRecipient implements Field{
 
     @Override
     public String formattedValue() {
-        return "Original-Recipient: " + addressType + "; " + originalRecipient;
+        return "Original-Recipient: " + addressType + "; " + originalRecipient.formatted();
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/beae701a/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 01b71b7..d34e13a 100644
--- a/mdn/src/test/java/org/apache/james/mdn/MDNFactoryTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/MDNFactoryTest.java
@@ -58,8 +58,8 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
-            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
+            .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
             .build()
@@ -87,8 +87,8 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
-            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
+            .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
             .build()
@@ -116,8 +116,8 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
-            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
+            .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
             .build()
@@ -145,8 +145,8 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
-            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
+            .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
             .build()
@@ -174,8 +174,8 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
-            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
+            .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
             .build()
@@ -203,8 +203,8 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
-            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
+            .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
             .build()
@@ -231,8 +231,8 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
-            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
+            .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
             .build()
@@ -259,8 +259,8 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
-            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
+            .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
             .build()
@@ -286,8 +286,8 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
-            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
+            .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
             .build()
@@ -315,8 +315,8 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.empty()))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
-            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
+            .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
             .build()
@@ -344,7 +344,7 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
             .build()
@@ -371,8 +371,8 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
-            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
+            .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .dispositionField(disposition)
             .build()
             .formattedValue();
@@ -392,8 +392,8 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
-            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
+            .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .build();
     }
 
@@ -411,9 +411,9 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .gatewayField(new Gateway("host.com"))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
-            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .gatewayField(new Gateway(Text.fromRawText("host.com")))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
+            .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
             .build()
@@ -442,9 +442,9 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .gatewayField(new Gateway("postal", "5 rue Charles mercier"))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
-            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .gatewayField(new Gateway("postal", Text.fromRawText("5 rue Charles mercier")))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
+            .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
             .build()
@@ -473,8 +473,8 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
-            .originalRecipientField(new OriginalRecipient("roomNumber", "385"))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
+            .originalRecipientField(new OriginalRecipient("roomNumber", Text.fromRawText("385")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
             .build()
@@ -489,6 +489,43 @@ public class MDNFactoryTest {
     }
 
     @Test
+    public void generateMDNReportShouldFormatMultilineAddresses() {
+        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", Text.fromRawText("8 rue Charles mercier\n
36555 Saint Coincoin\n France")))
+            .finalRecipientField(new FinalRecipient("postal", Text.fromRawText("5 rue Mercier\n
36555 Saint Coincoin\n France")))
+            .originalRecipientField(new OriginalRecipient("postal", Text.fromRawText("3 rue
Mercier\n 36555 Saint Coincoin\n France")))
+            .originalMessageIdField(new OriginalMessageId("original_message_id"))
+            .dispositionField(disposition)
+            .build()
+            .formattedValue();
+
+        assertThat(report)
+            .isEqualTo("Reporting-UA: UA_name; UA_product\r\n" +
+                "MDN-Gateway: postal;8 rue Charles mercier\r\n" +
+                " 36555 Saint Coincoin\r\n" +
+                " France\r\n" +
+                "Original-Recipient: postal; 3 rue Mercier\r\n" +
+                " 36555 Saint Coincoin\r\n" +
+                " France\r\n" +
+                "Final-Recepient: postal; 5 rue Mercier\r\n" +
+                " 36555 Saint Coincoin\r\n" +
+                " France\r\n" +
+                "Original-Message-ID: original_message_id\r\n" +
+                "Disposition: automatic-action/MDN-sent-automatically;processed/error,failed\r\n");
+    }
+
+    @Test
     public void generateMDNReportShouldFormatUnknownAddressTypeForOriginalRecipient() {
         Disposition disposition = Disposition.builder()
             .actionMode(DispositionActionMode.Automatic)
@@ -502,8 +539,8 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
-            .originalRecipientField(OriginalRecipient.ofUnknown("#$%*"))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
+            .originalRecipientField(OriginalRecipient.ofUnknown(Text.fromRawText("#$%*")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
             .build()
@@ -531,8 +568,8 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient("roomNumber", "781"))
-            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .finalRecipientField(new FinalRecipient("roomNumber", Text.fromRawText("781")))
+            .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
             .build()
@@ -562,7 +599,7 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
             .build();
@@ -582,8 +619,8 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
-            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
+            .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
             .errorField(new Error(Text.fromRawText("An error message")))
@@ -613,8 +650,8 @@ public class MDNFactoryTest {
             .reportingUserAgentField(new ReportingUserAgent(
                 "UA_name",
                 Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
-            .originalRecipientField(new OriginalRecipient("originalRecipient"))
+            .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
+            .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")))

http://git-wip-us.apache.org/repos/asf/james-project/blob/beae701a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/jsieve/RejectAction.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/jsieve/RejectAction.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/jsieve/RejectAction.java
index fb624bb..8cd47ef 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/jsieve/RejectAction.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/jsieve/RejectAction.java
@@ -38,6 +38,7 @@ import org.apache.james.mdn.fields.FinalRecipient;
 import org.apache.james.mdn.fields.OriginalMessageId;
 import org.apache.james.mdn.fields.OriginalRecipient;
 import org.apache.james.mdn.fields.ReportingUserAgent;
+import org.apache.james.mdn.fields.Text;
 import org.apache.james.mdn.modifier.DispositionModifier;
 import org.apache.james.mdn.sending.mode.DispositionSendingMode;
 import org.apache.james.mdn.type.DispositionType;
@@ -124,9 +125,9 @@ public class RejectAction implements MailAction {
                     new ReportingUserAgent(
                         reporting_UA_name,
                         Optional.ofNullable(reporting_UA_product)))
-                .finalRecipientField(new FinalRecipient(Optional.of(final_recipient)))
-                .originalRecipientField(Optional.ofNullable(original_recipient).map(OriginalRecipient::new))
-                .originalMessageIdField(new OriginalMessageId(Optional.of(original_message_id)))
+                .finalRecipientField(new FinalRecipient(Text.fromRawText(final_recipient)))
+                .originalRecipientField(Optional.ofNullable(original_recipient).map(Text::fromRawText).map(OriginalRecipient::new))
+                .originalMessageIdField(new OriginalMessageId(original_message_id))
                 .dispositionField(Disposition.builder()
                     .actionMode(DispositionActionMode.Automatic)
                     .sendingMode(DispositionSendingMode.Automatic)


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