JAMES-2134 Parse Reporting-UA field and construct appropriate object with 
builder


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

Branch: refs/heads/master
Commit: b7ea0fe98b262d37d52b4dd4fab515bbe5fd786d
Parents: 1da96b8
Author: Matthieu Baechler <[email protected]>
Authored: Fri Mar 30 17:58:58 2018 +0200
Committer: Raphael Ouazana <[email protected]>
Committed: Thu Apr 5 14:48:41 2018 +0200

----------------------------------------------------------------------
 .../mail/model/impl/MessageParserTest.java      |  3 +-
 .../java/org/apache/james/mdn/MDNReport.java    | 10 ---
 .../org/apache/james/mdn/MDNReportParser.java   | 48 +++++++++--
 .../james/mdn/fields/ReportingUserAgent.java    | 44 +++++++---
 .../james/mdn/MDNReportFormattingTest.java      | 90 +++++---------------
 .../apache/james/mdn/MDNReportParserTest.java   | 21 +++++
 .../org/apache/james/mdn/MDNReportTest.java     | 10 +--
 .../mdn/fields/ReportingUserAgentTest.java      | 49 +++++------
 .../transport/mailets/jsieve/RejectAction.java  |  3 +-
 .../org/apache/james/jmap/model/JmapMDN.java    |  5 +-
 10 files changed, 146 insertions(+), 137 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b7ea0fe9/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
index 98bf77a..ff2d9a2 100644
--- 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
@@ -32,6 +32,7 @@ import org.apache.james.mdn.MDN;
 import org.apache.james.mdn.MDNReport;
 import org.apache.james.mdn.action.mode.DispositionActionMode;
 import org.apache.james.mdn.fields.Disposition;
+import org.apache.james.mdn.fields.ReportingUserAgent;
 import org.apache.james.mdn.sending.mode.DispositionSendingMode;
 import org.apache.james.mdn.type.DispositionType;
 import org.apache.james.mime4j.dom.Message;
@@ -297,7 +298,7 @@ public class MessageParserTest {
                     .type(DispositionType.Processed)
                     .build())
                 .originalMessageIdField("[email protected]")
-                .reportingUserAgentField("Thunderbird")
+                
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("Thunderbird").build())
                 .finalRecipientField("[email protected]")
                 .originalRecipientField("[email protected]")
                 .build())

http://git-wip-us.apache.org/repos/asf/james-project/blob/b7ea0fe9/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 8785737..82030a1 100644
--- a/mdn/src/main/java/org/apache/james/mdn/MDNReport.java
+++ b/mdn/src/main/java/org/apache/james/mdn/MDNReport.java
@@ -57,16 +57,6 @@ public class MDNReport {
         private ImmutableList.Builder<Error> errorField = 
ImmutableList.builder();
         private ImmutableList.Builder<ExtensionField> extensionFields = 
ImmutableList.builder();
 
-        public Builder reportingUserAgentField(String userAgentName) {
-            this.reportingUserAgentField = Optional.of(new 
ReportingUserAgent(userAgentName, Optional.empty()));
-            return this;
-        }
-
-        public Builder reportingUserAgentField(String userAgentName, String 
userAgentProduct) {
-            this.reportingUserAgentField = Optional.of(new 
ReportingUserAgent(userAgentName, Optional.ofNullable(userAgentProduct)));
-            return this;
-        }
-
         public Builder reportingUserAgentField(ReportingUserAgent 
reportingUserAgentField) {
             this.reportingUserAgentField = 
Optional.of(reportingUserAgentField);
             return this;

http://git-wip-us.apache.org/repos/asf/james-project/blob/b7ea0fe9/mdn/src/main/java/org/apache/james/mdn/MDNReportParser.java
----------------------------------------------------------------------
diff --git a/mdn/src/main/java/org/apache/james/mdn/MDNReportParser.java 
b/mdn/src/main/java/org/apache/james/mdn/MDNReportParser.java
index ac41a7e..e625737 100644
--- a/mdn/src/main/java/org/apache/james/mdn/MDNReportParser.java
+++ b/mdn/src/main/java/org/apache/james/mdn/MDNReportParser.java
@@ -19,8 +19,7 @@
 
 package org.apache.james.mdn;
 
-import java.util.Optional;
-
+import org.apache.james.mdn.fields.ReportingUserAgent;
 import org.parboiled.BaseParser;
 import org.parboiled.Rule;
 
@@ -30,12 +29,8 @@ public class MDNReportParser {
     public MDNReportParser() {
     }
 
-    public Optional<MDNReport> parse(String mdnReport) {
-        return Optional.empty();
-    }
-
     @VisibleForTesting
-    static class Parser extends BaseParser<MDNReport> {
+    static class Parser extends BaseParser<Object> {
         //   CFWS            =   (1*([FWS] comment) [FWS]) / FWS
         Rule cfws() {
             return FirstOf(
@@ -298,6 +293,7 @@ public class MDNReportParser {
                      *( extension-field CRLF )    */
         Rule dispositionNotificationContent() {
             return Sequence(
+                push(MDNReport.builder()),
                 Optional(Sequence(reportingUaField(), crlf())),
                 Optional(Sequence(mdnGatewayField(), crlf())),
                 Optional(Sequence(originalRecipientField(), crlf())),
@@ -311,8 +307,42 @@ public class MDNReportParser {
         /*    reporting-ua-field = "Reporting-UA" ":" OWS ua-name OWS [
                                    ";" OWS ua-product OWS ]    */
         Rule reportingUaField() {
-            return Sequence("Reporting-UA", ":", ows(), uaName(), ows(),
-                Optional(Sequence(";", ows(), uaProduct(), ows())));
+            return Sequence(
+                push(ReportingUserAgent.builder()),
+                "Reporting-UA", ":", ows(), uaName(), 
ACTION(setUserAgentName()), ows(),
+                Optional(Sequence(";", ows(), uaProduct(), 
ACTION(setUserAgentProduct()), ows())),
+                ACTION(buildReportingUserAgent())
+                );
+        }
+
+        boolean buildReportingUserAgent() {
+            push(this.<ReportingUserAgent.Builder>popT().build());
+            return true;
+        }
+
+        boolean setUserAgentName() {
+            this.<ReportingUserAgent.Builder>peekT().userAgentName(match());
+            return true;
+        }
+
+        boolean setUserAgentProduct() {
+            this.<ReportingUserAgent.Builder>peekT().userAgentProduct(match());
+            return true;
+        }
+
+        @SuppressWarnings("unchecked")
+        <T> T popT() {
+            return (T) pop();
+        }
+
+        @SuppressWarnings("unchecked")
+        <T> T peekParent() {
+            return (T) peek(1);
+        }
+
+        @SuppressWarnings("unchecked")
+        <T> T peekT() {
+            return (T) peek();
         }
 
         //    ua-name = *text-no-semi

http://git-wip-us.apache.org/repos/asf/james-project/blob/b7ea0fe9/mdn/src/main/java/org/apache/james/mdn/fields/ReportingUserAgent.java
----------------------------------------------------------------------
diff --git 
a/mdn/src/main/java/org/apache/james/mdn/fields/ReportingUserAgent.java 
b/mdn/src/main/java/org/apache/james/mdn/fields/ReportingUserAgent.java
index f3c67fb..eddddfe 100644
--- a/mdn/src/main/java/org/apache/james/mdn/fields/ReportingUserAgent.java
+++ b/mdn/src/main/java/org/apache/james/mdn/fields/ReportingUserAgent.java
@@ -36,22 +36,42 @@ public class ReportingUserAgent implements Field {
     private final String userAgentName;
     private final Optional<String> userAgentProduct;
 
-    public ReportingUserAgent(String userAgentName) {
-        this(userAgentName, Optional.empty());
+    public static Builder builder() {
+        return new Builder();
     }
 
-    public ReportingUserAgent(String userAgentName, String userAgentProduct) {
-        this(userAgentName, Optional.of(userAgentProduct));
-    }
+    public static class Builder {
+
+        private String userAgentName;
+        private Optional<String> userAgentProduct;
+
+        private Builder() {
+            userAgentProduct = Optional.empty();
+        }
+
+        public Builder userAgentName(String userAgentName) {
+            this.userAgentName = userAgentName;
+            return this;
+        }
 
-    public ReportingUserAgent(String userAgentName, Optional<String> 
userAgentProduct) {
-        Preconditions.checkNotNull(userAgentName);
-        Preconditions.checkNotNull(userAgentProduct);
-        Preconditions.checkArgument(!userAgentName.contains("\n"), "Name 
should not contain line break");
-        String trimmedName = userAgentName.trim();
-        Preconditions.checkArgument(!trimmedName.isEmpty(), "Name should not 
be empty");
+        public Builder userAgentProduct(String userAgentProduct) {
+            this.userAgentProduct = Optional.of(userAgentProduct);
+            return this;
+        }
+
+        public ReportingUserAgent build() {
+            Preconditions.checkNotNull(userAgentName);
+            Preconditions.checkNotNull(userAgentProduct);
+            Preconditions.checkState(!userAgentName.contains("\n"), "Name 
should not contain line break");
+            String trimmedName = userAgentName.trim();
+            Preconditions.checkState(!trimmedName.isEmpty(), "Name should not 
be empty");
+
+            return new ReportingUserAgent(trimmedName, userAgentProduct);
+        }
+    }
 
-        this.userAgentName = trimmedName;
+    private ReportingUserAgent(String userAgentName, Optional<String> 
userAgentProduct) {
+        this.userAgentName = userAgentName;
         this.userAgentProduct = userAgentProduct
             .map(String::trim)
             .filter(IS_EMPTY.negate());

http://git-wip-us.apache.org/repos/asf/james-project/blob/b7ea0fe9/mdn/src/test/java/org/apache/james/mdn/MDNReportFormattingTest.java
----------------------------------------------------------------------
diff --git 
a/mdn/src/test/java/org/apache/james/mdn/MDNReportFormattingTest.java 
b/mdn/src/test/java/org/apache/james/mdn/MDNReportFormattingTest.java
index 3f1555e..8ccf42f 100644
--- a/mdn/src/test/java/org/apache/james/mdn/MDNReportFormattingTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/MDNReportFormattingTest.java
@@ -50,9 +50,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))
@@ -79,9 +77,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))
@@ -108,9 +104,7 @@ public class MDNReportFormattingTest {
         .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))
@@ -137,9 +131,7 @@ public class MDNReportFormattingTest {
         .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))
@@ -166,9 +158,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))
@@ -195,9 +185,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))
@@ -223,9 +211,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))
@@ -251,9 +237,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))
@@ -278,9 +262,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))
@@ -307,7 +289,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent("UA_name"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))
@@ -334,9 +316,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
@@ -361,9 +341,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
             .dispositionField(disposition)
@@ -388,9 +366,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .gatewayField(new Gateway(Text.fromRawText("host.com")))
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
@@ -419,9 +395,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .gatewayField(new Gateway(new AddressType("postal"), 
Text.fromRawText("5 rue Charles mercier")))
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
@@ -450,9 +424,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new OriginalRecipient(new 
AddressType("roomNumber"), Text.fromRawText("385")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))
@@ -479,9 +451,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .gatewayField(new Gateway(new AddressType("postal"), 
Text.fromRawText("8 rue Charles mercier\n 36555 Saint Coincoin\n France")))
             .finalRecipientField(new FinalRecipient(new AddressType("postal"), 
Text.fromRawText("5 rue Mercier\n 36555 Saint Coincoin\n France")))
             .originalRecipientField(new OriginalRecipient(new 
AddressType("postal"), Text.fromRawText("3 rue Mercier\n 36555 Saint Coincoin\n 
France")))
@@ -516,9 +486,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             
.originalRecipientField(OriginalRecipient.ofUnknown(Text.fromRawText("#$%*")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))
@@ -545,9 +513,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new FinalRecipient(new 
AddressType("roomNumber"), Text.fromRawText("781")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))
@@ -574,9 +540,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))
@@ -605,9 +569,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))
@@ -639,9 +601,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))
@@ -671,9 +631,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))
@@ -703,9 +661,7 @@ public class MDNReportFormattingTest {
             .build();
 
         String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))

http://git-wip-us.apache.org/repos/asf/james-project/blob/b7ea0fe9/mdn/src/test/java/org/apache/james/mdn/MDNReportParserTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/MDNReportParserTest.java 
b/mdn/src/test/java/org/apache/james/mdn/MDNReportParserTest.java
index 9e2a873..007b4a6 100644
--- a/mdn/src/test/java/org/apache/james/mdn/MDNReportParserTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/MDNReportParserTest.java
@@ -22,6 +22,7 @@ package org.apache.james.mdn;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import org.apache.james.mdn.MDNReportParser.Parser;
+import org.apache.james.mdn.fields.ReportingUserAgent;
 import org.junit.Test;
 import org.parboiled.Parboiled;
 import org.parboiled.parserunners.ReportingParseRunner;
@@ -71,4 +72,24 @@ public class MDNReportParserTest {
         ParsingResult<Object> result = new 
ReportingParseRunner<>(parser.dispositionNotificationContent()).run(duplicated);
         assertThat(result.matched).isFalse();
     }
+
+    @Test
+    public void reportingUserAgentShouldParseWithoutProduct() {
+        String minimal = "Reporting-UA: UA_name";
+        Parser parser = Parboiled.createParser(MDNReportParser.Parser.class);
+        ParsingResult<Object> result = new 
ReportingParseRunner<>(parser.reportingUaField()).run(minimal);
+        assertThat(result.matched).isTrue();
+        assertThat(result.resultValue).isInstanceOf(ReportingUserAgent.class);
+        
assertThat((ReportingUserAgent)result.resultValue).isEqualTo(ReportingUserAgent.builder().userAgentName("UA_name").build());
+    }
+
+    @Test
+    public void reportingUserAgentShouldParseWithProduct() {
+        String minimal = "Reporting-UA: UA_name; UA_product";
+        Parser parser = Parboiled.createParser(MDNReportParser.Parser.class);
+        ParsingResult<Object> result = new 
ReportingParseRunner<>(parser.reportingUaField()).run(minimal);
+        assertThat(result.matched).isTrue();
+        assertThat(result.resultValue).isInstanceOf(ReportingUserAgent.class);
+        
assertThat((ReportingUserAgent)result.resultValue).isEqualTo(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build());
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b7ea0fe9/mdn/src/test/java/org/apache/james/mdn/MDNReportTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/MDNReportTest.java 
b/mdn/src/test/java/org/apache/james/mdn/MDNReportTest.java
index 4d21946..6ee9d7e 100644
--- a/mdn/src/test/java/org/apache/james/mdn/MDNReportTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/MDNReportTest.java
@@ -61,9 +61,7 @@ public class MDNReportTest {
         expectedException.expect(IllegalStateException.class);
 
         MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .finalRecipientField(new 
FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
             .build();
@@ -82,9 +80,7 @@ public class MDNReportTest {
         expectedException.expect(IllegalStateException.class);
 
         MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                "UA_product"))
+            
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
             .originalRecipientField(new 
OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new 
OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
@@ -124,7 +120,7 @@ public class MDNReportTest {
         Gateway gateway = new Gateway(Text.fromRawText("address"));
         OriginalMessageId originalMessageIdField = new 
OriginalMessageId("msgId");
         OriginalRecipient originalRecipientField = new 
OriginalRecipient(Text.fromRawText("address"));
-        ReportingUserAgent reportingUserAgentField = new 
ReportingUserAgent("name");
+        ReportingUserAgent reportingUserAgentField = 
ReportingUserAgent.builder().userAgentName("name").build();
         Error errorField1 = new Error(Text.fromRawText("error 1"));
         Error errorField2 = new Error(Text.fromRawText("error 2"));
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/b7ea0fe9/mdn/src/test/java/org/apache/james/mdn/fields/ReportingUserAgentTest.java
----------------------------------------------------------------------
diff --git 
a/mdn/src/test/java/org/apache/james/mdn/fields/ReportingUserAgentTest.java 
b/mdn/src/test/java/org/apache/james/mdn/fields/ReportingUserAgentTest.java
index 53954b8..abd5f1c 100644
--- a/mdn/src/test/java/org/apache/james/mdn/fields/ReportingUserAgentTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/fields/ReportingUserAgentTest.java
@@ -21,8 +21,6 @@ package org.apache.james.mdn.fields;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-import java.util.Optional;
-
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -45,22 +43,17 @@ public class ReportingUserAgentTest {
 
     @Test
     public void productShouldBeOptional() {
-        assertThat(new ReportingUserAgent(USER_AGENT_NAME))
-            .isEqualTo(new ReportingUserAgent(USER_AGENT_NAME, 
Optional.empty()));
+        
assertThat(ReportingUserAgent.builder().userAgentName(USER_AGENT_NAME).build())
+            
.isEqualTo(ReportingUserAgent.builder().userAgentName(USER_AGENT_NAME).build());
     }
 
-    @Test
-    public void productShouldBePresentWhenSpecified() {
-        assertThat(new ReportingUserAgent(USER_AGENT_NAME, USER_AGENT_PRODUCT))
-            .isEqualTo(new ReportingUserAgent(USER_AGENT_NAME, 
Optional.of(USER_AGENT_PRODUCT)));
-    }
 
     @Test
     public void shouldThrowOnNullName() {
         expectedException.expect(NullPointerException.class);
 
         String userAgentName = null;
-        new ReportingUserAgent(userAgentName);
+        ReportingUserAgent.builder().userAgentName(userAgentName).build();
     }
 
     @Test
@@ -68,7 +61,7 @@ public class ReportingUserAgentTest {
         expectedException.expect(NullPointerException.class);
 
         String userAgentName = null;
-        new ReportingUserAgent(userAgentName, USER_AGENT_PRODUCT);
+        
ReportingUserAgent.builder().userAgentName(userAgentName).userAgentProduct(USER_AGENT_PRODUCT).build();
     }
 
     @Test
@@ -76,82 +69,82 @@ public class ReportingUserAgentTest {
         expectedException.expect(NullPointerException.class);
 
         String userAgentProduct = null;
-        new ReportingUserAgent(USER_AGENT_NAME, userAgentProduct);
+        
ReportingUserAgent.builder().userAgentName(USER_AGENT_NAME).userAgentProduct(userAgentProduct).build();
     }
 
     @Test
     public void shouldThrowOnEmptyName() {
-        expectedException.expect(IllegalArgumentException.class);
+        expectedException.expect(IllegalStateException.class);
 
         String userAgentName = "";
-        new ReportingUserAgent(userAgentName);
+        ReportingUserAgent.builder().userAgentName(userAgentName).build();
     }
 
     @Test
     public void shouldThrowOnFoldingWhiteSpaceName() {
-        expectedException.expect(IllegalArgumentException.class);
+        expectedException.expect(IllegalStateException.class);
 
         String userAgentName = "   ";
-        new ReportingUserAgent(userAgentName);
+        ReportingUserAgent.builder().userAgentName(userAgentName).build();
     }
 
     @Test
     public void shouldThrowOnNameWithLineBreak() {
-        expectedException.expect(IllegalArgumentException.class);
+        expectedException.expect(IllegalStateException.class);
 
         String userAgentName = "a\nb";
-        new ReportingUserAgent(userAgentName);
+        ReportingUserAgent.builder().userAgentName(userAgentName).build();
     }
 
     @Test
     public void shouldThrowOnNameWithLineBreakAtTheEnd() {
-        expectedException.expect(IllegalArgumentException.class);
+        expectedException.expect(IllegalStateException.class);
 
         String userAgentName = "a\n";
-        new ReportingUserAgent(userAgentName);
+        ReportingUserAgent.builder().userAgentName(userAgentName).build();
     }
 
     @Test
     public void shouldThrowOnNameWithLineBreakAtTheBeginning() {
-        expectedException.expect(IllegalArgumentException.class);
+        expectedException.expect(IllegalStateException.class);
 
         String userAgentName = "\nb";
-        new ReportingUserAgent(userAgentName);
+        ReportingUserAgent.builder().userAgentName(userAgentName).build();
     }
 
     @Test
     public void nameShouldBeTrimmed() {
-        assertThat(new ReportingUserAgent(" name ").getUserAgentName())
+        assertThat(ReportingUserAgent.builder().userAgentName(" name 
").build().getUserAgentName())
             .isEqualTo(USER_AGENT_NAME);
     }
 
     @Test
     public void productShouldBeTrimmed() {
-        assertThat(new ReportingUserAgent(USER_AGENT_NAME, " product 
").getUserAgentProduct())
+        
assertThat(ReportingUserAgent.builder().userAgentName(USER_AGENT_NAME).userAgentProduct("
 product ").build().getUserAgentProduct())
             .contains(USER_AGENT_PRODUCT);
     }
 
     @Test
     public void formattedValueShouldDisplayNameWhenProductMissing() {
-        assertThat(new ReportingUserAgent(USER_AGENT_NAME).formattedValue())
+        
assertThat(ReportingUserAgent.builder().userAgentName(USER_AGENT_NAME).build().formattedValue())
             .isEqualTo("Reporting-UA: name; ");
     }
 
     @Test
     public void emptyProductShouldBeFilteredOut() {
-        assertThat(new ReportingUserAgent(USER_AGENT_NAME, 
"").getUserAgentProduct())
+        
assertThat(ReportingUserAgent.builder().userAgentName(USER_AGENT_NAME).userAgentProduct("").build().getUserAgentProduct())
             .isEmpty();
     }
 
     @Test
     public void foldingWhiteSpaceProductShouldBeFilteredOut() {
-        assertThat(new ReportingUserAgent(USER_AGENT_NAME, "  
").getUserAgentProduct())
+        
assertThat(ReportingUserAgent.builder().userAgentName(USER_AGENT_NAME).userAgentProduct("
  ").build().getUserAgentProduct())
             .isEmpty();
     }
 
     @Test
     public void formattedValueShouldDisplayProduct() {
-        assertThat(new ReportingUserAgent(USER_AGENT_NAME, 
USER_AGENT_PRODUCT).formattedValue())
+        
assertThat(ReportingUserAgent.builder().userAgentName(USER_AGENT_NAME).userAgentProduct(USER_AGENT_PRODUCT).build().formattedValue())
             .isEqualTo("Reporting-UA: name; product");
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b7ea0fe9/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 25f2b61..ce5c9d5 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
@@ -34,6 +34,7 @@ import org.apache.james.mdn.MDN;
 import org.apache.james.mdn.MDNReport;
 import org.apache.james.mdn.action.mode.DispositionActionMode;
 import org.apache.james.mdn.fields.Disposition;
+import org.apache.james.mdn.fields.ReportingUserAgent;
 import org.apache.james.mdn.modifier.DispositionModifier;
 import org.apache.james.mdn.sending.mode.DispositionSendingMode;
 import org.apache.james.mdn.type.DispositionType;
@@ -112,7 +113,7 @@ public class RejectAction implements MailAction {
             .humanReadableText(humanText.toString())
             .report(
                 MDNReport.builder()
-                    .reportingUserAgentField(reportingUAName, 
reportingUAProduct)
+                    
.reportingUserAgentField(ReportingUserAgent.builder().userAgentName(reportingUAName).userAgentProduct(reportingUAProduct).build())
                     .finalRecipientField(finalRecipient)
                     .originalRecipientField(originalRecipient)
                     .originalMessageIdField(originalMessageId)

http://git-wip-us.apache.org/repos/asf/james-project/blob/b7ea0fe9/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/JmapMDN.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/JmapMDN.java 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/JmapMDN.java
index abb4cd9..99f54f5 100644
--- 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/JmapMDN.java
+++ 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/JmapMDN.java
@@ -32,6 +32,7 @@ import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mdn.MDN;
 import org.apache.james.mdn.MDNReport;
 import org.apache.james.mdn.fields.Disposition;
+import org.apache.james.mdn.fields.ReportingUserAgent;
 import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.dom.Message;
 import org.apache.james.mime4j.dom.address.AddressList;
@@ -131,8 +132,8 @@ public class JmapMDN {
         return textBody;
     }
 
-    public String getReportingUA() {
-        return reportingUA;
+    public ReportingUserAgent getReportingUA() {
+        return ReportingUserAgent.builder().userAgentName(reportingUA).build();
     }
 
     public MDNDisposition getDisposition() {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to