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 07:20:44 UTC

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

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



##########
File path: server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/mailet/ExtractMDNOriginalJMAPMessageIdTest.java
##########
@@ -1,107 +1,155 @@
-/****************************************************************
- * 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.mailet;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mime4j.dom.Message;
-import org.apache.james.mime4j.message.BodyPart;
-import org.apache.james.mime4j.message.BodyPartBuilder;
-import org.apache.james.mime4j.message.MultipartBuilder;
-import org.apache.james.mime4j.message.SingleBodyBuilder;
-import org.apache.james.user.api.UsersRepository;
-import org.junit.Test;
-
-public class ExtractMDNOriginalJMAPMessageIdTest {
-
-    @Test
-    public void extractReportShouldRejectNonMultipartMessage() throws IOException {
-        ExtractMDNOriginalJMAPMessageId testee = new ExtractMDNOriginalJMAPMessageId(mock(MailboxManager.class), mock(UsersRepository.class));
-
-        Message message = Message.Builder.of()
-            .setBody("content", StandardCharsets.UTF_8)
-            .build();
-
-        assertThat(testee.extractReport(message)).isEmpty();
-    }
-
-    @Test
-    public void extractReportShouldRejectMultipartWithSinglePart() throws Exception {
-        ExtractMDNOriginalJMAPMessageId testee = new ExtractMDNOriginalJMAPMessageId(mock(MailboxManager.class), mock(UsersRepository.class));
-
-        Message message = Message.Builder.of()
-            .setBody(
-                MultipartBuilder.create()
-                    .setSubType("report")
-                    .addTextPart("content", StandardCharsets.UTF_8)
-                    .build())
-            .build();
-
-        assertThat(testee.extractReport(message)).isEmpty();
-    }
-
-    @Test
-    public void extractReportShouldRejectSecondPartWithBadContentType() throws IOException {
-        ExtractMDNOriginalJMAPMessageId testee = new ExtractMDNOriginalJMAPMessageId(mock(MailboxManager.class), mock(UsersRepository.class));
-
-        Message message = Message.Builder.of()
-            .setBody(MultipartBuilder.create()
-                .setSubType("report")
-                .addTextPart("first", StandardCharsets.UTF_8)
-                .addTextPart("second", StandardCharsets.UTF_8)
-                .build())
-            .build();
-
-        assertThat(testee.extractReport(message)).isEmpty();
-    }
-
-    @Test
-    public void extractReportShouldExtractMDNWhenValidMDN() throws IOException {
-        ExtractMDNOriginalJMAPMessageId testee = new ExtractMDNOriginalJMAPMessageId(mock(MailboxManager.class), mock(UsersRepository.class));
-
-        BodyPart mdn = BodyPartBuilder
-            .create()
-            .setBody(SingleBodyBuilder.create()
-                .setText(
-                    "Reporting-UA: linagora.com; Evolution 3.26.5-1+b1 \n" +
-                        "Final-Recipient: rfc822; homer@linagora.com\n" +
-                        "Original-Message-ID: <15...@apache.org>\n" +
-                        "Disposition: manual-action/MDN-sent-manually;displayed\n")
-                .buildText())
-            .setContentType("message/disposition-notification")
-            .build();
-
-        Message message = Message.Builder.of()
-            .setBody(MultipartBuilder.create("report")
-                .addTextPart("first", StandardCharsets.UTF_8)
-                .addBodyPart(mdn)
-                .build())
-            .build();
-
-        assertThat(testee.extractReport(message))
-            .isNotEmpty()
-            .contains(mdn);
-    }
+/****************************************************************
+ * 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.mailet;
+
+import org.apache.james.mdn.MDN;
+import org.apache.james.mdn.MDN.MDNParseContentTypeException;
+import org.apache.james.mdn.MDN.MDNParseException;
+import org.apache.james.mdn.MDN.MDNParseBodyPartInvalidException;
+import org.apache.james.mdn.MDNReport;
+import org.apache.james.mdn.action.mode.DispositionActionMode;
+import org.apache.james.mdn.fields.*;
+import org.apache.james.mdn.modifier.DispositionModifier;
+import org.apache.james.mdn.sending.mode.DispositionSendingMode;
+import org.apache.james.mdn.type.DispositionType;
+import org.apache.james.mime4j.dom.Message;
+import org.apache.james.mime4j.message.BodyPart;
+import org.apache.james.mime4j.message.BodyPartBuilder;
+import org.apache.james.mime4j.message.MultipartBuilder;
+import org.apache.james.mime4j.message.SingleBodyBuilder;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.nio.charset.StandardCharsets;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class ExtractMDNOriginalJMAPMessageIdTest {
+
+    @Test
+    public void extractReportShouldRejectNonMultipartMessage() throws Exception {
+        Message message = Message.Builder.of()
+                .setBody("content", StandardCharsets.UTF_8)
+                .build();
+        assertThatThrownBy(() -> MDN.parse(message))
+                .isInstanceOf(MDNParseContentTypeException.class)
+                .hasMessage("MDN Message must be multipart");
+
+    }
+
+    @Test
+    public void extractReportShouldRejectMultipartWithSinglePart() throws Exception {
+        Message message = Message.Builder.of()
+                .setBody(
+                        MultipartBuilder.create()
+                                .setSubType("report")
+                                .addTextPart("content", StandardCharsets.UTF_8)
+                                .build())
+                .build();
+        assertThatThrownBy(() -> MDN.parse(message))
+                .isInstanceOf(MDNParseBodyPartInvalidException.class)
+                .hasMessage("MDN Message must contain at least two parts");
+    }
+
+    @Test
+    public void extractReportShouldRejectSecondPartWithBadContentType() throws Exception {
+        Message message = Message.Builder.of()
+                .setBody(MultipartBuilder.create()
+                        .setSubType("report")
+                        .addTextPart("first", StandardCharsets.UTF_8)
+                        .addTextPart("second", StandardCharsets.UTF_8)
+                        .build())
+                .build();
+        assertThatThrownBy(() -> MDN.parse(message))
+                .isInstanceOf(MDNParseException.class)
+                .hasMessage("MDN can not extract");
+    }
+
+    @Test
+    public void extractReportShouldExtractMDNWhenValidMDN() throws Exception {
+        BodyPart mdnBodyPart = BodyPartBuilder
+                .create()
+                .setBody(SingleBodyBuilder.create()
+                        .setText(
+                                "Reporting-UA: UA_name; UA_product\r\n" +
+                                        "MDN-Gateway: rfc822; apache.org\r\n" +
+                                        "Original-Recipient: rfc822; originalRecipient\r\n" +
+                                        "Final-Recipient: rfc822; final_recipient\r\n" +
+                                        "Original-Message-ID: <or...@message.id>\r\n" +
+                                        "Disposition: automatic-action/MDN-sent-automatically;processed/error,failed\r\n" +
+                                        "Error: Message1\r\n" +
+                                        "Error: Message2\r\n" +
+                                        "X-OPENPAAS-IP: 177.177.177.77\r\n" +
+                                        "X-OPENPAAS-PORT: 8000\r\n" +
+                                        ""
+                                                .replace(System.lineSeparator(), "\r\n").strip()
+                        )
+                        .buildText())
+                .setContentType("message/disposition-notification")
+                .build();
+
+        Message message = Message.Builder.of()
+                .setBody(MultipartBuilder.create("report")
+                        .addTextPart("first", StandardCharsets.UTF_8)
+                        .addBodyPart(mdnBodyPart)
+                        .build())
+                .build();
+        var mdnActual = MDN.parse(message);

Review comment:
       I we no longer have tests in it after test relocation, then yes.
   
   (Not having unit tests on this piece of code is a problem but let's not fix it now.)




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