public HookResult build() { Preconditions.checkNotNull(result); return new HookResult(result, smtpReturnCode.orElse(null), smtpDescription.orElse(null)); } }
/** * @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); }
/** * @see org.apache.james.protocols.smtp.hook.AuthHook#doAuth(org.apache.james.protocols.smtp.SMTPSession, java.lang.String, java.lang.String) */ public HookResult doAuth(SMTPSession session, String username, String password) { if (users.test(username, password)) { session.setUser(username); session.setRelayingAllowed(true); return new HookResult(HookReturnCode.OK, "Authentication Successful"); } return new HookResult(HookReturnCode.DECLINED); } }
/** * @see org.apache.james.protocols.smtp.hook.RcptHook#doRcpt(org.apache.james.protocols.smtp.SMTPSession, org.apache.mailet.MailAddress, org.apache.mailet.MailAddress) */ public HookResult doRcpt(SMTPSession session, MailAddress sender, MailAddress rcpt) { if (!session.isRelayingAllowed()) { // Check if session is blocklisted if (session.getState().get(SPF_BLOCKLISTED)!= null) { return new HookResult(HookReturnCode.DENY,DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_AUTH) + " " + session.getState().get(SPF_TEMPBLOCKLISTED)); } else if (session.getState().get(SPF_TEMPBLOCKLISTED) != null) { return new HookResult(HookReturnCode.DENYSOFT, SMTPRetCode.LOCAL_ERROR,DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.NETWORK_DIR_SERVER) + " " + "Temporarily rejected: Problem on SPF lookup"); } } return new HookResult(HookReturnCode.DECLINED); }
@Override public HookResult doRcpt(SMTPSession session, MailAddress sender, MailAddress rcpt) { SMTPNettySession nSession =(SMTPNettySession) session; if (nSession.verifyIdentity()) { return super.doRcpt(session, sender, rcpt); } else { return new HookResult(HookReturnCode.DECLINED); } }
@SuppressWarnings("unchecked") public HookResult onMessage(SMTPSession session, Mail mail) { Iterator<MailAddress> rcpts = mail.getRecipients().iterator(); Integer p = null; while(rcpts.hasNext()) { String domain = rcpts.next().getDomain(); Integer prio = null; if (domain != null) { prio = prioMap.get(domain); if (prio != null) { if (p == null || prio > p) { p = prio; } // already the highest priority if (p == MailPrioritySupport.HIGH_PRIORITY) break; } } } // set the priority if one was found if (p != null) mail.setAttribute(MailPrioritySupport.MAIL_PRIORITY, p); return new HookResult(HookReturnCode.DECLINED); }
mx = dnsService.findMXRecords(domain).iterator(); } catch (TemporaryResolutionException e1) { return new HookResult(HookReturnCode.DENYSOFT); return new HookResult(HookReturnCode.DENY,SMTPRetCode.AUTH_REQUIRED, DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_AUTH) + " Invalid MX " + session.getRemoteIPAddress() + " for domain " + domain + ". Reject email"); return new HookResult(HookReturnCode.DECLINED);
/** * @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); } }
return new HookResult(HookReturnCode.DENYSOFT,DSNStatus.getStatus(DSNStatus.TRANSIENT,DSNStatus.UNDEFINED_STATUS)+" Error processing message."); return new HookResult(HookReturnCode.OK, DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.CONTENT_OTHER)+" Message received");
return new HookResult(HookReturnCode.DENY,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"); session.getLogger().error(e.getMessage()); return new HookResult(HookReturnCode.DECLINED);
/** * @see org.apache.james.protocols.smtp.core.fastfail.AbstractGreylistHandler#doRcpt(org.apache.james.protocols.smtp.SMTPSession, org.apache.mailet.MailAddress, org.apache.mailet.MailAddress) */ public HookResult doRcpt(SMTPSession session, MailAddress sender, MailAddress rcpt) { if ((wNetworks == null) || (!wNetworks.matchInetNetwork(session.getRemoteIPAddress()))) { return super.doRcpt(session, sender, rcpt); } else { session.getLogger().info("IpAddress " + session.getRemoteIPAddress() + " is whitelisted. Skip greylisting."); } return new HookResult(HookReturnCode.DECLINED); }
/** * Adds header to the message * * @see org.apache.james.smtpserver.JamesMessageHook#onMessage(org.apache.james.protocols.smtp.SMTPSession, org.apache.mailet.Mail) */ public HookResult onMessage(SMTPSession session, Mail mail) { try { MimeMessage message = mail.getMessage (); //Set the header name and value (supplied at init time). if(headerName != null) { message.setHeader(headerName, headerValue); message.saveChanges(); } } catch (javax.mail.MessagingException me) { session.getLogger().error(me.getMessage()); } return new HookResult(HookReturnCode.DECLINED); }
public HookResult onMessage(SMTPSession session, Mail mail) { if (mail instanceof MailImpl) { final MailImpl mailImpl = (MailImpl) mail; mailImpl.setRemoteHost(session.getRemoteHost()); mailImpl.setRemoteAddr(session.getRemoteIPAddress()); if (session.getUser() != null) { mail.setAttribute(SMTP_AUTH_USER_ATTRIBUTE_NAME, session.getUser()); } if (session.isRelayingAllowed()) { mail.setAttribute(SMTP_AUTH_NETWORK_NAME,"true"); } } return new HookResult(HookReturnCode.DECLINED); }