AutomaticallySentMailDetectorImpl implements AutomaticallySentMailDetector { @Override public boolean isMailingList(Mail mail) throws MessagingException { return senderIsMailingList(mail) || headerIsMailingList(mail); }  @Override boolean isAutomaticallySent(Mail mail); @Override boolean isMailingList(Mail mail); @Override boolean isAutoSubmitted(Mail mail); @Override boolean isMdnSentAutomatically(Mail mail);  }
@Test public void ownerIsAMailingListPrefix() throws Exception { FakeMail fakeMail = FakeMail.builder() .name("mail") .sender("owner-list@any.com") .build(); assertThat(new AutomaticallySentMailDetectorImpl().isMailingList(fakeMail)).isTrue(); }
@Test public void requestIsAMailingListPrefix() throws Exception { FakeMail fakeMail = FakeMail.builder() .name("mail") .sender("list-request@any.com") .build(); assertThat(new AutomaticallySentMailDetectorImpl().isMailingList(fakeMail)).isTrue(); }
@Test public void mailerDaemonIsReserved() throws Exception { FakeMail fakeMail = FakeMail.builder() .name("mail") .sender("MAILER-DAEMON@any.com") .build(); assertThat(new AutomaticallySentMailDetectorImpl().isMailingList(fakeMail)).isTrue(); }
@Test public void listservIsReserved() throws Exception { FakeMail fakeMail = FakeMail.builder() .name("mail") .sender("LISTSERV@any.com") .build(); assertThat(new AutomaticallySentMailDetectorImpl().isMailingList(fakeMail)).isTrue(); }
@Test public void majordomoIsReserved() throws Exception { FakeMail fakeMail = FakeMail.builder() .name("mail") .sender("majordomo@any.com") .build(); assertThat(new AutomaticallySentMailDetectorImpl().isMailingList(fakeMail)).isTrue(); }
@Test public void listIdShouldBeDetected() throws Exception { FakeMail fakeMail = FakeMail.builder() .name("mail") .sender("any@any.com") .mimeMessage(MimeMessageBuilder.mimeMessageBuilder() .addHeader("List-Id", "any")) .build(); assertThat(new AutomaticallySentMailDetectorImpl().isMailingList(fakeMail)).isTrue(); }
@Test public void listHelpShouldBeDetected() throws Exception { FakeMail fakeMail = FakeMail.builder() .name("mail") .sender("any@any.com") .mimeMessage(MimeMessageBuilder.mimeMessageBuilder() .addHeader("List-Help", "any")) .build(); assertThat(new AutomaticallySentMailDetectorImpl().isMailingList(fakeMail)).isTrue(); }
@Test public void listSubscribeShouldBeDetected() throws Exception { FakeMail fakeMail = FakeMail.builder() .name("mail") .sender("any@any.com") .mimeMessage(MimeMessageBuilder.mimeMessageBuilder() .addHeader("List-Subscribe", "any")) .build(); assertThat(new AutomaticallySentMailDetectorImpl().isMailingList(fakeMail)).isTrue(); }
@Test public void listUnsubscribeShouldBeDetected() throws Exception { FakeMail fakeMail = FakeMail.builder() .name("mail") .sender("any@any.com") .mimeMessage(MimeMessageBuilder.mimeMessageBuilder() .addHeader("List-Unsubscribe", "any")) .build(); assertThat(new AutomaticallySentMailDetectorImpl().isMailingList(fakeMail)).isTrue(); }
@Test public void listPostShouldBeDetected() throws Exception { FakeMail fakeMail = FakeMail.builder() .name("mail") .sender("any@any.com") .mimeMessage(MimeMessageBuilder.mimeMessageBuilder() .addHeader("List-Post", "any")) .build(); assertThat(new AutomaticallySentMailDetectorImpl().isMailingList(fakeMail)).isTrue(); }
@Test public void listOwnerShouldBeDetected() throws Exception { FakeMail fakeMail = FakeMail.builder() .name("mail") .sender("any@any.com") .mimeMessage(MimeMessageBuilder.mimeMessageBuilder() .addHeader("List-Owner", "any")) .build(); assertThat(new AutomaticallySentMailDetectorImpl().isMailingList(fakeMail)).isTrue(); }
@Test public void listArchiveShouldBeDetected() throws Exception { FakeMail fakeMail = FakeMail.builder() .name("mail") .sender("any@any.com") .mimeMessage(MimeMessageBuilder.mimeMessageBuilder() .addHeader("List-Archive", "any")) .build(); assertThat(new AutomaticallySentMailDetectorImpl().isMailingList(fakeMail)).isTrue(); }
@Test public void normalMailShouldNotBeIdentifiedAsMailingList() throws Exception { FakeMail fakeMail = FakeMail.builder() .name("mail") .sender("any@any.com") .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()) .build(); assertThat(new AutomaticallySentMailDetectorImpl().isMailingList(fakeMail)).isFalse(); }