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 no...@apache.org on 2009/09/30 13:02:37 UTC
svn commit: r820244 - in /james/server/trunk/pop3server-function/src:
main/java/org/apache/james/pop3server/ test/java/org/apache/james/pop3server/
Author: norman
Date: Wed Sep 30 11:02:36 2009
New Revision: 820244
URL: http://svn.apache.org/viewvc?rev=820244&view=rev
Log:
Refactor POP3Server to support CAPA command (JAMES-925)
Added:
james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CapaCapability.java
james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CapaCmdHandler.java
Modified:
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/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
Added: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CapaCapability.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CapaCapability.java?rev=820244&view=auto
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CapaCapability.java (added)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CapaCapability.java Wed Sep 30 11:02:36 2009
@@ -0,0 +1,39 @@
+/****************************************************************
+ * 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.List;
+
+/**
+ * A handler which support the POP$ Extension Mechanism should implement this interface
+ *
+ *
+ */
+public interface CapaCapability {
+
+ /**
+ * Return a List of responses which should get returned when a client issue the CAPA command
+ *
+ * @param session
+ * @return list
+ */
+ public List<String> getImplementedCapabilities(POP3Session session);
+}
Added: 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=820244&view=auto
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CapaCmdHandler.java (added)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/CapaCmdHandler.java Wed Sep 30 11:02:36 2009
@@ -0,0 +1,63 @@
+/****************************************************************
+ * 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.List;
+
+public class CapaCmdHandler implements CommandHandler{
+ 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;
+ }
+
+ /**
+ * @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");
+
+ for (int i = 0; i < caps.size(); i++) {
+ List<String> cList = caps.get(i).getImplementedCapabilities(session);
+ for (int a = 0; a < cList.size(); a++) {
+ session.writeResponse(cList.get(a));
+ }
+ }
+ session.writeResponse(".");
+ }
+
+ /**
+ * Wire the handler
+ *
+ * @param capHandler
+ */
+ public void wireHandler(CapaCapability capHandler) {
+ caps.add(capHandler);
+ }
+
+}
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=820244&r1=820243&r2=820244&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 Wed Sep 30 11:02:36 2009
@@ -21,6 +21,8 @@
package org.apache.james.pop3server;
+import java.util.List;
+
/**
* Custom command handlers must implement this interface
* The command handlers will be Server wide common to all the POP3Handlers,
@@ -33,4 +35,10 @@
**/
void onCommand(POP3Session session);
+ /**
+ * Return list of implemented commands
+ *
+ * @return commands
+ */
+ List<String> getCommands();
}
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=820244&r1=820243&r2=820244&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 Wed Sep 30 11:02:36 2009
@@ -21,6 +21,9 @@
package org.apache.james.pop3server;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.mailet.Mail;
@@ -28,6 +31,7 @@
* Handles DELE command
*/
public class DeleCmdHandler implements CommandHandler {
+ private final static String COMMAND_NAME = "DELE";
/**
* @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
@@ -88,5 +92,14 @@
}
}
+ /**
+ * @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/ListCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/ListCmdHandler.java?rev=820244&r1=820243&r2=820244&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 Wed Sep 30 11:02:36 2009
@@ -21,6 +21,9 @@
package org.apache.james.pop3server;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.mail.MessagingException;
import org.apache.mailet.Mail;
@@ -129,4 +132,13 @@
}
}
+ /**
+ * @see org.apache.james.pop3server.CommandHandler#getCommands()
+ */
+ public List<String> getCommands() {
+ 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=820244&r1=820243&r2=820244&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 Wed Sep 30 11:02:36 2009
@@ -21,11 +21,14 @@
package org.apache.james.pop3server;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Handles NOOP command
*/
public class NoopCmdHandler implements CommandHandler {
-
+ private final static String COMMAND_NAME = "NOOP";
/**
* @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
*/
@@ -50,5 +53,14 @@
}
}
+ /**
+ * @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/POP3Handler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Handler.java?rev=820244&r1=820243&r2=820244&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 Wed Sep 30 11:02:36 2009
@@ -472,18 +472,30 @@
return context.getOutputStream();
}
+ /**
+ * @see org.apache.james.pop3server.POP3Session#getLogger()
+ */
public Log getLogger() {
return context.getLogger();
}
- public void secure() throws IOException {
+ /**
+ * @see org.apache.james.socket.TLSSupportedSession#startTLS()
+ */
+ public void startTLS() throws IOException {
context.secure();
}
+ /**
+ * @see org.apache.james.socket.TLSSupportedSession#isStartTLSSupported()
+ */
public boolean isStartTLSSupported() {
return getConfigurationData().isStartTLSSupported();
}
+ /**
+ * @see org.apache.james.socket.TLSSupportedSession#isTLSStarted()
+ */
public boolean isTLSStarted() {
return context.isSecure();
}
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=820244&r1=820243&r2=820244&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 Wed Sep 30 11:02:36 2009
@@ -22,13 +22,11 @@
package org.apache.james.pop3server;
import java.util.ArrayList;
-import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
-import java.util.Properties;
+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;
@@ -45,7 +43,7 @@
* The POP3HandlerChain is per service object providing access
* ConnectHandlers, Commandhandlers and message handlers
*/
-public class POP3HandlerChain implements Configurable, Serviceable {
+public class POP3HandlerChain implements Configurable, Serviceable, Initializable {
/** This log is the fall back shared by all instances */
private static final Log FALLBACK_LOG = LogFactory.getLog(POP3HandlerChain.class);
@@ -55,7 +53,7 @@
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;
@@ -80,7 +78,7 @@
* @param configuration configuration under handlerchain node
*/
public void configure(Configuration configuration) throws ConfigurationException {
- addToMap(UnknownCmdHandler.UNKNOWN_COMMAND, unknownHandler);
+ addToMap(unknownHandler);
if(configuration == null || configuration.getChildren("handler") == null || configuration.getChildren("handler").length == 0) {
configuration = createDefaultConfiguration();
}
@@ -148,13 +146,15 @@
//if it is a command handler add it to the map with key as command name
if(handler instanceof CommandHandler) {
- String commandName = children[i].getAttribute("command");
- commandName = commandName.toUpperCase(Locale.US);
- addToMap(commandName, (CommandHandler)handler);
+ 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()) {
@@ -181,25 +181,23 @@
private Configuration createDefaultConfiguration() {
Configuration configuration;
configuration = new DefaultConfiguration("handlerchain");
- Properties cmds = new Properties();
- cmds.setProperty("USER",UserCmdHandler.class.getName());
- cmds.setProperty("PASS",PassCmdHandler.class.getName());
- cmds.setProperty("STLS", StlsCmdHandler.class.getName());
- cmds.setProperty("LIST",ListCmdHandler.class.getName());
- cmds.setProperty("UIDL",UidlCmdHandler.class.getName());
- cmds.setProperty("RSET",RsetCmdHandler.class.getName());
- cmds.setProperty("DELE",DeleCmdHandler.class.getName());
- cmds.setProperty("NOOP",NoopCmdHandler.class.getName());
- cmds.setProperty("RETR",RetrCmdHandler.class.getName());
- cmds.setProperty("TOP" ,TopCmdHandler.class.getName());
- cmds.setProperty("STAT",StatCmdHandler.class.getName());
- cmds.setProperty("QUIT",QuitCmdHandler.class.getName());
- Enumeration e = cmds.keys();
- while (e.hasMoreElements()) {
- String cmdName = (String) e.nextElement();
- String className = cmds.getProperty(cmdName);
+ 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("command",cmdName);
cmdConf.setAttribute("class",className);
((DefaultConfiguration) configuration).addChild(cmdConf);
}
@@ -212,13 +210,17 @@
* @param commandName the command name which will be key
* @param cmdHandler The commandhandler object
*/
- private void addToMap(String commandName, CommandHandler cmdHandler) {
- List<CommandHandler> handlers = commandHandlerMap.get(commandName);
- if(handlers == null) {
- handlers = new ArrayList<CommandHandler>();
- commandHandlerMap.put(commandName, handlers);
- }
- handlers.add(cmdHandler);
+ 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);
+ }
}
/**
@@ -251,4 +253,24 @@
return connectHandlers;
}
+ /**
+ * @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));
+ }
+ }
+ }
+ }
+ }
+
}
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=820244&r1=820243&r2=820244&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 Wed Sep 30 11:02:36 2009
@@ -108,9 +108,17 @@
//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");
+ }
}
}
+
private void prepareHandlerChain() throws ConfigurationException {
//set the logger
@@ -125,6 +133,7 @@
throw new ConfigurationException("Failed to service handlerChain");
}
}
+
/**
* @see org.apache.james.socket.AbstractProtocolServer#getDefaultPort()
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=820244&r1=820243&r2=820244&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 Wed Sep 30 11:02:36 2009
@@ -21,6 +21,9 @@
package org.apache.james.pop3server;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.james.services.MailRepository;
import org.apache.james.util.POP3BeforeSMTPHelper;
@@ -29,6 +32,7 @@
*/
public class PassCmdHandler implements CommandHandler {
+ private final static String COMMAND_NAME ="PASS";
/**
* @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
*/
@@ -83,5 +87,14 @@
}
}
+ /**
+ * @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/QuitCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/QuitCmdHandler.java?rev=820244&r1=820243&r2=820244&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 Wed Sep 30 11:02:36 2009
@@ -21,6 +21,7 @@
package org.apache.james.pop3server;
+import java.util.ArrayList;
import java.util.List;
import org.apache.commons.collections.ListUtils;
@@ -30,6 +31,7 @@
* Handles QUIT command
*/
public class QuitCmdHandler implements CommandHandler {
+ private final static String COMMAND_NAME = "QUIT";
/**
* @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
@@ -69,6 +71,14 @@
}
session.endSession();
}
-
+
+ /**
+ * @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/RetrCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/RetrCmdHandler.java?rev=820244&r1=820243&r2=820244&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 Wed Sep 30 11:02:36 2009
@@ -29,12 +29,16 @@
import java.io.IOException;
import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
/**
* Handles RETR command
*/
public class RetrCmdHandler implements CommandHandler {
+ private final static String COMMAND_NAME = "RETR";
+
/**
* @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
*/
@@ -110,5 +114,12 @@
}
}
-
+ /**
+ * @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=820244&r1=820243&r2=820244&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 Wed Sep 30 11:02:36 2009
@@ -34,6 +34,7 @@
* Handles RSET command
*/
public class RsetCmdHandler implements CommandHandler {
+ private final static String COMMAND_NAME = "RSET";
/**
* @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
@@ -93,5 +94,13 @@
session.setBackupUserMailbox((List<Mail>) userMailbox.clone());
}
}
-
+
+ /**
+ * @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/StatCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/StatCmdHandler.java?rev=820244&r1=820243&r2=820244&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/StatCmdHandler.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/StatCmdHandler.java Wed Sep 30 11:02:36 2009
@@ -21,6 +21,9 @@
package org.apache.james.pop3server;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.mail.MessagingException;
import org.apache.mailet.Mail;
@@ -29,6 +32,7 @@
* Handles STAT command
*/
public class StatCmdHandler implements CommandHandler {
+ private final static String COMMAND_NAME = "STAT";
/**
* @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
@@ -74,6 +78,12 @@
session.writeResponse(responseString);
}
}
-
-
+ /**
+ * @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/StlsCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/StlsCmdHandler.java?rev=820244&r1=820243&r2=820244&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/StlsCmdHandler.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/StlsCmdHandler.java Wed Sep 30 11:02:36 2009
@@ -21,8 +21,11 @@
package org.apache.james.pop3server;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
-public class StlsCmdHandler implements CommandHandler{
+public class StlsCmdHandler implements CommandHandler, CapaCapability {
+ private final static String COMMAND_NAME = "STLS";
/**
* @see org.apache.james.pop3server.CommandHandler#onCommand(org.apache.james.pop3server.POP3Session)
@@ -32,7 +35,7 @@
if (session.isStartTLSSupported() && session.getHandlerState() == POP3Handler.TRANSACTION && session.isTLSStarted() == false) {
session.writeResponse(POP3Handler.OK_RESPONSE+ " Begin TLS negotiation");
try {
- session.secure();
+ session.startTLS();
} catch (IOException e) {
session.getLogger().info("Error while trying to secure connection",e);
session.endSession();
@@ -42,4 +45,24 @@
}
}
+ /**
+ * @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.pop3server.CapaCapability#getImplementedCapabilities(org.apache.james.pop3server.POP3Session)
+ */
+ public List<String> getImplementedCapabilities(POP3Session session) {
+ List<String> caps = new ArrayList<String>();
+ if (session.isStartTLSSupported() && session.getHandlerState() == POP3Handler.AUTHENTICATION_READY) {
+ caps.add(COMMAND_NAME);
+ return caps;
+ }
+ return caps;
+ }
}
Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/TopCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/TopCmdHandler.java?rev=820244&r1=820243&r2=820244&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/TopCmdHandler.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/TopCmdHandler.java Wed Sep 30 11:02:36 2009
@@ -25,7 +25,9 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
+import java.util.ArrayList;
import java.util.Enumeration;
+import java.util.List;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
@@ -37,7 +39,8 @@
/**
* Handles TOP command
*/
-public class TopCmdHandler implements CommandHandler {
+public class TopCmdHandler implements CommandHandler, CapaCapability {
+ private final static String COMMAND_NAME = "TOP";
/**
* @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
@@ -170,5 +173,25 @@
throw new MessagingException("No message set for this MailImpl.");
}
}
+
+ /**
+ * @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.pop3server.CapaCapability#getImplementedCapabilities(org.apache.james.pop3server.POP3Session)
+ */
+ public List<String> getImplementedCapabilities(POP3Session session) {
+ List<String> caps = new ArrayList<String>();
+ if (session.getHandlerState() == POP3Handler.TRANSACTION) {
+ caps.add(COMMAND_NAME);
+ return caps;
+ }
+ return caps;
+ }
}
Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/UidlCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/UidlCmdHandler.java?rev=820244&r1=820243&r2=820244&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/UidlCmdHandler.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/UidlCmdHandler.java Wed Sep 30 11:02:36 2009
@@ -21,12 +21,16 @@
package org.apache.james.pop3server;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.mailet.Mail;
/**
* Handles UIDL command
*/
-public class UidlCmdHandler implements CommandHandler {
+public class UidlCmdHandler implements CommandHandler, CapaCapability {
+ private final static String COMMAND_NAME = "UIDL";
/**
* @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
@@ -104,6 +108,25 @@
session.writeResponse(POP3Handler.ERR_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.pop3server.CapaCapability#getImplementedCapabilities(org.apache.james.pop3server.POP3Session)
+ */
+ public List<String> getImplementedCapabilities(POP3Session session) {
+ List<String> caps = new ArrayList<String>();
+ if (session.getHandlerState() == POP3Handler.TRANSACTION) {
+ caps.add(COMMAND_NAME);
+ return caps;
+ }
+ return caps;
+ }
}
Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/UnknownCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/UnknownCmdHandler.java?rev=820244&r1=820243&r2=820244&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/UnknownCmdHandler.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/UnknownCmdHandler.java Wed Sep 30 11:02:36 2009
@@ -21,11 +21,15 @@
package org.apache.james.pop3server;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Default command handler for handling unknown commands
*/
public class UnknownCmdHandler implements CommandHandler {
+ private final static String COMMAND_NAME = "UNKNOWN";
/**
* The name of the command handled by the command handler
@@ -42,4 +46,13 @@
session.writeResponse(POP3Handler.ERR_RESPONSE);
}
+ /**
+ * @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/UserCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/UserCmdHandler.java?rev=820244&r1=820243&r2=820244&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/UserCmdHandler.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/UserCmdHandler.java Wed Sep 30 11:02:36 2009
@@ -21,10 +21,15 @@
package org.apache.james.pop3server;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Handles NOOP command
*/
-public class UserCmdHandler implements CommandHandler {
+public class UserCmdHandler implements CommandHandler, CapaCapability {
+
+ private final static String COMMAND_NAME = "USER";
/**
* @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
@@ -51,5 +56,21 @@
session.writeResponse(responseString);
}
+ /**
+ * @see org.apache.james.pop3server.CapaCapability#getImplementedCapabilities(org.apache.james.pop3server.POP3Session)
+ */
+ public List<String> getImplementedCapabilities(POP3Session session) {
+ List<String> caps = new ArrayList<String>();
+ caps.add(COMMAND_NAME);
+ return caps;
+ }
+ /**
+ * @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/test/java/org/apache/james/pop3server/POP3ServerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/test/java/org/apache/james/pop3server/POP3ServerTest.java?rev=820244&r1=820243&r2=820244&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/test/java/org/apache/james/pop3server/POP3ServerTest.java (original)
+++ james/server/trunk/pop3server-function/src/test/java/org/apache/james/pop3server/POP3ServerTest.java Wed Sep 30 11:02:36 2009
@@ -25,6 +25,7 @@
import org.apache.avalon.framework.service.ServiceException;
import org.apache.commons.net.pop3.POP3Client;
import org.apache.commons.net.pop3.POP3MessageInfo;
+import org.apache.commons.net.pop3.POP3Reply;
import org.apache.james.api.dnsservice.AbstractDNSServer;
import org.apache.james.api.dnsservice.DNSService;
import org.apache.james.api.user.UsersRepository;
@@ -52,6 +53,8 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import junit.framework.TestCase;
@@ -82,6 +85,8 @@
m_pop3Server = new POP3Server();
ContainerUtil.enableLogging(m_pop3Server, new MockLogger());
ContainerUtil.service(m_pop3Server, setUpServiceManager());
+ ContainerUtil.initialize(m_pop3Server);
+
m_testConfiguration = new POP3TestConfiguration(m_pop3ListenerPort);
}
@@ -465,6 +470,38 @@
ContainerUtil.dispose(mockMailRepository);
}
+ public void testCapa() throws Exception {
+ finishSetUp(m_testConfiguration);
+
+ m_pop3Protocol = new POP3Client();
+ m_pop3Protocol.connect("127.0.0.1",m_pop3ListenerPort);
+
+ String pass = "password";
+ m_usersRepository.addUser("foo", pass);
+ InMemorySpoolRepository mockMailRepository = new InMemorySpoolRepository();
+ m_mailServer.setUserInbox("foo", mockMailRepository);
+
+ assertEquals(POP3Reply.OK, m_pop3Protocol.sendCommand("CAPA"));
+
+ m_pop3Protocol.getAdditionalReply();
+ m_pop3Protocol.getReplyString();
+ List<String> replies = Arrays.asList(m_pop3Protocol.getReplyStrings());
+
+ assertTrue("contains USER", replies.contains("USER"));
+
+ m_pop3Protocol.login("foo", pass);
+ assertEquals(POP3Reply.OK, m_pop3Protocol.sendCommand("CAPA"));
+
+ m_pop3Protocol.getAdditionalReply();
+ m_pop3Protocol.getReplyString();
+ replies = Arrays.asList(m_pop3Protocol.getReplyStrings());
+ assertTrue("contains USER", replies.contains("USER"));
+ assertTrue("contains UIDL", replies.contains("UIDL"));
+ assertTrue("contains TOP", replies.contains("TOP"));
+
+ ContainerUtil.dispose(mockMailRepository);
+
+ }
/*
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org