james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [26/27] james-project git commit: JAMES-2132 Ease calling MDNReport builder
Date Fri, 01 Sep 2017 01:18:39 GMT
JAMES-2132 Ease calling MDNReport 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/7c8ecec6
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/7c8ecec6
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/7c8ecec6

Branch: refs/heads/master
Commit: 7c8ecec6dba5c93fa7afe8d2b3cf02864bf8a72d
Parents: 4020b75
Author: benwa <btellier@linagora.com>
Authored: Wed Aug 30 14:18:44 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Sep 1 08:16:14 2017 +0700

----------------------------------------------------------------------
 .../java/org/apache/james/mdn/MDNReport.java    | 34 ++++++++++++++++++++
 .../james/mdn/fields/ReportingUserAgent.java    |  4 +--
 .../transport/mailets/jsieve/RejectAction.java  | 17 +++-------
 3 files changed, 39 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7c8ecec6/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 06b66b2..9682485 100644
--- a/mdn/src/main/java/org/apache/james/mdn/MDNReport.java
+++ b/mdn/src/main/java/org/apache/james/mdn/MDNReport.java
@@ -32,6 +32,7 @@ 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;
+import org.apache.james.mdn.fields.Text;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
@@ -52,11 +53,23 @@ public class MDNReport {
         private ImmutableList.Builder<Error> errorField = ImmutableList.builder();
         private ImmutableList.Builder<ExtensionField> extensionFields = ImmutableList.builder();
 
+        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;
         }
 
+        public Builder originalRecipientField(String originalRecipient) {
+            this.originalRecipientField = Optional.ofNullable(originalRecipient)
+                .map(Text::fromRawText)
+                .map(OriginalRecipient::new);
+            return this;
+        }
+
         public Builder originalRecipientField(OriginalRecipient originalRecipientField) {
             this.originalRecipientField = Optional.of(originalRecipientField);
             return this;
@@ -67,6 +80,11 @@ public class MDNReport {
             return this;
         }
 
+        public Builder gatewayField(String gatewayDns) {
+            this.gatewayField = Optional.of(new Gateway(Text.fromRawText(gatewayDns)));
+            return this;
+        }
+
         public Builder gatewayField(Optional<Gateway> gatewayField) {
             this.gatewayField = gatewayField;
             return this;
@@ -77,6 +95,12 @@ public class MDNReport {
             return this;
         }
 
+        public Builder addErrorField(String message) {
+            this.errorField.add(new Error(Text.fromRawText(message)));
+            return this;
+        }
+
+
         public Builder addErrorField(Error errorField) {
             this.errorField.add(errorField);
             return this;
@@ -87,11 +111,21 @@ public class MDNReport {
             return this;
         }
 
+        public Builder finalRecipientField(String finalRecipientField) {
+            this.finalRecipientField = Optional.of(new FinalRecipient(Text.fromRawText(finalRecipientField)));
+            return this;
+        }
+
         public Builder finalRecipientField(FinalRecipient finalRecipientField) {
             this.finalRecipientField = Optional.of(finalRecipientField);
             return this;
         }
 
+        public Builder originalMessageIdField(String originalMessageIdField) {
+            this.originalMessageIdField = Optional.of(new OriginalMessageId(originalMessageIdField));
+            return this;
+        }
+
         public Builder originalMessageIdField(OriginalMessageId originalMessageIdField) {
             this.originalMessageIdField = Optional.of(originalMessageIdField);
             return this;

http://git-wip-us.apache.org/repos/asf/james-project/blob/7c8ecec6/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 0772049..62bc92b 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
@@ -22,7 +22,6 @@ package org.apache.james.mdn.fields;
 import java.util.Objects;
 import java.util.Optional;
 
-import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 
 /**
@@ -43,8 +42,7 @@ public class ReportingUserAgent implements Field {
         this(userAgentName, Optional.of(userAgentProduct));
     }
 
-    @VisibleForTesting
-    ReportingUserAgent(String userAgentName, Optional<String> userAgentProduct) {
+    public ReportingUserAgent(String userAgentName, Optional<String> userAgentProduct)
{
         Preconditions.checkNotNull(userAgentName);
         Preconditions.checkNotNull(userAgentProduct);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/7c8ecec6/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 2dd88b8..0d4cbba 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
@@ -22,7 +22,6 @@ import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Optional;
 
 import javax.mail.Address;
 import javax.mail.MessagingException;
@@ -34,11 +33,6 @@ import org.apache.james.mdn.MDNFactory;
 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.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;
@@ -121,13 +115,10 @@ public class RejectAction implements MailAction {
         MimeMultipart multiPart = MDNFactory.create(
             humanText.toString(),
             MDNReport.builder()
-                .reportingUserAgentField(
-                    new ReportingUserAgent(
-                        reporting_UA_name,
-                        reporting_UA_product))
-                .finalRecipientField(new FinalRecipient(Text.fromRawText(final_recipient)))
-                .originalRecipientField(Optional.ofNullable(original_recipient).map(Text::fromRawText).map(OriginalRecipient::new))
-                .originalMessageIdField(new OriginalMessageId(original_message_id))
+                .reportingUserAgentField(reporting_UA_name, reporting_UA_product)
+                .finalRecipientField(final_recipient)
+                .originalRecipientField(original_recipient)
+                .originalMessageIdField(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