Skip to content

Conversation

@nevans
Copy link
Collaborator

@nevans nevans commented Mar 11, 2025

Tracking IMAP connection state has many uses. But in this PR, we're only tracking the session state and exposing a #connection_state attribute reader.

For forward-compatibility, the only documented methods on the connection state objects are (currently) #name and #to_sym, which will return one of not_authenticated, authenticated, selected, or logout.

From RFC9051:

                   +----------------------+
                   |connection established|
                   +----------------------+
                              ||
                              \/
            +--------------------------------------+
            |          server greeting             |
            +--------------------------------------+
                      || (1)       || (2)        || (3)
                      \/           ||            ||
            +-----------------+    ||            ||
            |Not Authenticated|    ||            ||
            +-----------------+    ||            ||
             || (7)   || (4)       ||            ||
             ||       \/           \/            ||
             ||     +----------------+           ||
             ||     | Authenticated  |<=++       ||
             ||     +----------------+  ||       ||
             ||       || (7)   || (5)   || (6)   ||
             ||       ||       \/       ||       ||
             ||       ||    +--------+  ||       ||
             ||       ||    |Selected|==++       ||
             ||       ||    +--------+           ||
             ||       ||       || (7)            ||
             \/       \/       \/                \/
            +--------------------------------------+
            |               Logout                 |
            +--------------------------------------+
                              ||
                              \/
                +-------------------------------+
                |both sides close the connection|
                +-------------------------------+

Legend for the above diagram:

(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 or UNSELECT command, unsolicited CLOSED response code, or
    failed SELECT or EXAMINE command
(7) LOGOUT command, server shutdown, or connection closed

Before the server greeting, the state is not_authenticated.
After the connection closes, the state remains logout.

nevans added 2 commits March 11, 2025 13:20
Because a `#connection_state` attribute will be added, I'd like to
consistently name the connection states everywhere they are used.
Tracking connection state can have many uses.  But in this version,
we're only tracking the session state and exposing a `#connection_state`
attribute reader.

For forward-compatibility, the only documented methods on the connection
state objects are (currently) `#name` and `#to_sym`, which will return
one of `not_authenticated`, `authenticated`, `selected`, or `logout`.

From RFC9051:
```
                   +----------------------+
                   |connection established|
                   +----------------------+
                              ||
                              \/
            +--------------------------------------+
            |          server greeting             |
            +--------------------------------------+
                      || (1)       || (2)        || (3)
                      \/           ||            ||
            +-----------------+    ||            ||
            |Not Authenticated|    ||            ||
            +-----------------+    ||            ||
             || (7)   || (4)       ||            ||
             ||       \/           \/            ||
             ||     +----------------+           ||
             ||     | Authenticated  |<=++       ||
             ||     +----------------+  ||       ||
             ||       || (7)   || (5)   || (6)   ||
             ||       ||       \/       ||       ||
             ||       ||    +--------+  ||       ||
             ||       ||    |Selected|==++       ||
             ||       ||    +--------+           ||
             ||       ||       || (7)            ||
             \/       \/       \/                \/
            +--------------------------------------+
            |               Logout                 |
            +--------------------------------------+
                              ||
                              \/
                +-------------------------------+
                |both sides close the connection|
                +-------------------------------+
```
> Legend for the above diagram:
>
> (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 or UNSELECT command, unsolicited CLOSED response code, or
>     failed SELECT or EXAMINE command
> (7) LOGOUT command, server shutdown, or connection closed

Before the server greeting, the state is `not_authenticated`.
After the connection closes, the state remains `logout`.
@nevans nevans merged commit 27d0cb6 into master Mar 11, 2025
37 checks passed
@nevans nevans deleted the track-connection-state branch March 11, 2025 22:46
@nevans nevans added the enhancement New feature or request label Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants