/** * @see org.apache.james.smtpserver.JamesMessageHook#onMessage(org.apache.james.protocols.smtp.SMTPSession, * org.apache.mailet.Mail) */ public HookResult onMessage(SMTPSession session, Mail mail) { // Store the spf header as attribute for later using mail.setAttribute(SPF_HEADER_MAIL_ATTRIBUTE_NAME, (String) session .getState().get(SPF_HEADER)); return null; }
/** * Cleanup temporary files * * @param channel */ protected void cleanup(Channel channel) { // Make sure we dispose everything on exit on session close SMTPSession smtpSession = (SMTPSession) attributes.get(channel); if (smtpSession != null) { LifecycleUtil.dispose(smtpSession.getState().get(SMTPConstants.MAIL)); LifecycleUtil.dispose(smtpSession.getState().get(SMTPConstants.DATA_MIMEMESSAGE_STREAMSOURCE)); } super.cleanup(channel); }
/** * @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); }
String heloEhlo = (String) session.getState().get( SMTPSession.CURRENT_HELO_NAME); session.getState().put(SPF_HEADER, result.getHeaderText()); explanation = "Block caused by an invalid SPF record"; session.getState().put(SPF_DETAIL, explanation); session.getState().put(SPF_BLOCKLISTED, "true"); session.getState().put(SPF_TEMPBLOCKLISTED, "true");
/** * @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); } }
StringBuffer buffer = new StringBuffer(256).append( "Rejected message from ").append( session.getState().get(SMTPSession.SENDER) .toString()).append(" from host ") .append(session.getRemoteHost()).append(" (")
public void onLine(SMTPSession session, byte[] line, LineHandler<SMTPSession> next) { MimeMessageInputStreamSource mmiss = (MimeMessageInputStreamSource) session.getState().get(SMTPConstants.DATA_MIMEMESSAGE_STREAMSOURCE); out.close(); List recipientCollection = (List) session.getState().get(SMTPSession.RCPT_LIST); MailImpl mail = new MailImpl(mailServer.getId(), (MailAddress) session.getState().get(SMTPSession.SENDER), recipientCollection); session.getState().put(SMTPConstants.MAIL, mail);
@SuppressWarnings("unchecked") public void onLine(SMTPSession session, byte[] line, LineHandler<SMTPSession> next) { MimeMessageInputStreamSource mmiss = (MimeMessageInputStreamSource) session.getState().get(SMTPConstants.DATA_MIMEMESSAGE_STREAMSOURCE); out.close(); List recipientCollection = (List) session.getState().get(SMTPSession.RCPT_LIST); MailImpl mail = new MailImpl(mailServer.getId(), (MailAddress) session.getState().get(SMTPSession.SENDER), recipientCollection); session.getState().put(SMTPConstants.MAIL, mail);
/** * Handler method called upon receipt of a DATA command. * Reads in message data, creates header, and delivers to * mail server service for delivery. * * @param session SMTP session object * @param argument the argument passed in with the command by the SMTP client */ protected SMTPResponse doDATA(SMTPSession session, String argument) { try { MimeMessageInputStreamSource mmiss = new MimeMessageInputStreamSource(mailServer.getId()); session.getState().put(SMTPConstants.DATA_MIMEMESSAGE_STREAMSOURCE, mmiss); } catch (MessagingException e) { session.getLogger().warn("Error creating mimemessagesource for incoming data",e); return new SMTPResponse(SMTPRetCode.LOCAL_ERROR, "Unexpected error preparing to receive DATA."); } // out = new PipedOutputStream(messageIn); session.pushLineHandler(getLineHandler()); return new SMTPResponse(SMTPRetCode.DATA_READY, "Ok Send data ending with <CRLF>.<CRLF>"); }