Add JMAP writes for the outbox #69

Merged
svc-agent-writer merged 1 commit from feat/jmap-writes into main 2026-11-01 00:19:28 +00:00

Closes #57. Parent: #51 (Phase 6). Decision: ADR 0006 §10, ADR 0004.

Changes

  • JMAP writes in jmap.py, applied by the sync worker as for IMAP:
    • A draft is the bytes from compose_draft, uploaded as a blob, then created with Email/import in Drafts with $draft and $seen. The inverse keeps the blob id that the import returns, because Stalwart stores the message under a new blob.
    • A flag change and a move are Email/set patches on keywords and mailboxIds. Each one carries ifInState, which is the Email state read just before the patch.
    • A concurrent change on the server fails the action with the code conflict. The action is failed, not refused, so the client can ask again. Nothing is overwritten.
    • A move removes the source mailbox and adds the target. A message that was already in the target (a Fastmail label) stays there on undo.
    • An undo replays the stored inverse. A draft is destroyed only while it keeps $draft and its blob id.
    • A read-only token refuses every write with unsupported. A draft needs from_address, because Identity/get needs the submission scope.
    • The mirror is updated at once, as the next pass would update it. The next pass then finds nothing to change.
    • EmailSubmission is never called.
  • Shared rules. The flag checks (flag_changes) and the draft building (draft_from) move to outbox.py. The undo checks (undo_target) move to source.py. Both sources use them, so the IMAP behaviour does not change.
  • Tools. An action ref carries the source id when the row has one. draft_id and the ids of a move are in the stable form for a JMAP account.
  • Docs. README, SECURITY.md, config.example.toml and CLAUDE.md describe the JMAP writes and the token they need.

Checks

  • make check: 180 passed. Ruff, mypy and pip-audit are clean.
  • make test-integration: 14 passed (8 GreenMail, 6 Stalwart). The new Stalwart tests cover draft, flag and move, the undo of each, a Junk target refused, and a concurrent change that fails with conflict.

Not in this PR

  • Live use waits on the write token for each instance (ADR 0004 §9, starbase #271).
  • Flag colours are #68.

🤖 Generated with Claude Code

Closes #57. Parent: #51 (Phase 6). Decision: ADR 0006 §10, ADR 0004. ## Changes - **JMAP writes** in `jmap.py`, applied by the sync worker as for IMAP: - A draft is the bytes from `compose_draft`, uploaded as a blob, then created with `Email/import` in Drafts with `$draft` and `$seen`. The inverse keeps the blob id that the import returns, because Stalwart stores the message under a new blob. - A flag change and a move are `Email/set` patches on `keywords` and `mailboxIds`. Each one carries `ifInState`, which is the Email state read just before the patch. - A concurrent change on the server fails the action with the code `conflict`. The action is `failed`, not `refused`, so the client can ask again. Nothing is overwritten. - A move removes the source mailbox and adds the target. A message that was already in the target (a Fastmail label) stays there on undo. - An undo replays the stored inverse. A draft is destroyed only while it keeps `$draft` and its blob id. - A read-only token refuses every write with `unsupported`. A draft needs `from_address`, because `Identity/get` needs the submission scope. - The mirror is updated at once, as the next pass would update it. The next pass then finds nothing to change. - `EmailSubmission` is never called. - **Shared rules.** The flag checks (`flag_changes`) and the draft building (`draft_from`) move to `outbox.py`. The undo checks (`undo_target`) move to `source.py`. Both sources use them, so the IMAP behaviour does not change. - **Tools.** An action ref carries the source id when the row has one. `draft_id` and the `ids` of a move are in the stable form for a JMAP account. - **Docs.** README, SECURITY.md, `config.example.toml` and CLAUDE.md describe the JMAP writes and the token they need. ## Checks - `make check`: 180 passed. Ruff, mypy and pip-audit are clean. - `make test-integration`: 14 passed (8 GreenMail, 6 Stalwart). The new Stalwart tests cover draft, flag and move, the undo of each, a Junk target refused, and a concurrent change that fails with `conflict`. ## Not in this PR - Live use waits on the write token for each instance (ADR 0004 §9, starbase #271). - Flag colours are #68. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Drafts go through blob upload and Email/import into Drafts with $draft
and $seen. Flags and moves are Email/set patches with ifInState, so a
change made on the server meanwhile fails the action with conflict. An
undo replays the stored inverse; a draft is destroyed only while it
keeps $draft and its blob id. EmailSubmission is never called.

The flag rules, the draft building and the undo checks move to outbox.py
and source.py, so both sources apply the same rules.

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