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>
) reply_to_email's AppleScript always echoed the original message's sender as "To:", regardless of what reply-to-all, a cc override, or a from_address override actually produced in the saved draft. Extend the existing patrickfreyer#71 read-back (verify_reply_body_outside_quote) to also check the real saved To/Cc/From headers against what was requested, sharing the same get_email_source round-trip. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
05fcc04 to
4df8165
Compare
|
This review was written by Claude (AI assistant) on Patrick's behalf. Thanks @proscar87, this is a solid step toward #70 (and it carries #91, which closes #71). 148 tests pass, and it merges cleanly with #101. Recipient check nits:
Body-placement nits from #91 (see that PR for details): locate the exact draft rather than first subject match, fix the three false FAILs (tag stripping, HTML bodies, whitespace), and surface a failure as a structured result rather than a trailing line. Heads-up: #98 also rewrites |
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>
Found on a real Mail.app draft: a cc of "Name <>" was saved as `Cc: Name`, and the check passed because getaddresses yields an empty address for that entry, which was filtered out before comparing. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Thanks, all addressed here (#91's points too, since they land together): c7ce288 and 82d7a07. I also changed "Closes #70" to "Refs #70". Body placement (#91):
Recipients (#92):
Checked on real Mail.app drafts (saved as drafts, never sent, then deleted):
159 tests pass. Each new test fails against the code before its fix. |
|
One more observation from those real drafts (a Gmail account). After each run I deleted the verified draft by its Message-ID, but other copies with the same "Re:" subject were left in Drafts: six across four runs, some with identical timestamps. They're probably autosave versions or Gmail-sync copies. In every run the new-draft lookup still resolved exactly one Message-ID, and verification read the right draft. But if those copies can appear before the lookup runs, it would see more than one new draft and report "could not uniquely identify the saved draft". That's a FAILED, not a wrong PASS, so it fails safe, but worth knowing. I cleaned up all the test drafts. |
|
This review was written by Claude (AI assistant) on Patrick's behalf. Thanks @proscar87, this is great work, and checking it on real drafts is much appreciated. Everything from both reviews is addressed: 161 tests pass on current main and it merges cleanly with #87 and #101 (both now merged). One thing before we merge:
Optional: on the duplicate Gmail copies, agreed it fails safe. If the new candidates all share one Message-ID, treating them as one draft would avoid that spurious FAILED. Once that's in we'll merge this and close #91 as superseded. |
|
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>
Summary
Builds on #91. This branch is stacked on #91's head, so until #91 is merged the diff here also shows #91's commit (
fix: verify a saved reply lands outside Mail's quoted original). Only the last commit is new in this PR.Refs #70 (Bcc,
draft_idand thread headers are not covered yet).reply_to_email's own AppleScript reports success by echoing"To: " & messageSender— the original message's sender — unconditionally. That's correct for a plain reply, but doesn't reflect what actually landed in the saved draft whenreply_to_all,cc, orfrom_addresschanges the real recipients/sender.This extends the existing #71 read-back mechanism (
get_email_sourcere-reading the just-saved draft) to also verify the realTo/Cc/Fromheaders, sharing the same round-trip already used to verify the reply body landed outside the quote.verify_recipients()inreply_verification.py: parses the saved draft's RFC 822 source and checks that every requestedccaddress actually made it into the savedCcheader (subset check — extra addresses Mail adds via reply-to-all are not a mismatch), and that a requestedfrom_addressoverride actually landed in the savedFromheader.Bccis deliberately not checked — whether an unsent draft's RFC 822 source even retainsBcc(vs. only applying it at send time) isn't something I could determine without a live draft to inspect, and I didn't want a check that always silently reports "not found" to be mistaken for a real verification. Documented in the docstring rather than guessed at._verify_saved_reply_bodynow runs both checks off the singleget_email_sourcefetch and appends aRecipients (PASSED|FAILED): ...line only whenccorfrom_addresswas actually requested — a plain reply with neither gets no extra line.Testing
verify_recipients/_extract_addressesintests/test_reply_verification.py(exact match, missing requested CC, reply-to-all extra CC tolerated, from-mismatch, no headers present, etc.)tests/test_compose_tools.py::ReplyDraftVerificationTestsexercising the fullreply_to_email→ readback path for: no-expectations (no Recipients line), CC actually saved (PASSED), CC silently dropped (FAILED), from_address honored (PASSED), from_address not applied (FAILED)expected_cc=cc, expected_from=sender_overridepass-through and confirmed exactly the 4 new recipient-specific tests fail (others unaffected)mainsubprocess.runinstrumented at the process level to confirm zero real AppleScript calls escape mocking — same isolation check used for bug: prevent reply bodies from being saved inside quoted text #71, since this wiring runs through the same draft-mode code path🤖 Generated with Claude Code