MAILET-122 Mails with null sender can be considered as automatically sent emails
James tends to send emails with null sender in case of error in the mailet pipeline Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/e0ca7967 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/e0ca7967 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/e0ca7967 Branch: refs/heads/master Commit: e0ca79672aa0c5006d3d52afb293be50595c4f18 Parents: cf28ef9 Author: Benoit Tellier <[email protected]> Authored: Fri Oct 7 15:54:51 2016 +0200 Committer: Benoit Tellier <[email protected]> Committed: Mon Oct 10 11:36:00 2016 +0200 ---------------------------------------------------------------------- .../base/AutomaticallySentMailDetectorImpl.java | 3 ++- .../AutomaticallySentMailDetectorImplTest.java | 21 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/e0ca7967/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java ---------------------------------------------------------------------- diff --git a/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java b/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java index b6360fb..0d1b634 100644 --- a/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java +++ b/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java @@ -46,7 +46,8 @@ public class AutomaticallySentMailDetectorImpl implements AutomaticallySentMailD "List-Archive" }; public boolean isAutomaticallySent(Mail mail) throws MessagingException { - return isMailingList(mail) || + return mail.getSender() == null || + isMailingList(mail) || isAutoSubmitted(mail) || isMdnSentAutomatically(mail); } http://git-wip-us.apache.org/repos/asf/james-project/blob/e0ca7967/mailet/base/src/test/java/org/apache/mailet/base/AutomaticallySentMailDetectorImplTest.java ---------------------------------------------------------------------- diff --git a/mailet/base/src/test/java/org/apache/mailet/base/AutomaticallySentMailDetectorImplTest.java b/mailet/base/src/test/java/org/apache/mailet/base/AutomaticallySentMailDetectorImplTest.java index 5e839ff..8a0147d 100644 --- a/mailet/base/src/test/java/org/apache/mailet/base/AutomaticallySentMailDetectorImplTest.java +++ b/mailet/base/src/test/java/org/apache/mailet/base/AutomaticallySentMailDetectorImplTest.java @@ -21,6 +21,7 @@ package org.apache.mailet.base; import static org.assertj.core.api.Assertions.assertThat; +import java.io.ByteArrayInputStream; import java.util.Properties; import javax.activation.DataHandler; @@ -37,6 +38,26 @@ import org.junit.Test; public class AutomaticallySentMailDetectorImplTest { @Test + public void nullSenderMailsShouldBeConsideredAsAutomaticMails() throws Exception { + assertThat( + new AutomaticallySentMailDetectorImpl() + .isAutomaticallySent(FakeMail.builder() + .build())) + .isTrue(); + } + + @Test + public void nonNullSenderMailsShouldNotBeConsideredAsAutomaticMails() throws Exception { + assertThat( + new AutomaticallySentMailDetectorImpl() + .isAutomaticallySent(FakeMail.builder() + .sender(MailAddressFixture.ANY_AT_JAMES) + .mimeMessage(new MimeMessage(Session.getDefaultInstance(new Properties()), new ByteArrayInputStream("".getBytes()))) + .build())) + .isFalse(); + } + + @Test public void ownerIsAMailingListPrefix() throws Exception { FakeMail fakeMail = FakeMail.builder() .sender(new MailAddress("[email protected]")) --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
