/** * Log message contents * * @param env */ private void logMessage(SMTPSession session, MailEnvelopeImpl env) { Charset charset = Charset.forName("US-ASCII"); try { InputStream in = env.getMessageInputStream(); byte[] buf = new byte[16384]; CharsetDecoder decoder = charset.newDecoder(); int len = 0; while ((len = in.read(buf)) >= 0) { session.getLogger().trace(decoder.decode(ByteBuffer.wrap(buf, 0, len)).toString()); } } catch (IOException ioex) { session.getLogger().debug("Mail data logging failed", ioex); } }
public HookResult onHookResult(SMTPSession session, HookResult result, Object hook) { String hookName = hook.getClass().getName(); try { HookStats stats; synchronized (hookStats) { stats = hookStats.get(hookName); if (stats == null) { stats = new HookStats(hookName); hookStats.put(hookName, stats); } } stats.increment(result.getResult()); } catch (Exception e) { session.getLogger().error( "Unable to register HookStats for hook " + hookName, e); } return result; }
session.getLogger().debug("sending mail"); recipientString = theRecipients.toString(); if (session.getLogger().isInfoEnabled()) { StringBuilder infoBuffer = new StringBuilder(256) .append(" for ") .append(recipientString); session.getLogger().info(infoBuffer.toString()); session.getLogger().error("Unknown error occurred while processing DATA.", me); return new HookResult(HookReturnCode.DENYSOFT,DSNStatus.getStatus(DSNStatus.TRANSIENT,DSNStatus.UNDEFINED_STATUS)+" Error processing message.");
session.getLogger().debug("mime type is: \"" + part.getContentType() + "\""); session.getLogger().debug("scanning: \"" + part.getContent().toString() + "\""); HashSet<String> newDom = URIScanner.scanContentForDomains(domains, part.getContent().toString()); MimeMultipart multipart = (MimeMultipart) part.getContent(); int count = multipart.getCount(); session.getLogger().debug("multipart count is: " + count); session.getLogger().debug("recursing index: " + index); MimeBodyPart mimeBodyPart = (MimeBodyPart) multipart.getBodyPart(index); HashSet<String> newDomains = scanMailForDomains(mimeBodyPart, session);
for (int i = 0; i < mHandlers.size(); i++) { MessageHook rawHandler = mHandlers.get(i); session.getLogger().debug( "executing james message handler " + rawHandler); HookResult hRes = rawHandler.onMessage(session, for (int i2 = 0; i2 < rHooks.size(); i2++) { Object rHook = rHooks.get(i2); session.getLogger() .debug("executing hook " + rHook); hRes = ((HookResultHook) rHook).onHookResult( for (int i = 0; i < count; i++) { Object rawHandler = messageHandlers.get(i); session.getLogger().debug( "executing james message handler " + rawHandler); HookResult hRes = ((JamesMessageHook) rawHandler) for (int i2 = 0; i2 < rHooks.size(); i2++) { Object rHook = rHooks.get(i2); session.getLogger() .debug("executing hook " + rHook); hRes = ((HookResultHook) rHook).onHookResult(
/** * @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); }
@Override protected boolean isValidRecipient(SMTPSession session, MailAddress recipient) { AccountStatus status = validator.getAccountStatus(recipient.toString()); session.getLogger().debug("Validated account (" + recipient + ") status is " + status); return status.equals(AccountStatus.ACTIVE) ? true : false; }
/** * 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); }
/** * 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>"); }
session.getLogger().info("Unexpected error handling DATA stream",e); session.writeResponse(new SMTPResponse(SMTPRetCode.LOCAL_ERROR, "Unexpected error handling DATA stream.")); } finally { DSNStatus.UNDEFINED_STATUS) + " Error processing message: " + e.getMessage()); session.getLogger().error( "Unknown error occurred while processing DATA.", e); session.writeResponse(response);
session.getLogger().info("Unexpected error handling DATA stream",e); session.writeResponse(new SMTPResponse(SMTPRetCode.LOCAL_ERROR, "Unexpected error handling DATA stream.")); } finally { DSNStatus.UNDEFINED_STATUS) + " Error processing message: " + e.getMessage()); session.getLogger().error( "Unknown error occurred while processing DATA.", e); session.writeResponse(response);
if (session.getLogger().isTraceEnabled()) { logMessage(session, env);