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 ba...@apache.org on 2006/05/08 23:58:27 UTC

svn commit: r405184 [2/2] - /james/server/trunk/src/java/org/apache/james/pop3server/

Added: james/server/trunk/src/java/org/apache/james/pop3server/PassCmdHandler.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/pop3server/PassCmdHandler.java?rev=405184&view=auto
==============================================================================
--- james/server/trunk/src/java/org/apache/james/pop3server/PassCmdHandler.java (added)
+++ james/server/trunk/src/java/org/apache/james/pop3server/PassCmdHandler.java Mon May  8 14:58:26 2006
@@ -0,0 +1,66 @@
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.pop3server;
+
+/**
+  * Handles PASS command
+  */
+public class PassCmdHandler implements CommandHandler {
+
+    /**
+     * @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
+     */
+    public void onCommand(POP3Session session) {
+        doPASS(session,session.getCommandArgument());
+    }
+
+    /**
+     * Handler method called upon receipt of a PASS command.
+     * Reads in and validates the password.
+     *
+     * @param command the command parsed by the parseCommand method
+     * @param argument the first argument parsed by the parseCommand method
+     */
+    private void doPASS(POP3Session session,String argument) {
+        String responseString = null;
+        if (session.getHandlerState() == POP3Handler.AUTHENTICATION_USERSET && argument != null) {
+            String passArg = argument;
+            if (session.getConfigurationData().getUsersRepository().test(session.getUser(), passArg)) {
+                StringBuffer responseBuffer =
+                    new StringBuffer(64)
+                            .append(POP3Handler.OK_RESPONSE)
+                            .append(" Welcome ")
+                            .append(session.getUser());
+                responseString = responseBuffer.toString();
+                session.setHandlerState(POP3Handler.TRANSACTION);
+                session.writeResponse(responseString);
+                session.setUserInbox(session.getConfigurationData().getMailServer().getUserInbox(session.getUser()));
+                session.stat();
+            } else {
+                responseString = POP3Handler.ERR_RESPONSE + " Authentication failed.";
+                session.setHandlerState(POP3Handler.AUTHENTICATION_READY);
+                session.writeResponse(responseString);
+            }
+        } else {
+            responseString = POP3Handler.ERR_RESPONSE;
+            session.writeResponse(responseString);
+        }
+    }
+
+
+}

Propchange: james/server/trunk/src/java/org/apache/james/pop3server/PassCmdHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/server/trunk/src/java/org/apache/james/pop3server/QuitCmdHandler.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/pop3server/QuitCmdHandler.java?rev=405184&view=auto
==============================================================================
--- james/server/trunk/src/java/org/apache/james/pop3server/QuitCmdHandler.java (added)
+++ james/server/trunk/src/java/org/apache/james/pop3server/QuitCmdHandler.java Mon May  8 14:58:26 2006
@@ -0,0 +1,69 @@
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.pop3server;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.commons.collections.ListUtils;
+
+import java.util.List;
+
+/**
+  * Handles QUIT command
+  */
+public class QuitCmdHandler extends AbstractLogEnabled implements CommandHandler {
+
+    /**
+     * @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
+     */
+    public void onCommand(POP3Session session) {
+        doQUIT(session,session.getCommandArgument());
+    }
+
+    /**
+     * Handler method called upon receipt of a QUIT command.
+     * This method handles cleanup of the POP3Handler state.
+     *
+     * @param command the command parsed by the parseCommand method
+     * @param argument the first argument parsed by the parseCommand method
+     */
+    private void doQUIT(POP3Session session,String argument) {
+        String responseString = null;
+        if (session.getHandlerState() == POP3Handler.AUTHENTICATION_READY ||  session.getHandlerState() == POP3Handler.AUTHENTICATION_USERSET) {
+            responseString = POP3Handler.OK_RESPONSE + " Apache James POP3 Server signing off.";
+            session.writeResponse(responseString);
+            return;
+        }
+        List toBeRemoved =  ListUtils.subtract(session.getBackupUserMailbox(), session.getUserMailbox());
+        try {
+            session.getUserInbox().remove(toBeRemoved);
+            // for (Iterator it = toBeRemoved.iterator(); it.hasNext(); ) {
+            //    Mail mc = (Mail) it.next();
+            //    userInbox.remove(mc.getName());
+            //}
+            responseString = POP3Handler.OK_RESPONSE + " Apache James POP3 Server signing off.";
+            session.writeResponse(responseString);
+        } catch (Exception ex) {
+            responseString = POP3Handler.ERR_RESPONSE + " Some deleted messages were not removed";
+            session.writeResponse(responseString);
+            getLogger().error("Some deleted messages were not removed: " + ex.getMessage());
+        }
+        session.endSession();
+    }
+
+
+}

Propchange: james/server/trunk/src/java/org/apache/james/pop3server/QuitCmdHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/server/trunk/src/java/org/apache/james/pop3server/RetrCmdHandler.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/pop3server/RetrCmdHandler.java?rev=405184&view=auto
==============================================================================
--- james/server/trunk/src/java/org/apache/james/pop3server/RetrCmdHandler.java (added)
+++ james/server/trunk/src/java/org/apache/james/pop3server/RetrCmdHandler.java Mon May  8 14:58:26 2006
@@ -0,0 +1,111 @@
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.pop3server;
+
+import org.apache.james.util.ExtraDotOutputStream;
+import org.apache.james.util.watchdog.BytesWrittenResetOutputStream;
+import org.apache.mailet.Mail;
+
+import javax.mail.MessagingException;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+  * Handles RETR command
+  */
+public class RetrCmdHandler implements CommandHandler {
+
+    /**
+     * @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
+     */
+    public void onCommand(POP3Session session) {
+        doRETR(session,session.getCommandArgument());
+    }
+
+    /**
+     * Handler method called upon receipt of a RETR command.
+     * This command retrieves a particular mail message from the
+     * mailbox.
+     *
+     * @param command the command parsed by the parseCommand method
+     * @param argument the first argument parsed by the parseCommand method
+     */
+    private void doRETR(POP3Session session,String argument) {
+        String responseString = null;
+        if (session.getHandlerState() == POP3Handler.TRANSACTION) {
+            int num = 0;
+            try {
+                num = Integer.parseInt(argument.trim());
+            } catch (Exception e) {
+                responseString = POP3Handler.ERR_RESPONSE + " Usage: RETR [mail number]";
+                session.writeResponse(responseString);
+                return;
+            }
+            try {
+                Mail mc = (Mail) session.getUserMailbox().get(num);
+                if (mc != POP3Handler.DELETED) {
+                    responseString = POP3Handler.OK_RESPONSE + " Message follows";
+                    session.writeResponse(responseString);
+                    try {
+                        ExtraDotOutputStream edouts =
+                                new ExtraDotOutputStream(session.getOutputStream());
+                        OutputStream nouts = new BytesWrittenResetOutputStream(edouts,
+                                                                  session.getWatchdog(),
+                                                                  session.getConfigurationData().getResetLength());
+                        mc.getMessage().writeTo(nouts);
+                        nouts.flush();
+                        edouts.checkCRLFTerminator();
+                        edouts.flush();
+                    } finally {
+                        session.writeResponse(".");
+                    }
+                } else {
+                    StringBuffer responseBuffer =
+                        new StringBuffer(64)
+                                .append(POP3Handler.ERR_RESPONSE)
+                                .append(" Message (")
+                                .append(num)
+                                .append(") already deleted.");
+                    responseString = responseBuffer.toString();
+                    session.writeResponse(responseString);
+                }
+            } catch (IOException ioe) {
+                responseString = POP3Handler.ERR_RESPONSE + " Error while retrieving message.";
+                session.writeResponse(responseString);
+            } catch (MessagingException me) {
+                responseString = POP3Handler.ERR_RESPONSE + " Error while retrieving message.";
+                session.writeResponse(responseString);
+            } catch (IndexOutOfBoundsException iob) {
+                StringBuffer responseBuffer =
+                    new StringBuffer(64)
+                            .append(POP3Handler.ERR_RESPONSE)
+                            .append(" Message (")
+                            .append(num)
+                            .append(") does not exist.");
+                responseString = responseBuffer.toString();
+                session.writeResponse(responseString);
+            }
+        } else {
+            responseString = POP3Handler.ERR_RESPONSE;
+            session.writeResponse(responseString);
+        }
+    }
+
+
+}

Propchange: james/server/trunk/src/java/org/apache/james/pop3server/RetrCmdHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/server/trunk/src/java/org/apache/james/pop3server/RsetCmdHandler.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/pop3server/RsetCmdHandler.java?rev=405184&view=auto
==============================================================================
--- james/server/trunk/src/java/org/apache/james/pop3server/RsetCmdHandler.java (added)
+++ james/server/trunk/src/java/org/apache/james/pop3server/RsetCmdHandler.java Mon May  8 14:58:26 2006
@@ -0,0 +1,52 @@
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.pop3server;
+
+
+/**
+  * Handles RSET command
+  */
+public class RsetCmdHandler implements CommandHandler {
+
+    /**
+     * @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
+     */
+    public void onCommand(POP3Session session) {
+        doRSET(session,session.getCommandArgument());
+    }
+
+    /**
+     * Handler method called upon receipt of a RSET command.
+     * Calls stat() to reset the mailbox.
+     *
+     * @param command the command parsed by the parseCommand method
+     * @param argument the first argument parsed by the parseCommand method
+     */
+    private void doRSET(POP3Session session,String argument) {
+        String responseString = null;
+        if (session.getHandlerState() == POP3Handler.TRANSACTION) {
+            session.stat();
+            responseString = POP3Handler.OK_RESPONSE;
+        } else {
+            responseString = POP3Handler.ERR_RESPONSE;
+        }
+        session.writeResponse(responseString);
+    }
+
+
+}

Propchange: james/server/trunk/src/java/org/apache/james/pop3server/RsetCmdHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/server/trunk/src/java/org/apache/james/pop3server/StatCmdHandler.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/pop3server/StatCmdHandler.java?rev=405184&view=auto
==============================================================================
--- james/server/trunk/src/java/org/apache/james/pop3server/StatCmdHandler.java (added)
+++ james/server/trunk/src/java/org/apache/james/pop3server/StatCmdHandler.java Mon May  8 14:58:26 2006
@@ -0,0 +1,79 @@
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.pop3server;
+
+import org.apache.mailet.Mail;
+
+import javax.mail.MessagingException;
+
+import java.util.Iterator;
+
+/**
+  * Handles STAT command
+  */
+public class StatCmdHandler implements CommandHandler {
+
+    /**
+     * @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
+     */
+    public void onCommand(POP3Session session) {
+        doSTAT(session,session.getCommandArgument());
+    }
+
+    /**
+     * Handler method called upon receipt of a STAT command.
+     * Returns the number of messages in the mailbox and its
+     * aggregate size.
+     *
+     * @param command the command parsed by the parseCommand method
+     * @param argument the first argument parsed by the parseCommand method
+     */
+    private void doSTAT(POP3Session session,String argument) {
+        String responseString = null;
+        if (session.getHandlerState() == POP3Handler.TRANSACTION) {
+            long size = 0;
+            int count = 0;
+            try {
+                for (Iterator i = session.getUserMailbox().iterator(); i.hasNext(); ) {
+                    Mail mc = (Mail) i.next();
+                    if (mc != POP3Handler.DELETED) {
+                        size += mc.getMessageSize();
+                        count++;
+                    }
+                }
+                StringBuffer responseBuffer =
+                    new StringBuffer(32)
+                            .append(POP3Handler.OK_RESPONSE)
+                            .append(" ")
+                            .append(count)
+                            .append(" ")
+                            .append(size);
+                responseString = responseBuffer.toString();
+                session.writeResponse(responseString);
+            } catch (MessagingException me) {
+                responseString = POP3Handler.ERR_RESPONSE;
+                session.writeResponse(responseString);
+            }
+        } else {
+            responseString = POP3Handler.ERR_RESPONSE;
+            session.writeResponse(responseString);
+        }
+    }
+
+
+}

Propchange: james/server/trunk/src/java/org/apache/james/pop3server/StatCmdHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/server/trunk/src/java/org/apache/james/pop3server/TopCmdHandler.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/pop3server/TopCmdHandler.java?rev=405184&view=auto
==============================================================================
--- james/server/trunk/src/java/org/apache/james/pop3server/TopCmdHandler.java (added)
+++ james/server/trunk/src/java/org/apache/james/pop3server/TopCmdHandler.java Mon May  8 14:58:26 2006
@@ -0,0 +1,163 @@
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.pop3server;
+
+import org.apache.james.util.ExtraDotOutputStream;
+import org.apache.james.util.watchdog.BytesWrittenResetOutputStream;
+import org.apache.mailet.Mail;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.util.Enumeration;
+
+/**
+  * Handles TOP command
+  */
+public class TopCmdHandler implements CommandHandler {
+
+    /**
+     * @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
+     */
+    public void onCommand(POP3Session session) {
+        doTOP(session,session.getCommandArgument());
+    }
+
+    /**
+     * Handler method called upon receipt of a TOP command.
+     * This command retrieves the top N lines of a specified
+     * message in the mailbox.
+     *
+     * The expected command format is
+     *  TOP [mail message number] [number of lines to return]
+     *
+     * @param command the command parsed by the parseCommand method
+     * @param argument the first argument parsed by the parseCommand method
+     */
+    private void doTOP(POP3Session session,String arguments) {
+        String argument = "";
+        String argument1 = "";
+        int pos = arguments.indexOf(" ");
+        if (pos > 0) {
+            argument = arguments.substring(0,pos);
+            argument1 = arguments.substring(pos+1);
+        }
+        String responseString = null;
+        if (session.getHandlerState() == POP3Handler.TRANSACTION) {
+            int num = 0;
+            int lines = 0;
+            try {
+                num = Integer.parseInt(argument);
+                lines = Integer.parseInt(argument1);
+            } catch (NumberFormatException nfe) {
+                responseString = POP3Handler.ERR_RESPONSE + " Usage: TOP [mail number] [Line number]";
+                session.writeResponse(responseString);
+                return;
+            }
+            try {
+                Mail mc = (Mail) session.getUserMailbox().get(num);
+                if (mc != POP3Handler.DELETED) {
+                    responseString = POP3Handler.OK_RESPONSE + " Message follows";
+                    session.writeResponse(responseString);
+                    try {
+                        for (Enumeration e = mc.getMessage().getAllHeaderLines(); e.hasMoreElements(); ) {
+                            session.writeResponse(e.nextElement().toString());
+                        }
+                        session.writeResponse("");
+                        ExtraDotOutputStream edouts =
+                                new ExtraDotOutputStream(session.getOutputStream());
+                        OutputStream nouts = new BytesWrittenResetOutputStream(edouts,
+                                                                  session.getWatchdog(),
+                                                                  session.getConfigurationData().getResetLength());
+                        writeMessageContentTo(mc.getMessage(),nouts,lines);
+                        nouts.flush();
+                        edouts.checkCRLFTerminator();
+                        edouts.flush();
+                    } finally {
+                        session.writeResponse(".");
+                    }
+                } else {
+                    StringBuffer responseBuffer =
+                        new StringBuffer(64)
+                                .append(POP3Handler.ERR_RESPONSE)
+                                .append(" Message (")
+                                .append(num)
+                                .append(") already deleted.");
+                    responseString = responseBuffer.toString();
+                    session.writeResponse(responseString);
+                }
+            } catch (IOException ioe) {
+                responseString = POP3Handler.ERR_RESPONSE + " Error while retrieving message.";
+                session.writeResponse(responseString);
+            } catch (MessagingException me) {
+                responseString = POP3Handler.ERR_RESPONSE + " Error while retrieving message.";
+                session.writeResponse(responseString);
+            } catch (IndexOutOfBoundsException iob) {
+                StringBuffer exceptionBuffer =
+                    new StringBuffer(64)
+                            .append(POP3Handler.ERR_RESPONSE)
+                            .append(" Message (")
+                            .append(num)
+                            .append(") does not exist.");
+                responseString = exceptionBuffer.toString();
+                session.writeResponse(responseString);
+            }
+        } else {
+            responseString = POP3Handler.ERR_RESPONSE;
+            session.writeResponse(responseString);
+        }
+    }
+
+
+    /**
+     * Writes the content of the message, up to a total number of lines, out to 
+     * an OutputStream.
+     *
+     * @param out the OutputStream to which to write the content
+     * @param lines the number of lines to write to the stream
+     *
+     * @throws MessagingException if the MimeMessage is not set for this MailImpl
+     * @throws IOException if an error occurs while reading or writing from the stream
+     */
+    public void writeMessageContentTo(MimeMessage message, OutputStream out, int lines)
+        throws IOException, MessagingException {
+        String line;
+        BufferedReader br;
+        if (message != null) {
+            br = new BufferedReader(new InputStreamReader(message.getRawInputStream()));
+            try {
+                while (lines-- > 0) {
+                    if ((line = br.readLine()) == null) {
+                        break;
+                    }
+                    line += "\r\n";
+                    out.write(line.getBytes());
+                }
+            } finally {
+                br.close();
+            }
+        } else {
+            throw new MessagingException("No message set for this MailImpl.");
+        }
+    }
+
+}

Propchange: james/server/trunk/src/java/org/apache/james/pop3server/TopCmdHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/server/trunk/src/java/org/apache/james/pop3server/UidlCmdHandler.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/pop3server/UidlCmdHandler.java?rev=405184&view=auto
==============================================================================
--- james/server/trunk/src/java/org/apache/james/pop3server/UidlCmdHandler.java (added)
+++ james/server/trunk/src/java/org/apache/james/pop3server/UidlCmdHandler.java Mon May  8 14:58:26 2006
@@ -0,0 +1,113 @@
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.pop3server;
+
+import org.apache.mailet.Mail;
+
+import java.util.Iterator;
+
+/**
+  * Handles UIDL command
+  */
+public class UidlCmdHandler implements CommandHandler {
+
+    /**
+     * @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
+     */
+    public void onCommand(POP3Session session) {
+        doUIDL(session,session.getCommandArgument());
+    }
+
+    /**
+     * Handler method called upon receipt of a UIDL command.
+     * Returns a listing of message ids to the client.
+     *
+     * @param command the command parsed by the parseCommand method
+     * @param argument the first argument parsed by the parseCommand method
+     */
+    private void doUIDL(POP3Session session,String argument) {
+        String responseString = null;
+        if (session.getHandlerState() == POP3Handler.TRANSACTION) {
+            if (argument == null) {
+                responseString = POP3Handler.OK_RESPONSE + " unique-id listing follows";
+                session.writeResponse(responseString);
+                int count = 0;
+                for (Iterator i = session.getUserMailbox().iterator(); i.hasNext(); count++) {
+                    Mail mc = (Mail) i.next();
+                    if (mc != POP3Handler.DELETED) {
+                        StringBuffer responseBuffer =
+                            new StringBuffer(64)
+                                    .append(count)
+                                    .append(" ")
+                                    .append(mc.getName());
+                        session.writeResponse(responseBuffer.toString());
+                    }
+                }
+                session.writeResponse(".");
+            } else {
+                int num = 0;
+                try {
+                    num = Integer.parseInt(argument);
+                    Mail mc = (Mail) session.getUserMailbox().get(num);
+                    if (mc != POP3Handler.DELETED) {
+                        StringBuffer responseBuffer =
+                            new StringBuffer(64)
+                                    .append(POP3Handler.OK_RESPONSE)
+                                    .append(" ")
+                                    .append(num)
+                                    .append(" ")
+                                    .append(mc.getName());
+                        responseString = responseBuffer.toString();
+                        session.writeResponse(responseString);
+                    } else {
+                        StringBuffer responseBuffer =
+                            new StringBuffer(64)
+                                    .append(POP3Handler.ERR_RESPONSE)
+                                    .append(" Message (")
+                                    .append(num)
+                                    .append(") already deleted.");
+                        responseString = responseBuffer.toString();
+                        session.writeResponse(responseString);
+                    }
+                } catch (IndexOutOfBoundsException npe) {
+                    StringBuffer responseBuffer =
+                        new StringBuffer(64)
+                                .append(POP3Handler.ERR_RESPONSE)
+                                .append(" Message (")
+                                .append(num)
+                                .append(") does not exist.");
+                    responseString = responseBuffer.toString();
+                    session.writeResponse(responseString);
+                } catch (NumberFormatException nfe) {
+                    StringBuffer responseBuffer =
+                        new StringBuffer(64)
+                                .append(POP3Handler.ERR_RESPONSE)
+                                .append(" ")
+                                .append(argument)
+                                .append(" is not a valid number");
+                    responseString = responseBuffer.toString();
+                    session.writeResponse(responseString);
+                }
+            }
+        } else {
+            session.writeResponse(POP3Handler.ERR_RESPONSE);
+        }
+    }
+
+
+}

Propchange: james/server/trunk/src/java/org/apache/james/pop3server/UidlCmdHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/server/trunk/src/java/org/apache/james/pop3server/UnknownCmdHandler.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/pop3server/UnknownCmdHandler.java?rev=405184&view=auto
==============================================================================
--- james/server/trunk/src/java/org/apache/james/pop3server/UnknownCmdHandler.java (added)
+++ james/server/trunk/src/java/org/apache/james/pop3server/UnknownCmdHandler.java Mon May  8 14:58:26 2006
@@ -0,0 +1,41 @@
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.pop3server;
+
+
+/**
+  * Default command handler for handling unknown commands
+  */
+public class UnknownCmdHandler implements CommandHandler {
+
+    /**
+     * The name of the command handled by the command handler
+     */
+    public static final String UNKNOWN_COMMAND = "UNKNOWN";
+
+    /**
+     * Handler method called upon receipt of an unrecognized command.
+     * Returns an error response and logs the command.
+     *
+     * @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
+    **/
+    public void onCommand(POP3Session session) {
+        session.writeResponse(POP3Handler.ERR_RESPONSE);
+    }
+
+}

Propchange: james/server/trunk/src/java/org/apache/james/pop3server/UnknownCmdHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/server/trunk/src/java/org/apache/james/pop3server/UserCmdHandler.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/pop3server/UserCmdHandler.java?rev=405184&view=auto
==============================================================================
--- james/server/trunk/src/java/org/apache/james/pop3server/UserCmdHandler.java (added)
+++ james/server/trunk/src/java/org/apache/james/pop3server/UserCmdHandler.java Mon May  8 14:58:26 2006
@@ -0,0 +1,52 @@
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.pop3server;
+
+/**
+  * Handles NOOP command
+  */
+public class UserCmdHandler implements CommandHandler {
+
+    /**
+     * @see org.apache.james.pop3server.CommandHandler#onCommand(POP3Session)
+     */
+    public void onCommand(POP3Session session) {
+        doUSER(session,session.getCommandArgument());
+    }
+
+    /**
+     * Handler method called upon receipt of a USER command.
+     * Reads in the user id.
+     *
+     * @param command the command parsed by the parseCommand method
+     * @param argument the first argument parsed by the parseCommand method
+     */
+    private void doUSER(POP3Session session,String argument) {
+        String responseString = null;
+        if (session.getHandlerState() == POP3Handler.AUTHENTICATION_READY && argument != null) {
+            session.setUser(argument);
+            session.setHandlerState(POP3Handler.AUTHENTICATION_USERSET);
+            responseString = POP3Handler.OK_RESPONSE;
+        } else {
+            responseString = POP3Handler.ERR_RESPONSE;
+        }
+        session.writeResponse(responseString);
+    }
+
+
+}

Propchange: james/server/trunk/src/java/org/apache/james/pop3server/UserCmdHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native



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