private boolean containsOnlyUnalteredOrTo(List<InternetAddress> apparentlyTo) { return apparentlyTo.size() == 1 && (apparentlyTo.get(0).equals(SpecialAddress.UNALTERED.toInternetAddress()) || apparentlyTo.get(0).equals(SpecialAddress.RECIPIENTS.toInternetAddress())); } }
public void setSender(Optional<MailAddress> sender) throws MessagingException { if (sender.isPresent()) { mail.getMessage().setFrom(sender.get().toInternetAddress()); if (mailet.getInitParameters().isDebug()) { LOGGER.debug("sender set to: {}", sender); } } }
@Test public void getToShouldReturnEmptyWhenMailetToContainsOnlyRecipients() throws Exception { when(mailet.getTo()) .thenReturn(ImmutableList.of(SpecialAddress.RECIPIENTS.toInternetAddress())); FakeMail fakeMail = FakeMail.defaultFakeMail(); List<MailAddress> to = testee.getTo(fakeMail); assertThat(to).isEmpty(); }
@Test public void replaceInternetAddressesShouldReturnEmptyWhenAddressesMatchReversePathAndNoSender() throws Exception { FakeMail mail = FakeMail.builder() .build(); List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.REVERSE_PATH.toInternetAddress())); assertThat(addresses).isEmpty(); }
@Test public void replaceInternetAddressesShouldReturnEmptyWhenAddressesMatchUnaltered() throws Exception { FakeMail mail = FakeMail.builder() .build(); List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.UNALTERED.toInternetAddress())); assertThat(addresses).isEmpty(); }
@Test public void replaceInternetAddressesShouldReturnEmptyWhenAddressesMatchNull() throws Exception { FakeMail mail = FakeMail.builder() .build(); List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.NULL.toInternetAddress())); assertThat(addresses).isEmpty(); }
@Test public void replaceInternetAddressesShouldReturnSameAddressWhenAddressesDoesntMatch() throws Exception { FakeMail mail = FakeMail.builder() .build(); MailAddress address = new MailAddress("user", "address.marker"); MailAddress address2 = new MailAddress("user2", "address.marker"); List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(address.toInternetAddress(), address2.toInternetAddress())); assertThat(addresses).containsOnly(address, address2); }
@Test public void replaceInternetAddressesShouldReturnSenderWhenAddressesMatchSender() throws Exception { MailAddress sender = MailAddressFixture.ANY_AT_JAMES; FakeMail mail = FakeMail.builder() .sender(sender) .build(); List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.SENDER.toInternetAddress())); assertThat(addresses).containsOnly(sender); }
@Test public void replaceInternetAddressesShouldReturnSenderWhenAddressesMatchReversePath() throws Exception { MailAddress sender = MailAddressFixture.ANY_AT_JAMES; FakeMail mail = FakeMail.builder() .sender(sender) .build(); List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.REVERSE_PATH.toInternetAddress())); assertThat(addresses).containsOnly(sender); }
@Test public void replaceInternetAddressesShouldReturnReplyToWhenAddressesMatchReplyTo() throws Exception { MimeMessage message = MimeMessageUtil.defaultMimeMessage(); message.setReplyTo(InternetAddress.parse(MailAddressFixture.ANY_AT_JAMES.toString() + ", " + MailAddressFixture.OTHER_AT_JAMES.toString())); FakeMail mail = FakeMail.from(message); MailAddress expectedReplyTo = MailAddressFixture.ANY_AT_JAMES; MailAddress expectedReplyTo2 = MailAddressFixture.OTHER_AT_JAMES; List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.REPLY_TO.toInternetAddress())); assertThat(addresses).containsOnly(expectedReplyTo, expectedReplyTo2); }
@Test public void replaceInternetAddressesShouldReturnToWhenAddressesMatchRecipients() throws Exception { MailAddress to = MailAddressFixture.ANY_AT_JAMES; MailAddress to2 = MailAddressFixture.OTHER_AT_JAMES; FakeMail mail = FakeMail.from(MimeMessageBuilder.mimeMessageBuilder() .addToRecipient(to.asString(), to2.asString())); List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.RECIPIENTS.toInternetAddress())); assertThat(addresses).containsOnly(to, to2); }
@Test public void replaceInternetAddressesShouldReturnToWhenAddressesMatchTo() throws Exception { MailAddress to = MailAddressFixture.ANY_AT_JAMES; MailAddress to2 = MailAddressFixture.OTHER_AT_JAMES; FakeMail mail = FakeMail.from(MimeMessageBuilder.mimeMessageBuilder() .addToRecipient(to.asString(), to2.asString())); List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.TO.toInternetAddress())); assertThat(addresses).containsOnly(to, to2); }
@Test public void replaceInternetAddressesShouldReturnSenderWhenAddressesMatchFromAndNoFrom() throws Exception { MailAddress sender = MailAddressFixture.ANY_AT_JAMES; FakeMail mail = FakeMail.builder() .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()) .sender(sender) .build(); List<MailAddress> addresses = testee.replaceInternetAddresses(mail, ImmutableList.of(SpecialAddress.FROM.toInternetAddress())); assertThat(addresses).containsOnly(sender); }
@Test public void getToShouldReturnPostmasterWhenToIsNotconfigured() throws Exception { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName(MAILET_NAME) .mailetContext(fakeMailContext) .build(); notifyPostmaster.init(mailetConfig); assertThat(notifyPostmaster.getTo()).containsOnly(postmaster.toInternetAddress()); }
@Test public void getToShouldReturnSenderWhenToIsNotconfigured() throws Exception { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName(MAILET_NAME) .mailetContext(fakeMailContext) .build(); notifySender.init(mailetConfig); assertThat(notifySender.getTo()).containsOnly(SpecialAddress.SENDER.toInternetAddress()); }
@Test public void getToShouldReturnSenderWhenToIsEqualToSender() throws Exception { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName(MAILET_NAME) .mailetContext(fakeMailContext) .setProperty("to", "sender") .build(); notifySender.init(mailetConfig); assertThat(notifySender.getTo()).containsOnly(SpecialAddress.SENDER.toInternetAddress()); }
@Test public void getToShouldReturnPostmasterWhenToIsEqualToPostmaster() throws Exception { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName(MAILET_NAME) .mailetContext(fakeMailContext) .setProperty("to", "postmaster") .build(); notifyPostmaster.init(mailetConfig); assertThat(notifyPostmaster.getTo()).containsOnly(postmaster.toInternetAddress()); }
@Test public void getToShouldReturnUnalteredWhenToIsEqualToUnaltered() throws Exception { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName(MAILET_NAME) .mailetContext(fakeMailContext) .setProperty("to", "unaltered") .build(); notifyPostmaster.init(mailetConfig); assertThat(notifyPostmaster.getTo()).containsOnly(SpecialAddress.UNALTERED.toInternetAddress()); }
@Test public void getToShouldReturnPostmasterWhenToIsNotEqualToPostmasterOrUnaltered() throws Exception { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName(MAILET_NAME) .mailetContext(fakeMailContext) .setProperty("to", "otherTo") .build(); notifyPostmaster.init(mailetConfig); assertThat(notifyPostmaster.getTo()).containsOnly(postmaster.toInternetAddress()); }
@Test public void getToShouldReturnSenderWhenToIsNotEqualToSenderUnalteredOrFrom() throws Exception { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName(MAILET_NAME) .mailetContext(fakeMailContext) .setProperty("to", "otherTo") .build(); notifySender.init(mailetConfig); assertThat(notifySender.getTo()).containsOnly(SpecialAddress.SENDER.toInternetAddress()); }