You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2020/12/30 03:35:32 UTC

[james-project] 20/29: JAMES-1717 VacationMailet should not return answers when no or empty Reply-To header

This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 9768f0fb9a472a7ae7c0efdd8599be13e1cc5cb7
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Sat Dec 26 10:52:03 2020 +0700

    JAMES-1717 VacationMailet should not return answers when no or empty Reply-To header
---
 .../james/jmap/VacationRelayIntegrationTest.java   |  2 +-
 .../apache/james/jmap/mailet/VacationMailet.java   |  8 ++-
 .../james/jmap/mailet/VacationMailetTest.java      | 20 +++++++
 .../jmap-draft/src/test/resources/noReplyTo.eml    | 69 ++++++++++++++++++++++
 4 files changed, 97 insertions(+), 2 deletions(-)

diff --git a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java
index 77ad8a4..c528413 100644
--- a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java
+++ b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java
@@ -105,7 +105,7 @@ public abstract class VacationRelayIntegrationTest {
         smtpClient.helo(DOMAIN);
         smtpClient.setSender(externalMail);
         smtpClient.rcpt("<" + USER_WITH_DOMAIN + ">");
-        smtpClient.sendShortMessageData("content");
+        smtpClient.sendShortMessageData("Reply-To: <" + externalMail + ">\r\n\r\ncontent");
 
         calmlyAwait.atMost(1, TimeUnit.MINUTES)
             .untilAsserted(() ->
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/mailet/VacationMailet.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/mailet/VacationMailet.java
index f5fd41f..3430534 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/mailet/VacationMailet.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/mailet/VacationMailet.java
@@ -24,6 +24,7 @@ import java.util.Locale;
 
 import javax.inject.Inject;
 import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
 
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.james.core.MailAddress;
@@ -70,11 +71,16 @@ public class VacationMailet extends GenericMailet {
             if (!mail.hasSender()) {
                 return;
             }
-            if (! automaticallySentMailDetector.isAutomaticallySent(mail)) {
+            if (!automaticallySentMailDetector.isAutomaticallySent(mail)
+                    && mail.getMessage().getReplyTo().length > 0) {
                 ZonedDateTime processingDate = zonedDateTimeProvider.get();
                 mail.getRecipients()
                     .forEach(mailAddress -> manageVacation(mailAddress, mail, processingDate));
             }
+        } catch (AddressException e) {
+            if (!e.getMessage().equals("Empty address")) {
+                LOGGER.warn("Can not process vacation for one or more recipients in {}", mail.getRecipients(), e);
+            }
         } catch (Throwable e) {
             LOGGER.warn("Can not process vacation for one or more recipients in {}", mail.getRecipients(), e);
         }
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/mailet/VacationMailetTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/mailet/VacationMailetTest.java
index 971628f..b4e511b 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/mailet/VacationMailetTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/mailet/VacationMailetTest.java
@@ -261,6 +261,26 @@ public class VacationMailetTest {
     }
 
     @Test
+    public void serviceShouldNotSendNotificationToEmptyReplyTo() throws Exception {
+        FakeMail mail = FakeMail.builder()
+            .name("name")
+            .fileName("noReplyTo.eml")
+            .recipient(originalRecipient)
+            .sender(new MailAddress("distant-noreply@apache.org"))
+            .build();
+
+        when(vacationRepository.retrieveVacation(AccountId.fromString(USERNAME)))
+            .thenReturn(Mono.just(VACATION));
+        when(zonedDateTimeProvider.get()).thenReturn(DATE_TIME_2017);
+        when(notificationRegistry.isRegistered(any(), any())).thenReturn(Mono.just(false));
+        when(automaticallySentMailDetector.isAutomaticallySent(mail)).thenReturn(false);
+
+        testee.service(mail);
+
+        verifyNoMoreInteractions(mailetContext);
+    }
+
+    @Test
     public void serviceShouldNotPropagateExceptionIfSendFails() throws Exception {
         when(vacationRepository.retrieveVacation(AccountId.fromString(USERNAME)))
             .thenReturn(Mono.just(VACATION));
diff --git a/server/protocols/jmap-draft/src/test/resources/noReplyTo.eml b/server/protocols/jmap-draft/src/test/resources/noReplyTo.eml
new file mode 100644
index 0000000..d4f0c3f
--- /dev/null
+++ b/server/protocols/jmap-draft/src/test/resources/noReplyTo.eml
@@ -0,0 +1,69 @@
+Return-Path: <ro...@listes.apache.org>
+Content-Type: multipart/mixed; boundary="----------=_1433322346-12583-0"
+MIME-Version: 1.0
+From: "Content-filter at spam.apache.org" <po...@apache.org>
+Date: Wed, 3 Jun 2015 09:05:46 +0000 (UTC)
+To: <ro...@listes.apache.org>
+Message-ID: <VA...@spam.apache.org>
+Subject: Original subject
+X-BeenThere: root@listes.apache.org
+Errors-To: root-bounces@listes.apache.org
+Sender: "root" <ro...@listes.apache.org>
+Reply-To: <>
+
+This is a multi-part message in MIME format...
+
+------------=_1433322346-12583-0
+Content-Type: text/plain; charset="UTF-8"
+Content-Disposition: inline
+Content-Transfer-Encoding: 7bit
+
+No viruses were found.
+
+Content type: Unchecked
+Internal reference code for the message is 12583-16/Ss-IZaXqmZao
+
+According to a 'Received:' trace, the message apparently originated at:
+  [198.252.153.129], [127.0.0.1] localhost [127.0.0.1] Authenticated sender:
+  quentin.h
+
+Return-Path: <qu...@apache.org>
+From: Quentin <qu...@apache.org>
+Message-ID: <55...@apache.org>
+Subject: XYZ
+Not quarantined.
+
+The message WILL BE relayed to:
+<xx...@apache.org>
+
+
+------------=_1433322346-12583-0
+Content-Type: text/rfc822-headers; name="header"
+Content-Disposition: inline; filename="header"
+Content-Transfer-Encoding: 7bit
+Content-Description: Message header section
+
+Return-Path: <qu...@apache.org>
+Message-ID: <55...@apache.org>
+Date: Wed, 03 Jun 2015 11:05:37 +0200
+From: Quentin <qu...@apache.org>
+MIME-Version: 1.0
+To: Yann <ya...@apache.org>
+Subject: XYZ
+References: <55...@wootdevices.io> <55...@apache.org>
+In-Reply-To: <55...@apache.org>
+Content-Type: multipart/encrypted;
+ protocol="application/pgp-encrypted";
+ boundary="M0xVhKIvXqi85dG57o5RfCUAoFwhAw1Nh"
+
+------------=_1433322346-12583-0
+Content-Type: text/plain; charset="iso-8859-1"
+MIME-Version: 1.0
+Content-Transfer-Encoding: quoted-printable
+Content-Disposition: inline
+
+_______________________________________________
+root mailing list
+root@listes.apache.org
+https://listes.apache.org/cgi-bin/mailman/listinfo/root
+------------=_1433322346-12583-0--


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