@Override @SuppressWarnings("unchecked") public HookResult doRcpt(SMTPSession session, MaybeSender sender, MailAddress rcpt) { Collection<MailAddress> rcptList = (Collection<MailAddress>) session.getAttachment(SMTPSession.RCPT_LIST, State.Transaction); // Check if the recipient is already in the rcpt list if (rcptList != null && rcptList.contains(rcpt)) { StringBuilder responseBuffer = new StringBuilder(); responseBuffer.append(DSNStatus.getStatus(DSNStatus.SUCCESS, DSNStatus.ADDRESS_VALID)) .append(" Recipient <") .append(rcpt.toString()) .append("> OK"); LOGGER.debug("Duplicate recipient not add to recipient list: {}", rcpt); return HookResult.builder() .hookReturnCode(HookReturnCode.ok()) .smtpReturnCode(SMTPRetCode.MAIL_OK) .smtpDescription(responseBuffer.toString()) .build(); } return HookResult.DECLINED; } }
.hookReturnCode(HookReturnCode.deny()) .smtpDescription(DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_OTHER) + " This message reach the spam hits treshold. Please contact the Postmaster if the email is not SPAM. Message rejected")
.hookReturnCode(HookReturnCode.deny()) .smtpReturnCode(SMTPRetCode.AUTH_REQUIRED) .smtpDescription(DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_AUTH)
mailboxManager.endProcessingRequest(mailboxSession); return HookResult.builder() .hookReturnCode(HookReturnCode.ok()) .smtpReturnCode(SMTPRetCode.MAIL_OK) .smtpDescription(DSNStatus.getStatus(DSNStatus.SUCCESS, DSNStatus.CONTENT_OTHER) + " Message received") 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 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; } }
@Override public HookResult doRcpt(SMTPSession session, MaybeSender sender, MailAddress rcpt) { checkDNSRBL(session, session.getRemoteAddress().getAddress().getHostAddress()); if (!session.isRelayingAllowed()) { String blocklisted = (String) session.getAttachment(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME, State.Connection); if (blocklisted != null) { // was found in the RBL if (blocklistedDetail == null) { return HookResult.builder() .hookReturnCode(HookReturnCode.deny()) .smtpDescription(DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_AUTH) + " Rejected: unauthenticated e-mail from " + session.getRemoteAddress().getAddress() + " is restricted. Contact the postmaster for details.") .build(); } else { return HookResult.builder() .hookReturnCode(HookReturnCode.deny()) .smtpDescription(DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH) + " " + blocklistedDetail) .build(); } } } return HookResult.DECLINED; }
/** * 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(); }
@Override public HookResult doUnknown(SMTPSession session, String command) { Integer count = (Integer) session.getAttachment(UNKOWN_COMMAND_COUNT, State.Transaction); if (count == null) { count = 1; } else { count++; } session.setAttachment(UNKOWN_COMMAND_COUNT, count, State.Transaction); if (count > maxUnknown) { return HookResult.builder() .hookReturnCode(HookReturnCode.disconnected(HookReturnCode.Action.DENY)) .smtpReturnCode("521") .smtpDescription("Closing connection as too many unknown commands received") .build(); } else { return HookResult.DECLINED; } }
@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; }
@Override public HookResult doAuth(SMTPSession session, String username, String password) { try { if (users.test(username, password)) { session.setUser(username); session.setRelayingAllowed(true); return HookResult.builder() .hookReturnCode(HookReturnCode.ok()) .smtpDescription("Authentication Successful") .build(); } } catch (UsersRepositoryException e) { LOGGER.info("Unable to access UsersRepository", e); } return HookResult.DECLINED; }
@Override public HookResult doRcpt(SMTPSession session, MaybeSender sender, MailAddress rcpt) { if (check(session,rcpt)) { return HookResult.builder() .hookReturnCode(HookReturnCode.deny()) .smtpReturnCode(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS) .smtpDescription(DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_INVALID_ARG) + " Provided EHLO/HELO " + session.getAttachment(SMTPSession.CURRENT_HELO_NAME, State.Connection) + " can not resolved.") .build(); } else { return HookResult.DECLINED; } }
public HookResult reject(MailAddress rcpt) { LOGGER.info("Rejected message. Unknown user: {}", rcpt); return HookResult.builder() .hookReturnCode(HookReturnCode.deny()) .smtpReturnCode(SMTPRetCode.MAILBOX_PERM_UNAVAILABLE) .smtpDescription(DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_MAILBOX) + " Unknown user: " + rcpt.asString()) .build(); }
@Override public HookResult doMail(SMTPSession session, MaybeSender sender) { if (!sender.isNullSender() && !hasMXRecord(session,sender.get().getDomain().name())) { return HookResult.builder() .hookReturnCode(HookReturnCode.deny()) .smtpReturnCode(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS) .smtpDescription(DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX_SENDER) + " sender " + sender + " contains a domain with no valid MX records") .build(); } else { return HookResult.DECLINED; } }