home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / rfc / 1000s / rfc1064.txt < prev    next >
Text File  |  1988-07-28  |  56KB  |  1,459 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. Network Working Group                                         M. Crispin
  8. Request for Comments: 1064                                     SUMEX-AIM
  9.                                                                July 1988
  10.  
  11.               INTERACTIVE MAIL ACCESS PROTOCOL - VERSION 2
  12.  
  13.  
  14. Status of this Memo
  15.  
  16.    This RFC suggests a method for workstations to dynamically access
  17.    mail from a mailbox server ("repository").  This RFC specifies a
  18.    standard for the SUMEX-AIM community and a proposed experimental
  19.    protocol for the Internet community.  Discussion and suggestions for
  20.    improvement are requested.  Distribution of this memo is unlimited.
  21.  
  22. Introduction
  23.  
  24.    The intent of the Interactive Mail Access Protocol, Version 2 (IMAP2)
  25.    is to allow a workstation or similar small machine to access
  26.    electronic mail from a mailbox server.  IMAP2 is the protocol used by
  27.    the SUMEX-AIM MM-D (MM Distributed) mail system.
  28.  
  29.    Although different in many ways from POP2 (RFC 937), IMAP2 may be
  30.    thought of as a functional superset of POP2, and the POP2 RFC was
  31.    used as a model for this RFC.  There was a cognizant reason for this;
  32.    RFC 937 deals with an identical problem and it was desirable to offer
  33.    a basis for comparison.
  34.  
  35.    Like POP2, IMAP2 specifies a means of accessing stored mail and not
  36.    of posting mail; this function is handled by a mail transfer protocol
  37.    such as SMTP (RFC 821).  A comparison with the DMSP protocol of
  38.    PCMAIL can be found at the end of "System Model and Philosophy"
  39.    section.
  40.  
  41.    This protocol assumes a reliable data stream such as provided by TCP
  42.    or any similar protocol.  When TCP is used, the IMAP2 server listens
  43.    on port 143.
  44.  
  45. System Model and Philosophy
  46.  
  47.    Electronic mail is a primary means of communication for the widely
  48.    spread SUMEX-AIM community.  The advent of distributed workstations
  49.    is forcing a significant rethinking of the mechanisms employed to
  50.    manage such mail.  With mainframes, each user tends to receive and
  51.    process mail at the computer he used most of the time, his "primary
  52.    host".  The first inclination of many users when an independent
  53.    workstation is placed in front of them is to begin receiving mail at
  54.    the workstation, and, in fact, many vendors have implemented
  55.  
  56.  
  57.  
  58. Crispin                                                         [Page 1]
  59.  
  60. RFC 1064                         IMAP2                         July 1988
  61.  
  62.  
  63.    facilities to do this.  However, this approach has several
  64.    disadvantages:
  65.  
  66.       (1) Workstations (especially Lisp workstations) have a software
  67.       design that gives full control of all aspects of the system to the
  68.       user at the console.  As a result, background tasks, like
  69.       receiving mail, could well be kept from running for long periods
  70.       of time either because the user is asking to use all of the
  71.       machine's resources, or because, in the course of working, the
  72.       user has (perhaps accidentally) manipulated the environment in
  73.       such a way as to prevent mail reception.  This could lead to
  74.       repeated failed delivery attempts by outside agents.
  75.  
  76.       (2) The hardware failure of a single workstation could keep its
  77.       user "off the air" for a considerable time, since repair of
  78.       individual workstation units might be delayed.  Given the growing
  79.       number of workstations spread throughout office environments,
  80.       quick repair would not be assured, whereas a centralized mainframe
  81.       is generally repaired very soon after failure.
  82.  
  83.       (3) It is more difficult to keep track of mailing addresses when
  84.       each person is associated with a distinct machine.  Consider the
  85.       difficulty in keeping track of a large number of postal addresses
  86.       or phone numbers, particularly if there was no single address or
  87.       phone number for an organization through which you could reach any
  88.       person in that organization.  Traditionally, electronic mail on
  89.       the ARPANET involved remembering a name and one of several "hosts"
  90.       (machines) whose name reflected the organization in which the
  91.       individual worked.  This was suitable at a time when most
  92.       organizations had only one central host.  It is less satisfactory
  93.       today unless the concept of a host is changed to refer to an
  94.       organizational entity and not a particular machine.
  95.  
  96.       (4)  It is very difficult to keep a multitude of heterogeneous
  97.       workstations working properly with complex mailing protocols,
  98.       making it difficult to move forward as progress is made in
  99.       electronic communication and as new standards emerge.  Each system
  100.       has to worry about receiving incoming mail, routing and delivering
  101.       outgoing mail, formatting, storing, and providing for the
  102.       stability of mailboxes over a variety of possible filing and
  103.       mailing protocols.
  104.  
  105.    Consequently, while the workstation may be viewed as an Internet host
  106.    in the sense that it implements IP, it should not be viewed as the
  107.    entity which contains the user's mailbox.  Rather, a mail server
  108.    machine (sometimes called a "repository") should hold the mailbox,
  109.    and the workstation (hereafter referred to as a "client") should
  110.    access the mailbox via mail transactions.  Because the mail server
  111.  
  112.  
  113.  
  114. Crispin                                                         [Page 2]
  115.  
  116. RFC 1064                         IMAP2                         July 1988
  117.  
  118.  
  119.    machine would be isolated from direct user manipulation, it could
  120.    achieve high software reliability easily, and, as a shared resource,
  121.    it could achieve high hardware reliability, perhaps through
  122.    redundancy.  The mail server could be used from arbitrary locations,
  123.    allowing users to read mail across campus, town, or country using
  124.    more and more commonly available clients.  Furthermore, the same user
  125.    may access his mailbox from different clients at different times, and
  126.    multiple users may access the same mailbox simultaneously.
  127.  
  128.    The mail server acts an an interface among users, data storage, and
  129.    other mailers.  The mail access protocol is used to retrieve
  130.    messages, access and change properties of messages, and manage
  131.    mailboxes.  This differs from some approaches (e.g., Unix mail via
  132.    NFS) in that the mail access protocol is used for all message
  133.    manipulations, isolating the user and the client from all knowledge
  134.    of how the data storage is used.  This means that the mail server can
  135.    utilize the data storage in whatever way is most efficient to
  136.    organize the mail in that particular environment, without having to
  137.    worry about storage representation compatibility across different
  138.    machines.
  139.  
  140.    In defining a mail access protocol, it is important to keep in mind
  141.    that the client and server form a macrosystem, in which it should be
  142.    possible to exploit the strong points of both while compensating for
  143.    each other's weaknesses.  Furthermore, it's desirable to allow for a
  144.    growth path beyond the hoary text-only RFC 822 protocol.  Unlike
  145.    POP2, IMAP2 has extensive features for remote searching and parsing
  146.    of messages on the server.  For example, a free text search
  147.    (optionally in conjunction with other searching) can be made
  148.    throughout the entire mailbox by the server and the results made
  149.    available to the client without the client having to transfer the
  150.    entire mailbox and searching itself.  Since remote parsing of a
  151.    message into a structured (and standard format) "envelope" is
  152.    available, a client can display envelope information and implement
  153.    commands such as REPLY without having any understanding of how to
  154.    parse RFC 822, etc. headers.
  155.  
  156.    Additionally, IMAP2 offers several facilities for managing a mailbox
  157.    beyond the simple "delete message" functionality of POP2.
  158.  
  159.    In spite of this, IMAP2 is a relatively simple protocol.  Although
  160.    servers should implement the full set of IMAP2 functions, a simple
  161.    client can be written which uses IMAP2 in much the way as a POP2
  162.    client.
  163.  
  164.    IMAP2 differs from the DMSP protocol of PCMAIL (RFC 1056) in a more
  165.    fundamental manner, reflecting the differing architectures of MM-D
  166.    and PCMAIL.  PCMAIL is either an online ("interactive mode"), or
  167.  
  168.  
  169.  
  170. Crispin                                                         [Page 3]
  171.  
  172. RFC 1064                         IMAP2                         July 1988
  173.  
  174.  
  175.    offline ("batch mode") system.  MM-D is primarily an online system in
  176.    which real-time and simultaneous mail access were considered
  177.    important.
  178.  
  179.    In PCMAIL, there is a long-term client/server relationship in which
  180.    some mailbox state is preserved on the client.  There is a
  181.    registration of clients used by a particular user, and the client
  182.    keeps a set of "descriptors" for each message which summarize the
  183.    message.  The server and client synchronize their states when the
  184.    DMSP connection starts up, and, if a client has not accessed the
  185.    server for a while, the client does a complete reset (reload) of its
  186.    state from the server.
  187.  
  188.    In MM-D, the client/server relationship lasts only for the duration
  189.    of the IMAP2 connection.  All mailbox state is maintained on the
  190.    server.  There is no registration of clients.  The function of a
  191.    descriptor is handled by a structured representation of the message
  192.    "envelope".  This structure makes it unnecessary for a client to know
  193.    anything about RFC 822 parsing.  There is no synchronization since
  194.    the client does not remember state between IMAP2 connections.  This
  195.    is not a problem since in general the client never needs the entire
  196.    state of the mailbox in a single session, therefore there isn't much
  197.    overhead in fetching the state information that is needed as it is
  198.    needed.
  199.  
  200.    There are also some functional differences between IMAP2 and DMSP.
  201.    DMSP has explicit support for bulletin boards which are only handled
  202.    implicitly in IMAP2.  DMSP has functions for sending messages,
  203.    printing messages, listing mailboxes, and changing passwords, all of
  204.    which are done outside of IMAP2.  DMSP has 16 binary flags of which 8
  205.    are defined by the system.  IMAP has flag names; there are currently
  206.    5 defined system flag names and a facility for some number (30 in the
  207.    current implementations) of user flag names.  IMAP2 has a
  208.    sophisticated message search facility in the server to identify
  209.    interesting messages based on dates, addresses, flag status, or
  210.    textual contents without compelling the client to fetch this data for
  211.    every message.
  212.  
  213.    It was felt that maintaining state on the client is advantageous only
  214.    in those cases where the client is only used by a single user, or if
  215.    there is some means on the client to restrict access to another
  216.    user's data.  It can be a serious disadvantage in an environment in
  217.    which multiple users routinely use the same client, the same user
  218.    routinely uses different clients, and where there are no access
  219.    restrictions on the client.  It was also observed that most user mail
  220.    access is to a relatively small set of "interesting" messages, which
  221.    were either "new" mail or mail based upon some user-selected
  222.    criteria. Consequently, IMAP2 was designed to easily identify those
  223.  
  224.  
  225.  
  226. Crispin                                                         [Page 4]
  227.  
  228. RFC 1064                         IMAP2                         July 1988
  229.  
  230.  
  231.    "interesting" messages so that the client could fetch the state of
  232.    those messages and not those that were not "interesting".
  233.  
  234. The Protocol
  235.  
  236.    The IMAP2 protocol consists of a sequence of client commands and
  237.    server responses, with server data interspersed between the
  238.    responses.  Unlike most Internet protocols, commands and responses
  239.    are tagged.  That is, a command begins with a unique identifier
  240.    (typically a short alphanumeric sequence such as a Lisp "gensym"
  241.    function would generate e.g., A0001, A0002, etc.), called a tag.  The
  242.    response to this command is given the same tag from the server.
  243.    Additionally, the server may send an arbitrary amount of "unsolicited
  244.    data", which is identified by the special reserved tag of "*".  There
  245.    is another special reserved tag, "+", discussed below.
  246.  
  247.    The server must be listening for a connection.  When a connection is
  248.    opened the server sends an unsolicited OK response as a greeting
  249.    message and then waits for commands.  When commands are received the
  250.    server acts on them and responds with responses, often interspersed
  251.    with data.
  252.  
  253.    The client opens a connection, waits for the greeting, then sends a
  254.    LOGIN command with user name and password arguments to establish
  255.    authorization.  Following an OK response from the server, the client
  256.    then sends a SELECT command to access the desired mailbox.  The
  257.    user's default mailbox has a special reserved name of "INBOX" which
  258.    is independent of the operating system that the server is implemented
  259.    on.  The server will generally send a list of valid flags, number of
  260.    messages, and number of messages arrived since last access for this
  261.    mailbox as unsolicited data, followed by an OK response.  The client
  262.    may terminate access to this mailbox and access a different one with
  263.    another SELECT command.
  264.  
  265.    The client reads mailbox information by means of FETCH commands.  The
  266.    actual data is transmitted via the unsolicited data mechanism (that
  267.    is, FETCH should be viewed as poking the server to include the
  268.    desired data along with any other data it wishes to transmit to the
  269.    client).  There are three major categories of data which may be
  270.    fetched.
  271.  
  272.    The first category is that data which is associated with a message as
  273.    an entity in the mailbox.  There are presently three such items of
  274.    data: the "internal date", the "RFC 822 size", and the "flags".  The
  275.    internal date is the date and time that the message was placed in the
  276.    mailbox.  The RFC 822 size is subject to deletion in the future; it
  277.    is the size in bytes of the message, expressed as an RFC 822 text
  278.    string.  Current clients only use it as part of a status display
  279.  
  280.  
  281.  
  282. Crispin                                                         [Page 5]
  283.  
  284. RFC 1064                         IMAP2                         July 1988
  285.  
  286.  
  287.    line.  The flags are a list of status flags associated with the
  288.    message (see below).  All of the first category data can be fetched
  289.    by using the macro-fetch word "FAST"; that is, "FAST" expands to
  290.    "(FLAGS INTERNALDATE RFC822.SIZE)".
  291.  
  292.    The second category is that data which describes the composition and
  293.    delivery information of a message; that is, information such as the
  294.    message sender, recipient lists, message-ID, subject, etc.  This is
  295.    the information which is stored in the message header in RFC 822
  296.    format message and is traditionally called the "envelope".  [Note:
  297.    this should not be confused with the SMTP (RFC 821) envelope, which
  298.    is strictly limited to delivery information.]  IMAP2 defines a
  299.    structured and unambiguous representation for the envelope which is
  300.    particularly nice for Lisp-based parsers.  A client can use the
  301.    envelope for operations such as replying and not worry about RFC 822
  302.    at all.  Envelopes are discussed in more detail below.  The first and
  303.    second category data can be fetched together by using the macro-fetch
  304.    word "ALL"; that is, "ALL" expands to "(FLAGS INTERNALDATE
  305.    RFC822.SIZE ENVELOPE)".
  306.  
  307.    The third category is that data which is intended for direct human
  308.    viewing.  The present RFC 822 based IMAP2 defines three such items:
  309.    RFC822.HEADER, RFC822.TEXT, and RFC822 (the latter being the two
  310.    former appended together in a single text string).  Fetching "RFC822"
  311.    is equivalent to typing the RFC 822 representation of the message as
  312.    stored on the mailbox without any filtering or processing.
  313.  
  314.    Typically, a client will "FETCH ALL" for some or all of the messages
  315.    in the mailbox for use as a presentation menu, and when the user
  316.    wishes to read a particular message will "FETCH RFC822.TEXT" to get
  317.    the message body.  A more primitive client could, of course, simply
  318.    "FETCH RFC822" a la POP2-type functionality.
  319.  
  320.    The client can alter certain data (presently only the flags) by means
  321.    of a STORE command.  As an example, a message is deleted from a
  322.    mailbox by a STORE command which includes the \DELETED flag as one of
  323.    the flags being set.
  324.  
  325.    Other client operations include copying a message to another mailbox
  326.    (COPY command), permanently removing deleted messages (EXPUNGE
  327.    command), checking for new messages (CHECK command), and searching
  328.    for messages which match certain criteria (SEARCH command).
  329.  
  330.    The client terminates the session with the LOGOUT command.  The
  331.    server returns a "BYE" followed by an "OK".
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338. Crispin                                                         [Page 6]
  339.  
  340. RFC 1064                         IMAP2                         July 1988
  341.  
  342.  
  343.    A Typical Scenario
  344.  
  345.            Client                          Server
  346.            ------                          ------
  347.                                        {Wait for Connection}
  348.        {Open Connection}        -->
  349.                                    <-- * OK IMAP2 Server Ready
  350.                                        {Wait for command}
  351.        A001 LOGIN Fred Secret   -->
  352.                                    <-- A001 OK User Fred logged in
  353.                                        {Wait for command}
  354.        A002 SELECT INBOX        -->
  355.                                    <-- * FLAGS (Meeting Notice \Answered
  356.                                                 \Flagged \Deleted \Seen)
  357.                                    <-- * 19 EXISTS
  358.                                    <-- * 2 RECENT
  359.                                    <-- A0002 OK Select complete
  360.                                        {Wait for command}
  361.        A003 FETCH 1:19 ALL      -->
  362.                                    <-- * 1 Fetch (......)
  363.                                            ...
  364.                                    <-- * 18 Fetch (......)
  365.                                    <-- * 19 Fetch (......)
  366.                                    <-- A003 OK Fetch complete
  367.                                        {Wait for command}
  368.        A004 FETCH 8 RFC822.TEXT -->
  369.                                    <-- * 8 Fetch (RFC822.TEXT {893}
  370.                                            ...893 characters of text...
  371.                                    <-- )
  372.                                    <-- A004 OK Fetch complete
  373.                                        {Wait for command}
  374.  
  375.        A005 STORE 8 +Flags \Deleted -->
  376.                                    <-- * 8 Store (Flags (\Deleted
  377.                                                   \Seen))
  378.                                    <-- A005 OK Store complete
  379.                                        {Wait for command}
  380.        A006 EXPUNGE             -->
  381.                                    <-- * 19 EXISTS
  382.                                    <-- * 8 EXPUNGE
  383.                                    <-- * 18 EXISTS
  384.                                    <-- A006 Expunge complete
  385.                                        {Wait for command}
  386.        A007 LOGOUT              -->
  387.                                    <-- * BYE IMAP2 server quitting
  388.                                    <-- A007 OK Logout complete
  389.        {Close Connection}       --><-- {Close connection}
  390.                                        {Go back to start}
  391.  
  392.  
  393.  
  394. Crispin                                                         [Page 7]
  395.  
  396. RFC 1064                         IMAP2                         July 1988
  397.  
  398.  
  399. Conventions
  400.  
  401.    The following terms are used in a meta-sense in the syntax
  402.    specification below:
  403.  
  404.       An ASCII-STRING is a sequence of arbitrary ASCII characters.
  405.  
  406.       An ATOM is a sequence of ASCII characters delimited by SP or CRLF.
  407.  
  408.       A CHARACTER is any ASCII character except """", "{", CR, LF, "%",
  409.       or "\".
  410.  
  411.       A CRLF is an ASCII carriage-return character followed immediately
  412.       by an ASCII linefeed character.
  413.  
  414.       A NUMBER is a sequence of the ASCII characters which represent
  415.       decimal numerals ("0" through "9"), delimited by SP, CRLF, ",", or
  416.       ":".
  417.  
  418.       A SP is the ASCII space character.
  419.  
  420.       A TEXT_LINE is a human-readable sequence of ASCII characters up to
  421.       but not including a terminating CRLF.
  422.  
  423.    One of the most common fields in the IMAP2 protocol is a STRING,
  424.    which may be an ATOM, QUOTED-STRING (a sequence of CHARACTERs inside
  425.    double-quotes), or a LITERAL.  A literal consists of an open brace
  426.    ("{"), a number, a close brace ("}"), a CRLF, and then an ASCII-
  427.    STRING of n characters, where n is the value of the number inside the
  428.    brace. In general, a string should be represented as an ATOM or
  429.    QUOTED-STRING if at all possible.  The semantics for QUOTED-STRING or
  430.    LITERAL are checked before those for ATOM; therefore an ATOM used in
  431.    a STRING may only contain CHARACTERs.  Literals are most often sent
  432.    from the server to the client; in the rare case of a client to server
  433.    literal there is a special consideration (see the "+ text" response
  434.    below).
  435.  
  436.    Another important field is the SEQUENCE, which identifies a set of
  437.    messages by consecutive numbers from 1 to n where n is the number of
  438.    messages in the mailbox.  A sequence may consist of a single number,
  439.    a pair of numbers delimited by colon indicating all numbers between
  440.    those two numbers, or a list of single numbers and/or number pairs.
  441.    For example, the sequence 2,4:7,9,12:15 is equivalent to
  442.    2,4,5,6,7,9,12,13,14,15 and identifies all of those messages.
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450. Crispin                                                         [Page 8]
  451.  
  452. RFC 1064                         IMAP2                         July 1988
  453.  
  454.  
  455. Definitions of Commands and Responses
  456.  
  457.      Summary of Commands and Responses
  458.  
  459.        Commands                            ||      Responses
  460.        --------                            ||      -------
  461.        tag NOOP                            ||      tag OK text
  462.        tag LOGIN user password             ||      tag NO text
  463.        tag LOGOUT                          ||      tag BAD text
  464.        tag SELECT mailbox                  ||      * message_number data
  465.        tag CHECK                           ||      * FLAGS flag_list
  466.        tag EXPUNGE                         ||      * SEARCH sequence
  467.        tag COPY sequence mailbox           ||      * BYE text
  468.        tag FETCH sequence data             ||      * OK text
  469.        tag STORE sequence data value       ||      * NO text
  470.        tag SEARCH search_program           ||      * BAD text
  471.                                            ||      + text
  472.  
  473. Commands
  474.  
  475.    tag NOOP
  476.  
  477.       The NOOP command returns an OK to the client.  By itself, it does
  478.       nothing, but certain things may happen as side effects.  For
  479.       example, server implementations which implicitly check the mailbox
  480.       for new mail may do so as a result of this command.  The primary
  481.       use of this command is to for the client to see if the server is
  482.       still alive (and notify the server that the client is still alive,
  483.       for those servers which have inactivity autologout timers).
  484.  
  485.    tag LOGIN user password
  486.  
  487.       The LOGIN command identifies the user to the server and carries
  488.       the password authenticating this user.  This information is used
  489.       by the server to control access to the mailboxes.
  490.  
  491.       EXAMPLE: A001 LOGIN SMITH SESAME logs in as user SMITH with
  492.       password SESAME.
  493.  
  494.    tag LOGOUT
  495.  
  496.       The LOGOUT command indicates the client is done with the session.
  497.       The server sends an unsolicited BYE response before the (tagged)
  498.       OK response, and then closes the connection.
  499.  
  500.    tag SELECT mailbox
  501.  
  502.       The SELECT command selects a particular mailbox.  The server must
  503.  
  504.  
  505.  
  506. Crispin                                                         [Page 9]
  507.  
  508. RFC 1064                         IMAP2                         July 1988
  509.  
  510.  
  511.       check that the user is permitted read access to this mailbox.
  512.       Prior to returning an OK to the client, the server must send an
  513.       unsolicited FLAGS and <n> EXISTS response to the client giving the
  514.       flags list for this mailbox (simply the system flags if this
  515.       mailbox doesn't have any special flags) and the number of messages
  516.       in the mailbox.  It is also recommended that the server send a <n>
  517.       RECENT unsolicited response to the client for the benefit of
  518.       clients which make use of the number of new messages in a mailbox.
  519.  
  520.       Multiple SELECT commands are permitted in a session, in which case
  521.       the prior mailbox is deselected first.
  522.  
  523.       The default mailbox for the SELECT command is INBOX, which is a
  524.       special name reserved to mean "the primary mailbox for this user
  525.       on this server".  The format of other mailbox names is operating
  526.       system dependent (as of this writing, it reflects the filename
  527.       path of the mailbox file on the current servers).
  528.  
  529.       EXAMPLE: A002 SELECT INBOX selects the default mailbox.
  530.  
  531.    tag CHECK
  532.  
  533.       The CHECK command forces a check for new messages and a rescan of
  534.       the mailbox for internal change for those implementations which
  535.       allow multiple simultaneous read/write access to the same mailbox
  536.       (e.g., TOPS-20).  It is recommend that periodic implicit checks
  537.       for new mail be done by servers as well.  The server should send
  538.       an unsolicited <n> EXISTS response prior to returning an OK to the
  539.       client.
  540.  
  541.    tag EXPUNGE
  542.  
  543.       The EXPUNGE command permanently removes all messages with the
  544.       \DELETED flag set in its flags from the mailbox.  Prior to
  545.       returning an OK to the client, for each message which is removed,
  546.       an unsolicited <n> EXPUNGE response is sent indicating which
  547.       message was removed.  The message number of each subsequent
  548.       message in the mailbox is immediately decremented by 1; this means
  549.       that if the last 5 messages in a 9-message mail file are expunged
  550.       you will receive 5 "* 5 EXPUNGE" responses.  To ensure mailbox
  551.       integrity and server/client synchronization, it is recommended
  552.       that the server do an implicit check prior to commencing the
  553.       expunge and again when the expunge is completed.  Furthermore, if
  554.       the server allows multiple simultaneous access to the same mail
  555.       file the server must lock the mail file for exclusive access while
  556.       an expunge is taking place.
  557.  
  558.  
  559.  
  560.  
  561.  
  562. Crispin                                                        [Page 10]
  563.  
  564. RFC 1064                         IMAP2                         July 1988
  565.  
  566.  
  567.       EXPUNGE is not allowed if the user does not have write access to
  568.       this mailbox.
  569.  
  570.    tag COPY sequence mailbox
  571.  
  572.       The COPY command copies the specified message(s) to the specified
  573.       destination mailbox.  If the destination mailbox does not exist,
  574.       the server should create it.  Prior to returning an OK to the
  575.       client, the server should return an unsolicited <n> COPY response
  576.       for each message copied.  A copy should set the \SEEN flag for all
  577.       messages which were successfully copied (provided, of course, that
  578.       the user has write access to this mailbox).
  579.  
  580.       EXAMPLE: A003 COPY 2:4 MEETING copies messages 2, 3, and 4 to
  581.       mailbox "MEETING".
  582.  
  583.       COPY is not allowed if the user does not have write access to the
  584.       destination mailbox.
  585.  
  586.    tag FETCH sequence data
  587.  
  588.       The FETCH command retrieves data associated with a message in the
  589.       mailbox.  The data items to be fetched may be either a single atom
  590.       or an S-expression list.  The currently defined data items that
  591.       can be fetched are:
  592.  
  593.       ALL             Macro equivalent to:
  594.                       (FLAGS INTERNALDATE RFC822.SIZE ENVELOPE)
  595.  
  596.       ENVELOPE        The envelope of the message.  The envelope is
  597.                       computed by the server by parsing the RFC 822
  598.                       header into the component parts, defaulting
  599.                       various fields as necessary.
  600.  
  601.       FAST            Macro equivalent to:
  602.                       (FLAGS INTERNALDATE RFC822.SIZE)
  603.  
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618. Crispin                                                        [Page 11]
  619.  
  620. RFC 1064                         IMAP2                         July 1988
  621.  
  622.  
  623.       FLAGS           The flags which are set for this message.
  624.                       This may include the following system flags:
  625.  
  626.                               \RECENT    Message arrived since
  627.                                           last read of this mail
  628.                                           file
  629.                               \SEEN      Message has been read
  630.                               \ANSWERED  Message has been answered
  631.                               \FLAGGED   Message is "flagged" for
  632.                                           urgent/special attention
  633.                               \DELETED   Message is "deleted" for
  634.                                           removal by later EXPUNGE
  635.  
  636.       INTERNALDATE    The date and time the message was written to
  637.                       the mailbox.
  638.  
  639.       RFC822          The message in RFC 822 format.
  640.  
  641.       RFC822.HEADER   The RFC 822 format header of the message.
  642.  
  643.       RFC822.SIZE     The number of characters in the message as
  644.                       expressed in RFC 822 format.
  645.  
  646.       RFC822.TEXT     The text body of the message, omitting the
  647.                       RFC 822 header.
  648.  
  649.       EXAMPLES:
  650.  
  651.       A003 FETCH 2:4 ALL
  652.          fetches the flags, internal date, RFC 822 size, and envelope
  653.          for messages 2, 3, and 4.
  654.  
  655.       A004 FETCH 3 RFC822
  656.          fetches the RFC 822 representation for message 3.
  657.  
  658.       A005 FETCH 4 (FLAGS RFC822.HEADER)
  659.          fetches the flags and RFC 822 format header for message 4.
  660.  
  661.    tag STORE sequence data value
  662.  
  663.       The STORE command alters data associated with a message in the
  664.       mailbox.  The currently defined data items that can be stored are:
  665.  
  666.       FLAGS           Replace the flags for the message with the
  667.                       argument (in flag list format).
  668.  
  669.       +FLAGS          Add the flags in the argument to the
  670.                       message's flag list.
  671.  
  672.  
  673.  
  674. Crispin                                                        [Page 12]
  675.  
  676. RFC 1064                         IMAP2                         July 1988
  677.  
  678.  
  679.       -FLAGS          Remove the flags in the argument from the
  680.                       message's flag list.
  681.  
  682.          STORE is not allowed if the user does not have write access to
  683.          this mailbox.
  684.  
  685.          EXAMPLE:  A003 STORE 2:4 +FLAGS (\DELETED)
  686.          marks messages 2, 3, and 4 for deletion.
  687.  
  688.    tag SEARCH search_criteria
  689.  
  690.       The SEARCH command searches the mailbox for messages which match
  691.       the given set of criteria.  The unsolicited SEARCH <1#number>
  692.       response from the server is a list of messages which express the
  693.       intersection (AND function) of all the messages.  The currently
  694.       defined criteria are:
  695.  
  696.       ALL             All messages in the mailbox; the default
  697.                       initial criterion for ANDing.
  698.  
  699.       ANSWERED        Messages with the \ANSWERED flag set.
  700.  
  701.       BCC string      Messages which contain the specified string
  702.                       in the envelope's BCC field.
  703.  
  704.       BEFORE date     Messages whose internal date is earlier than
  705.                       the specified date.
  706.  
  707.       BODY string     Messages which contain the specified string
  708.                       in the body of the message.
  709.  
  710.       CC string       Messages which contain the specified string
  711.                       in the envelope's CC field.
  712.  
  713.       DELETED         Messages with the \DELETED flag set.
  714.  
  715.       FLAGGED         Messages with the \FLAGGED flag set.
  716.  
  717.       KEYWORD flag    Messages with the specified flag set.
  718.  
  719.       NEW             Messages which have the \RECENT flag set but
  720.                       not the \SEEN flag.  This is functionally
  721.                       equivalent to "RECENT UNSEEN".
  722.  
  723.       OLD             Messages which do not have the \RECENT flag
  724.                       set.
  725.  
  726.  
  727.  
  728.  
  729.  
  730. Crispin                                                        [Page 13]
  731.  
  732. RFC 1064                         IMAP2                         July 1988
  733.  
  734.  
  735.       ON date         Messages whose internal date is the same as
  736.                       the specified date.
  737.  
  738.       RECENT          Messages which have the \RECENT flag set.
  739.  
  740.       SEEN            Messages which have the \SEEN flag set.
  741.  
  742.       SINCE date      Messages whose internal date is later than
  743.                       the specified date.
  744.  
  745.       SUBJECT string  Messages which contain the specified string
  746.                       in the envelope's SUBJECT field.
  747.  
  748.       TEXT string     Messages which contain the specified string.
  749.  
  750.       TO string       Messages which contain the specified string in
  751.                       the envelope's TO field.
  752.  
  753.       UNANSWERED      Messages which do not have the \ANSWERED flag
  754.                       set.
  755.  
  756.       UNDELETED       Messages which do not have the \DELETED flag
  757.                       set.
  758.  
  759.       UNFLAGGED       Messages which do not have the \FLAGGED flag
  760.                       set.
  761.  
  762.       UNKEYWORD flag  Messages which do not have the specified flag
  763.                       set.
  764.  
  765.       UNSEEN          Messages which do not have the \SEEN flag set.
  766.  
  767.          EXAMPLE:  A003 SEARCH DELETED FROM "SMITH" SINCE 1-OCT-87
  768.          returns the message numbers for all deleted messages from Smith
  769.          that were placed in the mail file since October 1, 1987.
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786. Crispin                                                        [Page 14]
  787.  
  788. RFC 1064                         IMAP2                         July 1988
  789.  
  790.  
  791. Responses
  792.  
  793.    tag OK text
  794.  
  795.       This response identifies successful completion of the command with
  796.       the indicated tag.  The text is a line of human-readable text
  797.       which may be useful in a protocol telemetry log for debugging
  798.       purposes.
  799.  
  800.    tag NO text
  801.  
  802.       This response identifies unsuccessful completion of the command
  803.       with the indicated tag.  The text is a line of human-readable text
  804.       which probably should be displayed to the user in an error report
  805.       by the client.
  806.  
  807.    tag BAD text
  808.  
  809.       This response indicates faulty protocol received from the client
  810.       and indicates a bug in the client.  The text is a line of human-
  811.       readable text which should be recorded in any telemetry as part of
  812.       a bug report to the maintainer of the client.
  813.  
  814.    * number message_data
  815.  
  816.       This response occurs as a result of several different commands.
  817.       The message_data is one of the following:
  818.  
  819.       EXISTS  The specified number of messages exists in the mailbox.
  820.  
  821.       RECENT  The specified number of messages have arrived since the
  822.               last time this mailbox was read.
  823.  
  824.       EXPUNGE The specified message number has been permanently
  825.               removed from the mailbox, and the next message in the
  826.               mailbox (if any) becomes that message number.
  827.  
  828.       STORE data
  829.               Functionally equivalent to FETCH, only it happens as a
  830.               result of a STORE command.
  831.  
  832.       FETCH data
  833.               This is the principle means by which data about a
  834.               message is returned to the client.  The data is in a
  835.               Lisp-like S-expression property list form.  The current
  836.               properties are:
  837.  
  838.          ENVELOPE     An S-expression format list which describes the
  839.  
  840.  
  841.  
  842. Crispin                                                        [Page 15]
  843.  
  844. RFC 1064                         IMAP2                         July 1988
  845.  
  846.  
  847.                       envelope of a message.  The envelope is computed
  848.                       by the server by parsing the RFC 822 header into
  849.                       the component parts, defaulting various fields
  850.                       as necessary.
  851.  
  852.                       The fields of the envelope are in the following
  853.                       order: date, subject, from, sender, reply-to, to,
  854.                       cc, bcc, in-reply-to, and message-id.  The date,
  855.                       subject, in-reply-to, and message-id fields are
  856.                       strings.  The from, sender, reply-to, to, cc,
  857.                       and bcc fields are lists of addresses.
  858.  
  859.                       An address is an S-expression format list which
  860.                       describes an electronic mail address.  The fields
  861.                       of an address are in the following order:
  862.                       personal name, source-route (a.k.a. the
  863.                       at-domain-list in SMTP), mailbox name, and
  864.                       host name.
  865.  
  866.                       Any field of an envelope or address which is
  867.                       not applicable is presented as the atom NIL.
  868.                       Note that the server must default the reply-to
  869.                       and sender fields from the from field; a client is
  870.                       not expected to know to do this.
  871.  
  872.          FLAGS        An S-expression format list of flags which are set
  873.                       for this message.  This may include the following
  874.                       system flags:
  875.  
  876.                       \RECENT       Message arrived since last
  877.                                      read of this mail file
  878.                       \SEEN         Message has been read
  879.                       \ANSWERED     Message has been answered
  880.                       \FLAGGED      Message is "flagged" for
  881.                                      urgent/special attention
  882.                       \DELETED      Message is "deleted" for
  883.                                      removal by later EXPUNGE
  884.  
  885.          INTERNALDATE  A string containing the date and time the
  886.                        message was written to the mailbox.
  887.  
  888.          RFC822        A string expressing the message in RFC 822
  889.                        format.
  890.  
  891.          RFC822.HEADER A string expressing the RFC 822 format
  892.                        header of the message
  893.  
  894.          RFC822.SIZE   A number indicating the number of
  895.  
  896.  
  897.  
  898. Crispin                                                        [Page 16]
  899.  
  900. RFC 1064                         IMAP2                         July 1988
  901.  
  902.  
  903.                        characters in the message as expressed
  904.                        in RFC 822 format.
  905.  
  906.          RFC822.TEXT   A string expressing the text body of the
  907.                        message, omitting the RFC 822 header.
  908.  
  909.    * FLAGS flag_list
  910.  
  911.       This response occurs as a result of a SELECT command.  The flag
  912.       list are the list of flags (at a minimum, the system-defined
  913.       flags) which are applicable for this mailbox.  Flags other than
  914.       the system flags are a function of the server implementation.
  915.  
  916.    * SEARCH number(s)
  917.  
  918.       This response occurs as a result of a SEARCH command.  The
  919.       number(s) refer those messages which match the search criteria.
  920.       Each number is delimited by a space, e.g., "SEARCH 2 3 6".
  921.  
  922.    * BYE text
  923.  
  924.       This response indicates that the server is about to close the
  925.       connection.  The text is a line of human-readable text which
  926.       should be displayed to the user in a status report by the client.
  927.       This may be sent as part of a normal logout sequence, or as a
  928.       panic shutdown announcement by the server.  It is also used by
  929.       some servers as an announcement of an inactivity autologout.
  930.  
  931.    * OK text
  932.  
  933.       This response indicates that the server is alive.  No special
  934.       action on the part of the client is called for.  This is presently
  935.       only used by servers at startup as a greeting message indicating
  936.       that they are ready to accept the first command.  The text is a
  937.       line of human-readable text which may be logged in protocol
  938.       telemetry.
  939.  
  940.    * NO text
  941.  
  942.       This response indicates some operational error at the server which
  943.       cannot be traced to any protocol command.  The text is a line of
  944.       human-readable text which should be logged in protocol telemetry
  945.       for the maintainer of the server and/or the client.  No known
  946.       server currently outputs such a response.
  947.  
  948.    * BAD text
  949.  
  950.       This response indicates some protocol error at the server which
  951.  
  952.  
  953.  
  954. Crispin                                                        [Page 17]
  955.  
  956. RFC 1064                         IMAP2                         July 1988
  957.  
  958.  
  959.       cannot be traced to any protocol command.  The text is a line of
  960.       human-readable text which should be logged in protocol telemetry
  961.       for the maintainer of the server and/or the client.  This
  962.       generally indicates a protocol synchronization problem on the part
  963.       of the client, and examination of the protocol telemetry is
  964.       advised to determine the cause of the problem.
  965.  
  966.    + text
  967.  
  968.       This response indicates that the server is ready to accept the
  969.       text of a literal from the client.  Normally, a command from the
  970.       client is a single text line.  If the server detects an error in
  971.       the command, it can simply discard the remainder of the line.  It
  972.       cannot do this in the case of commands which contain literals,
  973.       since a literal can be an arbitrarily long amount of text, and the
  974.       server may not even be expecting a literal.  This mechanism is
  975.       provided so the client knows not to send a literal until the
  976.       server definitely expects it, preserving client/server
  977.       synchronization.
  978.  
  979.       In actual practice, this situation is rarely encountered.  In the
  980.       current protocol, the only client command likely to contain a
  981.       literal is the LOGIN command.  Consider a situation in which a
  982.       server validates the user before checking the password.  If the
  983.       password contains "funny" characters and hence is sent as a
  984.       literal, then if the user is invalid an error would occur before
  985.       the password is parsed.
  986.  
  987.       No such synchronization protection is provided for literals sent
  988.       from the server to the client, for performance reasons.  Any
  989.       synchronization problems in this direction would be due to a bug
  990.       in the client or server and not for some operational problem.
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010. Crispin                                                        [Page 18]
  1011.  
  1012. RFC 1064                         IMAP2                         July 1988
  1013.  
  1014.  
  1015. Sample IMAP2 session
  1016.  
  1017.    The following is a transcript of an actual IMAP2 session.  Server
  1018.    output is identified by "S:" and client output by "U:".  In cases
  1019.    where lines were too long to fit within the boundaries of this
  1020.    document, the line was continued on the next line preceded by a tab.
  1021.  
  1022.    S:      * OK SUMEX-AIM.Stanford.EDU Interim Mail Access Protocol II
  1023.                    Service 6.1(349) at Thu, 9 Jun 88 14:58:30 PDT
  1024.    U:      a001 login crispin secret
  1025.    S:      a002 OK User CRISPIN logged in at Thu, 9 Jun 88 14:58:42 PDT,
  1026.                    job 76
  1027.    U:      a002 select inbox
  1028.    S:      * FLAGS (Bugs SF Party Skating Meeting Flames Request AI
  1029.                    Question Note \XXXX \YYYY \Answered \Flagged \Deleted
  1030.                    \Seen)
  1031.    S:      * 16 EXISTS
  1032.    S:      * 0 RECENT
  1033.    S:      a002 OK Select complete
  1034.    U:      a003 fetch 16 all
  1035.    S:      * 16 Fetch (Flags (\Seen) InternalDate " 9-Jun-88 12:55:
  1036.                RFC822.Size 637 Envelope ("Sat, 4 Jun 88 13:27:11 PDT"
  1037.                "INFO-MAC Mail Message" (("Larry Fagan" NIL "FAGAN"
  1038.                "SUMEX-AIM.Stanford.EDU")) (("Larry Fagan" NIL "FAGAN"
  1039.                "SUMEX-AIM.Stanford.EDU")) (("Larry Fagan" NIL "FAGAN"
  1040.                "SUMEX-AIM.Stanford.EDU")) ((NIL NIL "rindflEISCH"
  1041.                "SUMEX-AIM.Stanford.EDU")) NIL NIL NIL
  1042.                "<12403828905.13.FAGAN@SUMEX-AIM.Stanford.EDU>"))
  1043.    S:   a003 OK Fetch completed
  1044.    U:   a004 fetch 16 rfc822
  1045.    S:   * 16 Fetch (RFC822 {637}
  1046.    S:   Mail-From: RINDFLEISCH created at  9-Jun-88 12:55:43
  1047.    S:   Mail-From: FAGAN created at  4-Jun-88 13:27:12
  1048.    S:   Date: Sat, 4 Jun 88 13:27:11 PDT
  1049.    S:   From: Larry Fagan  <FAGAN@SUMEX-AIM.Stanford.EDU>
  1050.    S:   To: rindflEISCH@SUMEX-AIM.Stanford.EDU
  1051.    S:   Subject: INFO-MAC Mail Message
  1052.    S:   Message-ID: <12403828905.13.FAGAN@SUMEX-AIM.Stanford.EDU>
  1053.    S:   ReSent-Date: Thu, 9 Jun 88 12:55:43 PDT
  1054.    S:   ReSent-From: TC Rindfleisch <Rindfleisch@SUMEX-AIM.Stanford.EDU>
  1055.    S:   ReSent-To: Yeager@SUMEX-AIM.Stanford.EDU,
  1056.                    Crispin@SUMEX-AIM.Stanford.EDU
  1057.    S:   ReSent-Message-ID:
  1058.            <12405133897.80.RINDFLEISCH@SUMEX-AIM.Stanford.EDU>
  1059.    S:
  1060.    S:   The file is <info-mac>usenetv4-55.arc  ...
  1061.    S:   Larry
  1062.    S:   -------
  1063.  
  1064.  
  1065.  
  1066. Crispin                                                        [Page 19]
  1067.  
  1068. RFC 1064                         IMAP2                         July 1988
  1069.  
  1070.  
  1071.    S:   )
  1072.    S:   pa004 OK Fetch completed
  1073.    U:   a005 logout
  1074.    S:   * BYE DEC-20 IMAP II server terminating connection
  1075.    S:   a005 OK SUMEX-AIM.Stanford.EDU Interim Mail Access Protocol
  1076.                    Service logout
  1077.  
  1078.  
  1079.  
  1080.  
  1081.  
  1082.  
  1083.  
  1084.  
  1085.  
  1086.  
  1087.  
  1088.  
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122. Crispin                                                        [Page 20]
  1123.  
  1124. RFC 1064                         IMAP2                         July 1988
  1125.  
  1126.  
  1127. Implementation Discussion
  1128.  
  1129.    As of this writing, SUMEX has completed an IMAP2 client for Xerox
  1130.    Lisp machines written in hybrid Interlisp/CommonLisp and is beta-
  1131.    testing a client for TI Explorers written entirely in CommonLisp.
  1132.    SUMEX has also completed a portable IMAP2 client protocol library
  1133.    module written in C.  This library, with the addition of a small main
  1134.    program (primarily user interface) and a TCP/IP driver, became a
  1135.    rudimentary remote system mail-reading program under Unix.  The first
  1136.    production use of this library will be as a part of a MacII client
  1137.    which is under development.
  1138.  
  1139.    As of this writing, SUMEX has completed IMAP2 servers for TOPS-20
  1140.    written in DEC-20 assembly language and 4.2/3 BSD Unix written in C.
  1141.    The TOPS-20 server is fully compatible with MM-20, the standard
  1142.    TOPS-20 mailsystem, and requires no special action or setup on the
  1143.    part of the user.  The INBOX under TOPS-20 is the user's MAIL.TXT.
  1144.    The TOPS-20 server also supports multiple simultaneous access to the
  1145.    same mailbox, including simultaneous access between the IMAP2 server
  1146.    and MM-20.  The 4.2/3 BSD Unix server requires that the user use
  1147.    mail.txt format which is compatible only with SRI MM-32 or Columbia
  1148.    MM-C.  The 4.2/3 BSD Unix server only allows simultaneous read
  1149.    access; write access must be exclusive.
  1150.  
  1151.    The Xerox Lisp client and DEC-20 server have been in production use
  1152.    for over a year; the Unix server was put into production use a few
  1153.    months ago.  IMAP2 has been used to access mailboxes at remote sites
  1154.    from a local workstation via the Internet.  For example, from the
  1155.    Stanford local network the author has read his mailbox at a Milnet
  1156.    site.
  1157.  
  1158.    This specification does not make any formal definition of size
  1159.    restrictions, but the DEC-20 server has the following limitations:
  1160.  
  1161.     . length of a mailbox: 7,077,888 characters
  1162.     . maximum number of messages: 18,432 messages
  1163.     . length of a command line: 10,000 characters
  1164.     . length of the local host name: 64 characters
  1165.     . length of a "short" argument: 39 characters
  1166.     . length of a "long" argument: 491,520 characters
  1167.     . maximum amount of data output in a single fetch:
  1168.       655,360 characters
  1169.  
  1170.    To date, nobody has run up against any of these limitations, many of
  1171.    which are substantially larger than most current user mail reading
  1172.    programs.
  1173.  
  1174.    There are several advantages to the scheme of tags and unsolicited
  1175.  
  1176.  
  1177.  
  1178. Crispin                                                        [Page 21]
  1179.  
  1180. RFC 1064                         IMAP2                         July 1988
  1181.  
  1182.  
  1183.    responses.  First, the infamous synchronization problems of SMTP and
  1184.    similar protocols do not happen with tagged commands; a command is
  1185.    not considered satisfied until a response with the same tag is seen.
  1186.    Tagging allows an arbitrary amount of other responses ("unsolicited"
  1187.    data) to be sent by the server with no possibility of the client
  1188.    losing synchronization.  Compare this with the problems that FTP or
  1189.    SMTP clients have with continuation, partial completion, and
  1190.    commentary reply codes.
  1191.  
  1192.    Another advantage is that a non-lockstep client implementation is
  1193.    possible.  The client could send a command, and entrust the handling
  1194.    of the server responses to a different process which would signal the
  1195.    client when the tagged response comes in.  Under certain
  1196.    circumstances, the client could even have more than one command
  1197.    outstanding.
  1198.  
  1199.    It was observed that synchronization problems can occur with literals
  1200.    if the literal is not recognized as such.  Fortunately, the cases in
  1201.    which this can happen are relatively rare; a mechanism (the special
  1202.    "+" tag response) was introduced to handle those few cases which
  1203.    could happen.  The proper way to address this problem in all cases is
  1204.    probably to move towards a record-oriented architecture instead of
  1205.    the text stream model provided by TCP.
  1206.  
  1207.    Unsolicited data needs some discussion.  Unlike most protocols, in
  1208.    which the server merely does the client's bidding, an IMAP2 server
  1209.    has a semi-autonomous role.  By means of sending "unsolicited data",
  1210.    the server is in effect sending a command to the client -- to update
  1211.    and/or extend its (incomplete) model of the mailbox with new
  1212.    information from the server.  In this viewpoint, a "fetch" command is
  1213.    merely a request to the server to include the desired data in any
  1214.    other "unsolicited" data the server may send, and a server
  1215.    acknowledgement to the "fetch" is a statement that all the requested
  1216.    data has been sent.
  1217.  
  1218.    In terms of implementation, the client may have a local cache of data
  1219.    from the mailbox.  This cache is incomplete, and at startup is empty.
  1220.    A listener processes all unsolicited data, and updates the cache
  1221.    based on this data.  If a tagged response arrives, the listener
  1222.    unblocks the process which sent the tagged request.
  1223.  
  1224.    Perhaps as a result of opening a mailbox, unsolicited data from the
  1225.    server arrives.  The first piece of data is the number of messages.
  1226.    This is used to size the cache; note that by sending a new "number of
  1227.    messages" unsolicited data message the cache would be re-sized (this
  1228.    is how newly arrived mail is handled).  If the client attempts to
  1229.    access information from the cache, it will encounter empty spots
  1230.    which will trigger "fetch" requests.  The request would be sent, some
  1231.  
  1232.  
  1233.  
  1234. Crispin                                                        [Page 22]
  1235.  
  1236. RFC 1064                         IMAP2                         July 1988
  1237.  
  1238.  
  1239.    unsolicited data including the answer to the fetch will flow back,
  1240.    and then the "fetch" response will unblock the client.
  1241.  
  1242.    People familiar with demand-paged virtual memory operating system
  1243.    design will recognize this model as being very similar to page-fault
  1244.    handling on a demand-paged system.
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261.  
  1262.  
  1263.  
  1264.  
  1265.  
  1266.  
  1267.  
  1268.  
  1269.  
  1270.  
  1271.  
  1272.  
  1273.  
  1274.  
  1275.  
  1276.  
  1277.  
  1278.  
  1279.  
  1280.  
  1281.  
  1282.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290. Crispin                                                        [Page 23]
  1291.  
  1292. RFC 1064                         IMAP2                         July 1988
  1293.  
  1294.  
  1295. Formal Syntax
  1296.  
  1297.    The following syntax specification uses the augmented Backus-Naur
  1298.    Form (BNF) notation as specified in RFC 822 with one exception; the
  1299.    delimiter used with the "#" construct is a single space (SP) and not
  1300.    a comma.
  1301.  
  1302.    address         ::= "(" addr_name SP addr_adl SP addr_mailbox SP
  1303.                        addr_host ")"
  1304.  
  1305.    addr_adl        ::= nil / string
  1306.  
  1307.    addr_host       ::= nil / string
  1308.  
  1309.    addr_mailbox    ::= nil / string
  1310.  
  1311.    addr_name       ::= nil / string
  1312.  
  1313.    check           ::= "CHECK"
  1314.  
  1315.    copy            ::= "COPY" SP sequence SP mailbox
  1316.  
  1317.    data            ::= ("FLAGS" SP flag_list / "SEARCH" SP 1#number /
  1318.                        "BYE" SP text_line / "OK" SP text_line /
  1319.                        "NO" SP text_line / "BAD" SP text_line)
  1320.  
  1321.    date            ::= string in form "dd-mmm-yy hh:mm:ss-zzz"
  1322.  
  1323.    envelope        ::= "(" env_date SP env_subject SP env_from SP
  1324.                        env_sender SP env_reply-to SP env_to SP
  1325.                        env_cc SP env_bcc SP env_in-reply-to SP
  1326.                        env_message-id ")"
  1327.  
  1328.    env_bcc         ::= nil / "(" 1*address ")"
  1329.  
  1330.    env_cc          ::= nil / "(" 1*address ")"
  1331.  
  1332.    env_date        ::= string
  1333.  
  1334.    env_from        ::= nil / "(" 1*address ")"
  1335.  
  1336.    env_in-reply-to ::= nil / string
  1337.  
  1338.    env_message-id  ::= nil / string
  1339.  
  1340.    env_reply-to    ::= nil / "(" 1*address ")"
  1341.  
  1342.    env_sender      ::= nil / "(" 1*address ")"
  1343.  
  1344.  
  1345.  
  1346. Crispin                                                        [Page 24]
  1347.  
  1348. RFC 1064                         IMAP2                         July 1988
  1349.  
  1350.  
  1351.    env_subject     ::= nil / string
  1352.  
  1353.    env_to          ::= nil / "(" 1*address ")"
  1354.  
  1355.    expunge         ::= "EXPUNGE"
  1356.  
  1357.    fetch           ::= "FETCH" SP sequence SP ("ALL" / "FAST" /
  1358.                        fetch_att / "(" 1#fetch_att ")")
  1359.  
  1360.    fetch_att       ::= "ENVELOPE" / "FLAGS" / "INTERNALDATE" /
  1361.                        "RFC822" / "RFC822.HEADER" / "RFC822.SIZE" /
  1362.                        "RFC822.TEXT"
  1363.  
  1364.    flag_list       ::= ATOM / "(" 1#ATOM ")"
  1365.  
  1366.    literal         ::= "{" NUMBER "}" CRLF ASCII-STRING
  1367.  
  1368.    login           ::= "LOGIN" SP userid SP password
  1369.  
  1370.    logout          ::= "LOGOUT"
  1371.  
  1372.    mailbox         ::= "INBOX" / string
  1373.  
  1374.    msg_copy        ::= "COPY"
  1375.  
  1376.    msg_data        ::= (msg_exists / msg_recent / msg_expunge /
  1377.                        msg_fetch / msg_copy)
  1378.  
  1379.    msg_exists      ::= "EXISTS"
  1380.  
  1381.    msg_expunge     ::= "EXPUNGE"
  1382.  
  1383.    msg_fetch       ::= ("FETCH" / "STORE") SP "(" 1#("ENVELOPE" SP
  1384.                         envelope / "FLAGS" SP "(" 1#(recent_flag
  1385.                         flag_list) ")" / "INTERNALDATE" SP date /
  1386.                         "RFC822" SP string / "RFC822.HEADER" SP string /
  1387.                         "RFC822.SIZE" SP NUMBER / "RFC822.TEXT" SP
  1388.                         string) ")"
  1389.  
  1390.    msg_recent      ::= "RECENT"
  1391.  
  1392.    msg_num         ::= NUMBER
  1393.  
  1394.    nil             ::= "NIL"
  1395.  
  1396.    noop            ::= "NOOP"
  1397.  
  1398.    password        ::= string
  1399.  
  1400.  
  1401.  
  1402. Crispin                                                        [Page 25]
  1403.  
  1404. RFC 1064                         IMAP2                         July 1988
  1405.  
  1406.  
  1407.    recent_flag     ::= "\RECENT"
  1408.  
  1409.    ready           ::= "+" SP text_line
  1410.  
  1411.    request         ::= tag SP (noop / login / logout / select / check /
  1412.                        expunge / copy / fetch / store / search) CRLF
  1413.  
  1414.    response        ::= tag SP ("OK" / "NO" / "BAD") SP text_line CRLF
  1415.  
  1416.    search          ::= "SEARCH" SP 1#("ALL" / "ANSWERED" /
  1417.                        "BCC" SP string / "BEFORE" SP string /
  1418.                        "BODY" SP string / "CC" SP string / "DELETED" /
  1419.                        "FLAGGED" / "KEYWORD" SP atom / "NEW" / "OLD" /
  1420.                        "ON" SP string / "RECENT" / "SEEN" /
  1421.                        "SINCE" SP string / "TEXT" SP string /
  1422.                        "TO" SP string / "UNANSWERED" / "UNDELETED" /
  1423.                        "UNFLAGGED" / "UNKEYWORD" / "UNSEEN")
  1424.  
  1425.    select          ::= "SELECT" SP mailbox
  1426.  
  1427.    sequence        ::= NUMBER / (NUMBER "," sequence) / (NUMBER ":"
  1428.                        sequence)
  1429.  
  1430.    store           ::= "STORE" SP sequence SP store_att
  1431.  
  1432.    store_att       ::= ("+FLAGS" SP flag_list / "-FLAGS" SP flag_list /
  1433.                        "FLAGS" SP flag_list)
  1434.  
  1435.    string          ::= atom / """" 1*character """" / literal
  1436.  
  1437.    system_flags    ::= "\ANSWERED" SP "\FLAGGED" SP "\DELETED" SP
  1438.                        "\SEEN"
  1439.  
  1440.    tag             ::= atom
  1441.  
  1442.    unsolicited     ::= "*" SP (msg_num SP msg_data / data) CRLF
  1443.  
  1444.    userid          ::= string
  1445.  
  1446. Acknowledgements
  1447.  
  1448.    Bill Yeager and Rich Acuff both contributed invaluable suggestions in
  1449.    the evolution of IMAP2 from the original IMAP.  The SUMEX IMAP2
  1450.    software was written by Mark Crispin (DEC-20 server, Xerox Lisp
  1451.    client, C client), Frank Gilmurray (Common Lisp client), Christopher
  1452.    Lane (Xerox Lisp client), and Bill Yeager (Unix server).  Any
  1453.    mistakes or flaws in this IMAP2 protocol specification are, however,
  1454.    strictly my own.
  1455.  
  1456.  
  1457.  
  1458. Crispin                                                        [Page 26]
  1459.