public class POP3Connection
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
APOP |
protected static java.lang.String |
AUTH |
protected static java.lang.String |
CAPA |
static int |
DEFAULT_PORT
The default POP3 port.
|
static int |
DEFAULT_SSL_PORT
The default POP3S port.
|
protected static java.lang.String |
DELE |
protected static int |
ERR |
protected static java.lang.String |
LIST |
protected static java.lang.String |
NOOP |
protected static int |
OK |
protected static java.lang.String |
PASS |
static java.util.logging.Level |
POP3_TRACE
The network trace level.
|
protected static java.lang.String |
QUIT |
protected static int |
READY |
protected static java.lang.String |
RETR |
protected static java.lang.String |
RSET |
protected static java.lang.String |
STAT |
protected static java.lang.String |
STLS |
protected static java.lang.String |
TOP |
protected static java.lang.String |
UIDL |
protected static java.lang.String |
USER |
Constructor and Description |
---|
POP3Connection(java.lang.String hostname)
Creates a new connection to the server.
|
POP3Connection(java.lang.String hostname,
int port)
Creates a new connection to the server.
|
POP3Connection(java.lang.String hostname,
int port,
int connectionTimeout,
int timeout)
Creates a new connection to the server.
|
POP3Connection(java.lang.String hostname,
int port,
int connectionTimeout,
int timeout,
boolean secure,
javax.net.ssl.TrustManager tm)
Creates a new connection to the server.
|
Modifier and Type | Method and Description |
---|---|
boolean |
apop(java.lang.String username,
java.lang.String password)
Authenticate the specified user using the APOP MD5-based method.
|
boolean |
auth(java.lang.String mechanism,
java.lang.String username,
java.lang.String password)
Authenticates the connection using the specified SASL mechanism,
username, and password.
|
java.util.List<java.lang.String> |
capa()
Returns a list of capabilities supported by the POP3 server.
|
void |
dele(int msgnum)
Marks the specified message as deleted.
|
java.util.logging.Logger |
getLogger()
Returns the logger used by this connection for debug output.
|
protected int |
getResponse()
Parse the response from the server.
|
protected javax.net.ssl.SSLSocketFactory |
getSSLSocketFactory(javax.net.ssl.TrustManager tm)
Returns a configured SSLSocketFactory to use in creating new SSL
sockets.
|
int |
list(int msgnum)
Returns the size of the specified message.
|
boolean |
login(java.lang.String username,
java.lang.String password)
Authenticate the user using the basic USER and PASS handshake.
|
void |
noop()
Does nothing.
|
boolean |
quit()
Closes the connection.
|
java.io.InputStream |
retr(int msgnum)
Returns an input stream containing the entire message.
|
void |
rset()
If any messages have been marked as deleted, they are unmarked.
|
protected void |
send(java.lang.String command)
Send the command to the server.
|
int |
stat()
Returns the number of messages in the maildrop.
|
boolean |
stls()
Attempts to start TLS on the specified connection.
|
boolean |
stls(javax.net.ssl.TrustManager tm)
Attempts to start TLS on the specified connection.
|
java.io.InputStream |
top(int msgnum)
Returns just the headers of the specified message as an input stream.
|
java.util.Map<java.lang.Integer,java.lang.String> |
uidl()
Returns a map of message number to UID pairs.
|
java.lang.String |
uidl(int msgnum)
Returns a unique identifier for the specified message.
|
public static final java.util.logging.Level POP3_TRACE
public static final int DEFAULT_PORT
public static final int DEFAULT_SSL_PORT
protected static final java.lang.String STAT
protected static final java.lang.String LIST
protected static final java.lang.String RETR
protected static final java.lang.String DELE
protected static final java.lang.String NOOP
protected static final java.lang.String RSET
protected static final java.lang.String QUIT
protected static final java.lang.String TOP
protected static final java.lang.String UIDL
protected static final java.lang.String USER
protected static final java.lang.String PASS
protected static final java.lang.String APOP
protected static final java.lang.String CAPA
protected static final java.lang.String STLS
protected static final java.lang.String AUTH
protected static final int OK
protected static final int ERR
protected static final int READY
public POP3Connection(java.lang.String hostname)
hostname
- the hostname of the server to connect topublic POP3Connection(java.lang.String hostname, int port)
hostname
- the hostname of the server to connect toport
- the port to connect to(if <=0, use default POP3 port)public POP3Connection(java.lang.String hostname, int port, int connectionTimeout, int timeout)
hostname
- the hostname of the server to connect toport
- the port to connect to(if <=0, use default POP3 port)connectionTimeout
- the connection timeout, in millisecondstimeout
- the I/O timeout, in millisecondspublic POP3Connection(java.lang.String hostname, int port, int connectionTimeout, int timeout, boolean secure, javax.net.ssl.TrustManager tm)
hostname
- the hostname of the server to connect toport
- the port to connect to(if <=0, use default POP3 port)connectionTimeout
- the connection timeout, in millisecondstimeout
- the I/O timeout, in millisecondssecure
- if true, create a POP3S connectiontm
- a trust manager used to check SSL certificates, or null to
use the defaultpublic java.util.logging.Logger getLogger()
public boolean auth(java.lang.String mechanism, java.lang.String username, java.lang.String password) throws java.io.IOException
mechanism
- a SASL authentication mechanism, e.g. LOGIN, PLAIN,
CRAM-MD5, GSSAPIusername
- the authentication principalpassword
- the authentication credentialsjava.io.IOException
public boolean apop(java.lang.String username, java.lang.String password) throws java.io.IOException
username
- the user to authenticatepassword
- the user's passwordjava.io.IOException
public boolean login(java.lang.String username, java.lang.String password) throws java.io.IOException
auth
or apop
method if the server
understands them.username
- the user to authenticatepassword
- the user's passwordjava.io.IOException
protected javax.net.ssl.SSLSocketFactory getSSLSocketFactory(javax.net.ssl.TrustManager tm) throws java.security.GeneralSecurityException
tm
- an optional trust manager to usejava.security.GeneralSecurityException
public boolean stls() throws java.io.IOException
java.io.IOException
public boolean stls(javax.net.ssl.TrustManager tm) throws java.io.IOException
tm
- the custom trust manager to usejava.io.IOException
public int stat() throws java.io.IOException
java.io.IOException
public int list(int msgnum) throws java.io.IOException
msgnum
- the message numberjava.io.IOException
public java.io.InputStream retr(int msgnum) throws java.io.IOException
msgnum
- the message numberjava.io.IOException
public void dele(int msgnum) throws java.io.IOException
msgnum
- the message numberjava.io.IOException
public void noop() throws java.io.IOException
java.io.IOException
public void rset() throws java.io.IOException
java.io.IOException
public boolean quit() throws java.io.IOException
java.io.IOException
public java.io.InputStream top(int msgnum) throws java.io.IOException
msgnum
- the message numberjava.io.IOException
public java.lang.String uidl(int msgnum) throws java.io.IOException
msgnum
- the message numberjava.io.IOException
public java.util.Map<java.lang.Integer,java.lang.String> uidl() throws java.io.IOException
java.io.IOException
public java.util.List<java.lang.String> capa() throws java.io.IOException
null
.java.io.IOException
protected void send(java.lang.String command) throws java.io.IOException
java.io.IOException
protected int getResponse() throws java.io.IOException
java.io.IOException