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 8f92e35937b4ad7ea4145d54aed252e2ceaed9d8
Author: Benoit Tellier <[email protected]>
AuthorDate: Wed Sep 30 11:58:25 2020 +0700

    JAMES-1717 VacationMailet should not send notification to senders with 
'-noreply' suffix
    
    This additional heuristic allow to better handle automatic sender that did 
not set there headers correctly
    for notifying that a mail is sent automatically.
---
 .../org/apache/james/jmap/mailet/VacationMailet.java | 17 ++++++++++++++---
 .../apache/james/jmap/mailet/VacationMailetTest.java | 20 ++++++++++++++++++++
 2 files changed, 34 insertions(+), 3 deletions(-)

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 d9c2588..aea13e6 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
@@ -20,6 +20,7 @@
 package org.apache.james.jmap.mailet;
 
 import java.time.ZonedDateTime;
+import java.util.Locale;
 
 import javax.inject.Inject;
 import javax.mail.MessagingException;
@@ -93,14 +94,24 @@ public class VacationMailet extends GenericMailet {
     }
 
     private void sendNotificationIfRequired(MailAddress recipient, Mail 
processedMail, ZonedDateTime processingDate, Vacation vacation, Boolean 
alreadySent) {
-        if (shouldSendNotification(vacation, processingDate, alreadySent)) {
+        if (shouldSendNotification(processedMail, vacation, processingDate, 
alreadySent)) {
             sendNotification(recipient, processedMail, vacation);
         }
     }
 
-    private boolean shouldSendNotification(Vacation vacation, ZonedDateTime 
processingDate, boolean alreadySent) {
+    private boolean shouldSendNotification(Mail processedMail, Vacation 
vacation, ZonedDateTime processingDate, boolean alreadySent) {
         return vacation.isActiveAtDate(processingDate)
-            && ! alreadySent;
+            && !alreadySent
+            && !isNoReplySender(processedMail);
+    }
+
+    private Boolean isNoReplySender(Mail processedMail) {
+        return processedMail.getMaybeSender()
+            .asOptional()
+            .map(address -> address.getLocalPart()
+                .toLowerCase(Locale.US)
+                .endsWith("-noreply"))
+            .orElse(true);
     }
 
     private void sendNotification(MailAddress recipient, Mail processedMail, 
Vacation vacation) {
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 d03b751..4d36816 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
@@ -241,6 +241,26 @@ public class VacationMailetTest {
     }
 
     @Test
+    public void serviceShouldNotSendNotificationToSenderWithNoReplySuffix() 
throws Exception {
+        FakeMail mail = FakeMail.builder()
+            .name("name")
+            .fileName("spamMail.eml")
+            .recipient(originalRecipient)
+            .sender(new MailAddress("[email protected]"))
+            .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));


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to