You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ba...@apache.org on 2006/12/26 18:39:31 UTC

svn commit: r490340 - in /james/server/sandbox/handlerapi-experiment/src: java/org/apache/james/smtpserver/ java/org/apache/james/smtpserver/core/ test/org/apache/james/smtpserver/

Author: bago
Date: Tue Dec 26 09:39:31 2006
New Revision: 490340

URL: http://svn.apache.org/viewvc?view=rev&rev=490340
Log:
Moved welcome message from the SMPTHandler to a core ConnectHanlder.
Fixed tests for previous change checkAuthClients=>checkAuthNetworks

Added:
    james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/WelcomeMessageHandler.java   (with props)
Modified:
    james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandler.java
    james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/CoreCmdHandlerLoader.java
    james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SMTPServerTest.java
    james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java

Modified: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandler.java?view=diff&rev=490340&r1=490339&r2=490340
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandler.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandler.java Tue Dec 26 09:39:31 2006
@@ -22,17 +22,14 @@
 package org.apache.james.smtpserver;
 
 import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.james.Constants;
 import org.apache.james.core.AbstractJamesHandler;
 import org.apache.james.util.CRLFDelimitedByteBuffer;
 import org.apache.mailet.Mail;
-import org.apache.mailet.dates.RFC822DateFormat;
 
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.Socket;
 import java.util.Collection;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
@@ -59,22 +56,11 @@
     private final static byte MESSAGE_ABORT_MODE = 4;
 
     /**
-     * SMTP Server identification string used in SMTP headers
-     */
-    private final static String SOFTWARE_TYPE = "JAMES SMTP Server "
-                                                 + Constants.SOFTWARE_VERSION;
-
-    /**
      * Static Random instance used to generate SMTP ids
      */
     private final static Random random = new Random();
 
     /**
-     * Static RFC822DateFormat used to generate date headers
-     */
-    private final static RFC822DateFormat rfc822DateFormat = new RFC822DateFormat();
-
-    /**
      * The SMTPHandlerChain object set by SMTPServer
      */
     SMTPHandlerChain handlerChain = null;
@@ -115,12 +101,6 @@
      */
     private boolean heloEhloEnforcement;
     
-
-    /**
-     * The SMTPGreeting
-     */
-    private String smtpGreeting = null;
-    
     /**
      * The id associated with this particular SMTP interaction.
      */
@@ -171,28 +151,10 @@
         relayingAllowed = theConfigData.isRelayingAllowed(remoteIP);
         authRequired = theConfigData.isAuthRequired(remoteIP);
         heloEhloEnforcement = theConfigData.useHeloEhloEnforcement();
-        smtpGreeting = theConfigData.getSMTPGreeting();
         // Both called in resetHandler, we don't need to call them again here.
         // sessionEnded = false;
         // resetState();
         // resetConnectionState();
-
-        SMTPResponse welcomeResponse;
-        // if no greeting was configured use a default
-        if (smtpGreeting == null) {
-            // Initially greet the connector
-            // Format is:  Sat, 24 Jan 1998 13:16:09 -0500
-            welcomeResponse = new SMTPResponse("220",
-                          new StringBuffer(256)
-                          .append(theConfigData.getHelloName())
-                          .append(" SMTP Server (")
-                          .append(SOFTWARE_TYPE)
-                          .append(") ready ")
-                          .append(rfc822DateFormat.format(new Date())));
-        } else {
-            welcomeResponse = new SMTPResponse("220",smtpGreeting);
-        }
-        writeSMTPResponse(welcomeResponse);
 
         //the core in-protocol handling logic
         //run all the connection handlers, if it fast fails, end the session

Modified: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/CoreCmdHandlerLoader.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/CoreCmdHandlerLoader.java?view=diff&rev=490340&r1=490339&r2=490340
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/CoreCmdHandlerLoader.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/CoreCmdHandlerLoader.java Tue Dec 26 09:39:31 2006
@@ -43,6 +43,7 @@
     private final Object RCPTCMDHANDLER = RcptCmdHandler.class.getName();
     private final Object RSETCMDHANDLER = RsetCmdHandler.class.getName();
     private final Object VRFYCMDHANDLER = VrfyCmdHandler.class.getName();
+    private final Object WELCOMEMESSAGEHANDLER = WelcomeMessageHandler.class.getName();
    
     /**
      * @see org.apache.james.smtpserver.CommandsHandler#getCommands()
@@ -51,6 +52,7 @@
         Map commands = new HashMap();
         
         // Insert the basecommands in the Map
+        commands.put("", WELCOMEMESSAGEHANDLER);
         commands.put("AUTH", AUTHCMDHANDLER);
         commands.put("DATA", DATACMDHANDLER);
         commands.put("EHLO", EHLOCMDHANDLER);

Added: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/WelcomeMessageHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/WelcomeMessageHandler.java?view=auto&rev=490340
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/WelcomeMessageHandler.java (added)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/WelcomeMessageHandler.java Tue Dec 26 09:39:31 2006
@@ -0,0 +1,71 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you 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.core;
+
+import org.apache.james.Constants;
+import org.apache.james.smtpserver.ConnectHandler;
+import org.apache.james.smtpserver.SMTPResponse;
+import org.apache.james.smtpserver.SMTPSession;
+import org.apache.mailet.dates.RFC822DateFormat;
+
+import java.util.Date;
+
+/**
+ * This ConnectHandler can be used to activate pop-before-smtp
+ */
+public class WelcomeMessageHandler implements ConnectHandler {
+
+    /**
+     * SMTP Server identification string used in SMTP headers
+     */
+    private final static String SOFTWARE_TYPE = "JAMES SMTP Server "
+                                                 + Constants.SOFTWARE_VERSION;
+
+    /**
+     * Static RFC822DateFormat used to generate date headers
+     */
+    private final static RFC822DateFormat rfc822DateFormat = new RFC822DateFormat();
+
+    /**
+     * @see org.apache.james.smtpserver.ConnectHandler#onConnect(SMTPSession)
+     */
+    public void onConnect(SMTPSession session) {
+        String smtpGreeting = session.getConfigurationData().getSMTPGreeting();
+
+        SMTPResponse welcomeResponse;
+        // if no greeting was configured use a default
+        if (smtpGreeting == null) {
+            // Initially greet the connector
+            // Format is:  Sat, 24 Jan 1998 13:16:09 -0500
+            welcomeResponse = new SMTPResponse("220",
+                          new StringBuffer(256)
+                          .append(session.getConfigurationData().getHelloName())
+                          .append(" SMTP Server (")
+                          .append(SOFTWARE_TYPE)
+                          .append(") ready ")
+                          .append(rfc822DateFormat.format(new Date())));
+        } else {
+            welcomeResponse = new SMTPResponse("220",smtpGreeting);
+        }
+        session.writeSMTPResponse(welcomeResponse);
+    }
+
+}

Propchange: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/WelcomeMessageHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SMTPServerTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SMTPServerTest.java?view=diff&rev=490340&r1=490339&r2=490340
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SMTPServerTest.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SMTPServerTest.java Tue Dec 26 09:39:31 2006
@@ -542,7 +542,7 @@
     
     public void testSenderDomainResolvRelayClient() throws Exception {
         m_testConfiguration.setSenderDomainResolv();
-        m_testConfiguration.setCheckAuthClients(true);
+        m_testConfiguration.setCheckAuthNetworks(true);
         finishSetUp(m_testConfiguration);
 
         SMTPClient smtpProtocol1 = new SMTPClient();

Modified: james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java?view=diff&rev=490340&r1=490339&r2=490340
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java Tue Dec 26 09:39:31 2006
@@ -45,7 +45,6 @@
     private boolean m_ehloResolv = false;
     private boolean m_senderDomainResolv = false;
     private boolean m_checkAuthNetworks = false;
-    private boolean m_checkAuthClients = false;
     private boolean m_heloEhloEnforcement = true;
     private boolean m_reverseEqualsHelo = false;
     private boolean m_reverseEqualsEhlo = false;
@@ -125,10 +124,6 @@
         m_senderDomainResolv = true; 
     }
     
-    public void setCheckAuthClients(boolean ignore) {
-        m_checkAuthClients = ignore; 
-    }
-    
     public void setMaxRcpt(int maxRcpt) {
         m_maxRcpt = maxRcpt; 
     }
@@ -206,8 +201,8 @@
             DefaultConfiguration d = createHandler(
                     ValidSenderDomainHandler.class.getName(), null);
             d.setAttribute("command", "MAIL");
-            d.addChild(Util.getValuedConfiguration("checkAuthClients",
-                    m_checkAuthClients + ""));
+            d.addChild(Util.getValuedConfiguration("checkAuthNetworks",
+                    m_checkAuthNetworks + ""));
             config.addChild(d);
         }
         if (m_maxRcpt > 0) {



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org