trim_quoted keeps a forwarded message after a forward marker #3

Closed
opened 2026-11-03 00:56:07 +00:00 by svc-agent-writer · 2 comments

This was generated by AI from dev/mail-mind-mcp#113.

This is the blade half of dev/mail-mind-mcp#113. Triage ruled on 2026-11-02: fix trim_quoted here, then bump the pin in mail-mind-mcp. The operator ruled the marker list on 2026-11-03 (below).

Agent Brief

Category: bug
Summary: trim_quoted cuts a forwarded message at its header block, so the forwarded content is lost.

Current behavior:
trim_quoted in src/imap_blade_mcp/mime.py cuts at the first line, after line 0, that matches _QUOTE_HEADER_RE. That pattern includes From: …. A forward reads Begin forwarded message:, then a header block that starts From:. So trim_quoted keeps the text above the header block and drops the forwarded headers and body.

Desired behavior:
After an unambiguous forward marker line, trim_quoted does not cut at the header block that follows. It keeps the header block and the forwarded body. The forward markers are a closed list. Each marker matches with surrounding whitespace, case-insensitively:

  • Begin forwarded message: (Apple Mail)
  • ---------- Forwarded message --------- (Gmail; any run of two or more dashes on each side)

Inside the forwarded part, the existing rules still apply: > quote prefixes, On … wrote:, -- signatures and the other _QUOTE_HEADER_RE markers still cut. Only the header block directly after the forward marker is exempt.

Ruled out (operator, 2026-11-03): -----Original Message----- and -------- Original Message -------- are not forward markers. Outlook writes them on replies and on forwards alike, so they stay reply cuts, as today. Residual: an Outlook forward still loses its body.

Key interfaces:

  • trim_quoted(text: str) -> tuple[str, int] keeps the same signature. omitted_chars stays exactly len(text) - len(kept).

Acceptance criteria:

  • Hi\n\nBegin forwarded message:\n\nFrom: a@example.test\nSubject: x\n\nbody keeps every line, and omitted is 0.
  • The same for ---------- Forwarded message --------- with a From: header block.
  • A reply Thanks\n\nOn Mon, X wrote:\n> quoted still cuts at the On … wrote: line.
  • A forward whose forwarded part holds a quoted reply cuts at that inner quote (On … wrote: or >), not before the forwarded headers.
  • Body\n-----Original Message-----\nFrom: x still cuts at -----Original Message----- (existing test in tests/test_mime.py).
  • The existing trim_quoted tests in tests/test_mime.py stay green, and make check passes.

Out of scope:

  • Signature trimming rules.
  • The version bump and the release tag. The operator cuts v0.1.2 after merge.
  • The mail-mind-mcp pin bump and its mail_read test (dev/mail-mind-mcp#113).

Blocks

> *This was generated by AI from dev/mail-mind-mcp#113.* This is the blade half of dev/mail-mind-mcp#113. Triage ruled on 2026-11-02: fix `trim_quoted` here, then bump the pin in mail-mind-mcp. The operator ruled the marker list on 2026-11-03 (below). ## Agent Brief **Category:** bug **Summary:** `trim_quoted` cuts a forwarded message at its header block, so the forwarded content is lost. **Current behavior:** `trim_quoted` in `src/imap_blade_mcp/mime.py` cuts at the first line, after line 0, that matches `_QUOTE_HEADER_RE`. That pattern includes `From: …`. A forward reads `Begin forwarded message:`, then a header block that starts `From:`. So `trim_quoted` keeps the text above the header block and drops the forwarded headers and body. **Desired behavior:** After an unambiguous forward marker line, `trim_quoted` does not cut at the header block that follows. It keeps the header block and the forwarded body. The forward markers are a closed list. Each marker matches with surrounding whitespace, case-insensitively: - `Begin forwarded message:` (Apple Mail) - `---------- Forwarded message ---------` (Gmail; any run of two or more dashes on each side) Inside the forwarded part, the existing rules still apply: `>` quote prefixes, `On … wrote:`, `-- ` signatures and the other `_QUOTE_HEADER_RE` markers still cut. Only the header block directly after the forward marker is exempt. **Ruled out (operator, 2026-11-03):** `-----Original Message-----` and `-------- Original Message --------` are **not** forward markers. Outlook writes them on replies and on forwards alike, so they stay reply cuts, as today. Residual: an Outlook forward still loses its body. **Key interfaces:** - `trim_quoted(text: str) -> tuple[str, int]` keeps the same signature. `omitted_chars` stays exactly `len(text) - len(kept)`. **Acceptance criteria:** - [ ] `Hi\n\nBegin forwarded message:\n\nFrom: a@example.test\nSubject: x\n\nbody` keeps every line, and `omitted` is 0. - [ ] The same for `---------- Forwarded message ---------` with a `From:` header block. - [ ] A reply `Thanks\n\nOn Mon, X wrote:\n> quoted` still cuts at the `On … wrote:` line. - [ ] A forward whose forwarded part holds a quoted reply cuts at that inner quote (`On … wrote:` or `>`), not before the forwarded headers. - [ ] `Body\n-----Original Message-----\nFrom: x` still cuts at `-----Original Message-----` (existing test in `tests/test_mime.py`). - [ ] The existing `trim_quoted` tests in `tests/test_mime.py` stay green, and `make check` passes. **Out of scope:** - Signature trimming rules. - The version bump and the release tag. The operator cuts `v0.1.2` after merge. - The mail-mind-mcp pin bump and its `mail_read` test (dev/mail-mind-mcp#113). ## Blocks - dev/mail-mind-mcp#113
Collaborator

⏸ SVD architect gate: dev/imap-blade-mcp#3 trim-quoted-keeps-a-forwarded-message-after-a-forward-marker

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 additive · dispatch effort low

Run: 20261103T005914Z-a98ad411

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

Open risks:

  1. The downstream reader dev/mail-mind-mcp (evidence.py signature extraction calls the installed imap_blade_mcp.mime.trim_quoted) was not readable from this sandbox. When dev/mail-mind-mcp#113 bumps the pin, run that repo's evidence/signature tests and its new mail_read test with python3 -m pytest. Confirm that forwarded bodies now reaching sign-off extraction do not change existing golden outputs. [verification]
  2. Should this PR add a CHANGELOG.md entry (e.g. under 'Unreleased'), or does the operator write it when cutting v0.1.2? The issue rules out only the version bump and the tag. Lean: leave it to the release cut and keep the write set at two files. If an entry is wanted, add CHANGELOG.md | modify at the gate. [decision]

Change: In src/imap_blade_mcp/mime.py add two module-level Final regexes below _QUOTE_HEADER_RE (mime.py:154-158), mirroring its style. _FORWARD_MARKER_RE is ^\s*(?:Begin forwarded message:|-{2,}\sForwarded message\s-{2,})\s* with IGNORECASE. _HEADER_FIELD_RE is ^[A-Za-z][A-Za-z0-9-]{0,40}:(?:\s|). In trim_quoted (mime.py:161-175), add header_block/seen_header state ahead of the existing checks. A marker line arms the exemption and continues. While the exemption is armed, header-shaped lines continue, and blank lines before the first header continue. The first other line disarms it and falls through to the unchanged '>'/'-- ' and _QUOTE_HEADER_RE cuts. The return expression is unchanged, so omitted == len(text) - len(kept). This was prototyped in memory against the base tree: all acceptance cases, the existing TestTrimQuoted inputs and the test_tools.py mail_read fixture produced the expected results. Add the new test methods to class TestTrimQuoted in tests/test_mime.py:113-128.

Files: src/imap_blade_mcp/mime.py · tests/test_mime.py

Decision: accept the 2 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-03-trim-quoted-keeps-a-forwarded-message-after-a-forward-marker.md — next: codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-03-trim-quoted-keeps-a-forwarded-message-after-a-forward-marker.md

### ⏸ SVD architect gate: dev/imap-blade-mcp#3 trim-quoted-keeps-a-forwarded-message-after-a-forward-marker **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 `additive` · dispatch effort `low` **Run:** `20261103T005914Z-a98ad411` **Held because:** CLEAN but 2 open risk(s) (1 verification · 1 decision) — HOLD-ALL parks everything. The risks, verbatim: **Open risks:** 1. The downstream reader dev/mail-mind-mcp (evidence.py signature extraction calls the installed imap_blade_mcp.mime.trim_quoted) was not readable from this sandbox. When dev/mail-mind-mcp#113 bumps the pin, run that repo's evidence/signature tests and its new mail_read test with python3 -m pytest. Confirm that forwarded bodies now reaching sign-off extraction do not change existing golden outputs. [verification] 2. Should this PR add a CHANGELOG.md entry (e.g. under 'Unreleased'), or does the operator write it when cutting v0.1.2? The issue rules out only the version bump and the tag. Lean: leave it to the release cut and keep the write set at two files. If an entry is wanted, add CHANGELOG.md | modify at the gate. [decision] **Change:** In src/imap_blade_mcp/mime.py add two module-level Final regexes below _QUOTE_HEADER_RE (mime.py:154-158), mirroring its style. _FORWARD_MARKER_RE is ^\s*(?:Begin forwarded message:|-{2,}\s*Forwarded message\s*-{2,})\s*$ with IGNORECASE. _HEADER_FIELD_RE is ^[A-Za-z][A-Za-z0-9-]{0,40}:(?:\s|$). In trim_quoted (mime.py:161-175), add header_block/seen_header state ahead of the existing checks. A marker line arms the exemption and continues. While the exemption is armed, header-shaped lines continue, and blank lines before the first header continue. The first other line disarms it and falls through to the unchanged '>'/'-- ' and _QUOTE_HEADER_RE cuts. The return expression is unchanged, so omitted == len(text) - len(kept). This was prototyped in memory against the base tree: all acceptance cases, the existing TestTrimQuoted inputs and the test_tools.py mail_read fixture produced the expected results. Add the new test methods to class TestTrimQuoted in tests/test_mime.py:113-128. **Files:** `src/imap_blade_mcp/mime.py` · `tests/test_mime.py` **Decision:** accept the 2 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-03-trim-quoted-keeps-a-forwarded-message-after-a-forward-marker.md` — next: `codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-03-trim-quoted-keeps-a-forwarded-message-after-a-forward-marker.md`</sub>
Collaborator

spec-verify-dispatch Half B for dev/imap-blade-mcp#3 trim-quoted-keeps-a-forwarded-message-after-a-forward-marker completed integration verify.

  • PR: #4
  • Branch: feat/svd-dev-imap-blade-mcp-3-trim-quoted-keeps-a-forwarded-m-1aa7cbaf
  • Commit: 44a72dcb82
  • Build: none
  • Test: green
  • Reader audit clean: True
  • Spec fidelity: True
  • Ready for merge: True
  • Check woodpecker validation: absent
  • Checks: PR #4 head 44a72dc: no Forgejo commit statuses (absent). Local: 178 passed, ruff, format and mypy --strict clean.
  • Warning: No Forgejo commit statuses exist on PR head 44a72dc, so remote CI has not reported.
  • Warning: Downstream reader dev/mail-mind-mcp evidence.py was not checked; run its evidence and signature tests when #113 bumps the pin (spec Open Risk 1).
  • Warning: Outlook forwards still lose their body, by operator ruling.
  • Warning: no CI for woodpecker validation: Forgejo commit statuses on PR head 44a72dc return an empty list; no CI run in history for this commit. — reported as absent, not blocking (gh#633)
  • Decision: review the PR and merge? (codex-svd ship --run-id 20261103T021640Z-1aa7cbaf --confirm-merge)
spec-verify-dispatch Half B for dev/imap-blade-mcp#3 trim-quoted-keeps-a-forwarded-message-after-a-forward-marker completed integration verify. - PR: https://git.groupthink.asia/dev/imap-blade-mcp/pulls/4 - Branch: feat/svd-dev-imap-blade-mcp-3-trim-quoted-keeps-a-forwarded-m-1aa7cbaf - Commit: 44a72dcb8220027b5e838c8b4e68184d7fa4199b - Build: none - Test: green - Reader audit clean: True - Spec fidelity: True - Ready for merge: True - Check woodpecker validation: absent - Checks: PR #4 head 44a72dc: no Forgejo commit statuses (absent). Local: 178 passed, ruff, format and mypy --strict clean. - Warning: No Forgejo commit statuses exist on PR head 44a72dc, so remote CI has not reported. - Warning: Downstream reader dev/mail-mind-mcp evidence.py was not checked; run its evidence and signature tests when #113 bumps the pin (spec Open Risk 1). - Warning: Outlook forwards still lose their body, by operator ruling. - Warning: no CI for woodpecker validation: Forgejo commit statuses on PR head 44a72dc return an empty list; no CI run in history for this commit. — reported as absent, not blocking (gh#633) - Decision: review the PR and merge? (`codex-svd ship --run-id 20261103T021640Z-1aa7cbaf --confirm-merge`)
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/imap-blade-mcp#3
No description provided.