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:42:14 UTC

svn commit: r1203577 - in /james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3: ./ core/

Author: norman
Date: Fri Nov 18 10:42:13 2011
New Revision: 1203577

URL: http://svn.apache.org/viewvc?rev=1203577&view=rev
Log:
pop3 code in protocols does now not depend on mailbox-api anymore. See PROTOCOL-2

Added:
    james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/MailboxFactory.java
    james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/MessageMetaData.java
Removed:
    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/core/MessageMetaData.java
    james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/POP3CommandHandlerResultLogger.java
Modified:
    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/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/POP3CommandDispatcherLineHandler.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/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/UserCmdHandler.java

Modified: 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=1203577&r1=1203576&r2=1203577&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/Mailbox.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/Mailbox.java Fri Nov 18 10:42:13 2011
@@ -18,6 +18,49 @@
  ****************************************************************/
 package org.apache.james.protocols.pop3;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+
+/**
+ * A Mailbox which is used in POP3 to retrieve messages
+ * 
+ *
+ */
 public interface Mailbox {
+	
+	/**
+	 * Returns the message content as {@link InputStream} or <code>null</code> if no message can be found for the given <code>uid</code>
+	 * 
+	 * @param uid
+	 * @return content
+	 * @throws IOException
+	 */
+	InputStream getMessageContent(long uid) throws IOException;
+	
+	/**
+	 * Return a immutable {@link List} which holds the {@link MessageMetaData} for all messages in the {@link Mailbox}
+	 * 
+	 * @return messages
+	 * @throws IOException
+	 */
+	List<MessageMetaData> getMessages() throws IOException;;
+	
+	/**
+	 * Remove the messages with the given uids
+	 * 
+	 * @param uids
+	 */
+	void remove(long... uids) throws IOException;
+	
+	
+	/**
+	 * Return the identifier for the mailbox. This MUST not change 
+	 * 
+	 * @return identifer
+	 * @throws IOException
+	 */
+	String getIdentifier() throws IOException;
 
 }

Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/MailboxFactory.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/MailboxFactory.java?rev=1203577&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/MailboxFactory.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/MailboxFactory.java Fri Nov 18 10:42:13 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.IOException;
+
+/**
+ * 
+ *
+ */
+public interface MailboxFactory {
+
+	/**
+	 * Returns the {@link Mailbox} for the {@link POP3Session}. If the user does not exist or the password is not valid it will return <code>null</code>
+	 * 
+	 * @param user
+	 * @param password
+	 * @return mailbox or null if not valid user or password was given
+	 * @throws IOException
+	 */
+	public Mailbox getMailbox(POP3Session session, String password) throws IOException;
+	
+}

Added: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/MessageMetaData.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/MessageMetaData.java?rev=1203577&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/MessageMetaData.java (added)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/MessageMetaData.java Fri Nov 18 10:42:13 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;
+
+/**
+ * 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;
+    }
+}

Modified: 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=1203577&r1=1203576&r2=1203577&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CoreCmdHandlerLoader.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/CoreCmdHandlerLoader.java Fri Nov 18 10:42:13 2011
@@ -44,10 +44,6 @@ public class CoreCmdHandlerLoader implem
 
     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() {
@@ -69,9 +65,6 @@ public class CoreCmdHandlerLoader implem
         commands.add(UNKOWNCMDHANDLER);
         // add STARTTLS support to the core. See JAMES-1224
         commands.add(STLSCMDHANDLER);
-
-        // Add logging stuff
-        commands.add(COMMANDHANDLERRESULTLOGGER);
     }
 
     /**

Modified: 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=1203577&r1=1203576&r2=1203577&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/DeleCmdHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/DeleCmdHandler.java Fri Nov 18 10:42:13 2011
@@ -26,6 +26,7 @@ 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.MessageMetaData;
 import org.apache.james.protocols.pop3.POP3Response;
 import org.apache.james.protocols.pop3.POP3Session;
 

Modified: 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=1203577&r1=1203576&r2=1203577&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ExtraDotInputStream.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ExtraDotInputStream.java Fri Nov 18 10:42:13 2011
@@ -23,32 +23,30 @@ 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 {
+public class ExtraDotInputStream extends InputStream {
 
     boolean startLine = true;
     private int last;
+	private final PushbackInputStream in;
 
     public ExtraDotInputStream(InputStream in) {
-        super(new PushbackInputStream(in, 2));
+        this.in = new PushbackInputStream(in, 2);
         startLine = true;
     }
 
     
     @Override
     public int read() throws IOException {
-       PushbackInputStream pin = (PushbackInputStream) in;
-       int i = pin.read();
+       int i = in.read();
        if (startLine) {
            startLine = false;
            if (i == '.') {
-               pin.unread(i);
+        	   in.unread(i);
                return '.';
            }
            
@@ -63,4 +61,40 @@ public class ExtraDotInputStream extends
 
     }
 
+
+	@Override
+	public long skip(long n) throws IOException {
+		throw new IOException("Skip not supported");
+	}
+
+
+	@Override
+	public int available() throws IOException {
+		return in.available();
+	}
+
+
+	@Override
+	public void close() throws IOException {
+		in.close();
+	}
+
+
+	@Override
+	public void mark(int readlimit) {
+		// not supported
+	}
+
+
+	@Override
+	public void reset() throws IOException {
+		// not supported
+	}
+
+
+	@Override
+	public boolean markSupported() {
+		return false;
+	}
+
 }

Modified: 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=1203577&r1=1203576&r2=1203577&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ListCmdHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/ListCmdHandler.java Fri Nov 18 10:42:13 2011
@@ -23,11 +23,12 @@ 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;
+import org.apache.james.protocols.pop3.MessageMetaData;
+import org.apache.james.protocols.pop3.POP3Response;
+import org.apache.james.protocols.pop3.POP3Session;
 
 /**
  * Handles LIST command

Modified: 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=1203577&r1=1203576&r2=1203577&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/POP3CommandDispatcherLineHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/POP3CommandDispatcherLineHandler.java Fri Nov 18 10:42:13 2011
@@ -22,14 +22,9 @@ package org.apache.james.protocols.pop3.
 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;
+import org.apache.james.protocols.pop3.POP3Session;
 
 /**
  * Dispatch POP3 {@link CommandHandler}
@@ -37,13 +32,7 @@ import org.apache.james.protocols.api.ha
 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()
      */
@@ -65,21 +54,4 @@ public class POP3CommandDispatcherLineHa
         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;
-    }
-
 }

Modified: 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=1203577&r1=1203576&r2=1203577&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/PassCmdHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/PassCmdHandler.java Fri Nov 18 10:42:13 2011
@@ -19,23 +19,18 @@
 
 package org.apache.james.protocols.pop3.core;
 
+import java.io.IOException;
 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;
+import org.apache.james.protocols.pop3.Mailbox;
+import org.apache.james.protocols.pop3.MailboxFactory;
+import org.apache.james.protocols.pop3.POP3Response;
+import org.apache.james.protocols.pop3.POP3Session;
 
 /**
  * Handles PASS command
@@ -43,10 +38,9 @@ import org.apache.james.protocols.lib.PO
 public class PassCmdHandler extends RsetCmdHandler {
 
     private final static String COMMAND_NAME = "PASS";
-    private MailboxManager mailboxManager;
+    private MailboxFactory mailboxManager;
 
-    @Resource(name = "mailboxmanager")
-    public void setMailboxManager(MailboxManager manager) {
+    public void setMailboxFactory(MailboxFactory manager) {
         this.mailboxManager = manager;
     }
 
@@ -60,35 +54,19 @@ public class PassCmdHandler extends Rset
         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);
+                Mailbox mailbox = mailboxManager.getMailbox(session, passArg);
+                if (mailbox != null) {
+                	session.setUserMailbox(mailbox);
+                	stat(session);
+                
+                	StringBuilder responseBuffer = new StringBuilder(64).append("Welcome ").append(session.getUser());
+                	response = new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString());
+                	session.setHandlerState(POP3Session.TRANSACTION);
+                } else {
+                	response = new POP3Response(POP3Response.ERR_RESPONSE, "Authentication failed.");
+                	session.setHandlerState(POP3Session.AUTHENTICATION_READY);
                 }
-                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) {
+            } catch (IOException 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);

Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/QuitCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/QuitCmdHandler.java?rev=1203577&r1=1203576&r2=1203577&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/QuitCmdHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/QuitCmdHandler.java Fri Nov 18 10:42:13 2011
@@ -23,31 +23,18 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
-import javax.annotation.Resource;
-import javax.mail.Flags;
-
-import org.apache.james.mailbox.MessageManager;
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageRange;
-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.api.handler.CommandHandler;
+import org.apache.james.protocols.pop3.Mailbox;
+import org.apache.james.protocols.pop3.POP3Response;
+import org.apache.james.protocols.pop3.POP3Session;
 
 /**
  * Handles QUIT command
  */
 public class QuitCmdHandler implements CommandHandler<POP3Session> {
     private final static String COMMAND_NAME = "QUIT";
-    protected MailboxManager mailboxManager;
-
-    @Resource(name = "mailboxmanager")
-    public void setMailboxManager(MailboxManager manager) {
-        this.mailboxManager = manager;
-    }
 
     /**
      * Handler method called upon receipt of a QUIT command. This method handles
@@ -61,29 +48,21 @@ public class QuitCmdHandler implements C
             response.setEndSession(true);
             return response;
         }
-        MailboxSession mailboxSession = (MailboxSession) session.getState().get(POP3Session.MAILBOX_SESSION);
-
         List<Long> toBeRemoved = (List<Long>) session.getState().get(POP3Session.DELETED_UID_LIST);
         try {
-            MessageManager mailbox = session.getUserMailbox();
-
-            for (int i = 0; i < toBeRemoved.size(); i++) {
-                MessageRange range = MessageRange.one(toBeRemoved.get(i));
-                mailbox.setFlags(new Flags(Flags.Flag.DELETED), true, false, range, mailboxSession);
-                mailbox.expunge(range, mailboxSession);
+            Mailbox mailbox = session.getUserMailbox();
+            long uids[] = new long[toBeRemoved.size()];
+            for (int i = 0;i < toBeRemoved.size(); i++) {
+            	uids[i] = toBeRemoved.get(i);
             }
+            mailbox.remove(uids);
             response = new POP3Response(POP3Response.OK_RESPONSE, "Apache James POP3 Server signing off.");
         } catch (Exception ex) {
             response = new POP3Response(POP3Response.ERR_RESPONSE, "Some deleted messages were not removed");
             session.getLogger().error("Some deleted messages were not removed", ex);
         }
         response.setEndSession(true);
-        try {
-            mailboxManager.logout(mailboxSession, false);
-        } catch (MailboxException e) {
-            // nothing todo on logout
-        }
-
+      
         return response;
     }
 

Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RetrCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RetrCmdHandler.java?rev=1203577&r1=1203576&r2=1203577&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RetrCmdHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RetrCmdHandler.java Fri Nov 18 10:42:13 2011
@@ -23,23 +23,15 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Set;
 
-import org.apache.james.mailbox.Content;
-import org.apache.james.mailbox.MailboxException;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageRange;
-import org.apache.james.mailbox.MessageResult;
-import org.apache.james.mailbox.MessageResult.FetchGroup;
-import org.apache.james.pop3server.POP3Response;
-import org.apache.james.pop3server.POP3Session;
-import org.apache.james.pop3server.POP3StreamResponse;
 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.MessageMetaData;
+import org.apache.james.protocols.pop3.POP3Response;
+import org.apache.james.protocols.pop3.POP3Session;
+import org.apache.james.protocols.pop3.POP3StreamResponse;
 
 /**
  * Handles RETR command
@@ -47,19 +39,7 @@ import org.apache.james.protocols.api.ha
 public class RetrCmdHandler implements CommandHandler<POP3Session> {
 
     private final static String COMMAND_NAME = "RETR";
-    private final static FetchGroup GROUP = new FetchGroup() {
 
-        @Override
-        public int content() {
-            return FULL_CONTENT;
-        }
-
-        @Override
-        public Set<PartContentDescriptor> getPartContentDescriptors() {
-            return null;
-        }
-        
-    };
     /**
      * Handler method called upon receipt of a RETR command. This command
      * retrieves a particular mail message from the mailbox.
@@ -80,16 +60,14 @@ public class RetrCmdHandler implements C
                 List<MessageMetaData> uidList = (List<MessageMetaData>) session.getState().get(POP3Session.UID_LIST);
                 List<Long> deletedUidList = (List<Long>) session.getState().get(POP3Session.DELETED_UID_LIST);
 
-                MailboxSession mailboxSession = (MailboxSession) session.getState().get(POP3Session.MAILBOX_SESSION);
                 Long uid = uidList.get(num - 1).getUid();
                 if (deletedUidList.contains(uid) == false) {
-                    Iterator<MessageResult> results = session.getUserMailbox().getMessages(MessageRange.one(uid), GROUP, mailboxSession);
+                	
+                    InputStream content = session.getUserMailbox().getMessageContent(uid);
 
-                    if (results.hasNext()) {
-                        MessageResult result = results.next();
+                    if (content != null) {
 
-                        Content content = result.getFullContent();                           
-                        InputStream in = new CRLFTerminatedInputStream(new ExtraDotInputStream(content.getInputStream()));
+                        InputStream in = new CRLFTerminatedInputStream(new ExtraDotInputStream(content));
                         response = new POP3StreamResponse(POP3Response.OK_RESPONSE, "Message follows", in);
                         return response;
 
@@ -106,14 +84,6 @@ public class RetrCmdHandler implements C
                 }
             } catch (IOException ioe) {
                 response = new POP3Response(POP3Response.ERR_RESPONSE, "Error while retrieving message.");
-            } catch (MailboxException me) {
-                response = new POP3Response(POP3Response.ERR_RESPONSE, "Error while retrieving message.");
-            } catch (IndexOutOfBoundsException iob) {
-                StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
-                response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
-            } catch (NoSuchElementException e) {
-                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);

Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RsetCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RsetCmdHandler.java?rev=1203577&r1=1203576&r2=1203577&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RsetCmdHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/RsetCmdHandler.java Fri Nov 18 10:42:13 2011
@@ -19,22 +19,18 @@
 
 package org.apache.james.protocols.pop3.core;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
 
-import org.apache.james.mailbox.MailboxException;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageRange;
-import org.apache.james.mailbox.MessageResult;
-import org.apache.james.mailbox.MessageResult.FetchGroup;
-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;
+import org.apache.james.protocols.pop3.MessageMetaData;
+import org.apache.james.protocols.pop3.POP3Response;
+import org.apache.james.protocols.pop3.POP3Session;
 
 /**
  * Handles RSET command
@@ -42,20 +38,6 @@ import org.apache.james.protocols.api.ha
 public class RsetCmdHandler implements CommandHandler<POP3Session> {
     private final static String COMMAND_NAME = "RSET";
 
-    private final static FetchGroup GROUP = new FetchGroup() {
-
-        @Override
-        public int content() {
-            return MINIMAL;
-        }
-
-        @Override
-        public Set<PartContentDescriptor> getPartContentDescriptors() {
-            return null;
-        }
-        
-    };
-    
     /**
      * Handler method called upon receipt of a RSET command. Calls stat() to
      * reset the mailbox.
@@ -79,18 +61,11 @@ public class RsetCmdHandler implements C
      */
     protected void stat(POP3Session session) {
         try {
-            MailboxSession mailboxSession = (MailboxSession) session.getState().get(POP3Session.MAILBOX_SESSION);
-
-            List<MessageMetaData> uids = new ArrayList<MessageMetaData>();
-            Iterator<MessageResult> it = session.getUserMailbox().getMessages(MessageRange.all(), GROUP, mailboxSession);
-            while (it.hasNext()) {
-                MessageResult result = it.next();
-                uids.add(new MessageMetaData(result.getUid(), result.getSize()));
+            List<MessageMetaData> messages = session.getUserMailbox().getMessages();
 
-            }
-            session.getState().put(POP3Session.UID_LIST, uids);
+            session.getState().put(POP3Session.UID_LIST, messages);
             session.getState().put(POP3Session.DELETED_UID_LIST, new ArrayList<Long>());
-        } catch (MailboxException e) {
+        } catch (IOException e) {
             // In the event of an exception being thrown there may or may not be
             // anything in userMailbox
             session.getLogger().error("Unable to STAT mail box ", e);

Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/StatCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/StatCmdHandler.java?rev=1203577&r1=1203576&r2=1203577&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/StatCmdHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/StatCmdHandler.java Fri Nov 18 10:42:13 2011
@@ -23,11 +23,12 @@ 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;
+import org.apache.james.protocols.pop3.MessageMetaData;
+import org.apache.james.protocols.pop3.POP3Response;
+import org.apache.james.protocols.pop3.POP3Session;
 
 /**
  * Handles STAT command

Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/TopCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/TopCmdHandler.java?rev=1203577&r1=1203576&r2=1203577&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/TopCmdHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/TopCmdHandler.java Fri Nov 18 10:42:13 2011
@@ -19,49 +19,26 @@
 
 package org.apache.james.protocols.pop3.core;
 
-import java.io.ByteArrayInputStream;
-import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.SequenceInputStream;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 import java.util.NoSuchElementException;
-import java.util.Set;
 
-import org.apache.james.mailbox.MailboxException;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageRange;
-import org.apache.james.mailbox.MessageResult;
-import org.apache.james.mailbox.MessageResult.FetchGroup;
-import org.apache.james.pop3server.POP3Response;
-import org.apache.james.pop3server.POP3Session;
-import org.apache.james.pop3server.POP3StreamResponse;
 import org.apache.james.protocols.api.Request;
 import org.apache.james.protocols.api.Response;
+import org.apache.james.protocols.pop3.MessageMetaData;
+import org.apache.james.protocols.pop3.POP3Response;
+import org.apache.james.protocols.pop3.POP3Session;
+import org.apache.james.protocols.pop3.POP3StreamResponse;
 
 /**
  * Handles TOP command
  */
 public class TopCmdHandler extends RetrCmdHandler implements CapaCapability {
     private final static String COMMAND_NAME = "TOP";
-    private final static FetchGroup GROUP = new FetchGroup() {
 
-        @Override
-        public int content() {
-            return BODY_CONTENT | HEADERS;
-        }
-
-        @Override
-        public Set<PartContentDescriptor> getPartContentDescriptors() {
-            return null;
-        }
-        
-    };
     
     /**
      * Handler method called upon receipt of a TOP command. This command
@@ -102,20 +79,14 @@ public class TopCmdHandler extends RetrC
                 List<MessageMetaData> uidList = (List<MessageMetaData>) session.getState().get(POP3Session.UID_LIST);
                 List<Long> deletedUidList = (List<Long>) session.getState().get(POP3Session.DELETED_UID_LIST);
 
-                MailboxSession mailboxSession = (MailboxSession) session.getState().get(POP3Session.MAILBOX_SESSION);
                 Long uid = uidList.get(num - 1).getUid();
                 if (deletedUidList.contains(uid) == false) {
 
-                    Iterator<MessageResult> results = session.getUserMailbox().getMessages(MessageRange.one(uid), GROUP, mailboxSession);
+                    InputStream content = session.getUserMailbox().getMessageContent(uid);
 
-                    if (results.hasNext()) {
-                        MessageResult result = results.next();
+                    if (content != null) {
+                        InputStream in = new CountingBodyInputStream(new ExtraDotInputStream(new CRLFTerminatedInputStream(content)), lines);
 
-                        InputStream headersIn = result.getHeaders().getInputStream();
-                        InputStream bodyIn = new CountingBodyInputStream(new ExtraDotInputStream(new CRLFTerminatedInputStream(result.getBody().getInputStream())), lines);
-
-                        // write body
-                        InputStream in = new SequenceInputStream(Collections.enumeration(Arrays.asList(headersIn, new ByteArrayInputStream("\r\n".getBytes()), bodyIn)));
 
                         response = new POP3StreamResponse(POP3Response.OK_RESPONSE, "Message follows", in);
                         return response;
@@ -131,8 +102,7 @@ public class TopCmdHandler extends RetrC
                 }
             } catch (IOException ioe) {
                 response = new POP3Response(POP3Response.ERR_RESPONSE, "Error while retrieving message.");
-            } catch (MailboxException me) {
-                response = new POP3Response(POP3Response.ERR_RESPONSE, "Error while retrieving message.");
+            
             } catch (IndexOutOfBoundsException iob) {
                 StringBuilder exceptionBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
                 response = new POP3Response(POP3Response.ERR_RESPONSE, exceptionBuffer.toString());
@@ -172,11 +142,13 @@ public class TopCmdHandler extends RetrC
      * This {@link InputStream} implementation can be used to limit the body
      * lines which will be read from the wrapped {@link InputStream}
      */
-    private final class CountingBodyInputStream extends FilterInputStream {
+    // TODO: Fix me!
+    private final class CountingBodyInputStream extends InputStream {
 
         private int count = 0;
         private int limit = -1;
         private int lastChar;
+		private InputStream in;
 
         /**
          * 
@@ -186,7 +158,7 @@ public class TopCmdHandler extends RetrC
          *            the lines to read. -1 is used for no limits
          */
         public CountingBodyInputStream(InputStream in, int limit) {
-            super(in);
+            this.in = in;
             this.limit = limit;
         }
 
@@ -211,36 +183,36 @@ public class TopCmdHandler extends RetrC
 
         }
 
-        @Override
-        public int read(byte[] b, int off, int len) throws IOException {
-            if (limit == -1) {
-                return in.read(b, off, len);
-            } else {
-                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 {
-            if (limit == -1) {
-                return in.read(b);
-            } else {
-                return read(b, 0, b.length);
-            }
-        }
-
+		@Override
+		public long skip(long n) throws IOException {
+			return in.skip(n);
+		}
+
+		@Override
+		public int available() throws IOException {
+			return in.available();
+		}
+
+		@Override
+		public void close() throws IOException {
+			in.close();
+		}
+
+		@Override
+		public void mark(int readlimit) {
+			// not supported
+		}
+
+		@Override
+		public synchronized void reset() throws IOException {
+			// do nothing as mark is not supported
+		}
+
+		@Override
+		public boolean markSupported() {
+			return false;
+		}
+        
+        
     }
 }

Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/UidlCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/UidlCmdHandler.java?rev=1203577&r1=1203576&r2=1203577&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/UidlCmdHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/UidlCmdHandler.java Fri Nov 18 10:42:13 2011
@@ -19,19 +19,18 @@
 
 package org.apache.james.protocols.pop3.core;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
-import org.apache.james.mailbox.MailboxException;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageManager.MetaData;
-import org.apache.james.mailbox.MessageManager.MetaData.FetchGroup;
-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;
+import org.apache.james.protocols.pop3.MessageMetaData;
+import org.apache.james.protocols.pop3.POP3Response;
+import org.apache.james.protocols.pop3.POP3Session;
 
 /**
  * Handles UIDL command
@@ -50,17 +49,15 @@ public class UidlCmdHandler implements C
         if (session.getHandlerState() == POP3Session.TRANSACTION) {
             List<MessageMetaData> uidList = (List<MessageMetaData>) session.getState().get(POP3Session.UID_LIST);
             List<Long> deletedUidList = (List<Long>) session.getState().get(POP3Session.DELETED_UID_LIST);
-            MailboxSession mailboxSession = (MailboxSession) session.getState().get(POP3Session.MAILBOX_SESSION);
             try {
-                MetaData mData = session.getUserMailbox().getMetaData(false, mailboxSession, FetchGroup.NO_COUNT);
-                long validity = mData.getUidValidity();
+                String identifier = session.getUserMailbox().getIdentifier();
                 if (parameters == null) {
                     response = new POP3Response(POP3Response.OK_RESPONSE, "unique-id listing follows");
                     for (int i = 0; i < uidList.size(); i++) {
                         Long uid = uidList.get(i).getUid();
                         if (deletedUidList.contains(uid) == false) {
                             // construct unique UIDL. See JAMES-1264
-                            StringBuilder responseBuffer = new StringBuilder(64).append(i + 1).append(" ").append(validity).append("-").append(uid);
+                            StringBuilder responseBuffer = new StringBuilder(64).append(i + 1).append(" ").append(identifier).append("-").append(uid);
                             response.appendLine(responseBuffer.toString());
                         }
                     }
@@ -73,7 +70,7 @@ public class UidlCmdHandler implements C
                         Long uid = uidList.get(num - 1).getUid();
                         if (deletedUidList.contains(uid) == false) {
                             // construct unique UIDL. See JAMES-1264
-                            StringBuilder responseBuffer = new StringBuilder(64).append(num).append(" ").append(validity).append("-").append(uid);
+                            StringBuilder responseBuffer = new StringBuilder(64).append(num).append(" ").append(identifier).append("-").append(uid);
                             response = new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString());
 
                         } else {
@@ -88,7 +85,7 @@ public class UidlCmdHandler implements C
                         response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                     }
                 }
-            } catch (MailboxException e) {
+            } catch (IOException e) {
                 response = new POP3Response(POP3Response.ERR_RESPONSE);
                 return response;
             }

Modified: james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/UserCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/UserCmdHandler.java?rev=1203577&r1=1203576&r2=1203577&view=diff
==============================================================================
--- james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/UserCmdHandler.java (original)
+++ james/protocols/trunk/pop3/src/main/java/org/apache/james/protocols/pop3/core/UserCmdHandler.java Fri Nov 18 10:42:13 2011
@@ -23,11 +23,11 @@ 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;
+import org.apache.james.protocols.pop3.POP3Response;
+import org.apache.james.protocols.pop3.POP3Session;
 
 /**
  * Handles NOOP command



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