Repository navigation
Conversation
…ckfreyer#71) `reply_to_email` inserts the new body via a blind clipboard paste into Mail's native reply composer, which already contains the quoted original thread. That paste is never read back through `content of replyMessage` -- Mail's GUI editor buffer is decoupled from that scriptable property, so a read-back there always reports the pre-paste value even after a successful paste (documented in the existing comment above the keystroke step). The tool therefore reported success from the AppleScript completing without error, with no check on where the pasted text actually landed. `reply_verification.py` adds that check: parse the saved draft's RFC 822 source (via the existing `get_email_source` tool, no new AppleScript) and verify the reply body is present in the region preceding Mail's quote container -- HTML `<blockquote type="cite">` or a plain-text `>`-quoted block. If the body ends up inside the quote instead of above it (the bug patrickfreyer#71 describes), or isn't found at all (a different, pre-existing failure mode -- see the focus-polling comment in `compose.py`), the tool now says so instead of reporting the same "saved!" text either way. Wired into `reply_to_email` for `mode="draft"` only. That's the one case where the message is guaranteed to already be sitting in Drafts by the time the AppleScript that saved it returns, so re-reading it is safe and synchronous. "send" moves the message to Sent before a read-back could happen; "open" leaves it unsaved in a compose window with nothing in a mailbox yet. Neither is covered here -- flagged as a natural follow-up rather than solved in this PR. Found and fixed two bugs in my own first pass, before opening anything: 1. Gating the read-back on `not output_text.startswith("Error")` misses "No email found matching: <keyword>" -- a different failure with no saved draft to verify, that also doesn't start with "Error". Switched to checking for the AppleScript's own positive success marker instead of the absence of one particular negative one. A test written against the *intended* behaviour caught this before it shipped: reverting to the negative check is exactly the mutation `test_applescript_error_does_not_attempt_verification` exists to catch, and it does. 2. My first version of this integration made the existing sender-override tests issue real, unmocked AppleScript against whatever machine runs the suite (a fast "does this account exist" check that failed quickly since "Work" isn't a real account there, but real execution nonetheless). `reply_to_email`'s existing tests using `send=False` didn't anticipate a second read-back call, since there wasn't one before this change. Fixed by mocking `get_email_source` in those two tests too, and confirmed with a `subprocess.run`-tracking wrapper around the *entire* suite that zero real calls occur anywhere in it, not just in the tests I touched. Verification: - 9 new unit tests for the parsing/detection logic in isolation (HTML and plain-text quote markers, body-inside-quote, body-missing-entirely distinguished from body-inside-quote, multi-div HTML wrapping, no quote block at all, empty body, no recognizable body part). - 6 new integration tests for the `reply_to_email` wiring (pass, fail, get_email_source error, and that send/open/no-draft-saved paths do not attempt verification at all). - Mutation-tested three points in the detection logic (blockquote detection, HTML tag stripping, '>' marker detection) and the gating condition: each breaks exactly the test built to catch it, no others. - Full suite: 135 passed (was 120), matching CI's `PYTHONPATH=plugin` invocation. Zero real `subprocess.run` calls anywhere in the suite, confirmed by wrapping it for the entire run, not just the new tests. - `scripts/check_versions.py` (CI's version-drift guard): clean. What I could not verify: live behaviour against a real Mail.app draft. Everything above is against synthetic RFC 822 fixtures and mocked AppleScript output. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
7452ac8 to
4bf8a34
Compare
|
This review was written by Claude (AI assistant) on Patrick's behalf. Thanks @proscar87! Since #92 is stacked on this branch (same commit
Nice that it correctly flags a #88-wrapped body as "inside quote". |
Review feedback on patrickfreyer#91 and patrickfreyer#92: - The draft is identified by Message-ID: Drafts IDs are snapshotted before the reply is created, and only one new draft with the exact reply subject is accepted. No subject fallback; an ambiguous or missing identity is reported as a failure. - Body placement: markup is only stripped from an actual HTML body, the HTML that was sent is checked instead of its plain fallback, and whitespace is normalized on both sides, so wrapped plain bodies pass. - The result leads with 'Status: VERIFIED' or 'Status: FAILED — <why>' instead of a trailing line after 'Reply saved as draft!'. - Cc/From are parsed with email.utils.getaddresses and compared as lowercased addresses. - The saved To/Cc/From are always reported, including reply-all without overrides. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
This comment was written by Claude (AI assistant) on Patrick's behalf. Thanks @proscar87! To keep things moving, we carried this over in #114 with your commits preserved (authorship intact), plus one small follow-up: the Drafts snapshot now has its own |
…aved reply drafts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #71.
The gap
reply_to_emailinserts the new reply body via a blind clipboard paste into Mail's native reply composer, which already contains the quoted original thread. That paste is never read back throughcontent of replyMessage— Mail's GUI editor buffer is decoupled from that scriptable property, so a read-back there always reports the pre-paste value even after a successful paste (documented in the existing comment above the keystroke step incompose.py). The tool reported success from the AppleScript completing without error, with no check on where the pasted text actually landed relative to the quote.What this adds
reply_verification.py: parse the saved draft's RFC 822 source (via the existingget_email_sourcetool — no new AppleScript) and verify the reply body is present in the region preceding Mail's quote container, HTML<blockquote type="cite">or a plain-text>-quoted block. Three distinguishable outcomes:compose.pyabout the paste landing nowhere if Mail isn't frontmost).Wired into
reply_to_emailformode="draft"only. That's the one case where the message is guaranteed to already be sitting in Drafts by the time the AppleScript that saved it has returned, so re-reading it is safe and synchronous.sendmoves the message to Sent before a read-back could happen;openleaves it unsaved in a compose window with nothing in a mailbox yet. Neither is covered here — flagging both as a natural follow-up rather than solving them in this PR.Two bugs I found in my own first pass, before opening this
Gating the read-back on
not output_text.startswith("Error")misses"No email found matching: <keyword>"— a different failure with no saved draft to verify, that also doesn't start with"Error". Switched to checking for the AppleScript's own positive success marker (success_text) instead of the absence of one particular negative string. A test written against the intended behaviour caught this before it shipped —test_applescript_error_does_not_attempt_verificationis the mutation that reverting to the negative check breaks, and it does.My first version made the existing sender-override tests issue real, unmocked AppleScript against whatever machine runs the suite — a fast "does this account exist" check that failed quickly since
"Work"isn't a real account there, but real execution nonetheless.reply_to_email's existingsend=Falsetests didn't anticipate a second read-back call, since there wasn't one before this change. Fixed by mockingget_email_sourcein those two tests too, and confirmed with asubprocess.run-tracking wrapper around the entire suite that zero real calls occur anywhere, not just in the tests I touched.Verification
<div>HTML wrapping, no quote block at all (plain compose), empty body, no recognizable body part.reply_to_emailwiring: pass, fail,get_email_sourceerror, and thatsend/open/no-draft-saved paths never attempt verification.>-marker detection) and the gating condition — each breaks exactly the test built to catch it, no others.PYTHONPATH=plugininvocation exactly.subprocess.runcalls anywhere in the suite — confirmed by wrappingsubprocess.runfor the entire run, not just the new tests, and asserting the tracked-call count is 0.scripts/check_versions.py(CI's version-drift guard): clean.What I could not verify
Live behaviour against a real Mail.app draft. Everything above is against synthetic RFC 822 fixtures and mocked AppleScript output — I did not run this against an actual account.
🤖 Generated with Claude Code