Class IMAP

java.lang.Object
org.apache.commons.net.SocketClient
org.apache.commons.net.imap.IMAP
Direct Known Subclasses:
IMAPClient

public class IMAP extends SocketClient
The IMAP class provides the basic the functionality necessary to implement your own IMAP client.
  • Field Details Link icon

    • DEFAULT_PORT Link icon

      public static final int DEFAULT_PORT
      The default IMAP port (RFC 3501).
      See Also:
    • __DEFAULT_ENCODING Link icon

      protected static final String __DEFAULT_ENCODING
      The default control socket encoding.
    • TRUE_CHUNK_LISTENER Link icon

      Implements IMAP.IMAPChunkListener to 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.

      Since:
      3.4
      See Also:
    • __writer Link icon

    • _reader Link icon

  • Constructor Details Link icon

    • IMAP Link icon

      public IMAP()
      The default IMAPClient constructor. Initializes the state to DISCONNECTED_STATE.
  • Method Details Link icon

    • _connectAction_ Link icon

      protected void _connectAction_() throws IOException
      Performs connection initialization and sets state to IMAP.IMAPState.NOT_AUTH_STATE.
      Overrides:
      _connectAction_ in class SocketClient
      Throws:
      IOException - (SocketException) if a problem occurs with the socket
    • disconnect Link icon

      public void disconnect() throws IOException
      Disconnects the client from the server, and sets the state to 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.
      Overrides:
      disconnect in class SocketClient
      Throws:
      IOException - If there is an error in disconnecting.
    • doCommand Link icon

      public boolean doCommand(IMAPCommand command) throws IOException
      Sends a command to the server and return whether successful.
      Parameters:
      command - The IMAP command to send (one of the IMAPCommand constants).
      Returns:
      true if the command was successful
      Throws:
      IOException - on error
    • doCommand Link icon

      public boolean doCommand(IMAPCommand command, String args) throws IOException
      Sends 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:
      true if the command was successful
      Throws:
      IOException - on error
    • fireReplyReceived Link icon

      protected void fireReplyReceived(int replyCode, String ignored)
      Overrides SocketClient.fireReplyReceived(int, String) to avoid creating the reply string if there are no listeners to invoke.
      Overrides:
      fireReplyReceived in class SocketClient
      Parameters:
      replyCode - passed to the listeners
      ignored - the string is only created if there are listeners defined.
      Since:
      3.4
      See Also:
    • generateCommandID Link icon

      Generates a new command ID (tag) for a command.
      Returns:
      a new command ID (tag) for an IMAP command.
    • getReplyString Link icon

      Returns 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.
    • getReplyStrings Link icon

      public String[] getReplyStrings()
      Returns 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.
    • getState Link icon

      Returns the current IMAP client state.
      Returns:
      The current IMAP client state.
    • sendCommand Link icon

      public int sendCommand(IMAPCommand command) throws IOException
      Sends 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
    • sendCommand Link icon

      public int sendCommand(IMAPCommand command, String args) throws IOException
      Sends 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
    • sendCommand Link icon

      public int sendCommand(String command) throws IOException
      Sends 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
    • sendCommand Link icon

      public int sendCommand(String command, String args) throws IOException
      Sends 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
    • sendData Link icon

      public int sendData(String command) throws IOException
      Sends 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
    • setChunkListener Link icon

      public void setChunkListener(IMAP.IMAPChunkListener listener)
      Sets the current chunk listener. If a listener is registered and the implementation returns true, then any registered 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.
      Parameters:
      listener - the class to use, or null to disable
      Since:
      3.4
      See Also:
    • setState Link icon

      protected void setState(IMAP.IMAPState state)
      Sets IMAP client state. This must be one of the _STATE constants.
      Parameters:
      state - The new state.