Author: bago
Date: Sat Apr 15 06:58:51 2006
New Revision: 394291

URL: http://svn.apache.org/viewcvs?rev=394291&view=rev
Log:
Configure option to disable heloEhloEnforcement for better compatibility with 
earlier James versions (JAMES-477)
Patch by Norman Maurer

Modified:
    james/server/trunk/src/conf/james-config.xml
    james/server/trunk/src/java/org/apache/james/smtpserver/MailCmdHandler.java
    james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandler.java
    
james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandlerConfigurationData.java
    james/server/trunk/src/java/org/apache/james/smtpserver/SMTPServer.java
    james/server/trunk/src/java/org/apache/james/smtpserver/SMTPSession.java
    james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java
    
james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java

Modified: james/server/trunk/src/conf/james-config.xml
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/conf/james-config.xml?rev=394291&r1=394290&r2=394291&view=diff
==============================================================================
--- james/server/trunk/src/conf/james-config.xml (original)
+++ james/server/trunk/src/conf/james-config.xml Sat Apr 15 06:58:51 2006
@@ -688,6 +688,12 @@
          <!--  This sets the maximum allowed message size (in kilobytes) for 
this -->
          <!--  SMTP service. If unspecified, the value defaults to 0, which 
means no limit. -->
          <maxmessagesize>0</maxmessagesize>
+         
+         <!--  This sets wether to enforce the use of HELO/EHLO salutation 
before a -->
+         <!--  MAIL command is accepted. If unspecified, the value defaults to 
true -->
+         <!-- 
+         <heloEhloEnforcement>true</heloEhloEnforcement>
+         -->
 
          <!-- The configuration handler chain -->
          <handlerchain>

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=394291&r1=394290&r2=394291&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 
Sat Apr 15 06:58:51 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.getState().containsKey(SMTPSession.CURRENT_HELO_MODE)) {
+        } 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/SMTPHandler.java
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandler.java?rev=394291&r1=394290&r2=394291&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 
Sat Apr 15 06:58:51 2006
@@ -163,6 +163,11 @@
     private boolean relayingAllowed;
 
     /**
+     * Whether the remote Server must send HELO/EHLO 
+     */
+    private boolean heloEhloEnforcement;
+    
+    /**
      * TEMPORARY: is the sending address blocklisted
      */
     private boolean blocklisted;
@@ -273,6 +278,7 @@
             smtpID = random.nextInt(1024) + "";
             relayingAllowed = theConfigData.isRelayingAllowed(remoteIP);
             authRequired = theConfigData.isAuthRequired(remoteIP);
+            heloEhloEnforcement = theConfigData.useHeloEhloEnforcement();
             sessionEnded = false;
             resetState();
         } catch (Exception e) {
@@ -697,6 +703,12 @@
         return authRequired;
     }
 
+    /**
+     * @see org.apache.james.smtpserver.SMTPSession#useHeloEhloEnforcement()
+     */
+    public boolean useHeloEhloEnforcement() {
+        return heloEhloEnforcement;
+    }
     /**
      * @see org.apache.james.smtpserver.SMTPSession#getUser()
      */

Modified: 
james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandlerConfigurationData.java
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandlerConfigurationData.java?rev=394291&r1=394290&r2=394291&view=diff
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandlerConfigurationData.java
 (original)
+++ 
james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandlerConfigurationData.java
 Sat Apr 15 06:58:51 2006
@@ -79,6 +79,14 @@
      * @return whether SMTP authentication is on
      */
     boolean isVerifyIdentity();
+    
+    /**
+     * Returns whether the remote server needs to send a HELO/EHLO
+     * of its senders.
+     *
+     * @return whether SMTP authentication is on
+     */
+    boolean useHeloEhloEnforcement();
 
     /**
      * Returns the MailServer interface for this service.

Modified: 
james/server/trunk/src/java/org/apache/james/smtpserver/SMTPServer.java
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/smtpserver/SMTPServer.java?rev=394291&r1=394290&r2=394291&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/SMTPServer.java 
(original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/SMTPServer.java Sat 
Apr 15 06:58:51 2006
@@ -93,6 +93,11 @@
     private boolean verifyIdentity = false;
 
     /**
+     * Whether the server needs helo to be send first
+     */
+    private boolean heloEhloEnforcement = false;
+    
+    /**
      * This is a Network Matcher that should be configured to contain
      * authorized networks that bypass SMTP AUTH requirements.
      */
@@ -217,6 +222,10 @@
             if (getLogger().isInfoEnabled()) {
                 getLogger().info("The idle timeout will be reset every " + 
lengthReset + " bytes.");
             }
+            
+            heloEhloEnforcement = 
handlerConfiguration.getChild("heloEhloEnforcement").getValueAsBoolean();
+            
+            if (authRequiredString.equals("true")) authRequired = 
AUTH_REQUIRED;
 
             //set the logger
             ContainerUtil.enableLogging(handlerChain,getLogger());
@@ -421,6 +430,13 @@
          */
         public UsersRepository getUsersRepository() {
             return SMTPServer.this.users;
+        }
+        
+        /**
+         * @see 
org.apache.james.smtpserver.SMTPHandlerConfigurationData#useHeloEnforcement()
+         */
+        public boolean useHeloEhloEnforcement() {
+            return SMTPServer.this.heloEhloEnforcement;
         }
 
     }

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=394291&r1=394290&r2=394291&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 
Sat Apr 15 06:58:51 2006
@@ -1,217 +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 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=394291&r1=394290&r2=394291&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 
Sat Apr 15 06:58:51 2006
@@ -572,6 +572,25 @@
         
         smtpProtocol1.quit();
     }
+    
+    public void testHeloEnforcementDisabled() throws Exception, SMTPException {
+        m_testConfiguration.setHeloEhloEnforcement(false);
+        finishSetUp(m_testConfiguration);
+
+        SMTPProtocol smtpProtocol1 = new SMTPProtocol("127.0.0.1", 
m_smtpListenerPort);
+        smtpProtocol1.openPort();
+
+        assertEquals("first connection taken", 1, smtpProtocol1.getState());
+
+        // no message there, yet
+        assertNull("no mail received by mail server", 
m_mailServer.getLastMail());
+
+        String sender1 = "[EMAIL PROTECTED]";
+        
+        smtpProtocol1.mail(new Address(sender1));
+        
+        smtpProtocol1.quit();
+    }
 
     public void testAuth() throws Exception, SMTPException {
         m_testConfiguration.setAuthorizedAddresses("128.0.0.1/8");

Modified: 
james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java?rev=394291&r1=394290&r2=394291&view=diff
==============================================================================
--- 
james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java
 (original)
+++ 
james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java
 Sat Apr 15 06:58:51 2006
@@ -35,6 +35,7 @@
     private boolean m_ehloResolv = false;
     private boolean m_senderDomainResolv = false;
     private boolean m_checkAuthClients = false;
+    private boolean m_heloEhloEnforcement = true;
     private int m_maxRcpt = 0;
 
     
@@ -99,6 +100,10 @@
     public void setMaxRcpt(int maxRcpt) {
         m_maxRcpt = maxRcpt; 
     }
+    
+    public void setHeloEhloEnforcement(boolean heloEhloEnforcement) {
+        m_heloEhloEnforcement = heloEhloEnforcement; 
+    }
 
     public void init() throws ConfigurationException {
 
@@ -113,6 +118,7 @@
         
handlerConfig.addChild(Util.getValuedConfiguration("authorizedAddresses", 
m_authorizedAddresses));
         handlerConfig.addChild(Util.getValuedConfiguration("maxmessagesize", 
"" + m_maxMessageSize));
         handlerConfig.addChild(Util.getValuedConfiguration("authRequired", 
m_authorizingMode));
+        
handlerConfig.addChild(Util.getValuedConfiguration("heloEhloEnforcement", 
m_heloEhloEnforcement+""));
         if (m_verifyIdentity) 
handlerConfig.addChild(Util.getValuedConfiguration("verifyIdentity", "" + 
m_verifyIdentity));
         
         handlerConfig.addChild(Util.createSMTPHandlerChainConfiguration());



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

Reply via email to