org.apache.geronimo.javamail.store.pop3.connection
Class POP3Connection

java.lang.Object
  extended by org.apache.geronimo.javamail.util.MailConnection
      extended by org.apache.geronimo.javamail.store.pop3.connection.POP3Connection
All Implemented Interfaces:
POP3Constants

public class POP3Connection
extends MailConnection
implements POP3Constants

Simple implementation of POP3 transport.

Version:
$Rev: 597135 $ $Date: 2007-11-21 11:26:57 -0500 (Wed, 21 Nov 2007) $

Field Summary
protected  boolean apopEnabled
           
protected  boolean authEnabled
           
protected  boolean closed
           
protected  String greeting
           
protected  boolean loggedIn
           
protected static String MAIL_APOP_ENABLED
           
protected static String MAIL_AUTH_ENABLED
           
protected static String MAIL_DISABLE_TOP
           
protected static String MAIL_FORGET_TOP
           
protected static String MAIL_RESET_QUIT
           
protected  BufferedReader reader
           
protected  boolean topDisabled
           
protected  PrintWriter writer
           
 
Fields inherited from class org.apache.geronimo.javamail.util.MailConnection
AUTHENTICATION_CRAMMD5, AUTHENTICATION_DIGESTMD5, AUTHENTICATION_LOGIN, AUTHENTICATION_PLAIN, authentications, authid, capabilities, CAPABILITY_STARTTLS, CR, debug, debugStream, DEFAULT_MAIL_HOST, defaultPort, inputStream, LF, localAddress, localHost, localPort, MAIL_AUTH, MAIL_AUTHORIZATIONID, MAIL_ENCODE_TRACE, MAIL_FACTORY_CLASS, MAIL_FACTORY_FALLBACK, MAIL_FACTORY_PORT, MAIL_LOCALADDRESS, MAIL_LOCALHOST, MAIL_LOCALPORT, MAIL_LOGIN_DISABLE, MAIL_PLAIN_DISABLE, MAIL_PORT, MAIL_SASL_ENABLE, MAIL_SASL_MECHANISMS, MAIL_SASL_REALM, MAIL_SSL_CIPHERSUITES, MAIL_SSL_ENABLE, MAIL_SSL_PROTOCOLS, MAIL_STARTTLS_ENABLE, MAIL_TIMEOUT, mechanisms, MIN_MILLIS, outputStream, password, props, protocol, realm, serverHost, serverPort, session, socket, sslConnection, timeout, TIMEOUT, username
 
Fields inherited from interface org.apache.geronimo.javamail.store.pop3.POP3Constants
CHALLENGE, CRLF, DOT, ERR, OK, SPACE
 
Constructor Summary
POP3Connection(ProtocolProperties props)
          Normal constructor for an POP3Connection() object.
 
Method Summary
protected  POP3Response buildResponse(boolean isMultiLineResponse)
          Build a POP3Response item from the response stream.
 void close()
          Close the connection.
 void deleteMessage(int sequenceNumber)
          Delete a single message from the mail server.
protected  void getConnection()
          Create a transport connection object and connect it to the target server.
protected  ClientAuthenticator getSaslAuthenticator()
          Attempt to retrieve a SASL authenticator for this protocol.
protected  void getWelcome()
           
 boolean isClosed()
          Test if the connnection has been forcibly closed.
 boolean login()
          Login to the mail server, using whichever method is configured.
 void logout()
          Logout from the mail server.
 void pingServer()
          Ping the mail server to see if we still have an active connection.
 boolean processAPOPAuthentication()
          Process logging in using the APOP command.
 boolean processLogin()
          Process a basic LOGIN operation, using the plain test USER/PASS command combo.
protected  boolean processLogin(ClientAuthenticator authenticator)
          Process a login using the provided authenticator object.
protected  boolean processSaslAuthentication()
          Process SASL-type authentication.
 boolean protocolConnect(String host, int port, String authid, String realm, String username, String password)
          Connect to the server and do the initial handshaking.
 void reset()
          Perform a reset on the mail server.
 POP3StatusResponse retrieveMailboxStatus()
          Retrieve the mail drop status information.
 byte[] retrieveMessageData(int sequenceNumber)
          Retrieve the raw message content from the POP3 server.
 ByteArrayInputStream retrieveMessageHeaders(int sequenceNumber)
          Retrieve the message header information for a given message, returned as an input stream suitable for loading the message data.
 int retrieveMessageSize(int sequenceNumber)
          Retrieve the total message size from the mail server.
 String retrieveMessageUid(int sequenceNumber)
          Retrieve the UID for an individual message.
protected  List selectSaslMechanisms()
          Merge the configured SASL mechanisms with the capabilities that the server has indicated it supports, returning a merged list that can be used for selecting a mechanism.
protected  POP3Response sendCommand(String cmd)
           
protected  POP3Response sendCommand(String cmd, boolean multiLine)
           
protected  POP3Response sendMultiLineCommand(String cmd)
           
 void setClosed()
          Tag this connection as having been closed by the server.
 String toString()
           
 
Methods inherited from class org.apache.geronimo.javamail.util.MailConnection
checkConnected, closeServerConnection, connect, debugOut, debugOut, getCapabilities, getConnectedSocket, getConnectedSSLSocket, getConnectedTLSSocket, getConnectionProperties, getConnectionStreams, getHost, getLocalHost, getLoginAuthenticator, getSaslMechanisms, getSASLRealm, getServerMechanisms, hasCapability, protocolConnect, setLocalHost, setSASLRealm, supportsMechanism
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAIL_APOP_ENABLED

protected static final String MAIL_APOP_ENABLED
See Also:
Constant Field Values

MAIL_AUTH_ENABLED

protected static final String MAIL_AUTH_ENABLED
See Also:
Constant Field Values

MAIL_RESET_QUIT

protected static final String MAIL_RESET_QUIT
See Also:
Constant Field Values

MAIL_DISABLE_TOP

protected static final String MAIL_DISABLE_TOP
See Also:
Constant Field Values

MAIL_FORGET_TOP

protected static final String MAIL_FORGET_TOP
See Also:
Constant Field Values

greeting

protected String greeting

authEnabled

protected boolean authEnabled

apopEnabled

protected boolean apopEnabled

reader

protected BufferedReader reader

writer

protected PrintWriter writer

closed

protected boolean closed

loggedIn

protected boolean loggedIn

topDisabled

protected boolean topDisabled
Constructor Detail

POP3Connection

public POP3Connection(ProtocolProperties props)
Normal constructor for an POP3Connection() object.

Parameters:
store - The store we're associated with (source of parameter values).
host - The target host name of the IMAP server.
port - The target listening port of the server. Defaults to 119 if the port is specified as -1.
username - The login user name (can be null unless authentication is required).
password - Password associated with the userid account. Can be null if authentication is not required.
sslConnection - True if this is targetted as an SSLConnection.
debug - The session debug flag.
Method Detail

protocolConnect

public boolean protocolConnect(String host,
                               int port,
                               String authid,
                               String realm,
                               String username,
                               String password)
                        throws MessagingException
Connect to the server and do the initial handshaking.

Throws:
MessagingException

getConnection

protected void getConnection()
                      throws MessagingException
Create a transport connection object and connect it to the target server.

Overrides:
getConnection in class MailConnection
Throws:
MessagingException

getWelcome

protected void getWelcome()
                   throws IOException
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object

close

public void close()
           throws MessagingException
Close the connection. On completion, we'll be disconnected from the server and unable to send more data.

Throws:
MessagingException

setClosed

public void setClosed()
Tag this connection as having been closed by the server. This will not be returned to the connection pool.


isClosed

public boolean isClosed()
Test if the connnection has been forcibly closed.

Returns:
True if the server disconnected the connection.

sendCommand

protected POP3Response sendCommand(String cmd)
                            throws MessagingException
Throws:
MessagingException

sendMultiLineCommand

protected POP3Response sendMultiLineCommand(String cmd)
                                     throws MessagingException
Throws:
MessagingException

sendCommand

protected POP3Response sendCommand(String cmd,
                                   boolean multiLine)
                            throws MessagingException
Throws:
MessagingException

buildResponse

protected POP3Response buildResponse(boolean isMultiLineResponse)
                              throws MessagingException
Build a POP3Response item from the response stream.

Parameters:
isMultiLineResponse - If true, this command is expecting multiple lines back from the server.
Returns:
A POP3Response item with all of the command response data.
Throws:
MessagingException

retrieveMessageData

public byte[] retrieveMessageData(int sequenceNumber)
                           throws MessagingException
Retrieve the raw message content from the POP3 server. This is all of the message data, including the header.

Parameters:
sequenceNumber - The message sequence number.
Returns:
A byte array containing all of the message data.
Throws:
MessagingException

retrieveMessageHeaders

public ByteArrayInputStream retrieveMessageHeaders(int sequenceNumber)
                                            throws MessagingException
Retrieve the message header information for a given message, returned as an input stream suitable for loading the message data.

Parameters:
sequenceNumber - The server sequence number for the message.
Returns:
An inputstream that can be used to read the message data.
Throws:
MessagingException

retrieveMessageSize

public int retrieveMessageSize(int sequenceNumber)
                        throws MessagingException
Retrieve the total message size from the mail server. This is the size of the headers plus the size of the message content.

Parameters:
sequenceNumber - The message sequence number.
Returns:
The full size of the message.
Throws:
MessagingException

retrieveMailboxStatus

public POP3StatusResponse retrieveMailboxStatus()
                                         throws MessagingException
Retrieve the mail drop status information.

Returns:
An object representing the returned mail drop status.
Throws:
MessagingException

retrieveMessageUid

public String retrieveMessageUid(int sequenceNumber)
                          throws MessagingException
Retrieve the UID for an individual message.

Parameters:
sequenceNumber - The target message sequence number.
Returns:
The string UID maintained by the server.
Throws:
MessagingException

deleteMessage

public void deleteMessage(int sequenceNumber)
                   throws MessagingException
Delete a single message from the mail server.

Parameters:
sequenceNumber - The sequence number of the message to delete.
Throws:
MessagingException

logout

public void logout()
            throws MessagingException
Logout from the mail server. This sends a QUIT command, which will likely sever the mail connection.

Throws:
MessagingException

reset

public void reset()
           throws MessagingException
Perform a reset on the mail server.

Throws:
MessagingException

pingServer

public void pingServer()
                throws MessagingException
Ping the mail server to see if we still have an active connection.

Throws:
MessagingException - thrown if we do not have an active connection.

login

public boolean login()
              throws MessagingException
Login to the mail server, using whichever method is configured. This will try multiple methods, if allowed, in decreasing levels of security.

Returns:
true if the login was successful.
Throws:
MessagingException

processLogin

public boolean processLogin()
                     throws MessagingException
Process a basic LOGIN operation, using the plain test USER/PASS command combo.

Returns:
true if we logged successfully.
Throws:
MessagingException

processAPOPAuthentication

public boolean processAPOPAuthentication()
                                  throws MessagingException
Process logging in using the APOP command. Only works on servers that give a timestamp value in the welcome response.

Returns:
true if the login was accepted.
Throws:
MessagingException

processSaslAuthentication

protected boolean processSaslAuthentication()
                                     throws MessagingException
Process SASL-type authentication.

Returns:
Returns true if the server support a SASL authentication mechanism and accepted reponse challenges.
Throws:
MessagingException

getSaslAuthenticator

protected ClientAuthenticator getSaslAuthenticator()
Attempt to retrieve a SASL authenticator for this protocol.

Returns:
A SASL authenticator, or null if a suitable one was not located.

processLogin

protected boolean processLogin(ClientAuthenticator authenticator)
                        throws MessagingException
Process a login using the provided authenticator object. NB: This method is synchronized because we have a multi-step process going on here. No other commands should be sent to the server until we complete.

Returns:
Returns true if the server support a SASL authentication mechanism and accepted reponse challenges.
Throws:
MessagingException

selectSaslMechanisms

protected List selectSaslMechanisms()
Merge the configured SASL mechanisms with the capabilities that the server has indicated it supports, returning a merged list that can be used for selecting a mechanism.

Overrides:
selectSaslMechanisms in class MailConnection
Returns:
A List representing the intersection of the configured list and the capabilities list.


Copyright © 2003-2009 The Apache Software Foundation. All Rights Reserved.