Add a Stalwart integration target for the JMAP source #65

Merged
svc-agent-writer merged 1 commit from feat/stalwart-target into main 2026-10-31 23:49:57 +00:00

Closes #63. Part of epic #51 (phase 6).

What this adds

  • scripts/stalwart.sh up|down|logs, shaped like the blade's greenmail.sh:

    • It runs stalwartlabs/stalwart v0.16.26, pinned by its multi-arch digest. That release was published 2026-10-11; v0.16.27 and v1.0.x are under two weeks old.
    • JMAP is plain HTTP on 127.0.0.1:18080. STALWART_PUBLIC_URL makes the session's apiUrl and downloadUrl name that port.
    • IMAPS is on 127.0.0.1:13993, with the blade's localhost test certificate.
    • There is no volume, so up always starts from nothing and runs twice in a row. down removes the container and local/stalwart/.
  • scripts/stalwart_setup.py, stdlib only. It skips the web wizard in three phases, with a container restart between each:

    1. Submit x:Bootstrap/set as a recovery admin with a random password that lives for one run.
    2. Create the certificate, the user bot@example.test and an x:ApiKey for that user.
    3. Wait until the JMAP session answers the key and IMAPS verifies against the test CA.

    The password and the key go to mode-0600 files. The polls use /healthz/live, which needs no login.

  • tests/integration/test_stalwart.py, gated on MAILMIND_STALWART=1. Each test empties the account first, then places and changes mail over IMAP, never through the outbox. The tests cover:

    • backfill across two mailboxes, plus check();
    • a delta pass with one add, one flags change, one move and one del, where the moved message keeps its stable id;
    • the switch from IMAP on one account id, which keeps the triage class and leaves no IMAP rows.
  • Make targets: make test-integration now starts both GreenMail and Stalwart. make test-stalwart runs Stalwart alone. README and CLAUDE.md are updated.

Findings against the brief

  • The API key works as a bearer token on JMAP mail (Mailbox/get, Email/get, Email/changes). The brief's stop condition did not fire, and JmapClient is unchanged.
  • Accounts. In 0.16, accounts and keys are JMAP objects (x:Account, x:ApiKey, x:Certificate, x:Domain). The image ships no stalwart-cli, so setup calls the API directly.
  • Header search. Stalwart indexes IMAP SEARCH text asynchronously. The tests find uids by fetching the Message-ID header instead.
  • Failed-login ban. No test sends a wrong password. Auth-failure tests stay on the fake server.

Checks

  • make test-integration: 11 passed (8 GreenMail, 3 Stalwart).
  • make test-stalwart: 3 passed. Afterwards no container and no state directory remain.
  • make check: 163 passed. ruff, mypy and pip-audit are clean.

🤖 Generated with Claude Code

Closes #63. Part of epic #51 (phase 6). ## What this adds - **`scripts/stalwart.sh up|down|logs`**, shaped like the blade's `greenmail.sh`: - It runs `stalwartlabs/stalwart` v0.16.26, pinned by its multi-arch digest. That release was published 2026-10-11; v0.16.27 and v1.0.x are under two weeks old. - JMAP is plain HTTP on `127.0.0.1:18080`. `STALWART_PUBLIC_URL` makes the session's `apiUrl` and `downloadUrl` name that port. - IMAPS is on `127.0.0.1:13993`, with the blade's `localhost` test certificate. - There is no volume, so `up` always starts from nothing and runs twice in a row. `down` removes the container and `local/stalwart/`. - **`scripts/stalwart_setup.py`**, stdlib only. It skips the web wizard in three phases, with a container restart between each: 1. Submit `x:Bootstrap/set` as a recovery admin with a random password that lives for one run. 2. Create the certificate, the user `bot@example.test` and an `x:ApiKey` for that user. 3. Wait until the JMAP session answers the key and IMAPS verifies against the test CA. The password and the key go to mode-0600 files. The polls use `/healthz/live`, which needs no login. - **`tests/integration/test_stalwart.py`**, gated on `MAILMIND_STALWART=1`. Each test empties the account first, then places and changes mail over IMAP, never through the outbox. The tests cover: - backfill across two mailboxes, plus `check()`; - a delta pass with one add, one flags change, one move and one del, where the moved message keeps its stable id; - the switch from IMAP on one account id, which keeps the triage class and leaves no IMAP rows. - **Make targets:** `make test-integration` now starts both GreenMail and Stalwart. `make test-stalwart` runs Stalwart alone. README and CLAUDE.md are updated. ## Findings against the brief - **The API key works as a bearer token on JMAP mail** (`Mailbox/get`, `Email/get`, `Email/changes`). The brief's stop condition did not fire, and `JmapClient` is unchanged. - **Accounts.** In 0.16, accounts and keys are JMAP objects (`x:Account`, `x:ApiKey`, `x:Certificate`, `x:Domain`). The image ships no `stalwart-cli`, so setup calls the API directly. - **Header search.** Stalwart indexes IMAP `SEARCH` text asynchronously. The tests find uids by fetching the Message-ID header instead. - **Failed-login ban.** No test sends a wrong password. Auth-failure tests stay on the fake server. ## Checks - `make test-integration`: 11 passed (8 GreenMail, 3 Stalwart). - `make test-stalwart`: 3 passed. Afterwards no container and no state directory remain. - `make check`: 163 passed. ruff, mypy and pip-audit are clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
scripts/stalwart.sh starts Stalwart 0.16.26, pinned by digest, with one test user over IMAPS and JMAP. Setup skips the web wizard: it submits the Bootstrap object, loads the blade's localhost certificate, and creates the user and an API key over the JMAP management API. The API key works as a bearer token on JMAP mail, so the client needs no change.

The integration tests run the JMAP source against it: backfill, a delta pass with an add, a flag change, a move that keeps its id, and a delete, and the switch from IMAP on one account, which keeps the triage class. make test-integration runs Stalwart beside GreenMail; make test-stalwart runs it alone.

Closes #63

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.