geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickmcgu...@apache.org
Subject svn commit: r414173 [3/7] - in /geronimo/javamail/trunk: ./ javamail-provider-1.3/ javamail-provider-1.3/src/ javamail-provider-1.3/src/java/ javamail-provider-1.3/src/java/org/ javamail-provider-1.3/src/java/org/apache/ javamail-provider-1.3/src/java/...
Date Wed, 14 Jun 2006 10:18:55 GMT
Added: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/RangeList.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/RangeList.java?rev=414173&view=auto
==============================================================================
--- geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/RangeList.java (added)
+++ geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/RangeList.java Wed Jun 14 03:18:51 2006
@@ -0,0 +1,225 @@
+/**
+ *
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ *  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.geronimo.javamail.store.nntp.newsrc;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+/**
+ * Manage a list of ranges values from a newsrc file.
+ */
+public class RangeList {
+    boolean dirty = false;
+
+    ArrayList ranges = new ArrayList();
+
+    /**
+     * Create a RangeList instance from a newsrc range line. Values are saved as
+     * a comma separated set of range values. A range value is either a single
+     * number or a hypenated pair of numbers.
+     * 
+     * @param line
+     *            The newsrc range line.
+     */
+    public RangeList(String line) {
+
+        // we might be creating an first time list, so nothing to parse.
+        if (line != null) {
+            // ranges are comma delimited tokens
+            StringTokenizer tokenizer = new StringTokenizer(line, ",");
+
+            while (tokenizer.hasMoreTokens()) {
+                String rangeString = (String) tokenizer.nextToken();
+                rangeString = rangeString.trim();
+                if (rangeString.length() != 0) {
+                    Range range = Range.parse(rangeString);
+                    if (range != null) {
+                        insert(range);
+                    }
+                }
+            }
+        }
+        // make sure we start out in a clean state. Any changes from this point
+        // will flip on the dirty flat.
+        dirty = false;
+    }
+
+    /**
+     * Insert a range item into our list. If possible, the inserted range will
+     * be merged with existing ranges.
+     * 
+     * @param newRange
+     *            The new range item.
+     */
+    public void insert(Range newRange) {
+        // first find the insertion point
+        for (int i = 0; i < ranges.size(); i++) {
+            Range range = (Range) ranges.get(i);
+            // does an existing range fully contain the new range, we don't need
+            // to insert anything.
+            if (range.contains(newRange)) {
+                return;
+            }
+
+            // does the current one abutt or overlap with the inserted range?
+            if (range.abutts(newRange) || range.overlaps(newRange)) {
+                // rats, we have an overlap...and it is possible that we could
+                // overlap with
+                // the next range after this one too. Therefore, we merge these
+                // two ranges together,
+                // remove the place where we're at, and then recursively insert
+                // the larger range into
+                // the list.
+                dirty = true;
+                newRange.merge(range);
+                ranges.remove(i);
+                insert(newRange);
+                return;
+            }
+
+            // ok, we don't touch the current one at all. If it is completely
+            // above
+            // range we're adding, we can just poke this into the list here.
+            if (newRange.lessThan(range)) {
+                dirty = true;
+                ranges.add(i, newRange);
+                return;
+            }
+        }
+        dirty = true;
+        // this is easy (and fairly common)...we just tack this on to the end.
+        ranges.add(newRange);
+    }
+
+    /**
+     * Test if a given article point falls within one of the contained Ranges.
+     * 
+     * @param article
+     *            The test point.
+     * 
+     * @return true if this falls within one of our current mark Ranges, false
+     *         otherwise.
+     */
+    public boolean isMarked(int article) {
+        for (int i = 0; i < ranges.size(); i++) {
+            Range range = (Range) ranges.get(i);
+            if (range.contains(article)) {
+                return true;
+            }
+            // we've passed the point where a match is possible.
+            if (range.greaterThan(article)) {
+                return false;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Mark a target article as having been seen.
+     * 
+     * @param article
+     *            The target article number.
+     */
+    public void setMarked(int article) {
+        // go through the insertion logic.
+        insert(new Range(article, article));
+    }
+
+    /**
+     * Clear the seen mark for a target article.
+     * 
+     * @param article
+     *            The target article number.
+     */
+    public void setUnmarked(int article) {
+        for (int i = 0; i < ranges.size(); i++) {
+            Range range = (Range) ranges.get(i);
+            // does this fall within an existing range? We don't need to do
+            // anything here.
+            if (range.contains(article)) {
+                // ok, we've found where to insert, now to figure out how to
+                // insert
+                // article is at the beginning of the range. We can just
+                // increment the lower
+                // bound, or if this is a single element range, we can remove it
+                // entirely.
+                if (range.getStart() == article) {
+                    if (range.getEnd() == article) {
+                        // piece of cake!
+                        ranges.remove(i);
+                    } else {
+                        // still pretty easy.
+                        range.setStart(article + 1);
+                    }
+                } else if (range.getEnd() == article) {
+                    // pretty easy also
+                    range.setEnd(article - 1);
+                } else {
+                    // split this into two ranges and insert the trailing piece
+                    // after this.
+                    Range section = range.split(article);
+                    ranges.add(i + 1, section);
+                }
+                dirty = true;
+                return;
+            }
+            // did we find a point where any articles are greater?
+            if (range.greaterThan(article)) {
+                // nothing to do
+                return;
+            }
+        }
+        // didn't find it at all. That was easy!
+    }
+
+    /**
+     * Save this List of Ranges out to a .newsrc file. This creates a
+     * comma-separated list of range values from each of the Ranges.
+     * 
+     * @param out
+     *            The target output stream.
+     * 
+     * @exception IOException
+     */
+    public void save(Writer out) throws IOException {
+        // we have an empty list
+        if (ranges.size() == 0) {
+            return;
+        }
+
+        Range range = (Range) ranges.get(0);
+        range.save(out);
+
+        for (int i = 1; i < ranges.size(); i++) {
+            out.write(",");
+            range = (Range) ranges.get(i);
+            range.save(out);
+        }
+    }
+
+    /**
+     * Return the state of the dirty flag.
+     * 
+     * @return True if the range list information has changed, false otherwise.
+     */
+    public boolean isDirty() {
+        return dirty;
+    }
+}

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/RangeList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/RangeList.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/nntp/newsrc/RangeList.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Command.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Command.java?rev=414173&view=auto
==============================================================================
--- geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Command.java (added)
+++ geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Command.java Wed Jun 14 03:18:51 2006
@@ -0,0 +1,40 @@
+/**
+ *
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ *  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.geronimo.javamail.store.pop3;
+
+/**
+ * An abstraction for POP3Commands
+ * 
+ * @see org.apache.geronimo.javamail.store.pop3.POP3CommandFactory
+ * 
+ * @version $Rev$ $Date$
+ */
+public interface POP3Command {
+
+    /**
+     * This method will get the POP3 command in string format according o
+     * rfc1939
+     */
+    public String getCommand();
+
+    /**
+     * Indicates wether this command expects a multiline response or not
+     * 
+     */
+    public boolean isMultiLineResponse();
+}

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Command.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Command.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Command.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3CommandFactory.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3CommandFactory.java?rev=414173&view=auto
==============================================================================
--- geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3CommandFactory.java (added)
+++ geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3CommandFactory.java Wed Jun 14 03:18:51 2006
@@ -0,0 +1,186 @@
+/**
+ *
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ *  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.geronimo.javamail.store.pop3;
+
+/**
+ * Provides concrete implementations of
+ * org.apache.geronimo.javamail.store.pop3.POP3Command objects representing the
+ * POP3 commands defined in rfc 1939
+ * 
+ * @link http://www.faqs.org/rfcs/rfc1939.html
+ * @version $Rev$ $Date$
+ */
+public final class POP3CommandFactory implements POP3Constants {
+
+    public static POP3Command getCOMMAND_USER(final String user) {
+        return new POP3Command() {
+            public String getCommand() {
+                return "USER" + SPACE + user + CRLF;
+            }
+
+            public boolean isMultiLineResponse() {
+                return false;
+            }
+        };
+    }
+
+    public static POP3Command getCOMMAND_PASS(final String passwd) {
+        return new POP3Command() {
+            public String getCommand() {
+                return "PASS" + SPACE + passwd + CRLF;
+            }
+
+            public boolean isMultiLineResponse() {
+                return false;
+            }
+        };
+    }
+
+    public static POP3Command getCOMMAND_QUIT() {
+        return new POP3Command() {
+            public String getCommand() {
+                return "QUIT" + CRLF;
+            }
+
+            public boolean isMultiLineResponse() {
+                return false;
+            }
+        };
+    }
+
+    public static POP3Command getCOMMAND_NOOP() {
+        return new POP3Command() {
+            public String getCommand() {
+                return "NOOP" + CRLF;
+            }
+
+            public boolean isMultiLineResponse() {
+                return false;
+            }
+        };
+    }
+
+    public static POP3Command getCOMMAND_STAT() {
+        return new POP3Command() {
+            public String getCommand() {
+                return "STAT" + CRLF;
+            }
+
+            public boolean isMultiLineResponse() {
+                return false;
+            }
+        };
+    }
+
+    public static POP3Command getCOMMAND_LIST() {
+        return getCOMMAND_LIST(-1);
+    }
+
+    public static POP3Command getCOMMAND_LIST(final int msgNo) {
+        return new POP3Command() {
+            public String getCommand() {
+                if (msgNo > 0) {
+                    return "LIST" + SPACE + msgNo + CRLF;
+                } else {
+                    return "LIST" + CRLF;
+                }
+            }
+
+            /**
+             * If a msg num is specified then the the message details will be on
+             * the first line for ex. +OK 3 4520
+             * 
+             * if no msgnum is specified then all the msg details are return in
+             * a multiline format for ex. +OK 2 messages 1 456 2 46456 ..... n
+             * 366
+             */
+            public boolean isMultiLineResponse() {
+                return (msgNo < 0);
+            }
+        };
+    }
+
+    public static POP3Command getCOMMAND_RETR(final int msgNo) {
+        return new POP3Command() {
+            public String getCommand() {
+                return "RETR" + SPACE + msgNo + CRLF;
+            }
+
+            public boolean isMultiLineResponse() {
+                return true;
+            }
+        };
+    }
+
+    public static POP3Command getCOMMAND_DELE(final int msgNo) {
+        return new POP3Command() {
+            public String getCommand() {
+                return "DELE" + SPACE + msgNo + CRLF;
+            }
+
+            public boolean isMultiLineResponse() {
+                return false;
+            }
+        };
+    }
+
+    public static POP3Command getCOMMAND_REST(final int msgNo) {
+        return new POP3Command() {
+            public String getCommand() {
+                return "REST" + SPACE + msgNo + CRLF;
+            }
+
+            public boolean isMultiLineResponse() {
+                return false;
+            }
+        };
+    }
+
+    public static POP3Command getCOMMAND_TOP(final int msgNo, final int numLines) {
+        return new POP3Command() {
+            public String getCommand() {
+                return "TOP" + SPACE + msgNo + SPACE + numLines + CRLF;
+            }
+
+            public boolean isMultiLineResponse() {
+                return true;
+            }
+        };
+    }
+
+    public static POP3Command getCOMMAND_UIDL() {
+        return getCOMMAND_UIDL(-1);
+    }
+
+    public static POP3Command getCOMMAND_UIDL(final int msgNo) {
+        return new POP3Command() {
+            public String getCommand() {
+                if (msgNo > 0) {
+                    return "UIDL" + SPACE + msgNo + CRLF;
+                } else {
+                    return "UIDL" + CRLF;
+                }
+            }
+
+            public boolean isMultiLineResponse() {
+                return true;
+            }
+        };
+    }
+
+}

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3CommandFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3CommandFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3CommandFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Connection.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Connection.java?rev=414173&view=auto
==============================================================================
--- geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Connection.java (added)
+++ geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Connection.java Wed Jun 14 03:18:51 2006
@@ -0,0 +1,153 @@
+/**
+ *
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ *  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.geronimo.javamail.store.pop3;
+
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+
+import javax.mail.MessagingException;
+import javax.mail.Session;
+
+/**
+ * Represents a connection with the POP3 mail server. The connection is owned by
+ * a pop3 store and is only associated with one user who owns the respective
+ * POP3Store instance
+ * 
+ * @version $Rev$ $Date$
+ */
+
+public class POP3Connection {
+
+    private Socket soc;
+
+    private Session session;
+
+    private String host;
+
+    private int port;
+
+    private PrintWriter writer;
+
+    private BufferedReader reader;
+
+    POP3Connection(Session session, String host, int port) {
+
+        this.session = session;
+        this.host = host;
+        this.port = port;
+    }
+
+    public void open() throws Exception {
+        try {
+            soc = new Socket();
+            soc.connect(new InetSocketAddress(host, port));
+
+            if (session.getDebug()) {
+                session.getDebugOut().println("Connection successful " + this.toString());
+            }
+
+            buildInputReader();
+            buildOutputWriter();
+
+            // consume the greeting
+            if (session.getDebug()) {
+                session.getDebugOut().println("Greeting from server " + reader.readLine());
+            } else {
+                reader.readLine();
+            }
+
+        } catch (IOException e) {
+            Exception ex = new Exception("Error opening connection " + this.toString(), e);
+            throw ex;
+        }
+    }
+
+    void close() throws Exception {
+        try {
+            soc.close();
+            if (session.getDebug()) {
+                session.getDebugOut().println("Connection successfuly closed " + this.toString());
+            }
+
+        } catch (IOException e) {
+            Exception ex = new Exception("Error closing connection " + this.toString(), e);
+            throw ex;
+        }
+
+    }
+
+    public synchronized POP3Response sendCommand(POP3Command cmd) throws MessagingException {
+        if (soc.isConnected()) {
+
+            // if the underlying output stream is down
+            // attempt to rebuild the writer
+            if (soc.isOutputShutdown()) {
+                buildOutputWriter();
+            }
+
+            // if the underlying inout stream is down
+            // attempt to rebuild the reader
+            if (soc.isInputShutdown()) {
+                buildInputReader();
+            }
+
+            if (session.getDebug()) {
+                session.getDebugOut().println("\nCommand sent " + cmd.getCommand());
+            }
+
+            POP3Response res = null;
+
+            // this method supresses IOException
+            // but choose bcos of ease of use
+            {
+                writer.write(cmd.getCommand());
+                writer.flush();
+                res = POP3ResponseBuilder.buildResponse(session, reader, cmd.isMultiLineResponse());
+            }
+
+            return res;
+        }
+
+        throw new MessagingException("Connection to Mail Server is lost, connection " + this.toString());
+    }
+
+    private void buildInputReader() throws MessagingException {
+        try {
+            reader = new BufferedReader(new InputStreamReader(soc.getInputStream()));
+        } catch (IOException e) {
+            throw new MessagingException("Error obtaining input stream " + this.toString(), e);
+        }
+    }
+
+    private void buildOutputWriter() throws MessagingException {
+        try {
+            writer = new PrintWriter(new BufferedOutputStream(soc.getOutputStream()));
+        } catch (IOException e) {
+            throw new MessagingException("Error obtaining output stream " + this.toString(), e);
+        }
+    }
+
+    public String toString() {
+        return "POP3Connection host: " + host + " port: " + port;
+    }
+}

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Connection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Connection.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Connection.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Constants.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Constants.java?rev=414173&view=auto
==============================================================================
--- geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Constants.java (added)
+++ geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Constants.java Wed Jun 14 03:18:51 2006
@@ -0,0 +1,40 @@
+/**
+ *
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ *  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.geronimo.javamail.store.pop3;
+
+/**
+ * Defines a few constants that are used throught the implementation.
+ * 
+ * @version $Rev$ $Date$
+ */
+
+public interface POP3Constants {
+    public final static String SPACE = " ";
+
+    public final static String CRLF = "\r\n";
+
+    public final static int LF = '\n';
+
+    public final static int CR = '\r';
+
+    public final static int DOT = '.';
+
+    public final static int OK = 0;
+
+    public final static int ERR = 1;
+}
\ No newline at end of file

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Constants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Constants.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Constants.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Folder.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Folder.java?rev=414173&view=auto
==============================================================================
--- geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Folder.java (added)
+++ geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Folder.java Wed Jun 14 03:18:51 2006
@@ -0,0 +1,340 @@
+/**
+ *
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ *  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.geronimo.javamail.store.pop3;
+
+import java.util.Vector;
+
+import javax.mail.FetchProfile;
+import javax.mail.Flags;
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.MethodNotSupportedException;
+import javax.mail.Session;
+import javax.mail.Store;
+import javax.mail.URLName;
+import javax.mail.event.ConnectionEvent;
+
+import org.apache.geronimo.javamail.store.pop3.message.POP3Message;
+import org.apache.geronimo.javamail.store.pop3.message.POP3MessageFactory;
+import org.apache.geronimo.javamail.store.pop3.response.POP3ResponseFactory;
+import org.apache.geronimo.javamail.store.pop3.response.POP3StatusResponse;
+
+/**
+ * The POP3 implementation of the javax.mail.Folder Note that only INBOX is
+ * supported in POP3
+ * <p>
+ * <url>http://www.faqs.org/rfcs/rfc1939.html</url>
+ * </p>
+ * 
+ * @see javax.mail.Folder
+ * 
+ * @version $Rev$ $Date$
+ */
+public class POP3Folder extends Folder {
+
+    private boolean isFolderOpen = false;
+
+    private int mode;
+
+    private POP3Connection pop3Con;
+
+    private int msgCount;
+
+    private Session session;
+
+    /**
+     * Vector is synchronized so choose over the other Collection impls This is
+     * initialized on open A chache will save the expensive operation of
+     * retrieving the message again from the server.
+     */
+    private Vector msgCache;
+
+    protected POP3Folder(Store store, URLName url) {
+        super(store);
+    }
+
+    protected POP3Folder(Store store, Session session, POP3Connection pop3Con) {
+        super(store);
+        this.pop3Con = pop3Con;
+        this.session = session;
+    }
+
+    public String getName() {
+        return "INBOX";
+    }
+
+    public String getFullName() {
+        return "INBOX";
+    }
+
+    /**
+     * Never return "this" as the parent folder. Somebody not familliar with
+     * POP3 may do something like while(getParent() != null) or something
+     * simmilar which will result in an infinte loop
+     */
+    public Folder getParent() throws MessagingException {
+        throw new MethodNotSupportedException("INBOX is the root folder");
+    }
+
+    public boolean exists() throws MessagingException {
+        // INBOX always exists at the backend
+        return true;
+    }
+
+    public Folder[] list(String pattern) throws MessagingException {
+        throw new MethodNotSupportedException("Only INBOX is supported in POP3, no sub folders");
+    }
+
+    /**
+     * No sub folders, hence there is no notion of a seperator
+     */
+    public char getSeparator() throws MessagingException {
+        throw new MethodNotSupportedException("Only INBOX is supported in POP3, no sub folders");
+    }
+
+    public int getType() throws MessagingException {
+        return HOLDS_MESSAGES;
+    }
+
+    public boolean create(int type) throws MessagingException {
+        throw new MethodNotSupportedException("Only INBOX is supported in POP3, no sub folders");
+    }
+
+    public boolean hasNewMessages() throws MessagingException {
+        throw new MethodNotSupportedException("POP3 doesn't support this operation");
+    }
+
+    public Folder getFolder(String name) throws MessagingException {
+        throw new MethodNotSupportedException("Only INBOX is supported in POP3, no sub folders");
+    }
+
+    public boolean delete(boolean recurse) throws MessagingException {
+        throw new MethodNotSupportedException("Only INBOX is supported in POP3 and INBOX cannot be deleted");
+    }
+
+    public boolean renameTo(Folder f) throws MessagingException {
+        throw new MethodNotSupportedException("Only INBOX is supported in POP3 and INBOX cannot be renamed");
+    }
+
+    /**
+     * @see javax.mail.Folder#open(int)
+     */
+    public void open(int mode) throws MessagingException {
+        // Can only be performed on a closed folder
+        checkClosed();
+
+        try {
+
+            POP3StatusResponse res = (POP3StatusResponse) POP3ResponseFactory.getStatusResponse(pop3Con
+                    .sendCommand(POP3CommandFactory.getCOMMAND_STAT()));
+
+            // I am not checking for the res == null condition as the
+            // try catch block will handle it.
+
+            this.mode = mode;
+            this.isFolderOpen = true;
+            this.msgCount = res.getNumMessages();
+            // JavaMail API has no method in Folder to expose the total
+            // size (no of bytes) of the mail drop;
+
+            msgCache = new Vector(msgCount);
+            msgCache.setSize(msgCount);
+
+        } catch (Exception e) {
+            throw new MessagingException("Unable to execute STAT command", e);
+        }
+
+        notifyConnectionListeners(ConnectionEvent.OPENED);
+    }
+
+    public void close(boolean expunge) throws MessagingException {
+        // Can only be performed on an open folder
+        checkOpen();
+
+        try {
+            if (mode == READ_WRITE) {
+                // find all messages marked deleted and issue DELE commands
+                POP3Message m;
+                for (int i = 0; i < msgCache.size(); i++) {
+                    if ((m = (POP3Message) msgCache.elementAt(i)) != null) {
+                        if (m.isSet(Flags.Flag.DELETED)) {
+                            try {
+                                pop3Con.sendCommand(POP3CommandFactory.getCOMMAND_DELE(i + 1));
+                            } catch (Exception e) {
+                                throw new MessagingException("Exception deleting message no [" + (i + 1)
+                                        + "] during close", e);
+                            }
+                        }
+                    }
+                }
+            }
+
+            try {
+                pop3Con.sendCommand(POP3CommandFactory.getCOMMAND_QUIT());
+            } catch (Exception e) {
+                // doesn't really care about the response
+            }
+            // dosn't need a catch block here, but added incase something goes
+            // wrong
+            // so that the finnaly is garunteed to execute in such a case.
+        } finally {
+            try {
+                pop3Con.close();
+            } catch (Exception e) {
+                // doesn't really care about the response
+                // all we can do is to set the reference explicitly to null
+                pop3Con = null;
+            }
+
+            /*
+             * The message numbers depend on the mail drop if the connection is
+             * closed, then purge the cache
+             */
+            msgCache = null;
+            isFolderOpen = false;
+            notifyConnectionListeners(ConnectionEvent.CLOSED);
+        }
+    }
+
+    public boolean isOpen() {
+        return isFolderOpen;
+    }
+
+    public Flags getPermanentFlags() {
+        // unfortunately doesn't have a throws clause for this method
+        // throw new MethodNotSupportedException("POP3 doesn't support permanent
+        // flags");
+
+        // Better than returning null, save the extra condition from a user to
+        // check for null
+        // and avoids a NullPointerException for the careless.
+        return new Flags();
+    }
+
+    public int getMessageCount() throws MessagingException {
+        return msgCount;
+    }
+
+    /**
+     * Checks wether the message is in cache, if not will create a new message
+     * object and return it.
+     * 
+     * @see javax.mail.Folder#getMessage(int)
+     */
+    public Message getMessage(int msgNum) throws MessagingException {
+        // Can only be performed on an Open folder
+        checkOpen();
+        if (msgNum < 1 || msgNum > getMessageCount()) {
+            throw new MessagingException("Invalid Message number");
+        }
+
+        Message msg = null;
+        try {
+            msg = (Message) msgCache.elementAt(msgNum);
+        } catch (RuntimeException e) {
+            session.getDebugOut().println("Message not in cache");
+        }
+        if (msg == null) {
+            msg = POP3MessageFactory.createMessage(this, session, pop3Con, msgNum);
+            msgCache.setElementAt(msg, msgNum);
+        }
+
+        return msg;
+    }
+
+    public void appendMessages(Message[] msgs) throws MessagingException {
+        throw new MethodNotSupportedException("Message appending is not supported in POP3");
+
+    }
+
+    public Message[] expunge() throws MessagingException {
+        throw new MethodNotSupportedException("Expunge is not supported in POP3");
+    }
+
+    public int getMode() throws IllegalStateException {
+        // Can only be performed on an Open folder
+        checkOpen();
+        return mode;
+    }
+
+    /**
+     * @see javax.mail.Folder#fetch(javax.mail.Message[],
+     *      javax.mail.FetchProfile)
+     * 
+     * The JavaMail API recommends that this method be overrident to provide a
+     * meaningfull implementation.
+     */
+    public void fetch(Message[] msgs, FetchProfile fp) throws MessagingException {
+        // Can only be performed on an Open folder
+        checkOpen();
+        for (int i = 0; i < msgs.length; i++) {
+            Message msg = msgs[i];
+            if (msg == null) {
+                msg = POP3MessageFactory.createMessage(this, session, pop3Con, i);
+            }
+            if (fp.contains(FetchProfile.Item.ENVELOPE)) {
+                msg = POP3MessageFactory.createMessageWithEvelope((POP3Message) msg);
+            }
+
+            if (fp.contains(FetchProfile.Item.CONTENT_INFO)) {
+                msg = POP3MessageFactory.createMessageWithContentInfo((POP3Message) msg);
+            }
+
+            if (fp.contains(FetchProfile.Item.FLAGS)) {
+                msg = POP3MessageFactory.createMessageWithFlags((POP3Message) msg);
+            }
+
+            msgs[i] = msg;
+        }
+    }
+
+    /**
+     * Below is a list of covinience methods that avoid repeated checking for a
+     * value and throwing an exception
+     */
+
+    /** Ensure the folder is open */
+    private void checkOpen() throws IllegalStateException {
+        if (!isFolderOpen) {
+            throw new IllegalStateException("Folder is not Open");
+        }
+    }
+
+    /** Ensure the folder is not open */
+    private void checkClosed() throws IllegalStateException {
+        if (isFolderOpen) {
+            throw new IllegalStateException("Folder is Open");
+        }
+    }
+
+    /**
+     * @see javax.mail.Folder#notifyMessageChangedListeners(int,
+     *      javax.mail.Message)
+     * 
+     * this method is protected and cannot be used outside of Folder, therefore
+     * had to explicitly expose it via a method in POP3Folder, so that
+     * POP3Message has access to it
+     * 
+     * Bad design on the part of the Java Mail API.
+     */
+    public void notifyMessageChangedListeners(int type, Message m) {
+        super.notifyMessageChangedListeners(type, m);
+    }
+
+}

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Folder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Folder.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Folder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Response.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Response.java?rev=414173&view=auto
==============================================================================
--- geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Response.java (added)
+++ geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Response.java Wed Jun 14 03:18:51 2006
@@ -0,0 +1,61 @@
+/**
+ *
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ *  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.geronimo.javamail.store.pop3;
+
+import java.io.InputStream;
+
+/**
+ * An abstraction for POP3 Response
+ * 
+ * @see org.apache.geronimo.javamail.store.pop3.response.POP3ResponseFactory
+ * @see org.apache.geronimo.javamail.store.pop3.response.DefaultPOP3Response
+ * @see org.apache.geronimo.javamail.store.pop3.response.POP3StatusResponse
+ * 
+ * @version $Rev$ $Date$
+ */
+public interface POP3Response {
+
+    /**
+     * Returns the response OK or ERR
+     * <ul>
+     * <li>OK --> +OK in pop3 spec
+     * <li>ERR --> -ERR in pop3 spec
+     * </ul>
+     */
+    public int getStatus();
+
+    /**
+     * this corresponds to the line with the status however the status will be
+     * removed and the remainder is returned. Ex. "+OK 132 3023673" is the first
+     * line of response for a STAT command this method will return "132 3023673"
+     * 
+     * So any subsequent process can parse the params 132 as no of msgs and
+     * 3023674 as the size.
+     * 
+     * @see org.apache.geronimo.javamail.store.pop3.response.POP3StatusResponse
+     */
+    public String getFirstLine();
+
+    /**
+     * This way we are not restricting anybody as InputStream.class is the most
+     * basic type to represent an inputstream and ppl can decorate it anyway
+     * they want, for ex BufferedInputStream or as an InputStreamReader allowing
+     * maximum flexibility in using it.
+     */
+    public InputStream getData();
+}

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Response.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Response.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Response.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3ResponseBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3ResponseBuilder.java?rev=414173&view=auto
==============================================================================
--- geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3ResponseBuilder.java (added)
+++ geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3ResponseBuilder.java Wed Jun 14 03:18:51 2006
@@ -0,0 +1,128 @@
+/**
+ *
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ *  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.geronimo.javamail.store.pop3;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.mail.MessagingException;
+import javax.mail.Session;
+
+import org.apache.geronimo.javamail.store.pop3.response.POP3ResponseFactory;
+
+;
+
+/**
+ * Builds a basic response out of the input stream received by the connection.
+ * Performs only two basic functions
+ * <ul>
+ * <li>Extrats the status code</li>
+ * <li>If multi-line response then extract the data as an input stream</li>
+ * </ul>
+ * 
+ * @version $Rev$ $Date$
+ */
+
+public final class POP3ResponseBuilder implements POP3Constants {
+
+    public static POP3Response buildResponse(Session session, BufferedReader reader, boolean isMultiLineResponse)
+            throws MessagingException {
+
+        int status = ERR;
+        InputStream data = null;
+
+        String line;
+        try {
+            line = reader.readLine();
+        } catch (IOException e) {
+            throw new MessagingException("Error in receving response");
+        }
+        if (line == null || line.trim().equals("")) {
+            if (session.getDebug()) {
+                session.getDebugOut().println("Empty Response");
+            }
+            throw new MessagingException("Empty Response");
+        }
+        if (session.getDebug()) {
+            session.getDebugOut().println("Response From Server " + line);
+        }
+
+        if (line.startsWith("+OK")) {
+            status = OK;
+            line = removeStatusField(line);
+            if (isMultiLineResponse) {
+                data = getMultiLineResponse(session, reader);
+            }
+        } else if (line.startsWith("-ERR")) {
+            status = ERR;
+            line = removeStatusField(line);
+        } else {
+            throw new MessagingException("Unexpected response: " + line);
+        }
+
+        return POP3ResponseFactory.getDefaultResponse(status, line, data);
+    }
+
+    private static String removeStatusField(String line) {
+        return line.substring(line.indexOf(SPACE) + 1);
+    }
+
+    /**
+     * This could be a multiline response
+     */
+    private static InputStream getMultiLineResponse(Session session, BufferedReader reader) throws MessagingException {
+
+        int byteRead = -1;
+        int lastByteRead = LF;
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        try {
+            while ((byteRead = reader.read()) >= 0) {
+                // We are checking for the end of a multiline response
+                // the format is .CRLF
+
+                // checking for the DOT and CR
+                if (lastByteRead == DOT && byteRead == CR) {
+                    byteRead = reader.read();
+                    // now checking for the LF of the second CRLF
+                    if (byteRead == LF) {
+                        // end of response
+                        break;
+                    }
+                }
+
+                out.write(byteRead);
+                lastByteRead = byteRead;
+            }
+
+            if (session.getDebug()) {
+                session.getDebugOut().println("\n============================ Response Content==================\n");
+                session.getDebugOut().write(out.toByteArray());
+                session.getDebugOut().println("\n==============================================================\n");
+            }
+
+        } catch (IOException e) {
+            throw new MessagingException("Error processing a multi-line response", e);
+        }
+
+        return new ByteArrayInputStream(out.toByteArray());
+    }
+
+}

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3ResponseBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3ResponseBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3ResponseBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Store.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Store.java?rev=414173&view=auto
==============================================================================
--- geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Store.java (added)
+++ geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Store.java Wed Jun 14 03:18:51 2006
@@ -0,0 +1,204 @@
+/**
+ *
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ *  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.geronimo.javamail.store.pop3;
+
+import javax.mail.AuthenticationFailedException;
+import javax.mail.Folder;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.Store;
+import javax.mail.URLName;
+
+/**
+ * POP3 implementation of javax.mail.Store POP protocol spec is implemented in
+ * org.apache.geronimo.javamail.store.pop3.POP3Connection
+ * 
+ * @version $Rev$ $Date$
+ */
+
+public class POP3Store extends Store {
+
+    private POP3Connection pop3Con;
+
+    public POP3Store(Session session, URLName urlName) {
+        super(session, urlName);
+    }
+
+    /**
+     * @see javax.mail.Store#getDefaultFolder()
+     * 
+     * There is only INBOX supported in POP3 so the default folder is inbox
+     */
+    public Folder getDefaultFolder() throws MessagingException {
+        return getFolder("INBOX");
+    }
+
+    /**
+     * @see javax.mail.Store#getFolder(java.lang.String)
+     */
+    public Folder getFolder(String name) throws MessagingException {
+
+        checkConnectionStatus();
+
+        if (!"INBOX".equalsIgnoreCase(name)) {
+            throw new MessagingException("Only INBOX is supported in POP3");
+        }
+        return new POP3Folder(this, session, pop3Con);
+    }
+
+    /**
+     * @see javax.mail.Store#getFolder(javax.mail.URLName)
+     */
+    public Folder getFolder(URLName url) throws MessagingException {
+        return getFolder(url.getFile());
+    }
+
+    /**
+     * @see javax.mail.Service#protocolConnect(java.lang.String, int,
+     *      java.lang.String, java.lang.String)
+     */
+    protected synchronized boolean protocolConnect(String host, int portNum, String user, String passwd)
+            throws MessagingException {
+
+        // Never store the user, passwd for security reasons
+
+        // if these values are null, no connection attempt should be made
+        if (host == null || passwd == null || user == null) {
+            return false;
+        }
+
+        // validate port num
+        if (portNum < 1) {
+            String portstring = session.getProperty("mail.pop3.port");
+            if (portstring != null) {
+                try {
+                    portNum = Integer.parseInt(portstring);
+                } catch (NumberFormatException e) {
+                    portNum = 110;
+                }
+            }
+        }
+
+        /*
+         * Obtaining a connection to the server.
+         * 
+         */
+        pop3Con = new POP3Connection(this.session, host, portNum);
+        try {
+            pop3Con.open();
+        } catch (Exception e) {
+            throw new MessagingException("Connection failed", e);
+        }
+
+        /*
+         * Sending the USER command with username
+         * 
+         */
+        POP3Response resUser = null;
+        try {
+            resUser = pop3Con.sendCommand(POP3CommandFactory.getCOMMAND_USER(user));
+        } catch (Exception e) {
+            throw new MessagingException("Connection failed", e);
+        }
+
+        if (POP3Constants.ERR == resUser.getStatus()) {
+
+            /*
+             * Authentication failed so sending QUIT
+             * 
+             */
+            try {
+                pop3Con.sendCommand(POP3CommandFactory.getCOMMAND_QUIT());
+            } catch (Exception e) {
+                // We don't care about the response or if any error happens
+                // just trying to comply with the spec.
+                // Most likely the server would have terminated the connection
+                // by now.
+            }
+
+            throw new AuthenticationFailedException(resUser.getFirstLine());
+        }
+
+        /*
+         * Sending the PASS command with password
+         * 
+         */
+        POP3Response resPwd = null;
+        try {
+            resPwd = pop3Con.sendCommand(POP3CommandFactory.getCOMMAND_PASS(passwd));
+        } catch (Exception e) {
+            throw new MessagingException("Connection failed", e);
+        }
+
+        if (POP3Constants.ERR == resPwd.getStatus()) {
+
+            /*
+             * Authentication failed so sending QUIT
+             * 
+             */
+            try {
+                pop3Con.sendCommand(POP3CommandFactory.getCOMMAND_QUIT());
+            } catch (Exception e) {
+                // We don't care about the response or if any error happens
+                // just trying to comply with the spec.
+                // Most likely the server would have terminated the connection
+                // by now.
+            }
+
+            throw new AuthenticationFailedException(resPwd.getFirstLine());
+        }
+
+        return true;
+    }
+
+    /**
+     * @see javax.mail.Service#isConnected()
+     */
+    public boolean isConnected() {
+        POP3Response res = null;
+        try {
+            res = pop3Con.sendCommand(POP3CommandFactory.getCOMMAND_NOOP());
+        } catch (Exception e) {
+            return false;
+        }
+
+        return (POP3Constants.OK == res.getStatus());
+    }
+
+    /**
+     * @see javax.mail.Service#close()
+     */
+    public void close() throws MessagingException {
+        // This is done to ensure proper event notification.
+        super.close();
+        try {
+            pop3Con.close();
+        } catch (Exception e) {
+            // A message is already set at the connection level
+            // unfortuantely there is no constructor that takes only
+            // the root exception
+            new MessagingException("", e);
+        }
+    }
+
+    private void checkConnectionStatus() throws MessagingException {
+        if (!this.isConnected()) {
+            throw new MessagingException("Not connected ");
+        }
+    }
+}

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Store.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Store.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/POP3Store.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3Message.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3Message.java?rev=414173&view=auto
==============================================================================
--- geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3Message.java (added)
+++ geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3Message.java Wed Jun 14 03:18:51 2006
@@ -0,0 +1,261 @@
+/**
+ *
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ *  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.geronimo.javamail.store.pop3.message;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+
+import javax.mail.Flags;
+import javax.mail.Folder;
+import javax.mail.IllegalWriteException;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.event.MessageChangedEvent;
+import javax.mail.internet.InternetHeaders;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.geronimo.javamail.store.pop3.POP3CommandFactory;
+import org.apache.geronimo.javamail.store.pop3.POP3Connection;
+import org.apache.geronimo.javamail.store.pop3.POP3Folder;
+import org.apache.geronimo.javamail.store.pop3.POP3Response;
+import org.apache.geronimo.javamail.store.pop3.response.POP3ListResponse;
+import org.apache.geronimo.javamail.store.pop3.response.POP3ResponseFactory;
+
+/**
+ * POP3 implementation of javax.mail.internet.MimeMessage
+ * 
+ * Only the most basic information is given and Message objects created here is
+ * a light-weight reference to the actual Message As per the JavaMail spec items
+ * from the actual message will get filled up on demand
+ * 
+ * If some other items are obtained from the server as a result of one call,
+ * then the other details are also processed and filled in. For ex if RETR is
+ * called then header information will also be processed in addition to the
+ * content
+ * 
+ * @version $Rev$ $Date$
+ */
+public class POP3Message extends MimeMessage {
+
+    private POP3Connection pop3Con;
+
+    private int msgSize = -1;
+
+    private int headerSize = -1;
+
+    // We can't use header bcos it's already initialize to
+    // to an empty InternetHeader
+    private InputStream rawHeaders;
+
+    // used to force loading of headers again
+    private boolean loadHeaders = true;
+
+    // to get accessed to the debug setting and log
+    private Session session;
+
+    protected POP3Message(Folder folder, int msgnum, Session session, POP3Connection pop3Con) {
+        super(folder, msgnum);
+        this.pop3Con = pop3Con;
+        this.session = session;
+    }
+
+    /**
+     * @see javax.mail.internet.MimeMessage#getContentStream()
+     */
+    protected InputStream getContentStream() throws MessagingException {
+        POP3Response msgResponse = null;
+        try {
+            msgResponse = pop3Con.sendCommand(POP3CommandFactory.getCOMMAND_RETR(msgnum));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        loadHeaders = true;
+        loadHeaders(msgResponse.getData());
+        loadContent(msgResponse.getData());
+
+        return contentStream;
+    }
+
+    public void setFlags(Flags newFlags, boolean set) throws MessagingException {
+        Flags oldFlags = (Flags) flags.clone();
+        super.setFlags(newFlags, set);
+
+        if (!flags.equals(oldFlags)) {
+            ((POP3Folder) folder).notifyMessageChangedListeners(MessageChangedEvent.FLAGS_CHANGED, this);
+        }
+    }
+
+    protected void loadHeaders(InputStream in) throws MessagingException {
+        if (loadHeaders || rawHeaders == null) {
+            rawHeaders = in;
+            headers = new InternetHeaders(rawHeaders);
+            loadHeaders = false;
+        }
+    }
+
+    protected void loadContent(InputStream stream) throws MessagingException {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        try {
+            int byteRead = stream.read();
+            int lastByte = -1;
+            for (; byteRead > 0;) {
+                if (byteRead == ' ' && lastByte == '\n') {
+                    break;
+                }
+                lastByte = byteRead;
+                byteRead = stream.read();
+            }
+
+            for (; stream.available() > 0;) {
+                out.write(stream.read());
+            }
+
+            contentStream = new ByteArrayInputStream(out.toByteArray());
+            msgSize = contentStream.available();
+
+        } catch (IOException e) {
+
+            throw new MessagingException("Error loading content info", e);
+        }
+    }
+
+    public int getSize() throws MessagingException {
+        if (msgSize >= 0) {
+            return msgSize;
+        }
+        try {
+
+            if (msgSize < 0) {
+                if (rawHeaders == null) {
+                    loadHeaders();
+                }
+                POP3ListResponse res = (POP3ListResponse) POP3ResponseFactory.getListResponse(pop3Con
+                        .sendCommand(POP3CommandFactory.getCOMMAND_LIST(msgnum)));
+                msgSize = res.getSize() - headerSize;
+            }
+            return msgSize;
+        } catch (MessagingException ex) {
+            throw new MessagingException("error getting size", ex);
+        }
+    }
+
+    /**
+     * notice that we pass zero as the no of lines from the message,as it
+     * doesn't serv any purpose to get only a certain number of lines.
+     * 
+     * However this maybe important if a mail client only shows 3 or 4 lines of
+     * the message in the list and then when the user clicks they would load the
+     * message on demand.
+     * 
+     */
+    protected void loadHeaders() throws MessagingException {
+        POP3Response msgResponse = null;
+        try {
+
+            msgResponse = pop3Con.sendCommand(POP3CommandFactory.getCOMMAND_TOP(msgnum, 0));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        loadHeaders(msgResponse.getData());
+    }
+
+    /***************************************************************************
+     * Following is a set of methods that deal with headers I have tried to use
+     * the bare minimum
+     * 
+     * Used sun's POP3 impl & JavaMail API as a guide in decided which methods
+     * are important.
+     **************************************************************************/
+
+    public String[] getHeader(String name) throws MessagingException {
+        if (rawHeaders == null)
+            loadHeaders();
+        return headers.getHeader(name);
+    }
+
+    public String getHeader(String name, String delimiter) throws MessagingException {
+        if (headers == null)
+            loadHeaders();
+        return headers.getHeader(name, delimiter);
+    }
+
+    public Enumeration getAllHeaders() throws MessagingException {
+        if (headers == null)
+            loadHeaders();
+        return headers.getAllHeaders();
+    }
+
+    public Enumeration getMatchingHeaders(String[] names) throws MessagingException {
+        if (headers == null)
+            loadHeaders();
+        return headers.getMatchingHeaders(names);
+    }
+
+    public Enumeration getNonMatchingHeaders(String[] names) throws MessagingException {
+        if (headers == null)
+            loadHeaders();
+        return headers.getNonMatchingHeaders(names);
+    }
+
+    public Enumeration getAllHeaderLines() throws MessagingException {
+        if (headers == null)
+            loadHeaders();
+        return headers.getAllHeaderLines();
+    }
+
+    public Enumeration getMatchingHeaderLines(String[] names) throws MessagingException {
+        if (headers == null)
+            loadHeaders();
+        return headers.getMatchingHeaderLines(names);
+    }
+
+    public Enumeration getNonMatchingHeaderLines(String[] names) throws MessagingException {
+        if (headers == null)
+            loadHeaders();
+        return headers.getNonMatchingHeaderLines(names);
+    }
+
+    // the following are overrides for header modification methods. These
+    // messages are read only,
+    // so the headers cannot be modified.
+    public void addHeader(String name, String value) throws MessagingException {
+        throw new IllegalWriteException("POP3 messages are read-only");
+    }
+
+    public void setHeader(String name, String value) throws MessagingException {
+        throw new IllegalWriteException("POP3 messages are read-only");
+    }
+
+    public void removeHeader(String name) throws MessagingException {
+        throw new IllegalWriteException("POP3 messages are read-only");
+    }
+
+    public void addHeaderLine(String line) throws MessagingException {
+        throw new IllegalWriteException("POP3 messages are read-only");
+    }
+
+    /**
+     * We cannot modify these messages
+     */
+    public void saveChanges() throws MessagingException {
+        throw new IllegalWriteException("POP3 messages are read-only");
+    }
+}

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3Message.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3Message.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3Message.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageFactory.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageFactory.java?rev=414173&view=auto
==============================================================================
--- geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageFactory.java (added)
+++ geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageFactory.java Wed Jun 14 03:18:51 2006
@@ -0,0 +1,84 @@
+/**
+ *
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ *  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.geronimo.javamail.store.pop3.message;
+
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage.RecipientType;
+
+import org.apache.geronimo.javamail.store.pop3.POP3Connection;
+import org.apache.geronimo.javamail.store.pop3.POP3Folder;
+
+/**
+ * Fctory class to create POP3Messages based on the fetch profile
+ * 
+ * @version $Rev$ $Date$
+ */
+public final class POP3MessageFactory {
+
+    /**
+     * Creates a basic method with no items, the items will be loaded on demand
+     * 
+     * @param folder
+     * @param session
+     * @param pop3Con
+     * @param msgNum
+     * @return
+     */
+    public static Message createMessage(POP3Folder folder, Session session, POP3Connection pop3Con, int msgNum) {
+        return new POP3Message(folder, msgNum, session, pop3Con);
+    }
+
+    /**
+     * Created in response to <cpde>FetchProfile.ENVELOPE</code>
+     */
+    public static Message createMessageWithEvelope(POP3Message msg) throws MessagingException {
+        msg.getAllHeaders();
+        msg.getSender();
+        msg.getSentDate();
+        msg.getSubject();
+        msg.getReplyTo();
+        msg.getReceivedDate();
+        msg.getRecipients(RecipientType.TO);
+
+        return msg;
+    }
+
+    /**
+     * Created in response to <code>FetchProfile.CONTENT_INFO</code>
+     */
+    public static Message createMessageWithContentInfo(POP3Message msg) throws MessagingException {
+        msg.getContentType();
+        msg.getDisposition();
+        msg.getDescription();
+        msg.getSize();
+        msg.getLineCount();
+
+        return msg;
+    }
+
+    /**
+     * Created in response to <code>FetchProfile.FLAGS</code>
+     */
+    public static Message createMessageWithFlags(POP3Message msg) throws MessagingException {
+        msg.getFlags();
+        return msg;
+    }
+
+}

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithContentInfo.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithContentInfo.java?rev=414173&view=auto
==============================================================================
--- geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithContentInfo.java (added)
+++ geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithContentInfo.java Wed Jun 14 03:18:51 2006
@@ -0,0 +1,46 @@
+/**
+ *
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ *  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.geronimo.javamail.store.pop3.message;
+
+import javax.mail.Folder;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+
+import org.apache.geronimo.javamail.store.pop3.POP3Connection;
+
+/**
+ * light-weight Message object will be created in response to
+ * FetchProfile.CONTENT_INFO other details will be filled on demand *
+ * 
+ * @version $Rev$ $Date$
+ * 
+ */
+
+public class POP3MessageWithContentInfo extends POP3Message {
+
+    public POP3MessageWithContentInfo(Folder folder, int msgnum, Session session, POP3Connection pop3Con)
+            throws MessagingException {
+        super(folder, msgnum, null, pop3Con);
+        this.getContentType();
+        this.getDisposition();
+        this.getDescription();
+        this.getSize();
+        this.getLineCount();
+    }
+
+}

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithContentInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithContentInfo.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithContentInfo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithEnvelope.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithEnvelope.java?rev=414173&view=auto
==============================================================================
--- geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithEnvelope.java (added)
+++ geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithEnvelope.java Wed Jun 14 03:18:51 2006
@@ -0,0 +1,46 @@
+/**
+ *
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ *  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.geronimo.javamail.store.pop3.message;
+
+import javax.mail.Folder;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+
+import org.apache.geronimo.javamail.store.pop3.POP3Connection;
+
+/**
+ * light-weight Message object will be created in response to
+ * FetchProfile.ENVELOPE other details will be filled on demand *
+ * 
+ * @version $Rev$ $Date$
+ */
+
+public class POP3MessageWithEnvelope extends POP3Message {
+
+    protected POP3MessageWithEnvelope(Folder folder, int msgnum, Session session, POP3Connection pop3Con)
+            throws MessagingException {
+        super(folder, msgnum, session, pop3Con);
+        this.getAllHeaders();
+        this.getSender();
+        this.getSentDate();
+        this.getSubject();
+        this.getReplyTo();
+        this.getReceivedDate();
+        this.getRecipients(RecipientType.TO);
+    }
+}

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithEnvelope.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithEnvelope.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithEnvelope.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithFlags.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithFlags.java?rev=414173&view=auto
==============================================================================
--- geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithFlags.java (added)
+++ geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithFlags.java Wed Jun 14 03:18:51 2006
@@ -0,0 +1,40 @@
+/**
+ *
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ *  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.geronimo.javamail.store.pop3.message;
+
+import javax.mail.Folder;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+
+import org.apache.geronimo.javamail.store.pop3.POP3Connection;
+
+/**
+ * light-weight Message object will be created in response to FetchProfile.FLAGS
+ * other details will be filled on demand *
+ * 
+ * @version $Rev$ $Date$
+ */
+
+public class POP3MessageWithFlags extends POP3Message {
+
+    protected POP3MessageWithFlags(Folder folder, int msgnum, Session session, POP3Connection pop3Con)
+            throws MessagingException {
+        super(folder, msgnum, session, pop3Con);
+        this.getFlags();
+    }
+}

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithFlags.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithFlags.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithFlags.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/response/DefaultPOP3Response.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/response/DefaultPOP3Response.java?rev=414173&view=auto
==============================================================================
--- geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/response/DefaultPOP3Response.java (added)
+++ geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/response/DefaultPOP3Response.java Wed Jun 14 03:18:51 2006
@@ -0,0 +1,58 @@
+/**
+ *
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ *  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.geronimo.javamail.store.pop3.response;
+
+import java.io.InputStream;
+
+import org.apache.geronimo.javamail.store.pop3.POP3Constants;
+import org.apache.geronimo.javamail.store.pop3.POP3Response;
+
+/**
+ * This class provides the basic implementation for the POP3Response.
+ * 
+ * @see org.apache.geronimo.javamail.store.pop3.POP3Response
+ * @version $Rev$ $Date$
+ */
+
+public class DefaultPOP3Response implements POP3Response, POP3Constants {
+
+    private int status = ERR;
+
+    private String firstLine;
+
+    private InputStream data;
+
+    DefaultPOP3Response(int status, String firstLine, InputStream data) {
+        this.status = status;
+        this.firstLine = firstLine;
+        this.data = data;
+    }
+
+    public int getStatus() {
+        return status;
+    }
+
+    public InputStream getData() {
+        return data;
+    }
+
+    public String getFirstLine() {
+        return firstLine;
+    }
+
+}

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/response/DefaultPOP3Response.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/response/DefaultPOP3Response.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/response/DefaultPOP3Response.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ListResponse.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ListResponse.java?rev=414173&view=auto
==============================================================================
--- geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ListResponse.java (added)
+++ geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ListResponse.java Wed Jun 14 03:18:51 2006
@@ -0,0 +1,97 @@
+/**
+ *
+ * Copyright 2003-2005 The Apache Software Foundation
+ *
+ *  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.geronimo.javamail.store.pop3.response;
+
+import java.util.Vector;
+
+import javax.mail.MessagingException;
+
+import org.apache.geronimo.javamail.store.pop3.POP3Response;
+
+/**
+ * This class adds functionality to the basic response by parsing the reply for
+ * LIST command and obtaining specific information about the msgnum and the
+ * size. It could be for one or more msgs depending on wether a msg number was
+ * passed or not into the LIST command
+ * 
+ * @see org.apache.geronimo.javamail.store.pop3.POP3Response
+ * @see org.apache.geronimo.javamail.store.pop3.response.DefaultPOP3Response
+ * 
+ * @version $Rev$ $Date$
+ */
+
+public class POP3ListResponse extends DefaultPOP3Response {
+
+    private int msgnum = 0;
+
+    private int size = 0;
+
+    private Vector multipleMsgs = null;
+
+    POP3ListResponse(POP3Response baseRes) throws MessagingException {
+        super(baseRes.getStatus(), baseRes.getFirstLine(), baseRes.getData());
+
+        // if ERR not worth proceeding any further
+        if (OK == getStatus()) {
+
+            // if data == null, then it mean it's a single line response
+            if (baseRes.getData() == null) {
+                String[] args = getFirstLine().split(SPACE);
+                try {
+                    msgnum = Integer.parseInt(args[0]);
+                } catch (NumberFormatException e) {
+                    throw new MessagingException("Invalid response for STAT command", e);
+                }
+                try {
+                    size = Integer.parseInt(args[1]);
+                } catch (NumberFormatException e) {
+                    throw new MessagingException("Invalid response for STAT command", e);
+                }
+            } else {
+                int totalMsgs = 0;
+                String[] args = getFirstLine().split(SPACE);
+                try {
+                    totalMsgs = Integer.parseInt(args[0]);
+                } catch (NumberFormatException e) {
+                    throw new MessagingException("Invalid response for STAT command", e);
+                }
+                multipleMsgs = new Vector(totalMsgs);
+                multipleMsgs.setSize(totalMsgs);
+                // Todo : multi-line response parsing
+            }
+
+        }
+    }
+
+    public int getMessageNumber() {
+        return msgnum;
+    }
+
+    public int getSize() {
+        return size;
+    }
+
+    /**
+     * Messages can be accessed by multipleMsgs.getElementAt(msgnum)
+     * 
+     */
+    public Vector getMultipleMessageDetails() {
+        return multipleMsgs;
+    }
+
+}

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ListResponse.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ListResponse.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/javamail/trunk/javamail-provider-1.3/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ListResponse.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message