public class IMAP extends SocketClient
Modifier and Type | Class and Description |
---|---|
static interface |
IMAP.IMAPChunkListener
Implement this interface and register it via
setChunkListener(IMAPChunkListener)
in order to get access to multi-line partial command responses. |
static class |
IMAP.IMAPState |
Modifier and Type | Field and Description |
---|---|
protected static String |
__DEFAULT_ENCODING
The default control socket ecoding.
|
protected BufferedWriter |
__writer |
protected BufferedReader |
_reader |
static int |
DEFAULT_PORT
The default IMAP port (RFC 3501).
|
static IMAP.IMAPChunkListener |
TRUE_CHUNK_LISTENER
Implementation of IMAPChunkListener that returns
true
but otherwise does nothing. |
_defaultPort_, _hostname_, _input_, _output_, _serverSocketFactory_, _socket_, _socketFactory_, _timeout_, connectTimeout, NETASCII_EOL
Constructor and Description |
---|
IMAP()
The default IMAPClient constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_connectAction_()
Performs connection initialization and sets state to
IMAP.IMAPState.NOT_AUTH_STATE . |
void |
disconnect()
Disconnects the client from the server, and sets the state to
DISCONNECTED_STATE . |
boolean |
doCommand(IMAPCommand command)
Sends a command to the server and return whether successful.
|
boolean |
doCommand(IMAPCommand command,
String args)
Sends a command and arguments to the server and return whether successful.
|
protected void |
fireReplyReceived(int replyCode,
String ignored)
Overrides
SocketClient.fireReplyReceived(int, String) so as to
avoid creating the reply string if there are no listeners to invoke. |
protected String |
generateCommandID()
Generates a new command ID (tag) for a command.
|
String |
getReplyString()
Returns the reply to the last command sent to the server.
|
String[] |
getReplyStrings()
Returns an array of lines received as a reply to the last command
sent to the server.
|
IMAP.IMAPState |
getState()
Returns the current IMAP client state.
|
int |
sendCommand(IMAPCommand command)
Sends a command with no arguments to the server and returns the
reply code.
|
int |
sendCommand(IMAPCommand command,
String args)
Sends a command and arguments to the server and returns the reply code.
|
int |
sendCommand(String command)
Sends a command with no arguments to the server and returns the
reply code.
|
int |
sendCommand(String command,
String args)
Sends a command an arguments to the server and returns the reply code.
|
int |
sendData(String command)
Sends data to the server and returns the reply code.
|
void |
setChunkListener(IMAP.IMAPChunkListener listener)
Sets the current chunk listener.
|
protected void |
setState(IMAP.IMAPState state)
Sets IMAP client state.
|
addProtocolCommandListener, connect, connect, connect, connect, connect, connect, createCommandSupport, fireCommandSent, getCharset, getCharsetName, getCommandSupport, getConnectTimeout, getDefaultPort, getDefaultTimeout, getKeepAlive, getLocalAddress, getLocalPort, getProxy, getReceiveBufferSize, getRemoteAddress, getRemotePort, getSendBufferSize, getServerSocketFactory, getSoLinger, getSoTimeout, getTcpNoDelay, isAvailable, isConnected, removeProtocolCommandListener, setCharset, setConnectTimeout, setDefaultPort, setDefaultTimeout, setKeepAlive, setProxy, setReceiveBufferSize, setSendBufferSize, setServerSocketFactory, setSocketFactory, setSoLinger, setSoTimeout, setTcpNoDelay, verifyRemote
public static final int DEFAULT_PORT
protected static final String __DEFAULT_ENCODING
protected BufferedWriter __writer
protected BufferedReader _reader
public static final IMAP.IMAPChunkListener TRUE_CHUNK_LISTENER
Implementation of IMAPChunkListener that returns true
but 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.
setChunkListener(IMAPChunkListener)
public IMAP()
DISCONNECTED_STATE
.protected void fireReplyReceived(int replyCode, String ignored)
SocketClient.fireReplyReceived(int, String)
so as to
avoid creating the reply string if there are no listeners to invoke.fireReplyReceived
in class SocketClient
replyCode
- passed to the listenersignored
- the string is only created if there are listeners defined.getReplyString()
protected void _connectAction_() throws IOException
IMAP.IMAPState.NOT_AUTH_STATE
._connectAction_
in class SocketClient
IOException
- (SocketException) if a problem occurs with the socketprotected void setState(IMAP.IMAPState state)
_STATE
constants.state
- The new state.public IMAP.IMAPState getState()
public void disconnect() throws IOException
DISCONNECTED_STATE
. The reply text information
from the last issued command is voided to allow garbage collection
of the memory used to store that information.disconnect
in class SocketClient
IOException
- If there is an error in disconnecting.public int sendCommand(String command, String args) throws IOException
command
- The IMAP command to send.args
- The command arguments.IOException
- on errorpublic int sendCommand(String command) throws IOException
command
- The IMAP command to send.IOException
- on errorpublic int sendCommand(IMAPCommand command, String args) throws IOException
command
- The IMAP command to send
(one of the IMAPCommand constants).args
- The command arguments.IOException
- on errorpublic boolean doCommand(IMAPCommand command, String args) throws IOException
command
- The IMAP command to send
(one of the IMAPCommand constants).args
- The command arguments.true
if the command was successfulIOException
- on errorpublic int sendCommand(IMAPCommand command) throws IOException
command
- The IMAP command to send
(one of the IMAPCommand constants).IOException
- on errorpublic boolean doCommand(IMAPCommand command) throws IOException
command
- The IMAP command to send
(one of the IMAPCommand constants).true
if the command was successfulIOException
- on errorpublic int sendData(String command) throws IOException
command
- The IMAP command to send.IOException
- on errorpublic String[] getReplyStrings()
public String getReplyString()
public void setChunkListener(IMAP.IMAPChunkListener listener)
PrintCommandListener
instances will be invoked with the partial response and a status of
IMAPReply.PARTIAL
to indicate that the final reply code is not yet known.listener
- the class to use, or null
to disableTRUE_CHUNK_LISTENER
protected String generateCommandID()
Copyright © 2001–2016 The Apache Software Foundation. All rights reserved.