Class 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 Detail

      • TRUE_CHUNK_LISTENER

        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.

        Since:
        3.4
        See Also:
        setChunkListener(IMAPChunkListener)
      • __writer

        protected java.io.BufferedWriter __writer
      • _reader

        protected java.io.BufferedReader _reader
    • Constructor Detail

      • IMAP

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

      • disconnect

        public void disconnect()
                        throws java.io.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:
        java.io.IOException - If there is an error in disconnecting.
      • doCommand

        public boolean doCommand​(IMAPCommand command)
                          throws java.io.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:
        java.io.IOException - on error
      • doCommand

        public boolean doCommand​(IMAPCommand command,
                                 java.lang.String args)
                          throws java.io.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:
        java.io.IOException - on error
      • generateCommandID

        protected java.lang.String generateCommandID()
        Generates a new command ID (tag) for a command.
        Returns:
        a new command ID (tag) for an IMAP command.
      • getReplyString

        public java.lang.String getReplyString()
        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

        public java.lang.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

        public IMAP.IMAPState getState()
        Returns the current IMAP client state.
        Returns:
        The current IMAP client state.
      • sendCommand

        public int sendCommand​(IMAPCommand command)
                        throws java.io.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:
        java.io.IOException - on error
      • sendCommand

        public int sendCommand​(IMAPCommand command,
                               java.lang.String args)
                        throws java.io.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:
        java.io.IOException - on error
      • sendCommand

        public int sendCommand​(java.lang.String command)
                        throws java.io.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:
        java.io.IOException - on error
      • sendCommand

        public int sendCommand​(java.lang.String command,
                               java.lang.String args)
                        throws java.io.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:
        java.io.IOException - on error
      • sendData

        public int sendData​(java.lang.String command)
                     throws java.io.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:
        java.io.IOException - on error
      • setState

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