Author: bago
Date: Tue Aug 30 08:30:13 2005
New Revision: 264796

URL: http://svn.apache.org/viewcvs?rev=264796&view=rev
Log:
Applied patch from Anagha Mudigonda (update to JAMES-407)
Improved UnknownCommandHandler, added messageState to the SMTPSession.

Modified:
    james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandler.java
    james/server/trunk/src/java/org/apache/james/smtpserver/SMTPSession.java
    
james/server/trunk/src/java/org/apache/james/smtpserver/UnknownCmdHandler.java

Modified: 
james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandler.java
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandler.java?rev=264796&r1=264795&r2=264796&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandler.java 
(original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandler.java 
Tue Aug 30 08:30:13 2005
@@ -210,6 +210,21 @@
      */
     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
      *
@@ -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;
     }
 
     /**
@@ -838,6 +858,23 @@
      */
     public void abortMessage() {
         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;
     }
 
 }

Modified: 
james/server/trunk/src/java/org/apache/james/smtpserver/SMTPSession.java
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/smtpserver/SMTPSession.java?rev=264796&r1=264795&r2=264796&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/SMTPSession.java 
(original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/SMTPSession.java 
Tue Aug 30 08:30:13 2005
@@ -1,211 +1,227 @@
-/***********************************************************************
- * Copyright (c) 1999-2005 The Apache Software Foundation.             *
- * All rights reserved.                                                *
- * ------------------------------------------------------------------- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you *
- * may not use this file except in compliance with the License. You    *
- * may obtain a copy of the License at:                                *
- *                                                                     *
- *     http://www.apache.org/licenses/LICENSE-2.0                      *
- *                                                                     *
- * Unless required by applicable law or agreed to in writing, software *
- * distributed under the License is distributed on an "AS IS" BASIS,   *
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
- * implied.  See the License for the specific language governing       *
- * permissions and limitations under the License.                      *
- ***********************************************************************/
-
-package org.apache.james.smtpserver;
-
-
-import org.apache.mailet.Mail;
-import org.apache.james.core.MailImpl;
-import java.util.HashMap;
-import java.io.IOException;
-import java.io.InputStream;
-import org.apache.james.util.watchdog.Watchdog;
-
-/**
- * All the handlers access this interface to communicate with
- * SMTPHandler object
- */
-
-public interface SMTPSession {
-
-    /**
-     * Writes response string to the client
-     *
-     * @param respString String that needs to send to the client
-     */
-    void writeResponse(String respString);
-
-    /**
-     * Reads a line of characters off the command line.
-     *
-     * @return the trimmed input line
-     * @throws IOException if an exception is generated reading in the input 
characters
-     */
-    String readCommandLine() throws IOException;
-
-
-    /**
-     * Returns ResponseBuffer, this optimizes the unecessary creation of 
resources
-     * by each handler object
-     *
-     * @return responseBuffer
-     */
-    StringBuffer getResponseBuffer();
-
-    /**
-     * Clears the response buffer, returning the String of characters in the 
buffer.
-     *
-     * @return the data in the response buffer
-     */
-    String clearResponseBuffer();
-
-    /**
-     * Returns Inputstream for handling messages and commands
-     *
-     * @return InputStream object
-     */
-    InputStream getInputStream();
-
-    /**
-     * Returns currently process command name
-     *
-     * @return current command name
-     */
-    String getCommandName();
-
-    /**
-     * Returns currently process command argument
-     *
-     * @return current command argument
-     */
-    String getCommandArgument();
-
-    /**
-     * Returns Mail object for message handlers to process
-     *
-     * @return Mail object
-     */
-    Mail getMail();
-
-    /**
-     * Sets the MailImpl object for further processing
-     *
-     * @param mail MailImpl object
-     */
-    void setMail(MailImpl mail);
-
-    /**
-     * Returns host name of the client
-     *
-     * @return hostname of the client
-     */
-    String getRemoteHost();
-
-    /**
-     * Returns host ip address of the client
-     *
-     * @return host ip address of the client
-     */
-    String getRemoteIPAddress();
-
-    /**
-     * this makes the message to be dropped inprotocol
-     *
-     */
-    void abortMessage();
-
-    /**
-     * this makes the session to close
-     *
-     */
-    void endSession();
-
-    /**
-     * Returns the session status
-     *
-     * @return if the session is open or closed
-     */
-    boolean isSessionEnded();
-
-    /**
-     * Returns Map that consists of the state of the SMTPSession
-     *
-     * @return map of the current SMTPSession state
-     */
-    HashMap getState();
-
-    /**
-     * Resets message-specific, but not authenticated user, state.
-     *
-     */
-    void resetState();
-
-    /**
-     * Returns SMTPHandler service wide configuration
-     *
-     * @return SMTPHandlerConfigurationData
-     */
-    SMTPHandlerConfigurationData getConfigurationData();
-
-    /**
-     * Sets the blocklisted value
-     *
-     * @param blocklisted
-     */
-    void setBlockListed(boolean blocklisted);
-
-    /**
-     * Returns the blocklisted status
-     *
-     * @return blocklisted
-     */
-    boolean isBlockListed();
-
-    /**
-     * Returns whether Relaying is allowed or not
-     *
-     * @return the relaying status
-     */
-    boolean isRelayingAllowed();
-
-    /**
-     * Returns whether Authentication is required or not
-     *
-     * @return authentication required or not
-     */
-    boolean isAuthRequired();
-
-    /**
-     * Returns the user name associated with this SMTP interaction.
-     *
-     * @return the user name
-     */
-    String getUser();
-
-    /**
-     * Sets the user name associated with this SMTP interaction.
-     *
-     * @param userID the user name
-     */
-    void setUser(String user);
-
-    /**
-     * Returns Watchdog object used for handling timeout
-     *
-     * @return Watchdog object
-     */
-    Watchdog getWatchdog();
-
-    /**
-     * Returns the SMTP session id
-     *
-     * @return SMTP session id
-     */
-    String getSessionID();
-
-}
-
+/***********************************************************************
+ * Copyright (c) 1999-2005 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.smtpserver;
+
+
+import org.apache.mailet.Mail;
+import org.apache.james.core.MailImpl;
+import java.util.HashMap;
+import java.io.IOException;
+import java.io.InputStream;
+import org.apache.james.util.watchdog.Watchdog;
+
+/**
+ * All the handlers access this interface to communicate with
+ * SMTPHandler object
+ */
+
+public interface SMTPSession {
+
+    /**
+     * Writes response string to the client
+     *
+     * @param respString String that needs to send to the client
+     */
+    void writeResponse(String respString);
+
+    /**
+     * Reads a line of characters off the command line.
+     *
+     * @return the trimmed input line
+     * @throws IOException if an exception is generated reading in the input 
characters
+     */
+    String readCommandLine() throws IOException;
+
+
+    /**
+     * Returns ResponseBuffer, this optimizes the unecessary creation of 
resources
+     * by each handler object
+     *
+     * @return responseBuffer
+     */
+    StringBuffer getResponseBuffer();
+
+    /**
+     * Clears the response buffer, returning the String of characters in the 
buffer.
+     *
+     * @return the data in the response buffer
+     */
+    String clearResponseBuffer();
+
+    /**
+     * Returns Inputstream for handling messages and commands
+     *
+     * @return InputStream object
+     */
+    InputStream getInputStream();
+
+    /**
+     * Returns currently process command name
+     *
+     * @return current command name
+     */
+    String getCommandName();
+
+    /**
+     * Returns currently process command argument
+     *
+     * @return current command argument
+     */
+    String getCommandArgument();
+
+    /**
+     * Returns Mail object for message handlers to process
+     *
+     * @return Mail object
+     */
+    Mail getMail();
+
+    /**
+     * Sets the MailImpl object for further processing
+     *
+     * @param mail MailImpl object
+     */
+    void setMail(MailImpl mail);
+
+    /**
+     * Returns host name of the client
+     *
+     * @return hostname of the client
+     */
+    String getRemoteHost();
+
+    /**
+     * Returns host ip address of the client
+     *
+     * @return host ip address of the client
+     */
+    String getRemoteIPAddress();
+
+    /**
+     * this makes the message to be dropped inprotocol
+     *
+     */
+    void abortMessage();
+
+    /**
+     * this makes the session to close
+     *
+     */
+    void endSession();
+
+    /**
+     * Returns the session status
+     *
+     * @return if the session is open or closed
+     */
+    boolean isSessionEnded();
+
+    /**
+     * Returns Map that consists of the state of the SMTPSession
+     *
+     * @return map of the current SMTPSession state
+     */
+    HashMap getState();
+
+    /**
+     * Resets message-specific, but not authenticated user, state.
+     *
+     */
+    void resetState();
+
+    /**
+     * Returns SMTPHandler service wide configuration
+     *
+     * @return SMTPHandlerConfigurationData
+     */
+    SMTPHandlerConfigurationData getConfigurationData();
+
+    /**
+     * Sets the blocklisted value
+     *
+     * @param blocklisted
+     */
+    void setBlockListed(boolean blocklisted);
+
+    /**
+     * Returns the blocklisted status
+     *
+     * @return blocklisted
+     */
+    boolean isBlockListed();
+
+    /**
+     * Returns whether Relaying is allowed or not
+     *
+     * @return the relaying status
+     */
+    boolean isRelayingAllowed();
+
+    /**
+     * Returns whether Authentication is required or not
+     *
+     * @return authentication required or not
+     */
+    boolean isAuthRequired();
+
+    /**
+     * Returns the user name associated with this SMTP interaction.
+     *
+     * @return the user name
+     */
+    String getUser();
+
+    /**
+     * Sets the user name associated with this SMTP interaction.
+     *
+     * @param userID the user name
+     */
+    void setUser(String user);
+
+    /**
+     * Returns Watchdog object used for handling timeout
+     *
+     * @return Watchdog object
+     */
+    Watchdog getWatchdog();
+
+    /**
+     * Returns the SMTP session id
+     *
+     * @return SMTP session id
+     */
+    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();
+
+}
+

Modified: 
james/server/trunk/src/java/org/apache/james/smtpserver/UnknownCmdHandler.java
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/smtpserver/UnknownCmdHandler.java?rev=264796&r1=264795&r2=264796&view=diff
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/smtpserver/UnknownCmdHandler.java 
(original)
+++ 
james/server/trunk/src/java/org/apache/james/smtpserver/UnknownCmdHandler.java 
Tue Aug 30 08:30:13 2005
@@ -1,49 +1,60 @@
-/***********************************************************************
- * Copyright (c) 1999-2005 The Apache Software Foundation.             *
- * All rights reserved.                                                *
- * ------------------------------------------------------------------- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you *
- * may not use this file except in compliance with the License. You    *
- * may obtain a copy of the License at:                                *
- *                                                                     *
- *     http://www.apache.org/licenses/LICENSE-2.0                      *
- *                                                                     *
- * Unless required by applicable law or agreed to in writing, software *
- * distributed under the License is distributed on an "AS IS" BASIS,   *
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
- * implied.  See the License for the specific language governing       *
- * permissions and limitations under the License.                      *
- ***********************************************************************/
-
-package org.apache.james.smtpserver;
-
-import org.apache.james.util.mail.dsn.DSNStatus;
-
-/**
-  * Default command handler for handling unknown commands
-  */
-public class UnknownCmdHandler implements CommandHandler {
-
-    /**
-     * The name of the command handled by the command handler
-     */
-    public static final String UNKNOWN_COMMAND = "UNKNOWN";
-
-    /**
-     * Handler method called upon receipt of an unrecognized command.
-     * Returns an error response and logs the command.
-     *
-     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
-    **/
-    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());
-        String responseString = session.clearResponseBuffer();
-
-        session.writeResponse(responseString);
-    }
-
-}
+/***********************************************************************
+ * Copyright (c) 1999-2005 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.smtpserver;
+
+import org.apache.james.util.mail.dsn.DSNStatus;
+
+/**
+  * Default command handler for handling unknown commands
+  */
+public class UnknownCmdHandler implements CommandHandler {
+
+    /**
+     * The name of the command handled by the command handler
+     */
+    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.
+     *
+     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
+    **/
+    public void onCommand(SMTPSession session) {
+
+        //If there was message failure, don't consider it as an unknown command
+        if (session.getMessageState().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);
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to