james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r820662 [1/2] - in /james/server/trunk: avalon-socket-library/src/main/java/org/apache/james/socket/ pop3server-function/src/main/java/org/apache/james/pop3server/ pop3server-function/src/test/java/org/apache/james/pop3server/ smtpserver-fu...
Date Thu, 01 Oct 2009 14:05:53 GMT
Author: norman
Date: Thu Oct  1 14:05:52 2009
New Revision: 820662

URL: http://svn.apache.org/viewvc?rev=820662&view=rev
Log:
Massiv refactoring:
* use loaderservice for pop3server to inject stuff
* Share code between SMTPServer and POP3Server (packaging is sub-optimal atm)
* use same pattern in pop3server as in smtpserver

Added:
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CoreCmdHandlerLoader.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/LineHandler.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3CommandDispatcherLineHandler.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Response.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/WelcomeMessageHandler.java
    james/server/trunk/pop3server-function/src/test/java/org/apache/james/pop3server/FakeLoader.java
Removed:
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/ExtensibleHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/HandlersPackage.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/WiringException.java
Modified:
    james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/TLSSupportedSession.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CapaCmdHandler.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CommandHandler.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/DeleCmdHandler.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/ListCmdHandler.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/NoopCmdHandler.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Handler.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3HandlerChain.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Session.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/PassCmdHandler.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/QuitCmdHandler.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/RetrCmdHandler.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/RsetCmdHandler.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/StatCmdHandler.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/StlsCmdHandler.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/TopCmdHandler.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/UidlCmdHandler.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/UnknownCmdHandler.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/UserCmdHandler.java
    james/server/trunk/pop3server-function/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
    james/server/trunk/pop3server-function/src/test/java/org/apache/james/pop3server/POP3TestConfiguration.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/CommandHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandlerChain.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPSession.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/AbstractHookableCmdHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/CoreCmdHandlerLoader.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/CoreMessageHookLoader.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/DataCmdHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/DataLineMessageHookHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/SMTPCommandDispatcherLineHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/esmtp/AuthCmdHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/esmtp/EhloCmdHandler.java

Modified: james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/TLSSupportedSession.java
URL: http://svn.apache.org/viewvc/james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/TLSSupportedSession.java?rev=820662&r1=820661&r2=820662&view=diff
==============================================================================
--- james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/TLSSupportedSession.java (original)
+++ james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/TLSSupportedSession.java Thu Oct  1 14:05:52 2009
@@ -22,6 +22,8 @@
 
 import java.io.IOException;
 
+import org.apache.commons.logging.Log;
+
 public interface TLSSupportedSession {
     
 	/**
@@ -44,4 +46,10 @@
      * @throws IOException
      */
     void startTLS() throws IOException;
+    
+    /**
+     * Gets the context sensitive log for this session.
+     * @return log, not null
+     */
+    Log getLogger();
 }

Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CapaCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CapaCmdHandler.java?rev=820662&r1=820661&r2=820662&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CapaCmdHandler.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CapaCmdHandler.java Thu Oct  1 14:05:52 2009
@@ -21,55 +21,59 @@
 package org.apache.james.pop3server;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
-public class CapaCmdHandler implements CommandHandler, CapaCapability{
+import org.apache.james.socket.ExtensibleHandler;
+import org.apache.james.socket.WiringException;
+
+public class CapaCmdHandler implements CommandHandler, ExtensibleHandler{
 	public final static String COMMAND_NAME = "CAPA";
-	private List<CapaCapability> caps = new ArrayList<CapaCapability>();
-    
-	/**
-     * @see org.apache.james.pop3server.CommandHandler#getCommands()
-     */
-	public List<String> getCommands() {
-		List<String> commands = new ArrayList<String>();
-		commands.add(COMMAND_NAME);
-		return commands;
-	}
+	private List<CapaCapability> caps;
 
-	/**
-	 * @see org.apache.james.pop3server.CommandHandler#onCommand(org.apache.james.pop3server.POP3Session)
-	 */
-	public void onCommand(POP3Session session) {
-		session.writeResponse(POP3Handler.OK_RESPONSE+ " Capability list follows");	
 
+    public POP3Response onCommand(POP3Session session, String command, String parameters) {
+	    POP3Response response = new POP3Response(POP3Response.OK_RESPONSE,"Capability list follows");
 		
 		for (int i = 0; i < caps.size(); i++) {
-			List<String>  cList = caps.get(i).getImplementedCapabilities(session);
+			List<String> cList = caps.get(i).getImplementedCapabilities(session);
 			for (int a = 0; a < cList.size(); a++) {
-				session.writeResponse(cList.get(a));
+				response.appendLine(cList.get(a));
 			}
 		}
-		session.writeResponse(".");
+		response.appendLine(".");
+		return response;
 	}
-
 	
-	/**
-	 * Wire the handler
-	 * 
-	 * @param capHandler
-	 */
-	public void wireHandler(CapaCapability capHandler) {
-		caps.add(capHandler);
-	}
 
 	/**
-	 * @see org.apache.james.pop3server.CapaCapability#getImplementedCapabilities(org.apache.james.pop3server.POP3Session)
+	 * @see org.apache.james.socket.ExtensibleHandler#getMarkerInterfaces()
 	 */
-	public List<String> getImplementedCapabilities(POP3Session session) {
-		List<String> cList = new ArrayList<String>();
-		// PIPELINING is supported anyway
-		cList.add("PIPELINING");
-		return cList;
-	}
+	@SuppressWarnings("unchecked")
+    public List<Class<?>> getMarkerInterfaces() {
+        List<Class<?>> mList = new ArrayList();
+        mList.add(CapaCapability.class);
+        return mList;
+    }
+
+    /**
+     * @see org.apache.james.socket.ExtensibleHandler#wireExtensions(java.lang.Class, java.util.List)
+     */
+    @SuppressWarnings("unchecked")
+    public void wireExtensions(Class interfaceName, List extension)
+            throws WiringException {
+        if (interfaceName.equals(CapaCapability.class)) {
+            caps = extension;
+        }
+    }
+
+    /**
+     * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+     */
+    public Collection<String> getImplCommands() {
+        List<String> commands = new ArrayList<String>();
+        commands.add(COMMAND_NAME);
+        return commands;
+    }
 
 }

Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CommandHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CommandHandler.java?rev=820662&r1=820661&r2=820662&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CommandHandler.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CommandHandler.java Thu Oct  1 14:05:52 2009
@@ -21,7 +21,8 @@
 
 package org.apache.james.pop3server;
 
-import java.util.List;
+
+import org.apache.james.socket.CommonCommandHandler;
 
 /**
  * Custom command handlers must implement this interface
@@ -29,16 +30,10 @@
  * therefore the command handlers must store all the state information
  * in the POP3Session object
  */
- public interface CommandHandler {
+ public interface CommandHandler extends CommonCommandHandler{
     /**
      * Handle the command
     **/
-    void onCommand(POP3Session session);
+    POP3Response onCommand(POP3Session session, String command, String parameters);
 
-    /**
-     * Return list of implemented commands
-     * 
-     * @return commands
-     */
-    List<String> getCommands();
 }

Added: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CoreCmdHandlerLoader.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CoreCmdHandlerLoader.java?rev=820662&view=auto
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CoreCmdHandlerLoader.java (added)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CoreCmdHandlerLoader.java Thu Oct  1 14:05:52 2009
@@ -0,0 +1,73 @@
+/****************************************************************
+ * 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.pop3server;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.james.socket.HandlersPackage;
+
+public class CoreCmdHandlerLoader implements HandlersPackage{
+
+    private final static String CAPACMDHANDLER = CapaCmdHandler.class.getName();
+    private final static String USERCMDHANDLER = UserCmdHandler.class.getName();
+    private final static String PASSCMDHANDLER = PassCmdHandler.class.getName();
+    private final static String LISTCMDHANDLER = ListCmdHandler.class.getName();
+    private final static String UIDLCMDHANDLER = UidlCmdHandler.class.getName();
+    private final static String RSETCMDHANDLER = RsetCmdHandler.class.getName();
+    private final static String DELECMDHANDLER = DeleCmdHandler.class.getName();
+    private final static String NOOPCMDHANDLER = NoopCmdHandler.class.getName();
+    private final static String RETRSCMDHANDLER = RetrCmdHandler.class.getName();
+    private final static String TOPCMDHANDLER = TopCmdHandler.class.getName();
+    private final static String STATCMDHANDLER = StatCmdHandler.class.getName();
+    private final static String QUITCMDHANDLER = QuitCmdHandler.class.getName();
+    private final static String WELCOMEMESSAGEHANDLER = WelcomeMessageHandler.class.getName();
+    private final static String UNKOWNCMDHANDLER = UnknownCmdHandler.class.getName();
+
+    private final static String COMMANDDISPATCHER = POP3CommandDispatcherLineHandler.class.getName();
+    private final List<String> commands = new LinkedList<String>();
+
+    public CoreCmdHandlerLoader() {
+        // Insert the base commands in the Map
+        commands.add(WELCOMEMESSAGEHANDLER);
+        commands.add(COMMANDDISPATCHER);
+        commands.add(CAPACMDHANDLER);
+        commands.add(USERCMDHANDLER);
+        commands.add(PASSCMDHANDLER);
+        commands.add(LISTCMDHANDLER);
+        commands.add(UIDLCMDHANDLER);
+        commands.add(RSETCMDHANDLER);
+        commands.add(DELECMDHANDLER);
+        commands.add(NOOPCMDHANDLER);
+        commands.add(RETRSCMDHANDLER);
+        commands.add(TOPCMDHANDLER);
+        commands.add(STATCMDHANDLER);
+        commands.add(QUITCMDHANDLER);
+        commands.add(UNKOWNCMDHANDLER);
+
+    }
+    /**
+     * @see org.apache.james.socket.HandlersPackage#getHandlers()
+     */
+    public List<String> getHandlers() {
+        return commands;
+    }
+
+}

Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/DeleCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/DeleCmdHandler.java?rev=820662&r1=820661&r2=820662&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/DeleCmdHandler.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/DeleCmdHandler.java Thu Oct  1 14:05:52 2009
@@ -22,6 +22,7 @@
 package org.apache.james.pop3server;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 import org.apache.avalon.framework.container.ContainerUtil;
@@ -33,73 +34,63 @@
 public class DeleCmdHandler implements CommandHandler {
 	private final static String COMMAND_NAME = "DELE";
 
-    /**
-     * @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
-     */
-    public void onCommand(POP3Session session) {
-        doDELE(session,session.getCommandArgument());
-    }
-
-    /**
+	/**
      * Handler method called upon receipt of a DELE command.
      * This command deletes a particular mail message from the
-     * mailbox.
-     *
-     * @param argument the first argument parsed by the parseCommand method
-     */
-    private void doDELE(POP3Session session,String argument) {
-        String responseString = null;
+     * mailbox.	 
+     * 
+     * @see org.apache.james.pop3server.CommandHandler#onCommand(org.apache.james.pop3server.POP3Session, java.lang.String, java.lang.String)
+	 */
+    public POP3Response onCommand(POP3Session session, String command, String parameters) {
+        POP3Response response = null;
         if (session.getHandlerState() == POP3Handler.TRANSACTION) {
             int num = 0;
             try {
-                num = Integer.parseInt(argument);
+                num = Integer.parseInt(parameters);
             } catch (Exception e) {
-                responseString = POP3Handler.ERR_RESPONSE + " Usage: DELE [mail number]";
-                session.writeResponse(responseString);
-                return;
+                response = new POP3Response(POP3Response.ERR_RESPONSE,"Usage: DELE [mail number]");
+                return response;
             }
             try {
                 Mail mc = session.getUserMailbox().get(num);
                 if (mc == POP3Handler.DELETED) {
                     StringBuilder responseBuffer =
                         new StringBuilder(64)
-                                .append(POP3Handler.ERR_RESPONSE)
-                                .append(" Message (")
+                                .append("Message (")
                                 .append(num)
                                 .append(") already deleted.");
-                    responseString = responseBuffer.toString();
-                    session.writeResponse(responseString);
+                    response = new POP3Response(POP3Response.ERR_RESPONSE,responseBuffer.toString());
                 } else {
                     session.getUserMailbox().set(num, POP3Handler.DELETED);
                     // we are replacing our reference with "DELETED", so we have
                     // to dispose the no-more-referenced mail object.
                     ContainerUtil.dispose(mc);
-                    session.writeResponse(POP3Handler.OK_RESPONSE + " Message deleted");
+                    response = new POP3Response(POP3Response.OK_RESPONSE,"Message deleted");
                 }
             } catch (IndexOutOfBoundsException iob) {
                 StringBuilder responseBuffer =
                     new StringBuilder(64)
-                            .append(POP3Handler.ERR_RESPONSE)
-                            .append(" Message (")
+                            .append("Message (")
                             .append(num)
                             .append(") does not exist.");
-                responseString = responseBuffer.toString();
-                session.writeResponse(responseString);
+                response = new POP3Response(POP3Response.ERR_RESPONSE,responseBuffer.toString());
             }
         } else {
-            responseString = POP3Handler.ERR_RESPONSE;
-            session.writeResponse(responseString);
+            response = new POP3Response(POP3Response.ERR_RESPONSE);
         }
+        return response;   
     }
 
+
+
     /**
-     * @see org.apache.james.pop3server.CommandHandler#getCommands()
+     * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
      */
-	public List<String> getCommands() {
-		List<String> commands = new ArrayList<String>();
-		commands.add(COMMAND_NAME);
-		return commands;
-	}
+    public Collection<String> getImplCommands() {
+        List<String> commands = new ArrayList<String>();
+        commands.add(COMMAND_NAME);
+        return commands;
+    }
 
 
 }

Added: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/LineHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/LineHandler.java?rev=820662&view=auto
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/LineHandler.java (added)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/LineHandler.java Thu Oct  1 14:05:52 2009
@@ -0,0 +1,34 @@
+/****************************************************************
+ * 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.pop3server;
+
+/**
+ * Custom line handlers must implement this interface
+ */
+public interface LineHandler {
+     
+    /**
+     * Handle the command.
+     * @param session not null
+     * @param line not null 
+     */
+    void onLine(POP3Session session, String line);
+    
+}

Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/ListCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/ListCmdHandler.java?rev=820662&r1=820661&r2=820662&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/ListCmdHandler.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/ListCmdHandler.java Thu Oct  1 14:05:52 2009
@@ -22,6 +22,7 @@
 package org.apache.james.pop3server;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 import javax.mail.MessagingException;
@@ -33,12 +34,6 @@
   */
 public class ListCmdHandler implements CommandHandler {
 
-    /**
-     * @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
-     */
-    public void onCommand(POP3Session session) {
-        doLIST(session,session.getCommandArgument());
-    }
 
     /**
      * Handler method called upon receipt of a LIST command.
@@ -48,9 +43,12 @@
      *
      * @param argument the first argument parsed by the parseCommand method
      */
-    private void doLIST(POP3Session session,String argument) {
+
+    public POP3Response onCommand(POP3Session session, String command,
+            String parameters) {
+        POP3Response response = null;
         if (session.getHandlerState() == POP3Handler.TRANSACTION) {
-            if (argument == null) {
+            if (parameters == null) {
                 long size = 0;
                 int count = 0;
                 try {
@@ -62,12 +60,10 @@
                     }
                     StringBuilder responseBuffer =
                         new StringBuilder(32)
-                                .append(POP3Handler.OK_RESPONSE)
-                                .append(" ")
                                 .append(count)
                                 .append(" ")
                                 .append(size);
-                    session.writeResponse(responseBuffer.toString());
+                    response = new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString());
                     count = 0;
                     for (Mail mc:session.getUserMailbox()) {
                         if (mc != POP3Handler.DELETED) {
@@ -76,69 +72,61 @@
                                         .append(count)
                                         .append(" ")
                                         .append(mc.getMessageSize());
-                            session.writeResponse(responseBuffer.toString());
+                            response.appendLine(responseBuffer.toString());
                         }
                         count++;
                     }
-                    session.writeResponse(".");
+                    response.appendLine(".");
                 } catch (MessagingException me) {
-                    session.writeResponse(POP3Handler.ERR_RESPONSE);
+                    response = new POP3Response(POP3Response.ERR_RESPONSE);
                 }
             } else {
                 int num = 0;
                 try {
-                    num = Integer.parseInt(argument);
+                    num = Integer.parseInt(parameters);
                     Mail mc = session.getUserMailbox().get(num);
                     if (mc != POP3Handler.DELETED) {
                         StringBuilder responseBuffer =
                             new StringBuilder(64)
-                                    .append(POP3Handler.OK_RESPONSE)
-                                    .append(" ")
                                     .append(num)
                                     .append(" ")
                                     .append(mc.getMessageSize());
-                        session.writeResponse(responseBuffer.toString());
+                        response = new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString());
                     } else {
                         StringBuilder responseBuffer =
                             new StringBuilder(64)
-                                    .append(POP3Handler.ERR_RESPONSE)
-                                    .append(" Message (")
+                                    .append("Message (")
                                     .append(num)
                                     .append(") already deleted.");
-                        session.writeResponse(responseBuffer.toString());
+                        response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                     }
                 } catch (IndexOutOfBoundsException npe) {
                     StringBuilder responseBuffer =
                         new StringBuilder(64)
-                                .append(POP3Handler.ERR_RESPONSE)
-                                .append(" Message (")
+                                .append("Message (")
                                 .append(num)
                                 .append(") does not exist.");
-                    session.writeResponse(responseBuffer.toString());
+                    response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                 } catch (NumberFormatException nfe) {
                     StringBuilder responseBuffer =
                         new StringBuilder(64)
-                                .append(POP3Handler.ERR_RESPONSE)
-                                .append(" ")
-                                .append(argument)
+                                .append(parameters)
                                 .append(" is not a valid number");
-                    session.writeResponse(responseBuffer.toString());
+                    response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                 } catch (MessagingException me) {
-                    session.writeResponse(POP3Handler.ERR_RESPONSE);
+                    response = new POP3Response(POP3Response.ERR_RESPONSE);
                 }
             }
         } else {
-            session.writeResponse(POP3Handler.ERR_RESPONSE);
+            response = new POP3Response(POP3Response.ERR_RESPONSE);
         }
+        return response;
     }
 
-    /**
-     * @see org.apache.james.pop3server.CommandHandler#getCommands()
-     */
-	public List<String> getCommands() {
-		List<String> commands = new ArrayList<String>();
-		commands.add("LIST");
-		return commands;
-	}
+    public Collection<String> getImplCommands() {
+        List<String> commands = new ArrayList<String>();
+        commands.add("LIST");
+        return commands;
+    }
 
 }

Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/NoopCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/NoopCmdHandler.java?rev=820662&r1=820661&r2=820662&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/NoopCmdHandler.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/NoopCmdHandler.java Thu Oct  1 14:05:52 2009
@@ -22,6 +22,7 @@
 package org.apache.james.pop3server;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 /**
@@ -29,38 +30,33 @@
   */
 public class NoopCmdHandler implements CommandHandler {
 	private final static String COMMAND_NAME = "NOOP";
-    /**
-     * @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
-     */
-    public void onCommand(POP3Session session) {
-        doNOOP(session,session.getCommandArgument());
-    }
 
     /**
      * Handler method called upon receipt of a NOOP command.
      * Like all good NOOPs, does nothing much.
      *
-     * @param argument the first argument parsed by the parseCommand method
-     */
-    private void doNOOP(POP3Session session,String argument) {
-        String responseString = null;
+	 * @see org.apache.james.pop3server.CommandHandler#onCommand(org.apache.james.pop3server.POP3Session, java.lang.String, java.lang.String)
+	 */
+    public POP3Response onCommand(POP3Session session, String command, String parameters) {
+        POP3Response response = null;
         if (session.getHandlerState() == POP3Handler.TRANSACTION) {
-            responseString = POP3Handler.OK_RESPONSE;
-            session.writeResponse(responseString);
+            response = new POP3Response(POP3Response.OK_RESPONSE);
         } else {
-            responseString = POP3Handler.ERR_RESPONSE;
-            session.writeResponse(responseString);
+            response = new POP3Response(POP3Response.ERR_RESPONSE);
         }
+        return response;   
     }
 
-    /**
-     * @see org.apache.james.pop3server.CommandHandler#getCommands()
-     */
-	public List<String> getCommands() {
-		List<String> commands = new ArrayList<String>();
-		commands.add(COMMAND_NAME);
-		return commands;
-	}
+
+
+	/**
+	 * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+	 */
+    public Collection<String> getImplCommands() {
+        List<String> commands = new ArrayList<String>();
+        commands.add(COMMAND_NAME);
+        return commands;
+    }
 
 
 }

Added: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3CommandDispatcherLineHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3CommandDispatcherLineHandler.java?rev=820662&view=auto
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3CommandDispatcherLineHandler.java (added)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3CommandDispatcherLineHandler.java Thu Oct  1 14:05:52 2009
@@ -0,0 +1,144 @@
+/****************************************************************
+ * 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.pop3server;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.james.socket.AbstractCommandDispatcher;
+import org.apache.james.socket.LogEnabled;
+
+public class POP3CommandDispatcherLineHandler extends
+        AbstractCommandDispatcher<CommandHandler> implements LineHandler, LogEnabled {
+    private final static String[] mandatoryCommands = { "USER", "PASS", "LIST" };
+    private final UnknownCmdHandler unknownHandler = new UnknownCmdHandler();
+    /** This log is the fall back shared by all instances */
+    private static final Log FALLBACK_LOG = LogFactory
+            .getLog(POP3CommandDispatcherLineHandler.class);
+
+    /**
+     * Non context specific log should only be used when no context specific log
+     * is available
+     */
+    private Log serviceLog = FALLBACK_LOG;
+
+    /**
+     * @see org.apache.james.socket.AbstractCommandDispatcher#getLog()
+     */
+    protected Log getLog() {
+        return serviceLog;
+    }
+
+    /**
+     * @see org.apache.james.socket.AbstractCommandDispatcher#getMandatoryCommands()
+     */
+    protected List<String> getMandatoryCommands() {
+        return Arrays.asList(mandatoryCommands);
+    }
+
+    /**
+     * @see org.apache.james.socket.AbstractCommandDispatcher#getUnknownCommandHandler()
+     */
+    protected CommandHandler getUnknownCommandHandler() {
+        return unknownHandler;
+    }
+
+    /**
+     * @see org.apache.james.socket.AbstractCommandDispatcher#getUnknownCommandHandlerIdentifier()
+     */
+    protected String getUnknownCommandHandlerIdentifier() {
+        return UnknownCmdHandler.COMMAND_NAME;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.james.socket.ExtensibleHandler#getMarkerInterfaces()
+     */
+    @SuppressWarnings("unchecked")
+    public List<Class<?>> getMarkerInterfaces() {
+        List list = new ArrayList();
+        list.add(CommandHandler.class);
+        return list;
+    }
+
+    /**
+     * @see org.apache.james.pop3server.LineHandler#onLine(org.apache.james.pop3server.POP3Session,
+     *      java.lang.String)
+     */
+    public void onLine(POP3Session session, String cmdString) {
+        String curCommandName = null;
+        String curCommandArgument = null;
+        if (cmdString == null) {
+        }
+        int spaceIndex = cmdString.indexOf(" ");
+        if (spaceIndex > 0) {
+            curCommandName = cmdString.substring(0, spaceIndex);
+            curCommandArgument = cmdString.substring(spaceIndex + 1);
+        } else {
+            curCommandName = cmdString;
+        }
+        curCommandName = curCommandName.toUpperCase(Locale.US);
+
+        if (session.getLogger().isDebugEnabled()) {
+            // Don't display password in logger
+            if (!curCommandName.equals("PASS")) {
+                session.getLogger().debug("Command received: " + cmdString);
+            } else {
+                session.getLogger().debug(
+                        "Command received: PASS <password omitted>");
+            }
+        }
+
+        // fetch the command handlers registered to the command
+        List<CommandHandler> commandHandlers = getCommandHandlers(
+                curCommandName, session);
+        if (commandHandlers == null) {
+            // end the session
+            POP3Response resp = new POP3Response(POP3Response.ERR_RESPONSE,
+                    "Local configuration error: unable to find a command handler.");
+            resp.setEndSession(true);
+            session.writePOP3Response(resp);
+        } else {
+            int count = commandHandlers.size();
+            for (int i = 0; i < count; i++) {
+                POP3Response response = commandHandlers.get(i).onCommand(
+                        session, curCommandName, curCommandArgument);
+                if (response != null) {
+                    session.writePOP3Response(response);
+                    break;
+                }
+            }
+
+        }
+    }
+
+    /**
+     * @see org.apache.james.socket.LogEnabled#setLog(org.apache.commons.logging.Log)
+     */
+    public void setLog(Log log) {
+        this.serviceLog = log;
+    }
+
+}

Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Handler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Handler.java?rev=820662&r1=820661&r2=820662&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Handler.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Handler.java Thu Oct  1 14:05:52 2009
@@ -25,12 +25,11 @@
 import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.List;
-import java.util.Locale;
 
 import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.commons.logging.Log;
-import org.apache.james.Constants;
 import org.apache.james.core.MailImpl;
 import org.apache.james.services.MailRepository;
 import org.apache.james.socket.CRLFTerminatedReader;
@@ -50,20 +49,7 @@
     private final static byte COMMAND_MODE = 1;
     private final static byte RESPONSE_MODE = 2;
 
-    /** POP3 Server identification string used in POP3 headers */
-    private static final String softwaretype        = "JAMES POP3 Server "
-                                                        + Constants.SOFTWARE_VERSION;
-
-    // POP3 response prefixes
-    /** OK response.  Requested content will follow */
-    final static String OK_RESPONSE = "+OK";
-    
-    /** 
-     * Error response.  
-     * Requested content will not be provided.  
-     * This prefix is followed by a more detailed error message.
-     */
-    final static String ERR_RESPONSE = "-ERR";  
+   
 
     // Authentication states for the POP3 interaction
     /** Waiting for user id */
@@ -120,19 +106,9 @@
 
 
     /**
-     * The name of the currently parsed command
-     */
-    String curCommandName =  null;
-
-    /**
-     * The value of the currently parsed command
-     */
-    String curCommandArgument =  null;
-
-    /**
      * The POP3HandlerChain object set by POP3Server
      */
-    final POP3HandlerChain handlerChain;
+    private final POP3HandlerChain handlerChain;
 
     /**
      * The session termination status
@@ -150,10 +126,22 @@
      */
     private byte mode;
     
+    /**
+     * If not null every line is sent to this command handler instead
+     * of the default "command parsing -> dipatching" procedure.
+     */
+    private LinkedList<LineHandler> lineHandlers;
+
+    /**
+     * Connect Handlers
+     */
+    private final LinkedList<ConnectHandler> connectHandlers;
     
     public POP3Handler(final POP3HandlerConfigurationData theConfigData, final POP3HandlerChain handlerChain) {
         this.theConfigData = theConfigData;
         this.handlerChain = handlerChain;
+        connectHandlers = handlerChain.getHandlers(ConnectHandler.class);
+        lineHandlers = handlerChain.getHandlers(LineHandler.class);
     }
     
     /**
@@ -166,19 +154,8 @@
 
         sessionEnded = false;
 
-        // Initially greet the connector
-        // Format is:  Sat, 24 Jan 1998 13:16:09 -0500
-        responseBuffer.append(OK_RESPONSE)
-                    .append(" ")
-                    .append(theConfigData.getHelloName())
-                    .append(" POP3 server (")
-                    .append(POP3Handler.softwaretype)
-                    .append(") ready ");
-        String responseString = clearResponseBuffer();
-        context.writeLoggedFlushedResponse(responseString);
 
         //Session started - RUN all connect handlers
-        List<ConnectHandler> connectHandlers = handlerChain.getConnectHandlers();
         if(connectHandlers != null) {
             int count = connectHandlers.size();
             for(int i = 0; i < count; i++) {
@@ -189,54 +166,24 @@
             }
         }
 
-        
         context.getWatchdog().start();
         while(!sessionEnded) {
-          //Reset the current command values
-          curCommandName = null;
-          curCommandArgument = null;
-          mode = COMMAND_MODE;
-
           //parse the command
-          String cmdString =  readCommandLine();
-          if (cmdString == null) {
+          String line =  null;
+         
+          line = readCommandLine();
+        
+          if (line == null) {
               break;
           }
-          int spaceIndex = cmdString.indexOf(" ");
-          if (spaceIndex > 0) {
-              curCommandName = cmdString.substring(0, spaceIndex);
-              curCommandArgument = cmdString.substring(spaceIndex + 1);
-          } else {
-              curCommandName = cmdString;
-          }
-          curCommandName = curCommandName.toUpperCase(Locale.US);
-
-          if (context.getLogger().isDebugEnabled()) {
-              // Don't display password in logger
-              if (!curCommandName.equals("PASS")) {
-                  context.getLogger().debug("Command received: " + cmdString);
-              } else {
-                  context.getLogger().debug("Command received: PASS <password omitted>");
-              }
-          }
 
-          //fetch the command handlers registered to the command
-          List<CommandHandler> commandHandlers = handlerChain.getCommandHandlers(curCommandName);
-          if(commandHandlers == null) {
-              //end the session
-              break;
+          if (lineHandlers.size() > 0) {
+              ((LineHandler) lineHandlers.getLast()).onLine(this, line);
           } else {
-              int count = commandHandlers.size();
-              for(int i = 0; i < count; i++) {
-                  commandHandlers.get(i).onCommand(this);
-                  context.getWatchdog().reset();
-                  //if the response is received, stop processing of command handlers
-                  if(mode != COMMAND_MODE) {
-                      break;
-                  }
-              }
-
+              sessionEnded = true;
           }
+          context.getWatchdog().reset();
+          
         }
         context.getWatchdog().stop();
         if (context.getLogger().isInfoEnabled()) {
@@ -251,6 +198,8 @@
                     .append(") closed.");
             context.getLogger().info(logBuffer.toString());
         }
+       
+       
     }
     
     /**
@@ -258,7 +207,7 @@
      */
     public void fatalFailure(RuntimeException e, ProtocolContext context) {
         try {
-            context.getOutputWriter().println(ERR_RESPONSE + " Error closing connection.");
+            context.getOutputWriter().println(POP3Response.ERR_RESPONSE + " Error closing connection.");
             context.getOutputWriter().flush();
         } catch (Throwable t) {
             
@@ -289,6 +238,10 @@
             backupUserMailbox.clear();
             backupUserMailbox = null;
         }
+        
+        // empty any previous line handler and add self (command dispatcher)
+        // as the default.
+        lineHandlers = handlerChain.getHandlers(LineHandler.class);
     }
 
     /**
@@ -388,20 +341,6 @@
     }
 
     /**
-     * @see org.apache.james.pop3server.POP3Session#getCommandName()
-     */
-    public String getCommandName() {
-        return curCommandName;
-    }
-
-    /**
-     * @see org.apache.james.pop3server.POP3Session#getCommandArgument()
-     */
-    public String getCommandArgument() {
-        return curCommandArgument;
-    }
-
-    /**
      * @see org.apache.james.pop3server.POP3Session#getConfigurationData()
      */
     public POP3HandlerConfigurationData getConfigurationData() {
@@ -499,5 +438,29 @@
 	public boolean isTLSStarted() {
 		return context.isSecure();
 	}
+
+	/**
+	 * @see org.apache.james.pop3server.POP3Session#writePOP3Response(org.apache.james.pop3server.POP3Response)
+	 */
+    public void writePOP3Response(POP3Response response) {
+        // Write a single-line or multiline response
+        if (response != null) {
+            if (response.getRawLine() != null) {
+                context.writeLoggedFlushedResponse(response.getRawLine());
+            } 
+            
+            List<CharSequence> responseList = response.getLines();
+            if (responseList != null) {
+                for (int k = 0; k < responseList.size(); k++) {
+                    final CharSequence line = responseList.get(k);
+                    context.writeLoggedFlushedResponse(line.toString());
+                }
+            }
+           
+            if (response.isEndSession()) {
+                sessionEnded = true;
+            }
+        }
+    }
 	
 }

Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3HandlerChain.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3HandlerChain.java?rev=820662&r1=820661&r2=820662&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3HandlerChain.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3HandlerChain.java Thu Oct  1 14:05:52 2009
@@ -21,256 +21,44 @@
 
 package org.apache.james.pop3server;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.james.socket.AbstractHandlerChain;
 import org.apache.james.socket.LogEnabled;
 
 /**
   * The POP3HandlerChain is per service object providing access
   * ConnectHandlers, Commandhandlers and message handlers
   */
-public class POP3HandlerChain implements Configurable, Serviceable, Initializable {
+public class POP3HandlerChain extends AbstractHandlerChain implements LogEnabled{
 
     /** This log is the fall back shared by all instances */
     private static final Log FALLBACK_LOG = LogFactory.getLog(POP3HandlerChain.class);
     
     /** Non context specific log should only be used when no context specific log is available */
-    private Log log = FALLBACK_LOG;
+    private Log log  = FALLBACK_LOG;
     
-    private Map<String, List<CommandHandler>> commandHandlerMap = new HashMap<String, List<CommandHandler>>();
-    private List<ConnectHandler> connectHandlers = new ArrayList<ConnectHandler>();
-    private List<CapaCapability> capaList = new ArrayList<CapaCapability>();
-    private final CommandHandler unknownHandler = new UnknownCmdHandler();
-    private ServiceManager serviceManager;
-
-    private final static String[] mandatoryCommands = { "USER" , "PASS", "LIST"};
 
     /**
-     * Sets the service log.
-     * Where available, a context sensitive log should be used.
-     * @param Log not null
+     * @see org.apache.james.socket.LogEnabled#setLog(org.apache.commons.logging.Log)
      */
     public void setLog(Log log) {
         this.log = log;
     }
-    
-    public void service(ServiceManager serviceManager) throws ServiceException {
-        this.serviceManager = serviceManager;
-    }
-
-
-    /**
-     * loads the various handlers from the configuration
-     * @param configuration configuration under handlerchain node
-     */
-    public void configure(Configuration configuration) throws  ConfigurationException {
-        addToMap(unknownHandler);
-        if(configuration == null || configuration.getChildren("handler") == null || configuration.getChildren("handler").length == 0) {
-            configuration = createDefaultConfiguration();
-        }
-        if(configuration != null) {
-            Configuration[] children = configuration.getChildren("handler");
-            if ( children != null ) {
-                configureHandlers(children);
-            }
-        }
-        verifyCommandConfiguration();
-    }
-
-    private void verifyCommandConfiguration() throws ConfigurationException {
-        //the size must be greater than 1 because we added UnknownCmdHandler to the map
-        if(commandHandlerMap.size() < 2) {
-            if (log.isErrorEnabled()) {
-                log.error("No commandhandlers configured");
-            }
-            throw new ConfigurationException("No commandhandlers configured");
-        } else {
-            boolean found = true;
-            for (int i = 0; i < mandatoryCommands.length; i++) {
-                if(!commandHandlerMap.containsKey(mandatoryCommands[i])) {
-                    if (log.isErrorEnabled()) {
-                        log.error("No commandhandlers configured for the command:" + mandatoryCommands[i]);
-                    }
-                    found = false;
-                    break;
-                }
-            }
-
-            if(!found) {
-                throw new ConfigurationException("No commandhandlers configured for mandatory commands");
-            }
-        }
-    }
-
-    private void configureHandlers(Configuration[] children)
-            throws ConfigurationException {
-        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-        for ( int i = 0 ; i < children.length ; i++ ) {
-            String className = children[i].getAttribute("class");
-            if(className != null) {
-                //load the handler
-                try {
-                    Object handler = classLoader.loadClass(className).newInstance();
-                    
-                    if (handler instanceof LogEnabled) {
-                        ((LogEnabled) handler).setLog(log);
-                    }
-
-                    //servicing the handler
-                    ContainerUtil.service(handler,serviceManager);
-
-                    //configure the handler
-                    ContainerUtil.configure(handler,children[i]);
-
-                    //if it is a connect handler add it to list of connect handlers
-                    if(handler instanceof ConnectHandler) {
-                        connectHandlers.add((ConnectHandler)handler);
-                        if (log.isInfoEnabled()) {
-                            log.info("Added ConnectHandler: " + className);
-                        }
-                    }
-
-                    //if it is a command handler add it to the map with key as command name
-                    if(handler instanceof CommandHandler) {
-                        addToMap((CommandHandler)handler);
-                        if (log.isInfoEnabled()) {
-                            log.info("Added Commandhandler: " + className);
-                        }
-                    }
-                    
-                    if (handler instanceof CapaCapability) {
-                    	capaList.add((CapaCapability) handler);
-                    }
-
-                } catch (ClassNotFoundException ex) {
-                   if (log.isErrorEnabled()) {
-                       log.error("Failed to add Commandhandler: " + className,ex);
-                   }
-                } catch (IllegalAccessException ex) {
-                   if (log.isErrorEnabled()) {
-                       log.error("Failed to add Commandhandler: " + className,ex);
-                   }
-                } catch (InstantiationException ex) {
-                   if (log.isErrorEnabled()) {
-                       log.error("Failed to add Commandhandler: " + className,ex);
-                   }
-                } catch (ServiceException e) {
-                    if (log.isErrorEnabled()) {
-                        log.error("Failed to service Commandhandler: " + className,e);
-                    }
-                }
-            }
-        }
-    }
-
-    @SuppressWarnings("unchecked")
-    private Configuration createDefaultConfiguration() {
-        Configuration configuration;
-        configuration = new DefaultConfiguration("handlerchain");
-        List<String> defaultCommands = new ArrayList<String>();
-        defaultCommands.add(CapaCmdHandler.class.getName());
-        defaultCommands.add(UserCmdHandler.class.getName());
-        defaultCommands.add(PassCmdHandler.class.getName());
-        defaultCommands.add(StlsCmdHandler.class.getName());
-        defaultCommands.add(ListCmdHandler.class.getName());
-        defaultCommands.add(UidlCmdHandler.class.getName());
-        defaultCommands.add(RsetCmdHandler.class.getName());
-        defaultCommands.add(DeleCmdHandler.class.getName());
-        defaultCommands.add(NoopCmdHandler.class.getName());
-        defaultCommands.add(RetrCmdHandler.class.getName());
-        defaultCommands.add(TopCmdHandler.class.getName());
-        defaultCommands.add(StatCmdHandler.class.getName());
-        defaultCommands.add(QuitCmdHandler.class.getName());
-        for (int i = 0; i < defaultCommands.size(); i++) {
-            String className = defaultCommands.get(i);
-            DefaultConfiguration cmdConf = new DefaultConfiguration("handler");
-            cmdConf.setAttribute("class",className);
-            ((DefaultConfiguration) configuration).addChild(cmdConf);
-        }
-        return configuration;
-    }
 
-    /**
-     * Add it to map (key as command name, value is an array list of commandhandlers)
-     *
-     * @param commandName the command name which will be key
-     * @param cmdHandler The commandhandler object
-     */
-    private void addToMap(CommandHandler cmdHandler) {
-    	List<String> cmds = cmdHandler.getCommands();
-    	for (int i = 0 ; i< cmds.size(); i++) {
-    		String commandName = cmds.get(i);
-    		List<CommandHandler> handlers = commandHandlerMap.get(commandName);
-    		if(handlers == null) {
-    			handlers = new ArrayList<CommandHandler>();
-    			commandHandlerMap.put(commandName, handlers);
-       	 	}
-    		handlers.add(cmdHandler);
-    	}
-    }
 
     /**
-     * Returns all the configured commandhandlers for the specified command
-     *
-     * @param command the command name which will be key
-     * @return List of commandhandlers
+     * @see org.apache.james.socket.AbstractHandlerChain#getLog()
      */
-    List<CommandHandler> getCommandHandlers(String command) {
-        if (command == null) {
-            return null;
-        }
-        if (log.isDebugEnabled()) {
-            log.debug("Lookup command handler for command: " + command);
-        }
-        List<CommandHandler> handlers =  commandHandlerMap.get(command);
-        if(handlers == null) {
-            handlers = commandHandlerMap.get(UnknownCmdHandler.UNKNOWN_COMMAND);
-        }
-
-        return handlers;
+    protected Log getLog() {
+        return log;
     }
 
     /**
-     * Returns all the configured connect handlers
-     *
-     * @return List of connect handlers
+     * @see org.apache.james.socket.AbstractHandlerChain#getCoreCmdHandlerLoader()
      */
-    List<ConnectHandler> getConnectHandlers() {
-        return connectHandlers;
+    protected Class<?> getCoreCmdHandlerLoader() {
+        return CoreCmdHandlerLoader.class;
     }
 
-    /**
-     * @see org.apache.avalon.framework.activity.Initializable#initialize()
-     */
-	public void initialize() throws Exception {
-		// wire the capa stuff
-		List<CommandHandler> handlers = getCommandHandlers(CapaCmdHandler.COMMAND_NAME);
-		if (handlers != null) {
-			for (int i = 0; i < handlers.size(); i++) {
-				CommandHandler cHandler = handlers.get(i);
-			
-				// TODO: Maybe an interface ?
-				if (cHandler instanceof CapaCmdHandler) {
-					for (int a =0; a < capaList.size(); a++) {
-						((CapaCmdHandler) cHandler).wireHandler(capaList.get(a));
-					}
-				}
-			}
-		}
-	}
-
 }

Added: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Response.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Response.java?rev=820662&view=auto
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Response.java (added)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Response.java Thu Oct  1 14:05:52 2009
@@ -0,0 +1,134 @@
+/****************************************************************
+ * 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.pop3server;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Contains an SMTP result
+ */
+public class POP3Response {
+
+
+    // POP3 response prefixes
+    /** OK response.  Requested content will follow */
+    public final static String OK_RESPONSE = "+OK";
+    
+    /** 
+     * Error response.  
+     * Requested content will not be provided.  
+     * This prefix is followed by a more detailed error message.
+     */
+    public final static String ERR_RESPONSE = "-ERR";  
+    
+    private String retCode = null;
+    private List<CharSequence> lines = null;
+    private String rawLine = null;
+    private boolean endSession = false;
+    
+    
+    /**
+     * Construct a new POP3Response. The given code and description can not be null, if null an IllegalArgumentException
+     * get thrown
+     * 
+     * @param code the returnCode
+     * @param description the description 
+     */
+    public POP3Response(String code, CharSequence description) {
+        if (code == null) throw new IllegalArgumentException("POP3Response code can not be null");
+    
+        this.setRetCode(code);
+        if (description != null) {
+            this.rawLine = code + " " + description;
+
+        } else {
+            this.rawLine = code;
+        }
+    }
+    
+    public POP3Response(String code) {
+        this(code,null);
+    }
+    
+    /**
+     * Append the responseLine to the SMTPResponse
+     * 
+     * @param line the responseLine to append
+     */
+    public void appendLine(CharSequence line) {
+        if (lines == null) {
+            lines = new LinkedList<CharSequence>();
+        }
+        lines.add(line);
+    }
+
+    public String getRetCode() {
+        return retCode;
+    }
+
+
+    public void setRetCode(String retCode) {
+        this.retCode = retCode;
+    }
+
+    /**
+     * Return a List of all responseLines stored in this POP3Response
+     * 
+     * @return all responseLines
+     */
+    public List<CharSequence> getLines() {
+        return lines;
+    }
+
+    /**
+     * Return the raw representation of the Stored POP3Response
+     * 
+     * @return rawLine the raw POP3Response
+     */
+    public String getRawLine() {
+        return rawLine;
+    }
+
+    /**
+     * Return true if the session is ended
+     * 
+     * @return true if session is ended
+     */
+    public boolean isEndSession() {
+        return endSession;
+    }
+
+    /**
+     * Set to true to end the session
+     * 
+     * @param endSession
+     */
+    public void setEndSession(boolean endSession) {
+        this.endSession = endSession;
+    }
+
+    /**
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        return getRetCode() + " " + getLines();
+    }
+}

Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java?rev=820662&r1=820661&r2=820662&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java Thu Oct  1 14:05:52 2009
@@ -21,16 +21,19 @@
 
 package org.apache.james.pop3server;
 
+import javax.annotation.Resource;
+
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.commons.logging.impl.AvalonLogger;
+import org.apache.james.api.kernel.LoaderService;
 import org.apache.james.api.user.UsersRepository;
 import org.apache.james.services.MailServer;
 import org.apache.james.socket.AbstractProtocolServer;
 import org.apache.james.socket.ProtocolHandler;
+import org.apache.james.socket.configuration.JamesConfiguration;
 
 /**
  * <p>Accepts POP3 connections on a server socket and dispatches them to POP3Handlers.</p>
@@ -45,7 +48,7 @@
      * The handler chain - POP3handlers can lookup handlerchain to obtain
      * Command handlers , Message handlers and connection handlers
      */
-    POP3HandlerChain handlerChain = new POP3HandlerChain();
+    private POP3HandlerChain handlerChain;
 
     /**
      * The internal mail server service
@@ -70,7 +73,10 @@
     private POP3HandlerConfigurationData theConfigData
         = new POP3HandlerConfigurationDataImpl();
 
-    private ServiceManager serviceManager;
+
+    private LoaderService loader;
+
+    private Configuration handlerConfiguration;
 
     public void setMailServer(MailServer mailServer) {
         this.mailServer = mailServer;
@@ -79,14 +85,30 @@
     public void setUsers(UsersRepository users) {
         this.users = users;
     }
+    /**
+     * Gets the current instance loader.
+     * @return the loader
+     */
+    public final LoaderService getLoader() {
+        return loader;
+    }
+
+    /**
+     * Sets the loader to be used for instances.
+     * @param loader the loader to set, not null
+     */
+    @Resource(name="org.apache.james.LoaderService")
+    public final void setLoader(LoaderService loader) {
+        this.loader = loader;
+    }
 
+    
     /**
      * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager) 
      */
     public void service( final ServiceManager componentManager )
         throws ServiceException {
         super.service(componentManager);
-        serviceManager = componentManager;
         MailServer mailServer = (MailServer)componentManager.lookup( MailServer.ROLE );
         setMailServer(mailServer);
         UsersRepository users = (UsersRepository)componentManager.lookup( UsersRepository.ROLE );
@@ -104,36 +126,26 @@
             if (getLogger().isInfoEnabled()) {
                 getLogger().info("The idle timeout will be reset every " + lengthReset + " bytes.");
             }
-            prepareHandlerChain();
             
-            //read from the XML configuration and create and configure each of the handlers
-            ContainerUtil.configure(handlerChain,handlerConfiguration.getChild("handlerchain"));
-            try {
-                ContainerUtil.initialize(handlerChain);
-
-            } catch (Exception e) {
-                getLogger().error("Failed to init handlerChain",e);
-                throw new ConfigurationException("Failed to init handlerChain");
-    		}
-
+            this.handlerConfiguration = handlerConfiguration;
         }
     }
     
+    private void prepareHandlerChain() throws Exception {
 
-    private void prepareHandlerChain() throws ConfigurationException {
+        handlerChain = loader.load(POP3HandlerChain.class);
+        
         //set the logger
         handlerChain.setLog(new AvalonLogger(getLogger()));
+        
+        //read from the XML configuration and create and configure each of the handlers
+        handlerChain.configure(new JamesConfiguration(handlerConfiguration.getChild("handlerchain")));
+    }
 
-        try {
-            ContainerUtil.service(handlerChain,serviceManager);
-        } catch (ServiceException e) {
-            if (getLogger().isErrorEnabled()) {
-                getLogger().error("Failed to service handlerChain",e);
-            }
-            throw new ConfigurationException("Failed to service handlerChain");
-        }
+    @Override
+    protected void prepareInit() throws Exception {
+        prepareHandlerChain();
     }
-    
 
     /**
      * @see org.apache.james.socket.AbstractProtocolServer#getDefaultPort()

Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Session.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Session.java?rev=820662&r1=820661&r2=820662&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Session.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Session.java Thu Oct  1 14:05:52 2009
@@ -22,11 +22,9 @@
 package org.apache.james.pop3server;
 
 
-import java.io.IOException;
 import java.io.OutputStream;
 import java.util.List;
 
-import org.apache.commons.logging.Log;
 import org.apache.james.services.MailRepository;
 import org.apache.james.socket.TLSSupportedSession;
 import org.apache.james.socket.Watchdog;
@@ -40,40 +38,12 @@
 public interface POP3Session extends TLSSupportedSession{
 
     /**
-     * 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;
-
-    /**
      * Clears the response buffer, returning the String of characters in the buffer.
      *
      * @return the data in the response buffer
      */
     String clearResponseBuffer();
 
-    /**
-     * Returns currently process command name
-     *
-     * @return current command name
-     */
-    String getCommandName();
-
-    /**
-     * Returns currently process command argument
-     *
-     * @return current command argument
-     */
-    String getCommandArgument();
 
     /**
      * Returns host name of the client
@@ -90,12 +60,6 @@
     String getRemoteIPAddress();
 
     /**
-     * this makes the session to close
-     *
-     */
-    void endSession();
-
-    /**
      * Returns the session status
      *
      * @return if the session is open or closed
@@ -194,10 +158,10 @@
      */
     OutputStream getOutputStream();
 
-    /**
-     * Gets the context sensitive logger for this session.
-     * @return context sensitive log, not null
-     */
-    Log getLogger();
+    void writePOP3Response(POP3Response response);
+
+
+    void writeResponse(String string);
+
 }
 

Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/PassCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/PassCmdHandler.java?rev=820662&r1=820661&r2=820662&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/PassCmdHandler.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/PassCmdHandler.java Thu Oct  1 14:05:52 2009
@@ -22,6 +22,7 @@
 package org.apache.james.pop3server;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 import org.apache.james.services.MailRepository;
@@ -33,23 +34,17 @@
 public class PassCmdHandler implements CommandHandler {
 
 	private final static String COMMAND_NAME ="PASS";
-    /**
-     * @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
-     */
-    public void onCommand(POP3Session session) {
-        doPASS(session,session.getCommandArgument());
-    }
 
-    /**
+	/**
      * Handler method called upon receipt of a PASS command.
      * Reads in and validates the password.
      *
-     * @param argument the first argument parsed by the parseCommand method
-     */
-    private void doPASS(POP3Session session,String argument) {
-        String responseString = null;
-        if (session.getHandlerState() == POP3Handler.AUTHENTICATION_USERSET && argument != null) {
-            String passArg = argument;
+  	 * @see org.apache.james.pop3server.CommandHandler#onCommand(org.apache.james.pop3server.POP3Session, java.lang.String, java.lang.String)
+	 */
+    public POP3Response onCommand(POP3Session session, String command, String parameters) {
+        POP3Response response = null;
+        if (session.getHandlerState() == POP3Handler.AUTHENTICATION_USERSET && parameters != null) {
+            String passArg = parameters;
             if (session.getConfigurationData().getUsersRepository().test(session.getUser(), passArg)) {
                 try {
                     MailRepository inbox = session.getConfigurationData().getMailServer().getUserInbox(session.getUser());
@@ -64,37 +59,36 @@
                     
                     StringBuilder responseBuffer =
                         new StringBuilder(64)
-                                .append(POP3Handler.OK_RESPONSE)
-                                .append(" Welcome ")
+                                .append("Welcome ")
                                 .append(session.getUser());
-                    responseString = responseBuffer.toString();
+                    response = new POP3Response(POP3Response.OK_RESPONSE,responseBuffer.toString());
                     session.setHandlerState(POP3Handler.TRANSACTION);
-                    session.writeResponse(responseString);
                 } catch (RuntimeException e) {
                     session.getLogger().error("Unexpected error accessing mailbox for "+session.getUser(),e);
-                    responseString = POP3Handler.ERR_RESPONSE + " Unexpected error accessing mailbox";
+                    response = new POP3Response(POP3Response.ERR_RESPONSE,"Unexpected error accessing mailbox");
                     session.setHandlerState(POP3Handler.AUTHENTICATION_READY);
-                    session.writeResponse(responseString);
                 }
             } else {
-                responseString = POP3Handler.ERR_RESPONSE + " Authentication failed.";
+                response = new POP3Response(POP3Response.ERR_RESPONSE, "Authentication failed.");
+
                 session.setHandlerState(POP3Handler.AUTHENTICATION_READY);
-                session.writeResponse(responseString);
             }
         } else {
-            responseString = POP3Handler.ERR_RESPONSE;
-            session.writeResponse(responseString);
+            response = new POP3Response(POP3Response.ERR_RESPONSE);
         }
+        return response;    
     }
 
+  
+
     /**
-     * @see org.apache.james.pop3server.CommandHandler#getCommands()
+     * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
      */
-	public List<String> getCommands() {
-		List<String> commands = new ArrayList<String>();
-		commands.add(COMMAND_NAME);
-		return commands;
-	}
+    public Collection<String> getImplCommands() {
+        List<String> commands = new ArrayList<String>();
+        commands.add(COMMAND_NAME);
+        return commands;
+    }
 
 
 }

Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/QuitCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/QuitCmdHandler.java?rev=820662&r1=820661&r2=820662&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/QuitCmdHandler.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/QuitCmdHandler.java Thu Oct  1 14:05:52 2009
@@ -22,6 +22,7 @@
 package org.apache.james.pop3server;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 import org.apache.commons.collections.ListUtils;
@@ -33,27 +34,20 @@
 public class QuitCmdHandler implements CommandHandler {
 	private final static String COMMAND_NAME = "QUIT";
 
-    /**
-     * @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
-     */
-    public void onCommand(POP3Session session) {
-        doQUIT(session,session.getCommandArgument());
-    }
 
-    /**
+	/**
      * Handler method called upon receipt of a QUIT command.
      * This method handles cleanup of the POP3Handler state.
      *
-     * @param argument the first argument parsed by the parseCommand method
-     */
+	 * @see org.apache.james.pop3server.CommandHandler#onCommand(org.apache.james.pop3server.POP3Session, java.lang.String, java.lang.String)
+	 */
     @SuppressWarnings("unchecked")
-    private void doQUIT(POP3Session session,String argument) {
-        String responseString = null;
+    public POP3Response onCommand(POP3Session session, String command, String parameters) {
+        POP3Response response = null;
         if (session.getHandlerState() == POP3Handler.AUTHENTICATION_READY ||  session.getHandlerState() == POP3Handler.AUTHENTICATION_USERSET) {
-            responseString = POP3Handler.OK_RESPONSE + " Apache James POP3 Server signing off.";
-            session.writeResponse(responseString);
-            session.endSession();
-            return;
+            response = new POP3Response(POP3Response.OK_RESPONSE,"Apache James POP3 Server signing off.");
+            response.setEndSession(true);
+            return response;
         }
         List<Mail> toBeRemoved =  ListUtils.subtract(session.getBackupUserMailbox(), session.getUserMailbox());
         try {
@@ -62,23 +56,23 @@
             //    Mail mc = (Mail) it.next();
             //    userInbox.remove(mc.getName());
             //}
-            responseString = POP3Handler.OK_RESPONSE + " Apache James POP3 Server signing off.";
-            session.writeResponse(responseString);
+            response = new POP3Response(POP3Response.OK_RESPONSE ,"Apache James POP3 Server signing off.");
         } catch (Exception ex) {
-            responseString = POP3Handler.ERR_RESPONSE + " Some deleted messages were not removed";
-            session.writeResponse(responseString);
+            response = new POP3Response(POP3Response.ERR_RESPONSE,"Some deleted messages were not removed");
             session.getLogger().error("Some deleted messages were not removed: " + ex.getMessage());
         }
-        session.endSession();
+        response.setEndSession(true);
+        return response;    
     }
+   
     
-    /**
-     * @see org.apache.james.pop3server.CommandHandler#getCommands()
-     */
-	public List<String> getCommands() {
-		List<String> commands = new ArrayList<String>();
-		commands.add(COMMAND_NAME);
-		return commands;
-	}
+	/**
+	 * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+	 */
+    public Collection<String> getImplCommands() {
+        List<String> commands = new ArrayList<String>();
+        commands.add(COMMAND_NAME);
+        return commands;
+    }
 
 }

Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/RetrCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/RetrCmdHandler.java?rev=820662&r1=820661&r2=820662&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/RetrCmdHandler.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/RetrCmdHandler.java Thu Oct  1 14:05:52 2009
@@ -30,6 +30,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 /**
@@ -39,36 +40,29 @@
 
 	private final static String COMMAND_NAME = "RETR";
 
-    /**
-     * @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
-     */
-    public void onCommand(POP3Session session) {
-        doRETR(session,session.getCommandArgument());
-    }
 
     /**
      * Handler method called upon receipt of a RETR command.
      * This command retrieves a particular mail message from the
      * mailbox.
      *
-     * @param argument the first argument parsed by the parseCommand method
-     */
-    private void doRETR(POP3Session session,String argument) {
-        String responseString = null;
+	 * @see org.apache.james.pop3server.CommandHandler#onCommand(org.apache.james.pop3server.POP3Session, java.lang.String, java.lang.String)
+	 */
+    public POP3Response onCommand(POP3Session session, String command, String parameters) {
+        POP3Response response = null;
         if (session.getHandlerState() == POP3Handler.TRANSACTION) {
             int num = 0;
             try {
-                num = Integer.parseInt(argument.trim());
+                num = Integer.parseInt(parameters.trim());
             } catch (Exception e) {
-                responseString = POP3Handler.ERR_RESPONSE + " Usage: RETR [mail number]";
-                session.writeResponse(responseString);
-                return;
+                response = new POP3Response(POP3Response.ERR_RESPONSE, "Usage: RETR [mail number]");
+                return response;
             }
             try {
                 Mail mc = session.getUserMailbox().get(num);
                 if (mc != POP3Handler.DELETED) {
-                    responseString = POP3Handler.OK_RESPONSE + " Message follows";
-                    session.writeResponse(responseString);
+                    response = new POP3Response(POP3Response.OK_RESPONSE, "Message follows");
+                    session.writePOP3Response(response);
                     try {
                         ExtraDotOutputStream edouts =
                                 new ExtraDotOutputStream(session.getOutputStream());
@@ -83,43 +77,37 @@
                         session.writeResponse(".");
                     }
                 } else {
+                    
                     StringBuilder responseBuffer =
                         new StringBuilder(64)
-                                .append(POP3Handler.ERR_RESPONSE)
-                                .append(" Message (")
+                                .append("Message (")
                                 .append(num)
                                 .append(") already deleted.");
-                    responseString = responseBuffer.toString();
-                    session.writeResponse(responseString);
+                    response = new POP3Response(POP3Response.ERR_RESPONSE,responseBuffer.toString());
                 }
             } catch (IOException ioe) {
-                responseString = POP3Handler.ERR_RESPONSE + " Error while retrieving message.";
-                session.writeResponse(responseString);
+                response = new POP3Response(POP3Response.ERR_RESPONSE,"Error while retrieving message.");
             } catch (MessagingException me) {
-                responseString = POP3Handler.ERR_RESPONSE + " Error while retrieving message.";
-                session.writeResponse(responseString);
+                response = new POP3Response(POP3Response.ERR_RESPONSE,"Error while retrieving message.");
             } catch (IndexOutOfBoundsException iob) {
                 StringBuilder responseBuffer =
                     new StringBuilder(64)
-                            .append(POP3Handler.ERR_RESPONSE)
-                            .append(" Message (")
+                            .append("Message (")
                             .append(num)
                             .append(") does not exist.");
-                responseString = responseBuffer.toString();
-                session.writeResponse(responseString);
+                response = new POP3Response(POP3Response.ERR_RESPONSE,responseBuffer.toString());
             }
         } else {
-            responseString = POP3Handler.ERR_RESPONSE;
-            session.writeResponse(responseString);
+            response = new POP3Response(POP3Response.ERR_RESPONSE);
         }
+        return response;
+    }
+
+
+    public Collection<String> getImplCommands() {
+        List<String> commands = new ArrayList<String>();
+        commands.add(COMMAND_NAME);
+        return commands;
     }
 
-    /**
-     * @see org.apache.james.pop3server.CommandHandler#getCommands()
-     */
-	public List<String> getCommands() {
-		List<String> commands = new ArrayList<String>();
-		commands.add(COMMAND_NAME);
-		return commands;
-	}
 }

Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/RsetCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/RsetCmdHandler.java?rev=820662&r1=820661&r2=820662&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/RsetCmdHandler.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/RsetCmdHandler.java Thu Oct  1 14:05:52 2009
@@ -22,6 +22,7 @@
 package org.apache.james.pop3server;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 
@@ -36,30 +37,24 @@
 public class RsetCmdHandler implements CommandHandler {
 	private final static String COMMAND_NAME = "RSET";
 
-    /**
-     * @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
-     */
-    public void onCommand(POP3Session session) {
-        doRSET(session,session.getCommandArgument());
-    }
-
-    /**
+	/**
      * Handler method called upon receipt of a RSET command.
      * Calls stat() to reset the mailbox.
      *
-     * @param argument the first argument parsed by the parseCommand method
-     */
-    private void doRSET(POP3Session session,String argument) {
-        String responseString = null;
+  	 * @see org.apache.james.pop3server.CommandHandler#onCommand(org.apache.james.pop3server.POP3Session, java.lang.String, java.lang.String)
+	 */
+    public POP3Response onCommand(POP3Session session, String command, String parameters) {
+        POP3Response response = null;
         if (session.getHandlerState() == POP3Handler.TRANSACTION) {
             stat(session);
-            responseString = POP3Handler.OK_RESPONSE;
+            response = new POP3Response(POP3Response.OK_RESPONSE);
         } else {
-            responseString = POP3Handler.ERR_RESPONSE;
+            response = new POP3Response(POP3Response.ERR_RESPONSE);
         }
-        session.writeResponse(responseString);
+        return response;    
     }
 
+   
 
     /**
      * Implements a "stat".  If the handler is currently in
@@ -94,13 +89,14 @@
             session.setBackupUserMailbox((List<Mail>) userMailbox.clone());
         }
     }
-    
+
     /**
-     * @see org.apache.james.pop3server.CommandHandler#getCommands()
+     * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
      */
-	public List<String> getCommands() {
-		List<String> commands = new ArrayList<String>();
-		commands.add(COMMAND_NAME);
-		return commands;
-	}
+    public Collection<String> getImplCommands() {
+        List<String> commands = new ArrayList<String>();
+        commands.add(COMMAND_NAME);
+        return commands;
+    }
+    
 }



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


Mime
View raw message