public class POP3Connection extends Object
| Modifier and Type | Field and Description |
|---|---|
protected static String |
APOP |
protected static String |
AUTH |
protected static String |
CAPA |
static int |
DEFAULT_PORT
The default POP3 port.
|
protected static String |
DELE |
protected static int |
ERR |
protected LineInputStream |
in
The socket input stream.
|
protected static String |
LIST |
static Logger |
logger
The logger used for POP3 protocol traces.
|
protected static String |
NOOP |
protected static int |
OK |
protected CRLFOutputStream |
out
The socket output stream.
|
protected static String |
PASS |
static Level |
POP3_TRACE
The network trace level.
|
protected static String |
QUIT |
protected static int |
READY |
protected String |
response
The last response received from the server.
|
protected static String |
RETR |
protected static String |
RSET |
protected Socket |
socket
The socket used to communicate with the server.
|
protected static String |
STAT |
protected static String |
STLS |
protected byte[] |
timestamp
The APOP timestamp, if sent by the server on connection.
|
protected static String |
TOP |
protected static String |
UIDL |
protected static String |
USER |
| Constructor and Description |
|---|
POP3Connection(String hostname)
Creates a new connection to the server.
|
POP3Connection(String hostname,
int port)
Creates a new connection to the server.
|
POP3Connection(String hostname,
int port,
int connectionTimeout,
int timeout)
Creates a new connection to the server.
|
POP3Connection(String hostname,
int port,
int connectionTimeout,
int timeout,
boolean secure,
TrustManager tm)
Creates a new connection to the server.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
apop(String username,
String password)
Authenticate the specified user using the APOP MD5-based method.
|
boolean |
auth(String mechanism,
String username,
String password)
Authenticates the connection using the specified SASL mechanism,
username, and password.
|
List |
capa()
Returns a list of capabilities supported by the POP3 server.
|
void |
dele(int msgnum)
Marks the specified message as deleted.
|
protected int |
getResponse()
Parse the response from the server.
|
protected SSLSocketFactory |
getSSLSocketFactory(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(String username,
String password)
Authenticate the user using the basic USER and PASS handshake.
|
void |
noop()
Does nothing.
|
boolean |
quit()
Closes the connection.
|
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(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(TrustManager tm)
Attempts to start TLS on the specified connection.
|
InputStream |
top(int msgnum)
Returns just the headers of the specified message as an input stream.
|
Map |
uidl()
Returns a map of message number to UID pairs.
|
String |
uidl(int msgnum)
Returns a unique identifier for the specified message.
|
public static final Logger logger
public static final Level POP3_TRACE
public static final int DEFAULT_PORT
protected static final String STAT
protected static final String LIST
protected static final String RETR
protected static final String DELE
protected static final String NOOP
protected static final String RSET
protected static final String QUIT
protected static final String TOP
protected static final String UIDL
protected static final String USER
protected static final String PASS
protected static final String APOP
protected static final String CAPA
protected static final String STLS
protected static final String AUTH
protected static final int OK
protected static final int ERR
protected static final int READY
protected Socket socket
protected LineInputStream in
protected CRLFOutputStream out
protected String response
protected byte[] timestamp
public POP3Connection(String hostname) throws UnknownHostException, IOException
hostname - the hostname of the server to connect toUnknownHostExceptionIOExceptionpublic POP3Connection(String hostname, int port) throws UnknownHostException, IOException
hostname - the hostname of the server to connect toport - the port to connect to(if <=0, use default POP3 port)UnknownHostExceptionIOExceptionpublic POP3Connection(String hostname, int port, int connectionTimeout, int timeout) throws UnknownHostException, IOException
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 millisecondsUnknownHostExceptionIOExceptionpublic POP3Connection(String hostname, int port, int connectionTimeout, int timeout, boolean secure, TrustManager tm) throws UnknownHostException, IOException
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 defaultUnknownHostExceptionIOExceptionpublic boolean auth(String mechanism, String username, String password) throws IOException
mechanism - a SASL authentication mechanism, e.g. LOGIN, PLAIN,
CRAM-MD5, GSSAPIusername - the authentication principalpassword - the authentication credentialsIOExceptionpublic boolean apop(String username, String password) throws IOException
username - the user to authenticatepassword - the user's passwordIOExceptionpublic boolean login(String username, String password) throws IOException
auth or apop method if the server
understands them.username - the user to authenticatepassword - the user's passwordIOExceptionprotected SSLSocketFactory getSSLSocketFactory(TrustManager tm) throws GeneralSecurityException
tm - an optional trust manager to useGeneralSecurityExceptionpublic boolean stls()
throws IOException
IOExceptionpublic boolean stls(TrustManager tm) throws IOException
tm - the custom trust manager to useIOExceptionpublic int stat()
throws IOException
IOExceptionpublic int list(int msgnum)
throws IOException
msgnum - the message numberIOExceptionpublic InputStream retr(int msgnum) throws IOException
msgnum - the message numberIOExceptionpublic void dele(int msgnum)
throws IOException
msgnum - the message numberIOExceptionpublic void noop()
throws IOException
IOExceptionpublic void rset()
throws IOException
IOExceptionpublic boolean quit()
throws IOException
IOExceptionpublic InputStream top(int msgnum) throws IOException
msgnum - the message numberIOExceptionpublic String uidl(int msgnum) throws IOException
msgnum - the message numberIOExceptionpublic Map uidl() throws IOException
IOExceptionpublic List capa() throws IOException
null.IOExceptionprotected void send(String command) throws IOException
IOExceptionprotected int getResponse()
throws IOException
IOExceptionCopyright © 2017. All rights reserved.