james-server-dev mailing list archives

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

Branch: refs/heads/master
Commit: 800f176f0e08783d8950d5ece9a31d117e04b197
Parents: c470ef0
Author: Raphael Ouazana <raphael.ouazana@linagora.com>
Authored: Wed Apr 4 10:28:42 2018 +0200
Committer: Raphael Ouazana <raphael.ouazana@linagora.com>
Committed: Thu Apr 5 14:48:42 2018 +0200

----------------------------------------------------------------------
 .../org/apache/james/mdn/MDNReportParser.java   | 29 ++++++++++++++++++--
 .../apache/james/mdn/MDNReportParserTest.java   | 11 ++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/800f176f/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 07e8b16..f8a922a 100644
--- a/mdn/src/main/java/org/apache/james/mdn/MDNReportParser.java
+++ b/mdn/src/main/java/org/apache/james/mdn/MDNReportParser.java
@@ -21,6 +21,7 @@ package org.apache.james.mdn;
 
 import org.apache.james.mdn.fields.AddressType;
 import org.apache.james.mdn.fields.Gateway;
+import org.apache.james.mdn.fields.OriginalRecipient;
 import org.apache.james.mdn.fields.ReportingUserAgent;
 import org.apache.james.mdn.fields.Text;
 import org.parboiled.BaseParser;
@@ -437,8 +438,32 @@ public class MDNReportParser {
                      "Original-Recipient" ":" OWS address-type OWS
                      ";" OWS generic-address OWS    */
         Rule originalRecipientField() {
-            return Sequence("Original-Recipient", ":", ows(), addressType(), ows(),
-                ";", ows(), genericAddress(), ows());
+            return Sequence(
+                push(OriginalRecipient.builder()),
+                "Original-Recipient", ":",
+                ows(),
+                addressType(), ACTION(setAddressType()),
+                ows(),
+                ";",
+                ows(),
+                genericAddress(), ACTION(setGenericAddress()),
+                ows(),
+                ACTION(buildOriginalRecipient()));
+        }
+
+        boolean setAddressType() {
+            this.<OriginalRecipient.Builder>peekT().addressType(new AddressType(match()));
+            return true;
+        }
+
+        boolean setGenericAddress() {
+            this.<OriginalRecipient.Builder>peekT().originalRecipient(Text.fromRawText(match()));
+            return true;
+        }
+
+        boolean buildOriginalRecipient() {
+            push(this.<OriginalRecipient.Builder>popT().build());
+            return true;
         }
 
         //    address-type = Atom

http://git-wip-us.apache.org/repos/asf/james-project/blob/800f176f/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 d4d8cc9..a2ba033 100644
--- a/mdn/src/test/java/org/apache/james/mdn/MDNReportParserTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/MDNReportParserTest.java
@@ -24,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import org.apache.james.mdn.MDNReportParser.Parser;
 import org.apache.james.mdn.fields.AddressType;
 import org.apache.james.mdn.fields.Gateway;
+import org.apache.james.mdn.fields.OriginalRecipient;
 import org.apache.james.mdn.fields.ReportingUserAgent;
 import org.apache.james.mdn.fields.Text;
 import org.junit.Test;
@@ -106,4 +107,14 @@ public class MDNReportParserTest {
         assertThat(result.resultValue).isInstanceOf(Gateway.class);
         assertThat((Gateway)result.resultValue).isEqualTo(Gateway.builder().nameType(new
AddressType("smtp")).name(Text.fromRawText("apache.org")).build());
     }
+
+    @Test
+    public void originalRecipientFieldShouldParse() {
+        String originalRecipient = "Original-Recipient: rfc822; originalRecipient";
+        Parser parser = Parboiled.createParser(MDNReportParser.Parser.class);
+        ParsingResult<Object> result = new ReportingParseRunner<>(parser.originalRecipientField()).run(originalRecipient);
+        assertThat(result.matched).isTrue();
+        assertThat(result.resultValue).isInstanceOf(OriginalRecipient.class);
+        assertThat((OriginalRecipient)result.resultValue).isEqualTo(OriginalRecipient.builder().addressType(new
AddressType("rfc822")).originalRecipient(Text.fromRawText("originalRecipient")).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