tmail.sh

Tern in one page

Tern is one program and a store on disk. This page says who comes in at which door and where mail ends up. The other pages go into the protocol, the storage engine, search, and how it stands against Cyrus IMAP.

One process, five doors

The server is a single process, maild. It opens the store and serves everything from it: the gRPC API at two doors, LMTP for arriving mail, IMAP for other mail clients, and the page people sign in at.

The two gRPC doors serve the same API, mail.v1. It is the native protocol: the apps use nothing else, and IMAP is implemented beside it on the same store, not underneath it. See the protocol.

A development server, with the services' door and LMTP
maild store --blobs blobs \
  --grpc 127.0.0.1:2500 --lmtp 127.0.0.1:2400 \
  --token-file token

The names in the commands are from before the project was called Tern: the daemon is still maild and the API's package mail.v1.

Labels, conversations, one state

Mail coming in

Mail arrives by LMTP. Each message goes through the person's rules, which say what it is labelled with and whether it is kept at all. It is then taken apart, put together again, compared with what arrived, and written in one batch with its index rows and the words of its text. When LMTP answers, the message is on disk and can be found by its words.

Mail going out

Send hands a message to the server's relay while the caller waits, and keeps a copy, with its Bcc, in Sent. The server keeps no queue. A caller that got no answer asks again, and a message whose Message-ID the person has sent already is not sent twice.

Signing in

The clients

The apps are called tmail. A user interface calls only the core, never gRPC: the core, in Rust, holds the connection, the copy of the mailbox, the outbox and what each view shows.

ClientBuilt withCopy of the mailbox
LinuxGTK 4, libadwaita, Rustwhole, on the computer
iPhoneSwiftUI over the corewhole, on the phone
MacSwiftUI and AppKit over the corewhole, on the Mac
WebmailSvelte 5 and TypeScript; a small server in Rustnone: everything is asked of the server
tmaila command for agents, one for each tool of the assistantnone

The core finds out by itself that a server no longer answers: it asks its connection every 20 seconds whether the other end is there, and gives it up after 20 seconds without an answer.

The parts

CrateWhat it is
lsmThe sorted key-value engine: immutable runs with merge rules
mailstoreMail rows on the engine, delivery through a person's rules, reads, settings
blobstoreWhere large parts are kept: a directory, an S3-like store, or memory
msgpartsA raw message split into a skeleton and content-addressed parts, and put back byte for byte
mailqlThe query language: filters and pipes. No dependencies
sieveSieve as far as it is read: a script into its commands, to make rules of it
imapwire, mailimapIMAP on the wire, and IMAP sessions on the store
mailapiThe gRPC API and maild
mailclientThe clients' core, and the tmail command
cyrus-migrateMoves a mailbox from a Cyrus spool

What it takes to run

Not built yet

The API is declared unstable until the first release: mail.v1 may still change.

Next: the protocol