feat: mail aliases and per-domain catch-all

Merged
UR
3d ago
+4011-7

What it does

  • Aliases: a user can create extra addresses on their own domains (e.g. sales@x.id) that deliver into one of their mailboxes. List / create / delete, 20 per user, owner-only (an IRIS admin may delete anyone’s).
  • Catch-all: per domain, unknown recipients (no mailbox or alias of their own) route to one chosen mailbox, or are rejected again when disabled. Caller must own a mailbox on the domain or be an IRIS admin. The web UI warns that catch-all invites more spam.
  • Web UI for both on the Organize (#/organize) page. While the admin credential is unset the sections show “not configured on this server” instead of failing the page.

How it is stored (Stalwart)

Aliases are the account’s alias list via the Stalwart management JMAP API: x:Account/set whole-list replacement on the mailbox’s server account. Catch-all is the domain’s catchAllAddress via x:Domain/set. Both are mirrored in the IRIS database (migration 015_aliases.sql: mail_aliases, domain_catch_all, NULL target = disabled) and audited (alias.create, alias.delete, catchall.set).

The management API is a separate loopback listener from the user JMAP API (installer binds it to 127.0.0.1:8080; user JMAP stays on 8092), so this adds:

  • STALWART_MANAGEMENT_URL (default http://127.0.0.1:8080)
  • STALWART_ADMIN_USER / STALWART_ADMIN_PASSWORD

While either admin value is empty the alias and catch-all endpoints fail closed with 503 aliases_unavailable; nothing else is affected.

How to test

  • cargo fmt --check, cargo clippy --all-targets --all-features -- -D warnings, cargo test --all-targets (285 passed), web npm run typecheck + npm run build (CSP-clean). 12 new handler tests run against a stateful fake Stalwart management server asserting the exact x:Account/set / x:Domain/set patch shapes and admin basic auth.
  • Live: set the three env vars, create an alias on a test domain, send mail to it, confirm delivery; enable catch-all, mail a made-up address on the domain, confirm it lands in the target; disable it and confirm rejection.

Deploy note

Add STALWART_ADMIN_USER / STALWART_ADMIN_PASSWORD to the VPS .env at deploy time (never committed). The account must hold sysAccountGet, sysAccountUpdate, sysDomainGet and sysDomainUpdate (a System Administrator role account); whether the provisioned admin account has those permissions still needs a VPS check.

Design deviations (vs alias-catchall-design.md)

  • Whole-list read-modify-write of the server alias list under organize_lock instead of index patching (positions shift on delete).
  • Mirror table has no position column; rows match by address.
  • domain_catch_all has no separate enabled column (NULL target = disabled); no enable/disable toggle endpoint in v1.
  • The alias flag is enabled, not enable; the management listener is port 8080, not 8092 (separate STALWART_MANAGEMENT_URL).
  • One test-only quirk worth knowing: query_scalar::<String> on a NULL SQLite column decodes as "", so the catch-all tests read the nullable column as Option<String>.

Out of scope, deliberately

No integration with bercocok-tanam or any token-harvesting / mass-account-creation tooling, no temp-email provider API, no bulk account creation. This is a normal mail feature only.

Unverified (needs a VPS check after deploy approval)

  • Live Stalwart version and that the management listener really is on 8080.
  • x:Domain/query filter shape and the exact EmailAlias JSON shape against the live schema (code accepts both array and index-keyed list forms).
  • End-to-end alias / catch-all behaviour on a non-production domain.

Summary by CodeRabbit

  • New Features
    • Manage email aliases from the Organize page: add aliases, choose their delivery mailbox, and remove them.
    • Configure domain catch-all delivery to send unmatched messages to a mailbox on that domain, or turn catch-all off.
    • Alias creation checks the address and mailbox, prevents duplicate addresses, and is limited to 20 aliases per user.
    • Alias and catch-all controls require Stalwart management credentials and are unavailable when credentials are missing or the service cannot provide them.
  • Bug Fixes
    • Mailboxes with aliases can’t be unlinked until those aliases are removed.