RFC du protocole IMAP : State and Flow Diagram


3. State and Flow Diagram

   An IMAP4rev1 server is in one of four states.  Most commands are
   valid in only certain states.  It is a protocol error for the client
   to attempt a command while the command is in an inappropriate state.
   In this case, a server will respond with a BAD or NO (depending upon
   server implementation) command completion result.

3.1. Non-Authenticated State

   In non-authenticated state, the client MUST supply authentication
   credentials before most commands will be permitted.  This state is
   entered when a connection starts unless the connection has been pre-
   authenticated.

3.2. Authenticated State

   In authenticated state, the client is authenticated and MUST select a
   mailbox to access before commands that affect messages will be
   permitted.  This state is entered when a pre-authenticated connection
   starts, when acceptable authentication credentials have been
   provided, or after an error in selecting a mailbox.

3.3. Selected State

   In selected state, a mailbox has been selected to access.  This state
   is entered when a mailbox has been successfully selected.

3.4. Logout State

   In logout state, the connection is being terminated, and the server
   will close the connection.  This state can be entered as a result of
   a client request or by unilateral server decision.

            +--------------------------------------+
            |initial connection and server greeting|
            +--------------------------------------+
                      || (1)       || (2)        || (3)
                      VV           ||            ||
            +-----------------+    ||            ||
            |non-authenticated|    ||            ||
            +-----------------+    ||            ||
             || (7)   || (4)       ||            ||
             ||       VV           VV            ||
             ||     +----------------+           ||
             ||     | authenticated  |<=++       ||
             ||     +----------------+  ||       ||
             ||       || (7)   || (5)   || (6)   ||
             ||       ||       VV       ||       ||
             ||       ||    +--------+  ||       ||
             ||       ||    |selected|==++       ||
             ||       ||    +--------+           ||
             ||       ||       || (7)            ||
             VV       VV       VV                VV
            +--------------------------------------+
            |     logout and close connection      |
            +--------------------------------------+

         (1) connection without pre-authentication (OK greeting)
         (2) pre-authenticated connection (PREAUTH greeting)
         (3) rejected connection (BYE greeting)
         (4) successful LOGIN or AUTHENTICATE command
         (5) successful SELECT or EXAMINE command
         (6) CLOSE command, or failed SELECT or EXAMINE command
         (7) LOGOUT command, server shutdown, or connection closed