@Override public void init(Configuration config) throws ConfigurationException { setBlockSoftFail(config.getBoolean("blockSoftFail", false)); setBlockPermError(config.getBoolean("blockPermError", true)); }
@Override public HookResult doMail(SMTPSession session, MailAddress sender) { doSPFCheck(session, sender); return HookResult.DECLINED; }
@Test public void testSPFsoftFailRejectEnabled() throws Exception { MailAddress sender = new MailAddress("test@spf3.james.apache.org"); MailAddress rcpt = new MailAddress("test@localhost"); setupMockedSMTPSession("192.168.100.1", "spf3.james.apache.org"); SPFHandler spf = new SPFHandler(); spf.setDNSService(mockedDnsService); spf.setBlockSoftFail(true); assertThat(spf.doMail(mockedSMTPSession, sender).getResult()).describedAs("declined").isEqualTo(HookReturnCode.declined()); assertThat(spf.doRcpt(mockedSMTPSession, sender, rcpt).getResult()).describedAs("softfail reject").isEqualTo(HookReturnCode.deny()); }
@Test public void testSPFpermError() throws Exception { MailAddress sender = new MailAddress("test@spf4.james.apache.org"); MailAddress rcpt = new MailAddress("test@localhost"); setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org"); SPFHandler spf = new SPFHandler(); spf.setDNSService(mockedDnsService); spf.setBlockSoftFail(true); assertThat(spf.doMail(mockedSMTPSession, sender).getResult()).describedAs("declined").isEqualTo(HookReturnCode.declined()); assertThat(spf.doRcpt(mockedSMTPSession, sender, rcpt).getResult()).describedAs("permerror reject").isEqualTo(HookReturnCode.deny()); }
@Test public void testSPFpermErrorRejectDisabled() throws Exception { MailAddress sender = new MailAddress("test@spf4.james.apache.org"); MailAddress rcpt = new MailAddress("test@localhost"); setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org"); SPFHandler spf = new SPFHandler(); spf.setDNSService(mockedDnsService); spf.setBlockPermError(false); assertThat(spf.doMail(mockedSMTPSession, sender).getResult()).describedAs("declined").isEqualTo(HookReturnCode.declined()); assertThat(spf.doRcpt(mockedSMTPSession, sender, rcpt).getResult()).describedAs("declined").isEqualTo(HookReturnCode.declined()); } }
public void configure(HierarchicalConfiguration handlerConfiguration) throws ConfigurationException { setBlockSoftFail(handlerConfiguration.getBoolean( "blockSoftFail", false)); setBlockPermError(handlerConfiguration.getBoolean("blockPermError", true)); }
/** * @see org.apache.james.protocols.smtp.hook.MailHook#doMail(org.apache.james.protocols.smtp.SMTPSession, org.apache.mailet.MailAddress) */ public HookResult doMail(SMTPSession session, MailAddress sender) { doSPFCheck(session,sender); return new HookResult(HookReturnCode.DECLINED); }
@Test public void testSPFsoftFail() throws Exception { MailAddress sender = new MailAddress("test@spf3.james.apache.org"); MailAddress rcpt = new MailAddress("test@localhost"); setupMockedSMTPSession("192.168.100.1", "spf3.james.apache.org"); SPFHandler spf = new SPFHandler(); spf.setDNSService(mockedDnsService); assertThat(spf.doMail(mockedSMTPSession, sender).getResult()).describedAs("declined").isEqualTo(HookReturnCode.declined()); assertThat(spf.doRcpt(mockedSMTPSession, sender, rcpt).getResult()).describedAs("softfail declined").isEqualTo(HookReturnCode.declined()); }
@Test public void testSPFpass() throws Exception { MailAddress sender = new MailAddress("test@spf1.james.apache.org"); MailAddress rcpt = new MailAddress("test@localhost"); setupMockedSMTPSession("192.168.100.1", "spf1.james.apache.org"); SPFHandler spf = new SPFHandler(); spf.setDNSService(mockedDnsService); assertThat(spf.doMail(mockedSMTPSession, sender).getResult()).describedAs("declined").isEqualTo(HookReturnCode.declined()); assertThat(spf.doRcpt(mockedSMTPSession, sender, rcpt).getResult()).describedAs("declined").isEqualTo(HookReturnCode.declined()); }
@Test public void testSPFfail() throws Exception { MailAddress sender = new MailAddress("test@spf2.james.apache.org"); MailAddress rcpt = new MailAddress("test@localhost"); setupMockedSMTPSession("192.168.100.1", "spf2.james.apache.org"); SPFHandler spf = new SPFHandler(); spf.setDNSService(mockedDnsService); assertThat(spf.doMail(mockedSMTPSession, sender).getResult()).describedAs("declined").isEqualTo(HookReturnCode.declined()); assertThat(spf.doRcpt(mockedSMTPSession, sender, rcpt).getResult()).describedAs("fail").isEqualTo(HookReturnCode.deny()); }
@Test public void testSPFtempError() throws Exception { MailAddress sender = new MailAddress("test@spf5.james.apache.org"); MailAddress rcpt = new MailAddress("test@localhost"); setupMockedSMTPSession("192.168.100.1", "spf5.james.apache.org"); SPFHandler spf = new SPFHandler(); spf.setDNSService(mockedDnsService); assertThat(spf.doMail(mockedSMTPSession, sender).getResult()).describedAs("declined").isEqualTo(HookReturnCode.declined()); assertThat(spf.doRcpt(mockedSMTPSession, sender, rcpt).getResult()).describedAs("temperror denysoft").isEqualTo(HookReturnCode.denySoft()); }
@Test public void testSPFNoRecord() throws Exception { MailAddress sender = new MailAddress("test@spf6.james.apache.org"); MailAddress rcpt = new MailAddress("test@localhost"); setupMockedSMTPSession("192.168.100.1", "spf6.james.apache.org"); SPFHandler spf = new SPFHandler(); spf.setDNSService(mockedDnsService); assertThat(spf.doMail(mockedSMTPSession, sender).getResult()).describedAs("declined").isEqualTo(HookReturnCode.declined()); assertThat(spf.doRcpt(mockedSMTPSession, sender, rcpt).getResult()).describedAs("declined").isEqualTo(HookReturnCode.declined()); }