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 2011/11/18 11:00:52 UTC
svn commit: r1203562 [1/2] - in /james/protocols/trunk/pop3: .settings/
src/main/java/org/apache/james/protocols/pop3/
src/main/java/org/apache/james/protocols/pop3/core/
src/main/java/org/apache/james/protocols/pop3/pop3server/
src/main/java/org/apach...
Author: norman
Date: Fri Nov 18 10:00:50 2011
New Revision: 1203562
URL: http://svn.apache.org/viewvc?rev=1203562&view=rev
Log:
Start to fix packages and to factor out mailbox-api dependency. See PROTOCOLS-2
Added:
james/protocols/trunk/pop3/.settings/org.eclipse.jdt.core.prefs
james/protocols/trunk/pop3/.settings/org.eclipse.m2e.core.prefs
james/protocols/trunk/pop3/.settings/org.eclipse.pde.core.prefs
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/Mailbox.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3HandlerConfiguration.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Protocol.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Request.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Response.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Session.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3SessionImpl.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3StreamResponse.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/ReadByteFilterInputStream.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/StartTlsPop3Response.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CRLFTerminatedInputStream.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CapaCapability.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CapaCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CoreCmdHandlerLoader.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/DeleCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ExtraDotInputStream.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ListCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/MessageMetaData.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/NoopCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/POP3CommandDispatcherLineHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/POP3CommandHandlerResultLogger.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/PassCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/QuitCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RetrCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RsetCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/StatCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/StlsCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/TopCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/UidlCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/UnknownCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/UserCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/WelcomeMessageHandler.java
Removed:
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/POP3HandlerConfiguration.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/POP3Protocol.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/POP3Request.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/POP3Response.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/POP3Session.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/POP3SessionImpl.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/POP3StreamResponse.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/ReadByteFilterInputStream.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/StartTlsPop3Response.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/CRLFTerminatedInputStream.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/CapaCapability.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/CapaCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/CoreCmdHandlerLoader.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/DeleCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/ExtraDotInputStream.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/ListCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/MessageMetaData.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/NoopCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/POP3CommandDispatcherLineHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/POP3CommandHandlerResultLogger.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/PassCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/QuitCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/RetrCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/RsetCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/StatCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/StlsCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/TopCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/UidlCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/UnknownCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/UserCmdHandler.java
james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/pop3server/core/WelcomeMessageHandler.java
Added: james/protocols/trunk/pop3/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/.settings/org.eclipse.jdt.core.prefs?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/.settings/org.eclipse.jdt.core.prefs (added)
+++ james/protocols/trunk/pop3/.settings/org.eclipse.jdt.core.prefs Fri Nov 18 10:00:50 2011
@@ -0,0 +1,6 @@
+#Fri Nov 18 10:31:04 CET 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6
Added: james/protocols/trunk/pop3/.settings/org.eclipse.m2e.core.prefs
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/.settings/org.eclipse.m2e.core.prefs?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/.settings/org.eclipse.m2e.core.prefs (added)
+++ james/protocols/trunk/pop3/.settings/org.eclipse.m2e.core.prefs Fri Nov 18 10:00:50 2011
@@ -0,0 +1,5 @@
+#Fri Nov 18 10:31:04 CET 2011
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
Added: james/protocols/trunk/pop3/.settings/org.eclipse.pde.core.prefs
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/.settings/org.eclipse.pde.core.prefs?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/.settings/org.eclipse.pde.core.prefs (added)
+++ james/protocols/trunk/pop3/.settings/org.eclipse.pde.core.prefs Fri Nov 18 10:00:50 2011
@@ -0,0 +1,3 @@
+#Fri Nov 18 10:31:04 CET 2011
+BUNDLE_ROOT_PATH=target/classes
+eclipse.preferences.version=1
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/Mailbox.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/Mailbox.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/Mailbox.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/Mailbox.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,23 @@
+/****************************************************************
+ * 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.protocols.pop3;
+
+public interface Mailbox {
+
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3HandlerConfiguration.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3HandlerConfiguration.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3HandlerConfiguration.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3HandlerConfiguration.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,41 @@
+/****************************************************************
+ * 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.protocols.pop3;
+
+/**
+ * Provides a number of server-wide constant values to the POP3Handlers
+ */
+public interface POP3HandlerConfiguration {
+
+ /**
+ * Returns the service wide hello name
+ *
+ * @return the hello name
+ */
+ String getHelloName();
+
+ /**
+ * Return if starttls is supported by the POP3Server
+ *
+ * @return startTLSSupported
+ */
+ boolean isStartTLSSupported();
+
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Protocol.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Protocol.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Protocol.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Protocol.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,55 @@
+/****************************************************************
+ * 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.protocols.pop3;
+
+import org.apache.james.protocols.api.Protocol;
+import org.apache.james.protocols.api.ProtocolSession;
+import org.apache.james.protocols.api.ProtocolTransport;
+import org.apache.james.protocols.api.handler.ProtocolHandlerChain;
+import org.slf4j.Logger;
+
+public class POP3Protocol implements Protocol{
+
+ private ProtocolHandlerChain chain;
+ private POP3HandlerConfiguration config;
+ private Logger logger;
+
+ public POP3Protocol(ProtocolHandlerChain chain, POP3HandlerConfiguration config, Logger logger) {
+ this.chain = chain;
+ this.config = config;
+ this.logger = logger;
+ }
+ @Override
+ public ProtocolHandlerChain getProtocolChain() {
+ return chain;
+ }
+
+
+ @Override
+ public ProtocolSession newSession(ProtocolTransport transport) {
+ return new POP3SessionImpl(logger, transport, config);
+ }
+
+ @Override
+ public boolean isStartTLSSupported() {
+ return config.isStartTLSSupported();
+ }
+
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Request.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Request.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Request.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Request.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,32 @@
+/****************************************************************
+ * 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.protocols.pop3;
+
+import org.apache.james.protocols.api.BaseRequest;
+
+/**
+ * POP3Request object
+ */
+public class POP3Request extends BaseRequest {
+
+ public POP3Request(final String command, final String argument) {
+ super(command, argument);
+ }
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Response.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Response.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Response.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Response.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,80 @@
+/****************************************************************
+ * 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.protocols.pop3;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.james.protocols.api.AbstractResponse;
+
+/**
+ * Contains an POP3 result
+ */
+public class POP3Response extends AbstractResponse {
+
+ // POP3 response prefixes
+ /** OK response. Requested content will follow */
+ public final static String OK_RESPONSE = "+OK";
+
+ /**
+ * Error response. Requested content will not be provided. This prefix is
+ * followed by a more detailed error message.
+ */
+ public final static String ERR_RESPONSE = "-ERR";
+
+ /**
+ * Construct a new POP3Response. The given code and description can not be
+ * null, if null an IllegalArgumentException get thrown
+ *
+ * @param code
+ * the returnCode
+ * @param description
+ * the description
+ */
+ public POP3Response(String code, CharSequence description) {
+ super(code, description);
+ }
+
+ public POP3Response(String code) {
+ this(code, null);
+ }
+
+ protected POP3Response() {
+ }
+
+
+ /**
+ * Return a List of all responseLines stored in this POP3Response
+ *
+ * @return all responseLines
+ */
+ public List<CharSequence> getLines() {
+ List<CharSequence> responseList = new ArrayList<CharSequence>();
+ for (int i = 0; i < lines.size(); i++) {
+ if (i == 0) {
+ responseList.add(getRetCode() + " " +lines.get(i));
+ } else {
+ responseList.add(lines.get(i));
+ }
+ }
+ return responseList;
+ }
+
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Session.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Session.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Session.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3Session.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,81 @@
+/****************************************************************
+ * 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.protocols.pop3;
+
+import org.apache.james.protocols.api.ProtocolSession;
+
+/**
+ * All the handlers access this interface to communicate with POP3Handler object
+ */
+
+public interface POP3Session extends ProtocolSession {
+
+ final static String UID_LIST = "UID_LIST";
+ final static String DELETED_UID_LIST = "DELETED_UID_LIST";
+ final static String MAILBOX_SESSION = "MAILBOX_SESSION";
+
+ // Authentication states for the POP3 interaction
+ /** Waiting for user id */
+ final static int AUTHENTICATION_READY = 0;
+ /** User id provided, waiting for password */
+ final static int AUTHENTICATION_USERSET = 1;
+ /**
+ * A valid user id/password combination has been provided. In this state the
+ * client can access the mailbox of the specified user.
+ */
+ final static int TRANSACTION = 2;
+
+ /**
+ * Returns POP3Handler service wide configuration
+ *
+ * @return POP3HandlerConfigurationData
+ */
+ POP3HandlerConfiguration getConfigurationData();
+
+ /**
+ * Returns the current handler state
+ *
+ * @return handler state
+ */
+ int getHandlerState();
+
+ /**
+ * Sets the new handler state
+ *
+ * @param handlerState
+ * state
+ */
+ void setHandlerState(int handlerState);
+
+ /**
+ * Returns the mail list contained in the mailbox
+ *
+ * @return mailbox content
+ */
+ Mailbox getUserMailbox();
+
+ /**
+ * Sets a new mailbox content
+ *
+ * @param mailbox
+ * mailbox
+ */
+ void setUserMailbox(Mailbox mailbox);
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3SessionImpl.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3SessionImpl.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3SessionImpl.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3SessionImpl.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,100 @@
+/****************************************************************
+ * 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.protocols.pop3;
+
+import org.apache.james.protocols.api.AbstractSession;
+import org.apache.james.protocols.api.ProtocolTransport;
+import org.apache.james.protocols.api.Response;
+import org.slf4j.Logger;
+
+/**
+ * {@link POP3Session} implementation which use Netty
+ */
+public class POP3SessionImpl extends AbstractSession implements POP3Session {
+ private POP3HandlerConfiguration configData;
+
+ private int handlerState;
+
+ private Mailbox mailbox;
+
+
+ public POP3SessionImpl(Logger logger, ProtocolTransport transport, POP3HandlerConfiguration configData) {
+ super(logger, transport);
+ this.configData = configData;
+ }
+
+ /**
+ * @see org.apache.james.pop3server.POP3Session#getConfigurationData()
+ */
+ public POP3HandlerConfiguration getConfigurationData() {
+ return configData;
+ }
+
+ /**
+ * @see org.apache.james.pop3server.POP3Session#getHandlerState()
+ */
+ public int getHandlerState() {
+ return handlerState;
+ }
+
+ /**
+ * @see org.apache.james.pop3server.POP3Session#setHandlerState(int)
+ */
+ public void setHandlerState(int handlerState) {
+ this.handlerState = handlerState;
+ }
+
+ /**
+ * @see org.apache.james.protocols.api.ProtocolSession#resetState()
+ */
+ public void resetState() {
+ getState().clear();
+
+ setHandlerState(AUTHENTICATION_READY);
+ }
+
+ /**
+ * @see org.apache.james.pop3server.POP3Session#getUserMailbox()
+ */
+ public Mailbox getUserMailbox() {
+ return mailbox;
+ }
+
+ /**
+ * @see
+ * org.apache.james.pop3server.POP3Session#setUserMailbox(Mailbox)
+ */
+ public void setUserMailbox(Mailbox mailbox) {
+ this.mailbox = mailbox;
+ }
+
+ @Override
+ public Response newLineTooLongResponse() {
+ return null;
+ }
+
+ @Override
+ public Response newFatalErrorResponse() {
+ return null;
+ }
+
+
+
+
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3StreamResponse.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3StreamResponse.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3StreamResponse.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/POP3StreamResponse.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,40 @@
+/****************************************************************
+ * 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.protocols.pop3;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.SequenceInputStream;
+
+import org.apache.james.protocols.api.StreamResponse;
+
+public class POP3StreamResponse extends POP3Response implements StreamResponse {
+
+ private InputStream stream;
+
+ public POP3StreamResponse(String code, CharSequence description, InputStream stream) {
+ super(code, description);
+ this.stream = stream;
+ }
+
+ public InputStream getStream() {
+ return new SequenceInputStream(stream, new ByteArrayInputStream(".\r\n".getBytes()));
+ }
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/ReadByteFilterInputStream.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/ReadByteFilterInputStream.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/ReadByteFilterInputStream.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/ReadByteFilterInputStream.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,61 @@
+/****************************************************************
+ * 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.protocols.pop3;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * {@link FilterInputStream} which delagates every {@link #read(byte[])} and {@link #read(byte[], int, int)} to the {@link #read()} method
+ *
+ *
+ */
+public class ReadByteFilterInputStream extends FilterInputStream {
+
+ protected ReadByteFilterInputStream(InputStream in) {
+ super(in);
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ int i;
+ for (i = 0; i < len; i++) {
+ int a = read();
+ if (i == 0 && a == -1) {
+ return -1;
+ } else {
+ if (a == -1) {
+ break;
+ } else {
+ b[off++] = (byte) a;
+ }
+ }
+ }
+ return i;
+
+ }
+
+ @Override
+ public int read(byte[] b) throws IOException {
+ return read(b, 0, b.length);
+ }
+
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/StartTlsPop3Response.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/StartTlsPop3Response.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/StartTlsPop3Response.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/StartTlsPop3Response.java Fri Nov 18 10:00:50 2011
@@ -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.protocols.pop3;
+
+import org.apache.james.protocols.api.StartTlsResponse;
+
+/**
+ * Special sub-type of {@link POP3Response} which will trigger the start of TLS after the response was written to the client
+ *
+ *
+ */
+public class StartTlsPop3Response extends POP3Response implements StartTlsResponse{
+
+ public StartTlsPop3Response(String code, CharSequence description) {
+ super(code, description);
+ }
+
+ public StartTlsPop3Response(String code) {
+ super(code);
+ }
+
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CRLFTerminatedInputStream.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CRLFTerminatedInputStream.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CRLFTerminatedInputStream.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CRLFTerminatedInputStream.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,129 @@
+/****************************************************************
+ * 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.protocols.pop3.core;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * This {@link FilterInputStream} makes sure that the last chars of the stream
+ * are \r\n
+ *
+ * See JAMES-1174 for an use case
+ */
+public class CRLFTerminatedInputStream extends FilterInputStream {
+
+ private int last;
+ private byte[] extraData;
+ private int pos = 0;
+ private boolean complete = false;
+
+ private boolean endOfStream = false;
+
+ public CRLFTerminatedInputStream(InputStream in) {
+ super(in);
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ if (endOfStream == false) {
+
+ int r = in.read(b, off, len);
+ if (r == -1) {
+ endOfStream = true;
+ calculateExtraData();
+
+ return fillArray(b, off, len);
+ } else {
+ // Make sure we respect the offset. Otherwise it could let the RETRCmdHandler
+ // hang forever. See JAMES-1222
+ last = b[off + r - 1];
+ return r;
+ }
+ } else {
+ return fillArray(b, off, len);
+ }
+ }
+
+ private int fillArray(byte[] b, int off, int len) {
+ int a = -1;
+ int i = 0;
+ if (complete) {
+ return -1;
+ }
+ while (i < len) {
+ a = readNext();
+ if (a == -1) {
+ complete = true;
+ break;
+ } else {
+ b[off + i++] = (byte) a;
+
+ }
+ }
+ return i;
+ }
+
+ @Override
+ public int read(byte[] b) throws IOException {
+ return read(b, 0, b.length);
+ }
+
+ @Override
+ public int read() throws IOException {
+ if (endOfStream == false) {
+ int i = super.read();
+ if (i == -1) {
+ endOfStream = true;
+ calculateExtraData();
+ return readNext();
+ } else {
+ last = i;
+ }
+ return i;
+
+ } else {
+ return readNext();
+ }
+ }
+
+ private void calculateExtraData() {
+ if (last == '\n') {
+ extraData = null;
+ } else if (last == '\r') {
+ extraData = new byte[1];
+ extraData[0] = '\n';
+ } else {
+ extraData = new byte[2];
+ extraData[0] = '\r';
+ extraData[1] = '\n';
+ }
+
+ }
+
+ private int readNext() {
+ if (extraData == null || extraData.length == pos) {
+ return -1;
+ } else {
+ return extraData[pos++];
+ }
+ }
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CapaCapability.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CapaCapability.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CapaCapability.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CapaCapability.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,41 @@
+/****************************************************************
+ * 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.protocols.pop3.core;
+
+import java.util.List;
+
+import org.apache.james.protocols.pop3.POP3Session;
+
+
+/**
+ * A handler which support the POP3 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
+ */
+ List<String> getImplementedCapabilities(POP3Session session);
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CapaCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CapaCmdHandler.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CapaCmdHandler.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CapaCmdHandler.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,99 @@
+/****************************************************************
+ * 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.protocols.pop3.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+
+import org.apache.james.protocols.api.Request;
+import org.apache.james.protocols.api.Response;
+import org.apache.james.protocols.api.handler.CommandHandler;
+import org.apache.james.protocols.api.handler.ExtensibleHandler;
+import org.apache.james.protocols.api.handler.WiringException;
+import org.apache.james.protocols.pop3.POP3Response;
+import org.apache.james.protocols.pop3.POP3Session;
+
+/**
+ * This handler is used to handle CAPA commands
+ */
+public class CapaCmdHandler implements CommandHandler<POP3Session>, ExtensibleHandler, CapaCapability {
+ public final static String COMMAND_NAME = "CAPA";
+ private List<CapaCapability> caps;
+
+ /**
+ * @see
+ * org.apache.james.protocols.api.handler.CommandHandler
+ * #onCommand(org.apache.james.protocols.api.ProtocolSession, org.apache.james.protocols.api.Request)
+ */
+ public Response onCommand(POP3Session session, Request request) {
+ POP3Response response = new POP3Response(POP3Response.OK_RESPONSE, "Capability list follows");
+
+ for (int i = 0; i < caps.size(); i++) {
+ List<String> cList = caps.get(i).getImplementedCapabilities(session);
+ for (int a = 0; a < cList.size(); a++) {
+ response.appendLine(cList.get(a));
+ }
+ }
+ response.appendLine(".");
+ return response;
+ }
+
+ /**
+ * @see org.apache.james.protocols.api.handler.ExtensibleHandler#getMarkerInterfaces()
+ */
+ @SuppressWarnings("unchecked")
+ public List<Class<?>> getMarkerInterfaces() {
+ List<Class<?>> mList = new ArrayList();
+ mList.add(CapaCapability.class);
+ return mList;
+ }
+
+ /**
+ * @see org.apache.james.protocols.api.handler.ExtensibleHandler#wireExtensions(java.lang.Class,
+ * java.util.List)
+ */
+ @SuppressWarnings("unchecked")
+ public void wireExtensions(Class interfaceName, List extension) throws WiringException {
+ if (interfaceName.equals(CapaCapability.class)) {
+ caps = extension;
+ }
+ }
+
+ /**
+ * @see org.apache.james.protocols.api.handler.CommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+
+ /**
+ * @see org.apache.james.pop3server.core.CapaCapability#getImplementedCapabilities(org.apache.james.pop3server.POP3Session)
+ */
+ public List<String> getImplementedCapabilities(POP3Session session) {
+ List<String> cList = new ArrayList<String>();
+ cList.add("PIPELINING");
+ return cList;
+ }
+
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CoreCmdHandlerLoader.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CoreCmdHandlerLoader.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CoreCmdHandlerLoader.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CoreCmdHandlerLoader.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,84 @@
+/****************************************************************
+ * 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.protocols.pop3.core;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.james.protocols.api.handler.HandlersPackage;
+
+public class CoreCmdHandlerLoader implements HandlersPackage {
+
+ private final static String CAPACMDHANDLER = CapaCmdHandler.class.getName();
+ private final static String USERCMDHANDLER = UserCmdHandler.class.getName();
+ private final static String PASSCMDHANDLER = PassCmdHandler.class.getName();
+ private final static String LISTCMDHANDLER = ListCmdHandler.class.getName();
+ private final static String UIDLCMDHANDLER = UidlCmdHandler.class.getName();
+ private final static String RSETCMDHANDLER = RsetCmdHandler.class.getName();
+ private final static String DELECMDHANDLER = DeleCmdHandler.class.getName();
+ private final static String NOOPCMDHANDLER = NoopCmdHandler.class.getName();
+ private final static String RETRSCMDHANDLER = RetrCmdHandler.class.getName();
+ private final static String TOPCMDHANDLER = TopCmdHandler.class.getName();
+ private final static String STATCMDHANDLER = StatCmdHandler.class.getName();
+ private final static String QUITCMDHANDLER = QuitCmdHandler.class.getName();
+ private final static String WELCOMEMESSAGEHANDLER = WelcomeMessageHandler.class.getName();
+ private final static String UNKOWNCMDHANDLER = UnknownCmdHandler.class.getName();
+ private final static String STLSCMDHANDLER = StlsCmdHandler.class.getName();
+
+ private final static String COMMANDDISPATCHER = POP3CommandDispatcherLineHandler.class.getName();
+
+ // logging stuff
+ private final String COMMANDHANDLERRESULTLOGGER = POP3CommandHandlerResultLogger.class.getName();
+
+
+ private final List<String> commands = new LinkedList<String>();
+
+ public CoreCmdHandlerLoader() {
+ // Insert the base commands in the Map
+ commands.add(WELCOMEMESSAGEHANDLER);
+ commands.add(COMMANDDISPATCHER);
+ commands.add(CAPACMDHANDLER);
+ commands.add(USERCMDHANDLER);
+ commands.add(PASSCMDHANDLER);
+ commands.add(LISTCMDHANDLER);
+ commands.add(UIDLCMDHANDLER);
+ commands.add(RSETCMDHANDLER);
+ commands.add(DELECMDHANDLER);
+ commands.add(NOOPCMDHANDLER);
+ commands.add(RETRSCMDHANDLER);
+ commands.add(TOPCMDHANDLER);
+ commands.add(STATCMDHANDLER);
+ commands.add(QUITCMDHANDLER);
+ commands.add(UNKOWNCMDHANDLER);
+ // add STARTTLS support to the core. See JAMES-1224
+ commands.add(STLSCMDHANDLER);
+
+ // Add logging stuff
+ commands.add(COMMANDHANDLERRESULTLOGGER);
+ }
+
+ /**
+ * @see org.apache.james.protocols.api.handler.HandlersPackage#getHandlers()
+ */
+ public List<String> getHandlers() {
+ return commands;
+ }
+
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/DeleCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/DeleCmdHandler.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/DeleCmdHandler.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/DeleCmdHandler.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,87 @@
+/****************************************************************
+ * 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.protocols.pop3.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.james.protocols.api.Request;
+import org.apache.james.protocols.api.Response;
+import org.apache.james.protocols.api.handler.CommandHandler;
+import org.apache.james.protocols.pop3.POP3Response;
+import org.apache.james.protocols.pop3.POP3Session;
+
+/**
+ * Handles DELE command
+ */
+public class DeleCmdHandler implements CommandHandler<POP3Session> {
+ private final static String COMMAND_NAME = "DELE";
+
+ /**
+ * Handler method called upon receipt of a DELE command. This command
+ * deletes a particular mail message from the mailbox.
+ */
+ @SuppressWarnings("unchecked")
+ public Response onCommand(POP3Session session, Request request) {
+ POP3Response response = null;
+ if (session.getHandlerState() == POP3Session.TRANSACTION) {
+ int num = 0;
+ try {
+ num = Integer.parseInt(request.getArgument());
+ } catch (Exception e) {
+ response = new POP3Response(POP3Response.ERR_RESPONSE, "Usage: DELE [mail number]");
+ return response;
+ }
+ try {
+ List<MessageMetaData> uidList = (List<MessageMetaData>) session.getState().get(POP3Session.UID_LIST);
+ List<Long> deletedUidList = (List<Long>) session.getState().get(POP3Session.DELETED_UID_LIST);
+
+ Long uid = uidList.get(num - 1).getUid();
+
+ if (deletedUidList.contains(uid)) {
+ StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") already deleted.");
+ response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
+ } else {
+ deletedUidList.add(uid);
+ // we are replacing our reference with "DELETED", so we have
+ // to dispose the no-more-referenced mail object.
+ response = new POP3Response(POP3Response.OK_RESPONSE, "Message deleted");
+ }
+ } catch (IndexOutOfBoundsException iob) {
+ StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
+ response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
+ }
+ } else {
+ response = new POP3Response(POP3Response.ERR_RESPONSE);
+ }
+ return response;
+ }
+
+ /**
+ * @see org.apache.james.protocols.api.handler.CommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ExtraDotInputStream.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ExtraDotInputStream.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ExtraDotInputStream.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ExtraDotInputStream.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,66 @@
+/****************************************************************
+ * 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.protocols.pop3.core;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PushbackInputStream;
+
+import org.apache.james.protocols.pop3.ReadByteFilterInputStream;
+
+
+/**
+ * Adds extra dot if dot occurs in message body at beginning of line (according
+ * to RFC1939)
+ */
+public class ExtraDotInputStream extends ReadByteFilterInputStream {
+
+ boolean startLine = true;
+ private int last;
+
+ public ExtraDotInputStream(InputStream in) {
+ super(new PushbackInputStream(in, 2));
+ startLine = true;
+ }
+
+
+ @Override
+ public int read() throws IOException {
+ PushbackInputStream pin = (PushbackInputStream) in;
+ int i = pin.read();
+ if (startLine) {
+ startLine = false;
+ if (i == '.') {
+ pin.unread(i);
+ return '.';
+ }
+
+ }
+
+ if (last == '\r' && i == '\n') {
+ startLine = true;
+ }
+ last = i;
+ return i;
+
+
+ }
+
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ListCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ListCmdHandler.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ListCmdHandler.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ListCmdHandler.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,116 @@
+/****************************************************************
+ * 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.protocols.pop3.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.james.pop3server.POP3Response;
+import org.apache.james.pop3server.POP3Session;
+import org.apache.james.protocols.api.Request;
+import org.apache.james.protocols.api.Response;
+import org.apache.james.protocols.api.handler.CommandHandler;
+
+/**
+ * Handles LIST command
+ */
+public class ListCmdHandler implements CommandHandler<POP3Session> {
+
+ /**
+ * Handler method called upon receipt of a LIST command. Returns the number
+ * of messages in the mailbox and its aggregate size, or optionally, the
+ * number and size of a single message.
+ *
+ * @param session
+ * the pop3 session
+ * @param request
+ * the request to process
+ */
+
+ @SuppressWarnings("unchecked")
+ public Response onCommand(POP3Session session, Request request) {
+ POP3Response response = null;
+ String parameters = request.getArgument();
+ List<MessageMetaData> uidList = (List<MessageMetaData>) session.getState().get(POP3Session.UID_LIST);
+ List<Long> deletedUidList = (List<Long>) session.getState().get(POP3Session.DELETED_UID_LIST);
+
+ if (session.getHandlerState() == POP3Session.TRANSACTION) {
+ if (parameters == null) {
+
+ long size = 0;
+ int count = 0;
+ List<MessageMetaData> validResults = new ArrayList<MessageMetaData>();
+ if (uidList.isEmpty() == false) {
+
+ for (int i = 0; i < uidList.size(); i++) {
+ MessageMetaData data = uidList.get(i);
+ if (deletedUidList.contains(data.getUid()) == false) {
+ size += data.getSize();
+ count++;
+ validResults.add(data);
+ }
+ }
+ }
+ StringBuilder responseBuffer = new StringBuilder(32).append(count).append(" ").append(size);
+ response = new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString());
+ count = 0;
+ for (int i = 0; i < validResults.size(); i++) {
+ responseBuffer = new StringBuilder(16).append(i + 1).append(" ").append(validResults.get(i).getSize());
+ response.appendLine(responseBuffer.toString());
+ }
+ response.appendLine(".");
+ } else {
+ int num = 0;
+ try {
+ num = Integer.parseInt(parameters);
+ MessageMetaData data = uidList.get(num - 1);
+ if (deletedUidList.contains(data.getUid()) == false) {
+
+ StringBuilder responseBuffer = new StringBuilder(64).append(num).append(" ").append(data.getSize());
+ response = new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString());
+ } else {
+ StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") already deleted.");
+ response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
+ }
+ } catch (IndexOutOfBoundsException npe) {
+ StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
+ response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
+ } catch (NumberFormatException nfe) {
+ StringBuilder responseBuffer = new StringBuilder(64).append(parameters).append(" is not a valid number");
+ response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
+ }
+ }
+ } else {
+ response = new POP3Response(POP3Response.ERR_RESPONSE);
+ }
+ return response;
+ }
+
+ /**
+ * @see org.apache.james.protocols.api.handler.CommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add("LIST");
+ return commands;
+ }
+
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/MessageMetaData.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/MessageMetaData.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/MessageMetaData.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/MessageMetaData.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,51 @@
+/****************************************************************
+ * 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.protocols.pop3.core;
+
+/**
+ * Hold meta data for a message
+ */
+public final class MessageMetaData {
+
+ private long uid;
+ private long size;
+
+ public MessageMetaData(long uid, long size) {
+ this.uid = uid;
+ this.size = size;
+ }
+
+ /**
+ * Return the uid of the message
+ *
+ * @return uid
+ */
+ public long getUid() {
+ return uid;
+ }
+
+ /**
+ * Return the size of a message
+ *
+ * @return size
+ */
+ public long getSize() {
+ return size;
+ }
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/NoopCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/NoopCmdHandler.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/NoopCmdHandler.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/NoopCmdHandler.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,61 @@
+/****************************************************************
+ * 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.protocols.pop3.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.james.protocols.api.Request;
+import org.apache.james.protocols.api.Response;
+import org.apache.james.protocols.api.handler.CommandHandler;
+import org.apache.james.protocols.pop3.POP3Response;
+import org.apache.james.protocols.pop3.POP3Session;
+
+/**
+ * Handles NOOP command
+ */
+public class NoopCmdHandler implements CommandHandler<POP3Session> {
+ private final static String COMMAND_NAME = "NOOP";
+
+ /**
+ * Handler method called upon receipt of a NOOP command. Like all good
+ * NOOPs, does nothing much.
+ */
+ public Response onCommand(POP3Session session, Request request) {
+ POP3Response response = null;
+ if (session.getHandlerState() == POP3Session.TRANSACTION) {
+ response = new POP3Response(POP3Response.OK_RESPONSE);
+ } else {
+ response = new POP3Response(POP3Response.ERR_RESPONSE);
+ }
+ return response;
+ }
+
+ /**
+ * @see org.apache.james.protocols.api.handler.CommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/POP3CommandDispatcherLineHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/POP3CommandDispatcherLineHandler.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/POP3CommandDispatcherLineHandler.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/POP3CommandDispatcherLineHandler.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,85 @@
+/****************************************************************
+ * 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.protocols.pop3.core;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.pop3server.POP3Session;
+import org.apache.james.protocols.api.Response;
+import org.apache.james.protocols.api.handler.AbstractCommandDispatcher;
+import org.apache.james.protocols.api.handler.CommandHandler;
+
+/**
+ * Dispatch POP3 {@link CommandHandler}
+ */
+public class POP3CommandDispatcherLineHandler extends AbstractCommandDispatcher<POP3Session> {
+ private final static String[] mandatoryCommands = { "USER", "PASS", "LIST" };
+ private final CommandHandler<POP3Session> unknownHandler = new UnknownCmdHandler();
+ private MailboxManager manager;
+
+ @Resource(name = "mailboxmanager")
+ public void setMailboxManager(MailboxManager manager) {
+ this.manager = manager;
+ }
+
+ /**
+ * @see org.apache.james.protocols.api.handler.AbstractCommandDispatcher#getMandatoryCommands()
+ */
+ protected List<String> getMandatoryCommands() {
+ return Arrays.asList(mandatoryCommands);
+ }
+
+ /**
+ * @see org.apache.james.protocols.api.handler.AbstractCommandDispatcher#getUnknownCommandHandler()
+ */
+ protected CommandHandler<POP3Session> getUnknownCommandHandler() {
+ return unknownHandler;
+ }
+
+ /**
+ * @see org.apache.james.protocols.api.handler.AbstractCommandDispatcher#getUnknownCommandHandlerIdentifier()
+ */
+ protected String getUnknownCommandHandlerIdentifier() {
+ return UnknownCmdHandler.COMMAND_NAME;
+ }
+
+
+ @Override
+ public Response onLine(POP3Session session, byte[] line) {
+ MailboxSession mSession = (MailboxSession) session.getState().get(POP3Session.MAILBOX_SESSION);
+
+ // notify the mailboxmanager about the start of the processing
+ manager.startProcessingRequest(mSession);
+
+ // do the processing
+ Response response = super.onLine(session, line);
+
+ // notify the mailboxmanager about the end of the processing
+ manager.endProcessingRequest(mSession);
+
+ return response;
+ }
+
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/POP3CommandHandlerResultLogger.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/POP3CommandHandlerResultLogger.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/POP3CommandHandlerResultLogger.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/POP3CommandHandlerResultLogger.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,32 @@
+/****************************************************************
+ * 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.protocols.pop3.core;
+
+/**
+ * Log {@link POP3Response} with {@link POP3Response#ERR_RESPONSE} return code
+ * to INFO. The rest to DEBUG
+ */
+public class POP3CommandHandlerResultLogger extends AbstractCommandHandlerResultLogger<POP3Response, POP3Session> {
+
+ @Override
+ protected boolean logWithInfo(String code) {
+ return code.startsWith(POP3Response.ERR_RESPONSE);
+ }
+
+}
Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/PassCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/PassCmdHandler.java?rev=1203562&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/PassCmdHandler.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/PassCmdHandler.java Fri Nov 18 10:00:50 2011
@@ -0,0 +1,114 @@
+/****************************************************************
+ * 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.protocols.pop3.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.james.mailbox.BadCredentialsException;
+import org.apache.james.mailbox.MailboxPath;
+import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MailboxException;
+import org.apache.james.pop3server.POP3Response;
+import org.apache.james.pop3server.POP3Session;
+import org.apache.james.protocols.api.Request;
+import org.apache.james.protocols.api.Response;
+import org.apache.james.protocols.lib.POP3BeforeSMTPHelper;
+
+/**
+ * Handles PASS command
+ */
+public class PassCmdHandler extends RsetCmdHandler {
+
+ private final static String COMMAND_NAME = "PASS";
+ private MailboxManager mailboxManager;
+
+ @Resource(name = "mailboxmanager")
+ public void setMailboxManager(MailboxManager manager) {
+ this.mailboxManager = manager;
+ }
+
+ /**
+ * Handler method called upon receipt of a PASS command. Reads in and
+ * validates the password.
+ */
+ public Response onCommand(POP3Session session, Request request) {
+ String parameters = request.getArgument();
+ POP3Response response = null;
+ if (session.getHandlerState() == POP3Session.AUTHENTICATION_USERSET && parameters != null) {
+ String passArg = parameters;
+ try {
+ MailboxSession mSession = mailboxManager.login(session.getUser(), passArg, session.getLogger());
+
+ // explicit call start processing because it was not stored
+ // before in the session
+ mailboxManager.startProcessingRequest(mSession);
+
+ MailboxPath mailboxPath = MailboxPath.inbox(mSession);
+
+ // check if mailbox exists.. if not just create it
+ if (mailboxManager.mailboxExists(mailboxPath, mSession) == false) {
+ mailboxManager.createMailbox(mailboxPath, mSession);
+ }
+ MessageManager mailbox = mailboxManager.getMailbox(mailboxPath, mSession);
+
+ session.getState().put(POP3Session.MAILBOX_SESSION, mSession);
+ session.setUserMailbox(mailbox);
+ stat(session);
+
+ // Store the ipAddress to use it later for pop before smtp
+ POP3BeforeSMTPHelper.addIPAddress(session.getRemoteIPAddress());
+
+ StringBuilder responseBuffer = new StringBuilder(64).append("Welcome ").append(session.getUser());
+ response = new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString());
+ session.setHandlerState(POP3Session.TRANSACTION);
+ } catch (BadCredentialsException e) {
+
+ response = new POP3Response(POP3Response.ERR_RESPONSE, "Authentication failed.");
+ session.setHandlerState(POP3Session.AUTHENTICATION_READY);
+ } catch (MailboxException e) {
+ session.getLogger().error("Unexpected error accessing mailbox for " + session.getUser(), e);
+ response = new POP3Response(POP3Response.ERR_RESPONSE, "Unexpected error accessing mailbox");
+ session.setHandlerState(POP3Session.AUTHENTICATION_READY);
+ }
+ } else {
+ response = new POP3Response(POP3Response.ERR_RESPONSE, "Authentication failed.");
+
+ session.setHandlerState(POP3Session.AUTHENTICATION_READY);
+ }
+
+ return response;
+ }
+
+ /**
+ * @see org.apache.james.protocols.api.handler.CommandHandler#getImplCommands()
+ */
+ public Collection<String> getImplCommands() {
+ List<String> commands = new ArrayList<String>();
+ commands.add(COMMAND_NAME);
+ return commands;
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org