Mail protocols
The IMAP, POP3 and ManageSieve listeners follow the connection sequence shared by all interactive protocols. What differs between them is the protocol dialogue. For each protocol, this page lists the commands that the proxy answers before authentication, the authentication commands it accepts, and how it opens the session on the backend.
Two rules apply to all three protocols. Cleartext authentication is gated on TLS, as described under Authentication mechanisms, and LOGIN exchanges are replayed as PLAIN, as described under Authentication replay.
The IMAP listener serves implicit TLS, usually on port 993, or STARTTLS, usually on port 143, according to its tls mode.
Before authentication
Section titled “Before authentication”On connection, the proxy sends an untagged OK greeting with the advertised capabilities and the configured banner. Until the client authenticates, the proxy handles a small set of commands itself:
CAPABILITYis answered with the advertised capabilities.NOOPandIDare acknowledged.LOGOUTends the connection.STARTTLSupgrades the connection, on a STARTTLS listener.
Other commands are refused as not allowed before authentication.
The capabilities are the advertise list of [capabilities.imap], followed by the available AUTH= mechanisms. When cleartext authentication is not permitted on the connection, the proxy advertises LOGINDISABLED. On a STARTTLS listener, STARTTLS is advertised until the connection is upgraded.
Authentication
Section titled “Authentication”The proxy accepts two commands. AUTHENTICATE works with PLAIN, LOGIN, OAUTHBEARER or XOAUTH2, with the initial response either on the command line (SASL-IR) or after a continuation. An initial response on the command line may be as large as the 64 KiB request limit, which leaves room for large OAuth tokens. The LOGIN command is treated as PLAIN.
A malformed command receives one BAD reply, and the proxy discards the rest of its line before reading the next command.
A literal that would not fit in the 64 KiB request limit is refused before its data is read. A synchronizing literal ({N}) receives a tagged BAD [TOOBIG] instead of the continuation, and the client may send another command. A non-synchronizing literal ({N+}) ends the connection with * BYE [TOOBIG], because its data is already on the way (RFC 7888). A literal size that does not fit in 32 bits is treated the same way.
Backend session
Section titled “Backend session”The proxy connects to the destination’s IMAP endpoint and reads the greeting. On a STARTTLS endpoint, it issues STARTTLS and upgrades the connection. When the greeting carries a capability list, the proxy first checks that STARTTLS is advertised in it. After the upgrade, it sends CAPABILITY, and from then on relies only on that list, as RFC 2595 requires. It then checks that the connection is encrypted, unless the destination allows plaintext authentication.
When the destination uses XCLIENT forwarding and the backend’s capabilities list ID, the proxy announces the client with an ID command. The command carries the client’s and the proxy’s addresses and ports, the forwarding time-to-live, a session identifier and the transport security.
The proxy then replays the authentication, adapting it to what the backend supports. The initial response is sent on the command line only when the backend advertised SASL-IR, either in its greeting or, on a STARTTLS endpoint, in its capabilities after the upgrade. Otherwise, it is sent after the backend’s continuation, which servers without SASL-IR require.
The proxy relays the result and, on success, joins the connections. From then on, client and backend exchange IMAP directly, including long IDLE sessions, until the connection closes or stays idle for longer than server.bridge_idle.
The POP3 listener serves implicit TLS, usually on port 995, or STARTTLS, usually on port 110.
Before authentication
Section titled “Before authentication”On connection, the proxy sends a +OK greeting with the configured banner. It answers CAPA, NOOP, UTF8 and QUIT, begins TLS on STLS on a STARTTLS listener, and answers APOP as unsupported.
The CAPA response always lists TOP, RESP-CODES, PIPELINING, EXPIRE NEVER, UIDL, UTF8 and IMPLEMENTATION Stalwart Server. The rest depends on the connection. USER and the PLAIN and LOGIN mechanisms are listed only when cleartext authentication is permitted on the connection. When it is not, the SASL line still lists OAUTHBEARER and XOAUTH2. On a STARTTLS listener, the response also lists STLS until the upgrade.
Authentication
Section titled “Authentication”The proxy accepts two forms of authentication. The USER and PASS commands are held until PASS arrives, and are then treated as PLAIN. AUTH works with PLAIN, LOGIN, OAUTHBEARER or XOAUTH2, with the initial response either on the command line or after a continuation. AUTH without an argument lists the available mechanisms.
Backend session
Section titled “Backend session”The proxy connects to the destination’s POP3 endpoint and reads the +OK greeting. On a STARTTLS endpoint, it sends CAPA, checks that STLS is advertised, upgrades the connection, and sends CAPA again over TLS. It then checks that the connection is encrypted.
When the destination uses XCLIENT forwarding and the backend advertises XCLIENT in its greeting or, on a STARTTLS endpoint, in its CAPA reply after the upgrade (either is enough: Dovecot lists it only in the greeting), the proxy announces the client with an XCLIENT command. The command carries the client’s and the proxy’s addresses, a session identifier and the transport security. The proxy then replays the authentication, relays the result, and on success joins the connections.
The authentication is replayed with AUTH and the initial response on the same line (RFC 5034), so POP3 backends must support AUTH with an initial response. The response goes after the server’s empty + challenge instead when it would make the command longer than 255 octets, or when the CAPA reply received over TLS on a STARTTLS endpoint does not list SASL. Implicit TLS and plain endpoints are not asked for CAPA, to save a round trip on every login.
ManageSieve
Section titled “ManageSieve”The ManageSieve listener lets clients manage the Sieve scripts of their account on the backend. It is usually served with STARTTLS on port 4190.
Before authentication
Section titled “Before authentication”A ManageSieve server starts by announcing its capabilities, so on connection the proxy sends a capability block followed by OK. The block contains the following:
- The
implementationstring and thesieveextensions of[capabilities.managesieve] - The protocol version
- The SASL mechanisms
STARTTLS, on a STARTTLS listener before the upgrade
The proxy answers CAPABILITY (by sending the block again), NOOP, LOGOUT and STARTTLS.
Authentication
Section titled “Authentication”The proxy accepts AUTHENTICATE with PLAIN, LOGIN, OAUTHBEARER or XOAUTH2. The initial response may be given on the command line, as a quoted string, or as a literal after the proxy’s continuation, following the ManageSieve literal syntax. In a LOGIN exchange, the proxy sends its prompts as literals. Clients send literals in the non-synchronizing form ({N+}), as RFC 5804 requires; a synchronizing literal ({N}) is read as well, but the proxy sends no continuation for it. A literal that would not fit in the 64 KiB request limit, of either form, ends the connection with BYE, because its data is already on the way.
Backend session
Section titled “Backend session”The proxy connects to the destination’s ManageSieve endpoint and reads the capability block. On a STARTTLS endpoint, it checks that STARTTLS is advertised, issues it, and reads the capabilities again after the upgrade. It then checks that the connection is encrypted.
When the destination uses XCLIENT forwarding and the backend advertises XCLIENT, the proxy announces the client with an XCLIENT command. The command carries the client’s and the proxy’s addresses, a session identifier and the transport security. The proxy then replays the authentication, relays the result, and on success joins the connections.
The authentication is replayed with AUTHENTICATE and the initial response as a quoted string, or as a non-synchronizing literal ({N+}) when it is longer than 1024 octets, the RFC 5804 limit for quoted strings. Backend challenges may be quoted strings or literals; the proxy answers each with a quoted string, so an exchange that the backend ends with an error challenge (for example OAUTHBEARER with an expired token) completes with the backend’s verdict instead of waiting for the backend timeout.