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 46d83c4a2f8612a46579a575ead58fc91ef439e4 Author: Benoit Tellier <[email protected]> AuthorDate: Wed Sep 30 10:51:11 2020 +0700 JAMES-1717 AutomaticallySentMailDetector should handle auto-generated and auto-notified See https://www.iana.org/assignments/auto-submitted-keywords/auto-submitted-keywords.xhtml --- .../mailet/base/AutomaticallySentMailDetector.java | 2 ++ .../AutomaticallySentMailDetectorImpl.java | 8 +++++++- .../AutomaticallySentMailDetectorImplTest.java | 24 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetector.java b/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetector.java index c90fc44..e81992e 100644 --- a/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetector.java +++ b/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetector.java @@ -27,6 +27,8 @@ public interface AutomaticallySentMailDetector { String AUTO_SUBMITTED_HEADER = "Auto-Submitted"; String AUTO_REPLIED_VALUE = "auto-replied"; + String AUTO_GENERATED_VALUE = "auto-generated"; + String AUTO_NOTIFIED_VALUE = "auto-notified"; boolean isAutomaticallySent(Mail mail) throws MessagingException; diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/AutomaticallySentMailDetectorImpl.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/AutomaticallySentMailDetectorImpl.java index ab9f557..6f91048 100644 --- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/AutomaticallySentMailDetectorImpl.java +++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/AutomaticallySentMailDetectorImpl.java @@ -85,11 +85,17 @@ public class AutomaticallySentMailDetectorImpl implements AutomaticallySentMailD String[] headers = mail.getMessage().getHeader(AUTO_SUBMITTED_HEADER); if (headers != null) { return Arrays.stream(headers) - .anyMatch(header -> header.equalsIgnoreCase(AUTO_REPLIED_VALUE)); + .anyMatch(this::isAutoSubmitted); } return false; } + private boolean isAutoSubmitted(String header) { + return header.equalsIgnoreCase(AUTO_REPLIED_VALUE) + || header.equalsIgnoreCase(AUTO_GENERATED_VALUE) + || header.equalsIgnoreCase(AUTO_NOTIFIED_VALUE); + } + @Override public boolean isMdnSentAutomatically(Mail mail) throws MessagingException { ResultCollector resultCollector = new ResultCollector(false); diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/AutomaticallySentMailDetectorImplTest.java b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/AutomaticallySentMailDetectorImplTest.java index b827b57..52d0071 100644 --- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/AutomaticallySentMailDetectorImplTest.java +++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/AutomaticallySentMailDetectorImplTest.java @@ -235,6 +235,30 @@ public class AutomaticallySentMailDetectorImplTest { } @Test + public void isAutoSubmittedShouldBeDetectedWhenAutoGenerated() throws Exception { + FakeMail fakeMail = FakeMail.builder() + .name("mail") + .sender("[email protected]") + .mimeMessage(MimeMessageBuilder.mimeMessageBuilder() + .addHeader("Auto-Submitted", "auto-generated")) + .build(); + + assertThat(new AutomaticallySentMailDetectorImpl().isAutoSubmitted(fakeMail)).isTrue(); + } + + @Test + public void isAutoSubmittedShouldBeDetectedWhenAutoNotified() throws Exception { + FakeMail fakeMail = FakeMail.builder() + .name("mail") + .sender("[email protected]") + .mimeMessage(MimeMessageBuilder.mimeMessageBuilder() + .addHeader("Auto-Submitted", "auto-notified")) + .build(); + + assertThat(new AutomaticallySentMailDetectorImpl().isAutoSubmitted(fakeMail)).isTrue(); + } + + @Test public void isMdnSentAutomaticallyShouldBeDetected() throws Exception { MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties())); MimeMultipart multipart = new MimeMultipart(); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
