@Override public void init(Configuration config) throws ConfigurationException { String[] servers = config.getStringArray("uriRblServers.server"); Collection<String> serverCollection = new ArrayList<>(); for (String rblServerName : servers) { serverCollection.add(rblServerName); LOGGER.info("Adding uriRBL server: {}", rblServerName); } if (serverCollection != null && serverCollection.size() > 0) { setUriRblServer(serverCollection); } else { throw new ConfigurationException("Please provide at least one server"); } setGetDetail(config.getBoolean("getDetail", false)); }
message = mail.getMessage(); HashSet<String> domains = scanMailForDomains(message, session);
@Test public void testNotBlocked() throws IOException, MessagingException { ArrayList<String> servers = new ArrayList<>(); servers.add(URISERVER); SMTPSession session = setupMockedSMTPSession(setupMockedMail(setupMockedMimeMessage( "http://" + GOOD_DOMAIN + "/"))); URIRBLHandler handler = new URIRBLHandler(); handler.setDNSService(setupMockedDnsServer()); handler.setUriRblServer(servers); HookResult response = handler.onMessage(session, mockedMail); assertThat(HookReturnCode.declined()).describedAs("Email was not rejected").isEqualTo(response.getResult()); }
/** * @see org.apache.james.smtpserver.JamesMessageHook#onMessage(org.apache.james.protocols.smtp.SMTPSession, org.apache.mailet.Mail) */ public HookResult onMessage(SMTPSession session, Mail mail) { if (check(session, mail)) { String uRblServer = (String) session.getState().get(URBLSERVER); String target = (String) session.getState().get(LISTED_DOMAIN); String detail = null; // we should try to retrieve details if (getDetail) { Collection<String> txt = dnsService.findTXTRecords(target+ "." + uRblServer); // Check if we found a txt record if (!txt.isEmpty()) { // Set the detail detail = txt.iterator().next(); } } if (detail != null) { return new HookResult(HookReturnCode.DENY, DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_OTHER) + "Rejected: message contains domain " + target + " listed by " + uRblServer +" . Details: " + detail); } else { return new HookResult(HookReturnCode.DENY, DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_OTHER) + " Rejected: message contains domain " + target + " listed by " + uRblServer); } } else { return new HookResult(HookReturnCode.DECLINED); } }
@Test public void testBlockedMultiPart() throws IOException, MessagingException { ArrayList<String> servers = new ArrayList<>(); servers.add(URISERVER); SMTPSession session = setupMockedSMTPSession(setupMockedMail(setupMockedMimeMessageMP( "http://" + BAD_DOMAIN1 + "/" + " " + "http://" + GOOD_DOMAIN + "/"))); URIRBLHandler handler = new URIRBLHandler(); handler.setDNSService(setupMockedDnsServer()); handler.setUriRblServer(servers); HookResult response = handler.onMessage(session, mockedMail); assertThat(HookReturnCode.deny()).describedAs("Email was rejected").isEqualTo(response.getResult()); }
@Override public HookResult onMessage(SMTPSession session, Mail mail) { if (check(session, mail)) { String uRblServer = (String) session.getAttachment(URBLSERVER, State.Transaction); String target = (String) session.getAttachment(LISTED_DOMAIN, State.Transaction); String detail = null; // we should try to retrieve details if (getDetail) { Collection<String> txt = dnsService.findTXTRecords(target + "." + uRblServer); // Check if we found a txt record if (!txt.isEmpty()) { // Set the detail detail = txt.iterator().next(); } } if (detail != null) { return HookResult.builder() .hookReturnCode(HookReturnCode.deny()) .smtpDescription(DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_OTHER) + "Rejected: message contains domain " + target + " listed by " + uRblServer + " . Details: " + detail) .build(); } else { return HookResult.builder() .hookReturnCode(HookReturnCode.deny()) .smtpDescription(DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_OTHER) + " Rejected: message contains domain " + target + " listed by " + uRblServer) .build(); } } else { return HookResult.DECLINED; } }
@Test public void testBlocked() throws IOException, MessagingException { ArrayList<String> servers = new ArrayList<>(); servers.add(URISERVER); SMTPSession session = setupMockedSMTPSession(setupMockedMail(setupMockedMimeMessage( "http://" + BAD_DOMAIN1 + "/"))); URIRBLHandler handler = new URIRBLHandler(); handler.setDNSService(setupMockedDnsServer()); handler.setUriRblServer(servers); HookResult response = handler.onMessage(session, mockedMail); assertThat(HookReturnCode.deny()).describedAs("Email was rejected").isEqualTo(response.getResult()); }
public void configure(HierarchicalConfiguration config) throws ConfigurationException { String[] servers = config.getStringArray("uriRblServers.server"); Collection<String> serverCollection = new ArrayList<String>(); for ( int i = 0 ; i < servers.length ; i++ ) { String rblServerName = servers[i]; serverCollection.add(rblServerName); if (serviceLog.isInfoEnabled()) { serviceLog.info("Adding uriRBL server: " + rblServerName); } } if (serverCollection != null && serverCollection.size() > 0) { setUriRblServer(serverCollection); } else { throw new ConfigurationException("Please provide at least one server"); } setGetDetail(config.getBoolean("getDetail",false)); }
message = mail.getMessage(); HashSet<String> domains = scanMailForDomains(message, session);
LOGGER.debug("recursing index: {}", index); MimeBodyPart mimeBodyPart = (MimeBodyPart) multipart.getBodyPart(index); HashSet<String> newDomains = scanMailForDomains(mimeBodyPart, session);
session.getLogger().debug("recursing index: " + index); MimeBodyPart mimeBodyPart = (MimeBodyPart) multipart.getBodyPart(index); HashSet<String> newDomains = scanMailForDomains(mimeBodyPart, session);