Top Description Fields Constructors Methods
com.sun.mail.pop3

pack-priv Class Protocol

Additional top-level class in compilation unit: Response.

extends Object
Class Inheritance
Imports
java.util.*, java.net.*, java.io.*, java.security.*, java.util.logging.Level, javax.net.ssl.SSLSocket, com.sun.mail.util.PropUtil, .MailLogger, .SocketFetcher, .LineInputStream, .TraceInputStream, .TraceOutputStream, .SharedByteArrayOutputStream

This class provides a POP3 connection and implements the POP3 protocol requests. APOP support courtesy of "chamness".
Author
Bill Shannon

Field Summary

Modifier and TypeField and Description
private String
private Map<String, String>
private static final String
private static char[]
private String
private BufferedReader
private MailLogger
private boolean
private PrintWriter
private boolean
private static final int
private String
private Properties
private static final int
private Socket
private TraceInputStream
private MailLogger
private TraceOutputStream
private boolean

Constructor Summary

AccessConstructor and Description
pack-priv
Protocol(String host, int port, MailLogger logger, Properties props, String prefix, boolean isSSL)

Open a connection to the POP3 server.

Method Summary

Modifier and TypeMethod and Description
private void
private void
private void
pack-priv synchronized InputStream
capa()

Get server capabilities using CAPA command specified by RFC 2449.

private static IOException
pack-priv void
close()

Close the connection without sending any commands.

pack-priv synchronized boolean
dele(int msg)

Delete (permanently) the specified message.

protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
private final synchronized boolean
getBoolProp(Properties props, String prop)

Get the value of a boolean property.

pack-priv synchronized Map<String, String>
getCapabilities()

Return the map of capabilities returned by the server.

private String

Returns:

The APOP digest or an empty string if an error occurs.
getDigest
(String
The APOP password
password
)

Gets the APOP message digest.

pack-priv synchronized boolean
hasCapability(String c)

Check whether the given capability is supported by this server.

private void
private static boolean
pack-priv synchronized boolean
isSSL()

Is this connection using SSL?

private void
issueCommand(String cmd)

Send the specified command.

protected boolean
isTracing()

Is protocol tracing enabled?

pack-priv synchronized int
list(int msg)

Return the size of the message using the LIST command.

pack-priv synchronized InputStream
list()

Return the size of all messages using the LIST command.

pack-priv synchronized String
login(String user, String password)

Login to the server, using the USER and PASS commands.

private Response
multilineCommand(String cmd, int size)

Issue a POP3 command that expects a multi-line response.

private void
private void
pack-priv synchronized boolean
noop()

Do a NOOP.

pack-priv synchronized boolean
quit()

Close down the connection, sending the QUIT command.

private InputStream
readMultilineResponse(int size)

Read the response to a multiline command after the command response.

private Response
readResponse()

Read the response to a command.

private void
resumeTracing()

Resume protocol tracing, if it was enabled to begin with.

pack-priv synchronized InputStream
retr(int msg, int size)

Retrieve the specified message.

pack-priv synchronized boolean
retr(int msg, OutputStream os)

Retrieve the specified message and stream the content to the specified OutputStream.

pack-priv synchronized boolean
rset()

Do an RSET.

pack-priv synchronized void
setCapabilities(InputStream in)

Parse the capabilities from a CAPA response.

private Response
simpleCommand(String cmd)

Issue a simple POP3 command and return the response.

private void
private void
pack-priv synchronized Status
stat()

Return the total number of messages and mailbox size, using the STAT command.

pack-priv synchronized boolean
stls()

Start TLS using STLS command specified by RFC 2595.

private void
suspendTracing()

Temporarily turn off protocol tracing, e.g., to prevent tracing the authentication sequence, including the password.

private static String
toHex(byte[] bytes)

Convert a byte array to a string of hex digits representing the bytes.

pack-priv synchronized InputStream
top(int msg, int n)

Return the message header and the first n lines of the message.

pack-priv synchronized String
uidl(int msg)

Return the UIDL string for the message.

pack-priv synchronized boolean
uidl(String[] uids)

Return the UIDL strings for all messages.

Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

apopChallengeback to summary
private String apopChallenge
capabilitiesback to summary
private Map<String, String> capabilities
CRLFback to summary
private static final String CRLF
digitsback to summary
private static char[] digits
hostback to summary
private String host
inputback to summary
private BufferedReader input
loggerback to summary
private MailLogger logger
noauthdebugback to summary
private boolean noauthdebug
outputback to summary
private PrintWriter output
pipeliningback to summary
private boolean pipelining
POP3_PORTback to summary
private static final int POP3_PORT
prefixback to summary
private String prefix
propsback to summary
private Properties props
SLOPback to summary
private static final int SLOP
socketback to summary
private Socket socket
traceInputback to summary
private TraceInputStream traceInput
traceLoggerback to summary
private MailLogger traceLogger
traceOutputback to summary
private TraceOutputStream traceOutput
traceSuspendedback to summary
private boolean traceSuspended

Constructor Detail

Protocolback to summary
pack-priv Protocol(String host, int port, MailLogger logger, Properties props, String prefix, boolean isSSL) throws IOException

Open a connection to the POP3 server.

Method Detail

batchCommandContinueback to summary
private void batchCommandContinue(String command)
batchCommandEndback to summary
private void batchCommandEnd()
batchCommandStartback to summary
private void batchCommandStart(String command)
capaback to summary
pack-priv synchronized InputStream capa() throws IOException

Get server capabilities using CAPA command specified by RFC 2449. Returns null if not supported.

cleanupAndThrowback to summary
private static IOException cleanupAndThrow(Socket socket, IOException ife)
closeback to summary
pack-priv void close()

Close the connection without sending any commands.

deleback to summary
pack-priv synchronized boolean dele(int msg) throws IOException

Delete (permanently) the specified message.

finalizeback to summary
protected void finalize() throws Throwable

Overrides java.lang.Object.finalize.

Doc from java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

When running in a Java virtual machine in which finalization has been disabled or removed, the garbage collector will never call finalize(). In a Java virtual machine in which finalization is enabled, the garbage collector might call finalize only after an indefinite delay.

The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Annotations
@Override
Exceptions
Throwable:
the Exception raised by this method
getBoolPropback to summary
private final synchronized boolean getBoolProp(Properties props, String prop)

Get the value of a boolean property. Print out the value if logging is enabled.

getCapabilitiesback to summary
pack-priv synchronized Map<String, String> getCapabilities()

Return the map of capabilities returned by the server.

getDigestback to summary
private String getDigest(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:String

The APOP password

Returns:String

The APOP digest or an empty string if an error occurs.

hasCapabilityback to summary
pack-priv synchronized boolean hasCapability(String c)

Check whether the given capability is supported by this server. Returns true if so, otherwise returns false.

initStreamsback to summary
private void initStreams() throws IOException
isRecoverableback to summary
private static boolean isRecoverable(Throwable t)
isSSLback to summary
pack-priv synchronized boolean isSSL()

Is this connection using SSL?

issueCommandback to summary
private void issueCommand(String cmd) throws IOException

Send the specified command.

isTracingback to summary
protected boolean isTracing()

Is protocol tracing enabled?

listback to summary
pack-priv synchronized int list(int msg) throws IOException

Return the size of the message using the LIST command.

listback to summary
pack-priv synchronized InputStream list() throws IOException

Return the size of all messages using the LIST command.

loginback to summary
pack-priv synchronized String login(String user, String password) throws IOException

Login to the server, using the USER and PASS commands.

multilineCommandback to summary
private Response multilineCommand(String cmd, int size) throws IOException

Issue a POP3 command that expects a multi-line response. size is an estimate of the response size.

multilineCommandEndback to summary
private void multilineCommandEnd()
multilineCommandStartback to summary
private void multilineCommandStart(String command)
noopback to summary
pack-priv synchronized boolean noop() throws IOException

Do a NOOP.

quitback to summary
pack-priv synchronized boolean quit() throws IOException

Close down the connection, sending the QUIT command.

readMultilineResponseback to summary
private InputStream readMultilineResponse(int size) throws IOException

Read 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.

readResponseback to summary
private Response readResponse() throws IOException

Read the response to a command.

resumeTracingback to summary
private void resumeTracing()

Resume protocol tracing, if it was enabled to begin with.

retrback to summary
pack-priv synchronized InputStream retr(int msg, int size) throws IOException

Retrieve 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.

retrback to summary
pack-priv synchronized boolean retr(int msg, OutputStream os) throws IOException

Retrieve the specified message and stream the content to the specified OutputStream. Return true on success.

rsetback to summary
pack-priv synchronized boolean rset() throws IOException

Do an RSET.

setCapabilitiesback to summary
pack-priv synchronized void setCapabilities(InputStream in)

Parse the capabilities from a CAPA response.

simpleCommandback to summary
private Response simpleCommand(String cmd) throws IOException

Issue a simple POP3 command and return the response.

simpleCommandEndback to summary
private void simpleCommandEnd()
simpleCommandStartback to summary
private void simpleCommandStart(String command)
statback to summary
pack-priv synchronized Status stat() throws IOException

Return the total number of messages and mailbox size, using the STAT command.

stlsback to summary
pack-priv synchronized boolean stls() throws IOException

Start TLS using STLS command specified by RFC 2595. If already using SSL, this is a nop and the STLS command is not issued.

suspendTracingback to summary
private void suspendTracing()

Temporarily turn off protocol tracing, e.g., to prevent tracing the authentication sequence, including the password.

toHexback to summary
private static String toHex(byte[] bytes)

Convert a byte array to a string of hex digits representing the bytes.

topback to summary
pack-priv synchronized InputStream top(int msg, int n) throws IOException

Return the message header and the first n lines of the message.

uidlback to summary
pack-priv synchronized String uidl(int msg) throws IOException

Return the UIDL string for the message.

uidlback to summary
pack-priv synchronized boolean uidl(String[] uids) throws IOException

Return the UIDL strings for all messages. The UID for msg #N is returned in uids[N-1].