Add a Stalwart integration target for the IMAP and JMAP sources #63

Closed
opened 2026-10-31 22:20:13 +00:00 by svc-agent-writer · 1 comment

Parent: #51 (Phase 6). Decision: ADR 0006, Consequences (one server with both IMAP and JMAP). Split from #55 at triage.

#55 tests the JMAP source against a fake JMAP server in the test process. This issue adds a real server: Stalwart, which serves IMAP and JMAP for the same account from one container.

Known constraints (checked 2026-11-01 against the Stalwart Docker docs)

  • Image stalwartlabs/stalwart (also ghcr.io/stalwartlabs/stalwart). Pin it by digest, like the GreenMail and base images.
  • A fresh container starts in bootstrap mode with a setup wizard. A test run must skip it: either the bootstrap API, or a written config.json applied with the CLI in recovery mode. STALWART_RECOVERY_ADMIN=admin:<password> sets a known admin credential.
  • The docs show no scripted way to create an account; find one through the CLI or the management API.
  • Set server.hostname, or the session's apiUrl names the container's internal host.
  • Stalwart bans an address after 100 failed logins a day by default; a test suite must not trip it.

Acceptance

  • A script like ../imap-blade-mcp/scripts/greenmail.sh: up starts a configured Stalwart with one test account and a known CA or plain HTTP on localhost, down removes it.
  • A make target runs the JMAP integration tests against it; make test-integration runs it too, or the README says why not.
  • The tests from #55 that use the fake server also pass against Stalwart: backfill, a delta pass, a move that keeps the id, and the IMAP-to-JMAP switch on one account.

Blocked by

Filed under: operator word "advice/leans accepted" sha256:70868845a7df

Parent: #51 (Phase 6). Decision: ADR 0006, Consequences (one server with both IMAP and JMAP). Split from #55 at triage. #55 tests the JMAP source against a fake JMAP server in the test process. This issue adds a real server: Stalwart, which serves IMAP and JMAP for the same account from one container. ## Known constraints (checked 2026-11-01 against the Stalwart Docker docs) - Image `stalwartlabs/stalwart` (also `ghcr.io/stalwartlabs/stalwart`). Pin it by digest, like the GreenMail and base images. - A fresh container starts in bootstrap mode with a setup wizard. A test run must skip it: either the bootstrap API, or a written `config.json` applied with the CLI in recovery mode. `STALWART_RECOVERY_ADMIN=admin:<password>` sets a known admin credential. - The docs show no scripted way to create an account; find one through the CLI or the management API. - Set `server.hostname`, or the session's `apiUrl` names the container's internal host. - Stalwart bans an address after 100 failed logins a day by default; a test suite must not trip it. ## Acceptance - A script like `../imap-blade-mcp/scripts/greenmail.sh`: `up` starts a configured Stalwart with one test account and a known CA or plain HTTP on localhost, `down` removes it. - A make target runs the JMAP integration tests against it; `make test-integration` runs it too, or the README says why not. - The tests from #55 that use the fake server also pass against Stalwart: backfill, a delta pass, a move that keeps the id, and the IMAP-to-JMAP switch on one account. ## Blocked by - #55 Filed under: operator word "advice/leans accepted" sha256:70868845a7df
Author
Member

This was generated by AI during triage.

Agent Brief

Category: enhancement
Summary: Add a Stalwart container as a second integration target, and run the JMAP source tests against it as well as against the fake server.

Correction to the issue body: the line "the docs show no scripted way to create an account" is out of date. Stalwart 0.16 removed the /api/principal REST API. Management now runs through JMAP objects with an x: prefix (capability urn:stalwart:jmap), and stalwart-cli create <Object> --field key=value creates them. An account is probably an x:Account object; confirm the name in the Stalwart object reference before you use it.

Current behavior:

  • The JMAP source tests run only against FakeJmap, an in-process fake server.
  • The only integration target is GreenMail, IMAP only, started by the blade's scripts/greenmail.sh and driven by make test-integration with MAILMIND_GREENMAIL=1.

Desired behavior:

  • A script in this repo, shaped like the blade's greenmail.sh, with up and down.
  • up must:
    1. Start a Stalwart container pinned by image digest. Pick a release at least two weeks old, 0.16 or later.
    2. Get past bootstrap mode without the web wizard.
    3. Create one test account, then a credential that the JMAP source can send as Authorization: Bearer <token>.
    4. Write that token to an owner-only file (mode 0600). The file name must not end in .token.
    5. Wait until both IMAPS and the JMAP session answer.
  • down removes the container and the files it wrote.
  • IMAPS uses the blade's test certificate (localhost.pem, localhost.key) and is verified with the blade's ca.pem.
  • JMAP may be plain HTTP on 127.0.0.1. The session URL check accepts that, as long as Stalwart's apiUrl and downloadUrl also use http://127.0.0.1:<port>. Set the server hostname so that they do.
  • A make target runs the Stalwart tests. make test-integration runs them too, or the README says why it does not.
  • Tests marked integration and gated on an env var (like MAILMIND_GREENMAIL) drive a real JmapSource against Stalwart.
  • Tests put mail in place, and change it, through the server itself: JMAP Email/import and Email/set from the test's own client, or IMAP APPEND, STORE and MOVE. They never go through mailmind's outbox. JMAP writes are #57.

Key interfaces:

  • JmapSource(account, store, config): run_pass(), check(). JmapAccountConfig takes source = "jmap", session_url and credential_file.
  • MirrorAccountConfig: an IMAP account on the same Stalwart user. It is needed for the switch test.
  • Store:
    • get_by_source, get_state(account, "email_state") and has_imap_rows;
    • copy_assessments and copy_embeddings, already called by the switch.
  • ids.encode_source(account, source_id): the stable id, which must be the same before and after a move.

Acceptance criteria:

  • up then down leaves no container and no secret file behind. up run twice in a row succeeds.
  • Backfill: three or more messages in two mailboxes mirror with the correct mailbox, mailboxes, flags and Message-ID.
  • Delta pass: an added message, a keyword change and a destroy each give one add, flags and del change.
  • Move: a message moved between mailboxes keeps its stable id and logs one move.
  • Switch: an account mirrored first as IMAP and then as JMAP, with the same account id, keeps a triage class set on its IMAP row. Afterwards has_imap_rows is false.
  • JmapSource.check() returns an OK jmap host=127.0.0.1 line.
  • One suite run stays far below Stalwart's 100-failed-logins-a-day ban. No test sends a wrong password to Stalwart. Auth-failure tests stay on FakeJmap.
  • make check still passes, and the existing GreenMail integration tests still pass.

Stop and report, do not work around:

  • If no Stalwart credential works as a bearer token for JMAP mail, stop and report what you tried. Do not add Basic auth to JmapClient. It would change the credential surface ADR 0006 §11 decides, and that needs the operator's ruling. The sources disagree here: the current API-key page says keys work as bearer tokens on JMAP, but other material says keys cannot reach mail protocols. The OAuth password grant is not supported, so a script cannot get an access token without a person.
  • If getting past bootstrap needs anything beyond a config file, the recovery admin or stalwart-cli, also stop and report. One example is a web-only step. One report against 0.16 also disputes the format of STALWART_RECOVERY_ADMIN.

Out of scope:

  • JMAP push (#56) and JMAP writes through the outbox (#57).
  • Any change to JmapClient auth or to ADR 0006.
  • CI files (.woodpecker/*): the architect adds these.
  • Replacing GreenMail. It stays for the IMAP edge cases it covers.
> *This was generated by AI during triage.* ## Agent Brief **Category:** enhancement **Summary:** Add a Stalwart container as a second integration target, and run the JMAP source tests against it as well as against the fake server. **Correction to the issue body:** the line "the docs show no scripted way to create an account" is out of date. Stalwart 0.16 removed the `/api/principal` REST API. Management now runs through JMAP objects with an `x:` prefix (capability `urn:stalwart:jmap`), and `stalwart-cli create <Object> --field key=value` creates them. An account is probably an `x:Account` object; confirm the name in the Stalwart object reference before you use it. **Current behavior:** - The JMAP source tests run only against `FakeJmap`, an in-process fake server. - The only integration target is GreenMail, IMAP only, started by the blade's `scripts/greenmail.sh` and driven by `make test-integration` with `MAILMIND_GREENMAIL=1`. **Desired behavior:** - A script in this repo, shaped like the blade's `greenmail.sh`, with `up` and `down`. - `up` must: 1. Start a Stalwart container pinned by image digest. Pick a release at least two weeks old, 0.16 or later. 2. Get past bootstrap mode without the web wizard. 3. Create one test account, then a credential that the JMAP source can send as `Authorization: Bearer <token>`. 4. Write that token to an owner-only file (mode 0600). The file name must not end in `.token`. 5. Wait until both IMAPS and the JMAP session answer. - `down` removes the container and the files it wrote. - IMAPS uses the blade's test certificate (`localhost.pem`, `localhost.key`) and is verified with the blade's `ca.pem`. - JMAP may be plain HTTP on `127.0.0.1`. The session URL check accepts that, as long as Stalwart's `apiUrl` and `downloadUrl` also use `http://127.0.0.1:<port>`. Set the server hostname so that they do. - A make target runs the Stalwart tests. `make test-integration` runs them too, or the README says why it does not. - Tests marked `integration` and gated on an env var (like `MAILMIND_GREENMAIL`) drive a real `JmapSource` against Stalwart. - Tests put mail in place, and change it, through the server itself: JMAP `Email/import` and `Email/set` from the test's own client, or IMAP APPEND, STORE and MOVE. They never go through mailmind's outbox. JMAP writes are #57. **Key interfaces:** - `JmapSource(account, store, config)`: `run_pass()`, `check()`. `JmapAccountConfig` takes `source = "jmap"`, `session_url` and `credential_file`. - `MirrorAccountConfig`: an IMAP account on the same Stalwart user. It is needed for the switch test. - `Store`: - `get_by_source`, `get_state(account, "email_state")` and `has_imap_rows`; - `copy_assessments` and `copy_embeddings`, already called by the switch. - `ids.encode_source(account, source_id)`: the stable id, which must be the same before and after a move. **Acceptance criteria:** - [ ] `up` then `down` leaves no container and no secret file behind. `up` run twice in a row succeeds. - [ ] Backfill: three or more messages in two mailboxes mirror with the correct `mailbox`, `mailboxes`, flags and Message-ID. - [ ] Delta pass: an added message, a keyword change and a destroy each give one `add`, `flags` and `del` change. - [ ] Move: a message moved between mailboxes keeps its stable id and logs one `move`. - [ ] Switch: an account mirrored first as IMAP and then as JMAP, with the same account id, keeps a triage class set on its IMAP row. Afterwards `has_imap_rows` is false. - [ ] `JmapSource.check()` returns an `OK jmap host=127.0.0.1` line. - [ ] One suite run stays far below Stalwart's 100-failed-logins-a-day ban. No test sends a wrong password to Stalwart. Auth-failure tests stay on `FakeJmap`. - [ ] `make check` still passes, and the existing GreenMail integration tests still pass. **Stop and report, do not work around:** - If no Stalwart credential works as a bearer token for JMAP mail, stop and report what you tried. Do not add Basic auth to `JmapClient`. It would change the credential surface ADR 0006 §11 decides, and that needs the operator's ruling. The sources disagree here: the current API-key page says keys work as bearer tokens on JMAP, but other material says keys cannot reach mail protocols. The OAuth password grant is not supported, so a script cannot get an access token without a person. - If getting past bootstrap needs anything beyond a config file, the recovery admin or `stalwart-cli`, also stop and report. One example is a web-only step. One report against 0.16 also disputes the format of `STALWART_RECOVERY_ADMIN`. **Out of scope:** - JMAP push (#56) and JMAP writes through the outbox (#57). - Any change to `JmapClient` auth or to ADR 0006. - CI files (`.woodpecker/*`): the architect adds these. - Replacing GreenMail. It stays for the IMAP edge cases it covers.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dev/mail-mind-mcp#63
No description provided.