org.apache.commons.net.pop3

Class POP3

Known Direct Subclasses:
POP3Client

public class POP3
extends SocketClient

The POP3 class is not meant to be used by itself and is provided only so that you may easily implement your own POP3 client if you so desire. If you have no need to perform your own implementation, you should use POP3Client.

Rather than list it separately for each method, we mention here that every method communicating with the server and throwing an IOException can also throw a MalformedServerReplyException , which is a subclass of IOException. A MalformedServerReplyException will be thrown when the reply received from the server deviates enough from the protocol specification that it cannot be interpreted in a useful manner despite attempts to be as lenient as possible.

Author:
Daniel F. Savarese

See Also:
POP3Client, MalformedServerReplyException

Field Summary

static int
AUTHORIZATION_STATE
A constant representing the POP3 authorization state.
static int
DEFAULT_PORT
The default POP3 port.
static int
DISCONNECTED_STATE
A constant representing the state where the client is not yet connected to a POP3 server.
static int
TRANSACTION_STATE
A constant representing the POP3 transaction state.
static int
UPDATE_STATE
A constant representing the POP3 update state.
(package private) static String
_ERROR
(package private) static String
_OK
private static String
__DEFAULT_ENCODING
private StringBuffer
__commandBuffer
private int
__popState
private BufferedWriter
__writer
protected ProtocolCommandSupport
_commandSupport_
A ProtocolCommandSupport object used to manage the registering of ProtocolCommandListeners and te firing of ProtocolCommandEvents.
(package private) String
_lastReplyLine
(package private) BufferedReader
_reader
(package private) int
_replyCode
(package private) Vector
_replyLines

Fields inherited from class org.apache.commons.net.SocketClient

NETASCII_EOL, __DEFAULT_SOCKET_FACTORY, _defaultPort_, _input_, _isConnected_, _output_, _socketFactory_, _socket_, _timeout_

Constructor Summary

POP3()
The default POP3Client constructor.

Method Summary

private void
__getReply()
protected void
_connectAction_()
Performs connection initialization and sets state to AUTHORIZATION_STATE .
void
addProtocolCommandListener(ProtocolCommandListener listener)
Adds a ProtocolCommandListener.
void
disconnect()
Disconnects the client from the server, and sets the state to DISCONNECTED_STATE .
void
getAdditionalReply()
Retrieves the additional lines of a multi-line server reply.
String
getReplyString()
Returns the reply to the last command sent to the server.
String[]
getReplyStrings()
Returns an array of lines received as a reply to the last command sent to the server.
int
getState()
Returns the current POP3 client state.
void
removeProtocolCommandistener(ProtocolCommandListener listener)
Removes a ProtocolCommandListener.
int
sendCommand(String command)
Sends a command with no arguments to the server and returns the reply code.
int
sendCommand(String command, String args)
Sends a command an arguments to the server and returns the reply code.
int
sendCommand(int command)
Sends a command with no arguments to the server and returns the reply code.
int
sendCommand(int command, String args)
Sends a command an arguments to the server and returns the reply code.
void
setState(int state)
Sets POP3 client state.

Methods inherited from class org.apache.commons.net.SocketClient

_connectAction_, connect, connect, connect, connect, connect, connect, disconnect, getDefaultPort, getDefaultTimeout, getLocalAddress, getLocalPort, getRemoteAddress, getRemotePort, getSoLinger, getSoTimeout, getTcpNoDelay, isConnected, setDefaultPort, setDefaultTimeout, setSoLinger, setSoTimeout, setSocketFactory, setTcpNoDelay, verifyRemote

Field Details

AUTHORIZATION_STATE

public static final int AUTHORIZATION_STATE
A constant representing the POP3 authorization state. **

Field Value:
0


DEFAULT_PORT

public static final int DEFAULT_PORT
The default POP3 port. Set to 110 according to RFC 1288. **

Field Value:
110


DISCONNECTED_STATE

public static final int DISCONNECTED_STATE
A constant representing the state where the client is not yet connected to a POP3 server.

Field Value:
-1


TRANSACTION_STATE

public static final int TRANSACTION_STATE
A constant representing the POP3 transaction state. **

Field Value:
1


UPDATE_STATE

public static final int UPDATE_STATE
A constant representing the POP3 update state. **

Field Value:
2


_ERROR

(package private) static final String _ERROR


_OK

(package private) static final String _OK


__DEFAULT_ENCODING

private static final String __DEFAULT_ENCODING


__commandBuffer

private StringBuffer __commandBuffer


__popState

private int __popState


__writer

private BufferedWriter __writer


_commandSupport_

protected ProtocolCommandSupport _commandSupport_
A ProtocolCommandSupport object used to manage the registering of ProtocolCommandListeners and te firing of ProtocolCommandEvents.


_lastReplyLine

(package private)  String _lastReplyLine


_reader

(package private)  BufferedReader _reader


_replyCode

(package private)  int _replyCode


_replyLines

(package private)  Vector _replyLines

Constructor Details

POP3

public POP3()
The default POP3Client constructor. Initializes the state to DISCONNECTED_STATE.

Method Details

__getReply

private void __getReply()
            throws IOException


_connectAction_

protected void _connectAction_()
            throws IOException
Performs connection initialization and sets state to AUTHORIZATION_STATE .
Overrides:
_connectAction_ in interface SocketClient


addProtocolCommandListener

public void addProtocolCommandListener(ProtocolCommandListener listener)
Adds a ProtocolCommandListener. Delegates this task to _commandSupport_ .

Parameters:
listener - The ProtocolCommandListener to add.


disconnect

public void disconnect()
            throws IOException
Disconnects the client from the server, and sets the state to DISCONNECTED_STATE . The reply text information from the last issued command is voided to allow garbage collection of the memory used to store that information.

Overrides:
disconnect in interface SocketClient


getAdditionalReply

public void getAdditionalReply()
            throws IOException
Retrieves the additional lines of a multi-line server reply.


getReplyString

public String getReplyString()

Returns:
The last server response.


getReplyStrings

public String[] getReplyStrings()

Returns:
The last server response.


getState

public int getState()
Returns the current POP3 client state.

Returns:
The current POP3 client state.


removeProtocolCommandistener

public void removeProtocolCommandistener(ProtocolCommandListener listener)
Removes a ProtocolCommandListener. Delegates this task to _commandSupport_ .

Parameters:
listener - The ProtocolCommandListener to remove.


sendCommand

public int sendCommand(String command)
            throws IOException
Sends a command with no arguments to the server and returns the reply code.

Parameters:
command - The POP3 command to send.

Returns:
The server reply code (either POP3Reply.OK or POP3Reply.ERROR).


sendCommand

public int sendCommand(String command,
                       String args)
            throws IOException
Sends a command an arguments to the server and returns the reply code.

Parameters:
command - The POP3 command to send.
args - The command arguments.

Returns:
The server reply code (either POP3Reply.OK or POP3Reply.ERROR).


sendCommand

public int sendCommand(int command)
            throws IOException
Sends a command with no arguments to the server and returns the reply code.

Parameters:
command - The POP3 command to send (one of the POP3Command constants).

Returns:
The server reply code (either POP3Reply.OK or POP3Reply.ERROR).


sendCommand

public int sendCommand(int command,
                       String args)
            throws IOException
Sends a command an arguments to the server and returns the reply code.

Parameters:
command - The POP3 command to send (one of the POP3Command constants).
args - The command arguments.

Returns:
The server reply code (either POP3Reply.OK or POP3Reply.ERROR).


setState

public void setState(int state)
Sets POP3 client state. This must be one of the _STATE constants.

Parameters:
state - The new state.