Package org.apache.commons.net.imap
Class IMAP
java.lang.Object
org.apache.commons.net.SocketClient
org.apache.commons.net.imap.IMAP
- Direct Known Subclasses:
- IMAPClient
The IMAP class provides the basic the functionality necessary to implement your own IMAP client.
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic interfaceImplement this interface and register it viasetChunkListener(IMAPChunkListener)in order to get access to multi-line partial command responses.static enum
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected static final StringThe default control socket encoding.protected BufferedWriterprotected BufferedReaderstatic final intThe default IMAP port (RFC 3501).static final IMAP.IMAPChunkListenerImplementsIMAP.IMAPChunkListenerto returnstruebut otherwise does nothing.Fields inherited from class org.apache.commons.net.SocketClient_defaultPort_, _hostname_, _input_, _output_, _serverSocketFactory_, _socket_, _socketFactory_, _timeout_, connectTimeout, NETASCII_EOL, remoteInetSocketAddress
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidPerforms connection initialization and sets state toIMAP.IMAPState.NOT_AUTH_STATE.voidDisconnects the client from the server, and sets the state toDISCONNECTED_STATE.booleandoCommand(IMAPCommand command) Sends a command to the server and return whether successful.booleandoCommand(IMAPCommand command, String args) Sends a command and arguments to the server and return whether successful.protected voidfireReplyReceived(int replyCode, String ignored) OverridesSocketClient.fireReplyReceived(int, String)to avoid creating the reply string if there are no listeners to invoke.protected StringGenerates a new command ID (tag) for a command.Returns the reply to the last command sent to the server.String[]Returns an array of lines received as a reply to the last command sent to the server.getState()Returns the current IMAP client state.intsendCommand(String command) Sends a command with no arguments to the server and returns the reply code.intsendCommand(String command, String args) Sends a command an arguments to the server and returns the reply code.intsendCommand(IMAPCommand command) Sends a command with no arguments to the server and returns the reply code.intsendCommand(IMAPCommand command, String args) Sends a command and arguments to the server and returns the reply code.intSends data to the server and returns the reply code.voidsetChunkListener(IMAP.IMAPChunkListener listener) Sets the current chunk listener.protected voidsetState(IMAP.IMAPState state) Sets IMAP client state.Methods inherited from class org.apache.commons.net.SocketClientaddProtocolCommandListener, applySocketAttributes, checkOpenOutputStream, connect, connect, connect, connect, connect, connect, createCommandSupport, fireCommandSent, getCharset, getCharsetName, getCommandSupport, getConnectTimeout, getDefaultPort, getDefaultTimeout, getKeepAlive, getLocalAddress, getLocalPort, getProxy, getReceiveBufferSize, getRemoteAddress, getRemoteInetSocketAddress, getRemotePort, getSendBufferSize, getServerSocketFactory, getSoLinger, getSoTimeout, getTcpNoDelay, isAvailable, isConnected, removeProtocolCommandListener, setCharset, setConnectTimeout, setDefaultPort, setDefaultTimeout, setKeepAlive, setProxy, setReceiveBufferSize, setSendBufferSize, setServerSocketFactory, setSocketFactory, setSoLinger, setSoTimeout, setTcpNoDelay, verifyRemote
- 
Field Details- 
DEFAULT_PORTThe default IMAP port (RFC 3501).- See Also:
 
- 
__DEFAULT_ENCODINGThe default control socket encoding.
- 
TRUE_CHUNK_LISTENERImplements IMAP.IMAPChunkListenerto returnstruebut otherwise does nothing.This is intended for use with a suitable ProtocolCommandListener. If the IMAP response contains multiple-line data, the protocol listener will be called for each multi-line chunk. The accumulated reply data will be cleared after calling the listener. If the response is very long, this can significantly reduce memory requirements. The listener will also start receiving response data earlier, as it does not have to wait for the entire response to be read. The ProtocolCommandListener must be prepared to accept partial responses. This should not be a problem for listeners that just log the input. - Since:
- 3.4
- See Also:
 
- 
__writer
- 
_reader
 
- 
- 
Constructor Details- 
IMAPpublic IMAP()The default IMAPClient constructor. Initializes the state toDISCONNECTED_STATE.
 
- 
- 
Method Details- 
_connectAction_Performs connection initialization and sets state toIMAP.IMAPState.NOT_AUTH_STATE.- Overrides:
- _connectAction_in class- SocketClient
- Throws:
- IOException- (SocketException) if a problem occurs with the socket
 
- 
disconnectDisconnects the client from the server, and sets the state toDISCONNECTED_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:
- disconnectin class- SocketClient
- Throws:
- IOException- If there is an error in disconnecting.
 
- 
doCommandSends a command to the server and return whether successful.- Parameters:
- command- The IMAP command to send (one of the IMAPCommand constants).
- Returns:
- trueif the command was successful
- Throws:
- IOException- on error
 
- 
doCommandSends a command and arguments to the server and return whether successful.- Parameters:
- command- The IMAP command to send (one of the IMAPCommand constants).
- args- The command arguments.
- Returns:
- trueif the command was successful
- Throws:
- IOException- on error
 
- 
fireReplyReceivedOverridesSocketClient.fireReplyReceived(int, String)to avoid creating the reply string if there are no listeners to invoke.- Overrides:
- fireReplyReceivedin class- SocketClient
- Parameters:
- replyCode- passed to the listeners
- ignored- the string is only created if there are listeners defined.
- Since:
- 3.4
- See Also:
 
- 
generateCommandIDGenerates a new command ID (tag) for a command.- Returns:
- a new command ID (tag) for an IMAP command.
 
- 
getReplyStringReturns the reply to the last command sent to the server. The value is a single string containing all the reply lines including newlines.- Returns:
- The last server response.
 
- 
getReplyStringsReturns an array of lines received as a reply to the last command sent to the server. The lines have end of lines truncated.- Returns:
- The last server response.
 
- 
getStateReturns the current IMAP client state.- Returns:
- The current IMAP client state.
 
- 
sendCommandSends a command with no arguments to the server and returns the reply code.- Parameters:
- command- The IMAP command to send (one of the IMAPCommand constants).
- Returns:
- The server reply code (see IMAPReply).
- Throws:
- IOException- on error
 
- 
sendCommandSends a command and arguments to the server and returns the reply code.- Parameters:
- command- The IMAP command to send (one of the IMAPCommand constants).
- args- The command arguments.
- Returns:
- The server reply code (see IMAPReply).
- Throws:
- IOException- on error
 
- 
sendCommandSends a command with no arguments to the server and returns the reply code.- Parameters:
- command- The IMAP command to send.
- Returns:
- The server reply code (see IMAPReply).
- Throws:
- IOException- on error
 
- 
sendCommandSends a command an arguments to the server and returns the reply code.- Parameters:
- command- The IMAP command to send.
- args- The command arguments.
- Returns:
- The server reply code (see IMAPReply).
- Throws:
- IOException- on error
 
- 
sendDataSends data to the server and returns the reply code.- Parameters:
- command- The IMAP command to send.
- Returns:
- The server reply code (see IMAPReply).
- Throws:
- IOException- on error
 
- 
setChunkListenerSets the current chunk listener. If a listener is registered and the implementation returns true, then any registeredPrintCommandListenerinstances will be invoked with the partial response and a status ofIMAPReply.PARTIALto indicate that the final reply code is not yet known.- Parameters:
- listener- the class to use, or- nullto disable
- Since:
- 3.4
- See Also:
 
- 
setStateSets IMAP client state. This must be one of the_STATEconstants.- Parameters:
- state- The new state.
 
 
-