james-server-dev mailing list archives

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

Branch: refs/heads/master
Commit: db60b102799c98605a02caba3207d665959cfa3a
Parents: 93352f6
Author: Raphael Ouazana <raphael.ouazana@linagora.com>
Authored: Wed Apr 4 10:05:20 2018 +0200
Committer: Raphael Ouazana <raphael.ouazana@linagora.com>
Committed: Thu Apr 5 14:48:41 2018 +0200

----------------------------------------------------------------------
 .../org/apache/james/mdn/MDNReportParser.java   | 29 +++++++++++++++++++-
 .../apache/james/mdn/MDNReportParserTest.java   | 14 ++++++++++
 2 files changed, 42 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/db60b102/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 e625737..07e8b16 100644
--- a/mdn/src/main/java/org/apache/james/mdn/MDNReportParser.java
+++ b/mdn/src/main/java/org/apache/james/mdn/MDNReportParser.java
@@ -19,7 +19,10 @@
 
 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.ReportingUserAgent;
+import org.apache.james.mdn.fields.Text;
 import org.parboiled.BaseParser;
 import org.parboiled.Rule;
 
@@ -393,7 +396,31 @@ public class MDNReportParser {
         /*    mdn-gateway-field = "MDN-Gateway" ":" OWS mta-name-type OWS
                                   ";" OWS mta-name    */
         Rule mdnGatewayField() {
-            return Sequence("MDN-Gateway", ":", mtaNameType(), ows(), ";", ows(), mtaName());
+            return Sequence(
+                push(Gateway.builder()),
+                "MDN-Gateway", ":",
+                ows(),
+                mtaNameType(), ACTION(setMtaNameType()),
+                ows(),
+                ";",
+                ows(),
+                mtaName(), ACTION(setMtaName()),
+                ACTION(buildGateway()));
+        }
+
+        boolean setMtaNameType() {
+            this.<Gateway.Builder>peekT().nameType(new AddressType(match()));
+            return true;
+        }
+
+        boolean setMtaName() {
+            this.<Gateway.Builder>peekT().name(Text.fromRawText(match()));
+            return true;
+        }
+
+        boolean buildGateway() {
+            push(this.<Gateway.Builder>popT().build());
+            return true;
         }
 
         //    mta-name-type = Atom

http://git-wip-us.apache.org/repos/asf/james-project/blob/db60b102/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 007b4a6..d4d8cc9 100644
--- a/mdn/src/test/java/org/apache/james/mdn/MDNReportParserTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/MDNReportParserTest.java
@@ -22,7 +22,10 @@ package org.apache.james.mdn;
 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.ReportingUserAgent;
+import org.apache.james.mdn.fields.Text;
 import org.junit.Test;
 import org.parboiled.Parboiled;
 import org.parboiled.parserunners.ReportingParseRunner;
@@ -41,6 +44,7 @@ public class MDNReportParserTest {
     @Test
     public void dispositionNotificationContentShouldParseWhenMaximalSubset() {
         String maximal = "Reporting-UA: UA_name; UA_product\r\n" +
+            "MDN-Gateway: smtp; apache.org\r\n" +
             "Original-Recipient: rfc822; originalRecipient\r\n" +
             "Final-Recipient: rfc822; final_recipient\r\n" +
             "Original-Message-ID: <original@message.id>\r\n" +
@@ -92,4 +96,14 @@ public class MDNReportParserTest {
         assertThat(result.resultValue).isInstanceOf(ReportingUserAgent.class);
         assertThat((ReportingUserAgent)result.resultValue).isEqualTo(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build());
     }
+
+    @Test
+    public void mdnGatewayFieldShouldParse() {
+        String gateway = "MDN-Gateway: smtp; apache.org";
+        Parser parser = Parboiled.createParser(MDNReportParser.Parser.class);
+        ParsingResult<Object> result = new ReportingParseRunner<>(parser.mdnGatewayField()).run(gateway);
+        assertThat(result.matched).isTrue();
+        assertThat(result.resultValue).isInstanceOf(Gateway.class);
+        assertThat((Gateway)result.resultValue).isEqualTo(Gateway.builder().nameType(new
AddressType("smtp")).name(Text.fromRawText("apache.org")).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