Index: java/org/apache/james/smtpserver/SMTPHandler.java =================================================================== --- java/org/apache/james/smtpserver/SMTPHandler.java (revision 264759) +++ java/org/apache/james/smtpserver/SMTPHandler.java (working copy) @@ -210,7 +210,22 @@ */ private StringBuffer responseBuffer = new StringBuffer(256); + /** + * The per-handler map to store session scope variables + * the various handlers use this for storing state information + */ + private HashMap sessionState = new HashMap(); + + /** + * The per-handler map to store message scope variables + * the various handlers use this for storing state information + */ + private HashMap messageState = new HashMap(); + + + + /** * Set the configuration data for the handler * * @param theData the per-service configuration data for this handler @@ -425,6 +440,9 @@ mail.dispose(); mail = null; resetState(); + + //reset the message scope state + messageState.clear(); } } @@ -470,6 +488,8 @@ + e.getMessage(), e ); } } finally { + //Clear all the session state variables + sessionState.clear(); resetHandler(); } } @@ -649,9 +669,9 @@ * @see org.apache.james.smtpserver.SMTPSession#writeResponse(String) */ public void writeResponse(String respString) { - SMTPHandler.this.writeLoggedFlushedResponse(respString); + writeLoggedFlushedResponse(respString); //TODO Explain this well - if(SMTPHandler.this.mode == COMMAND_MODE) { + if(mode == COMMAND_MODE) { mode = RESPONSE_MODE; } } @@ -728,7 +748,7 @@ * @see org.apache.james.smtpserver.SMTPSession#getState() */ public HashMap getState() { - return SMTPHandler.this.state; + return state; } /** @@ -763,7 +783,7 @@ * @see org.apache.james.smtpserver.SMTPSession#isAuthRequired() */ public boolean isAuthRequired() { - return SMTPHandler.this.authRequired; + return authRequired; } /** @@ -840,4 +860,21 @@ mode = MESSAGE_ABORT_MODE; } + + + /** + * @see org.apache.james.smtpserver.SMTPSession#getMessageState() + */ + public HashMap getMessageState() { + return messageState; + } + + + /** + * @see org.apache.james.smtpserver.SMTPSession#getSessionState() + */ + public HashMap getSessionState() { + return sessionState; + } + } Index: java/org/apache/james/smtpserver/UnknownCmdHandler.java =================================================================== --- java/org/apache/james/smtpserver/UnknownCmdHandler.java (revision 264759) +++ java/org/apache/james/smtpserver/UnknownCmdHandler.java (working copy) @@ -30,6 +30,12 @@ public static final String UNKNOWN_COMMAND = "UNKNOWN"; /** + * Message failed flag to indicate if there is any failure + */ + private final static String MESG_FAILED = "MESG_FAILED"; + + + /** * Handler method called upon receipt of an unrecognized command. * Returns an error response and logs the command. * @@ -37,10 +43,15 @@ **/ public void onCommand(SMTPSession session) { - session.getResponseBuffer().append("500 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.UNDEFINED_STATUS)+" ") - .append(session.getConfigurationData().getHelloName()) - .append(" Syntax error, command unrecognized: ") - .append(session.getCommandName()); + //If there was message failure, don't consider it as an unknown command + if (state.get(MESG_FAILED) != null) { + return; + } + + session.getResponseBuffer().append("500 "+DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_INVALID_CMD)) + .append(" Command ") + .append(session.getCommandName()) + .append(" unrecognized."); String responseString = session.clearResponseBuffer(); session.writeResponse(responseString); Index: java/org/apache/james/smtpserver/SMTPSession.java =================================================================== --- java/org/apache/james/smtpserver/SMTPSession.java (revision 264759) +++ java/org/apache/james/smtpserver/SMTPSession.java (working copy) @@ -207,5 +207,21 @@ */ String getSessionID(); + + /** + * Used for storing session scope variables + * + * @return map message scope param-values + */ + HashMap getMessageState(); + + + /** + * Used for storing Session scope variables + * + * @return map of session scope param-values + */ + HashMap getSessionState(); + }