interplane.Get Omega
Read in your language

mailhand

mailhand: agents look after a person's email in seeded Omega. Maildir + MIME parsing, JSONL CLI and MCP, rule triage, policy-gated sending, hash-chained audit. Free (Apache-2.0).

Brought by drakestapleton

branch main Branches Tags History

mailhand / README.md

173 lines · 11852 bytes Raw Blame History Source

mailhand

mailhand lets software agents look after a person's email, so the person does almost nothing. The person runs one setup command, reads one summary file, and now and then says yes to a draft. Agents do the rest through a command line that prints JSON lines, or through the same operations as MCP tools. It is written in seeded Omega and is free software (Apache-2.0).

What it does

Setup (the person's one step)

./build.sh                         # needs the pinned omc as ./omc (see DEPENDENCIES.md)
build/mailhand setup --maildir "$HOME/Mail" --me me@example.org --name Me \
    --smtp unix:/run/user/1000/mail/smtp.sock

This creates ~/.mailhand/ (or --home DIR, or $MAILHAND_HOME) with config, policy, rules, approvals, drafts/, outbox/, sent/, labels/, audit.log, the address book, and the Maildir folders INBOX, Sent, Drafts and Archive when missing. The default policy sends nothing without approval. To approve a draft: build/mailhand approve --draft SHA (it shows the draft and waits for yes). Read ~/.mailhand/digest.txt after an agent runs digest.

For agents

mailhand list [--folder NAME|all] [--unread] [--since EPOCH|YYYY-MM-DD] [--from TEXT] [--thread HEX]
mailhand show --id FOLDER/UNIQUE        mailhand thread --id ID        mailhand search --query TEXT
mailhand triage [--id ID | --folder F]  mailhand mark-read --id ID     mailhand archive --id ID
mailhand move --id ID --folder NAME     mailhand label --id ID --label NAME [--remove] [--why TEXT]
mailhand draft-reply --id ID --body TEXT [--all]    mailhand draft-new --to A,B --subject S --body TEXT
mailhand drafts     mailhand queue-send --draft SHA     mailhand deliver     mailhand book
mailhand digest     mailhand audit [--limit N]          mailhand verify [--head HEX]
mailhand stats [--folder F|all]     (parse every message; counts only)
mailhand mcp        (MCP over stdio: the same operations as tools)

--thread HEX selects messages whose 16-hex thread field (first 8 bytes of SHA-256 of the root id: the first References id, else In-Reply-To, else Message-ID) equals HEX; thread --id ID follows the whole conversation across folders, including replies that name only their parent.

Output is one JSON object per line on stdout; diagnostics go to stderr. Exit codes: 0 ok, 1 usage, 2 not found, 3 refused by the send gate, 4 message refused by the parser, 5 path refused (traversal, symlink, outside the mail root), 6 I/O error, 7 audit chain broken, 8 delivery failed, 9 not set up.

Remote accounts (IMAP sync, SMTP submission over TLS)

The person writes the credentials file ~/.mailhand/accounts (or names another file with the config line accounts PATH). One block per account, key value lines, # comment lines:

account work
imap imaps://imap.example.org            # implicit TLS, port 993 unless :PORT is given
smtp submission://smtp.example.org       # STARTTLS on 587; or smtps://HOST (implicit TLS, 465)
user me@example.org
password the rest of this line, exactly
roots /etc/ssl/certs/ca-certificates.crt # optional trust store (this is the default)

connect 127.0.0.1 exists for tests only: the TCP connection goes to that address while the certificate is still checked against the host name. mailhand refuses the file unless it is a regular file (never followed through a symlink), owned by the user running mailhand, with mode 0600 or tighter (mode & 077 == 0), and at most 262144 bytes (the one buffer that holds it). A refusal exits 5 and names the file and its mode on stderr, never its content; a missing file exits 9. The password is read into that one buffer, used once for AUTHENTICATE PLAIN, LOGIN or AUTH PLAIN, and overwritten with zeros: it is never written to stdout, stderr, the audit log, a state file or MCP output, and the JSON records (which MCP returns) do not name the file.

TLS is the omtls library (TLS 1.3 written in seeded Omega, OmegaTls), built into mailhand from one commit named in DEPS (see DEPENDENCIES.md). A certificate that does not match the host name, has expired, or does not chain to the trust store stops the session before any command is sent (exit 6 for sync, 8 for deliver, with the reason on stderr).

Safety model

Limits

Check it yourself

You need the pinned compiler: the file PIN names the omega-mv revision and the sha256 of its seed/out/omc; copy that file to ./omc in this directory (sha256sum omc must print the omc-sha256 of PIN). You also need git: build.sh fetches the dependencies named in DEPS at their commits (see DEPENDENCIES.md). Then, from the repository root:

./build.sh tests/GATE_UNITS build/gate-bin && build/gate-bin ./omc

The gate reads PIN, checks the compiler's SHA-256 itself and refuses any other (exit 3), checks that no tracked file other than PIN restates the pin (MHGATE pincheck files=N restated=0), builds mailhand, the test SMTP sink and the fake mail servers from the unit lists build.sh generated in build/gen/, runs every scenario in tests/scenarios/ (synthetic mail only; the language is in tests/scenarios/README.md), then builds each mutant in tests/mutants.txt (for example the send policy check removed, the re-check in deliver removed, the warning field removed, the path checks removed) and requires a scenario to fail against each. The last line is MHGATE PASS scenarios=9 steps=864 mutants-killed=27/27. Scenario 50-robust cuts every fixture at 64 lengths and changes 256 single bytes in it (14,272 parser runs); each must give a result or a defined refusal, never a trap. Scenarios 55-creds, 60-imap and 70-smtp-tls run the remote-account code against the fake IMAP and SMTP servers in tests/srv/ (built by the gate as srv with the omtls test TLS server, over real TLS 1.3 to the host name mail.test with the omtls test certificates; including refused handshakes), including a credential leak scan of every file mailhand wrote.

Speed, on 10,000 generated messages (tests/gen/mkmaildir.om):

./build.sh && ./build.sh tests/BENCH_UNITS build/bench && build/bench build/mailhand build/bench-run

proofs/ has Lean 4 proofs of two models (see proofs/README.md).

Not done (next slices)