Add IMAP write primitives and drain the outbox in the sync worker #12

Closed
opened 2026-10-31 03:45:43 +00:00 by svc-agent-writer · 0 comments

Epic: #7

IMAP write primitives and the outbox drain (ADR 0004 §1, §2, §3, §6).

What to build

  • New module src/imap_mailmind_mcp/actions.py. It uses the blade's AccountSession.run(fn) (imap_blade_mcp/connection.py) with SELECT, not EXAMINE. Do not add write code to the blade: the blade is read-only by class.
  • Primitives:
    • append_draft: build the message with email.message.EmailMessage. From is the account identity from config. Parse recipients with email.headerregistry. Refuse any header value with CR or LF. For a reply, set In-Reply-To, References and Re: subject from the mirrored row. APPEND to the Drafts role with \Draft. Record the new UID (APPENDUID when UIDPLUS is present; else SEARCH by the generated Message-ID).
    • store_flags: \Seen and \Flagged only, add or remove. Record previous flags as the inverse.
    • move: UID MOVE (RFC 6851) when advertised; else UID COPY + UID STORE \Deleted + UID EXPUNGE of that UID only, and only with UIDPLUS. Without MOVE or UIDPLUS, refuse with unsupported. The target must be a mirrored mailbox and must not have the Trash or Junk role. Record source mailbox and new UID (COPYUID) as the inverse.
    • Draft undo: remove the appended UID only while it still has \Draft and its RFC822.SIZE matches the recorded size.
  • The sync worker drains next_actions at the start of each pass and between IDLE checks. Poll at most every 2 s while idle (configurable). Apply each action, update the mirror rows and write changes rows in one store transaction, then finish_action.
  • Logs: kind, account, role, result code and counts. Never subjects, addresses or bodies.

Acceptance

  • Unit tests for message construction (header injection refused, reply threading headers).
  • Integration tests against GreenMail (make test-integration): append, flag, move, each undo, and the refusal cases (Trash target, unchanged-draft check).
  • make check green.

Blocked by

Epic: #7 IMAP write primitives and the outbox drain (ADR 0004 §1, §2, §3, §6). ## What to build - New module `src/imap_mailmind_mcp/actions.py`. It uses the blade's `AccountSession.run(fn)` (`imap_blade_mcp/connection.py`) with SELECT, not EXAMINE. Do not add write code to the blade: the blade is read-only by class. - Primitives: - `append_draft`: build the message with `email.message.EmailMessage`. `From` is the account identity from config. Parse recipients with `email.headerregistry`. Refuse any header value with CR or LF. For a reply, set `In-Reply-To`, `References` and `Re:` subject from the mirrored row. APPEND to the Drafts role with `\Draft`. Record the new UID (APPENDUID when UIDPLUS is present; else SEARCH by the generated Message-ID). - `store_flags`: `\Seen` and `\Flagged` only, add or remove. Record previous flags as the inverse. - `move`: UID MOVE (RFC 6851) when advertised; else UID COPY + UID STORE `\Deleted` + UID EXPUNGE of that UID only, and only with UIDPLUS. Without MOVE or UIDPLUS, refuse with `unsupported`. The target must be a mirrored mailbox and must not have the Trash or Junk role. Record source mailbox and new UID (COPYUID) as the inverse. - Draft undo: remove the appended UID only while it still has `\Draft` and its RFC822.SIZE matches the recorded size. - The sync worker drains `next_actions` at the start of each pass and between IDLE checks. Poll at most every 2 s while idle (configurable). Apply each action, update the mirror rows and write `changes` rows in one store transaction, then `finish_action`. - Logs: kind, account, role, result code and counts. Never subjects, addresses or bodies. ## Acceptance - Unit tests for message construction (header injection refused, reply threading headers). - Integration tests against GreenMail (`make test-integration`): append, flag, move, each undo, and the refusal cases (Trash target, unchanged-draft check). - `make check` green. ## Blocked by - #11
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#12
No description provided.