This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 156c0866b964e2643189499dca767ef26258e8ab Author: Rémi Kowalski <[email protected]> AuthorDate: Tue Mar 17 16:55:01 2020 +0100 JAMES-3120 add test to demonstrate that RemoteMimeHeader will fail to process no-op a mail with incorrect headers --- .../transport/mailets/RemoveMimeHeaderTest.java | 17 +++++ .../src/test/resources/mime/incorrect-headers.mime | 87 ++++++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveMimeHeaderTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveMimeHeaderTest.java index baa5b5a..e29d425 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveMimeHeaderTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveMimeHeaderTest.java @@ -21,6 +21,7 @@ package org.apache.james.transport.mailets; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -29,11 +30,13 @@ import javax.mail.MessagingException; import org.apache.james.core.MailAddress; import org.apache.james.core.builder.MimeMessageBuilder; +import org.apache.james.util.MimeMessageUtil; import org.apache.mailet.Mail; import org.apache.mailet.PerRecipientHeaders.Header; import org.apache.mailet.base.GenericMailet; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMailetConfig; +import org.apache.mailet.base.test.MailUtil; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -174,6 +177,20 @@ class RemoveMimeHeaderTest { } @Test + void serviceShouldNotThrowWhenNoneMatchingAndIncorrectHeaders() throws MessagingException { + FakeMailetConfig mailetConfig = FakeMailetConfig.builder() + .mailetName("Test") + .setProperty("name", "") + .build(); + mailet.init(mailetConfig); + + Mail mail = MailUtil.createMockMail2Recipients( + MimeMessageUtil.mimeMessageFromStream( + ClassLoader.getSystemResourceAsStream("mime/incorrect-headers.mime"))); + assertThatCode(() -> mailet.service(mail)).doesNotThrowAnyException(); + } + + @Test void serviceShouldNotRemoveHeaderWhenEmptyConfig() throws MessagingException { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName("Test") diff --git a/mailet/standard/src/test/resources/mime/incorrect-headers.mime b/mailet/standard/src/test/resources/mime/incorrect-headers.mime new file mode 100644 index 0000000..426bdf1 --- /dev/null +++ b/mailet/standard/src/test/resources/mime/incorrect-headers.mime @@ -0,0 +1,87 @@ +Return-Path: <[email protected]> +Subject: Fwd: Invitation: (Aucun objet) - ven. 20 janv. 2017 14:00 - 15:00 + (CET) ([email protected]) +To: =?UTF-8?Q?Beno=c3=aet_SOMEONE?= <[email protected]> +From: james <[email protected]> +X-Forwarded-Message-Id: <[email protected]> +Message-ID: <[email protected]> +Date: Thu, 19 Jan 2017 20:36:37 +0100 +MIME-Version: 1.0 +In-Reply-To: <[email protected]> +Content-Type: multipart/mixed;charset=charset=us-ascii; + boundary="------------17D96D411CBD55D8239A8C1F" + +This is a multi-part message in MIME format. +--------------17D96D411CBD55D8239A8C1F +Content-Type: multipart/alternative; + boundary="------------64D716A3DDAEC185D3E67448" + + +--------------64D716A3DDAEC185D3E67448 +Content-Type: text/plain; charset=utf-8; format=flowed +Content-Transfer-Encoding: 8bit + + + + +-------- Message transéré -------- +Sujet : Invitation: (Aucun objet) - ven. 20 janv. 2017 14:00 - 15:00 +(CET) ([email protected]) +Date : Thu, 19 Jan 2017 19:18:23 +0000 +De : James <[email protected]> +Répondre à : [email protected] +Pour : [email protected] + + + + +--------------64D716A3DDAEC185D3E67448 +Content-Type: text/html; charset=utf-8 +Content-Transfer-Encoding: 8bit + +<html> + <head> + + <meta http-equiv="content-type" content="text/html; charset=utf-8"> + </head> + <body bgcolor="#FFFFFF" text="#000000"> + <p><br> + </p> + <div class="moz-forward-container"><br> + <br> + -------- Message transéré -------- + <table class="moz-email-headers-table" border="0" cellpadding="0" + cellspacing="0"> + <tbody> + <tr> + <th align="RIGHT" valign="BASELINE" nowrap="nowrap">Sujet : + </th> + <td>Invitation: (Aucun objet) - ven. 20 janv. 2017 14:00 - + 15:00 (CET) (<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>)</td> + </tr> + <tr> + <th align="RIGHT" valign="BASELINE" nowrap="nowrap">Date : </th> + <td>Thu, 19 Jan 2017 19:18:23 +0000</td> + </tr> + <tr> + <th align="RIGHT" valign="BASELINE" nowrap="nowrap">De : </th> + <td>Antoine james <a class="moz-txt-link-rfc2396E" href="mailto:[email protected]"><[email protected]></a></td> + </tr> + <tr> + <th align="RIGHT" valign="BASELINE" nowrap="nowrap">Répondre + à  : </th> + <td><a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a></td> + </tr> + <tr> + <th align="RIGHT" valign="BASELINE" nowrap="nowrap">Pour : </th> + <td><a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a></td> + </tr> + </tbody> + </table> + <br> + <br> + </div> + </body> +</html> + +--------------64D716A3DDAEC185D3E67448-- --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
