Author: bago
Date: Sun Apr 16 12:40:12 2006
New Revision: 394548

URL: http://svn.apache.org/viewcvs?rev=394548&view=rev
Log:
Reverted previous commit, added a different patch (compliant with approach of 
other code) ad added a test to SMTPServer (JAMES-479)

Modified:
    james/server/trunk/src/java/org/apache/james/smtpserver/EhloCmdHandler.java
    james/server/trunk/src/java/org/apache/james/smtpserver/HeloCmdHandler.java
    james/server/trunk/src/java/org/apache/james/smtpserver/MailCmdHandler.java
    james/server/trunk/src/java/org/apache/james/smtpserver/RsetCmdHandler.java
    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/test/org/apache/james/smtpserver/SMTPServerTest.java

Modified: 
james/server/trunk/src/java/org/apache/james/smtpserver/EhloCmdHandler.java
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/smtpserver/EhloCmdHandler.java?rev=394548&r1=394547&r2=394548&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/EhloCmdHandler.java 
(original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/EhloCmdHandler.java 
Sun Apr 16 12:40:12 2006
@@ -92,7 +92,6 @@
             session.writeResponse(responseString);
         } else if (badEhlo == false){
             session.resetState();
-            session.setHeloEhloSend(true);
             session.getState().put(SMTPSession.CURRENT_HELO_MODE, 
COMMAND_NAME);
 
             ArrayList esmtpextensions = new ArrayList();

Modified: 
james/server/trunk/src/java/org/apache/james/smtpserver/HeloCmdHandler.java
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/smtpserver/HeloCmdHandler.java?rev=394548&r1=394547&r2=394548&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/HeloCmdHandler.java 
(original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/HeloCmdHandler.java 
Sun Apr 16 12:40:12 2006
@@ -93,7 +93,6 @@
             getLogger().info(responseString);
         } else if (badHelo == false) {
             session.resetState();
-            session.setHeloEhloSend(true);
             session.getState().put(SMTPSession.CURRENT_HELO_MODE, 
COMMAND_NAME);
             session.getResponseBuffer().append("250 ")
                           
.append(session.getConfigurationData().getHelloName())

Modified: 
james/server/trunk/src/java/org/apache/james/smtpserver/MailCmdHandler.java
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/smtpserver/MailCmdHandler.java?rev=394548&r1=394547&r2=394548&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/MailCmdHandler.java 
(original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/MailCmdHandler.java 
Sun Apr 16 12:40:12 2006
@@ -105,7 +105,7 @@
         if (session.getState().containsKey(SMTPSession.SENDER)) {
             responseString = "503 
"+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" Sender 
already specified";
             session.writeResponse(responseString);
-        } else if (!session.isHeloEhloSend() && 
session.useHeloEhloEnforcement()) {
+        } else if 
(!session.getState().containsKey(SMTPSession.CURRENT_HELO_MODE) && 
session.useHeloEhloEnforcement()) {
             responseString = "503 
"+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" Need HELO 
or EHLO before MAIL";
             session.writeResponse(responseString);
         } else if (argument == null || 
!argument.toUpperCase(Locale.US).equals("FROM")

Modified: 
james/server/trunk/src/java/org/apache/james/smtpserver/RsetCmdHandler.java
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/smtpserver/RsetCmdHandler.java?rev=394548&r1=394547&r2=394548&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/RsetCmdHandler.java 
(original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/RsetCmdHandler.java 
Sun Apr 16 12:40:12 2006
@@ -48,8 +48,14 @@
     private void doRSET(SMTPSession session, String argument) {
         String responseString = "";
         if ((argument == null) || (argument.length() == 0)) {
-            responseString = "250 
"+DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.UNDEFINED_STATUS)+" OK";
+            // remember the ehlo mode
+            Object currentHeloMode = 
session.getState().get(SMTPSession.CURRENT_HELO_MODE);
             session.resetState();
+            // start again with the old helo mode
+            if (currentHeloMode != null) {
+                
session.getState().put(SMTPSession.CURRENT_HELO_MODE,currentHeloMode);
+            }
+            responseString = "250 
"+DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.UNDEFINED_STATUS)+" OK";
         } else {
             responseString = "500 
"+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" 
Unexpected argument provided with RSET command";
         }

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=394548&r1=394547&r2=394548&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 
Sun Apr 16 12:40:12 2006
@@ -168,11 +168,6 @@
     private boolean heloEhloEnforcement;
     
     /**
-     * Whether the remote Server has send HELO/EHLO
-     */
-    private boolean heloEhloSend;
-    
-    /**
      * TEMPORARY: is the sending address blocklisted
      */
     private boolean blocklisted;
@@ -714,21 +709,6 @@
     public boolean useHeloEhloEnforcement() {
         return heloEhloEnforcement;
     }
-    
-    /**
-     * @see org.apache.james.smtpserver.SMTPSession#isHeloEhloSend()
-     */
-    public boolean isHeloEhloSend() {
-        return heloEhloSend;
-    }
-    
-    /**
-     * @see org.apache.james.smtpserver.SMTPSession#setHeloEhloSend()
-     */
-    public void setHeloEhloSend(boolean heloEhloSend ) {
-        this.heloEhloSend = heloEhloSend;
-    }
-    
     /**
      * @see org.apache.james.smtpserver.SMTPSession#getUser()
      */

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=394548&r1=394547&r2=394548&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 
Sun Apr 16 12:40:12 2006
@@ -1,236 +1,224 @@
-/***********************************************************************
- * Copyright (c) 1999-2006 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.watchdog.Watchdog;
-import org.apache.mailet.Mail;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-
-/**
- * All the handlers access this interface to communicate with
- * SMTPHandler object
- */
-
-public interface SMTPSession {
-
-    // Keys used to store/lookup data in the internal state hash map
-    public final static String MESG_FAILED = "MESG_FAILED";   // Message 
failed flag
-    public final static String SENDER = "SENDER_ADDRESS";     // Sender's 
email address
-    public final static String RCPT_LIST = "RCPT_LIST";   // The message 
recipients
-    public final static String CURRENT_HELO_MODE = "CURRENT_HELO_MODE"; // 
HELO or EHLO
-
-    /**
-     * 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(Mail 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 whether remote server needs to send HELO/EHLO
-     *
-     * @return HELO/EHLO required or not
-     */
-    boolean useHeloEhloEnforcement();
-
-    /**
-     * Identify if a HELO/EHLO was send in this session
-     * 
-     * @return HELO/EHLO was send
-     */
-    boolean isHeloEhloSend();
-    
-    /**
-     * Get called if HELO/EHLO was send
-     */
-    void setHeloEhloSend(boolean heloEhloSend);
-    
-    /**
-     * 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-2006 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.watchdog.Watchdog;
+import org.apache.mailet.Mail;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+
+/**
+ * All the handlers access this interface to communicate with
+ * SMTPHandler object
+ */
+
+public interface SMTPSession {
+
+    // Keys used to store/lookup data in the internal state hash map
+    public final static String MESG_FAILED = "MESG_FAILED";   // Message 
failed flag
+    public final static String SENDER = "SENDER_ADDRESS";     // Sender's 
email address
+    public final static String RCPT_LIST = "RCPT_LIST";   // The message 
recipients
+    public final static String CURRENT_HELO_MODE = "CURRENT_HELO_MODE"; // 
HELO or EHLO
+
+    /**
+     * 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(Mail 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 whether remote server needs to send HELO/EHLO
+     *
+     * @return HELO/EHLO required or not
+     */
+    boolean useHeloEhloEnforcement();
+
+    /**
+     * 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();
+
+}
+

Modified: 
james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java?rev=394548&r1=394547&r2=394548&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java 
(original)
+++ james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java 
Sun Apr 16 12:40:12 2006
@@ -714,6 +714,26 @@
         assertNull("no mail received by mail server", 
m_mailServer.getLastMail());
     }
 
+    public void testMultipleMailsAndRset() throws Exception, SMTPException {
+        finishSetUp(m_testConfiguration);
+
+        MySMTPProtocol smtpProtocol = new MySMTPProtocol("127.0.0.1", 
m_smtpListenerPort);
+        smtpProtocol.openPort();
+
+        smtpProtocol.ehlo(InetAddress.getLocalHost());
+
+        smtpProtocol.mail(new Address("[EMAIL PROTECTED]"));
+        
+        smtpProtocol.reset();
+        
+        smtpProtocol.mail(new Address("[EMAIL PROTECTED]"));
+
+        smtpProtocol.quit();
+
+        // mail was propagated by SMTPServer
+        assertNull("no mail received by mail server", 
m_mailServer.getLastMail());
+    }
+
     public void testRelayingDenied() throws Exception, SMTPException {
         m_testConfiguration.setAuthorizedAddresses("128.0.0.1/8");
         finishSetUp(m_testConfiguration);
@@ -807,6 +827,8 @@
         smtpProtocol2.openPort();
         assertEquals("second connection not taken", 
SMTPProtocol.NOT_CONNECTED, smtpProtocol2.getState());
     }
+    
+    
 }
 
 class MySMTPProtocol extends SMTPProtocol



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

Reply via email to