Package com.sun.mail.pop3
Class Protocol
- java.lang.Object
-
- com.sun.mail.pop3.Protocol
-
class Protocol extends java.lang.ObjectThis class provides a POP3 connection and implements the POP3 protocol requests. APOP support courtesy of "chamness".
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringapopChallengeprivate java.util.Map<java.lang.String,java.lang.String>capabilitiesprivate static java.lang.StringCRLFprivate static char[]digitsprivate java.lang.Stringhostprivate java.io.BufferedReaderinputprivate MailLoggerloggerprivate booleannoauthdebugprivate java.io.PrintWriteroutputprivate booleanpipeliningprivate static intPOP3_PORTprivate java.lang.Stringprefixprivate java.util.Propertiespropsprivate static intSLOPprivate java.net.Socketsocketprivate TraceInputStreamtraceInputprivate MailLoggertraceLoggerprivate TraceOutputStreamtraceOutputprivate booleantraceSuspended
-
Constructor Summary
Constructors Constructor Description Protocol(java.lang.String host, int port, MailLogger logger, java.util.Properties props, java.lang.String prefix, boolean isSSL)Open a connection to the POP3 server.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidbatchCommandContinue(java.lang.String command)private voidbatchCommandEnd()private voidbatchCommandStart(java.lang.String command)(package private) java.io.InputStreamcapa()Get server capabilities using CAPA command specified by RFC 2449.private static java.io.IOExceptioncleanupAndThrow(java.net.Socket socket, java.io.IOException ife)(package private) voidclose()Close the connection without sending any commands.(package private) booleandele(int msg)Delete (permanently) the specified message.protected voidfinalize()private booleangetBoolProp(java.util.Properties props, java.lang.String prop)Get the value of a boolean property.(package private) java.util.Map<java.lang.String,java.lang.String>getCapabilities()Return the map of capabilities returned by the server.private java.lang.StringgetDigest(java.lang.String password)Gets the APOP message digest.(package private) booleanhasCapability(java.lang.String c)Check whether the given capability is supported by this server.private voidinitStreams()private static booleanisRecoverable(java.lang.Throwable t)(package private) booleanisSSL()Is this connection using SSL?private voidissueCommand(java.lang.String cmd)Send the specified command.protected booleanisTracing()Is protocol tracing enabled?(package private) java.io.InputStreamlist()Return the size of all messages using the LIST command.(package private) intlist(int msg)Return the size of the message using the LIST command.(package private) java.lang.Stringlogin(java.lang.String user, java.lang.String password)Login to the server, using the USER and PASS commands.private ResponsemultilineCommand(java.lang.String cmd, int size)Issue a POP3 command that expects a multi-line response.private voidmultilineCommandEnd()private voidmultilineCommandStart(java.lang.String command)(package private) booleannoop()Do a NOOP.(package private) booleanquit()Close down the connection, sending the QUIT command.private java.io.InputStreamreadMultilineResponse(int size)Read the response to a multiline command after the command response.private ResponsereadResponse()Read the response to a command.private voidresumeTracing()Resume protocol tracing, if it was enabled to begin with.(package private) java.io.InputStreamretr(int msg, int size)Retrieve the specified message.(package private) booleanretr(int msg, java.io.OutputStream os)Retrieve the specified message and stream the content to the specified OutputStream.(package private) booleanrset()Do an RSET.(package private) voidsetCapabilities(java.io.InputStream in)Parse the capabilities from a CAPA response.private ResponsesimpleCommand(java.lang.String cmd)Issue a simple POP3 command and return the response.private voidsimpleCommandEnd()private voidsimpleCommandStart(java.lang.String command)(package private) Statusstat()Return the total number of messages and mailbox size, using the STAT command.(package private) booleanstls()Start TLS using STLS command specified by RFC 2595.private voidsuspendTracing()Temporarily turn off protocol tracing, e.g., to prevent tracing the authentication sequence, including the password.private static java.lang.StringtoHex(byte[] bytes)Convert a byte array to a string of hex digits representing the bytes.(package private) java.io.InputStreamtop(int msg, int n)Return the message header and the first n lines of the message.(package private) java.lang.Stringuidl(int msg)Return the UIDL string for the message.(package private) booleanuidl(java.lang.String[] uids)Return the UIDL strings for all messages.
-
-
-
Field Detail
-
socket
private java.net.Socket socket
-
host
private java.lang.String host
-
props
private java.util.Properties props
-
prefix
private java.lang.String prefix
-
input
private java.io.BufferedReader input
-
output
private java.io.PrintWriter output
-
traceInput
private TraceInputStream traceInput
-
traceOutput
private TraceOutputStream traceOutput
-
logger
private MailLogger logger
-
traceLogger
private MailLogger traceLogger
-
apopChallenge
private java.lang.String apopChallenge
-
capabilities
private java.util.Map<java.lang.String,java.lang.String> capabilities
-
pipelining
private boolean pipelining
-
noauthdebug
private boolean noauthdebug
-
traceSuspended
private boolean traceSuspended
-
POP3_PORT
private static final int POP3_PORT
- See Also:
- Constant Field Values
-
CRLF
private static final java.lang.String CRLF
- See Also:
- Constant Field Values
-
SLOP
private static final int SLOP
- See Also:
- Constant Field Values
-
digits
private static char[] digits
-
-
Constructor Detail
-
Protocol
Protocol(java.lang.String host, int port, MailLogger logger, java.util.Properties props, java.lang.String prefix, boolean isSSL) throws java.io.IOExceptionOpen a connection to the POP3 server.- Throws:
java.io.IOException
-
-
Method Detail
-
cleanupAndThrow
private static java.io.IOException cleanupAndThrow(java.net.Socket socket, java.io.IOException ife)
-
isRecoverable
private static boolean isRecoverable(java.lang.Throwable t)
-
getBoolProp
private final boolean getBoolProp(java.util.Properties props, java.lang.String prop)Get the value of a boolean property. Print out the value if logging is enabled.
-
initStreams
private void initStreams() throws java.io.IOException- Throws:
java.io.IOException
-
finalize
protected void finalize() throws java.lang.Throwable- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
setCapabilities
void setCapabilities(java.io.InputStream in)
Parse the capabilities from a CAPA response.
-
hasCapability
boolean hasCapability(java.lang.String c)
Check whether the given capability is supported by this server. Returnstrueif so, otherwise returns false.
-
getCapabilities
java.util.Map<java.lang.String,java.lang.String> getCapabilities()
Return the map of capabilities returned by the server.
-
login
java.lang.String login(java.lang.String user, java.lang.String password) throws java.io.IOExceptionLogin to the server, using the USER and PASS commands.- Throws:
java.io.IOException
-
getDigest
private java.lang.String getDigest(java.lang.String password)
Gets the APOP message digest. From RFC 1939: The 'digest' parameter is calculated by applying the MD5 algorithm [RFC1321] to a string consisting of the timestamp (including angle-brackets) followed by a shared secret. The 'digest' parameter itself is a 16-octet value which is sent in hexadecimal format, using lower-case ASCII characters.- Parameters:
password- The APOP password- Returns:
- The APOP digest or an empty string if an error occurs.
-
toHex
private static java.lang.String toHex(byte[] bytes)
Convert a byte array to a string of hex digits representing the bytes.
-
quit
boolean quit() throws java.io.IOExceptionClose down the connection, sending the QUIT command.- Throws:
java.io.IOException
-
close
void close()
Close the connection without sending any commands.
-
stat
Status stat() throws java.io.IOException
Return the total number of messages and mailbox size, using the STAT command.- Throws:
java.io.IOException
-
list
int list(int msg) throws java.io.IOException
Return the size of the message using the LIST command.- Throws:
java.io.IOException
-
list
java.io.InputStream list() throws java.io.IOExceptionReturn the size of all messages using the LIST command.- Throws:
java.io.IOException
-
retr
java.io.InputStream retr(int msg, int size) throws java.io.IOExceptionRetrieve the specified message. Given an estimate of the message's size we can be more efficient, preallocating the array and returning a SharedInputStream to allow us to share the array.- Throws:
java.io.IOException
-
retr
boolean retr(int msg, java.io.OutputStream os) throws java.io.IOExceptionRetrieve the specified message and stream the content to the specified OutputStream. Return true on success.- Throws:
java.io.IOException
-
top
java.io.InputStream top(int msg, int n) throws java.io.IOExceptionReturn the message header and the first n lines of the message.- Throws:
java.io.IOException
-
dele
boolean dele(int msg) throws java.io.IOExceptionDelete (permanently) the specified message.- Throws:
java.io.IOException
-
uidl
java.lang.String uidl(int msg) throws java.io.IOExceptionReturn the UIDL string for the message.- Throws:
java.io.IOException
-
uidl
boolean uidl(java.lang.String[] uids) throws java.io.IOExceptionReturn the UIDL strings for all messages. The UID for msg #N is returned in uids[N-1].- Throws:
java.io.IOException
-
noop
boolean noop() throws java.io.IOExceptionDo a NOOP.- Throws:
java.io.IOException
-
rset
boolean rset() throws java.io.IOExceptionDo an RSET.- Throws:
java.io.IOException
-
stls
boolean stls() throws java.io.IOExceptionStart TLS using STLS command specified by RFC 2595. If already using SSL, this is a nop and the STLS command is not issued.- Throws:
java.io.IOException
-
isSSL
boolean isSSL()
Is this connection using SSL?
-
capa
java.io.InputStream capa() throws java.io.IOExceptionGet server capabilities using CAPA command specified by RFC 2449. Returns null if not supported.- Throws:
java.io.IOException
-
simpleCommand
private Response simpleCommand(java.lang.String cmd) throws java.io.IOException
Issue a simple POP3 command and return the response.- Throws:
java.io.IOException
-
issueCommand
private void issueCommand(java.lang.String cmd) throws java.io.IOExceptionSend the specified command.- Throws:
java.io.IOException
-
readResponse
private Response readResponse() throws java.io.IOException
Read the response to a command.- Throws:
java.io.IOException
-
multilineCommand
private Response multilineCommand(java.lang.String cmd, int size) throws java.io.IOException
Issue a POP3 command that expects a multi-line response.sizeis an estimate of the response size.- Throws:
java.io.IOException
-
readMultilineResponse
private java.io.InputStream readMultilineResponse(int size) throws java.io.IOExceptionRead the response to a multiline command after the command response. The size parameter indicates the expected size of the response; the actual size can be different. Returns an InputStream to the response bytes.- Throws:
java.io.IOException
-
isTracing
protected boolean isTracing()
Is protocol tracing enabled?
-
suspendTracing
private void suspendTracing()
Temporarily turn off protocol tracing, e.g., to prevent tracing the authentication sequence, including the password.
-
resumeTracing
private void resumeTracing()
Resume protocol tracing, if it was enabled to begin with.
-
simpleCommandStart
private void simpleCommandStart(java.lang.String command)
-
simpleCommandEnd
private void simpleCommandEnd()
-
multilineCommandStart
private void multilineCommandStart(java.lang.String command)
-
multilineCommandEnd
private void multilineCommandEnd()
-
batchCommandStart
private void batchCommandStart(java.lang.String command)
-
batchCommandContinue
private void batchCommandContinue(java.lang.String command)
-
batchCommandEnd
private void batchCommandEnd()
-
-