james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [12/27] james-project git commit: JAMES-2132 Correct MDN Disposition structure
Date Fri, 01 Sep 2017 01:18:25 GMT
JAMES-2132 Correct MDN Disposition structure

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

   disposition-field =
             "Disposition" ":" OWS disposition-mode OWS ";"
             OWS disposition-type
             [ OWS "/" OWS disposition-modifier
             *( OWS "," OWS disposition-modifier ) ] OWS

   disposition-mode = action-mode OWS "/" OWS sending-mode

action-mode sending-mode and disposition-type are compulsory


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

Branch: refs/heads/master
Commit: fdd5cf34820116119782db85c9a0b1ca4398a842
Parents: d4303c5
Author: benwa <btellier@linagora.com>
Authored: Mon Aug 28 17:36:48 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Thu Aug 31 18:00:20 2017 +0700

----------------------------------------------------------------------
 .../apache/james/mdn/fields/Disposition.java    | 25 +++---
 .../org/apache/james/mdn/MDNFactoryTest.java    | 82 --------------------
 2 files changed, 14 insertions(+), 93 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/fdd5cf34/mdn/src/main/java/org/apache/james/mdn/fields/Disposition.java
----------------------------------------------------------------------
diff --git a/mdn/src/main/java/org/apache/james/mdn/fields/Disposition.java b/mdn/src/main/java/org/apache/james/mdn/fields/Disposition.java
index 85a0474..a3c802e 100644
--- a/mdn/src/main/java/org/apache/james/mdn/fields/Disposition.java
+++ b/mdn/src/main/java/org/apache/james/mdn/fields/Disposition.java
@@ -28,6 +28,7 @@ import org.apache.james.mdn.modifier.DispositionModifier;
 import org.apache.james.mdn.sending.mode.DispositionSendingMode;
 import org.apache.james.mdn.type.DispositionType;
 
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 
 public class Disposition implements Field {
@@ -63,7 +64,11 @@ public class Disposition implements Field {
         }
 
         public Disposition build() {
-            return new Disposition(actionMode, sendingMode, type, modifiers.build());
+            Preconditions.checkState(actionMode.isPresent());
+            Preconditions.checkState(sendingMode.isPresent());
+            Preconditions.checkState(type.isPresent());
+
+            return new Disposition(actionMode.get(), sendingMode.get(), type.get(), modifiers.build());
         }
     }
 
@@ -71,27 +76,27 @@ public class Disposition implements Field {
         return new Builder();
     }
 
-    private final Optional<DispositionActionMode> actionMode;
-    private final Optional<DispositionSendingMode> sendingMode;
-    private final Optional<DispositionType> type;
+    private final DispositionActionMode actionMode;
+    private final DispositionSendingMode sendingMode;
+    private final DispositionType type;
     private final List<DispositionModifier> modifiers;
 
-    private Disposition(Optional<DispositionActionMode> actionMode, Optional<DispositionSendingMode>
sendingMode, Optional<DispositionType> type, List<DispositionModifier> modifiers)
{
+    private Disposition(DispositionActionMode actionMode, DispositionSendingMode sendingMode,
DispositionType type, List<DispositionModifier> modifiers) {
         this.actionMode = actionMode;
         this.sendingMode = sendingMode;
         this.type = type;
         this.modifiers = ImmutableList.copyOf(modifiers);
     }
 
-    public Optional<DispositionActionMode> getActionMode() {
+    public DispositionActionMode getActionMode() {
         return actionMode;
     }
 
-    public Optional<DispositionSendingMode> getSendingMode() {
+    public DispositionSendingMode getSendingMode() {
         return sendingMode;
     }
 
-    public Optional<DispositionType> getType() {
+    public DispositionType getType() {
         return type;
     }
 
@@ -102,9 +107,7 @@ public class Disposition implements Field {
     @Override
     public String formattedValue() {
         return "Disposition: "
-            + actionMode.map(DispositionActionMode::getValue).orElse("") + "/"
-            + sendingMode.map(DispositionSendingMode::getValue).orElse("") + ";"
-            + type.map(DispositionType::getValue).orElse("")
+            + actionMode.getValue() + "/" + sendingMode.getValue() + ";" + type.getValue()
             + formattedModifiers();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/fdd5cf34/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 9749d81..968c788 100644
--- a/mdn/src/test/java/org/apache/james/mdn/MDNFactoryTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/MDNFactoryTest.java
@@ -330,88 +330,6 @@ public class MDNFactoryTest {
     }
 
     @Test
-    public void generateMDNReportShouldFormatNoModifierNullType() {
-        Disposition disposition = Disposition.builder()
-            .actionMode(DispositionActionMode.Manual)
-            .sendingMode(DispositionSendingMode.Manual)
-            .build();
-
-        String report = MDNReport.builder()
-            .reportingUserAgentField(new ReportingUserAgent(
-                "UA_name",
-                Optional.of("UA_product")))
-            .finalRecipientField(new FinalRecipient("final_recipient"))
-            .originalRecipientField(new OriginalRecipient("originalRecipient"))
-            .originalMessageIdField(new OriginalMessageId("original_message_id"))
-            .dispositionField(disposition)
-            .build()
-            .formattedValue();
-
-        assertThat(report)
-            .isEqualTo("Reporting-UA: UA_name; UA_product\r\n" +
-                "Original-Recipient: rfc822; originalRecipient\r\n" +
-                "Final-Recepient: rfc822; final_recipient\r\n" +
-                "Original-Message-ID: original_message_id\r\n" +
-                "Disposition: manual-action/MDN-sent-manually;\r\n");
-    }
-
-    @Test
-    public void generateMDNReportShouldFormatNullActionMode() {
-        Disposition disposition = Disposition.builder()
-            .sendingMode(DispositionSendingMode.Manual)
-            .type(DispositionType.Deleted)
-            .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("originalRecipient"))
-            .originalMessageIdField(new OriginalMessageId("original_message_id"))
-            .dispositionField(disposition)
-            .build()
-            .formattedValue();
-
-        assertThat(report)
-            .isEqualTo("Reporting-UA: UA_name; UA_product\r\n" +
-                "Original-Recipient: rfc822; originalRecipient\r\n" +
-                "Final-Recepient: rfc822; final_recipient\r\n" +
-                "Original-Message-ID: original_message_id\r\n" +
-                "Disposition: /MDN-sent-manually;deleted/error,failed\r\n");
-    }
-
-    @Test
-    public void generateMDNReportShouldFormatNullSendingMode() {
-        Disposition disposition = Disposition.builder()
-            .actionMode(DispositionActionMode.Manual)
-            .type(DispositionType.Deleted)
-            .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("originalRecipient"))
-            .originalMessageIdField(new OriginalMessageId("original_message_id"))
-            .dispositionField(disposition)
-            .build()
-            .formattedValue();
-
-        assertThat(report)
-            .isEqualTo("Reporting-UA: UA_name; UA_product\r\n" +
-                "Original-Recipient: rfc822; originalRecipient\r\n" +
-                "Final-Recepient: rfc822; final_recipient\r\n" +
-                "Original-Message-ID: original_message_id\r\n" +
-                "Disposition: manual-action/;deleted/error,failed\r\n");
-    }
-
-    @Test
     public void generateMDNReportShouldFormatNullUserAgentProduct() {
         Disposition disposition = Disposition.builder()
             .actionMode(DispositionActionMode.Manual)


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