Skip to content

fix: compose and draft audit — account names, trash counts, thread grouping, draft window damage, blind replies, draft editing - #98

Closed
herbeckrobin wants to merge 7 commits into
patrickfreyer:mainfrom
herbeckrobin:fix/compose-audit-base
Closed

herbeckrobin wants to merge 7 commits into
patrickfreyer:mainfrom
herbeckrobin:fix/compose-audit-base

Conversation

@herbeckrobin

Copy link
Copy Markdown
Contributor

Six fixes to the compose/draft surface, each reproduced against a live Mail.app before the fix and covered by a regression test. Commit subjects are in German (the fork's working language); the code, comments and tests are English.

What is in here

  • Account names containing | were cut in half. list_accounts, list_account_addresses and get_mailbox_unread_counts used | as their field delimiter, so an account literally named Robin Herbeck | Full Stack Developer came back as two unusable fragments and every follow-up call failed with "account not found".
  • manage_trash reported deletions that never happened. It counted delete calls, but Mail's delete is a no-op on a message already in Trash. It now measures the mailbox before and after. It also iterated a message list forward while deleting from it, which shifts the list and skips every second message (-1728 on the next index); the loop runs backwards now.
  • save_email_attachment had no mailbox parameter, so an attachment outside INBOX was unreachable.
  • Threads were grouped by subject. get_email_thread matched on the subject string, which merges unrelated conversations that happen to share one. It follows Message-Id / In-Reply-To / References now.
  • compose_email(mode="draft") closed the wrong window. The message is created with visible:false and owns no window, so close window 1 saving yes closed — and silently saved as a draft — whatever the user had open, while the attachment of the intended draft was lost. It closes its own message object now.
  • Replies were sent empty. The reply path pasted the body blind after a fixed delay; whenever Mail was not frontmost the Cmd+V landed in another app and the reply went out with correct In-Reply-To headers and no text. It now polls for focus and aborts with an explanation rather than typing into a foreign app.
  • manage_drafts could not edit a draft. Mail cannot modify a stored draft in place, so action="update" rebuilds it: existing attachments are extracted to disk and re-attached, the old version is deleted only after the replacement is confirmed to exist, and if an attachment cannot be extracted the draft is left untouched rather than rebuilt without it.

Relationship to #95

The first commit here is the one from #95 (--read-only blocking delivery instead of removing the compose tools). Everything after it depends on it, so it could not be left out. If #95 is merged first this branch rebases down to the six remaining commits; if you would rather take this one, #95 can be closed as contained.

Verification

python -m pytest tests/ -q and python scripts/check_versions.py both pass. Every fix has a regression test that fails against the previous code.

https://claude.ai/code/session_01BxRqpRbe7bC31Sj6yuJ8ic

Two problems, one cause: the flag was applied by deleting tools rather
than by gating the sending path.

1. The guard in manage_drafts(action="send") never fired. compose.py did
   `from apple_mail_mcp.server import READ_ONLY`, binding the value False
   at import, while __main__ assigns server.READ_ONLY afterwards. The
   module now reads the flag through the server module at call time.

2. --read-only removed compose_email and reply_to_email outright, even
   though their "draft" and "open" modes never deliver anything. Those
   two are also the only tools in the compose surface that accept
   attachments, so read-only mode left no supported way to attach a file
   to a draft. They now stay registered and refuse mode="send"
   themselves. forward_email has no non-sending mode and is still
   removed.

Adds regression coverage for both, including one test that fails if the
flag is ever bound at import time again.
@patrickfreyer

Copy link
Copy Markdown
Owner

This review was written by Claude (AI assistant) on Patrick's behalf.

Thanks @herbeckrobin, this is a thorough audit and a lot of it is good. 166 tests pass. As one PR, though, it's hard to review and merge safely: it bundles 7 unrelated fixes, conflicts with #91, #92, #94 and #104, and #99 then rewrites its reply design again.

Could you split it? These four look good and would land quickly as small standalone PRs:

  1. Account names containing |
  2. Trash counts
  3. The mailbox parameter on save_email_attachment
  4. Message-ID based thread grouping

Note: 23ed2a2 is #95's head, so #95 is fully contained here. Keeping #95 as its own PR makes sense.

The reply/draft rewrite is the part that needs the most care. We'd like it as one reply/compose PR built against epic #80 (id-first targeting, verified drafts), coordinated with #91/#92 which already add draft verification. Specific concerns are in the #99 review, several of which start here:

  • The hardcoded German quote header REPLY_QUOTE_HEADER = "Am {date} schrieb {sender}:" (compose.py:680) is used for every plain reply.
  • Reply targeting is still by subject_keyword (now newest match wins), which conflicts with Epic: reply-safety redesign (verified drafts, body placement, simpler compose surface) #80's id-first direction.
  • Behavior changes worth calling out in the changelog: --read-only exposes compose/reply/forward, body_html compose no longer uses a visible window, and get_email_thread grouping changes.

@herbeckrobin

Copy link
Copy Markdown
Contributor Author

Split into #107, #108, #109 and #110 as suggested. The read-only part lives on in #95, the reply/draft rewrite will come as one PR against #80.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants