You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2021/04/01 09:44:03 UTC

[GitHub] [james-project] Arsnael commented on a change in pull request #351: JAMES-4298 JAMP: Implement MDN parse

Arsnael commented on a change in pull request #351:
URL: https://github.com/apache/james-project/pull/351#discussion_r605508029



##########
File path: mdn/src/main/java/org/apache/james/mdn/MDN.java
##########
@@ -74,10 +83,83 @@ public MDN build() {
         }
     }
 
+    public static class MDNParseException extends Exception {
+        public MDNParseException(String message) {
+            super(message);
+        }
+
+        public MDNParseException(String message, Throwable cause) {
+            super(message, cause);
+        }
+    }
+
+    public static class MDNParseContentTypeException extends MDNParseException {
+        public MDNParseContentTypeException(String message) {
+            super(message);
+        }
+    }
+
+    public static class MDNParseBodyPartInvalidException extends MDNParseException {
+
+        public MDNParseBodyPartInvalidException(String message) {
+            super(message);
+        }
+    }
+
+
     public static Builder builder() {
         return new Builder();
     }
 
+    public static MDN parse(Message message) throws MDNParseException {
+        if (!message.isMultipart()) {
+            throw new MDNParseContentTypeException("MDN Message must be multipart");
+        }
+        List<Entity> bodyParts = ((Multipart) message.getBody()).getBodyParts();
+        if (bodyParts.size() < 2) {
+            throw new MDNParseBodyPartInvalidException("MDN Message must contain at least two parts");
+        }
+        try {
+            var humanReadableTextEntity = bodyParts.get(0);
+            return extractHumanReadableText(humanReadableTextEntity)
+                    .flatMap(humanReadableText1 -> extractMDNReport(bodyParts.get(1))
+                            .map(report1 -> MDN.builder()

Review comment:
       why do you need to put a 1 as a variable suffix here? Just call it `report` and also `humanReadableText` for the one above

##########
File path: server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/MDNParseSerializer.scala
##########
@@ -0,0 +1,52 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.json
+
+import org.apache.james.jmap.mail.{BlobId, BlobIds, ErrorField, ExtensionField, FinalRecipientField, ForEmailIdField, MDNDisposition, MDNNotFound, MDNNotParsable, MDNParseRequest, MDNParseResponse, MDNParsed, OriginalMessageIdField, ReportUAField, SubjectField, TextBodyField}
+import play.api.libs.json._
+
+object MDNParseSerializer {
+  private implicit val blobIdFormats: Format[BlobId] = Json.valueFormat[BlobId]
+  private implicit val blobIdsFormats: Format[BlobIds] = Json.valueFormat[BlobIds]

Review comment:
       duplicated line

##########
File path: server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/mailet/ExtractMDNOriginalJMAPMessageId.java
##########
@@ -85,12 +75,17 @@ public void service(Mail mail) throws MessagingException {
         MailAddress recipient = Iterables.getOnlyElement(mail.getRecipients());
         MimeMessage mimeMessage = mail.getMessage();
 
-        findReport(mimeMessage)
-            .flatMap(this::parseReport)
-            .flatMap(MDNReport::getOriginalMessageIdField)
-            .map(OriginalMessageId::getOriginalMessageId)
-            .flatMap(messageId -> findMessageIdForRFC822MessageId(messageId, recipient))
-            .ifPresent(messageId -> setJmapMessageIdAsHeader(mimeMessage, messageId));
+        try {
+            var message = new DefaultMessageBuilder().parseMessage(new MimeMessageInputStream(mimeMessage));
+            Optional.of(MDN.parse(message))
+                    .map(MDN::getReport)
+                    .flatMap(MDNReport::getOriginalMessageIdField)
+                    .map(OriginalMessageId::getOriginalMessageId)
+                    .flatMap(messageId -> findMessageIdForRFC822MessageId(messageId, recipient))
+                    .ifPresent(messageId -> setJmapMessageIdAsHeader(mimeMessage, messageId));

Review comment:
       indent issue




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org