/** * Adds header to the message * */ @Override public HookResult onMessage(SMTPSession session, Mail mail) { LOGGER.debug("sending mail"); try { queue.enQueue(mail); LOGGER.info("Successfully spooled mail {} from {} on {} for {}", mail.getName(), mail.getMaybeSender(), session.getRemoteAddress().getAddress(), mail.getRecipients()); } catch (MessagingException me) { LOGGER.error("Unknown error occurred while processing DATA.", me); return HookResult.builder() .hookReturnCode(HookReturnCode.denySoft()) .smtpDescription(DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.UNDEFINED_STATUS) + " Error processing message.") .build(); } return HookResult.builder() .hookReturnCode(HookReturnCode.ok()) .smtpDescription(DSNStatus.getStatus(DSNStatus.SUCCESS, DSNStatus.CONTENT_OTHER) + " Message received") .build(); }
@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()); }
LOGGER.error("Unexpected error handling DATA stream", e); return HookResult.builder() .hookReturnCode(HookReturnCode.denySoft()) .smtpDescription(" Temporary error deliver message to " + recipient) .build();
@Override public HookResult doRcpt(SMTPSession session, MailAddress sender, MailAddress rcpt) { if (!session.isRelayingAllowed()) { // Check if session is blocklisted if (session.getAttachment(SPF_BLOCKLISTED, State.Transaction) != null) { return HookResult.builder() .hookReturnCode(HookReturnCode.deny()) .smtpDescription(DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_AUTH) + " " + session.getAttachment(SPF_TEMPBLOCKLISTED, State.Transaction)) .build(); } else if (session.getAttachment(SPF_TEMPBLOCKLISTED, State.Transaction) != null) { return HookResult.builder() .hookReturnCode(HookReturnCode.denySoft()) .smtpReturnCode(SMTPRetCode.LOCAL_ERROR) .smtpDescription(DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.NETWORK_DIR_SERVER) + " Temporarily rejected: Problem on SPF lookup") .build(); } } return HookResult.DECLINED; }