geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bsny...@apache.org
Subject svn commit: r372731 - in /geronimo/trunk/modules/javamail-transport/src: java/org/apache/geronimo/javamail/store/ java/org/apache/geronimo/javamail/store/pop3/ java/org/apache/geronimo/javamail/store/pop3/message/ java/org/apache/geronimo/javamail/stor...
Date Fri, 27 Jan 2006 04:54:20 GMT
Author: bsnyder
Date: Thu Jan 26 20:54:10 2006
New Revision: 372731

URL: http://svn.apache.org/viewcvs?rev=372731&view=rev
Log:
Committing POP3 implementation work from GERONIMO-1341.

Added:
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Command.java   (with props)
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3CommandFactory.java   (with props)
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Connection.java   (with props)
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Constants.java   (with props)
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Folder.java   (with props)
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Response.java   (with props)
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3ResponseBuilder.java   (with props)
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Store.java   (with props)
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3Message.java   (with props)
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageFactory.java   (with props)
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithContentInfo.java   (with props)
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithEnvelope.java   (with props)
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithFlags.java   (with props)
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/DefaultPOP3Response.java   (with props)
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ListResponse.java   (with props)
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ResponseFactory.java   (with props)
    geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3StatusResponse.java   (with props)
Modified:
    geronimo/trunk/modules/javamail-transport/src/resources/META-INF/javamail.default.providers

Added: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Command.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Command.java?rev=372731&view=auto
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Command.java (added)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Command.java Thu Jan 26 20:54:10 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/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Command.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Command.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

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

Added: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3CommandFactory.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3CommandFactory.java?rev=372731&view=auto
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3CommandFactory.java (added)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3CommandFactory.java Thu Jan 26 20:54:10 2006
@@ -0,0 +1,224 @@
+/**
+ *
+ * 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/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3CommandFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3CommandFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

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

Added: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Connection.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Connection.java?rev=372731&view=auto
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Connection.java (added)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Connection.java Thu Jan 26 20:54:10 2006
@@ -0,0 +1,158 @@
+/**
+ *
+ * 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/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Connection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Connection.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

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

Added: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Constants.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Constants.java?rev=372731&view=auto
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Constants.java (added)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Constants.java Thu Jan 26 20:54:10 2006
@@ -0,0 +1,37 @@
+/**
+ *
+ * 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/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Constants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Constants.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

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

Added: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Folder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Folder.java?rev=372731&view=auto
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Folder.java (added)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Folder.java Thu Jan 26 20:54:10 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/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Folder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Folder.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

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

Added: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Response.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Response.java?rev=372731&view=auto
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Response.java (added)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Response.java Thu Jan 26 20:54:10 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/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Response.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Response.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

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

Added: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3ResponseBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3ResponseBuilder.java?rev=372731&view=auto
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3ResponseBuilder.java (added)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3ResponseBuilder.java Thu Jan 26 20:54:10 2006
@@ -0,0 +1,129 @@
+/**
+ *
+ * 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/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3ResponseBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3ResponseBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

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

Added: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Store.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Store.java?rev=372731&view=auto
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Store.java (added)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Store.java Thu Jan 26 20:54:10 2006
@@ -0,0 +1,211 @@
+/**
+ *
+ * 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/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Store.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/POP3Store.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

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

Added: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3Message.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3Message.java?rev=372731&view=auto
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3Message.java (added)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3Message.java Thu Jan 26 20:54:10 2006
@@ -0,0 +1,255 @@
+/**
+ *
+ * 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.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Enumeration;
+
+import javax.mail.Flags;
+import javax.mail.Folder;
+import javax.mail.Header;
+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;
+import org.apache.geronimo.javamail.store.pop3.response.POP3StatusResponse;
+
+
+/**
+ * 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);
+	}
+
+	/**
+	 * We cannot modify these messages
+	 */
+	public void saveChanges() throws MessagingException {
+		throw new IllegalWriteException("POP3 messages are read-only");
+	}
+}

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

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3Message.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

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

Added: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageFactory.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageFactory.java?rev=372731&view=auto
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageFactory.java (added)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageFactory.java Thu Jan 26 20:54:10 2006
@@ -0,0 +1,85 @@
+/**
+ *
+ * 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/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

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

Added: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithContentInfo.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithContentInfo.java?rev=372731&view=auto
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithContentInfo.java (added)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithContentInfo.java Thu Jan 26 20:54:10 2006
@@ -0,0 +1,47 @@
+/**
+ *
+ * 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/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithContentInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithContentInfo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

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

Added: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithEnvelope.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithEnvelope.java?rev=372731&view=auto
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithEnvelope.java (added)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithEnvelope.java Thu Jan 26 20:54:10 2006
@@ -0,0 +1,49 @@
+/**
+ *
+ * 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 javax.mail.internet.MimeMessage.RecipientType;
+
+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/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithEnvelope.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithEnvelope.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

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

Added: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithFlags.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithFlags.java?rev=372731&view=auto
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithFlags.java (added)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithFlags.java Thu Jan 26 20:54:10 2006
@@ -0,0 +1,41 @@
+/**
+ *
+ * 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/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithFlags.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/message/POP3MessageWithFlags.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

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

Added: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/DefaultPOP3Response.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/DefaultPOP3Response.java?rev=372731&view=auto
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/DefaultPOP3Response.java (added)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/DefaultPOP3Response.java Thu Jan 26 20:54:10 2006
@@ -0,0 +1,57 @@
+/**
+ *
+ * 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/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/DefaultPOP3Response.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/DefaultPOP3Response.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

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

Added: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ListResponse.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ListResponse.java?rev=372731&view=auto
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ListResponse.java (added)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ListResponse.java Thu Jan 26 20:54:10 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.Hashtable;
+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/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ListResponse.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ListResponse.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

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

Added: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ResponseFactory.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ResponseFactory.java?rev=372731&view=auto
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ResponseFactory.java (added)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ResponseFactory.java Thu Jan 26 20:54:10 2006
@@ -0,0 +1,48 @@
+/**
+ *
+ * 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 javax.mail.MessagingException;
+
+import org.apache.geronimo.javamail.store.pop3.POP3Constants;
+import org.apache.geronimo.javamail.store.pop3.POP3Response;
+
+/**
+ * This factory provides a uniform way of handling the 
+ * creation of response objects.
+ *  
+ * @version $Rev$ $Date$ 
+ */
+
+public final class POP3ResponseFactory implements POP3Constants{
+	
+	public static POP3Response getDefaultResponse(int status,String line,InputStream data){
+		return new DefaultPOP3Response(status,line,data);
+	}
+	
+	public static POP3Response getStatusResponse(POP3Response baseRes) throws MessagingException{
+		return new POP3StatusResponse(baseRes);
+	}
+	
+	public static POP3Response getListResponse(POP3Response baseRes) throws MessagingException{
+		return new POP3StatusResponse(baseRes);
+	}
+	
+
+}

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ResponseFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ResponseFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3ResponseFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3StatusResponse.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3StatusResponse.java?rev=372731&view=auto
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3StatusResponse.java (added)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3StatusResponse.java Thu Jan 26 20:54:10 2006
@@ -0,0 +1,66 @@
+/**
+ *
+ * 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 javax.mail.MessagingException;
+import org.apache.geronimo.javamail.store.pop3.POP3Response;
+
+/**
+ * This class adds functionality to the basic response
+ * by parsing the status line and obtaining specific
+ * information about num of msgs and the size
+ * 
+ * @see  org.apache.geronimo.javamail.store.pop3.POP3Response
+ * @see  org.apache.geronimo.javamail.store.pop3.response.DefaultPOP3Response
+ *  
+ * @version $Rev$ $Date$ 
+ */
+
+public class POP3StatusResponse extends DefaultPOP3Response {
+
+	private int numMessages = 0;
+	private int size = 0;
+	
+	POP3StatusResponse(POP3Response baseRes) throws MessagingException{
+		super(baseRes.getStatus(),baseRes.getFirstLine(),baseRes.getData());
+		
+		// if ERR not worth proceeding any further
+		if(OK == getStatus()){			
+			String[] args = getFirstLine().split(SPACE);
+			try {
+				numMessages = 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);
+			}
+		}
+	}
+
+	public int getNumMessages() {
+		return numMessages;
+	}
+
+	public int getSize() {
+		return size;
+	}
+
+}

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3StatusResponse.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3StatusResponse.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/store/pop3/response/POP3StatusResponse.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/trunk/modules/javamail-transport/src/resources/META-INF/javamail.default.providers
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/resources/META-INF/javamail.default.providers?rev=372731&r1=372730&r2=372731&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/resources/META-INF/javamail.default.providers (original)
+++ geronimo/trunk/modules/javamail-transport/src/resources/META-INF/javamail.default.providers Thu Jan 26 20:54:10 2006
@@ -7,3 +7,4 @@
 # $Rev$ $Date$
 #
 protocol=smtp; type=transport; class=org.apache.geronimo.javamail.transport.smtp.SMTPTransport; vendor=Apache Software Foundation; version=1.0
+protocol=pop3; type=store; class=org.apache.geronimo.javamail.store.pop3.POP3Store; vendor=Apache Software Foundation; version=1.0
\ No newline at end of file



Mime
View raw message