public MessageHandler getMessageHandler(ConnectionContext context) { return context.getSession().getMessageHandler(); } }
/** * {@inheritDoc} */ public void execute(String commandString, Session sess) throws IOException, DropConnectionException { if (!sess.getServer().getRequireAuth() || sess.isAuthenticated()) wrapped.execute(commandString, sess); else sess.sendResponse("530 5.7.0 Authentication required"); }
@Override public void execute(String commandString, Session sess) throws IOException { sess.sendResponse("221 Bye"); sess.quit(); } }
if (!sess.isMailTransactionInProgress()) sess.sendResponse("503 5.5.1 Error: need MAIL command"); return; else if (sess.getRecipientCount() == 0) sess.sendResponse("503 Error: need RCPT command"); return; sess.sendResponse("354 End data with <CR><LF>.<CR><LF>"); InputStream stream = sess.getRawInput(); stream = new BufferedInputStream(stream, BUFFER_SIZE); stream = new DotTerminatedInputStream(stream); stream = new DotUnstuffingInputStream(stream); if (!sess.getServer().getDisableReceivedHeaders()) stream = new ReceivedHeaderStream(stream, sess.getHelo(), sess .getRemoteAddress().getAddress(), sess.getServer() .getHostName(), sess.getServer().getSoftwareName(), sess.getSessionId(), sess.getSingleRecipient()); sess.getMessageHandler().data(stream); sess.sendResponse(ex.getErrorResponse()); return; sess.sendResponse("250 Ok");
if (!sess.getHasMailFrom()) sess.sendResponse("503 Error: need MAIL command"); return; else if (sess.getRecipientCount() == 0) sess.sendResponse("503 Error: need RCPT command"); return; sess.sendResponse("354 End data with <CR><LF>.<CR><LF>"); InputStream stream = sess.getRawInput(); stream = new BufferedInputStream(stream, BUFFER_SIZE); stream = new DotTerminatedInputStream(stream); stream = new DotUnstuffingInputStream(stream); if (!sess.getServer().getDisableReceivedHeaders()) stream = new ReceivedHeaderStream(stream, sess.getHelo(), sess .getRemoteAddress().getAddress(), sess.getServer() .getHostName(), sess.getServer().getSoftwareName(), sess.getSessionId(), sess.getSingleRecipient()); sess.getMessageHandler().data(stream); sess.sendResponse("250 Ok"); sess.sendResponse(ex.getErrorResponse());
throws IOException, DropConnectionException if (!sess.isMailTransactionInProgress()) sess.sendResponse("503 5.5.1 Error: need MAIL command"); return; else if (sess.getServer().getMaxRecipients() >= 0 && sess.getRecipientCount() >= sess.getServer().getMaxRecipients()) sess.sendResponse("452 Error: too many recipients"); return; if (!args.toUpperCase(Locale.ENGLISH).startsWith("TO:")) sess.sendResponse( "501 Syntax: RCPT TO: <address> Error in parameters: \"" + args + "\""); try sess.getMessageHandler().recipient(recipientAddress); sess.addRecipient(recipientAddress); sess.sendResponse("250 Ok"); sess.sendResponse(ex.getErrorResponse());
if (sess.isMailTransactionInProgress()) sess.sendResponse("503 5.5.1 Sender already specified."); return; sess.sendResponse("501 Syntax: MAIL FROM: <address>"); return; sess.sendResponse( "501 Syntax: MAIL FROM: <address> Error in parameters: \"" + this.getArgPredicate(commandString) + "\""); sess.sendResponse("553 <" + emailAddress + "> Invalid email address."); return; if (size > sess.getServer().getMaxMessageSize()) sess.sendResponse("552 5.3.4 Message size exceeds fixed limit"); return; sess.setDeclaredMessageSize(size); sess.startMailTransaction(); sess.getMessageHandler().from(emailAddress); sess.resetMailTransaction(); throw ex; // Propagate this sess.resetMailTransaction();
if (sess.isAuthenticated()) sess.sendResponse("503 Refusing any other AUTH command."); return; AuthenticationHandlerFactory authFactory = sess.getServer().getAuthenticationHandlerFactory(); sess.sendResponse("502 Authentication not supported"); return; sess.sendResponse("501 Syntax: " + VERB + " mechanism [initial-response]"); return; sess.sendResponse("504 The requested authentication mechanism is not supported"); return; CRLFTerminatedReader reader = sess.getReader(); sess.sendResponse(response); sess.sendResponse("501 Authentication canceled by client."); return; sess.sendResponse(response); sess.sendResponse("235 Authentication successful."); sess.setAuthenticationHandler(authHandler); sess.sendResponse(authFailed.getErrorResponse());
InetAddress remoteInetAddress = this.getRemoteAddress().getAddress(); runCommandLoop(); } catch (IOException e1) { if (!this.quitting) { this.sendResponse( "421 4.4.0 Problem attempting to execute commands. Please try again later."); } catch (IOException e) { log.error("Unexpected error in the SMTP handler thread", e); try { this.sendResponse("421 4.3.0 Mail system failure, closing transmission channel"); } catch (IOException e1) { throw new RuntimeException("Unexpected exception", e); } finally { this.closeConnection(); this.endMessageHandler(); serverThread.sessionEnded(this); Thread.currentThread().setName(originalName);
throws IOException, DropConnectionException if (!sess.getHasMailFrom()) sess.sendResponse("503 Error: need MAIL command"); return; else if (sess.getServer().getMaxRecipients() >= 0 && sess.getRecipientCount() >= sess.getServer().getMaxRecipients()) sess.sendResponse("452 Error: too many recipients"); return; if (!args.toUpperCase(Locale.ENGLISH).startsWith("TO:")) sess.sendResponse( "501 Syntax: RCPT TO: <address> Error in parameters: \"" + args + "\""); try sess.getMessageHandler().recipient(recipientAddress); sess.addRecipient(recipientAddress); sess.sendResponse("250 Ok"); sess.sendResponse(ex.getErrorResponse());
DropConnectionException if (sess.getHasMailFrom()) sess.sendResponse("503 Sender already specified."); sess.sendResponse("501 Syntax: MAIL FROM: <address>"); return; sess.sendResponse( "501 Syntax: MAIL FROM: <address> Error in parameters: \"" + this.getArgPredicate(commandString) + "\""); if (size > sess.getServer().getMaxMessageSize()) sess.sendResponse("552 5.3.4 Message size exceeds fixed limit"); return; sess.startMailTransaction(); sess.getMessageHandler().from(emailAddress); sess.setDeclaredMessageSize(size); sess.setHasMailFrom(true); sess.sendResponse("250 Ok"); sess.sendResponse(ex.getErrorResponse()); sess.sendResponse("553 <" + emailAddress + "> Invalid email address.");
if (!session.getHasSender()) else if (session.getRecipientCount() >= context.getServer().getMaxRecipients()) try session.getMessageHandler().recipient(recipientAddress); session.addRecipient(); context.sendResponse("250 Ok");
if (!session.getHasSender()) else if (session.getRecipientCount() == 0) session.setDataMode(true); session.getMessageHandler().data(stream); context.sendResponse("250 Ok"); session.reset(true); // reset session, but don't require new HELO/EHLO
if (!session.getHasSeenHelo()) else if (session.getHasSender()) session.getMessageHandler().from(emailAddress); session.setHasSender(true); context.sendResponse("250 Ok");
@Override public void execute(String commandString, ConnectionContext context) throws IOException { context.sendResponse("221 Bye"); context.getSession().quit(); } }
try session = new Session(server, this, socket);
if (!session.getHasSeenHelo()) session.setHasSeenHelo(true); String response = "250-" + context.getServer().getHostName() + "\r\n" + "250-8BITMIME"; .getMessageHandler());
throws IOException if (context.getSession().isAuthenticated()) context.getSession().setAuthenticated(true); context.getSession().setAuthenticated(false);
/** * Triggers the shutdown of the thread and the closing of the connection. */ public void quit() { this.quitting = true; this.closeConnection(); }