Section 6. Client Commands

IMAP4rev2 commands are described in this section.  Commands are
   organized by the state in which the command is permitted.  Commands
   that are permitted in multiple states are listed in the minimum
   permitted state (for example, commands valid in authenticated and
   selected states are listed in the authenticated state commands).
   Command arguments, identified by "Arguments:" in the command
   descriptions below, are described by function, not by syntax.  The
   precise syntax of command arguments is described in "Formal Syntax"
   (Section 9).
   Some commands cause specific server responses to be returned; these
   are identified by "Responses:" in the command descriptions below.
   See the response descriptions in "Responses" (Section 7) for
   information on these responses and in "Formal Syntax" (Section 9) for
   the precise syntax of these responses.  It is possible for server
   data to be transmitted as a result of any command.  Thus, commands
   that do not specifically require server data specify "no specific
   responses for this command" instead of "none".
   The "Result:" in the command description refers to the possible
   tagged status responses to a command and any special interpretation
   of these status responses.
   The state of a connection is only changed by successful commands that
   are documented as changing state.  A rejected command (BAD response)
   never changes the state of the connection or of the selected mailbox.
   A failed command (NO response) generally does not change the state of
   the connection or of the selected mailbox, with the exception of the
   SELECT and EXAMINE commands.
6.1.  Client Commands - Any State
   The following commands are valid in any state: CAPABILITY, NOOP, and
   LOGOUT.
6.1.1.  CAPABILITY Command
   Arguments:    none
   Responses:    REQUIRED untagged response:  CAPABILITY
   Result:       OK -  capability completed
                 BAD -  arguments invalid
   The CAPABILITY command requests a listing of capabilities (e.g.,
   extensions and/or modifications of server behavior) that the server
   supports.  The server MUST send a single untagged CAPABILITY response
   with "IMAP4rev2" as one of the listed capabilities before the
   (tagged) OK response.
   A capability name that begins with "AUTH=" indicates that the server
   supports that particular authentication mechanism as defined in the
   Simple Authentication and Security Layer (SASL) [SASL].  All such
   names are, by definition, part of this specification.
   Other capability names refer to extensions, revisions, or amendments
   to this specification.  See the documentation of the CAPABILITY
   response in Section 7.2.2 for additional information.  If IMAP4rev1
   capability is not advertised, no capabilities, beyond the base
   IMAP4rev2 set defined in this specification, are enabled without
   explicit client action to invoke the capability.  If both IMAP4rev1
   and IMAP4rev2 capabilities are advertised, no capabilities, beyond
   the base IMAP4rev1 set specified in [RFC3501], are enabled without
   explicit client action to invoke the capability.
   Client and server implementations MUST implement the STARTTLS
   (Section 6.2.1) and LOGINDISABLED capabilities on cleartext ports.
   Client and server implementations MUST also implement AUTH=PLAIN
   (described in [PLAIN]) capability on both cleartext and Implicit TLS
   ports.  See the Security Considerations (Section 11) for important
   information.
   Unless otherwise specified, all registered extensions to IMAP4rev1
   are also valid extensions to IMAP4rev2.
   Example:
     C: abcd CAPABILITY
     S: * CAPABILITY IMAP4rev2 STARTTLS AUTH=GSSAPI
      LOGINDISABLED
     S: abcd OK CAPABILITY completed
     C: efgh STARTTLS
     S: efgh OK STARTTLS completed
     <TLS negotiation, further commands are under TLS layer>
     C: ijkl CAPABILITY
     S: * CAPABILITY IMAP4rev2 AUTH=GSSAPI AUTH=PLAIN
     S: ijkl OK CAPABILITY completed
6.1.2.  NOOP Command
   Arguments:    none
   Responses:    no specific responses for this command (but see below)
   Result:       OK -  noop completed
                 BAD -  command unknown or arguments invalid
   The NOOP command always succeeds.  It does nothing.
   Since any command can return a status update as untagged data, the
   NOOP command can be used as a periodic poll for new messages or
   message status updates during a period of inactivity (the IDLE
   command; see Section 6.3.13) should be used instead of NOOP if real-
   time updates to mailbox state are desirable).  The NOOP command can
   also be used to reset any inactivity autologout timer on the server.
   Example:
     C: a002 NOOP
     S: a002 OK NOOP completed
        . . .
     C: a047 NOOP
     S: * 22 EXPUNGE
     S: * 23 EXISTS
     S: * 14 FETCH (UID 1305 FLAGS (\Seen \Deleted))
     S: a047 OK NOOP completed
6.1.3.  LOGOUT Command
   Arguments:    none
   Responses:    REQUIRED untagged response:  BYE
   Result:       OK -  logout completed
                 BAD -  command unknown or arguments invalid
   The LOGOUT command informs the server that the client is done with
   the connection.  The server MUST send a BYE untagged response before
   the (tagged) OK response, and then close the network connection.
   Example:
     C: A023 LOGOUT
     S: * BYE IMAP4rev2 Server logging out
     S: A023 OK LOGOUT completed
     (Server and client then close the connection)
6.2.  Client Commands - Not Authenticated State
   In the not authenticated state, the AUTHENTICATE or LOGIN command
   establishes authentication and enters the authenticated state.  The
   AUTHENTICATE command provides a general mechanism for a variety of
   authentication techniques, privacy protection, and integrity
   checking, whereas the LOGIN command uses a conventional user name and
   plaintext password pair and has no means of establishing privacy
   protection or integrity checking.
   The STARTTLS command is an alternative form of establishing session
   privacy protection and integrity checking but does not by itself
   establish authentication or enter the authenticated state.
   Server implementations MAY allow access to certain mailboxes without
   establishing authentication.  This can be done by means of the
   ANONYMOUS [SASL] authenticator described in [ANONYMOUS].  An older
   convention is a LOGIN command using the userid "anonymous"; in this
   case, a password is required although the server may choose to accept
   any password.  The restrictions placed on anonymous users are
   implementation dependent.
   Once authenticated (including as anonymous), it is not possible to
   re-enter not authenticated state.
   In addition to the universal commands (CAPABILITY, NOOP, and LOGOUT),
   the following commands are valid in the not authenticated state:
   STARTTLS, AUTHENTICATE, and LOGIN.  See the Security Considerations
   (Section 11) for important information about these commands.
6.2.1.  STARTTLS Command
   Arguments:    none
   Responses:    no specific response for this command
   Result:       OK -  starttls completed, begin TLS negotiation
                 NO -  TLS negotiation can't be initiated, due to server
                    configuration error
                 BAD -  STARTTLS received after a successful TLS
                    negotiation or arguments invalid
   Note that the STARTTLS command is available only on cleartext ports.
   The server MUST always respond with a tagged BAD response when the
   STARTTLS command is received on an Implicit TLS port.
   A TLS [TLS-1.3] negotiation begins immediately after the CRLF at the
   end of the tagged OK response from the server.  Once a client issues
   a STARTTLS command, it MUST NOT issue further commands until a server
   response is seen and the TLS negotiation is complete.  Some past
   server implementations incorrectly implemented STARTTLS processing
   and are known to contain STARTTLS plaintext command injection
   vulnerability [CERT-555316].  In order to avoid this vulnerability,
   server implementations MUST do one of the following if any data is
   received in the same TCP buffer after the CRLF that starts the
   STARTTLS command:
   1.  Extra data from the TCP buffer is interpreted as the beginning of
       the TLS handshake.  (If the data is in cleartext, this will
       result in the TLS handshake failing.)
   2.  Extra data from the TCP buffer is thrown away.
   Note that the first option is friendlier to clients that pipeline the
   beginning of the STARTTLS command with TLS handshake data.
   After successful TLS negotiation, the server remains in the non-
   authenticated state, even if client credentials are supplied during
   the TLS negotiation.  This does not preclude an authentication
   mechanism such as EXTERNAL (defined in [SASL]) from using client
   identity determined by the TLS negotiation.
   Once TLS has been started, the client MUST discard cached information
   about server capabilities and SHOULD reissue the CAPABILITY command.
   This is necessary to protect against active attacks that alter the
   capabilities list prior to STARTTLS.  The server MAY advertise
   different capabilities and, in particular, SHOULD NOT advertise the
   STARTTLS capability, after a successful STARTTLS command.
   Example:
      C: a001 CAPABILITY
      S: * CAPABILITY IMAP4rev2 STARTTLS LOGINDISABLED
      S: a001 OK CAPABILITY completed
      C: a002 STARTTLS
      S: a002 OK Begin TLS negotiation now
      <TLS negotiation, further commands are under TLS layer>
      C: a003 CAPABILITY
      S: * CAPABILITY IMAP4rev2 AUTH=PLAIN
      S: a003 OK CAPABILITY completed
      C: a004 AUTHENTICATE PLAIN dGVzdAB0ZXN0AHRlc3Q=
      S: a004 OK Success (tls protection)
6.2.2.  AUTHENTICATE Command
   Arguments:    SASL authentication mechanism name
                 OPTIONAL initial response
   Responses:    continuation data can be requested
   Result:       OK -  authenticate completed, now in authenticated
                    state
                 NO -  authenticate failure: unsupported authentication
                    mechanism, credentials rejected
                 BAD -  command unknown or arguments invalid,
                    authentication exchange canceled
   The AUTHENTICATE command indicates a [SASL] authentication mechanism
   to the server.  If the server supports the requested authentication
   mechanism, it performs an authentication protocol exchange to
   authenticate and identify the client.  It MAY also negotiate an
   OPTIONAL security layer for subsequent protocol interactions.  If the
   requested authentication mechanism is not supported, the server
   SHOULD reject the AUTHENTICATE command by sending a tagged NO
   response.
   The AUTHENTICATE command supports the optional "initial response"
   feature defined in Section 4 of [SASL].  The client doesn't need to
   use it.  If a SASL mechanism supports "initial response", but it is
   not specified by the client, the server handles it as specified in
   Section 3 of [SASL].
   The service name specified by this protocol's profile of [SASL] is
   "imap".
   The authentication protocol exchange consists of a series of server
   challenges and client responses that are specific to the
   authentication mechanism.  A server challenge consists of a command
   continuation request response with the "+" token followed by a
   base64-encoded (see Section 4 of [RFC4648]) string.  The client
   response consists of a single line consisting of a base64-encoded
   string.  If the client wishes to cancel an authentication exchange,
   it issues a line consisting of a single "*".  If the server receives
   such a response, or if it receives an invalid base64 string (e.g.,
   characters outside the base64 alphabet or non-terminal "="), it MUST
   reject the AUTHENTICATE command by sending a tagged BAD response.
   As with any other client response, the initial response MUST be
   encoded as base64.  It also MUST be transmitted outside of a quoted
   string or literal.  To send a zero-length initial response, the
   client MUST send a single pad character ("=").  This indicates that
   the response is present, but it is a zero-length string.
   When decoding the base64 data in the initial response, decoding
   errors MUST be treated as in any normal SASL client response, i.e.,
   with a tagged BAD response.  In particular, the server should check
   for any characters not explicitly allowed by the base64 alphabet, as
   well as any sequence of base64 characters that contains the pad
   character ('=') anywhere other than the end of the string (e.g.,
   "=AAA" and "AAA=BBB" are not allowed).
   If the client uses an initial response with a SASL mechanism that
   does not support an initial response, the server MUST reject the
   command with a tagged BAD response.
   If a security layer is negotiated through the [SASL] authentication
   exchange, it takes effect immediately following the CRLF that
   concludes the authentication exchange for the client and the CRLF of
   the tagged OK response for the server.
   While client and server implementations MUST implement the
   AUTHENTICATE command itself, it is not required to implement any
   authentication mechanisms other than the PLAIN mechanism described in
   [PLAIN].  Also, an authentication mechanism is not required to
   support any security layers.
      Note: a server implementation MUST implement a configuration in
      which it does NOT permit any plaintext password mechanisms, unless
      the STARTTLS command has been negotiated, TLS has been negotiated
      on an Implicit TLS port, or some other mechanism that protects the
      session from password snooping has been provided.  Server sites
      SHOULD NOT use any configuration that permits a plaintext password
      mechanism without such a protection mechanism against password
      snooping.  Client and server implementations SHOULD implement
      additional [SASL] mechanisms that do not use plaintext passwords,
      such as the GSSAPI mechanism described in [RFC4752], the SCRAM-
      SHA-256/SCRAM-SHA-256-PLUS [SCRAM-SHA-256] mechanisms, and/or the
      EXTERNAL [SASL] mechanism for mutual TLS authentication.  (Note
      that the SASL framework allows for the creation of SASL mechanisms
      that support 2-factor authentication (2FA); however, none are
      fully ready to be recommended by this document.)
   Servers and clients can support multiple authentication mechanisms.
   The server SHOULD list its supported authentication mechanisms in the
   response to the CAPABILITY command so that the client knows which
   authentication mechanisms to use.
   A server MAY include a CAPABILITY response code in the tagged OK
   response of a successful AUTHENTICATE command in order to send
   capabilities automatically.  It is unnecessary for a client to send a
   separate CAPABILITY command if it recognizes these automatic
   capabilities.  This should only be done if a security layer was not
   negotiated by the AUTHENTICATE command, because the tagged OK
   response as part of an AUTHENTICATE command is not protected by
   encryption/integrity checking.  [SASL] requires the client to re-
   issue a CAPABILITY command in this case.  The server MAY advertise
   different capabilities after a successful AUTHENTICATE command.
   If an AUTHENTICATE command fails with a NO response, the client MAY
   try another authentication mechanism by issuing another AUTHENTICATE
   command.  It MAY also attempt to authenticate by using the LOGIN
   command (see Section 6.2.3 for more detail).  In other words, the
   client MAY request authentication types in decreasing order of
   preference, with the LOGIN command as a last resort.
   The authorization identity passed from the client to the server
   during the authentication exchange is interpreted by the server as
   the user name whose privileges the client is requesting.
   Example:
     S: * OK [CAPABILITY IMAP4rev2 STARTTLS AUTH=GSSAPI]
      Capabilities
     C: A001 AUTHENTICATE GSSAPI
     S: +
     C: YIIB+wYJKoZIhvcSAQICAQBuggHqMIIB5qADAgEFoQMCAQ6iBw
        MFACAAAACjggEmYYIBIjCCAR6gAwIBBaESGxB1Lndhc2hpbmd0
        b24uZWR1oi0wK6ADAgEDoSQwIhsEaW1hcBsac2hpdmFtcy5jYW
        Mud2FzaGluZ3Rvbi5lZHWjgdMwgdCgAwIBAaEDAgEDooHDBIHA
        cS1GSa5b+fXnPZNmXB9SjL8Ollj2SKyb+3S0iXMljen/jNkpJX
        AleKTz6BQPzj8duz8EtoOuNfKgweViyn/9B9bccy1uuAE2HI0y
        C/PHXNNU9ZrBziJ8Lm0tTNc98kUpjXnHZhsMcz5Mx2GR6dGknb
        I0iaGcRerMUsWOuBmKKKRmVMMdR9T3EZdpqsBd7jZCNMWotjhi
        vd5zovQlFqQ2Wjc2+y46vKP/iXxWIuQJuDiisyXF0Y8+5GTpAL
        pHDc1/pIGmMIGjoAMCAQGigZsEgZg2on5mSuxoDHEA1w9bcW9n
        FdFxDKpdrQhVGVRDIzcCMCTzvUboqb5KjY1NJKJsfjRQiBYBdE
        NKfzK+g5DlV8nrw81uOcP8NOQCLR5XkoMHC0Dr/80ziQzbNqhx
        O6652Npft0LQwJvenwDI13YxpwOdMXzkWZN/XrEqOWp6GCgXTB
        vCyLWLlWnbaUkZdEYbKHBPjd8t/1x5Yg==
     S: + YGgGCSqGSIb3EgECAgIAb1kwV6ADAgEFoQMCAQ+iSzBJoAMC
        AQGiQgRAtHTEuOP2BXb9sBYFR4SJlDZxmg39IxmRBOhXRKdDA0
        uHTCOT9Bq3OsUTXUlk0CsFLoa8j+gvGDlgHuqzWHPSQg==
     C:
     S: + YDMGCSqGSIb3EgECAgIBAAD/////6jcyG4GE3KkTzBeBiVHe
        ceP2CWY0SR0fAQAgAAQEBAQ=
     C: YDMGCSqGSIb3EgECAgIBAAD/////3LQBHXTpFfZgrejpLlLImP
        wkhbfa2QteAQAgAG1yYwE=
     S: A001 OK GSSAPI authentication successful
   The following example demonstrates the use of an initial response.
   Example:
     S: * OK [CAPABILITY IMAP4rev2 STARTTLS AUTH=GSSAPI
      LOGINDISABLED] Server ready
     C: A01 STARTTLS
     S: A01 OK STARTTLS completed
     <TLS negotiation, further commands are under TLS layer>
     C: A02 CAPABILITY
     S: * CAPABILITY IMAP4rev2 AUTH=GSSAPI AUTH=PLAIN
     S: A02 OK CAPABILITY completed
     C: A03 AUTHENTICATE PLAIN dGVzdAB0ZXN0AHRlc3Q=
     S: A03 OK Success (tls protection)
   Note that because the initial response is optional, the following
   negotiation (which does not use the initial response) is still valid
   and MUST be supported by the server:
     ... client connects to server and negotiates a TLS
         protection layer ...
     C: C01 CAPABILITY
     S: * CAPABILITY IMAP4rev2 AUTH=PLAIN
     S: C01 OK Completed
     C: A01 AUTHENTICATE PLAIN
     S: +
     C: dGVzdAB0ZXN0AHRlc3Q=
     S: A01 OK Success (tls protection)
   Note that in the above example there is a space following the "+"
   from the server.
   The following is an example authentication using the SASL EXTERNAL
   mechanism (defined in [SASL]) under a TLS protection layer and an
   empty initial response:
     ... client connects to server and negotiates a TLS
         protection layer ...
     C: C01 CAPABILITY
     S: * CAPABILITY IMAP4rev2 AUTH=PLAIN AUTH=EXTERNAL
     S: C01 OK Completed
     C: A01 AUTHENTICATE EXTERNAL =
     S: A01 OK Success (tls protection)
   Note: The line breaks within server challenges and client responses
   are for editorial clarity and are not in real authenticators.
6.2.3.  LOGIN Command
   Arguments:    user name
                 password
   Responses:    no specific responses for this command
   Result:       OK -  login completed, now in authenticated state
                 NO -  login failure: user name or password rejected
                 BAD -  command unknown or arguments invalid
   The LOGIN command identifies the client to the server and carries the
   plaintext password authenticating this user.  The LOGIN command
   SHOULD NOT be used except as a last resort (after attempting and
   failing to authenticate using the AUTHENTICATE command one or more
   times), and it is recommended that client implementations have a
   means to disable any automatic use of the LOGIN command.
   A server MAY include a CAPABILITY response code in the tagged OK
   response to a successful LOGIN command in order to send capabilities
   automatically.  It is unnecessary for a client to send a separate
   CAPABILITY command if it recognizes these automatic capabilities.
   Example:
     C: a001 LOGIN SMITH SESAME
     S: a001 OK LOGIN completed
   Note: Use of the LOGIN command over an insecure network (such as the
   Internet) is a security risk, because anyone monitoring network
   traffic can obtain plaintext passwords.  For that reason, clients
   MUST NOT use LOGIN on unsecure networks.
   Unless the client is accessing IMAP service on an Implicit TLS port
   [RFC8314], the STARTTLS command has been negotiated, or some other
   mechanism that protects the session from password snooping has been
   provided, a server implementation MUST implement a configuration in
   which it advertises the LOGINDISABLED capability and does NOT permit
   the LOGIN command.  Server sites SHOULD NOT use any configuration
   that permits the LOGIN command without such a protection mechanism
   against password snooping.  A client implementation MUST NOT send a
   LOGIN command if the LOGINDISABLED capability is advertised.
6.3.  Client Commands - Authenticated State
   In the authenticated state, commands that manipulate mailboxes as
   atomic entities are permitted.  Of these commands, SELECT and EXAMINE
   will select a mailbox for access and enter the selected state.
   In addition to the universal commands (CAPABILITY, NOOP, and LOGOUT),
   the following commands are valid in the authenticated state: ENABLE,
   SELECT, EXAMINE, NAMESPACE, CREATE, DELETE, RENAME, SUBSCRIBE,
   UNSUBSCRIBE, LIST, STATUS, APPEND, and IDLE.
6.3.1.  ENABLE Command
   Arguments:    capability names
   Responses:    no specific responses for this command
   Result:       OK -  Relevant capabilities enabled
                 BAD -  No arguments, or syntax error in an argument
   Several IMAP extensions allow the server to return unsolicited
   responses specific to these extensions in certain circumstances.
   However, servers cannot send those unsolicited responses (with the
   exception of response codes (see Section 7.1) included in tagged or
   untagged OK/NO/BAD responses, which can always be sent) until they
   know that the clients support such extensions and thus will be able
   to correctly parse and process the extension response data.
   The ENABLE command provides an explicit indication from the client
   that it supports particular extensions.  It is designed such that the
   client can send a simple constant string with the extensions it
   supports, and the server will enable the shared subset that both
   support.
   The ENABLE command takes a list of capability names and requests the
   server to enable the named extensions.  Once enabled using ENABLE,
   each extension remains active until the IMAP connection is closed.
   For each argument, the server does the following:
   *  If the argument is not an extension known to the server, the
      server MUST ignore the argument.
   *  If the argument is an extension known to the server, and it is not
      specifically permitted to be enabled using ENABLE, the server MUST
      ignore the argument.  (Note that knowing about an extension
      doesn't necessarily imply supporting that extension.)
   *  If the argument is an extension that is supported by the server
      and that needs to be enabled, the server MUST enable the extension
      for the duration of the connection.  Note that once an extension
      is enabled, there is no way to disable it.
   If the ENABLE command is successful, the server MUST send an untagged
   ENABLED response (Section 7.2.1), which includes all enabled
   extensions as specified above.  The ENABLED response is sent even if
   no extensions were enabled.
   Clients SHOULD only include extensions that need to be enabled by the
   server.  For example, a client can enable IMAP4rev2-specific behavior
   when both IMAP4rev1 and IMAP4rev2 are advertised in the CAPABILITY
   response.  Future RFCs may add to this list.
   The ENABLE command is only valid in the authenticated state, before
   any mailbox is selected.  Clients MUST NOT issue ENABLE once they
   SELECT/EXAMINE a mailbox; however, server implementations don't have
   to check that no mailbox is selected or was previously selected
   during the duration of a connection.
   The ENABLE command can be issued multiple times in a session.  It is
   additive; that is, "ENABLE a b", followed by "ENABLE c", is the same
   as a single command "ENABLE a b c".  When multiple ENABLE commands
   are issued, each corresponding ENABLED response SHOULD only contain
   extensions enabled by the corresponding ENABLE command, i.e., for the
   above example, the ENABLED response to "ENABLE c" should not contain
   "a" or "b".
   There are no limitations on pipelining ENABLE.  For example, it is
   possible to send ENABLE and then immediately SELECT, or a LOGIN
   immediately followed by ENABLE.
   The server MUST NOT change the CAPABILITY list as a result of
   executing ENABLE; that is, a CAPABILITY command issued right after an
   ENABLE command MUST list the same capabilities as a CAPABILITY
   command issued before the ENABLE command.  This is demonstrated in
   the following example.  Note that below "X-GOOD-IDEA" is a fictitious
   extension capability that can be ENABLED.
     C: t1 CAPABILITY
     S: * CAPABILITY IMAP4rev2 ID LITERAL+ X-GOOD-IDEA
     S: t1 OK foo
     C: t2 ENABLE CONDSTORE X-GOOD-IDEA
     S: * ENABLED X-GOOD-IDEA
     S: t2 OK foo
     C: t3 CAPABILITY
     S: * CAPABILITY IMAP4rev2 ID LITERAL+ X-GOOD-IDEA
     S: t3 OK foo again
   In the following example, the client enables the Conditional Store
   (CONDSTORE) extension [RFC7162]:
     C: a1 ENABLE CONDSTORE
     S: * ENABLED CONDSTORE
     S: a1 OK Conditional Store enabled
6.3.1.1.  Note to Designers of Extensions That May Use the ENABLE
          Command
   Designers of IMAP extensions are discouraged from creating extensions
   that require ENABLE unless there is no good alternative design.
   Specifically, extensions that cause potentially incompatible behavior
   changes to deployed server responses (and thus benefit from ENABLE)
   have a higher complexity cost than extensions that do not.
6.3.2.  SELECT Command
   Arguments:    mailbox name
   Responses:    REQUIRED untagged responses:  FLAGS, EXISTS, LIST
                 REQUIRED OK untagged responses:  PERMANENTFLAGS,
                    UIDNEXT, UIDVALIDITY
   Result:       OK -  select completed, now in selected state
                 NO -  select failure, now in authenticated state: no
                    such mailbox, can't access mailbox
                 BAD -  command unknown or arguments invalid
   The SELECT command selects a mailbox so that messages in the mailbox
   can be accessed.  Before returning an OK to the client, the server
   MUST send the following untagged data to the client.  (The order of
   individual responses is not important.)  Note that earlier versions
   of this protocol, such as the IMAP4rev1 version specified in
   [RFC2060], only required the FLAGS and EXISTS untagged responses and
   UIDVALIDITY response code.  Client implementations that need to
   remain compatible with such older IMAP versions have to implement
   default behavior for missing data, as discussed with the individual
   items.
   FLAGS
      Defined flags in the mailbox.  See the description of the FLAGS
      response in Section 7.3.5 for more detail.
   <n> EXISTS
      The number of messages in the mailbox.  See the description of the
      EXISTS response in Section 7.4.1 for more detail.
   LIST
      The server MUST return a LIST response with the mailbox name.  The
      list of mailbox attributes MUST be accurate.  If the server allows
      denormalized UTF-8 mailbox names (see Section 5.1) and the
      supplied mailbox name differs from the normalized version, the
      server MUST return LIST with the OLDNAME extended data item.  See
      Section 6.3.9.7 for more details.
   OK [PERMANENTFLAGS (<list of flags>)]
      A list of message flags that the client can change permanently.
      If this is missing, the client should assume that all flags can be
      changed permanently.
   OK [UIDNEXT <n>]
      The next unique identifier value.  Refer to Section 2.3.1.1 for
      more information.
   OK [UIDVALIDITY <n>]
      The unique identifier validity value.  Refer to Section 2.3.1.1
      for more information.
   Only one mailbox can be selected at a time in a connection;
   simultaneous access to multiple mailboxes requires multiple
   connections.  The SELECT command automatically deselects any
   currently selected mailbox before attempting the new selection.
   Consequently, if a mailbox is selected and a SELECT command that
   fails is attempted, no mailbox is selected.  When deselecting a
   selected mailbox, the server MUST return an untagged OK response with
   the "[CLOSED]" response code when the currently selected mailbox is
   closed (see Section 7.1).
   If the client is permitted to modify the mailbox, the server SHOULD
   prefix the text of the tagged OK response with the "[READ-WRITE]"
   response code.
   If the client is not permitted to modify the mailbox but is permitted
   read access, the mailbox is selected as read-only, and the server
   MUST prefix the text of the tagged OK response to SELECT with the
   "[READ-ONLY]" response code.  Read-only access through SELECT differs
   from the EXAMINE command in that certain read-only mailboxes MAY
   permit the change of permanent state on a per-user (as opposed to
   global) basis.  Netnews messages marked in a server-based .newsrc
   file are an example of such per-user permanent state that can be
   modified with read-only mailboxes.
   Example:
     C: A142 SELECT INBOX
     S: * 172 EXISTS
     S: * OK [UIDVALIDITY 3857529045] UIDs valid
     S: * OK [UIDNEXT 4392] Predicted next UID
     S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
     S: * OK [PERMANENTFLAGS (\Deleted \Seen \*)] Limited
     S: * LIST () "/" INBOX
     S: A142 OK [READ-WRITE] SELECT completed
   Example:
     C: A142 SELECT INBOX
     S: * 172 EXISTS
     S: * OK [UIDVALIDITY 3857529045] UIDs valid
     S: * OK [UIDNEXT 4392] Predicted next UID
     S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
     S: * OK [PERMANENTFLAGS (\Deleted \Seen \*)] Limited
     S: A142 OK [READ-WRITE] SELECT completed
     [...some time later...]
     C: A143 SELECT Drafts
     S: * OK [CLOSED] Previous mailbox is now closed
     S: * 5 EXISTS
     S: * OK [UIDVALIDITY 9877410381] UIDs valid
     S: * OK [UIDNEXT 102] Predicted next UID
     S: * LIST () "/" Drafts
     S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
     S: * OK [PERMANENTFLAGS (\Deleted \Seen \Answered
         \Flagged \Draft \*)] System flags and keywords allowed
     S: A143 OK [READ-WRITE] SELECT completed
   Note that IMAP4rev1-compliant servers can also send the untagged
   RECENT response that was deprecated in IMAP4rev2, e.g., "* 0 RECENT".
   Pure IMAP4rev2 clients are advised to ignore the untagged RECENT
   response.
6.3.3.  EXAMINE Command
   Arguments:    mailbox name
   Responses:    REQUIRED untagged responses:  FLAGS, EXISTS, LIST
                 REQUIRED OK untagged responses:  PERMANENTFLAGS,
                    UIDNEXT, UIDVALIDITY
   Result:       OK -  examine completed, now in selected state
                 NO -  examine failure, now in authenticated state: no
                    such mailbox, can't access mailbox
                 BAD -  command unknown or arguments invalid
   The EXAMINE command is identical to SELECT and returns the same
   output; however, the selected mailbox is identified as read-only.  No
   changes to the permanent state of the mailbox, including per-user
   state, are permitted.
   The text of the tagged OK response to the EXAMINE command MUST begin
   with the "[READ-ONLY]" response code.
   Example:
      C: A932 EXAMINE blurdybloop
      S: * 17 EXISTS
      S: * OK [UIDVALIDITY 3857529045] UIDs valid
      S: * OK [UIDNEXT 4392] Predicted next UID
      S: * LIST () "/" blurdybloop
      S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
      S: * OK [PERMANENTFLAGS ()] No permanent flags permitted
      S: A932 OK [READ-ONLY] EXAMINE completed
6.3.4.  CREATE Command
   Arguments:    mailbox name
   Responses:    OPTIONAL untagged response:  LIST
   Result:       OK -  create completed
                 NO -  create failure: can't create mailbox with that
                    name
                 BAD -  command unknown or arguments invalid
   The CREATE command creates a mailbox with the given name.  An OK
   response is returned only if a new mailbox with that name has been
   created.  It is an error to attempt to create INBOX or a mailbox with
   a name that refers to an extant mailbox.  Any error in creation will
   return a tagged NO response.  If a client attempts to create a UTF-8
   mailbox name that is not a valid Net-Unicode name, the server MUST
   reject the creation or convert the name to Net-Unicode prior to
   creating the mailbox.  If the server decides to convert (normalize)
   the name, it SHOULD return an untagged LIST with an OLDNAME extended
   data item, with the OLDNAME value being the supplied mailbox name and
   the name parameter being the normalized mailbox name.  (See
   Section 6.3.9.7 for more details.)
   Mailboxes created in one IMAP session MAY be announced to other IMAP
   sessions using an unsolicited LIST response.  If the server
   automatically subscribes a mailbox when it is created, then the
   unsolicited LIST response for each affected subscribed mailbox name
   MUST include the \Subscribed attribute.
   If the mailbox name is suffixed with the server's hierarchy separator
   character (as returned from the server by a LIST command), this is a
   declaration that the client intends to create mailbox names under
   this name in the hierarchy.  Server implementations that do not
   require this declaration MUST ignore the declaration.  In any case,
   the name created is without the trailing hierarchy delimiter.
   If the server's hierarchy separator character appears elsewhere in
   the name, the server SHOULD create any superior hierarchical names
   that are needed for the CREATE command to be successfully completed.
   In other words, an attempt to create "foo/bar/zap" on a server in
   which "/" is the hierarchy separator character SHOULD create foo/ and
   foo/bar/ if they do not already exist.
   If a new mailbox is created with the same name as a mailbox that was
   deleted, its unique identifiers MUST be greater than any unique
   identifiers used in the previous incarnation of the mailbox unless
   the new incarnation has a different unique identifier validity value.
   See the description of the UID command in Section 6.4.9 for more
   detail.
   Example:
     C: A003 CREATE owatagusiam/
     S: A003 OK CREATE completed
     C: A004 CREATE owatagusiam/blurdybloop
     S: A004 OK CREATE completed
     C: A005 CREATE NonNormalized
     S: * LIST () "/" "Normalized" ("OLDNAME" ("NonNormalized"))
     S: A005 OK CREATE completed
   (In the last example, imagine that "NonNormalized" is a non-NFC
   normalized Unicode mailbox name and that "Normalized" is its NFC
   normalized version.)
      |  Note: The interpretation of this example depends on whether "/"
      |  was returned as the hierarchy separator from LIST.  If "/" is
      |  the hierarchy separator, a new level of hierarchy named
      |  "owatagusiam" with a member called "blurdybloop" is created.
      |  Otherwise, two mailboxes at the same hierarchy level are
      |  created.
6.3.5.  DELETE Command
   Arguments:    mailbox name
   Responses:    OPTIONAL untagged response:  LIST
   Result:       OK -  delete completed
                 NO -  delete failure: can't delete mailbox with that
                    name
                 BAD -  command unknown or arguments invalid
   The DELETE command permanently removes the mailbox with the given
   name.  A tagged OK response is returned only if the mailbox has been
   deleted.  It is an error to attempt to delete INBOX or a mailbox name
   that does not exist.
   The DELETE command MUST NOT remove inferior hierarchical names.  For
   example, if a mailbox "foo" has an inferior "foo.bar" (assuming "."
   is the hierarchy delimiter character), removing "foo" MUST NOT remove
   "foo.bar".  It is an error to attempt to delete a name that has
   inferior hierarchical names and also has the \Noselect mailbox name
   attribute (see the description of the LIST response (Section 7.3.1)
   for more details).
   It is permitted to delete a name that has inferior hierarchical names
   and does not have the \Noselect mailbox name attribute.  If the
   server implementation does not permit deleting the name while
   inferior hierarchical names exist, then it SHOULD disallow the DELETE
   command by returning a tagged NO response.  The NO response SHOULD
   include the HASCHILDREN response code.  Alternatively, the server MAY
   allow the DELETE command, but it sets the \Noselect mailbox name
   attribute for that name.
   If the server returns an OK response, all messages in that mailbox
   are removed by the DELETE command.
   The value of the highest-used unique identifier of the deleted
   mailbox MUST be preserved so that a new mailbox created with the same
   name will not reuse the identifiers of the former incarnation, unless
   the new incarnation has a different unique identifier validity value.
   See the description of the UID command in Section 6.4.9 for more
   detail.
   If the server decides to convert (normalize) the mailbox name, it
   SHOULD return an untagged LIST with the "\NonExistent" attribute and
   OLDNAME extended data item, with the OLDNAME value being the supplied
   mailbox name and the name parameter being the normalized mailbox
   name.  (See Section 6.3.9.7 for more details.)
   Mailboxes deleted in one IMAP session MAY be announced to other IMAP
   sessions using an unsolicited LIST response, containing the
   "\NonExistent" attribute.
   Example:
     C: A682 LIST "" *
     S: * LIST () "/" blurdybloop
     S: * LIST (\Noselect) "/" foo
     S: * LIST () "/" foo/bar
     S: A682 OK LIST completed
     C: A683 DELETE blurdybloop
     S: A683 OK DELETE completed
     C: A684 DELETE foo
     S: A684 NO Name "foo" has inferior hierarchical names
     C: A685 DELETE foo/bar
     S: A685 OK DELETE Completed
     C: A686 LIST "" *
     S: * LIST (\Noselect) "/" foo
     S: A686 OK LIST completed
     C: A687 DELETE foo
     S: A687 OK DELETE Completed
   Example:
     C: A82 LIST "" *
     S: * LIST () "." blurdybloop
     S: * LIST () "." foo
     S: * LIST () "." foo.bar
     S: A82 OK LIST completed
     C: A83 DELETE blurdybloop
     S: A83 OK DELETE completed
     C: A84 DELETE foo
     S: A84 OK DELETE Completed
     C: A85 LIST "" *
     S: * LIST () "." foo.bar
     S: A85 OK LIST completed
     C: A86 LIST "" %
     S: * LIST (\Noselect) "." foo
     S: A86 OK LIST completed
6.3.6.  RENAME Command
   Arguments:    existing mailbox name
                 new mailbox name
   Responses:    OPTIONAL untagged response:  LIST
   Result:       OK -  rename completed
                 NO -  rename failure: can't rename mailbox with that
                    name, can't rename to mailbox with that name
                 BAD -  command unknown or arguments invalid
   The RENAME command changes the name of a mailbox.  A tagged OK
   response is returned only if the mailbox has been renamed.  It is an
   error to attempt to rename from a mailbox name that does not exist or
   to a mailbox name that already exists.  Any error in renaming will
   return a tagged NO response.
   If the name has inferior hierarchical names, then the inferior
   hierarchical names MUST also be renamed.  For example, a rename of
   "foo" to "zap" will rename "foo/bar" (assuming "/" is the hierarchy
   delimiter character) to "zap/bar".
   If the server's hierarchy separator character appears in the new
   mailbox name, the server SHOULD create any superior hierarchical
   names that are needed for the RENAME command to complete
   successfully.  In other words, an attempt to rename "foo/bar/zap" to
   "baz/rag/zowie" on a server in which "/" is the hierarchy separator
   character in the corresponding namespace SHOULD create "baz/" and
   "baz/rag/" if they do not already exist.
   The value of the highest-used unique identifier of the old mailbox
   name MUST be preserved so that a new mailbox created with the same
   name will not reuse the identifiers of the former incarnation, unless
   the new incarnation has a different unique identifier validity value.
   See the description of the UID command in Section 6.4.9 for more
   detail.
   Renaming INBOX is permitted and does not result in a tagged BAD
   response, and it has special behavior: It moves all messages in INBOX
   to a new mailbox with the given name, leaving INBOX empty.  If the
   server implementation supports inferior hierarchical names of INBOX,
   these are unaffected by a rename of INBOX.  (Note that some servers
   disallow renaming INBOX by returning a tagged NO response, so clients
   need to be able to handle the failure of such RENAME commands.)
   If the server allows creation of mailboxes with names that are not
   valid Net-Unicode names, the server normalizes both the existing
   mailbox name parameter and the new mailbox name parameter.  If the
   normalized version of any of these 2 parameters differs from the
   corresponding supplied version, the server SHOULD return an untagged
   LIST response with an OLDNAME extended data item, with the OLDNAME
   value being the supplied existing mailbox name and the name parameter
   being the normalized new mailbox name (see Section 6.3.9.7).  This
   would allow the client to correlate the supplied name with the
   normalized name.
   Mailboxes renamed in one IMAP session MAY be announced to other IMAP
   sessions using an unsolicited LIST response with an OLDNAME extended
   data item.
   In both of the above cases, if the server automatically subscribes a
   mailbox when it is renamed, then the unsolicited LIST response for
   each affected subscribed mailbox name MUST include the \Subscribed
   attribute.  No unsolicited LIST responses need to be sent for child
   mailboxes.  When INBOX is successfully renamed, it is assumed that a
   new INBOX is created.  No unsolicited LIST responses need to be sent
   for INBOX in this case.
   Examples:
     C: A682 LIST "" *
     S: * LIST () "/" blurdybloop
     S: * LIST (\Noselect) "/" foo
     S: * LIST () "/" foo/bar
     S: A682 OK LIST completed
     C: A683 RENAME blurdybloop sarasoop
     S: A683 OK RENAME completed
     C: A684 RENAME foo zowie
     S: A684 OK RENAME Completed
     C: A685 LIST "" *
     S: * LIST () "/" sarasoop
     S: * LIST (\Noselect) "/" zowie
     S: * LIST () "/" zowie/bar
     S: A685 OK LIST completed
     C: Z432 LIST "" *
     S: * LIST () "." INBOX
     S: * LIST () "." INBOX.bar
     S: Z432 OK LIST completed
     C: Z433 RENAME INBOX old-mail
     S: Z433 OK RENAME completed
     C: Z434 LIST "" *
     S: * LIST () "." INBOX
     S: * LIST () "." INBOX.bar
     S: * LIST () "." old-mail
     S: Z434 OK LIST completed
   Note that renaming a mailbox doesn't update subscription information
   on the original name.  To keep subscription information in sync, the
   following sequence of commands can be used:
     C: 1001 RENAME X Y
     C: 1002 SUBSCRIBE Y
     C: 1003 UNSUBSCRIBE X
   Note that the above sequence of commands doesn't account for updating
   the subscription for any child mailboxes of mailbox X.
6.3.7.  SUBSCRIBE Command
   Arguments:    mailbox
   Responses:    no specific responses for this command
   Result:       OK -  subscribe completed
                 NO -  subscribe failure: can't subscribe to that name
                 BAD -  command unknown or arguments invalid
   The SUBSCRIBE command adds the specified mailbox name to the server's
   set of "active" or "subscribed" mailboxes as returned by the LIST
   (SUBSCRIBED) command.  This command returns a tagged OK response if
   the subscription is successful or if the mailbox is already
   subscribed.
   A server MAY validate the mailbox argument to SUBSCRIBE to verify
   that it exists.  However, it SHOULD NOT unilaterally remove an
   existing mailbox name from the subscription list even if a mailbox by
   that name no longer exists.
      |  Note: This requirement is because a server site can choose to
      |  routinely remove a mailbox with a well-known name (e.g.,
      |  "system-alerts") after its contents expire, with the intention
      |  of recreating it when new contents are appropriate.
   Example:
     C: A002 SUBSCRIBE #news.comp.mail.mime
     S: A002 OK SUBSCRIBE completed
6.3.8.  UNSUBSCRIBE Command
   Arguments:    mailbox name
   Responses:    no specific responses for this command
   Result:       OK -  unsubscribe completed
                 NO -  unsubscribe failure: can't unsubscribe that name
                 BAD -  command unknown or arguments invalid
   The UNSUBSCRIBE command removes the specified mailbox name from the
   server's set of "active" or "subscribed" mailboxes as returned by the
   LIST (SUBSCRIBED) command.  This command returns a tagged OK response
   if the unsubscription is successful or if the mailbox is not
   subscribed.
   Example:
     C: A002 UNSUBSCRIBE #news.comp.mail.mime
     S: A002 OK UNSUBSCRIBE completed
6.3.9.  LIST Command
   Arguments (basic):
                 reference name
                 mailbox name with possible wildcards
   Arguments (extended):
                 selection options (OPTIONAL)
                 reference name
                 mailbox patterns
                 return options (OPTIONAL)
   Responses:    untagged responses: LIST
   Result:       OK -  list completed
                 NO -  list failure: can't list that reference or
                    mailbox name
                 BAD -  command unknown or arguments invalid
   The LIST command returns a subset of mailbox names from the complete
   set of all mailbox names available to the client.  Zero or more
   untagged LIST responses are returned, containing the name attributes,
   hierarchy delimiter, name, and possible extension information; see
   the description of the LIST response (Section 7.3.1) for more detail.
   The LIST command SHOULD return its data quickly, without undue delay.
   For example, it should not go to excess trouble to calculate the
   \Marked or \Unmarked status or perform other processing; if each name
   requires 1 second of processing, then a list of 1200 names would take
   20 minutes!
   The extended LIST command, originally introduced in [RFC5258],
   provides capabilities beyond that of the original IMAP LIST command.
   The extended syntax is being used if one or more of the following
   conditions is true:
   1.  the first word after the command name begins with a parenthesis
       ("LIST selection options");
   2.  the second word after the command name begins with a parenthesis;
       and
   3.  the LIST command has more than 2 parameters ("LIST return
       options").
   An empty ("" string) reference name argument indicates that the
   mailbox name is interpreted as by SELECT.  The returned mailbox names
   MUST match the supplied mailbox name pattern(s).  A non-empty
   reference name argument is the name of a mailbox or a level of
   mailbox hierarchy, and it indicates the context in which the mailbox
   name is interpreted.  Clients SHOULD use the empty reference
   argument.
   In the basic syntax only, an empty ("" string) mailbox name argument
   is a special request to return the hierarchy delimiter and the root
   name of the name given in the reference.  The value returned as the
   root MAY be the empty string if the reference is non-rooted or is an
   empty string.  In all cases, a hierarchy delimiter (or NIL if there
   is no hierarchy) is returned.  This permits a client to get the
   hierarchy delimiter (or find out that the mailbox names are flat)
   even when no mailboxes by that name currently exist.
   In the extended syntax, any mailbox name arguments that are empty
   strings are ignored.  There is no special meaning for empty mailbox
   names when the extended syntax is used.
   The reference and mailbox name arguments are interpreted into a
   canonical form that represents an unambiguous left-to-right
   hierarchy.  The returned mailbox names will be in the interpreted
   form, which we call a "canonical LIST pattern": the canonical pattern
   constructed internally by the server from the reference and mailbox
   name arguments.
      Note: The interpretation of the reference argument is
      implementation defined.  It depends on whether the server
      implementation has a concept of the "current working directory"
      and leading "break out characters", which override the current
      working directory.
      For example, on a server that exports a UNIX or NT file system,
      the reference argument contains the current working directory, and
      the mailbox name argument contains the name as interpreted in the
      current working directory.
      If a server implementation has no concept of break out characters,
      the canonical form is normally the reference name appended with
      the mailbox name.  Note that if the server implements the
      namespace convention (Section 5.1.2.1), "#" is a break out
      character and must be treated as such.
      If the reference argument is not a level of mailbox hierarchy
      (that is, it is a \NoInferiors name), and/or the reference
      argument does not end with the hierarchy delimiter, it is
      interpreted as implementation dependent.  For example, a reference
      of "foo/bar" and mailbox name of "rag/baz" could be interpreted as
      "foo/bar/rag/baz", "foo/barrag/baz", or "foo/rag/baz".  A client
      SHOULD NOT use such a reference argument except at the explicit
      request of the user.  A hierarchical browser MUST NOT make any
      assumptions about server interpretation of the reference unless
      the reference is a level of mailbox hierarchy AND ends with the
      hierarchy delimiter.
   Any part of the reference argument that is included in the
   interpreted form SHOULD prefix the interpreted form.  It SHOULD also
   be in the same form as the reference name argument.  This rule
   permits the client to determine if the returned mailbox name is in
   the context of the reference argument or if something about the
   mailbox argument overrode the reference argument.  Without this rule,
   the client would have to have knowledge of the server's naming
   semantics including what characters are "breakouts" that override a
   naming context.
   Here are some examples of how references and mailbox names might be
   interpreted on a UNIX-based server:
            +==============+==============+===================+
            | Reference    | Mailbox Name | Interpretation    |
            +==============+==============+===================+
            | ~smith/Mail/ | foo.*        | ~smith/Mail/foo.* |
            +--------------+--------------+-------------------+
            | archive/     | %            | archive/%         |
            +--------------+--------------+-------------------+
            | #news.       | comp.mail.*  | #news.comp.mail.* |
            +--------------+--------------+-------------------+
            | ~smith/Mail/ | /usr/doc/foo | /usr/doc/foo      |
            +--------------+--------------+-------------------+
            | archive/     | ~fred/Mail/* | ~fred/Mail/*      |
            +--------------+--------------+-------------------+
                                  Table 1
   The first three examples above demonstrate interpretations in the
   context of the reference argument.  Note that "~smith/Mail" SHOULD
   NOT be transformed into something like "/u2/users/smith/Mail", or it
   would be impossible for the client to determine that the
   interpretation was in the context of the reference.
   The character "*" is a wildcard and matches zero or more characters
   at this position.  The character "%" is similar to "*", but it does
   not match a hierarchy delimiter.  If the "%" wildcard is the last
   character of a mailbox name argument, matching levels of hierarchy
   are also returned.  If these levels of hierarchy are not also
   selectable mailboxes, they are returned with the \Noselect mailbox
   name attribute (see the description of the LIST response
   (Section 7.3.1) for more details).
   Any syntactically valid pattern that is not accepted by a server for
   any reason MUST be silently ignored, i.e., it results in no LIST
   responses, and the LIST command still returns a tagged OK response.
   Selection options tell the server to limit the mailbox names that are
   selected by the LIST operation.  If selection options are used, the
   mailboxes returned are those that match both the list of canonical
   LIST patterns and the selection options.  Unless a particular
   selection option provides special rules, the selection options are
   cumulative: a mailbox that matches the mailbox patterns is selected
   only if it also matches all of the selection options.  (An example of
   a selection option with special rules is the RECURSIVEMATCH option.)
   Return options control what information is returned for each matched
   mailbox.  Return options MUST NOT cause the server to report
   information about additional mailbox names other than those that
   match the canonical LIST patterns and selection options.  If no
   return options are specified, the client is only expecting
   information about mailbox attributes.  The server MAY return other
   information about the matched mailboxes, and clients MUST be able to
   handle that situation.
   Initial selection options and return options are defined in the
   following subsections, and new ones will also be defined in
   extensions.  Initial options defined in this document MUST be
   supported.  Each non-initial option will be enabled by a capability
   string (one capability may enable multiple options), and a client
   MUST NOT send an option for which the server has not advertised
   support.  A server MUST respond to options it does not recognize with
   a BAD response.  The client SHOULD NOT specify any option more than
   once; however, if the client does this, the server MUST act as if it
   received the option only once.  The order in which options are
   specified by the client is not significant.
   In general, each selection option except RECURSIVEMATCH will have a
   corresponding return option with the same name.  The REMOTE selection
   option is an anomaly in this regard and does not have a corresponding
   return option.  That is because it expands, rather than restricts,
   the set of mailboxes that are returned.  Future extensions to this
   specification should keep this parallelism in mind and define a pair
   of corresponding selection and return options.
   Server implementations are permitted to "hide" otherwise accessible
   mailboxes from the wildcard characters, by preventing certain
   characters or names from matching a wildcard in certain situations.
   For example, a UNIX-based server might restrict the interpretation of
   "*" so that an initial "/" character does not match.
   The special name INBOX is included in the output from LIST, if INBOX
   is supported by this server for this user and if the uppercase string
   "INBOX" matches the interpreted reference and mailbox name arguments
   with wildcards as described above.  The criteria for omitting INBOX
   is whether SELECT INBOX will return a failure; it is not relevant
   whether the user's real INBOX resides on this or some other server.
6.3.9.1.  LIST Selection Options
   The selection options defined in this specification are as follows:
   SUBSCRIBED
      Causes the LIST command to list subscribed names rather than the
      existing mailboxes.  This will often be a subset of the actual
      mailboxes.  It's also possible for this list to contain the names
      of mailboxes that don't exist.  In any case, the list MUST include
      exactly those mailbox names that match the canonical list pattern
      and are subscribed to.
      This option defines a mailbox attribute, "\Subscribed", that
      indicates that a mailbox name is subscribed to.  The "\Subscribed"
      attribute MUST be supported and MUST be accurately computed when
      the SUBSCRIBED selection option is specified.
      Note that the SUBSCRIBED selection option implies the SUBSCRIBED
      return option (see below).
   REMOTE
      Causes the LIST command to show remote mailboxes as well as local
      ones, as described in [RFC2193].  This option is intended to
      replace the RLIST command and, in conjunction with the SUBSCRIBED
      selection option, the RLSUB command.  Servers that don't support
      the concept of remote mailboxes can ignore this option.
      This option defines a mailbox attribute, "\Remote", that indicates
      that a mailbox is a remote mailbox.  The "\Remote" attribute MUST
      be accurately computed when the REMOTE option is specified.
      The REMOTE selection option has no interaction with other options.
      Its effect is to tell the server to apply the other options, if
      any, to remote mailboxes, in addition to local ones.  In
      particular, it has no interaction with RECURSIVEMATCH (see below).
      A request for (REMOTE RECURSIVEMATCH) is invalid, because a
      request for (RECURSIVEMATCH) is also invalid.  A request for
      (REMOTE RECURSIVEMATCH SUBSCRIBED) is asking for all subscribed
      mailboxes, both local and remote.
   RECURSIVEMATCH
      Forces the server to return information about parent mailboxes
      that don't match other selection options but have some
      submailboxes that do.  Information about children is returned in
      the CHILDINFO extended data item, as described in Section 6.3.9.6.
      Note 1:  In order for a parent mailbox to be returned, it still
         has to match the canonical LIST pattern.
      Note 2:  When returning the CHILDINFO extended data item, it
         doesn't matter whether or not the submailbox matches the
         canonical LIST pattern.  See also Example 9 in Section 6.3.9.8.
      The RECURSIVEMATCH option MUST NOT occur as the only selection
      option (or only with REMOTE), as it only makes sense when other
      selection options are also used.  The server MUST return a BAD
      tagged response in such case.
      Note that even if the RECURSIVEMATCH option is specified, the
      client MUST still be able to handle cases when a CHILDINFO
      extended data item is returned and there are no submailboxes that
      meet the selection criteria of the subsequent LIST command, as
      they can be deleted/renamed after the LIST response was sent but
      before the client had a chance to access them.
6.3.9.2.  LIST Return Options
   The return options defined in this specification are as follows:
   SUBSCRIBED
      Causes the LIST command to return subscription state for all
      matching mailbox names.  The "\Subscribed" attribute MUST be
      supported and MUST be accurately computed when the SUBSCRIBED
      return option is specified.  Furthermore, all other mailbox
      attributes MUST be accurately computed (this differs from the
      behavior of the obsolete LSUB command from [RFC3501]).  Note that
      the above requirements don't override the requirement for the LIST
      command to return results quickly (see Section 6.3.9), i.e.,
      server implementations need to compute results quickly and
      accurately.  For example, server implementors might need to create
      quick access indices.
   CHILDREN
      Requests mailbox child information as originally proposed in
      [RFC3348].  See Section 6.3.9.5, below, for details.
   STATUS
      Requests STATUS response for each matching mailbox.
      This option takes STATUS data items as parameters.  For each
      selectable mailbox matching the list pattern and selection
      options, the server MUST return an untagged LIST response followed
      by an untagged STATUS response containing the information
      requested in the STATUS return option, except for some cases
      described below.
      If an attempted STATUS for a listed mailbox fails because the
      mailbox can't be selected (e.g., if the "l" Access Control List
      (ACL) right [RFC4314] is granted to the mailbox and the "r" right
      is not granted, or is due to a race condition between LIST and
      STATUS changing the mailbox to \NoSelect), the STATUS response
      MUST NOT be returned, and the LIST response MUST include the
      \NoSelect attribute.  This means the server may have to buffer the
      LIST reply until it has successfully looked up the necessary
      STATUS information.
      If the server runs into unexpected problems while trying to look
      up the STATUS information, it MAY drop the corresponding STATUS
      reply.  In such a situation, the LIST command would still return a
      tagged OK reply.
      See the note in the discussion of the STATUS command in
      Section 6.3.11 for information about obtaining status on the
      currently selected mailbox.
6.3.9.3.  General Principles for Returning LIST Responses
   This section outlines several principles that can be used by server
   implementations of this document to decide whether a LIST response
   should be returned, as well as how many responses and what kind of
   information they may contain.
   1.  At most, one LIST response should be returned for each mailbox
       name that matches the canonical LIST pattern.  Server
       implementors must not assume that clients will be able to
       assemble mailbox attributes and other information returned in
       multiple LIST responses.
   2.  There are only two reasons for including a matching mailbox name
       in the responses to the LIST command (note that the server is
       allowed to return unsolicited responses at any time, and such
       responses are not governed by this rule):
       A.  The mailbox name also satisfies the selection criteria.
       B.  The mailbox name doesn't satisfy the selection criteria, but
           it has at least one descendant mailbox name that satisfies
           the selection criteria and that doesn't match the canonical
           LIST pattern.
           For more information on this case, see the CHILDINFO extended
           data item described in Section 6.3.9.6.  Note that the
           CHILDINFO extended data item can only be returned when the
           RECURSIVEMATCH selection option is specified.
   3.  Attributes returned in the same LIST response are treated
       additively.  For example, the following response
        S: * LIST (\Subscribed \NonExistent) "/" "Fruit/Peach"
       means that the "Fruit/Peach" mailbox doesn't exist, but it is
       subscribed.
6.3.9.4.  Additional LIST-Related Requirements on Clients
   All clients MUST treat a LIST attribute with a stronger meaning as
   implying any attribute that can be inferred from it.  (See
   Section 7.3.1 for the list of currently defined attributes.)  For
   example, the client must treat the presence of the \NoInferiors
   attribute as if the \HasNoChildren attribute was also sent by the
   server.
   The following table summarizes inference rules.
                +====================+===================+
                | returned attribute | implied attribute |
                +====================+===================+
                |    \NoInferiors    |   \HasNoChildren  |
                +--------------------+-------------------+
                |    \NonExistent    |     \NoSelect     |
                +--------------------+-------------------+
                                 Table 2
6.3.9.5.  The CHILDREN Return Option
   The CHILDREN return option is simply an indication that the client
   wants information about whether or not mailboxes contain child
   mailboxes; a server MAY provide it even if the option is not
   specified.
   Many IMAP clients present the user with a hierarchical view of the
   mailboxes that a user has access to.  Rather than initially
   presenting the entire mailbox hierarchy to the user, it is often
   preferable to show the user a collapsed outline list of the mailbox
   hierarchy (particularly if there is a large number of mailboxes).
   The user can then expand the collapsed outline hierarchy as needed.
   It is common to include a visual clue (such as a ''+'') within the
   collapsed hierarchy to indicate that there are child mailboxes under
   a particular mailbox.  When the visual clue is clicked, the hierarchy
   list is expanded to show the child mailboxes.  The CHILDREN return
   option provides a mechanism for a client to efficiently determine
   whether a particular mailbox has children, without issuing a LIST ""
   * or a LIST "" % for each mailbox name.  The CHILDREN return option
   defines two new attributes that MUST be returned within a LIST
   response: \HasChildren and \HasNoChildren.  Although these attributes
   MAY be returned in response to any LIST command, the CHILDREN return
   option is provided to indicate that the client particularly wants
   this information.  If the CHILDREN return option is present, the
   server MUST return these attributes even if their computation is
   expensive.
   \HasChildren
        The presence of this attribute indicates that the mailbox has
        child mailboxes.  A server SHOULD NOT set this attribute if
        there are child mailboxes and the user does not have permission
        to access any of them.  In this case, \HasNoChildren SHOULD be
        used.  In many cases, however, a server may not be able to
        efficiently compute whether a user has access to any child
        mailbox.  Note that even though the \HasChildren attribute for a
        mailbox must be correct at the time of processing the mailbox, a
        client must be prepared to deal with a situation when a mailbox
        is marked with the \HasChildren attribute, but no child mailbox
        appears in the response to the LIST command.  This might happen,
        for example, due to child mailboxes being deleted or made
        inaccessible to the user (using access control) by another
        client before the server is able to list them.
   \HasNoChildren
        The presence of this attribute indicates that the mailbox has NO
        child mailboxes that are accessible to the currently
        authenticated user.
   It is an error for the server to return both a \HasChildren and a
   \HasNoChildren attribute in the same LIST response.
   Note: the \HasNoChildren attribute should not be confused with the
   \NoInferiors attribute, which indicates that no child mailboxes exist
   now and none can be created in the future.
6.3.9.6.  CHILDINFO Extended Data Item
   The CHILDINFO extended data item MUST NOT be returned unless the
   client has specified the RECURSIVEMATCH selection option.
   The CHILDINFO extended data item in a LIST response describes the
   selection criteria that has caused it to be returned and indicates
   that the mailbox has at least one descendant mailbox that matches the
   selection criteria.
   Note: Some servers allow for mailboxes to exist without requiring
   their parent to exist.  For example, the mailbox "Customers/ABC" can
   exist while the mailbox "Customers" does not.  As the CHILDINFO
   extended data item is not allowed if the RECURSIVEMATCH selection
   option is not specified, such servers SHOULD use the "\NonExistent
   \HasChildren" attribute pair to signal to the client that there is a
   descendant mailbox that matches the selection criteria.  See Example
   11 in Section 6.3.9.8.
   The returned selection criteria allows the client to distinguish a
   solicited response from an unsolicited one, as well as to distinguish
   among solicited responses caused by multiple pipelined LIST commands
   that specify different criteria.
   Servers SHOULD only return a non-matching mailbox name along with
   CHILDINFO if at least one matching child is not also being returned.
   That is, servers SHOULD suppress redundant CHILDINFO responses.
   Examples 8 and 10 in Section 6.3.9.8 demonstrate the difference
   between the present CHILDINFO extended data item and the
   "\HasChildren" attribute.
   The following table summarizes interaction between the "\NonExistent"
   attribute and CHILDINFO (the first column indicates whether the
   parent mailbox exists):
     +========+===========+====================+=====================+
     | Exists | Meets the |  Has a child that  | Returned IMAP4rev2/ |
     |        | selection |     meets the      |    LIST-EXTENDED    |
     |        |  criteria | selection criteria |    attributes and   |
     |        |           |                    |      CHILDINFO      |
     +========+===========+====================+=====================+
     |   no   |     no    |         no         |   no LIST response  |
     |        |           |                    |       returned      |
     +--------+-----------+--------------------+---------------------+
     |  yes   |     no    |         no         |   no LIST response  |
     |        |           |                    |       returned      |
     +--------+-----------+--------------------+---------------------+
     |   no   |    yes    |         no         |    (\NonExistent    |
     |        |           |                    |       <attr>)       |
     +--------+-----------+--------------------+---------------------+
     |  yes   |    yes    |         no         |       (<attr>)      |
     +--------+-----------+--------------------+---------------------+
     |   no   |     no    |        yes         |   (\NonExistent) +  |
     |        |           |                    |      CHILDINFO      |
     +--------+-----------+--------------------+---------------------+
     |  yes   |     no    |        yes         |    () + CHILDINFO   |
     +--------+-----------+--------------------+---------------------+
     |   no   |    yes    |        yes         |    (\NonExistent    |
     |        |           |                    | <attr>) + CHILDINFO |
     +--------+-----------+--------------------+---------------------+
     |  yes   |    yes    |        yes         |      (<attr>) +     |
     |        |           |                    |      CHILDINFO      |
     +--------+-----------+--------------------+---------------------+
                                  Table 3
   where <attr> is one or more attributes that correspond to the
   selection criteria; for example, for the SUBSCRIBED option, the
   <attr> is \Subscribed.
6.3.9.7.  OLDNAME Extended Data Item
   The OLDNAME extended data item is included when a mailbox name is
   created (with the CREATE command), renamed (with the RENAME command),
   or deleted (with the DELETE command).  (When a mailbox is deleted,
   the "\NonExistent" attribute is also included.)  IMAP extensions can
   specify other conditions when the OLDNAME extended data item should
   be included.
   If the server allows denormalized mailbox names (see Section 5.1) in
   SELECT/EXAMINE, CREATE, RENAME, or DELETE, it SHOULD return an
   unsolicited LIST response that includes the OLDNAME extended data
   item, whenever the supplied mailbox name differs from the resulting
   normalized mailbox name.  From the client point of view, this is
   indistinguishable from another user renaming or deleting the mailbox,
   as specified in the previous paragraph.
   A deleted mailbox can be announced as follows:
     S: * LIST (\NonExistent) "." "INBOX.DeletedMailbox"
   Example of a renamed mailbox:
     S: * LIST () "/" "NewMailbox" ("OLDNAME" ("OldMailbox"))
6.3.9.8.  LIST Command Examples
   This example shows some uses of the basic LIST command:
   Example:
     C: A101 LIST "" ""
     S: * LIST (\Noselect) "/" ""
     S: A101 OK LIST Completed
     C: A102 LIST #news.comp.mail.misc ""
     S: * LIST (\Noselect) "." #news.
     S: A102 OK LIST Completed
     C: A103 LIST /usr/staff/jones ""
     S: * LIST (\Noselect) "/" /
     S: A103 OK LIST Completed
     C: A202 LIST ~/Mail/ %
     S: * LIST (\Noselect) "/" ~/Mail/foo
     S: * LIST () "/" ~/Mail/meetings
     S: A202 OK LIST completed
   Extended examples:
   1:   The first example shows the complete local hierarchy that will
        be used for the other examples.
        C: A01 LIST "" "*"
        S: * LIST (\Marked \NoInferiors) "/" "inbox"
        S: * LIST () "/" "Fruit"
        S: * LIST () "/" "Fruit/Apple"
        S: * LIST () "/" "Fruit/Banana"
        S: * LIST () "/" "Tofu"
        S: * LIST () "/" "Vegetable"
        S: * LIST () "/" "Vegetable/Broccoli"
        S: * LIST () "/" "Vegetable/Corn"
        S: A01 OK done
   2:   In the next example, we will see the subscribed mailboxes.  This
        is similar to, but not equivalent with, the now deprecated <LSUB
        "" "*"> (see [RFC3501] for more details on the LSUB command).
        Note that the mailbox called "Fruit/Peach" is subscribed to, but
        it does not actually exist (perhaps it was deleted while still
        subscribed).  The "Fruit" mailbox is not subscribed to, but it
        has two subscribed children.  The "Vegetable" mailbox is
        subscribed and has two children; one of them is subscribed as
        well.
        C: A02 LIST (SUBSCRIBED) "" "*"
        S: * LIST (\Marked \NoInferiors \Subscribed) "/" "inbox"
        S: * LIST (\Subscribed) "/" "Fruit/Banana"
        S: * LIST (\Subscribed \NonExistent) "/" "Fruit/Peach"
        S: * LIST (\Subscribed) "/" "Vegetable"
        S: * LIST (\Subscribed) "/" "Vegetable/Broccoli"
        S: A02 OK done
   3:   The next example shows the use of the CHILDREN option.  The
        client, without having to list the second level of hierarchy,
        now knows which of the top-level mailboxes have submailboxes
        (children) and which do not.  Note that it's not necessary for
        the server to return the \HasNoChildren attribute for the inbox,
        because the \NoInferiors attribute already implies that and has
        a stronger meaning.
        C: A03 LIST () "" "%" RETURN (CHILDREN)
        S: * LIST (\Marked \NoInferiors) "/" "inbox"
        S: * LIST (\HasChildren) "/" "Fruit"
        S: * LIST (\HasNoChildren) "/" "Tofu"
        S: * LIST (\HasChildren) "/" "Vegetable"
        S: A03 OK done
   4:   In this example, we see more mailboxes that reside on another
        server.  This is similar to the command <RLIST "" "%">.
        C: A04 LIST (REMOTE) "" "%" RETURN (CHILDREN)
        S: * LIST (\Marked \NoInferiors) "/" "inbox"
        S: * LIST (\HasChildren) "/" "Fruit"
        S: * LIST (\HasNoChildren) "/" "Tofu"
        S: * LIST (\HasChildren) "/" "Vegetable"
        S: * LIST (\Remote \HasNoChildren) "/" "Bread"
        S: * LIST (\HasChildren \Remote) "/" "Meat"
        S: A04 OK done
   5:   The following example also requests the server to include
        mailboxes that reside on another server.  The server returns
        information about all mailboxes that are subscribed.  This is
        similar to the command <RLSUB "" "*"> (see [RFC2193] for more
        details on RLSUB).  We also see the use of two selection
        options.
        C: A05 LIST (REMOTE SUBSCRIBED) "" "*"
        S: * LIST (\Marked \NoInferiors \Subscribed) "/" "inbox"
        S: * LIST (\Subscribed) "/" "Fruit/Banana"
        S: * LIST (\Subscribed \NonExistent) "/" "Fruit/Peach"
        S: * LIST (\Subscribed) "/" "Vegetable"
        S: * LIST (\Subscribed) "/" "Vegetable/Broccoli"
        S: * LIST (\Remote \Subscribed) "/" "Bread"
        S: A05 OK done
   6:   The following example requests the server to include mailboxes
        that reside on another server.  The server is asked to return
        subscription information for all returned mailboxes.  This is
        different from the example above.
        Note that the output of this command is not a superset of the
        output in the previous example, as it doesn't include a LIST
        response for the non-existent "Fruit/Peach".
        C: A06 LIST (REMOTE) "" "*" RETURN (SUBSCRIBED)
        S: * LIST (\Marked \NoInferiors \Subscribed) "/" "inbox"
        S: * LIST () "/" "Fruit"
        S: * LIST () "/" "Fruit/Apple"
        S: * LIST (\Subscribed) "/" "Fruit/Banana"
        S: * LIST () "/" "Tofu"
        S: * LIST (\Subscribed) "/" "Vegetable"
        S: * LIST (\Subscribed) "/" "Vegetable/Broccoli"
        S: * LIST () "/" "Vegetable/Corn"
        S: * LIST (\Remote \Subscribed) "/" "Bread"
        S: * LIST (\Remote) "/" "Meat"
        S: A06 OK done
   7:   The following example demonstrates the difference between the
        \HasChildren attribute and the CHILDINFO extended data item.
        Let's assume there is the following hierarchy:
        C: C01 LIST "" "*"
        S: * LIST (\Marked \NoInferiors) "/" "inbox"
        S: * LIST () "/" "Foo"
        S: * LIST () "/" "Foo/Bar"
        S: * LIST () "/" "Foo/Baz"
        S: * LIST () "/" "Moo"
        S: C01 OK done
        If the client asks RETURN (CHILDREN), it will get this:
        C: CA3 LIST "" "%" RETURN (CHILDREN)
        S: * LIST (\Marked \NoInferiors) "/" "inbox"
        S: * LIST (\HasChildren) "/" "Foo"
        S: * LIST (\HasNoChildren) "/" "Moo"
        S: CA3 OK done
        A)  Let's also assume that the mailbox "Foo/Baz" is the only
            subscribed mailbox.  Then we get this result:
             C: C02 LIST (SUBSCRIBED) "" "*"
             S: * LIST (\Subscribed) "/" "Foo/Baz"
             S: C02 OK done
            Now, if the client issues <LIST (SUBSCRIBED) "" "%">, the
            server will return no mailboxes (as the mailboxes "Moo",
            "Foo", and "Inbox" are NOT subscribed).  However, if the
            client issues this:
             C: C04 LIST (SUBSCRIBED RECURSIVEMATCH) "" "%"
             S: * LIST () "/" "Foo" ("CHILDINFO" ("SUBSCRIBED"))
             S: C04 OK done
            (that is, the mailbox "Foo" is not subscribed, but it has a
            child that is), then A1 or A2 occurs.
            A1)  If the mailbox "Foo" had also been subscribed, the last
                 command would return this:
                 C: C04 LIST (SUBSCRIBED RECURSIVEMATCH) "" "%"
                 S: * LIST (\Subscribed) "/" "Foo" ("CHILDINFO"
                     ("SUBSCRIBED"))
                 S: C04 OK done
                 or even this:
                 C: C04 LIST (SUBSCRIBED RECURSIVEMATCH) "" "%"
                 S: * LIST (\Subscribed \HasChildren) "/" "Foo"
                     ("CHILDINFO" ("SUBSCRIBED"))
                 S: C04 OK done
            A2)  If we assume instead that the mailbox "Foo" is not part
                 of the original hierarchy and is not subscribed, the
                 last command will give this result:
                 C: C04 LIST (SUBSCRIBED RECURSIVEMATCH) "" "%"
                 S: * LIST (\NonExistent) "/" "Foo" ("CHILDINFO"
                     ("SUBSCRIBED"))
                 S: C04 OK done
        B)  Now, let's assume that no mailbox is subscribed.  In this
            case, the command <LIST (SUBSCRIBED RECURSIVEMATCH) "" "%">
            will return no responses, as there are no subscribed
            children (even though "Foo" has children).
        C)  And finally, suppose that only the mailboxes "Foo" and "Moo"
            are subscribed.  In that case, we see this result:
             C: C04 LIST (SUBSCRIBED RECURSIVEMATCH) "" "%" RETURN
                 (CHILDREN)
             S: * LIST (\HasChildren \Subscribed) "/" "Foo"
             S: * LIST (\HasNoChildren \Subscribed) "/" "Moo"
             S: C04 OK done
            (which means that the mailbox "Foo" has children, but none
            of them is subscribed).
   8:   The following example demonstrates that the CHILDINFO extended
        data item is returned whether or not child mailboxes match the
        canonical LIST pattern.
        Let's assume there is the following hierarchy:
        C: D01 LIST "" "*"
        S: * LIST (\Marked \NoInferiors) "/" "inbox"
        S: * LIST () "/" "foo2"
        S: * LIST () "/" "foo2/bar1"
        S: * LIST () "/" "foo2/bar2"
        S: * LIST () "/" "baz2"
        S: * LIST () "/" "baz2/bar2"
        S: * LIST () "/" "baz2/bar22"
        S: * LIST () "/" "baz2/bar222"
        S: * LIST () "/" "eps2"
        S: * LIST () "/" "eps2/mamba"
        S: * LIST () "/" "qux2/bar2"
        S: D01 OK done
        And that the following mailboxes are subscribed:
        C: D02 LIST (SUBSCRIBED) "" "*"
        S: * LIST (\Subscribed) "/" "foo2/bar1"
        S: * LIST (\Subscribed) "/" "foo2/bar2"
        S: * LIST (\Subscribed) "/" "baz2/bar2"
        S: * LIST (\Subscribed) "/" "baz2/bar22"
        S: * LIST (\Subscribed) "/" "baz2/bar222"
        S: * LIST (\Subscribed) "/" "eps2"
        S: * LIST (\Subscribed) "/" "eps2/mamba"
        S: * LIST (\Subscribed) "/" "qux2/bar2"
        S: D02 OK done
        The client issues the following command first:
        C: D03 LIST (RECURSIVEMATCH SUBSCRIBED) "" "*2"
        S: * LIST () "/" "foo2" ("CHILDINFO" ("SUBSCRIBED"))
        S: * LIST (\Subscribed) "/" "foo2/bar2"
        S: * LIST (\Subscribed) "/" "baz2/bar2"
        S: * LIST (\Subscribed) "/" "baz2/bar22"
        S: * LIST (\Subscribed) "/" "baz2/bar222"
        S: * LIST (\Subscribed) "/" "eps2" ("CHILDINFO" ("SUBSCRIBED"))
        S: * LIST (\Subscribed) "/" "qux2/bar2"
        S: D03 OK done
        and the server may also include the following (but this would
        violate a restriction in Section 6.3.9.6, because CHILDINFO is
        redundant):
        S: * LIST () "/" "baz2" ("CHILDINFO" ("SUBSCRIBED"))
        S: * LIST (\NonExistent) "/" "qux2" ("CHILDINFO" ("SUBSCRIBED"))
        The CHILDINFO extended data item is returned for mailboxes
        "foo2", "baz2", and "eps2" because all of them have subscribed
        children, even though for the mailbox "foo2", only one of the
        two subscribed children matches the pattern; for the mailbox
        "baz2", all of the subscribed children match the pattern; and
        for the mailbox "eps2", none of the subscribed children match
        the pattern.
        Note that if the client issues the following:
        C: D03 LIST (RECURSIVEMATCH SUBSCRIBED) "" "*"
        S: * LIST () "/" "foo2" ("CHILDINFO" ("SUBSCRIBED"))
        S: * LIST (\Subscribed) "/" "foo2/bar1"
        S: * LIST (\Subscribed) "/" "foo2/bar2"
        S: * LIST () "/" "baz2" ("CHILDINFO" ("SUBSCRIBED"))
        S: * LIST (\Subscribed) "/" "baz2/bar2"
        S: * LIST (\Subscribed) "/" "baz2/bar22"
        S: * LIST (\Subscribed) "/" "baz2/bar222"
        S: * LIST (\Subscribed) "/" "eps2" ("CHILDINFO" ("SUBSCRIBED"))
        S: * LIST (\Subscribed) "/" "eps2/mamba"
        S: * LIST (\Subscribed) "/" "qux2/bar2"
        S: D03 OK done
        the LIST responses for mailboxes "foo2", "baz2", and "eps2"
        still have the CHILDINFO extended data item, even though this
        information is redundant and the client can determine it by
        itself.
   9:   The following example shows usage of an extended syntax for the
        mailbox pattern.  It also demonstrates that the presence of the
        CHILDINFO extended data item doesn't necessarily imply
        \HasChildren.
        C: a1 LIST "" ("foo")
        S: * LIST () "/" foo
        S: a1 OK done
        C: a2 LIST (SUBSCRIBED) "" "foo/*"
        S: * LIST (\Subscribed \NonExistent) "/" foo/bar
        S: a2 OK done
        C: a3 LIST (SUBSCRIBED RECURSIVEMATCH) "" foo RETURN (CHILDREN)
        S: * LIST (\HasNoChildren) "/" foo ("CHILDINFO" ("SUBSCRIBED"))
        S: a3 OK done
   10:  The following example shows how a server that supports missing
        mailbox hierarchy elements can signal to a client that didn't
        specify the RECURSIVEMATCH selection option that there is a
        child mailbox that matches the selection criteria.
        C: a1 LIST (REMOTE) "" *
        S: * LIST () "/" music/rock
        S: * LIST (\Remote) "/" also/jazz
        S: a1 OK done
        C: a2 LIST () "" %
        S: * LIST (\NonExistent \HasChildren) "/" music
        S: a2 OK done
        C: a3 LIST (REMOTE) "" %
        S: * LIST (\NonExistent \HasChildren) "/" music
        S: * LIST (\NonExistent \HasChildren) "/" also
        S: a3 OK done
        C: a3.1 LIST "" (% music/rock)
        S: * LIST () "/" music/rock
        S: a3.1 OK done
        Because "music/rock" is the only mailbox under "music", there's
        no need for the server to also return "music".  However, clients
        must handle both cases.
   11:  The following examples show use of the STATUS return option.
        C: A01 LIST "" % RETURN (STATUS (MESSAGES UNSEEN))
        S: * LIST () "."  "INBOX"
        S: * STATUS "INBOX" (MESSAGES 17 UNSEEN 16)
        S: * LIST () "." "foo"
        S: * STATUS "foo" (MESSAGES 30 UNSEEN 29)
        S: * LIST (\NoSelect) "." "bar"
        S: A01 OK List completed.
        The "bar" mailbox isn't selectable, so it has no STATUS reply.
        C: A02 LIST (SUBSCRIBED RECURSIVEMATCH) "" % RETURN (STATUS
             (MESSAGES))
        S: * LIST (\Subscribed) "."  "INBOX"
        S: * STATUS "INBOX" (MESSAGES 17)
        S: * LIST () "." "foo" (CHILDINFO ("SUBSCRIBED"))
        S: A02 OK List completed.
        The LIST reply for "foo" is returned because it has matching
        children, but no STATUS reply is returned because "foo" itself
        doesn't match the selection criteria.
6.3.10.  NAMESPACE Command
   Arguments:    none
   Responses:    REQUIRED untagged responses:  NAMESPACE
   Result:       OK -  command completed
                 NO -  Can't complete the command
                 BAD -  arguments invalid
   The NAMESPACE command causes a single untagged NAMESPACE response to
   be returned.  The untagged NAMESPACE response contains the prefix and
   hierarchy delimiter to the server's Personal Namespace(s), Other
   Users' Namespace(s), and Shared Namespace(s) that the server wishes
   to expose.  The response will contain a NIL for any namespace class
   that is not available.  The namespace-response-extensions ABNF non-
   terminal is defined for extensibility and MAY be included in the
   NAMESPACE response.
   Example 1:
   In this example, a server supports a single Personal Namespace.  No
   leading prefix is used on personal mailboxes, and "/" is the
   hierarchy delimiter.
     C: A001 NAMESPACE
     S: * NAMESPACE (("" "/")) NIL NIL
     S: A001 OK NAMESPACE command completed
   Example 2:
   A user logged on anonymously to a server.  No personal mailboxes are
   associated with the anonymous user, and the user does not have access
   to the Other Users' Namespace.  No prefix is required to access
   shared mailboxes, and the hierarchy delimiter is "."
     C: A001 NAMESPACE
     S: * NAMESPACE NIL NIL (("" "."))
     S: A001 OK NAMESPACE command completed
   Example 3:
   A server that contains a Personal Namespace and a single Shared
   Namespace.
     C: A001 NAMESPACE
     S: * NAMESPACE (("" "/")) NIL (("Public Folders/" "/"))
     S: A001 OK NAMESPACE command completed
   Example 4:
   A server that contains a Personal Namespace, Other Users' Namespace,
   and multiple Shared Namespaces.  Note that the hierarchy delimiter
   used within each namespace can be different.
     C: A001 NAMESPACE
     S: * NAMESPACE (("" "/")) (("~" "/")) (("#shared/" "/")
         ("#public/" "/")("#ftp/" "/")("#news." "."))
     S: A001 OK NAMESPACE command completed
   The prefix string allows a client to do things such as automatically
   create personal mailboxes or LIST all available mailboxes within a
   namespace.
   Example 5:
   A server that supports only the Personal Namespace, with a leading
   prefix of INBOX to personal mailboxes and a hierarchy delimiter of
   ".".
     C: A001 NAMESPACE
     S: * NAMESPACE (("INBOX." ".")) NIL  NIL
     S: A001 OK NAMESPACE command completed
   Automatically create a mailbox to store sent items.
     C: A002 CREATE "INBOX.Sent Mail"
     S: A002 OK CREATE command completed
   Although a server will typically support only a single Personal
   Namespace, and a single Other User's Namespace, circumstances exist
   where there MAY be multiples of these, and a client MUST be prepared
   for them.  If a client is configured such that it is required to
   create a certain mailbox, there can be circumstances where it is
   unclear which Personal Namespaces it should create the mailbox in.
   In these situations, a client SHOULD let the user select which
   namespaces to create the mailbox in, or just use the first Personal
   Namespace.
   Example 6:
   In this example, a server supports two Personal Namespaces.  In
   addition to the regular Personal Namespace, the user has an
   additional Personal Namespace that allows access to mailboxes in an
   MH format mailstore.
   The client is configured to save a copy of all mail sent by the user
   into a mailbox with the \Sent attribute (see Section 7.3.1).
   Furthermore, after a message is deleted from a mailbox, the client is
   configured to move that message to a mailbox with the \Trash
   attribute.  The server signals with the \NonExistent mailbox
   attribute that the corresponding mailboxes don't exist yet and that
   it is possible to create them.  Once created, they could be used for
   \Sent or \Trash purposes, and the server will no longer include the
   \NonExistent mailbox attribute for them.
   Note that this example demonstrates how some extension parameters can
   be passed to further describe the #mh namespace.  See the fictitious
   "X-PARAM" extension parameter.
     C: A001 NAMESPACE
     S: * NAMESPACE (("" "/")("#mh/" "/" "X-PARAM"
         ("FLAG1" "FLAG2"))) NIL NIL
     S: A001 OK NAMESPACE command completed
     C: A002 LIST (SPECIAL-USE) "" "*"
     S: * LIST (\NonExistent \Archive) "/" Archives
     S: * LIST (\NonExistent \Drafts) "/" Drafts
     S: * LIST (\NonExistent \Junk) "/" Junk
     S: * LIST (\NonExistent \Sent) "/" "Sent Mail"
     S: * LIST (\NonExistent \Trash) "/" "Deleted Items"
     S: A002 OK LIST Completed
     C: A003 LIST (SPECIAL-USE) "#mh/" "*"
     S: * LIST (\NonExistent \Archive) "/" "#mh/Archives"
     S: * LIST (\NonExistent \Drafts) "/" "#mh/Drafts"
     S: * LIST (\NonExistent \Junk) "/" "#mh/Junk"
     S: * LIST (\NonExistent \Sent) "/" "#mh/Sent Mail"
     S: * LIST (\NonExistent \Trash) "/" "#mh/Deleted Items"
     S: A003 OK LIST Completed
   It is desired to keep only one copy of sent mail.  It is unclear
   which Personal Namespace the client should use to create the 'Sent
   Mail' mailbox.  The user is prompted to select a namespace, and only
   one 'Sent Mail' mailbox is created.
     C: A004 CREATE "Sent Mail"
     S: A004 OK CREATE command completed
   The client is designed so that it keeps two 'Deleted Items'
   mailboxes, one for each namespace.
     C: A005 CREATE "Delete Items"
     S: A005 OK CREATE command completed
     C: A006 CREATE "#mh/Deleted Items"
     S: A006 OK CREATE command completed
   The next level of hierarchy following the Other Users' Namespace
   prefix SHOULD consist of <username>, where <username> is a user name
   as per the LOGIN or AUTHENTICATE command.
   A client can construct a LIST command by appending a "%" to the Other
   Users' Namespace prefix to discover the Personal Namespaces of other
   users that are available to the currently authenticated user.
   In response to such a LIST command, a server SHOULD NOT return user
   names that have not granted access to their personal mailboxes to the
   user in question.
   A server MAY return a LIST response containing only the names of
   users that have explicitly granted access to the user in question.
   Alternatively, a server MAY return NO to such a LIST command,
   requiring that a user name be included with the Other Users'
   Namespace prefix before listing any other user's mailboxes.
   Example 7:
   A server that supports providing a list of other user's mailboxes
   that are accessible to the currently logged on user.
     C: A001 NAMESPACE
     S: * NAMESPACE (("" "/")) (("Other Users/" "/")) NIL
     S: A001 OK NAMESPACE command completed
     C: A002 LIST "" "Other Users/%"
     S: * LIST () "/" "Other Users/Mike"
     S: * LIST () "/" "Other Users/Karen"
     S: * LIST () "/" "Other Users/Matthew"
     S: * LIST () "/" "Other Users/Tesa"
     S: A002 OK LIST command completed
   Example 8:
   A server that does not support providing a list of other user's
   mailboxes that are accessible to the currently logged on user.  The
   mailboxes are listable if the client includes the name of the other
   user with the Other Users' Namespace prefix.
     C: A001 NAMESPACE
     S: * NAMESPACE (("" "/")) (("#Users/" "/")) NIL
     S: A001 OK NAMESPACE command completed
   In this example, the currently logged on user has access to the
   Personal Namespace of user Mike, but the server chose to suppress
   this information in the LIST response.  However, by appending the
   user name Mike (received through user input) to the Other Users'
   Namespace prefix, the client is able to get a listing of the personal
   mailboxes of user Mike.
     C: A002 LIST "" "#Users/%"
     S: A002 NO The requested item could not be found.
     C: A003 LIST "" "#Users/Mike/%"
     S: * LIST () "/" "#Users/Mike/INBOX"
     S: * LIST () "/" "#Users/Mike/Foo"
     S: A003 OK LIST command completed.
   A prefix string might not contain a hierarchy delimiter, because in
   some cases, it is not needed as part of the prefix.
   Example 9:
   A server that allows access to the Other Users' Namespace by
   prefixing the others' mailboxes with a '~' followed by <username>,
   where <username> is a user name as per the LOGIN or AUTHENTICATE
   command.
     C: A001 NAMESPACE
     S: * NAMESPACE (("" "/")) (("~" "/")) NIL
     S: A001 OK NAMESPACE command completed
   List the mailboxes for user mark
     C: A002 LIST "" "~mark/%"
     S: * LIST () "/" "~mark/INBOX"
     S: * LIST () "/" "~mark/foo"
     S: A002 OK LIST command completed
6.3.11.  STATUS Command
   Arguments:    mailbox name
                 status data item names
   Responses:    REQUIRED untagged responses:  STATUS
   Result:       OK -  status completed
                 NO -  status failure: no status for that name
                 BAD -  command unknown or arguments invalid
   The STATUS command requests the status of the indicated mailbox.  It
   does not change the currently selected mailbox, nor does it affect
   the state of any messages in the queried mailbox.
   The STATUS command provides an alternative to opening a second
   IMAP4rev2 connection and doing an EXAMINE command on a mailbox to
   query that mailbox's status without deselecting the current mailbox
   in the first IMAP4rev2 connection.
   Unlike the LIST command, the STATUS command is not guaranteed to be
   fast in its response.  Under certain circumstances, it can be quite
   slow.  In some implementations, the server is obliged to open the
   mailbox as "read-only" internally to obtain certain status
   information.  Also unlike the LIST command, the STATUS command does
   not accept wildcards.
      Note: The STATUS command is intended to access the status of
      mailboxes other than the currently selected mailbox.  Because the
      STATUS command can cause the mailbox to be opened internally, and
      because this information is available by other means on the
      selected mailbox, the STATUS command SHOULD NOT be used on the
      currently selected mailbox.  However, servers MUST be able to
      execute the STATUS command on the selected mailbox.  (This might
      also implicitly happen when the STATUS return option is used in a
      LIST command.)
      The STATUS command MUST NOT be used as a "check for new messages
      in the selected mailbox" operation (refer to Sections 7 and 7.4.1
      for more information about the proper method for new message
      checking).
      STATUS SIZE (see below) can take a significant amount of time,
      depending upon server implementation.  Clients should use STATUS
      SIZE cautiously.
   The currently defined status data items that can be requested are:
   MESSAGES
      The number of messages in the mailbox.
   UIDNEXT
      The next unique identifier value of the mailbox.  Refer to
      Section 2.3.1.1 for more information.
   UIDVALIDITY
      The unique identifier validity value of the mailbox.  Refer to
      Section 2.3.1.1 for more information.
   UNSEEN
      The number of messages that do not have the \Seen flag set.
   DELETED
      The number of messages that have the \Deleted flag set.
   SIZE
      The total size of the mailbox in octets.  This is not strictly
      required to be an exact value, but it MUST be equal to or greater
      than the sum of the values of the RFC822.SIZE FETCH message data
      items (see Section 6.4.5) of all messages in the mailbox.
   Example:
     C: A042 STATUS blurdybloop (UIDNEXT MESSAGES)
     S: * STATUS blurdybloop (MESSAGES 231 UIDNEXT 44292)
     S: A042 OK STATUS completed
6.3.12.  APPEND Command
   Arguments:    mailbox name
                 OPTIONAL flag parenthesized list
                 OPTIONAL date/time string
                 message literal
   Responses:    OPTIONAL untagged response:  LIST
   Result:       OK -  append completed
                 NO -  append error: can't append to that mailbox, error
                    in flags or date/time or message text
                 BAD -  command unknown or arguments invalid
   The APPEND command appends the literal argument as a new message to
   the end of the specified destination mailbox.  This argument SHOULD
   be in the format of an [RFC5322] or [I18N-HDRS] message.  8-bit
   characters are permitted in the message.  A server implementation
   that is unable to preserve 8-bit data properly MUST be able to
   reversibly convert 8-bit APPEND data to 7 bits using a [MIME-IMB]
   content transfer encoding.
      Note: There may be exceptions, such as draft messages, in which
      required [RFC5322] header fields are omitted in the message
      literal argument to APPEND.  The full implications of doing so
      must be understood and carefully weighed.
   If a flag parenthesized list is specified, the flags SHOULD be set in
   the resulting message; otherwise, the flag list of the resulting
   message is set to "empty" by default.
   If a date-time is specified, the internal date SHOULD be set in the
   resulting message; otherwise, the internal date of the resulting
   message is set to the current date and time by default.
   If the append is unsuccessful for any reason, the mailbox MUST be
   restored to its state before the APPEND attempt (other than possibly
   keeping the changed mailbox's UIDNEXT value); no partial appending is
   permitted.
   If the destination mailbox does not exist, a server MUST return an
   error and MUST NOT automatically create the mailbox.  Unless it is
   certain that the destination mailbox cannot be created, the server
   MUST send the response code "[TRYCREATE]" as the prefix of the text
   of the tagged NO response.  This gives a hint to the client that it
   can attempt a CREATE command and retry the APPEND if the CREATE is
   successful.
   On successful completion of an APPEND, the server returns an
   APPENDUID response code (see Section 7.1), unless otherwise specified
   below.
   In the case of a mailbox that has permissions set so that the client
   can APPEND to the mailbox, but not SELECT or EXAMINE it, the server
   MUST NOT send an APPENDUID response code as it would disclose
   information about the mailbox.
   In the case of a mailbox that has UIDNOTSTICKY status (see
   Section 7.1), the server MAY omit the APPENDUID response code as it
   is not meaningful.
   If the mailbox is currently selected, normal new message actions
   SHOULD occur.  Specifically, the server SHOULD notify the client
   immediately via an untagged EXISTS response.  If the server does not
   do so, the client MAY issue a NOOP command after one or more APPEND
   commands.
   If the server decides to convert (normalize) the mailbox name, it
   SHOULD return an untagged LIST with an OLDNAME extended data item,
   with the OLDNAME value being the supplied mailbox name and the name
   parameter being the normalized mailbox name.  (See Section 6.3.9.7
   for more details.)
   Example:
     C: A003 APPEND saved-messages (\Seen) {326}
     S: + Ready for literal data
     C: Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST)
     C: From: Fred Foobar <foobar@Blurdybloop.example>
     C: Subject: afternoon meeting
     C: To: mooch@owatagu.siam.edu.example
     C: Message-Id: <B27397-0100000@Blurdybloop.example>
     C: MIME-Version: 1.0
     C: Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
     C:
     C: Hello Joe, do you think we can meet at 3:30 tomorrow?
     C:
     S: A003 OK APPEND completed
   Example:
     C: A003 APPEND saved-messages (\Seen) {297+}
     C: Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST)
     C: From: Fred Foobar <foobar@example.com>
     C: Subject: afternoon meeting
     C: To: mooch@example.com
     C: Message-Id: <B27397-0100000@example.com>
     C: MIME-Version: 1.0
     C: Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
     C:
     C: Hello Joe, do you think we can meet at 3:30 tomorrow?
     C:
     S: A003 OK [APPENDUID 38505 3955] APPEND completed
     C: A004 COPY 2:4 meeting
     S: A004 OK [COPYUID 38505 304,319:320 3956:3958] Done
     C: A005 UID COPY 305:310 meeting
     S: A005 OK No matching messages, so nothing copied
     C: A006 COPY 2 funny
     S: A006 OK Done
     C: A007 SELECT funny
     S: * 1 EXISTS
     S: * OK [UIDVALIDITY 3857529045] Validity session-only
     S: * OK [UIDNEXT 2] Predicted next UID
     S: * NO [UIDNOTSTICKY] Non-persistent UIDs
     S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
     S: * OK [PERMANENTFLAGS (\Deleted \Seen)] Limited
     S: * LIST () "." funny
     S: A007 OK [READ-WRITE] SELECT completed
   In this example, A003 and A004 demonstrate successful appending and
   copying to a mailbox that returns the UIDs assigned to the messages.
   A005 is an example in which no messages were copied; this is because
   in A003, we see that message 2 had UID 304, and message 3 had UID
   319; therefore, UIDs 305 through 310 do not exist (refer to
   Section 2.3.1.1 for further explanation).  A006 is an example of a
   message being copied that did not return a COPYUID; and, as expected,
   A007 shows that the mail store containing that mailbox does not
   support persistent UIDs.
      |  Note: The APPEND command is not used for message delivery,
      |  because it does not provide a mechanism to transfer [SMTP]
      |  envelope information.
6.3.13.  IDLE Command
   Arguments:    none
   Responses:    continuation data will be requested; the client sends
                 the continuation data "DONE" to end the command
   Result:       OK -  IDLE completed after client sent "DONE"
                 NO -  failure: the server will not allow the IDLE
                    command at this time
                 BAD -  command unknown or arguments invalid
   Without the IDLE command, a client would need to poll the server for
   changes to the selected mailbox (new mail, deletions, and flag
   changes).  It's often more desirable to have the server transmit
   updates to the client in real time.  This allows a user to see new
   mail immediately.  The IDLE command allows a client to tell the
   server that it's ready to accept such real-time updates.
   The IDLE command is sent from the client to the server when the
   client is ready to accept unsolicited update messages.  The server
   requests a response to the IDLE command using the continuation ("+")
   response.  The IDLE command remains active until the client responds
   to the continuation, and as long as an IDLE command is active, the
   server is now free to send untagged EXISTS, EXPUNGE, FETCH, and other
   responses at any time.  If the server chooses to send unsolicited
   FETCH responses, they MUST include a UID FETCH item.
   The IDLE command is terminated by the receipt of a "DONE"
   continuation from the client; such response satisfies the server's
   continuation request.  At that point, the server MAY send any
   remaining queued untagged responses and then MUST immediately send
   the tagged response to the IDLE command and prepare to process other
   commands.  As for other commands, the processing of any new command
   may cause the sending of unsolicited untagged responses, subject to
   the ambiguity limitations.  The client MUST NOT send a command while
   the server is waiting for the DONE, since the server will not be able
   to distinguish a command from a continuation.
   The server MAY consider a client inactive if it has an IDLE command
   running, and if such a server has an inactivity timeout, it MAY log
   the client off implicitly at the end of its timeout period.  Because
   of that, clients using IDLE are advised to terminate IDLE and reissue
   it at least every 29 minutes to avoid being logged off.  This still
   allows a client to receive immediate mailbox updates even though it
   need only "poll" at half hour intervals.
   Example:
     C: A001 SELECT INBOX
     S: * FLAGS (\Deleted \Seen \Flagged)
     S: * OK [PERMANENTFLAGS (\Deleted \Seen \Flagged)] Limited
     S: * 3 EXISTS
     S: * OK [UIDVALIDITY 1]
     S: * OK [UIDNEXT 1]
     S: * LIST () "/" INBOX
     S: A001 OK [READ-WRITE] SELECT completed
     C: A002 IDLE
     S: + idling
     ...time passes; new mail arrives...
     S: * 4 EXISTS
     C: DONE
     S: A002 OK IDLE terminated
     ...another client expunges message 2 now...
     C: A003 FETCH 4 ALL
     S: * 4 FETCH (...)
     S: A003 OK FETCH completed
     C: A004 IDLE
     S: * 2 EXPUNGE
     S: * 3 EXISTS
     S: + idling
     ...time passes; another client expunges message 3...
     S: * 3 EXPUNGE
     S: * 2 EXISTS
     ...time passes; new mail arrives...
     S: * 3 EXISTS
     C: DONE
     S: A004 OK IDLE terminated
     C: A005 FETCH 3 ALL
     S: * 3 FETCH (...)
     S: A005 OK FETCH completed
     C: A006 IDLE
6.4.  Client Commands - Selected State
   In the selected state, commands that manipulate messages in a mailbox
   are permitted.
   In addition to the universal commands (CAPABILITY, NOOP, and LOGOUT),
   and the authenticated state commands (SELECT, EXAMINE, NAMESPACE,
   CREATE, DELETE, RENAME, SUBSCRIBE, UNSUBSCRIBE, LIST, STATUS, and
   APPEND), the following commands are valid in the selected state:
   CLOSE, UNSELECT, EXPUNGE, SEARCH, FETCH, STORE, COPY, MOVE, and UID.
6.4.1.  CLOSE Command
   Arguments:    none
   Responses:    no specific responses for this command
   Result:       OK -  close completed, now in authenticated state
                 BAD -  command unknown or arguments invalid
   The CLOSE command permanently removes all messages that have the
   \Deleted flag set from the currently selected mailbox, and it returns
   to the authenticated state from the selected state.  No untagged
   EXPUNGE responses are sent.
   No messages are removed, and no error is given, if the mailbox is
   selected by an EXAMINE command or is otherwise selected as read-only.
   Even if a mailbox is selected, a SELECT, EXAMINE, or LOGOUT command
   MAY be issued without previously issuing a CLOSE command.  The
   SELECT, EXAMINE, and LOGOUT commands implicitly close the currently
   selected mailbox without doing an expunge.  However, when many
   messages are deleted, a CLOSE-LOGOUT or CLOSE-SELECT sequence is
   considerably faster than an EXPUNGE-LOGOUT or EXPUNGE-SELECT because
   no untagged EXPUNGE responses (which the client would probably
   ignore) are sent.
   Example:
     C: A341 CLOSE
     S: A341 OK CLOSE completed
6.4.2.  UNSELECT Command
   Arguments:    none
   Responses:    no specific responses for this command
   Result:       OK -  unselect completed, now in authenticated state
                 BAD -  no mailbox selected, or argument supplied but
                    none permitted
   The UNSELECT command frees a session's resources associated with the
   selected mailbox and returns the server to the authenticated state.
   This command performs the same actions as CLOSE, except that no
   messages are permanently removed from the currently selected mailbox.
   Example:
     C: A342 UNSELECT
     S: A342 OK Unselect completed
6.4.3.  EXPUNGE Command
   Arguments:    none
   Responses:    untagged responses:  EXPUNGE
   Result:       OK -  expunge completed
                 NO -  expunge failure: can't expunge (e.g., permission
                    denied)
                 BAD -  command unknown or arguments invalid
   The EXPUNGE command permanently removes all messages that have the
   \Deleted flag set from the currently selected mailbox.  Before
   returning an OK to the client, an untagged EXPUNGE response is sent
   for each message that is removed.
   Example:
     C: A202 EXPUNGE
     S: * 3 EXPUNGE
     S: * 3 EXPUNGE
     S: * 5 EXPUNGE
     S: * 8 EXPUNGE
     S: A202 OK EXPUNGE completed
   Note: In this example, messages 3, 4, 7, and 11 had the \Deleted flag
   set.  See the description of the EXPUNGE response (Section 7.5.1) for
   further explanation.
6.4.4.  SEARCH Command
   Arguments:    OPTIONAL result specifier
                 OPTIONAL [CHARSET] specification
                 searching criteria (one or more)
   Responses:    OPTIONAL untagged response:  ESEARCH
   Result:       OK -  search completed
                 NO -  search error: can't search that [CHARSET] or
                    criteria
                 BAD -  command unknown or arguments invalid
   The SEARCH command searches the mailbox for messages that match the
   given searching criteria.
   The SEARCH command may contain result options.  Result options
   control what kind of information is returned about messages matching
   the search criteria in an untagged ESEARCH response.  If no result
   option is specified or empty list of options is specified as "()",
   ALL is assumed (see below).  The order of individual options is
   arbitrary.  Individual options may contain parameters enclosed in
   parentheses.  (However, if an option has a mandatory parameter, which
   can always be represented as a number or a sequence-set, the option
   parameter does not need the enclosing parentheses.  See "Formal
   Syntax" (Section 9) for more details.)  If an option has parameters,
   they consist of atoms and/or strings and/or lists in a specific
   order.  Any options not defined by extensions that the server
   supports MUST be rejected with a BAD response.
   Note that IMAP4rev1 used SEARCH responses [RFC3501] instead of
   ESEARCH responses.  Clients that support only IMAP4rev2 MUST ignore
   SEARCH responses.
   This document specifies the following result options:
   MIN
      Return the lowest message number/UID that satisfies the SEARCH
      criteria.
      If the SEARCH results in no matches, the server MUST NOT include
      the MIN result option in the ESEARCH response; however, it still
      MUST send the ESEARCH response.
   MAX
      Return the highest message number/UID that satisfies the SEARCH
      criteria.
      If the SEARCH results in no matches, the server MUST NOT include
      the MAX result option in the ESEARCH response; however, it still
      MUST send the ESEARCH response.
   ALL
      Return all message numbers/UIDs that satisfy the SEARCH criteria
      using the sequence-set syntax.  Note that the client MUST NOT
      assume that messages/UIDs will be listed in any particular order.
      If the SEARCH results in no matches, the server MUST NOT include
      the ALL result option in the ESEARCH response; however, it still
      MUST send the ESEARCH response.
   COUNT
      Return the number of messages that satisfy the SEARCH criteria.
      This result option MUST always be included in the ESEARCH
      response.
   SAVE
      This option tells the server to remember the result of the SEARCH
      or UID SEARCH command (as well as any command based on SEARCH,
      e.g., SORT and THREAD [RFC5256]) and store it in an internal
      variable that we will reference as the "search result variable".
      The client can use the "$" marker to reference the content of this
      internal variable.  The "$" marker can be used instead of message
      sequence or UID sequence in order to indicate that the server
      should substitute it with the list of messages from the search
      result variable.  Thus, the client can use the result of the
      latest remembered SEARCH command as a parameter to another
      command.  See Section 6.4.4.1 for details on how the value of the
      search result variable is determined, how it is affected by other
      commands executed, and how the SAVE return option interacts with
      other return options.
      In absence of any other SEARCH result option, the SAVE result
      option also suppresses any ESEARCH response that would have been
      otherwise returned by the SEARCH command.
   Note: future extensions to this document can allow servers to return
   multiple ESEARCH responses for a single extended SEARCH command.
   However, all options specified above MUST result in a single ESEARCH
   response if used by themselves or in combination.  This guarantee
   simplifies processing in IMAP4rev2 clients.  Future SEARCH extensions
   that relax this restriction will have to describe how results from
   multiple ESEARCH responses are to be combined.
   Searching criteria consist of one or more search keys.
   When multiple keys are specified, the result is the intersection (AND
   function) of all the messages that match those keys.  For example,
   the criteria DELETED FROM "SMITH" SINCE 1-Feb-1994 refers to all
   deleted messages from Smith with INTERNALDATE greater than February
   1, 1994.  A search key can also be a parenthesized list of one or
   more search keys (e.g., for use with the OR and NOT keys).
   Server implementations MAY exclude [MIME-IMB] body parts with
   terminal content media types other than TEXT and MESSAGE from
   consideration in SEARCH matching.
   The OPTIONAL [CHARSET] specification consists of the word "CHARSET"
   followed by the name of a character set from the registry
   [CHARSET-REG].  It indicates the [CHARSET] of the strings that appear
   in the search criteria.  [MIME-IMB] content transfer encodings and
   [MIME-HDRS] strings in [RFC5322]/[MIME-IMB] headers MUST be decoded
   before comparing text.  Servers MUST support US-ASCII and UTF-8
   charsets; other CHARSETs MAY be supported.  Clients SHOULD use UTF-8.
   Note that if CHARSET is not provided, IMAP4rev2 servers MUST assume
   UTF-8, so selecting CHARSET UTF-8 is redundant.  It is permitted for
   improved compatibility with existing IMAP4rev1 clients.
   If the server does not support the specified [CHARSET], it MUST
   return a tagged NO response (not a BAD).  This response SHOULD
   contain the BADCHARSET response code, which MAY list the CHARSETs
   supported by the server.
   In all search keys that use strings, and unless otherwise specified,
   a message matches the key if the string is a substring of the
   associated text.  The matching SHOULD be case insensitive for
   characters within the ASCII range.  Consider using [IMAP-I18N] for
   language-sensitive, case-insensitive searching.  Note that the empty
   string is a substring; this is useful when performing a HEADER search
   in order to test for a header field presence in the message.
   The defined search keys are as follows.  Refer to "Formal Syntax"
   (Section 9) for the precise syntactic definitions of the arguments.
   <sequence set>
      Messages with message sequence numbers corresponding to the
      specified message sequence number set.
   ALL
      All messages in the mailbox; the default initial key for ANDing.
   ANSWERED
      Messages with the \Answered flag set.
   BCC <string>
      Messages that contain the specified string in the envelope
      structure's Blind Carbon Copy (BCC) field.
   BEFORE <date>
      Messages whose internal date (disregarding time and timezone) is
      earlier than the specified date.
   BODY <string>
      Messages that contain the specified string in the body of the
      message.  Unlike TEXT (see below), this doesn't match any header
      fields.  Servers are allowed to implement flexible matching for
      this search key, for example, by matching "swim" to both "swam"
      and "swum" in English language text or only performing full word
      matching (where "swim" will not match "swimming").
   CC <string>
      Messages that contain the specified string in the envelope
      structure's CC field.
   DELETED
      Messages with the \Deleted flag set.
   DRAFT
      Messages with the \Draft flag set.
   FLAGGED
      Messages with the \Flagged flag set.
   FROM <string>
      Messages that contain the specified string in the envelope
      structure's FROM field.
   HEADER <field-name> <string>
      Messages that have a header field with the specified field-name
      (as defined in [RFC5322]) and that contain the specified string in
      the text of the header field (what comes after the colon).  If the
      string to search is zero-length, this matches all messages that
      have a header field with the specified field-name regardless of
      the contents.  Servers should use a substring search for this
      SEARCH item, as clients can use it for automatic processing not
      initiated by end users.  For example, this can be used when
      searching for Message-ID or Content-Type header field values that
      need to be exact or for searches in header fields that the IMAP
      server might not know anything about.
   KEYWORD <flag>
      Messages with the specified keyword flag set.
   LARGER <n>
      Messages with an RFC822.SIZE larger than the specified number of
      octets.
   NOT <search-key>
      Messages that do not match the specified search key.
   ON <date>
      Messages whose internal date (disregarding time and timezone) is
      within the specified date.
   OR <search-key1> <search-key2>
      Messages that match either search key.
   SEEN
      Messages that have the \Seen flag set.
   SENTBEFORE <date>
      Messages whose [RFC5322] Date: header field (disregarding time and
      timezone) is earlier than the specified date.
   SENTON <date>
      Messages whose [RFC5322] Date: header field (disregarding time and
      timezone) is within the specified date.
   SENTSINCE <date>
      Messages whose [RFC5322] Date: header field (disregarding time and
      timezone) is within or later than the specified date.
   SINCE <date>
      Messages whose internal date (disregarding time and timezone) is
      within or later than the specified date.
   SMALLER <n>
      Messages with an RFC822.SIZE smaller than the specified number of
      octets.
   SUBJECT <string>
      Messages that contain the specified string in the envelope
      structure's SUBJECT field.
   TEXT <string>
      Messages that contain the specified string in the header
      (including MIME header fields) or body of the message.  Servers
      are allowed to implement flexible matching for this search key,
      for example, matching "swim" to both "swam" and "swum" in English
      language text or only performing full-word matching (where "swim"
      will not match "swimming").
   TO <string>
      Messages that contain the specified string in the envelope
      structure's TO field.
   UID <sequence set>
      Messages with unique identifiers corresponding to the specified
      unique identifier set.  Sequence-set ranges are permitted.
   UNANSWERED
      Messages that do not have the \Answered flag set.
   UNDELETED
      Messages that do not have the \Deleted flag set.
   UNDRAFT
      Messages that do not have the \Draft flag set.
   UNFLAGGED
      Messages that do not have the \Flagged flag set.
   UNKEYWORD <flag>
      Messages that do not have the specified keyword flag set.
   UNSEEN
      Messages that do not have the \Seen flag set.
   Example:
     C: A282 SEARCH RETURN (MIN COUNT) FLAGGED
         SINCE 1-Feb-1994 NOT FROM "Smith"
     S: * ESEARCH (TAG "A282") MIN 2 COUNT 3
     S: A282 OK SEARCH completed
   Example:
     C: A283 SEARCH RETURN () FLAGGED
         SINCE 1-Feb-1994 NOT FROM "Smith"
     S: * ESEARCH (TAG "A283") ALL 2,10:11
     S: A283 OK SEARCH completed
   Example:
     C: A284 SEARCH TEXT "string not in mailbox"
     S: * ESEARCH (TAG "A284")
     S: A284 OK SEARCH completed
     C: A285 SEARCH CHARSET UTF-8 TEXT {12}
     S: + Ready for literal text
     C: отпуск
     S: * ESEARCH (TAG "A285") ALL 43
     S: A285 OK SEARCH completed
   The following example demonstrates finding the first unseen message
   in the mailbox:
   Example:
     C: A284 SEARCH RETURN (MIN) UNSEEN
     S: * ESEARCH (TAG "A284") MIN 4
     S: A284 OK SEARCH completed
   The following example demonstrates that if the ESEARCH UID indicator
   is present, all data in the ESEARCH response is referring to UIDs;
   for example, the MIN result specifier will be followed by a UID.
   Example:
     C: A285 UID SEARCH RETURN (MIN MAX) 1:5000
     S: * ESEARCH (TAG "A285") UID MIN 7 MAX 3800
     S: A285 OK SEARCH completed
   The following example demonstrates returning the number of deleted
   messages:
   Example:
     C: A286 SEARCH RETURN (COUNT) DELETED
     S: * ESEARCH (TAG "A286") COUNT 15
     S: A286 OK SEARCH completed
6.4.4.1.  SAVE Result Option and SEARCH Result Variable
   Upon successful completion of a SELECT or an EXAMINE command (after
   the tagged OK response), the current search result variable is reset
   to the empty sequence.
   A successful SEARCH command with the SAVE result option sets the
   value of the search result variable to the list of messages found in
   the SEARCH command.  For example, if no messages were found, the
   search result variable will contain the empty sequence.
   Any of the following SEARCH commands MUST NOT change the search
   result variable:
      a SEARCH command that caused the server to return the BAD tagged
      response,
      a SEARCH command with no SAVE result option that caused the server
      to return NO tagged response, and
      a successful SEARCH command with no SAVE result option.
   A SEARCH command with the SAVE result option that caused the server
   to return the NO tagged response sets the value of the search result
   variable to the empty sequence.
   When a message listed in the search result variable is EXPUNGEd, it
   is automatically removed from the list.  Implementors are reminded
   that if the server stores the list as a list of message numbers, it
   MUST automatically adjust them when notifying the client about
   expunged messages, as described in Section 7.5.1.
   If the server decides to send a new UIDVALIDITY value while the
   mailbox is opened, it causes the resetting of the search variable to
   the empty sequence.
   Note that even if the "$" marker contains the empty sequence of
   messages, it must be treated by all commands accepting message sets
   as parameters as a valid, but non-matching, list of messages.  For
   example, the "FETCH $" command would return a tagged OK response and
   no FETCH responses.  See also Example 5 in Section 6.4.4.4.
   The SAVE result option doesn't change whether the server would return
   items corresponding to MIN, MAX, ALL, or COUNT result options.
   When the SAVE result option is combined with the MIN or MAX result
   option, and both ALL and COUNT result options are absent, the
   corresponding MIN/MAX is returned (if the search result is not
   empty), but the "$" marker would contain a single message as returned
   in the MIN/MAX return item.
   If the SAVE result option is combined with both MIN and MAX result
   options, and both ALL and COUNT result options are absent, the "$"
   marker would contain zero messages, one message, or two messages as
   returned in the MIN/MAX return items.
   If the SAVE result option is combined with the ALL and/or COUNT
   result option(s), the "$" marker would always contain all messages
   found by the SEARCH or UID SEARCH command.
   The following table summarizes the additional requirement on ESEARCH
   server implementations described in this section.
           +==============================+====================+
           | Combination of Result Option |  "$" Marker Value  |
           +==============================+====================+
           |           SAVE MIN           |        MIN         |
           +------------------------------+--------------------+
           |           SAVE MAX           |        MAX         |
           +------------------------------+--------------------+
           |         SAVE MIN MAX         |     MIN & MAX      |
           +------------------------------+--------------------+
           |          SAVE * [m]          | all found messages |
           +------------------------------+--------------------+
                                  Table 4
   where '*' means "ALL" and/or "COUNT", and '[m]' means optional "MIN"
   and/or "MAX"
   Implementation note: server implementors should note that "$" can
   reference IMAP message sequences or UID sequences, depending on the
   context where it is used.  For example, the "$" marker can be set as
   a result of a SEARCH (SAVE) command and used as a parameter to a UID
   FETCH command (which accepts a UID sequence, not a message sequence),
   or the "$" marker can be set as a result of a UID SEARCH (SAVE)
   command and used as a parameter to a FETCH command (which accepts a
   message sequence, not a UID sequence).  Server implementations need
   to automatically map the "$" marker value to message numbers or UIDs,
   depending on the context where the "$" marker is used.
6.4.4.2.  Multiple Commands in Progress
   Use of a SEARCH RETURN (SAVE) command followed by a command using the
   "$" marker creates direct dependency between the two commands.  As
   directed by Section 5.5, a server MUST execute the two commands in
   the order they were received.
   A client MAY pipeline a SEARCH RETURN (SAVE) command with one or more
   commands using the "$" marker, as long as this doesn't create an
   ambiguity, as described in Section 5.5.  Examples 7-9 in
   Section 6.4.4.4 explain this in more details.
6.4.4.3.  Refusing to Save Search Results
   In some cases, the server MAY refuse to save a SEARCH (SAVE) result,
   for example, if an internal limit on the number of saved results is
   reached.  In this case, the server MUST return a tagged NO response
   containing the NOTSAVED response code and set the search result
   variable to the empty sequence, as described in Section 6.4.4.1.
6.4.4.4.  Examples Showing Use of the SAVE Result Option
   Only in this section: explanatory comments in examples that start
   with // are not part of the protocol.
   1.  The following example demonstrates how the client can use the
       result of a SEARCH command to FETCH headers of interesting
       messages:
       Example 1:
        C: A282 SEARCH RETURN (SAVE) FLAGGED SINCE 1-Feb-1994
            NOT FROM "Smith"
        S: A282 OK SEARCH completed, result saved
        C: A283 FETCH $ (UID INTERNALDATE FLAGS BODY.PEEK[HEADER])
        S: * 2 FETCH (UID 14 ...
        S: * 84 FETCH (UID 100 ...
        S: * 882 FETCH (UID 1115 ...
        S: A283 OK completed
       The client can also pipeline the two commands:
       Example 2:
        C: A282 SEARCH RETURN (SAVE) FLAGGED SINCE 1-Feb-1994
            NOT FROM "Smith"
        C: A283 FETCH $ (UID INTERNALDATE FLAGS BODY.PEEK[HEADER])
        S: A282 OK SEARCH completed
        S: * 2 FETCH (UID 14 ...
        S: * 84 FETCH (UID 100 ...
        S: * 882 FETCH (UID 1115 ...
        S: A283 OK completed
   2.  The following example demonstrates that the result of one SEARCH
       command can be used as input to another SEARCH command:
       Example 3:
        C: A300 SEARCH RETURN (SAVE) SINCE 1-Jan-2004
            NOT FROM "Smith"
        S: A300 OK SEARCH completed
        C: A301 UID SEARCH UID $ SMALLER 4096
        S: * ESEARCH (TAG "A301") UID ALL 17,900,901
        S: A301 OK completed
       Note that the second command in Example 3 can be replaced with:
        C: A301 UID SEARCH $ SMALLER 4096
       and the result of the command would be the same.
   3.  The following example shows that the "$" marker can be combined
       with other message numbers using the OR SEARCH criterion.
       Example 4:
        C: P282 SEARCH RETURN (SAVE) SINCE 1-Feb-1994
            NOT FROM "Smith"
        S: P282 OK SEARCH completed
        C: P283 SEARCH CHARSET UTF-8 (OR $ 1,3000:3021) TEXT {8+}
        C: мать
        S: * ESEARCH (TAG "P283") ALL 882,1102,3003,3005:3006
        S: P283 OK completed
   4.  The following example demonstrates that a failed SEARCH sets the
       search result variable to the empty list.  The server doesn't
       implement the KOI8-R charset.
       Example 5:
        C: B282 SEARCH RETURN (SAVE) SINCE 1-Feb-1994
            NOT FROM "Smith"
        S: B282 OK SEARCH completed
        C: B283 SEARCH RETURN (SAVE) CHARSET KOI8-R
            (OR $ 1,3000:3021) TEXT {4}
        C: XXXX
        S: B283 NO [BADCHARSET UTF-8] KOI8-R is not supported
       //After this command, the saved result variable contains
       //no messages.  A client that wants to reissue the B283
       //SEARCH command with another CHARSET would have to reissue
       //the B282 command as well.  One possible workaround for
       //this is to include the desired CHARSET parameter
       //in the earliest SEARCH RETURN (SAVE) command in a
       //sequence of related SEARCH commands, to cause
       //the earliest SEARCH in the sequence to fail.
       //A better approach might be to always use CHARSET UTF-8
       //instead.
       Note: Since this document format is restricted to 7-bit ASCII
       text, it is not possible to show actual KOI8-R data.  The "XXXX"
       is a placeholder for what would be 4 octets of 8-bit data in an
       actual transaction.
   5.  The following example demonstrates that it is not an error to use
       the "$" marker when it contains no messages.
       Example 6:
        C: E282 SEARCH RETURN (SAVE) SINCE 28-Oct-2006
            NOT FROM "Eric"
        C: E283 COPY $ "Other Messages"
       //The "$" contains no messages
        S: E282 OK SEARCH completed
        S: E283 OK COPY completed, nothing copied
       Example 7:
        C: F282 SEARCH RETURN (SAVE) KEYWORD $Junk
        C: F283 COPY $ "Junk"
        C: F284 STORE $ +FLAGS.Silent (\Deleted)
        S: F282 OK SEARCH completed
        S: F283 OK COPY completed
        S: F284 OK STORE completed
       Example 8:
        C: G282 SEARCH RETURN (SAVE) KEYWORD $Junk
        C: G283 SEARCH RETURN (ALL) SINCE 28-Oct-2006
            FROM "Eric"
       // The server can execute the two SEARCH commands
       // in any order, as they don't have any dependency.
       // For example, it may return:
        S: * ESEARCH (TAG "G283") ALL 3:15,27,29:103
        S: G283 OK SEARCH completed
        S: G282 OK SEARCH completed
       The following example demonstrates that the result of the second
       SEARCH RETURN (SAVE) always overrides the result of the first.
       Example 9:
        C: H282 SEARCH RETURN (SAVE) KEYWORD $Junk
        C: H283 SEARCH RETURN (SAVE) SINCE 28-Oct-2006
            FROM "Eric"
        S: H282 OK SEARCH completed
        S: H283 OK SEARCH completed
       // At this point "$" would contain results of H283
       The following example demonstrates behavioral difference for
       different combinations of ESEARCH result options.
       Example 10:
        C: C282 SEARCH RETURN (ALL) SINCE 12-Feb-2006
            NOT FROM "Smith"
        S: * ESEARCH (TAG "C283") ALL 2,10:15,21
      //$ value hasn't changed
        S: C282 OK SEARCH completed
        C: C283 SEARCH RETURN (ALL SAVE) SINCE 12-Feb-2006
            NOT FROM "Smith"
        S: * ESEARCH (TAG "C283") ALL 2,10:15,21
      //$ value is 2,10:15,21
        S: C283 OK SEARCH completed
        C: C284 SEARCH RETURN (SAVE MIN) SINCE 12-Feb-2006
            NOT FROM "Smith"
        S: * ESEARCH (TAG "C284") MIN 2
      //$ value is 2
        S: C284 OK SEARCH completed
        C: C285 SEARCH RETURN (MAX SAVE MIN) SINCE
            12-Feb-2006 NOT FROM "Smith"
        S: * ESEARCH (TAG "C285") MIN 2 MAX 21
      //$ value is 2,21
        S: C285 OK SEARCH completed
        C: C286 SEARCH RETURN (MAX SAVE MIN COUNT)
            SINCE 12-Feb-2006 NOT FROM "Smith"
        S: * ESEARCH (TAG "C286") MIN 2 MAX 21 COUNT 8
      //$ value is 2,10:15,21
        S: C286 OK SEARCH completed
        C: C286 SEARCH RETURN (ALL SAVE MIN) SINCE
            12-Feb-2006 NOT FROM "Smith"
        S: * ESEARCH (TAG "C286") MIN 2 ALL 2,10:15,21
      //$ value is 2,10:15,21
        S: C286 OK SEARCH completed
6.4.5.  FETCH Command
   Arguments:    sequence set
                 message data item names or macro
   Responses:    untagged responses:  FETCH
   Result:       OK -  fetch completed
                 NO -  fetch error: can't fetch that data
                 BAD -  command unknown or arguments invalid
   The FETCH command retrieves data associated with a message in the
   mailbox.  The data items to be fetched can be either a single atom or
   a parenthesized list.
   Most data items, identified in the formal syntax (Section 9) under
   the msg-att-static rule, are static and MUST NOT change for any
   particular message.  Other data items, identified in the formal
   syntax under the msg-att-dynamic rule, MAY change either as a result
   of a STORE command or due to external events.
      For example, if a client receives an ENVELOPE for a message when
      it already knows the envelope, it can safely ignore the newly
      transmitted envelope.
   There are three macros that specify commonly used sets of data items
   and can be used instead of data items.  A macro must be used by
   itself and not in conjunction with other macros or data items.
   ALL
      Macro equivalent to: (FLAGS INTERNALDATE RFC822.SIZE ENVELOPE)
   FAST
      Macro equivalent to: (FLAGS INTERNALDATE RFC822.SIZE)
   FULL
      Macro equivalent to: (FLAGS INTERNALDATE RFC822.SIZE ENVELOPE
      BODY)
   Several data items reference "section" or "section-binary".  See
   Section 6.4.5.1 for their detailed definition.
   The currently defined data items that can be fetched are:
   BINARY[<section-binary>]<<partial>>
      Requests that the specified section be transmitted after
      performing decoding of the section's Content-Transfer-Encoding.
      The <partial> argument, if present, requests that a subset of the
      data be returned.  The semantics of a partial FETCH BINARY command
      are the same as for a partial FETCH BODY command, with the
      exception that the <partial> arguments refer to the DECODED
      section data.
      Note that this data item can only be requested for leaf body
      parts: those that have media types other than multipart/*,
      message/rfc822, or message/global.
   BINARY.PEEK[<section-binary>]<<partial>>
      An alternate form of BINARY[<section-binary>] that does not
      implicitly set the \Seen flag.
   BINARY.SIZE[<section-binary>]
      Requests the decoded size of the section (i.e., the size to expect
      in response to the corresponding FETCH BINARY request).
      Note: client authors are cautioned that this might be an expensive
      operation for some server implementations.  Needlessly issuing
      this request could result in degraded performance due to servers
      having to calculate the value every time the request is issued.
      Note that this data item can only be requested for leaf body
      parts: those that have media types other than multipart/*,
      message/rfc822, or message/global.
   BODY
      Non-extensible form of BODYSTRUCTURE.
   BODY[<section>]<<partial>>
      The text of a particular body section.  If BODY[] is specified
      (the section specification is omitted), the FETCH is requesting
      the [RFC5322] expression of the entire message.
      It is possible to fetch a substring of the designated text.  This
      is done by appending an open angle bracket ("<"), the octet
      position of the first desired octet, a period, the maximum number
      of octets desired, and a close angle bracket (">") to the part
      specifier.  If the starting octet is beyond the end of the text,
      an empty string is returned.
      Any partial fetch that attempts to read beyond the end of the text
      is truncated as appropriate.  A partial fetch that starts at octet
      0 is returned as a partial fetch, even if this truncation
      happened.
         Note: This means that BODY[]<0.2048> of a 1500-octet message
         will return BODY[]<0> with a literal of size 1500, not BODY[].
         Note: A substring fetch of a HEADER.FIELDS or HEADER.FIELDS.NOT
         part specifier is calculated after subsetting the header.
      The \Seen flag is implicitly set; if this causes the flags to
      change, they SHOULD be included as part of the FETCH responses.
   BODY.PEEK[<section>]<<partial>>
      An alternate form of BODY[<section>] that does not implicitly set
      the \Seen flag.
   BODYSTRUCTURE
      The [MIME-IMB] body structure of the message.  This is computed by
      the server by parsing the [MIME-IMB] header fields in the
      [RFC5322] header and [MIME-IMB] headers.  See Section 7.5.2 for
      more details.
   ENVELOPE
      The envelope structure of the message.  This is computed by the
      server by parsing the [RFC5322] header into the component parts,
      defaulting various fields as necessary.  See Section 7.5.2 for
      more details.
   FLAGS
      The flags that are set for this message.
   INTERNALDATE
      The internal date of the message.
   RFC822.SIZE
      The size of the message, as defined in Section 2.3.4.
   UID
      The unique identifier for the message.
   Example:
     C: A654 FETCH 2:4 (FLAGS BODY[HEADER.FIELDS (DATE FROM)])
     S: * 2 FETCH ....
     S: * 3 FETCH ....
     S: * 4 FETCH ....
     S: A654 OK FETCH completed
6.4.5.1.  FETCH Section Specification
   Several FETCH data items reference "section" or "section-binary".
   The section specification is a set of zero or more part specifiers
   delimited by periods.  A part specifier is either a part number or
   one of the following: HEADER, HEADER.FIELDS, HEADER.FIELDS.NOT, MIME,
   and TEXT.  (Non-numeric part specifiers have to be the last specifier
   in a section specification.)  An empty section specification refers
   to the entire message, including the header.
   Every message has at least one part number.  Messages that do not use
   MIME, and MIME messages that are not multipart and have no
   encapsulated message within them, only have a part 1.
   Multipart messages are assigned consecutive part numbers, as they
   occur in the message.  If a particular part is of type message or
   multipart, its parts MUST be indicated by a period followed by the
   part number within that nested multipart part.
   A part of type MESSAGE/RFC822 or MESSAGE/GLOBAL also has nested part
   numbers, referring to parts of the MESSAGE part's body.
   The HEADER, HEADER.FIELDS, HEADER.FIELDS.NOT, and TEXT part
   specifiers can be the sole part specifier or can be prefixed by one
   or more numeric part specifiers, provided that the numeric part
   specifier refers to a part of type MESSAGE/RFC822 or MESSAGE/GLOBAL.
   The MIME part specifier MUST be prefixed by one or more numeric part
   specifiers.
   The HEADER, HEADER.FIELDS, and HEADER.FIELDS.NOT part specifiers
   refer to the [RFC5322] header of the message or of an encapsulated
   [MIME-IMT] MESSAGE/RFC822 or MESSAGE/GLOBAL message.  HEADER.FIELDS
   and HEADER.FIELDS.NOT are followed by a list of field-names (as
   defined in [RFC5322]) and return a subset of the header.  The subset
   returned by HEADER.FIELDS contains only those header fields with a
   field-name that matches one of the names in the list; similarly, the
   subset returned by HEADER.FIELDS.NOT contains only the header fields
   with a non-matching field-name.  The field-matching is ASCII-range
   case insensitive but is otherwise exact.  Subsetting does not exclude
   the [RFC5322] delimiting blank line between the header and the body;
   the blank line is included in all header fetches, except in the case
   of a message that has no body and no blank line.
   The MIME part specifier refers to the [MIME-IMB] header for this
   part.
   The TEXT part specifier refers to the text body of the message,
   omitting the [RFC5322] header.
   Here is an example of a complex message with some of its part
   specifiers:
     HEADER     ([RFC5322] header of the message)
     TEXT       ([RFC5322] text body of the message) MULTIPART/MIXED
     1          TEXT/PLAIN
     2          APPLICATION/OCTET-STREAM
     3          MESSAGE/RFC822
     3.HEADER   ([RFC5322] header of the message)
     3.TEXT     ([RFC5322] text body of the message) MULTIPART/MIXED
     3.1        TEXT/PLAIN
     3.2        APPLICATION/OCTET-STREAM
     4          MULTIPART/MIXED
     4.1        IMAGE/GIF
     4.1.MIME   ([MIME-IMB] header for the IMAGE/GIF)
     4.2        MESSAGE/RFC822
     4.2.HEADER ([RFC5322] header of the message)
     4.2.TEXT   ([RFC5322] text body of the message) MULTIPART/MIXED
     4.2.1      TEXT/PLAIN
     4.2.2      MULTIPART/ALTERNATIVE
     4.2.2.1    TEXT/PLAIN
     4.2.2.2    TEXT/RICHTEXT
6.4.6.  STORE Command
   Arguments:    sequence set
                 message data item name
                 value for message data item
   Responses:    untagged responses:  FETCH
   Result:       OK -  store completed
                 NO -  store error: can't store that data
                 BAD -  command unknown or arguments invalid
   The STORE command alters data associated with a message in the
   mailbox.  Normally, STORE will return the updated value of the data
   with an untagged FETCH response.  A suffix of ".SILENT" in the data
   item name prevents the untagged FETCH, and the server SHOULD assume
   that the client has determined the updated value itself or does not
   care about the updated value.
      Note: Regardless of whether or not the ".SILENT" suffix was used,
      the server SHOULD send an untagged FETCH response if a change to a
      message's flags from an external source is observed.  The intent
      is that the status of the flags is determinate without a race
      condition.
   The currently defined data items that can be stored are:
   FLAGS <flag list>
      Replace the flags for the message with the argument.  The new
      value of the flags is returned as if a FETCH of those flags was
      done.
   FLAGS.SILENT <flag list>
      Equivalent to FLAGS, but without returning a new value.
   +FLAGS <flag list>
      Add the argument to the flags for the message.  The new value of
      the flags is returned as if a FETCH of those flags was done.
   +FLAGS.SILENT <flag list>
      Equivalent to +FLAGS, but without returning a new value.
   -FLAGS <flag list>
      Remove the argument from the flags for the message.  The new value
      of the flags is returned as if a FETCH of those flags was done.
   -FLAGS.SILENT <flag list>
      Equivalent to -FLAGS, but without returning a new value.
   Example:
     C: A003 STORE 2:4 +FLAGS (\Deleted)
     S: * 2 FETCH (FLAGS (\Deleted \Seen))
     S: * 3 FETCH (FLAGS (\Deleted))
     S: * 4 FETCH (FLAGS (\Deleted \Flagged \Seen))
     S: A003 OK STORE completed
6.4.7.  COPY Command
   Arguments:    sequence set
                 mailbox name
   Responses:    no specific responses for this command
   Result:       OK -  copy completed
                 NO -  copy error: can't copy those messages or to that
                    name
                 BAD -  command unknown or arguments invalid
   The COPY command copies the specified message(s) to the end of the
   specified destination mailbox.  The flags and internal date of the
   message(s) SHOULD be preserved in the copy.
   If the destination mailbox does not exist, a server MUST return an
   error.  It MUST NOT automatically create the mailbox.  Unless it is
   certain that the destination mailbox can not be created, the server
   MUST send the response code "[TRYCREATE]" as the prefix of the text
   of the tagged NO response.  This gives a hint to the client that it
   can attempt a CREATE command and retry the COPY if the CREATE is
   successful.
   If the COPY command is unsuccessful for any reason, server
   implementations MUST restore the destination mailbox to its state
   before the COPY attempt (other than possibly incrementing UIDNEXT),
   i.e., partial copy MUST NOT be done.
   On successful completion of a COPY, the server returns a COPYUID
   response code (see Section 7.1).  Two exceptions to this requirement
   are listed below.
   In the case of a mailbox that has permissions set so that the client
   can COPY to the mailbox, but not SELECT or EXAMINE it, the server
   MUST NOT send a COPYUID response code as it would disclose
   information about the mailbox.
   In the case of a mailbox that has UIDNOTSTICKY status (see
   Section 7.1), the server MAY omit the COPYUID response code as it is
   not meaningful.
   Example:
     C: A003 COPY 2:4 MEETING
     S: A003 OK [COPYUID 38505 304,319:320 3956:3958] COPY completed
6.4.8.  MOVE Command
   Arguments:    sequence set
                 mailbox name
   Responses:    no specific responses for this command
   Result:       OK -  move completed
                 NO -  move error: can't move those messages or to that
                    name
                 BAD -  command unknown or arguments invalid
   The MOVE command moves the specified message(s) to the end of the
   specified destination mailbox.  The flags and internal date of the
   message(s) SHOULD be preserved.
   This means that a new message is created in the target mailbox with a
   new UID, the original message is removed from the source mailbox, and
   it appears to the client as a single action.  This has the same
   effect for each message as this sequence:
   1.  [UID] COPY
   2.  [UID] STORE +FLAGS.SILENT \DELETED
   3.  UID EXPUNGE
   Although the effect of the MOVE is the same as the preceding steps,
   the semantics are not identical: the intermediate states produced by
   those steps do not occur, and the response codes are different.  In
   particular, though the COPY and EXPUNGE response codes will be
   returned, response codes for a STORE MUST NOT be generated, and the
   \Deleted flag MUST NOT be set for any message.
   Unlike the COPY command, MOVE of a set of messages might fail partway
   through the set.  Regardless of whether the command is successful in
   moving the entire set, each individual message MUST be either moved
   or unaffected.  The server MUST leave each message in a state where
   it is in at least one of the source or target mailboxes (no message
   can be lost or orphaned).  The server SHOULD NOT leave any message in
   both mailboxes (it would be bad for a partial failure to result in a
   bunch of duplicate messages).  This is true even if the server
   returns a tagged NO response to the command.
   If the destination mailbox does not exist, a server MUST return an
   error.  It MUST NOT automatically create the mailbox.  Unless it is
   certain that the destination mailbox cannot be created, the server
   MUST send the response code "[TRYCREATE]" as the prefix of the text
   of the tagged NO response.  This gives a hint to the client that it
   can attempt a CREATE command and retry the MOVE if the CREATE is
   successful.
   Because of the similarity of MOVE to COPY, extensions that affect
   COPY affect MOVE in the same way.  Response codes listed in
   Section 7.1, as well as those defined by extensions, are sent as
   indicated for COPY.
   Servers send COPYUID in response to a MOVE or a UID MOVE (see
   Section 6.4.9) command.  For additional information about COPYUID,
   see Section 7.1.  Note that there are several exceptions listed in
   Section 6.4.7 that allow servers not to return COPYUID.
   Servers are also REQUIRED to send the COPYUID response code in an
   untagged OK before sending EXPUNGE or similar responses.  (Sending
   COPYUID in the tagged OK, as described in Section 6.4.7, means that
   clients first receive an EXPUNGE for a message and afterwards COPYUID
   for the same message.  It can be unnecessarily difficult to process
   that sequence usefully.)
   An example:
     C: a UID MOVE 42:69 foo
     S: * OK [COPYUID 432432 42:69 1202:1229]
     S: * 22 EXPUNGE
     ...More EXPUNGE responses from the server...
     S: a OK Done
   Note that the server may send unrelated EXPUNGE responses as well, if
   any happen to have been expunged at the same time; this is normal
   IMAP operation.
   Note that moving a message to the currently selected mailbox (that
   is, where the source and target mailboxes are the same) is allowed
   when copying the message to the currently selected mailbox is
   allowed.
   The server may send EXPUNGE responses before the tagged response, so
   the client cannot safely send more commands with message sequence
   number arguments while the server is processing MOVE.
   MOVE and UID MOVE can be pipelined with other commands, but care has
   to be taken.  Both commands modify sequence numbers and also allow
   unrelated EXPUNGE responses.  The renumbering of other messages in
   the source mailbox following any EXPUNGE response can be surprising
   and makes it unsafe to pipeline any command that relies on message
   sequence numbers after a MOVE or UID MOVE.  Similarly, MOVE cannot be
   pipelined with a command that might cause message renumbering.  See
   Section 5.5 for more information about ambiguities as well as
   handling requirements for both clients and servers.
6.4.9.  UID Command
   Arguments:    command name
                 command arguments
   Responses:    untagged responses:  FETCH, ESEARCH, EXPUNGE
   Result:       OK -  UID command completed
                 NO -  UID command error
                 BAD -  command unknown or arguments invalid
   The UID command has three forms.  In the first form, it takes as its
   arguments a COPY, MOVE, FETCH, or STORE command with arguments
   appropriate for the associated command.  However, the numbers in the
   sequence-set argument are unique identifiers instead of message
   sequence numbers.  Sequence-set ranges are permitted, but there is no
   guarantee that unique identifiers will be contiguous.
   A non-existent unique identifier is ignored without any error message
   generated.  Thus, it is possible for a UID FETCH command to return an
   OK without any data or a UID COPY, UID MOVE, or UID STORE to return
   an OK without performing any operations.
   In the second form, the UID command takes an EXPUNGE command with an
   extra parameter that specifies a sequence set of UIDs to operate on.
   The UID EXPUNGE command permanently removes all messages that have
   both the \Deleted flag set and a UID that is included in the
   specified sequence set from the currently selected mailbox.  If a
   message either does not have the \Deleted flag set or has a UID that
   is not included in the specified sequence set, it is not affected.
   UID EXPUNGE is particularly useful for disconnected use clients.  By
   using UID EXPUNGE instead of EXPUNGE when resynchronizing with the
   server, the client can ensure that it does not inadvertently remove
   any messages that have been marked as \Deleted by other clients
   between the time that the client was last connected and the time the
   client resynchronizes.
   Example:
     C: A003 UID EXPUNGE 3000:3002
     S: * 3 EXPUNGE
     S: * 3 EXPUNGE
     S: * 3 EXPUNGE
     S: A003 OK UID EXPUNGE completed
   In the third form, the UID command takes a SEARCH command with SEARCH
   command arguments.  The interpretation of the arguments is the same
   as with SEARCH; however, the numbers returned in an ESEARCH response
   for a UID SEARCH command are unique identifiers instead of message
   sequence numbers.  Also, the corresponding ESEARCH response MUST
   include the UID indicator.  For example, the command UID SEARCH 1:100
   UID 443:557 returns the unique identifiers corresponding to the
   intersection of two sequence sets, the message sequence number range
   1:100, and the UID range 443:557.
      Note: in the above example, the UID range 443:557 appears.  The
      same comment about a non-existent unique identifier being ignored
      without any error message also applies here.  Hence, even if
      neither UID 443 or 557 exist, this range is valid and would
      include an existing UID 495.
      Also note that a UID range of 559:* always includes the UID of the
      last message in the mailbox, even if 559 is higher than any
      assigned UID value.  This is because the contents of a range are
      independent of the order of the range endpoints.  Thus, any UID
      range with * as one of the endpoints indicates at least one
      message (the message with the highest numbered UID), unless the
      mailbox is empty.
   The number after the "*" in an untagged FETCH or EXPUNGE response is
   always a message sequence number, not a unique identifier, even for a
   UID command response.  However, server implementations MUST
   implicitly include the UID message data item as part of any FETCH
   response caused by a UID command, regardless of whether a UID was
   specified as a message data item to the FETCH.
   Note: The rule about including the UID message data item as part of a
   FETCH response primarily applies to the UID FETCH and UID STORE
   commands, including a UID FETCH command that does not include UID as
   a message data item.  Although it is unlikely that the other UID
   commands will cause an untagged FETCH, this rule applies to these
   commands as well.
   Example:
     C: A999 UID FETCH 4827313:4828442 FLAGS
     S: * 23 FETCH (FLAGS (\Seen) UID 4827313)
     S: * 24 FETCH (FLAGS (\Seen) UID 4827943)
     S: * 25 FETCH (FLAGS (\Seen) UID 4828442)
     S: A999 OK UID FETCH completed
6.5.  Client Commands - Experimental/Expansion
   Each command that is not part of this specification MUST have at
   least one capability name (see Section 6.1.1) associated with it.
   (Multiple commands can be associated with the same capability name.)
   Server implementations MUST NOT send any added untagged responses
   (not specified in this specification), unless the client requested it
   by issuing the associated experimental command (specified in an
   extension document) or the ENABLE command (Section 6.3.1).
   The following example demonstrates how a client can check for the
   presence of a fictitious XPIG-LATIN capability that adds the XPIG-
   LATIN command and the XPIG-LATIN untagged response.  (Note that for
   an extension, the command name and the capability name don't have to
   be the same.)
   Example:
     C: a441 CAPABILITY
     S: * CAPABILITY IMAP4rev2 XPIG-LATIN
     S: a441 OK CAPABILITY completed
     C: A442 XPIG-LATIN
     S: * XPIG-LATIN ow-nay eaking-spay ig-pay atin-lay
     S: A442 OK XPIG-LATIN ompleted-cay