mail.imap.server
import mail
Everything here is re-exported by
import mailis enough and the names are called asmail.*. Importingmail.imap.serveron its own works too and reaches the same definitions.
The serving end of IMAP.
ImapServer accepts connections, runs the session state machine, and
answers every command out of a MailStore. What mail there is and where
it lives is the store’s business; this knows only the protocol.
import mail.imap { ImapServer, MaildirStore }
var store = MaildirStore('/var/mail')
store.add_account('ann', secret)
ImapServer({ port: 143 }, store).listen()
Constants
BASE_CAPABILITIES
mail.BASE_CAPABILITIES = [...]
ALLOWED_FLAGS
mail.ALLOWED_FLAGS = [...]
DEFAULT_TIMEOUT
mail.DEFAULT_TIMEOUT = 1800000
Classes
ImapSession
class mail.ImapSession
One connection, and what it has got as far as doing.
- printable — has a
@to_string(), soechoandprint()show something useful
Constructor
mail.ImapSession(peer: string, secure: bool)
Parameters
peer(string)secure(bool)
ImapSession.is_selected()
mail.ImapSession.is_selected() -> bool
Whether a mailbox is open.
Returns bool
ImapSession.to_string()
mail.ImapSession.to_string()
ImapServer
class mail.ImapServer
A server that serves mail.
- printable — has a
@to_string(), soechoandprint()show something useful
Constructor
mail.ImapServer(options: ?dict, store)
| option | default | what it does |
|---|---|---|
host | 127.0.0.1 | the address to bind |
port | 143 | the port to bind |
greeting | Zuri IMAP ready | what to say on connecting |
timeout | 1800000 | milliseconds a client may go quiet |
require_tls | false | refuse to authenticate without TLS |
Parameters
options(?dict)store(MailStore) — Where the mail is.
ImapServer.on_connect()
mail.ImapServer.on_connect(handler) -> ImapServer
Called with the session when a connection opens.
Parameters
handler(function(1))
Returns ImapServer — itself.
ImapServer.on_close()
mail.ImapServer.on_close(handler) -> ImapServer
Called with the session when a connection closes.
Parameters
handler(function(1))
Returns ImapServer — itself.
ImapServer.on_error()
mail.ImapServer.on_error(handler) -> ImapServer
Called with the error and the session when something inside the server fails.
Parameters
handler(function(2))
Returns ImapServer — itself.
ImapServer.use_tls()
mail.ImapServer.use_tls(cert_chain: string, private_key: string) -> ImapServer
Gives the server a certificate, which is what lets it offer STARTTLS.
Parameters
cert_chain(string)private_key(string)
Returns ImapServer — itself.
ImapServer.set_tls_config()
mail.ImapServer.set_tls_config(config) -> ImapServer
Gives the server a TLS configuration built elsewhere.
Parameters
config(TlsConfig)
Returns ImapServer — itself.
ImapServer.bind()
mail.ImapServer.bind() -> ImapServer
Binds the listening socket without accepting anything yet.
Returns ImapServer — itself.
ImapServer.address()
mail.ImapServer.address() -> SocketAddr
The address the server is listening on.
Returns SocketAddr
ImapServer.accept()
mail.ImapServer.accept() -> ImapServer
Accepts one connection and serves it to the end.
Returns ImapServer — itself.
ImapServer.listen()
mail.ImapServer.listen() -> ImapServer
Accepts connections one after another until close().
One at a time: an IMAP connection is long-lived, so a server expecting more than one client at once wants a worker per connection.
Returns ImapServer — itself.
ImapServer.close()
mail.ImapServer.close() -> ImapServer
Stops the accept loop and closes the listening socket.
Returns ImapServer — itself.
ImapServer.is_listening()
mail.ImapServer.is_listening() -> bool
Whether the accept loop is running.
Returns bool
ImapServer.serve_connection()
mail.ImapServer.serve_connection(client) -> ImapServer
Serves one already-accepted connection to the end.
Parameters
client(TcpStream)
Returns ImapServer — itself.
ImapServer.to_string()
mail.ImapServer.to_string()
2026, Richard Ore and Zuri contributors