james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [13/16] james-project git commit: JAMES-2134 Parse extension field and construct appropriate object
Date Thu, 05 Apr 2018 12:52:03 GMT
JAMES-2134 Parse extension field and construct appropriate object


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

Branch: refs/heads/master
Commit: 270c6ddceaa65cb7b837194bedb03d1151d31bb8
Parents: f92070e
Author: Raphael Ouazana <raphael.ouazana@linagora.com>
Authored: Wed Apr 4 12:31:53 2018 +0200
Committer: Raphael Ouazana <raphael.ouazana@linagora.com>
Committed: Thu Apr 5 14:48:43 2018 +0200

----------------------------------------------------------------------
 .../org/apache/james/mdn/MDNReportParser.java   | 23 +++++++++++++++++++-
 .../apache/james/mdn/MDNReportParserTest.java   | 11 ++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/270c6ddc/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 acba3f6..daf096f 100644
--- a/mdn/src/main/java/org/apache/james/mdn/MDNReportParser.java
+++ b/mdn/src/main/java/org/apache/james/mdn/MDNReportParser.java
@@ -23,6 +23,7 @@ import org.apache.james.mdn.action.mode.DispositionActionMode;
 import org.apache.james.mdn.fields.AddressType;
 import org.apache.james.mdn.fields.Disposition;
 import org.apache.james.mdn.fields.Error;
+import org.apache.james.mdn.fields.ExtensionField;
 import org.apache.james.mdn.fields.FinalRecipient;
 import org.apache.james.mdn.fields.Gateway;
 import org.apache.james.mdn.fields.OriginalMessageId;
@@ -644,7 +645,27 @@ public class MDNReportParser {
 
         //    extension-field = extension-field-name ":" *([FWS] text)
         Rule extentionField() {
-            return Sequence(extensionFieldName(), ":", ZeroOrMore(Sequence(Optional(fws()),
text())));
+            return Sequence(
+                push(ExtensionField.builder()),
+                extensionFieldName(), ACTION(setExtensionFieldName()),
+                ":",
+                ZeroOrMore(Sequence(Optional(fws()), text())), ACTION(setExtensionText()),
+                ACTION(buildExtension()));
+        }
+
+        boolean setExtensionFieldName() {
+            this.<ExtensionField.Builder>peekT().fieldName(match());
+            return true;
+        }
+
+        boolean setExtensionText() {
+            this.<ExtensionField.Builder>peekT().rawValue(match());
+            return true;
+        }
+
+        boolean buildExtension() {
+            push(this.<ExtensionField.Builder>popT().build());
+            return true;
         }
 
         //    extension-field-name = field-name

http://git-wip-us.apache.org/repos/asf/james-project/blob/270c6ddc/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 a3d0e11..dabe94c 100644
--- a/mdn/src/test/java/org/apache/james/mdn/MDNReportParserTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/MDNReportParserTest.java
@@ -26,6 +26,7 @@ import org.apache.james.mdn.action.mode.DispositionActionMode;
 import org.apache.james.mdn.fields.AddressType;
 import org.apache.james.mdn.fields.Disposition;
 import org.apache.james.mdn.fields.Error;
+import org.apache.james.mdn.fields.ExtensionField;
 import org.apache.james.mdn.fields.FinalRecipient;
 import org.apache.james.mdn.fields.Gateway;
 import org.apache.james.mdn.fields.OriginalMessageId;
@@ -262,4 +263,14 @@ public class MDNReportParserTest {
         assertThat(result.resultValue).isInstanceOf(Error.class);
         assertThat((Error)result.resultValue).isEqualTo(new Error(Text.fromRawText("Message1")));
     }
+
+    @Test
+    public void extensionFieldShouldParse() {
+        String extension = "X-OPENPAAS-IP: 177.177.177.77";
+        Parser parser = Parboiled.createParser(MDNReportParser.Parser.class);
+        ParsingResult<Object> result = new ReportingParseRunner<>(parser.extentionField()).run(extension);
+        assertThat(result.matched).isTrue();
+        assertThat(result.resultValue).isInstanceOf(ExtensionField.class);
+        assertThat((ExtensionField)result.resultValue).isEqualTo(ExtensionField.builder().fieldName("X-OPENPAAS-IP").rawValue("
177.177.177.77").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