Forward drafts: forward_id in mail_draft #194

Closed
opened 2026-11-12 05:52:18 +00:00 by svc-agent-writer · 3 comments

Part of epic #187. Implements ADR 0013 item 7.

Read docs/adr/0013-trash-forward-and-draft-edits.md and ADR 0004 first. ADR 0013 is the contract. If the code shows that a ruling cannot work, stop and report; do not change the ruling here.

Standing rules: tools only queue to the outbox and never call a mail server. The sync worker applies each action through the existing source apply interface. Logs carry counts, roles and error codes only. Secrets are files. Add no new test seam: use the tools over HTTP with the stand-in worker, the source apply interface with the fake IMAP session or the fake JMAP server, and the GreenMail and Stalwart integration targets.

What to build

  1. mail_draft gains the argument forward_id. It is exclusive with reply_to_id; both together is invalid_argument. It implies the account, as reply_to_id does.
  2. Compose the forward in the pure outbox composition, shared by both sources. Add no source-specific code.
  3. The subject defaults to Fwd: plus the original subject. Set neither In-Reply-To nor References.
  4. The forward block has From, Date, Subject and To lines, then the body_text of the mirror row. Do not read the raw message.
  5. When the original has attachments, add one bounded line with their count and names. Remove CR and LF from the names: they are untrusted. Include no attachment bytes.
  6. The existing limit of 200,000 characters covers the caller's body and the whole block. Reserve space for the header lines, the attachment line and a marker line. Cut the quoted text to fit and end a cut with the marker line. Refuse a caller body that leaves too little space for the fixed material.
  7. A forward draft counts against drafts_per_day. Its undo is the existing draft undo.
  8. The docstring states that the quoted block is untrusted mail content.

Acceptance criteria

  • Over HTTP: forward_id queues one draft action; forward_id with reply_to_id is refused; an unknown id is refused as for reply_to_id.
  • Pure composition tests: subject default, an explicit subject wins, no threading headers, the four header lines, the body text, the attachment line, CR and LF removed from a hostile attachment name.
  • A long original is cut and ends with the marker. A caller body that leaves no space is refused. The result never exceeds 200,000 characters.
  • Fake IMAP session and fake JMAP server each store the forward draft in Drafts, and nothing is submitted.
  • GreenMail: forward draft then undo.
  • make check passes.

Out of scope

Attachment bytes, HTML bodies, Bcc and any sending path.

Blocked by

  • #188 (ADR 0013 merged and accepted)
Part of epic #187. Implements ADR 0013 item 7. Read `docs/adr/0013-trash-forward-and-draft-edits.md` and ADR 0004 first. ADR 0013 is the contract. If the code shows that a ruling cannot work, stop and report; do not change the ruling here. Standing rules: tools only queue to the outbox and never call a mail server. The sync worker applies each action through the existing source `apply` interface. Logs carry counts, roles and error codes only. Secrets are files. Add no new test seam: use the tools over HTTP with the stand-in worker, the source `apply` interface with the fake IMAP session or the fake JMAP server, and the GreenMail and Stalwart integration targets. ## What to build 1. `mail_draft` gains the argument `forward_id`. It is exclusive with `reply_to_id`; both together is `invalid_argument`. It implies the account, as `reply_to_id` does. 2. Compose the forward in the pure outbox composition, shared by both sources. Add no source-specific code. 3. The subject defaults to `Fwd:` plus the original subject. Set neither `In-Reply-To` nor `References`. 4. The forward block has From, Date, Subject and To lines, then the `body_text` of the mirror row. Do not read the raw message. 5. When the original has attachments, add one bounded line with their count and names. Remove CR and LF from the names: they are untrusted. Include no attachment bytes. 6. The existing limit of 200,000 characters covers the caller's body and the whole block. Reserve space for the header lines, the attachment line and a marker line. Cut the quoted text to fit and end a cut with the marker line. Refuse a caller body that leaves too little space for the fixed material. 7. A forward draft counts against `drafts_per_day`. Its undo is the existing draft undo. 8. The docstring states that the quoted block is untrusted mail content. ## Acceptance criteria - [ ] Over HTTP: `forward_id` queues one draft action; `forward_id` with `reply_to_id` is refused; an unknown id is refused as for `reply_to_id`. - [ ] Pure composition tests: subject default, an explicit subject wins, no threading headers, the four header lines, the body text, the attachment line, CR and LF removed from a hostile attachment name. - [ ] A long original is cut and ends with the marker. A caller body that leaves no space is refused. The result never exceeds 200,000 characters. - [ ] Fake IMAP session and fake JMAP server each store the forward draft in Drafts, and nothing is submitted. - [ ] GreenMail: forward draft then undo. - [ ] `make check` passes. ## Out of scope Attachment bytes, HTML bodies, Bcc and any sending path. ## Blocked by - #188 (ADR 0013 merged and accepted)
Collaborator

⏸ SVD architect gate: dev/mail-mind-mcp#194 forward-drafts-forward-id-in-mail-draft

Status: CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity substrate · dispatch effort high

Run: 20261112T190657Z-a01807ea

Held because: CLEAN but 3 open risk(s) (2 verification · 1 decision) — HOLD-ALL parks everything. The risks, verbatim:

Open risks:

  1. Should #194 dispatch before or after the ADR 0013 item 8 draft-edit issue of epic #187? Both write outbox.py, server.py, actions.py and jmap.py, and CONV-37 dispatch-batch refuses overlapping written sets, so they must go one at a time. The lean recommends #194 first, because draft-edit must retain forward context from the replaced action, which needs the params['forward'] ref this spec introduces. The draft-edit issue number was not in this run's issue context. [decision]
  2. No numeric test baseline: the host checkout has no .venv, and Half A is read-only on the target. Check: on pristine base 1481d94, before the first edit, run make check and record the failure set. After the change, the failure set must be unchanged, and the new tests in tests/test_actions.py, tests/test_write_tools.py and tests/test_jmap.py must pass. [verification]
  3. The GreenMail acceptance criterion is provable only with the integration containers, and the test skips without MAILMIND_GREENMAIL=1, so make check alone does not prove it. Check: make test-integration passes tests/integration/test_greenmail_writes.py::test_draft_forward_then_undo, and the PR quotes the run. [verification]

Change: Mirror the reply path one-for-one. In server.py mail_draft (:1535-1558), add forward_id. Check that it is exclusive with reply_to_id first (invalid_argument). Then load the original with _mirrored (not_found) and apply the same cross-account check as the reply branch at :1548-1553. Store params["forward"] = _ref(row): a ref only, never quoted text. Switch the early refusal at :1557 to compose_draft(sender, draft_from(params, None, forwarded)), swapping the Draft import for draft_from. In outbox.py, add a Forwarded Protocol (shaped like Original :44-52), forward_subject = literal "Fwd: " + subject (shaped like reply_subject :73-74), and forward_body. forward_body writes a separator plus From/Date/Subject/To lines and an optional "Attachments (n): names" line. Every line has CR and LF removed and is cut to 1,000 characters. Bounding against MAX_BODY_CHARS is exact: always reserve the marker line, refuse with CODE_LIMIT when caller body plus fixed material exceeds 200,000, and otherwise cut body_text and append FORWARD_CUT_MARKER. Extend draft_from(params, original, forward=None) to refuse both, and to leave a forward without threading headers. In actions._draft (:214-237) and jmap._draft (:900-927), load params["forward"] the same way the reply_to row is loaded (store.get_message / self._row) and pass it to draft_from. In server._action_detail (:1640-1647), add a " forward" marker. There is no schema, cap or undo change: a forward is kind "draft".

Files: src/mail_mind_mcp/outbox.py · src/mail_mind_mcp/server.py · src/mail_mind_mcp/actions.py · src/mail_mind_mcp/jmap.py · tests/test_actions.py · tests/test_write_tools.py · tests/test_jmap.py · tests/integration/test_greenmail_writes.py

Decision: accept the 3 open risk(s) above and dispatch this spec (svd:go), or park (svd:skip) / re-spec (svd:respec)?

Your call (when this issue is held at the gate via svd:hold):

  • add label svd:go — approve; Half-B dispatch accepts exactly this spec (open risks accepted)
  • add label svd:fire beside svd:go — approve AND authorise the Half-B fire from the phone; never on its own
  • add label svd:skip — park it; dispatch refuses it and the issue stays for a human
  • add label svd:respec — discard this spec; the next Half-A run re-produces it with this record as prior-attempt context

Spec: /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-12-forward-drafts-forward-id-in-mail-draft.md — next: codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-12-forward-drafts-forward-id-in-mail-draft.md

### ⏸ SVD architect gate: dev/mail-mind-mcp#194 forward-drafts-forward-id-in-mail-draft **Status:** CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity `substrate` · dispatch effort `high` **Run:** `20261112T190657Z-a01807ea` **Held because:** CLEAN but 3 open risk(s) (2 verification · 1 decision) — HOLD-ALL parks everything. The risks, verbatim: **Open risks:** 1. Should #194 dispatch before or after the ADR 0013 item 8 draft-edit issue of epic #187? Both write outbox.py, server.py, actions.py and jmap.py, and CONV-37 dispatch-batch refuses overlapping written sets, so they must go one at a time. The lean recommends #194 first, because draft-edit must retain forward context from the replaced action, which needs the params['forward'] ref this spec introduces. The draft-edit issue number was not in this run's issue context. [decision] 2. No numeric test baseline: the host checkout has no .venv, and Half A is read-only on the target. Check: on pristine base 1481d94, before the first edit, run `make check` and record the failure set. After the change, the failure set must be unchanged, and the new tests in tests/test_actions.py, tests/test_write_tools.py and tests/test_jmap.py must pass. [verification] 3. The GreenMail acceptance criterion is provable only with the integration containers, and the test skips without MAILMIND_GREENMAIL=1, so `make check` alone does not prove it. Check: `make test-integration` passes tests/integration/test_greenmail_writes.py::test_draft_forward_then_undo, and the PR quotes the run. [verification] **Change:** Mirror the reply path one-for-one. In server.py mail_draft (:1535-1558), add forward_id. Check that it is exclusive with reply_to_id first (invalid_argument). Then load the original with _mirrored (not_found) and apply the same cross-account check as the reply branch at :1548-1553. Store params["forward"] = _ref(row): a ref only, never quoted text. Switch the early refusal at :1557 to compose_draft(sender, draft_from(params, None, forwarded)), swapping the Draft import for draft_from. In outbox.py, add a Forwarded Protocol (shaped like Original :44-52), forward_subject = literal "Fwd: " + subject (shaped like reply_subject :73-74), and forward_body. forward_body writes a separator plus From/Date/Subject/To lines and an optional "Attachments (n): names" line. Every line has CR and LF removed and is cut to 1,000 characters. Bounding against MAX_BODY_CHARS is exact: always reserve the marker line, refuse with CODE_LIMIT when caller body plus fixed material exceeds 200,000, and otherwise cut body_text and append FORWARD_CUT_MARKER. Extend draft_from(params, original, forward=None) to refuse both, and to leave a forward without threading headers. In actions._draft (:214-237) and jmap._draft (:900-927), load params["forward"] the same way the reply_to row is loaded (store.get_message / self._row) and pass it to draft_from. In server._action_detail (:1640-1647), add a " forward" marker. There is no schema, cap or undo change: a forward is kind "draft". **Files:** `src/mail_mind_mcp/outbox.py` · `src/mail_mind_mcp/server.py` · `src/mail_mind_mcp/actions.py` · `src/mail_mind_mcp/jmap.py` · `tests/test_actions.py` · `tests/test_write_tools.py` · `tests/test_jmap.py` · `tests/integration/test_greenmail_writes.py` **Decision:** accept the 3 open risk(s) above and dispatch this spec (`svd:go`), or park (`svd:skip`) / re-spec (`svd:respec`)? **Your call** (when this issue is held at the gate via `svd:hold`): - add label `svd:go` — approve; Half-B dispatch accepts exactly this spec (open risks accepted) - add label `svd:fire` **beside** `svd:go` — approve AND authorise the Half-B fire from the phone; never on its own - add label `svd:skip` — park it; dispatch refuses it and the issue stays for a human - add label `svd:respec` — discard this spec; the next Half-A run re-produces it with this record as prior-attempt context <sub>Spec: `/Users/piers/.local/state/exhaust/groupthink/specs/2026-11-12-forward-drafts-forward-id-in-mail-draft.md` — next: `codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-12-forward-drafts-forward-id-in-mail-draft.md`</sub>
Collaborator

✅ SVD architect gate: dev/mail-mind-mcp#194 forward-drafts-forward-id-in-mail-draft

Status: CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity unclassified · dispatch effort unclassified

Run: 20261112T190657Z-a01807ea

Files: src/mail_mind_mcp/outbox.py · src/mail_mind_mcp/server.py · src/mail_mind_mcp/actions.py · src/mail_mind_mcp/jmap.py · tests/test_actions.py · tests/test_write_tools.py · tests/test_jmap.py · tests/integration/test_greenmail_writes.py

Write-set divergence: present table wins. 0 sourceHashes vs 16-row table.

Decision: dispatch this spec (svd:go)?

Your call (when this issue is held at the gate via svd:hold):

  • add label svd:go — approve; Half-B dispatch accepts exactly this spec (open risks accepted)
  • add label svd:fire beside svd:go — approve AND authorise the Half-B fire from the phone; never on its own
  • add label svd:skip — park it; dispatch refuses it and the issue stays for a human
  • add label svd:respec — discard this spec; the next Half-A run re-produces it with this record as prior-attempt context

Spec: /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-12-forward-drafts-forward-id-in-mail-draft.md — next: codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-12-forward-drafts-forward-id-in-mail-draft.md

### ✅ SVD architect gate: dev/mail-mind-mcp#194 forward-drafts-forward-id-in-mail-draft **Status:** CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity `unclassified` · dispatch effort `unclassified` **Run:** `20261112T190657Z-a01807ea` **Files:** `src/mail_mind_mcp/outbox.py` · `src/mail_mind_mcp/server.py` · `src/mail_mind_mcp/actions.py` · `src/mail_mind_mcp/jmap.py` · `tests/test_actions.py` · `tests/test_write_tools.py` · `tests/test_jmap.py` · `tests/integration/test_greenmail_writes.py` **Write-set divergence:** present table wins. 0 sourceHashes vs 16-row table. **Decision:** dispatch this spec (`svd:go`)? **Your call** (when this issue is held at the gate via `svd:hold`): - add label `svd:go` — approve; Half-B dispatch accepts exactly this spec (open risks accepted) - add label `svd:fire` **beside** `svd:go` — approve AND authorise the Half-B fire from the phone; never on its own - add label `svd:skip` — park it; dispatch refuses it and the issue stays for a human - add label `svd:respec` — discard this spec; the next Half-A run re-produces it with this record as prior-attempt context <sub>Spec: `/Users/piers/.local/state/exhaust/groupthink/specs/2026-11-12-forward-drafts-forward-id-in-mail-draft.md` — next: `codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-12-forward-drafts-forward-id-in-mail-draft.md`</sub>
Collaborator

spec-verify-dispatch Half B for dev/mail-mind-mcp#194 forward-drafts-forward-id-in-mail-draft completed integration verify.

  • PR: #201
  • Branch: feat/svd-dev-mail-mind-mcp-194-forward-drafts-forward-id-in-m-bce73e06
  • Commit: 31d5dc75ac
  • Build: none
  • Test: green
  • Reader audit clean: True
  • Spec fidelity: True
  • Ready for merge: True
  • Check ci/woodpecker/pr/validation: green https://ci.groupthink.asia/repos/72/pipeline/78/1
  • Checks: required ci/woodpecker/pr/validation resolved pass by CI-wait poll
  • Warning: GreenMail integration criterion (tests/integration/test_greenmail_writes.py::test_draft_forward_then_undo) is collected but was not run: Podman unreachable per subagent adjustment E3. The owner runs make test-integration after merge.
  • Warning: pip-audit step of make check was not run locally (ruff, ruff format, mypy and the unit suite were run and are clean).
  • Warning: Remote Woodpecker validation is still pending on the PR head.
  • CI wait: ci/woodpecker/pr/validation -> pass
  • Decision: review the PR and merge? (codex-svd ship --run-id 20261112T192838Z-bce73e06 --confirm-merge)
spec-verify-dispatch Half B for dev/mail-mind-mcp#194 forward-drafts-forward-id-in-mail-draft completed integration verify. - PR: https://git.groupthink.asia/dev/mail-mind-mcp/pulls/201 - Branch: feat/svd-dev-mail-mind-mcp-194-forward-drafts-forward-id-in-m-bce73e06 - Commit: 31d5dc75ace384c885dccaf3a15fd693d7864d74 - Build: none - Test: green - Reader audit clean: True - Spec fidelity: True - Ready for merge: True - Check ci/woodpecker/pr/validation: green https://ci.groupthink.asia/repos/72/pipeline/78/1 - Checks: required ci/woodpecker/pr/validation resolved pass by CI-wait poll - Warning: GreenMail integration criterion (tests/integration/test_greenmail_writes.py::test_draft_forward_then_undo) is collected but was not run: Podman unreachable per subagent adjustment E3. The owner runs make test-integration after merge. - Warning: pip-audit step of make check was not run locally (ruff, ruff format, mypy and the unit suite were run and are clean). - Warning: Remote Woodpecker validation is still pending on the PR head. - CI wait: ci/woodpecker/pr/validation -> pass - Decision: review the PR and merge? (`codex-svd ship --run-id 20261112T192838Z-bce73e06 --confirm-merge`)
svc-svd-writer 2026-11-12 19:54:50 +00:00
  • closed this issue
  • removed the
    svd:go
    label
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
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#194
No description provided.