protected MailEnvelope createEnvelope(SMTPSession session, MaybeSender sender, List<MailAddress> recipients) { MailEnvelopeImpl env = new MailEnvelopeImpl(); env.setRecipients(recipients); env.setSender(sender); return env; }
@Override protected Response processExtensions(SMTPSession session, MailEnvelopeImpl mail) { LMTPMultiResponse mResponse = null; Iterator<MailAddress> recipients = mail.getRecipients().iterator(); while (recipients.hasNext()) { MailAddress recipient = recipients.next(); Response response = null; for (DeliverToRecipientHook handler: handlers) { response = AbstractHookableCmdHandler.calcDefaultSMTPResponse(handler.deliver(session, recipient, mail)); if (response != null) { break; } } if (response == null) { // Add some default response for not handled responses response = new SMTPResponse(SMTPRetCode.LOCAL_ERROR, DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.UNDEFINED_STATUS) + "Temporary error deliver message to " + recipient); } if (mResponse == null) { mResponse = new LMTPMultiResponse(response); } else { mResponse.addResponse(response); } } return mResponse; }
/** * 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); } }
@Override public Response onLine(SMTPSession session, ByteBuffer line, LineHandler<SMTPSession> next) { MailEnvelopeImpl env = (MailEnvelopeImpl) session.getAttachment(DataCmdHandler.MAILENV, ProtocolSession.State.Transaction); OutputStream out = env.getMessageOutputStream(); try {
for (MailAddress address : env.getRecipients()) { replies.put(address, DeliveryReturnCode.TEMPORARY_FAILURE);