Package org.apache.commons.net.imap

# Class IMAPClient

java.lang.Object
org.apache.commons.net.SocketClient
org.apache.commons.net.imap.IMAP
org.apache.commons.net.imap.IMAPClient

Direct Known Subclasses:
  `IMAPSClient`

public class IMAPClient extends IMAP
The IMAPClient class provides the basic functionalities found in an IMAP client.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static enum`
  `IMAPClient.FETCH_ITEM_NAMES`
  The message data item names for the FETCH command defined in RFC 3501.
  `static enum`
  `IMAPClient.SEARCH_CRITERIA`
  The search criteria defined in RFC 3501.
  `static enum`
  `IMAPClient.STATUS_DATA_ITEMS`
  The status data items defined in RFC 3501.

  ## Nested classes/interfaces inherited from class org.apache.commons.net.imap.IMAP

  `IMAP.IMAPChunkListener, IMAP.IMAPState`

- ## Field Summary

  ### Fields inherited from class org.apache.commons.net.imap.IMAP

  `__DEFAULT_ENCODING, __writer, _reader, DEFAULT_PORT, TRUE_CHUNK_LISTENER`

  ### Fields inherited from class org.apache.commons.net.SocketClient

  `_defaultPort_, _hostname_, _input_, _output_, _serverSocketFactory_, _socket_, _socketFactory_, _timeout_, connectTimeout, NETASCII_EOL, remoteInetSocketAddress`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `IMAPClient()`
  Constructs a new instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `append(String mailboxName)`
  Deprecated.
  (3.4) Does not work; the message body is not optional.
  `boolean`
  `append(String mailboxName, String flags, String datetime)`
  Deprecated.
  (3.4) Does not work; the message body is not optional.
  `boolean`
  `append(String mailboxName, String flags, String datetime, String message)`
  Send an APPEND command to the server.
  `boolean`
  `capability()`
  Send a CAPABILITY command to the server.
  `boolean`
  `check()`
  Send a CHECK command to the server.
  `boolean`
  `close()`
  Send a CLOSE command to the server.
  `boolean`
  `copy(String sequenceSet, String mailboxName)`
  Send a COPY command to the server.
  `boolean`
  `create(String mailboxName)`
  Send a CREATE command to the server.
  `boolean`
  `delete(String mailboxName)`
  Send a DELETE command to the server.
  `boolean`
  `examine(String mailboxName)`
  Send an EXAMINE command to the server.
  `boolean`
  `expunge()`
  Send an EXPUNGE command to the server.
  `boolean`
  `fetch(String sequenceSet, String itemNames)`
  Send a FETCH command to the server.
  `boolean`
  `list(String refName, String mailboxName)`
  Send a LIST command to the server.
  `boolean`
  `login(String user, String password)`
  Login to the IMAP server with the given user and password.
  `boolean`
  `logout()`
  Send a LOGOUT command to the server.
  `boolean`
  `lsub(String refName, String mailboxName)`
  Send an LSUB command to the server.
  `boolean`
  `noop()`
  Send a NOOP command to the server.
  `boolean`
  `rename(String oldMailboxName, String newMailboxName)`
  Send a RENAME command to the server.
  `boolean`
  `search(String criteria)`
  Send a SEARCH command to the server.
  `boolean`
  `search(String charset, String criteria)`
  Send a SEARCH command to the server.
  `boolean`
  `select(String mailboxName)`
  Send a SELECT command to the server.
  `boolean`
  `status(String mailboxName, String[] itemNames)`
  Send a STATUS command to the server.
  `boolean`
  `store(String sequenceSet, String itemNames, String itemValues)`
  Send a STORE command to the server.
  `boolean`
  `subscribe(String mailboxName)`
  Send a SUBSCRIBE command to the server.
  `boolean`
  `uid(String command, String commandArgs)`
  Send a UID command to the server.
  `boolean`
  `unsubscribe(String mailboxName)`
  Send a UNSUBSCRIBE command to the server.

  ### Methods inherited from class org.apache.commons.net.imap.IMAP

  `_connectAction_, disconnect, doCommand, doCommand, fireReplyReceived, generateCommandID, getReplyString, getReplyStrings, getState, sendCommand, sendCommand, sendCommand, sendCommand, sendData, setChunkListener, setState`

  ### Methods inherited from class org.apache.commons.net.SocketClient

  `addProtocolCommandListener, applySocketAttributes, checkOpenOutputStream, connect, connect, connect, connect, connect, connect, createCommandSupport, fireCommandSent, getCharset, getCharsetName, getCommandSupport, getConnectTimeout, getDefaultPort, getDefaultTimeout, getHostAddress, getHostAddress, 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`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### IMAPClient

    public IMAPClient()
    Constructs a new instance.

- ## Method Details

  - ### append

    @Deprecated public boolean append(String mailboxName) throws IOException
    Deprecated.
    (3.4) Does not work; the message body is not optional. Use `append(String, String, String, String)` instead.
    Send an APPEND command to the server.
    Parameters:
      `mailboxName` - The mailbox name.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### append

    @Deprecated public boolean append(String mailboxName, String flags, String datetime) throws IOException
    Deprecated.
    (3.4) Does not work; the message body is not optional. Use `append(String, String, String, String)` instead.
    Send an APPEND command to the server.
    Parameters:
      `mailboxName` - The mailbox name.
      `flags` - The flag parenthesized list (optional).
      `datetime` - The date/time string (optional).
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### append

    public boolean append(String mailboxName, String flags, String datetime, String message) throws IOException
    Send an APPEND command to the server.
    Parameters:
      `mailboxName` - The mailbox name.
      `flags` - The flag parenthesized list (optional).
      `datetime` - The date/time string (optional).
      `message` - The message to append.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.
    Since:
      3.4

  - ### capability

    public boolean capability() throws IOException
    Send a CAPABILITY command to the server.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs

  - ### check

    public boolean check() throws IOException
    Send a CHECK command to the server.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### close

    public boolean close() throws IOException
    Send a CLOSE command to the server.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### copy

    public boolean copy(String sequenceSet, String mailboxName) throws IOException
    Send a COPY command to the server.
    Parameters:
      `sequenceSet` - The sequence set to fetch.
      `mailboxName` - The mailbox name.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### create

    public boolean create(String mailboxName) throws IOException
    Send a CREATE command to the server.
    Parameters:
      `mailboxName` - The mailbox name to create.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### delete

    public boolean delete(String mailboxName) throws IOException
    Send a DELETE command to the server.
    Parameters:
      `mailboxName` - The mailbox name to delete.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### examine

    public boolean examine(String mailboxName) throws IOException
    Send an EXAMINE command to the server.
    Parameters:
      `mailboxName` - The mailbox name to examine.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### expunge

    public boolean expunge() throws IOException
    Send an EXPUNGE command to the server.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### fetch

    public boolean fetch(String sequenceSet, String itemNames) throws IOException
    Send a FETCH command to the server.
    Parameters:
      `sequenceSet` - The sequence set to fetch (e.g. 1:4,6,11,100:*)
      `itemNames` - The item names for the FETCH command. (e.g. BODY.PEEK[HEADER.FIELDS (SUBJECT)]) If multiple item names are requested, these must be enclosed in parentheses, e.g. "(UID FLAGS BODY.PEEK[])"
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.
    See Also:
      - `IMAP.getReplyString()`
      - `IMAP.getReplyStrings()`

  - ### list

    public boolean list(String refName, String mailboxName) throws IOException
    Send a LIST command to the server. Quotes the parameters if necessary.
    Parameters:
      `refName` - The reference name If empty, indicates that the mailbox name is interpreted as by SELECT.
      `mailboxName` - The mailbox name. If empty, this is a special request to return the hierarchy delimiter and the root name of the name given in the reference
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### login

    public boolean login(String user, String password) throws IOException
    Login to the IMAP server with the given user and password. You must first connect to the server with `connect` before attempting to log in. A login attempt is only valid if the client is in the NOT_AUTH_STATE. After logging in, the client enters the AUTH_STATE.
    Parameters:
      `user` - The account name being logged in to.
      `password` - The plain text password of the account.
    Returns:
      True if the login attempt was successful, false if not.
    Throws:
      `IOException` - If a network I/O error occurs in the process of logging in.

  - ### logout

    public boolean logout() throws IOException
    Send a LOGOUT command to the server. To fully disconnect from the server you must call disconnect(). A logout attempt is valid in any state. If the client is in the not authenticated or authenticated state, it enters the logout on a successful logout.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### lsub

    public boolean lsub(String refName, String mailboxName) throws IOException
    Send an LSUB command to the server. Quotes the parameters if necessary.
    Parameters:
      `refName` - The reference name.
      `mailboxName` - The mailbox name.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### noop

    public boolean noop() throws IOException
    Send a NOOP command to the server. This is useful for keeping a connection alive since most IMAP servers will time out after 10 minutes of inactivity.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### rename

    public boolean rename(String oldMailboxName, String newMailboxName) throws IOException
    Send a RENAME command to the server.
    Parameters:
      `oldMailboxName` - The existing mailbox name to rename.
      `newMailboxName` - The new mailbox name.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### search

    public boolean search(String criteria) throws IOException
    Send a SEARCH command to the server.
    Parameters:
      `criteria` - The search criteria.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### search

    public boolean search(String charset, String criteria) throws IOException
    Send a SEARCH command to the server.
    Parameters:
      `charset` - The charset (optional).
      `criteria` - The search criteria.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### select

    public boolean select(String mailboxName) throws IOException
    Send a SELECT command to the server.
    Parameters:
      `mailboxName` - The mailbox name to select.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### status

    public boolean status(String mailboxName, String[] itemNames) throws IOException
    Send a STATUS command to the server.
    Parameters:
      `mailboxName` - The reference name.
      `itemNames` - The status data item names.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### store

    public boolean store(String sequenceSet, String itemNames, String itemValues) throws IOException
    Send a STORE command to the server.
    Parameters:
      `sequenceSet` - The sequence set to update (e.g. 2:5)
      `itemNames` - The item name for the STORE command (i.e. [+|-]FLAGS[.SILENT])
      `itemValues` - The item values for the STORE command. (e.g. (\Deleted) )
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### subscribe

    public boolean subscribe(String mailboxName) throws IOException
    Send a SUBSCRIBE command to the server.
    Parameters:
      `mailboxName` - The mailbox name to subscribe to.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### uid

    public boolean uid(String command, String commandArgs) throws IOException
    Send a UID command to the server.
    Parameters:
      `command` - The command for UID.
      `commandArgs` - The arguments for the command.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.

  - ### unsubscribe

    public boolean unsubscribe(String mailboxName) throws IOException
    Send a UNSUBSCRIBE command to the server.
    Parameters:
      `mailboxName` - The mailbox name to unsubscribe from.
    Returns:
      `true` if the command was successful,`false` if not.
    Throws:
      `IOException` - If a network I/O error occurs.