Put IMAP sync and writes behind a MailSource seam #61

Merged
svc-agent-writer merged 1 commit from refactor/mail-source-seam into main 2026-10-31 14:15:52 +00:00

Closes #53 (epic #51, ADR 0006 §1 to §3). No change in behaviour.

  • source.py (new) holds the protocol-neutral parts:
    • the MailSource protocol: account, run_pass, wait, apply, check, close;
    • PassResult;
    • drain and settle for the outbox, plus sleep, which ends early when an action is queued;
    • SyncWorker and open_source.
  • ingest.py is now the IMAP source only. AccountSync gains apply() and check(). drain_actions() and _sleep() delegate to the shared functions.
  • outbox.py (new) holds the pure outbox rules and compose_draft. These moved out of actions.py, so a future JMAP source can use them and server.py imports no IMAP module. actions.py keeps the IMAP runner.
  • cli check logs in through open_source(...).check(). The output is the same.
  • Config: each account takes source = "imap", which is the default. Any other value is refused. The discriminated union comes with the JMAP account type in #55.
  • Docs: the CLAUDE.md structure and its rule now read "never add a mail-server call to server.py". The README config row and config.example.toml name source.

Tests:

  • Existing tests changed only their imports.
  • New tests:
    • test_source.py fails if server.py imports ingest, actions, imapclient or the blade's connection module.
    • a config test for source;
    • an integration test that runs mailmind check against GreenMail through the source.
  • make check passes 132 tests. make test-integration passes 8.

🤖 Generated with Claude Code

Closes #53 (epic #51, ADR 0006 §1 to §3). No change in behaviour. - **`source.py`** (new) holds the protocol-neutral parts: - the `MailSource` protocol: `account`, `run_pass`, `wait`, `apply`, `check`, `close`; - `PassResult`; - `drain` and `settle` for the outbox, plus `sleep`, which ends early when an action is queued; - `SyncWorker` and `open_source`. - **`ingest.py`** is now the IMAP source only. `AccountSync` gains `apply()` and `check()`. `drain_actions()` and `_sleep()` delegate to the shared functions. - **`outbox.py`** (new) holds the pure outbox rules and `compose_draft`. These moved out of `actions.py`, so a future JMAP source can use them and `server.py` imports no IMAP module. `actions.py` keeps the IMAP runner. - **`cli check`** logs in through `open_source(...).check()`. The output is the same. - **Config:** each account takes `source = "imap"`, which is the default. Any other value is refused. The discriminated union comes with the JMAP account type in #55. - **Docs:** the CLAUDE.md structure and its rule now read "never add a mail-server call to `server.py`". The README config row and `config.example.toml` name `source`. Tests: - Existing tests changed only their imports. - New tests: - `test_source.py` fails if `server.py` imports `ingest`, `actions`, `imapclient` or the blade's connection module. - a config test for `source`; - an integration test that runs `mailmind check` against GreenMail through the source. - `make check` passes 132 tests. `make test-integration` passes 8. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Add source.py with the MailSource protocol, the outbox drain and settle,
and SyncWorker, which builds one source per account. ingest.py is now the
IMAP source; it gains apply() and check(), and cli check goes through it.
Move the pure outbox rules and draft composition to outbox.py, so server.py
imports no IMAP module, and a test keeps it that way. Accounts take
source = "imap", the default. No change in behaviour.

Closes #53

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