@Override protected boolean isBadHelo(SMTPSession session, String argument) { try { String reverse = resolve(session.getRemoteAddress().getAddress().getHostAddress()); if (!argument.equals(reverse)) { return true; } } catch (UnknownHostException e) { // ignore } return false; }
@Override public HookResult doRcpt(SMTPSession session, MailAddress sender, MailAddress rcpt) { if ((wNetworks == null) || (!wNetworks.matchInetNetwork(session.getRemoteAddress().getAddress().getHostAddress()))) { return super.doRcpt(session, sender, rcpt); } else { LOGGER.info("IpAddress {} is whitelisted. Skip greylisting.", session.getRemoteAddress().getAddress().getHostAddress()); } return HookResult.DECLINED; }
@Override public HookResult doRcpt(SMTPSession session, MaybeSender sender, MailAddress rcpt) { if (!session.isRelayingAllowed()) { return doGreyListCheck(session, sender,rcpt); } else { LOGGER.info("IpAddress {} is allowed to send. Skip greylisting.", session.getRemoteAddress().getAddress().getHostAddress()); } return HookResult.DECLINED; } }
@Override protected Response doCoreCmd(SMTPSession session, String command, String parameters) { session.setAttachment(SMTPSession.CURRENT_HELO_MODE, COMMAND_NAME, ProtocolSession.State.Connection); StringBuilder response = new StringBuilder(); response.append(session.getConfiguration().getHelloName()).append( " Hello ").append(parameters).append(" [").append( session.getRemoteAddress().getAddress().getHostAddress()).append("])"); return new SMTPResponse(SMTPRetCode.MAIL_OK, response); }
@Override public HookResult doRcpt(SMTPSession session, MaybeSender sender, MailAddress rcpt) { String address = session.getRemoteAddress().getAddress().getHostAddress(); if (isBlocked(address, session)) { return HookResult.DENY; } else { if (spamTrapRecips.contains(rcpt.toString().toLowerCase(Locale.US))) { addIp(address, session); return HookResult.DENY; } } return HookResult.DECLINED; }
@Override public HookResult onMessage(SMTPSession session, MailEnvelope mail) { Boolean failed = (Boolean) session.getAttachment(MESG_FAILED, State.Transaction); if (failed != null && failed.booleanValue()) { LOGGER.error("Rejected message from {} from {} exceeding system maximum message size of {}", session.getAttachment(SMTPSession.SENDER, State.Transaction), session.getRemoteAddress().getAddress().getHostAddress(), session.getConfiguration().getMaxMessageSize()); return QUOTA_EXCEEDED; } else { return HookResult.DECLINED; } }
@Override public Response onConnect(SMTPSession session) { // some kind of random cleanup process if (Math.random() > 0.99) { POP3BeforeSMTPHelper.removeExpiredIP(expireTime); } // Check if the ip is allowed to relay if (!session.isRelayingAllowed() && POP3BeforeSMTPHelper.isAuthorized(session.getRemoteAddress().getAddress().getHostAddress())) { session.setRelayingAllowed(true); } return null; }
/** * Handler method called upon receipt of a EHLO command. Responds with a * greeting and informs the client whether client authentication is * required. * * @param session * SMTP session object * @param argument * the argument passed in with the command by the SMTP client */ private Response doEHLO(SMTPSession session, String argument) { SMTPResponse resp = new SMTPResponse(SMTPRetCode.MAIL_OK, new StringBuilder(session.getConfiguration().getHelloName()).append(" Hello ").append(argument) .append(" [") .append(session.getRemoteAddress().getAddress().getHostAddress()).append("])")); session.setAttachment(SMTPSession.CURRENT_HELO_MODE, COMMAND_NAME, State.Connection); processExtensions(session, resp); return resp; }
session.getRemoteAddress().getAddress().getHostAddress(), size, maxMessageSize);
@Override public HookResult onMessage(SMTPSession session, Mail mail) { if (mail instanceof MailImpl) { final MailImpl mailImpl = (MailImpl) mail; mailImpl.setRemoteHost(session.getRemoteAddress().getHostName()); mailImpl.setRemoteAddr(session.getRemoteAddress().getAddress().getHostAddress()); if (session.getUser() != null) { mail.setAttribute(Mail.SMTP_AUTH_USER_ATTRIBUTE_NAME, session.getUser()); } if (session.isRelayingAllowed()) { mail.setAttribute(SMTP_AUTH_NETWORK_NAME, "true"); } } return HookResult.DECLINED; }
headerLineBuffer.append("from ").append(session.getRemoteAddress().getHostName()); headerLineBuffer.append(" ([").append(session.getRemoteAddress().getAddress().getHostAddress()).append("])"); Header header = new Header("Received", headerLineBuffer.toString());
LOGGER.info("Ipaddress {} is allowed to relay. Don't check it", session.getRemoteAddress().getAddress()); return; return; } else { LOGGER.debug("IpAddress {} not listed on {}", session.getRemoteAddress().getAddress(), rbl);
LOGGER.error("AUTH method {} failed from {}@{}", authType, user, session.getRemoteAddress().getAddress().getHostAddress()); return res;
String ipAddress = session.getRemoteAddress().getAddress().getHostAddress();
} else { String ip = session.getRemoteAddress().getAddress().getHostAddress();
String buffer = "Rejected message from " + session.getAttachment(SMTPSession.SENDER, State.Transaction).toString() + " from host " + session.getRemoteAddress().getHostName() + " (" + session.getRemoteAddress().getAddress().getHostAddress() + ") This message reach the spam hits treshold. Required rejection hits: " + spamdRejectionHits + " hits: " + hits; LOGGER.info(buffer);
@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; }
.smtpReturnCode(SMTPRetCode.AUTH_REQUIRED) .smtpDescription(DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_AUTH) + " Invalid MX " + session.getRemoteAddress().getAddress().toString() + " for domain " + domain.asString() + ". Reject email") .build();
/** * 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(); }