james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [11/16] james-project git commit: JAMES-2134 Parse Error field and construct appropriate object
Date Thu, 05 Apr 2018 12:52:01 GMT
JAMES-2134 Parse Error 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/6528e342
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/6528e342
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/6528e342

Branch: refs/heads/master
Commit: 6528e3422ad27e82d1bbb2bfc3cca51b04dba8f6
Parents: e204857
Author: Raphael Ouazana <raphael.ouazana@linagora.com>
Authored: Wed Apr 4 12:16:46 2018 +0200
Committer: Raphael Ouazana <raphael.ouazana@linagora.com>
Committed: Thu Apr 5 14:48:42 2018 +0200

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


http://git-wip-us.apache.org/repos/asf/james-project/blob/6528e342/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 07a4ef2..acba3f6 100644
--- a/mdn/src/main/java/org/apache/james/mdn/MDNReportParser.java
+++ b/mdn/src/main/java/org/apache/james/mdn/MDNReportParser.java
@@ -22,6 +22,7 @@ package org.apache.james.mdn;
 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.FinalRecipient;
 import org.apache.james.mdn.fields.Gateway;
 import org.apache.james.mdn.fields.OriginalMessageId;
@@ -636,7 +637,9 @@ public class MDNReportParser {
 
         //    error-field = "Error" ":" *([FWS] text)
         Rule errorField() {
-            return Sequence("Error", ":", ZeroOrMore(Sequence(Optional(fws()), text())));
+            return Sequence(
+                "Error", ":",
+                ZeroOrMore(Sequence(Optional(fws()), text())), push(new Error(Text.fromRawText(match()))));
         }
 
         //    extension-field = extension-field-name ":" *([FWS] text)

http://git-wip-us.apache.org/repos/asf/james-project/blob/6528e342/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 05bc80f..a3d0e11 100644
--- a/mdn/src/test/java/org/apache/james/mdn/MDNReportParserTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/MDNReportParserTest.java
@@ -25,6 +25,7 @@ import org.apache.james.mdn.MDNReportParser.Parser;
 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.FinalRecipient;
 import org.apache.james.mdn.fields.Gateway;
 import org.apache.james.mdn.fields.OriginalMessageId;
@@ -251,4 +252,14 @@ public class MDNReportParserTest {
         assertThat(result.resultValue).isInstanceOf(Disposition.class);
         assertThat((Disposition)result.resultValue).isEqualTo(expected);
     }
+
+    @Test
+    public void errorFieldShouldParse() {
+        String error = "Error: Message1";
+        Parser parser = Parboiled.createParser(MDNReportParser.Parser.class);
+        ParsingResult<Object> result = new ReportingParseRunner<>(parser.errorField()).run(error);
+        assertThat(result.matched).isTrue();
+        assertThat(result.resultValue).isInstanceOf(Error.class);
+        assertThat((Error)result.resultValue).isEqualTo(new Error(Text.fromRawText("Message1")));
+    }
 }


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