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 2010/01/14 18:57:42 UTC

svn commit: r899333 [2/2] - in /james/server/trunk: mina-socket-library/ mina-socket-library/src/main/java/org/apache/james/socket/mina/ mina-socket-library/src/main/java/org/apache/james/socket/mina/filter/ pop3server-function/ pop3server-function/src...

Added: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/AsyncPOP3Server.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/AsyncPOP3Server.java?rev=899333&view=auto
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/AsyncPOP3Server.java (added)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/AsyncPOP3Server.java Thu Jan 14 17:57:41 2010
@@ -0,0 +1,175 @@
+/****************************************************************
+ * 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.mina;
+
+import javax.annotation.Resource;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.configuration.SubnodeConfiguration;
+import org.apache.james.pop3server.POP3HandlerConfigurationData;
+import org.apache.james.pop3server.POP3ServerMBean;
+import org.apache.james.pop3server.core.CoreCmdHandlerLoader;
+import org.apache.james.pop3server.mina.filter.POP3ResponseFilter;
+import org.apache.james.pop3server.mina.filter.POP3ValidationFilter;
+import org.apache.james.socket.mina.AbstractAsyncServer;
+import org.apache.james.socket.shared.ProtocolHandlerChainImpl;
+import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
+import org.apache.mina.core.service.IoHandler;
+
+/**
+ * Async implementation of a POP3Server
+ * 
+ *
+ */
+public class AsyncPOP3Server extends AbstractAsyncServer implements POP3ServerMBean{
+
+    /**
+     * The number of bytes to read before resetting
+     * the connection timeout timer.  Defaults to
+     * 20 KB.
+     */
+    private int lengthReset = 20 * 1024;
+    
+    /**
+     * The configuration data to be passed to the handler
+     */
+    private POP3HandlerConfigurationData theConfigData
+        = new POP3HandlerConfigurationDataImpl();
+
+	private SubnodeConfiguration handlerConfiguration;
+
+	private ProtocolHandlerChainImpl handlerChain;
+
+
+	@Override
+	protected IoHandler createIoHandler() {
+		return new POP3IoHandler(handlerChain, theConfigData, getLogger(), getSslContextFactory());
+	}
+
+	 /**
+     * Prepare the handlerchain
+     * 
+     * @throws Exception
+     */
+    private void prepareHandlerChain() throws Exception {
+        //read from the XML configuration and create and configure each of the handlers
+        HierarchicalConfiguration handlerchainConfig = handlerConfiguration.configurationAt("handlerchain");
+        if (handlerchainConfig.getString("[@coreHandlersPackage]") == null)
+            handlerchainConfig.addProperty("[@coreHandlersPackage]", CoreCmdHandlerLoader.class.getName());
+        
+        handlerChain = getLoader().load(ProtocolHandlerChainImpl.class, getLogger(), handlerchainConfig);
+        handlerChain.configure(handlerchainConfig);
+        
+    }
+
+
+    /**
+     * @see org.apache.james.socket.mina.AbstractAsyncServer#preInit()
+     */
+    protected void preInit() throws Exception {
+        prepareHandlerChain();
+    }
+    
+	@Override
+	protected int getDefaultPort() {
+		return 110;
+	}
+
+	@Override
+	protected String getServiceType() {
+        return "POP3 Service";
+	}
+
+	 
+    @Override
+    protected void doConfigure(final HierarchicalConfiguration configuration) throws ConfigurationException {
+        super.doConfigure(configuration);
+        handlerConfiguration = configuration.configurationAt("handler");
+        lengthReset = handlerConfiguration.getInteger("lengthReset", lengthReset);
+        if (getLogger().isInfoEnabled()) {
+            getLogger().info("The idle timeout will be reset every " + lengthReset + " bytes.");
+        }
+    }
+    
+    /**
+     * @see org.apache.james.socket.mina.AbstractAsyncServer#createIoFilterChainBuilder()
+     */
+    protected DefaultIoFilterChainBuilder createIoFilterChainBuilder() {
+        DefaultIoFilterChainBuilder builder = super.createIoFilterChainBuilder();
+        
+        // response and validation filter to the chain
+        builder.addLast("pop3ResponseFilter", new POP3ResponseFilter());
+        builder.addLast("requestValidationFilter", new POP3ValidationFilter(getLogger()));
+        return builder;
+    }
+
+    /**
+     * A class to provide POP3 handler configuration to the handlers
+     */
+    private class POP3HandlerConfigurationDataImpl implements POP3HandlerConfigurationData {
+
+        /**
+         * @see org.apache.james.pop3server.POP3HandlerConfigurationData#getHelloName()
+         */
+        public String getHelloName() {
+            if (AsyncPOP3Server.this.getHelloName() == null) {
+                return AsyncPOP3Server.this.getMailServer().getHelloName();
+            } else {
+                return AsyncPOP3Server.this.getHelloName();
+            }
+        }
+
+        /**
+         * @see org.apache.james.pop3server.POP3HandlerConfigurationData#getResetLength()
+         */
+        public int getResetLength() {
+            return AsyncPOP3Server.this.lengthReset;
+        }
+
+
+        /**
+         * @see org.apache.james.pop3server.POP3HandlerConfigurationData#isStartTLSSupported()
+         */
+		public boolean isStartTLSSupported() {
+			return AsyncPOP3Server.this.isStartTLSSupported();
+		}
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.pop3server.POP3ServerMBean#getNetworkInterface()
+     */
+	public String getNetworkInterface() {
+		return "unkown";
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.apache.james.pop3server.POP3ServerMBean#getSocketType()
+	 */
+	public String getSocketType() {
+		return "plain";
+	}
+
+
+
+}

Added: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/POP3IoHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/POP3IoHandler.java?rev=899333&view=auto
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/POP3IoHandler.java (added)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/POP3IoHandler.java Thu Jan 14 17:57:41 2010
@@ -0,0 +1,130 @@
+/****************************************************************
+ * 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.mina;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.james.api.protocol.ProtocolHandlerChain;
+import org.apache.james.pop3server.ConnectHandler;
+import org.apache.james.pop3server.LineHandler;
+import org.apache.james.pop3server.POP3HandlerConfigurationData;
+import org.apache.james.pop3server.POP3Request;
+import org.apache.james.pop3server.POP3Session;
+
+import org.apache.mina.core.service.IoHandlerAdapter;
+import org.apache.mina.core.session.IdleStatus;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.ssl.SslContextFactory;
+
+/**
+ * This IoHandler handling the calling of ConnectHandler and LineHandlers
+ * 
+ *
+ */
+public class POP3IoHandler extends IoHandlerAdapter{
+    private final static String POP3_SESSION = "org.apache.james.pop3server.mina.POP3IoHandler.POP3_SESSION";
+    
+    private Log logger;
+    private ProtocolHandlerChain chain;
+    private POP3HandlerConfigurationData conf;
+    private SslContextFactory contextFactory;
+
+    public POP3IoHandler(ProtocolHandlerChain chain,
+            POP3HandlerConfigurationData conf, Log logger) {
+        this(chain,conf,logger,null);
+    }
+    
+    public POP3IoHandler(ProtocolHandlerChain chain,
+    		POP3HandlerConfigurationData conf, Log logger, SslContextFactory contextFactory) {
+        this.chain = chain;
+        this.conf = conf;
+        this.logger = logger;
+        this.contextFactory = contextFactory;
+    }
+
+    /**
+     * @see org.apache.mina.core.service.IoHandlerAdapter#messageReceived(org.apache.mina.core.session.IoSession, java.lang.Object)
+     */
+    public void messageReceived(IoSession session, Object message)
+            throws Exception {
+        POP3Session pop3Session = (POP3Session) session.getAttribute(POP3_SESSION);
+        LinkedList<LineHandler> lineHandlers = chain.getHandlers(LineHandler.class);
+        if (lineHandlers.size() > 0) {
+            // thats not really optimal but it allow us to keep things as generic as possible
+            // Will prolly get refactored later
+            String line = ((POP3Request) message).toString();
+            ((LineHandler) lineHandlers.getLast()).onLine(pop3Session, line);
+        }
+    }
+
+    /**
+     * @see org.apache.mina.core.service.IoHandler#exceptionCaught(org.apache.mina.core.session.IoSession,
+     *      java.lang.Throwable)
+     */
+    public void exceptionCaught(IoSession session, Throwable exception)
+            throws Exception {
+        logger.error("Caught exception: " + session.getCurrentWriteMessage(),
+                exception);
+        // just close session
+        session.close(true);
+    }
+
+    /**
+     * @see org.apache.mina.core.service.IoHandler#sessionCreated(org.apache.mina.core.session.IoSession)
+     */
+    public void sessionCreated(IoSession session) throws Exception {
+        POP3Session pop3Session;
+        if (contextFactory == null) {
+        	pop3Session = new POP3SessionImpl(conf, logger, session);
+        } else {
+        	pop3Session = new POP3SessionImpl(conf, logger, session, contextFactory.newInstance());
+        }
+        
+        // Add attribute
+        session.setAttribute(POP3_SESSION,pop3Session);
+    }
+
+    /**
+     * @see org.apache.mina.core.service.IoHandler#sessionIdle(org.apache.mina.core.session.IoSession,
+     *      org.apache.mina.core.session.IdleStatus)
+     */
+    public void sessionIdle(IoSession session, IdleStatus status)
+            throws Exception {
+        logger.debug("Connection timed out");
+        session.write("Connection timeout");
+    }
+
+    /**
+     * @see org.apache.mina.core.service.IoHandler#sessionOpened(org.apache.mina.core.session.IoSession)
+     */
+    public void sessionOpened(IoSession session) throws Exception {
+        List<ConnectHandler> connectHandlers = chain
+                .getHandlers(ConnectHandler.class);
+      
+        if (connectHandlers != null) {
+            for (int i = 0; i < connectHandlers.size(); i++) {
+                connectHandlers.get(i).onConnect(
+                        (POP3Session) session.getAttribute(POP3_SESSION));
+            }
+        }    
+    }
+}

Added: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/POP3SessionImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/POP3SessionImpl.java?rev=899333&view=auto
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/POP3SessionImpl.java (added)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/POP3SessionImpl.java Thu Jan 14 17:57:41 2010
@@ -0,0 +1,169 @@
+/****************************************************************
+ * 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.mina;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.james.pop3server.POP3HandlerConfigurationData;
+import org.apache.james.pop3server.POP3Response;
+import org.apache.james.pop3server.POP3Session;
+import org.apache.james.services.MailRepository;
+import org.apache.james.socket.mina.AbstractMINASession;
+import org.apache.mailet.Mail;
+import org.apache.mina.core.session.IoSession;
+
+public class POP3SessionImpl extends AbstractMINASession implements POP3Session{
+
+
+	private POP3HandlerConfigurationData configData;
+
+	private Map<String, Object> state = new HashMap<String, Object>();
+
+	private List<Mail> userMailbox;
+
+	private MailRepository userInbox;
+
+	private int handlerState;
+
+	private List<Mail> backupUserMailbox;
+	
+	public POP3SessionImpl(POP3HandlerConfigurationData configData, Log logger, IoSession session, SSLContext context) {
+		super(logger, session, context);
+		
+		this.configData = configData;
+	}
+
+	public POP3SessionImpl(POP3HandlerConfigurationData configData, Log logger, IoSession session) {
+		this(configData, logger, session, null);
+	}
+	
+	/*
+	 * (non-Javadoc)
+	 * @see org.apache.james.pop3server.POP3Session#getBackupUserMailbox()
+	 */
+	public List<Mail> getBackupUserMailbox() {
+		return backupUserMailbox;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.apache.james.pop3server.POP3Session#getConfigurationData()
+	 */
+	public POP3HandlerConfigurationData getConfigurationData() {
+		return configData;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.apache.james.pop3server.POP3Session#getHandlerState()
+	 */
+	public int getHandlerState() {
+		return handlerState;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.apache.james.api.protocol.TLSSupportedSession#getState()
+	 */
+	public Map<String, Object> getState() {
+		return state;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.apache.james.pop3server.POP3Session#getUserInbox()
+	 */
+	public MailRepository getUserInbox() {
+		return userInbox;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.apache.james.pop3server.POP3Session#getUserMailbox()
+	 */
+	public List<Mail> getUserMailbox() {
+		return userMailbox;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.apache.james.pop3server.POP3Session#setBackupUserMailbox(java.util.List)
+	 */
+	public void setBackupUserMailbox(List<Mail> backupUserMailbox) {
+		this.backupUserMailbox = backupUserMailbox;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.apache.james.pop3server.POP3Session#setHandlerState(int)
+	 */
+	public void setHandlerState(int handlerState) {
+		this.handlerState = handlerState;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.apache.james.pop3server.POP3Session#setUserInbox(org.apache.james.services.MailRepository)
+	 */
+	public void setUserInbox(MailRepository userInbox) {
+		this.userInbox = userInbox;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.apache.james.pop3server.POP3Session#setUserMailbox(java.util.List)
+	 */
+	public void setUserMailbox(List<Mail> userMailbox) {
+		this.userMailbox = userMailbox;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.apache.james.pop3server.POP3Session#writePOP3Response(org.apache.james.pop3server.POP3Response)
+	 */
+	public void writePOP3Response(POP3Response response) {
+		getIoSession().write(response);		
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.apache.james.pop3server.POP3Session#writeResponse(java.lang.String)
+	 */
+	public void writeResponse(String string) {
+		getIoSession().write(string);
+	}
+
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.apache.james.api.protocol.TLSSupportedSession#resetState()
+	 */
+	public void resetState() {
+		state.clear();
+		
+		setHandlerState(AUTHENTICATION_READY);
+	}
+
+}

Added: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/filter/POP3ResponseFilter.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/filter/POP3ResponseFilter.java?rev=899333&view=auto
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/filter/POP3ResponseFilter.java (added)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/filter/POP3ResponseFilter.java Thu Jan 14 17:57:41 2010
@@ -0,0 +1,102 @@
+/****************************************************************
+ * 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.mina.filter;
+
+import java.util.Locale;
+
+import org.apache.james.pop3server.POP3Request;
+import org.apache.james.pop3server.POP3Response;
+import org.apache.james.socket.mina.filter.AbstractResponseFilter;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.core.write.DefaultWriteRequest;
+import org.apache.mina.core.write.WriteRequest;
+
+public class POP3ResponseFilter extends AbstractResponseFilter {
+
+    private static final String SCHEDULE_CLOSE_ATTRIBUTE = POP3ResponseFilter.class.getName() + ".closeAttribute";
+
+    @Override
+    protected String getCloseAttribute() {
+        return SCHEDULE_CLOSE_ATTRIBUTE;
+    }
+
+    /**
+     * (non-Javadoc)
+     * 
+     * @see org.apache.mina.core.filterchain.IoFilterAdapter#messageReceived(org.apache.mina.core.filterchain.IoFilter.NextFilter,
+     *      org.apache.mina.core.session.IoSession, java.lang.Object)
+     */
+    public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception {
+        if (message instanceof String) {
+            String cmdString = (String) message;
+            if (cmdString != null) {
+                cmdString = cmdString.trim();
+            }
+
+            String curCommandArgument = null;
+            String curCommandName = 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);
+
+            nextFilter.messageReceived(session, new POP3Request(curCommandName, curCommandArgument));
+        } else {
+            super.messageReceived(nextFilter, session, message);
+        }
+    }
+
+    /**
+     * @see org.apache.mina.core.filterchain.IoFilterAdapter#filterWrite(org.apache.mina.core.filterchain.IoFilter.NextFilter,
+     *      org.apache.mina.core.session.IoSession,
+     *      org.apache.mina.core.write.WriteRequest)
+     */
+    public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception {
+
+        if (writeRequest.getMessage() instanceof POP3Response) {
+            POP3Response response = (POP3Response) writeRequest.getMessage();
+            if (response != null) {
+                for (int k = 0; k < response.getLines().size(); k++) {
+                    StringBuffer respBuff = new StringBuffer(256);
+                    if (k == 0) {
+                        respBuff.append(response.getRetCode());
+                        respBuff.append(" ");
+                        respBuff.append(response.getLines().get(k));
+
+                    } else {
+                        respBuff.append(response.getLines().get(k));
+                    }
+                    nextFilter.filterWrite(session, new DefaultWriteRequest(respBuff.toString()));
+                }
+
+                if (response.isEndSession()) {
+                    session.setAttribute(getCloseAttribute());
+                }
+            }
+        } else {
+            super.filterWrite(nextFilter, session, writeRequest);
+        }
+
+    }
+}

Added: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/filter/POP3ValidationFilter.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/filter/POP3ValidationFilter.java?rev=899333&view=auto
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/filter/POP3ValidationFilter.java (added)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/mina/filter/POP3ValidationFilter.java Thu Jan 14 17:57:41 2010
@@ -0,0 +1,65 @@
+/****************************************************************
+ * 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.mina.filter;
+
+import org.apache.commons.logging.Log;
+import org.apache.james.pop3server.POP3Request;
+import org.apache.james.pop3server.POP3Response;
+import org.apache.james.socket.mina.filter.AbstractValidationFilter;
+import org.apache.mina.core.write.DefaultWriteRequest;
+import org.apache.mina.core.write.WriteRequest;
+
+/**
+ * Validation filter which checks if the written objects are valid for POP3
+ * 
+ */
+public class POP3ValidationFilter extends AbstractValidationFilter {
+
+    public POP3ValidationFilter(Log logger) {
+        super(logger);
+    }
+
+    @Override
+    protected WriteRequest errorRequest(Object obj) {
+        return new DefaultWriteRequest(POP3Response.ERR_RESPONSE + " Cannot handle message of type " + (obj != null ? obj.getClass() : "NULL"));
+    }
+
+    @Override
+    protected WriteRequest errorResponse(Object obj) {
+        return null;
+    }
+
+    @Override
+    protected boolean isValidRequest(Object requestObject) {
+        if (requestObject instanceof POP3Request) {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    protected boolean isValidResponse(Object responseObject) {
+        if (responseObject instanceof POP3Response) {
+            return true;
+        }
+        return false;
+    }
+
+}

Added: james/server/trunk/pop3server-function/src/test/java/org/apache/james/pop3server/AsyncPOP3ServerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/test/java/org/apache/james/pop3server/AsyncPOP3ServerTest.java?rev=899333&view=auto
==============================================================================
--- james/server/trunk/pop3server-function/src/test/java/org/apache/james/pop3server/AsyncPOP3ServerTest.java (added)
+++ james/server/trunk/pop3server-function/src/test/java/org/apache/james/pop3server/AsyncPOP3ServerTest.java Thu Jan 14 17:57:41 2010
@@ -0,0 +1,56 @@
+/****************************************************************
+ * 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 org.apache.commons.logging.impl.SimpleLog;
+import org.apache.james.pop3server.mina.AsyncPOP3Server;
+import org.apache.james.util.ConfigurationAdapter;
+
+public class AsyncPOP3ServerTest extends POP3ServerTest {
+
+    private AsyncPOP3Server m_pop3Server;
+
+    protected void setUp() throws Exception {
+        setUpServiceManager();
+
+        m_pop3Server = new AsyncPOP3Server();
+        m_pop3Server.setDNSService(dnsservice);
+        m_pop3Server.setFileSystem(fSystem);
+        m_pop3Server.setLoader(serviceManager);
+        SimpleLog log = new SimpleLog("Mock");
+        log.setLevel(SimpleLog.LOG_LEVEL_DEBUG);
+        m_pop3Server.setLog(log);
+        m_pop3Server.setMailServer(m_mailServer);
+        m_testConfiguration = new POP3TestConfiguration(m_pop3ListenerPort);
+    }
+
+    protected void finishSetUp(POP3TestConfiguration testConfiguration) throws Exception {
+        testConfiguration.init();
+        m_pop3Server.configure(new ConfigurationAdapter(testConfiguration));
+        m_pop3Server.init();
+    }
+
+    public void testNotAsciiCharsInPassword() throws Exception {
+        // TODO: This currently fails with Async implementation because
+        //       it use Charset US-ASCII to decode / Encode the protocol
+        //       from the RFC I'm currently not understand if NON-ASCII chars
+        //       are allowed at all. So this needs to be checked
+    }
+}

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=899333&r1=899332&r2=899333&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 Thu Jan 14 17:57:41 2010
@@ -66,7 +66,7 @@
 public class POP3ServerTest extends TestCase {
     protected int m_pop3ListenerPort = Util.getNonPrivilegedPort();
 
-    private MockMailServer m_mailServer;
+    protected MockMailServer m_mailServer;
 
     protected POP3TestConfiguration m_testConfiguration;
 
@@ -81,15 +81,16 @@
     private MailImpl testMail2;
     protected FakeLoader serviceManager;
 
-    private MockThreadManager threadManager;
+    protected MockThreadManager threadManager;
 
-    private DNSService dnsservice;
+    protected DNSService dnsservice;
 
-    private MockSocketManager socketManager;
+    protected MockSocketManager socketManager;
 
-    private SimpleConnectionManager connectionManager;
+    protected SimpleConnectionManager connectionManager;
 
-    private MockFileSystem fSystem;
+    protected MockFileSystem fSystem;
+    
     public POP3ServerTest() {
         super("POP3ServerTest");
     }
@@ -169,7 +170,6 @@
             m_pop3Protocol.sendCommand("quit");
             m_pop3Protocol.disconnect();
         }
-        //m_pop3Server.dispose();
         ContainerUtil.dispose(m_mailServer);
         if (testMail1 != null) testMail1.dispose();
         if (testMail2 != null) testMail2.dispose();
@@ -377,7 +377,9 @@
         assertEquals(1, m_pop3Protocol.getState());
 
         Reader r = m_pop3Protocol.retrieveMessageTop(entries[0].number, 0);
+
         assertNotNull(r);
+
         r.close();
 
         Reader r2 = m_pop3Protocol.retrieveMessage(entries[0].number);

Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/AsyncSMTPServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/AsyncSMTPServer.java?rev=899333&r1=899332&r2=899333&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/AsyncSMTPServer.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/AsyncSMTPServer.java Thu Jan 14 17:57:41 2010
@@ -44,10 +44,6 @@
  *
  * @version 1.1.0, 06/02/2001
  */
-/*
- * IMPORTANT: AsyncSMTPServer extends AbstractAsyncServer.  If you implement ANY
- * lifecycle methods, you MUST call super.<method> as well.
- */
 public class AsyncSMTPServer extends AbstractAsyncServer implements SMTPServerMBean {
    
     /**

Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/SMTPSessionImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/SMTPSessionImpl.java?rev=899333&r1=899332&r2=899333&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/SMTPSessionImpl.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/SMTPSessionImpl.java Thu Jan 14 17:57:41 2010
@@ -1,304 +1,223 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.smtpserver.mina;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Random;
-
-import javax.net.ssl.SSLContext;
-
-import org.apache.commons.logging.Log;
-import org.apache.james.smtpserver.mina.filter.FilterLineHandlerAdapter;
-import org.apache.james.smtpserver.mina.filter.TarpitFilter;
-import org.apache.james.smtpserver.protocol.LineHandler;
-import org.apache.james.smtpserver.protocol.SMTPConfiguration;
-import org.apache.james.smtpserver.protocol.SMTPResponse;
-import org.apache.james.smtpserver.protocol.SMTPSession;
-import org.apache.mina.core.session.IoSession;
-import org.apache.mina.filter.ssl.SslFilter;
-
-public class SMTPSessionImpl implements SMTPSession {
-
-        private static Random random = new Random();
-
-        private boolean relayingAllowed;
-
-        private String smtpID;
-
-        private Map<String, Object> connectionState;
-
-        private SMTPConfiguration theConfigData;
-
-        private InetSocketAddress socketAddress;
-
-        private String user;
-
-        private IoSession session;
-
-        private int lineHandlerCount = 0;
-
-        private Log logger;
-        
-        private SSLContext context;
-
-        public SMTPSessionImpl(SMTPConfiguration theConfigData,
-                Log logger, IoSession session, SSLContext context) {
-            this.theConfigData = theConfigData;
-            this.session = session;
-            connectionState = new HashMap<String, Object>();
-            smtpID = random.nextInt(1024) + "";
-
-            this.socketAddress = (InetSocketAddress) session.getRemoteAddress();
-            relayingAllowed = theConfigData.isRelayingAllowed(getRemoteIPAddress());
-            session.setAttribute(FilterLineHandlerAdapter.SMTP_SESSION, this);
-            this.logger = logger;
-            this.context = context;
-        }
-
-        public SMTPSessionImpl(SMTPConfiguration theConfigData,
-                Log logger, IoSession session) {
-            this(theConfigData,logger,session,null);
-        }
-        /**
-         * @see org.apache.james.smtpserver.protocol.SMTPSession#getConnectionState()
-         */
-        public Map<String, Object> getConnectionState() {
-            return connectionState;
-        }
-
-        /**
-         * @see org.apache.james.api.protocol.TLSSupportedSession#getRemoteHost()
-         */
-        public String getRemoteHost() {
-            return socketAddress.getHostName();
-        }
-
-        /**
-         * @see org.apache.james.api.protocol.TLSSupportedSession#getRemoteIPAddress()
-         */
-        public String getRemoteIPAddress() {
-            return socketAddress.getAddress().getHostAddress();
-        }
-        
-        /**
-         * @see org.apache.james.smtpserver.protocol.SMTPSession#getSessionID()
-         */
-        public String getSessionID() {
-            return smtpID;
-        }
-
-        /**
-         * @see org.apache.james.smtpserver.protocol.SMTPSession#getState()
-         */
-        @SuppressWarnings("unchecked")
-        public Map<String, Object> getState() {
-            Map<String, Object> res = (Map<String, Object>) getConnectionState()
-                    .get(SMTPSession.SESSION_STATE_MAP);
-            if (res == null) {
-                res = new HashMap<String, Object>();
-                getConnectionState().put(SMTPSession.SESSION_STATE_MAP, res);
-            }
-            return res;
-        }
-
-        /**
-         * @see org.apache.james.api.protocol.TLSSupportedSession#getUser()
-         */
-        public String getUser() {
-            return user;
-        }
-
-        /**
-         * @see org.apache.james.smtpserver.protocol.SMTPSession#isRelayingAllowed()
-         */
-        public boolean isRelayingAllowed() {
-            return relayingAllowed;
-        }
-
-        /**
-         * @see org.apache.james.smtpserver.protocol.SMTPSession#resetState()
-         */
-        public void resetState() {
-            // remember the ehlo mode between resets
-            Object currentHeloMode = getState().get(CURRENT_HELO_MODE);
-
-            getState().clear();
-
-            // start again with the old helo mode
-            if (currentHeloMode != null) {
-                getState().put(CURRENT_HELO_MODE, currentHeloMode);
-            }
-        }
-
-        /**
-         * @see org.apache.james.api.protocol.TLSSupportedSession#setUser(java.lang.String)
-         */
-        public void setUser(String user) {
-            this.user = user;
-        }
-
-        public IoSession getIoSession() {
-            return session;
-        }
-
-        /**
-         * @see org.apache.james.smtpserver.protocol.SMTPSession#popLineHandler()
-         */
-        public void popLineHandler() {
-            getIoSession().getFilterChain()
-                    .remove("lineHandler" + lineHandlerCount);
-            lineHandlerCount--;
-        }
-
-        /**
-         * @see org.apache.james.smtpserver.protocol.SMTPSession#pushLineHandler(org.apache.james.smtpserver.protocol.LineHandler)
-         */
-        public void pushLineHandler(LineHandler overrideCommandHandler) {
-            lineHandlerCount++;
-            getIoSession().getFilterChain().addAfter("protocolCodecFactory",
-                    "lineHandler" + lineHandlerCount,
-                    new FilterLineHandlerAdapter(overrideCommandHandler));
-        }
-
-        /**
-         * @see org.apache.james.smtpserver.protocol.SMTPSession#writeSMTPResponse(org.apache.james.smtpserver.protocol.SMTPResponse)
-         */
-        public void writeSMTPResponse(SMTPResponse response) {
-            getIoSession().write(response);
-        }
-
-
-        /**
-         * @see org.apache.james.smtpserver.protocol.SMTPSession#getHelloName()
-         */
-        public String getHelloName() {
-            return theConfigData.getHelloName();
-        }
-
-
-        /**
-         * @see org.apache.james.smtpserver.protocol.SMTPSession#getMaxMessageSize()
-         */
-        public long getMaxMessageSize() {
-            return theConfigData.getMaxMessageSize();
-        }
-
-
-        /**
-         * @see org.apache.james.smtpserver.protocol.SMTPSession#getRcptCount()
-         */
-        @SuppressWarnings("unchecked")
-        public int getRcptCount() {
-            int count = 0;
-
-            // check if the key exists
-            if (getState().get(SMTPSession.RCPT_LIST) != null) {
-                count = ((Collection) getState().get(SMTPSession.RCPT_LIST)).size();
-            }
-
-            return count;
-        }
-
-        /**
-         * @see org.apache.james.smtpserver.protocol.SMTPSession#getSMTPGreeting()
-         */
-        public String getSMTPGreeting() {
-            return theConfigData.getSMTPGreeting();
-        }
-
-
-        /**
-         * @see org.apache.james.smtpserver.protocol.SMTPSession#isAuthSupported()
-         */
-        public boolean isAuthSupported() {
-            return theConfigData.isAuthRequired(socketAddress.getAddress().getHostAddress());
-        }
-
-
-        /**
-         * @see org.apache.james.smtpserver.protocol.SMTPSession#setRelayingAllowed(boolean)
-         */
-        public void setRelayingAllowed(boolean relayingAllowed) {
-            this.relayingAllowed = relayingAllowed;
-        }
-
-
-        /**
-         * @see org.apache.james.smtpserver.protocol.SMTPSession#sleep(long)
-         */
-        public void sleep(long ms) {
-            session.getFilterChain().addAfter("connectionFilter", "tarpitFilter",new TarpitFilter(ms));
-        }
-
-
-        /**
-         * @see org.apache.james.smtpserver.protocol.SMTPSession#useAddressBracketsEnforcement()
-         */
-        public boolean useAddressBracketsEnforcement() {
-            return theConfigData.useAddressBracketsEnforcement();
-        }
-
-        /**
-         * @see org.apache.james.smtpserver.protocol.SMTPSession#useHeloEhloEnforcement()
-         */
-        public boolean useHeloEhloEnforcement() {
-            return theConfigData.useHeloEhloEnforcement();
-        }
-
-
-        /**
-         * @see org.apache.james.api.protocol.TLSSupportedSession#isStartTLSSupported()
-         */
-        public boolean isStartTLSSupported() {
-            return context != null;
-        }
-
-        /**
-         * @see org.apache.james.api.protocol.TLSSupportedSession#isTLSStarted()
-         */
-        public boolean isTLSStarted() {
-            return session.getFilterChain().contains("sslFilter");
-        }
-
-        /**
-         * @see org.apache.james.api.protocol.TLSSupportedSession#startTLS()
-         */
-        public void startTLS() throws IOException {
-            session.suspendRead();
-            SslFilter filter = new SslFilter(context);
-            resetState();
-            session.getFilterChain().addFirst("sslFilter", filter);
-            session.resumeRead();
-        }
-
-
-        /**
-         * @see org.apache.james.api.protocol.LogEnabledSession#getLogger()
-         */
-        public Log getLogger() {
-            return logger;
-        }
-
-
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.smtpserver.mina;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.james.smtpserver.mina.filter.FilterLineHandlerAdapter;
+import org.apache.james.smtpserver.mina.filter.TarpitFilter;
+import org.apache.james.smtpserver.protocol.LineHandler;
+import org.apache.james.smtpserver.protocol.SMTPConfiguration;
+import org.apache.james.smtpserver.protocol.SMTPResponse;
+import org.apache.james.smtpserver.protocol.SMTPSession;
+import org.apache.james.socket.mina.AbstractMINASession;
+import org.apache.mina.core.session.IoSession;
+
+public class SMTPSessionImpl extends AbstractMINASession implements SMTPSession {
+
+        private static Random random = new Random();
+
+        private boolean relayingAllowed;
+
+        private String smtpID;
+
+        private Map<String, Object> connectionState;
+
+        private SMTPConfiguration theConfigData;
+
+        private int lineHandlerCount = 0;
+
+        public SMTPSessionImpl(SMTPConfiguration theConfigData,
+                Log logger, IoSession session, SSLContext context) {
+            super(logger, session, context);
+        	this.theConfigData = theConfigData;
+            connectionState = new HashMap<String, Object>();
+            smtpID = random.nextInt(1024) + "";
+
+            relayingAllowed = theConfigData.isRelayingAllowed(getRemoteIPAddress());
+            session.setAttribute(FilterLineHandlerAdapter.SMTP_SESSION, this);
+        }
+
+        public SMTPSessionImpl(SMTPConfiguration theConfigData,
+                Log logger, IoSession session) {
+            this(theConfigData, logger, session, null);
+        }
+        /**
+         * @see org.apache.james.smtpserver.protocol.SMTPSession#getConnectionState()
+         */
+        public Map<String, Object> getConnectionState() {
+            return connectionState;
+        }
+        
+        /**
+         * @see org.apache.james.smtpserver.protocol.SMTPSession#getSessionID()
+         */
+        public String getSessionID() {
+            return smtpID;
+        }
+
+        /**
+         * @see org.apache.james.smtpserver.protocol.SMTPSession#getState()
+         */
+        @SuppressWarnings("unchecked")
+        public Map<String, Object> getState() {
+            Map<String, Object> res = (Map<String, Object>) getConnectionState()
+                    .get(SMTPSession.SESSION_STATE_MAP);
+            if (res == null) {
+                res = new HashMap<String, Object>();
+                getConnectionState().put(SMTPSession.SESSION_STATE_MAP, res);
+            }
+            return res;
+        }
+
+        /**
+         * @see org.apache.james.smtpserver.protocol.SMTPSession#isRelayingAllowed()
+         */
+        public boolean isRelayingAllowed() {
+            return relayingAllowed;
+        }
+
+        /**
+         * @see org.apache.james.smtpserver.protocol.SMTPSession#resetState()
+         */
+        public void resetState() {
+            // remember the ehlo mode between resets
+            Object currentHeloMode = getState().get(CURRENT_HELO_MODE);
+
+            getState().clear();
+
+            // start again with the old helo mode
+            if (currentHeloMode != null) {
+                getState().put(CURRENT_HELO_MODE, currentHeloMode);
+            }
+        }
+
+        /**
+         * @see org.apache.james.smtpserver.protocol.SMTPSession#popLineHandler()
+         */
+        public void popLineHandler() {
+            getIoSession().getFilterChain()
+                    .remove("lineHandler" + lineHandlerCount);
+            lineHandlerCount--;
+        }
+
+        /**
+         * @see org.apache.james.smtpserver.protocol.SMTPSession#pushLineHandler(org.apache.james.smtpserver.protocol.LineHandler)
+         */
+        public void pushLineHandler(LineHandler overrideCommandHandler) {
+            lineHandlerCount++;
+            getIoSession().getFilterChain().addAfter("protocolCodecFactory",
+                    "lineHandler" + lineHandlerCount,
+                    new FilterLineHandlerAdapter(overrideCommandHandler));
+        }
+
+        /**
+         * @see org.apache.james.smtpserver.protocol.SMTPSession#writeSMTPResponse(org.apache.james.smtpserver.protocol.SMTPResponse)
+         */
+        public void writeSMTPResponse(SMTPResponse response) {
+            getIoSession().write(response);
+        }
+
+
+        /**
+         * @see org.apache.james.smtpserver.protocol.SMTPSession#getHelloName()
+         */
+        public String getHelloName() {
+            return theConfigData.getHelloName();
+        }
+
+
+        /**
+         * @see org.apache.james.smtpserver.protocol.SMTPSession#getMaxMessageSize()
+         */
+        public long getMaxMessageSize() {
+            return theConfigData.getMaxMessageSize();
+        }
+
+
+        /**
+         * @see org.apache.james.smtpserver.protocol.SMTPSession#getRcptCount()
+         */
+        @SuppressWarnings("unchecked")
+        public int getRcptCount() {
+            int count = 0;
+
+            // check if the key exists
+            if (getState().get(SMTPSession.RCPT_LIST) != null) {
+                count = ((Collection) getState().get(SMTPSession.RCPT_LIST)).size();
+            }
+
+            return count;
+        }
+
+        /**
+         * @see org.apache.james.smtpserver.protocol.SMTPSession#getSMTPGreeting()
+         */
+        public String getSMTPGreeting() {
+            return theConfigData.getSMTPGreeting();
+        }
+
+
+        /**
+         * @see org.apache.james.smtpserver.protocol.SMTPSession#isAuthSupported()
+         */
+        public boolean isAuthSupported() {
+            return theConfigData.isAuthRequired(socketAddress.getAddress().getHostAddress());
+        }
+
+
+        /**
+         * @see org.apache.james.smtpserver.protocol.SMTPSession#setRelayingAllowed(boolean)
+         */
+        public void setRelayingAllowed(boolean relayingAllowed) {
+            this.relayingAllowed = relayingAllowed;
+        }
+
+
+        /**
+         * @see org.apache.james.smtpserver.protocol.SMTPSession#sleep(long)
+         */
+        public void sleep(long ms) {
+            session.getFilterChain().addAfter("connectionFilter", "tarpitFilter",new TarpitFilter(ms));
+        }
+
+
+        /**
+         * @see org.apache.james.smtpserver.protocol.SMTPSession#useAddressBracketsEnforcement()
+         */
+        public boolean useAddressBracketsEnforcement() {
+            return theConfigData.useAddressBracketsEnforcement();
+        }
+
+        /**
+         * @see org.apache.james.smtpserver.protocol.SMTPSession#useHeloEhloEnforcement()
+         */
+        public boolean useHeloEhloEnforcement() {
+            return theConfigData.useHeloEhloEnforcement();
+        }
+
+
+}

Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/filter/SMTPResponseFilter.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/filter/SMTPResponseFilter.java?rev=899333&r1=899332&r2=899333&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/filter/SMTPResponseFilter.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/filter/SMTPResponseFilter.java Thu Jan 14 17:57:41 2010
@@ -1,122 +1,110 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-package org.apache.james.smtpserver.mina.filter;
-
-import java.util.Locale;
-
-import org.apache.james.smtpserver.protocol.SMTPRequest;
-import org.apache.james.smtpserver.protocol.SMTPResponse;
-import org.apache.mina.core.filterchain.IoFilterAdapter;
-import org.apache.mina.core.session.IoSession;
-import org.apache.mina.core.write.DefaultWriteRequest;
-import org.apache.mina.core.write.WriteRequest;
-
-
-/**
- * Filter to convert SMTPResponse to String Objects
- * 
- */
-public class SMTPResponseFilter extends IoFilterAdapter {
-   
-    private static final String SCHEDULE_CLOSE_ATTRIBUTE = SMTPRequestFilter.class.getName() + ".closeAttribute";
-
-    /**
-     * (non-Javadoc)
-     * @see org.apache.mina.core.filterchain.IoFilterAdapter#messageReceived(org.apache.mina.core.filterchain.IoFilter.NextFilter, org.apache.mina.core.session.IoSession, java.lang.Object)
-     */
-    public void messageReceived(NextFilter nextFilter, IoSession session,
-            Object message) throws Exception {
-        if (message instanceof String) {
-            String cmdString = (String) message;
-            if (cmdString != null) {
-                cmdString = cmdString.trim();
-            }
-
-            String curCommandArgument = null;
-            String curCommandName = 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);
-
-            nextFilter.messageReceived(session, new SMTPRequest(curCommandName,
-                    curCommandArgument));
-        } else {
-            super.messageReceived(nextFilter, session, message);
-        }
-    }
-
-    /**
-     * @see org.apache.mina.core.filterchain.IoFilterAdapter#messageSent(org.apache.mina.core.filterchain.IoFilter.NextFilter, org.apache.mina.core.session.IoSession, org.apache.mina.core.write.WriteRequest)
-     */
-    public void messageSent(NextFilter nextFilter, IoSession session,
-            WriteRequest writeRequest) throws Exception {
-        super.messageSent(nextFilter, session, writeRequest);
-        // System.err.println("### "+arg2);
-        if (session.containsAttribute(SCHEDULE_CLOSE_ATTRIBUTE)) {
-            // Close the session if no more scheduled writes are there.
-            if (session.getScheduledWriteMessages() == 0) {
-                session.close(true);
-            }
-        }
-    }
-
-    /**
-     * @see org.apache.mina.core.filterchain.IoFilterAdapter#filterWrite(org.apache.mina.core.filterchain.IoFilter.NextFilter, org.apache.mina.core.session.IoSession, org.apache.mina.core.write.WriteRequest)
-     */
-    public void filterWrite(NextFilter nextFilter, IoSession session,
-            WriteRequest writeRequest) throws Exception {
-
-        if (writeRequest.getMessage() instanceof SMTPResponse) {
-            SMTPResponse response = (SMTPResponse) writeRequest.getMessage();
-            if (response != null) {
-                // Iterator i = esmtpextensions.iterator();
-                for (int k = 0; k < response.getLines().size(); k++) {
-                    StringBuffer respBuff = new StringBuffer(256);
-                    respBuff.append(response.getRetCode());
-                    if (k == response.getLines().size() - 1) {
-                        respBuff.append(" ");
-                        respBuff.append(response.getLines().get(k));
-                        nextFilter.filterWrite(session,
-                                new DefaultWriteRequest(respBuff.toString()));
-                    } else {
-                        respBuff.append("-");
-                        respBuff.append(response.getLines().get(k));
-                        nextFilter.filterWrite(session,
-                                new DefaultWriteRequest(respBuff.toString()));
-                    }
-                }
-
-                if (response.isEndSession()) {
-                    session.setAttribute(SCHEDULE_CLOSE_ATTRIBUTE);
-                    // arg0.filterClose(arg1);
-                    // arg1.close();
-                }
-            }
-        } else {
-            super.filterWrite(nextFilter, session, writeRequest);
-        }
-
-    }
-
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.smtpserver.mina.filter;
+
+import java.util.Locale;
+
+import org.apache.james.smtpserver.protocol.SMTPRequest;
+import org.apache.james.smtpserver.protocol.SMTPResponse;
+import org.apache.james.socket.mina.filter.AbstractResponseFilter;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.core.write.DefaultWriteRequest;
+import org.apache.mina.core.write.WriteRequest;
+
+
+/**
+ * Filter to convert SMTPResponse to String Objects
+ * 
+ */
+public class SMTPResponseFilter extends AbstractResponseFilter {
+   
+    private static final String SCHEDULE_CLOSE_ATTRIBUTE = SMTPResponseFilter.class.getName() + ".closeAttribute";
+
+    /**
+     * (non-Javadoc)
+     * @see org.apache.mina.core.filterchain.IoFilterAdapter#messageReceived(org.apache.mina.core.filterchain.IoFilter.NextFilter, org.apache.mina.core.session.IoSession, java.lang.Object)
+     */
+    public void messageReceived(NextFilter nextFilter, IoSession session,
+            Object message) throws Exception {
+        if (message instanceof String) {
+            String cmdString = (String) message;
+            if (cmdString != null) {
+                cmdString = cmdString.trim();
+            }
+
+            String curCommandArgument = null;
+            String curCommandName = 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);
+
+            nextFilter.messageReceived(session, new SMTPRequest(curCommandName,
+                    curCommandArgument));
+        } else {
+            super.messageReceived(nextFilter, session, message);
+        }
+    }
+
+
+    /**
+     * @see org.apache.mina.core.filterchain.IoFilterAdapter#filterWrite(org.apache.mina.core.filterchain.IoFilter.NextFilter, org.apache.mina.core.session.IoSession, org.apache.mina.core.write.WriteRequest)
+     */
+    public void filterWrite(NextFilter nextFilter, IoSession session,
+            WriteRequest writeRequest) throws Exception {
+
+        if (writeRequest.getMessage() instanceof SMTPResponse) {
+            SMTPResponse response = (SMTPResponse) writeRequest.getMessage();
+            if (response != null) {
+                for (int k = 0; k < response.getLines().size(); k++) {
+                    StringBuffer respBuff = new StringBuffer(256);
+                    respBuff.append(response.getRetCode());
+                    if (k == response.getLines().size() - 1) {
+                        respBuff.append(" ");
+                        respBuff.append(response.getLines().get(k));
+                        nextFilter.filterWrite(session,
+                                new DefaultWriteRequest(respBuff.toString()));
+                    } else {
+                        respBuff.append("-");
+                        respBuff.append(response.getLines().get(k));
+                        nextFilter.filterWrite(session,
+                                new DefaultWriteRequest(respBuff.toString()));
+                    }
+                }
+
+                if (response.isEndSession()) {
+                    session.setAttribute(getCloseAttribute());
+                }
+            }
+        } else {
+            super.filterWrite(nextFilter, session, writeRequest);
+        }
+
+    }
+
+	@Override
+	protected String getCloseAttribute() {
+		return SCHEDULE_CLOSE_ATTRIBUTE;
+	}
+
+}

Modified: james/server/trunk/socket-api/src/main/java/org/apache/james/api/protocol/TLSSupportedSession.java
URL: http://svn.apache.org/viewvc/james/server/trunk/socket-api/src/main/java/org/apache/james/api/protocol/TLSSupportedSession.java?rev=899333&r1=899332&r2=899333&view=diff
==============================================================================
--- james/server/trunk/socket-api/src/main/java/org/apache/james/api/protocol/TLSSupportedSession.java (original)
+++ james/server/trunk/socket-api/src/main/java/org/apache/james/api/protocol/TLSSupportedSession.java Thu Jan 14 17:57:41 2010
@@ -21,6 +21,7 @@
 package org.apache.james.api.protocol;
 
 import java.io.IOException;
+import java.util.Map;
 
 /**
  * Session which supports TLS 
@@ -71,10 +72,22 @@
     boolean isTLSStarted();
 
     /**
-     * Starttls
+     * Start TLS encryption 
      * 
      * @throws IOException
      */
     void startTLS() throws IOException;
     
+    /**
+     * Return Map which can be used to store objects within a session
+     * 
+     * @return state
+     */
+    public Map<String, Object> getState();
+    
+    /**
+     * Reset the state
+     */
+    public void resetState();
+    
 }

Modified: james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml?rev=899333&r1=899332&r2=899333&view=diff
==============================================================================
--- james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml (original)
+++ james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml Thu Jan 14 17:57:41 2010
@@ -200,6 +200,14 @@
 		<property name="protocolServer" ref="pop3server.protocolserver" />
 	</bean>
 	
+	<!-- Async POP3 Server -->
+	<!-- enable this to use the MINA based POP3 Server which uses NIO -->
+	<!--
+		<bean id="pop3server"
+		class="org.apache.james.pop3server.mina.AsyncPOP3Server" />
+	-->
+	
+	
 	<!-- SMTP Server Beans-->
 	<bean id="smtpserver.protocolhandlerfactory"
 		class="org.apache.james.smtpserver.SMTPServerProtocolHandlerFactory" />



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