protected boolean isBadHelo(SMTPSession session, String argument) { // try to resolv the provided helo. If it can not resolved do not // accept it. try { resolve(argument); } catch (UnknownHostException e) { return true; } return false; }
@Override public HookResult doHelo(SMTPSession session, String helo) { checkEhloHelo(session, helo); return HookResult.DECLINED; }
@Override public HookResult doRcpt(SMTPSession session, MaybeSender sender, MailAddress rcpt) { if (!isLocalDomain(session, rcpt.getDomain())) { return HookResult.DECLINED; } if (!isValidRecipient(session, rcpt)) { return reject(rcpt); } return HookResult.DECLINED; }
@Test public void testBlackListedNoTxt() throws Exception { DNSRBLHandler rbl = createHandler(); setRemoteIp("127.0.0.3"); setupMockedSMTPSession(new MailAddress("any@domain")); rbl.setBlacklist(new String[] { "bl.spamcop.net." }); rbl.setGetDetail(true); rbl.doRcpt(mockedSMTPSession, null, new MailAddress("test@localhost")); assertThat(mockedSMTPSession.getAttachment(RBL_DETAIL_MAIL_ATTRIBUTE_NAME, Connection)).isNull(); assertThat(mockedSMTPSession.getAttachment(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME, Connection)).withFailMessage("Blocked").isNotNull(); }
@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, null, 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 testNullSenderNotReject() { ValidSenderDomainHandler handler = createHandler(); HookReturnCode response = handler.doMail(setupMockedSession(null),null).getResult(); assertThat(HookReturnCode.declined()).describedAs("Not blocked cause its a nullsender").isEqualTo(response); }
@Override public InetSocketAddress getRemoteAddress() { return new InetSocketAddress(getRemoteIPAddress(), 10000); }
@Override public InetSocketAddress getRemoteAddress() { return new InetSocketAddress(getRemoteIPAddress(), 10000); }
@Before public void setUp() throws Exception { setRelayingAllowed(false); }
@Override public Object getAttachment(String key, State state) { if (state == State.Connection) { throw new UnsupportedOperationException(); } else { return getState().get(key); } }
/** * Check if EHLO/HELO is resolvable * * @param session * The SMTPSession * @param argument * The argument */ protected void checkEhloHelo(SMTPSession session, String argument) { if (isBadHelo(session, argument)) { session.setAttachment(BAD_EHLO_HELO, "true", State.Transaction); } }
@Resource(name="dnsservice") public void setDNSService(DNSService dns) { super.setDNSService(new SMTPServerDNSServiceAdapter(dns)); } }
@Resource(name="dnsservice") public void setDNSService(DNSService dns) { super.setDNSService(new SMTPServerDNSServiceAdapter(dns)); } }
@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, null, 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(); }
@Override public InetSocketAddress getRemoteAddress() { return new InetSocketAddress(getRemoteIPAddress(), 10000); }
@Override public InetSocketAddress getRemoteAddress() { return new InetSocketAddress(getRemoteIPAddress(), 10000); }
@Before public void setUp() throws Exception { setRelayingAllowed(false); }
@Override public Object getAttachment(String key, State state) { if (state == State.Connection) { throw new UnsupportedOperationException(); } else { return getState().get(key); } }
@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, null, 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 testGetNoDetail() throws Exception { DNSRBLHandler rbl = createHandler(); setupMockedSMTPSession(new MailAddress("any@domain")); rbl.setBlacklist(new String[] { "bl.spamcop.net." }); rbl.setGetDetail(false); rbl.doRcpt(mockedSMTPSession, null, 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("Blocked").isNotNull(); }