private Set<MailAddress> getReplyTos(InternetAddress[] replyToArray) { ImmutableSet.Builder<MailAddress> builder = ImmutableSet.builder(); for (InternetAddress replyTo : replyToArray) { try { builder.add(new MailAddress(replyTo)); } catch (ParseException pe) { LOGGER.warn("Unable to parse a \"REPLY_TO\" header address in the original message: {}; ignoring.", replyTo); } } return builder.build(); }
/** * Test method for {@link MailAddress#equals(java.lang.Object)}. * * @throws AddressException */ @Test public void testEqualsObject() throws AddressException { MailAddress a = new MailAddress(GOOD_ADDRESS); MailAddress b = new MailAddress(GOOD_ADDRESS); assertThat(a).isNotNull().isEqualTo(b); }
/** * Test method for {@link MailAddress#equals(java.lang.Object)}. * * @throws AddressException */ @Test public void testEqualsObject() throws AddressException { MailAddress a = new MailAddress(GOOD_ADDRESS); MailAddress b = new MailAddress(GOOD_ADDRESS); assertThat(a).isNotNull().isEqualTo(b); }
private MaybeSender toMaybeSender(String senderAsString) throws AddressException { if (senderAsString.length() == 0) { // This is the <> case. return MaybeSender.nullSender(); } if (senderAsString.equals("@")) { return MaybeSender.nullSender(); } return MaybeSender.of(new MailAddress( appendDefaultDomainIfNeeded(senderAsString))); }
@Override public MailAddress getMailAddressFor(User user) throws UsersRepositoryException { try { if (supportVirtualHosting()) { return new MailAddress(user.asString()); } return new MailAddress(user.getLocalPart(), domainList.getDefaultDomain()); } catch (Exception e) { throw new UsersRepositoryException("Failed to compute mail address associated with the user", e); } } }
@SuppressWarnings("deprecation") @Test public void getMailSenderShouldReturnParsedAddressWhenNotNullAddress() throws Exception { assertThat(MailAddress.getMailSender(GOOD_ADDRESS)) .isEqualTo(new MailAddress(GOOD_ADDRESS)); }
@Before public void setup() throws Exception { final MailetContext mailetContext = mock(MailetContext.class); postmaster = new MailAddress("postmaster@james.org"); when(mailetContext.getPostmaster()) .thenReturn(postmaster); RedirectNotify mailet = mock(RedirectNotify.class); when(mailet.getMailetContext()) .thenReturn(mailetContext); testee = SpecialAddressesUtils.from(mailet); }
@Test void getMailSenderShouldReturnParsedAddressWhenNotNullAddress() throws Exception { assertThat(MaybeSender.getMailSender(GOOD_ADDRESS)) .isEqualTo(MaybeSender.of(new MailAddress(GOOD_ADDRESS))); }
@Before public void setUp() throws Exception { DNSService dnsService = mock(DNSService.class); forward = new Forward(dnsService); postmaster = new MailAddress("postmaster@james.org"); fakeMailContext = FakeMailContext.builder() .postmaster(postmaster) .build(); when(dnsService.getLocalHost()).thenThrow(new UnknownHostException()); }
@Test public void nonVirtualHostedUsersRepositoryShouldUseLocalPartAsUsername() throws Exception { usersRepository.setEnableVirtualHosting(false); // Some implementations do not support changing virtual hosting value Assume.assumeFalse(usersRepository.supportVirtualHosting()); assertThat(usersRepository.getUser(new MailAddress("local@domain"))).isEqualTo("local"); }
@Test public void testBlackListedTextPresent() throws Exception { DNSRBLHandler rbl = createHandler(); setupMockedSMTPSession(new MailAddress("any@domain")); rbl.setBlacklist(new String[] { "bl.spamcop.net." }); rbl.setGetDetail(true); rbl.doRcpt(mockedSMTPSession, MaybeSender.nullSender(), new MailAddress("test@localhost")); assertThat(mockedSMTPSession.getAttachment(RBL_DETAIL_MAIL_ATTRIBUTE_NAME, State.Connection)).describedAs("Details").isEqualTo("Blocked - see http://www.spamcop.net/bl.shtml?127.0.0.2"); assertThat(mockedSMTPSession.getAttachment(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME, Connection)).withFailMessage("Blocked").isNotNull(); }
@Test public void testRejectInvalidHelo() throws Exception { MailAddress mailAddress = new MailAddress("test@localhost"); SMTPSession session = setupMockSession(INVALID_HOST,false,false,null,mailAddress); ResolvableEhloHeloHandler handler = createHandler(); handler.doHelo(session, INVALID_HOST); assertThat(session.getAttachment(BAD_EHLO_HELO, Transaction)).withFailMessage("Invalid HELO").isNotNull(); HookReturnCode result = handler.doRcpt(session,null, mailAddress).getResult(); assertThat(HookReturnCode.deny()).describedAs("Reject").isEqualTo(result); }
@Test public void testRejectInvalidHelo() throws Exception { MailAddress mailAddress = new MailAddress("test@localhost"); SMTPSession session = setupMockSession(INVALID_HOST,false,false,null,mailAddress); ResolvableEhloHeloHandler handler = createHandler(); handler.doHelo(session, INVALID_HOST); assertThat(session.getAttachment(BAD_EHLO_HELO, Transaction)).withFailMessage("Invalid HELO").isNotNull(); HookReturnCode result = handler.doRcpt(session, MaybeSender.nullSender(), mailAddress).getResult(); assertThat(HookReturnCode.deny()).describedAs("Reject").isEqualTo(result); }
@Test public void testRejectInvalidHeloAuthUser() throws Exception { MailAddress mailAddress = new MailAddress("test@localhost"); SMTPSession session = setupMockSession(INVALID_HOST,false,true,"valid@user",mailAddress); ResolvableEhloHeloHandler handler = createHandler(); handler.doHelo(session, INVALID_HOST); assertThat(session.getAttachment(BAD_EHLO_HELO, Transaction)).withFailMessage("Value stored").isNotNull(); HookReturnCode result = handler.doRcpt(session, MaybeSender.nullSender(), mailAddress).getResult(); assertThat(HookReturnCode.deny()).describedAs("Reject").isEqualTo(result); }
@Test public void testInvalidSenderDomainReject() throws Exception { ValidSenderDomainHandler handler = createHandler(); SMTPSession session = setupMockedSession(new MailAddress("invalid@invalid")); MaybeSender sender = (MaybeSender) session.getAttachment(SMTPSession.SENDER, State.Transaction); HookReturnCode response = handler.doMail(session, sender).getResult(); assertThat(HookReturnCode.deny()).describedAs("Blocked cause we use reject action").isEqualTo(response); } }
@Test public void testWhiteListed() throws Exception { DNSRBLHandler rbl = createHandler(); setRemoteIp("127.0.0.2"); setupMockedSMTPSession(new MailAddress("any@domain")); rbl.setWhitelist(new String[] { "bl.spamcop.net." }); rbl.setGetDetail(true); rbl.doRcpt(mockedSMTPSession, MaybeSender.nullSender(), new MailAddress("test@localhost")); assertThat(mockedSMTPSession.getAttachment(RBL_DETAIL_MAIL_ATTRIBUTE_NAME, Connection)).isNull(); assertThat(mockedSMTPSession.getAttachment(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME, Connection)).withFailMessage("Not blocked").isNull(); }
@Test public void testNotBlackListed() throws Exception { DNSRBLHandler rbl = createHandler(); setRemoteIp("192.168.0.1"); setupMockedSMTPSession(new MailAddress("any@domain")); rbl.setBlacklist(new String[] { "bl.spamcop.net." }); rbl.setGetDetail(true); rbl.doRcpt(mockedSMTPSession, MaybeSender.nullSender(), new MailAddress("test@localhost")); assertThat(mockedSMTPSession.getAttachment(RBL_DETAIL_MAIL_ATTRIBUTE_NAME, Connection)).withFailMessage("No details").isNull(); assertThat(mockedSMTPSession.getAttachment(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME, Connection)).withFailMessage("Not blocked").isNull(); }
@Test public void testNotRejectMaxRcpt() throws Exception { SMTPSession session = setupMockedSession(3); MaxRcptHandler handler = new MaxRcptHandler(); handler.setMaxRcpt(4); HookReturnCode resp = handler.doRcpt(session, MaybeSender.nullSender(), new MailAddress("test@test")).getResult(); assertThat(HookReturnCode.declined()).describedAs("Not Rejected..").isEqualTo(resp); }
@Test public void testRejectMaxRcpt() throws Exception { SMTPSession session = setupMockedSession(3); MaxRcptHandler handler = new MaxRcptHandler(); handler.setMaxRcpt(2); HookReturnCode resp = handler.doRcpt(session, MaybeSender.nullSender(), new MailAddress("test@test")).getResult(); assertThat(HookReturnCode.deny()).describedAs("Rejected.. To many recipients").isEqualTo(resp); }
@Test public void testNotRejectValidHelo() throws Exception { MailAddress mailAddress = new MailAddress("test@localhost"); SMTPSession session = setupMockSession(VALID_HOST,false,false,null,mailAddress); ResolvableEhloHeloHandler handler = createHandler(); handler.doHelo(session, VALID_HOST); assertThat(session.getAttachment(BAD_EHLO_HELO, Transaction)).withFailMessage("Valid HELO").isNull(); HookReturnCode result = handler.doRcpt(session, MaybeSender.nullSender(), mailAddress).getResult(); assertThat(HookReturnCode.declined()).describedAs("Not reject").isEqualTo(result); }