Skip to content

fix(mail): hide and save drafts when visible drafts are turned off - #104

Merged
JonathanRReed merged 3 commits into
mainfrom
fix/mail-hidden-drafts-103
Nov 14, 2026
Merged

JonathanRReed merged 3 commits into
mainfrom
fix/mail-hidden-drafts-103

Conversation

@JonathanRReed

Copy link
Copy Markdown
Owner

Fixes #103, reported by @MVMcris. Their diagnosis of both gaps was right, and this follows it.

What was wrong

With APPLE_MAIL_MCP_VISIBLE_DRAFTS=false:

  • mail_compose_draft with from_account forced the window visible and left it open.
  • Replies and forwards saved as drafts (safe_manage) always left their window open.
  • A hidden draft was never saved. It reached Drafts only at Mail's next autosave, and was lost if Mail quit first.

On a Mac nobody watches, the windows piled up.

What changes

  • Every draft is saved to Drafts straight away.
  • With the setting off, the draft's window is then hidden. This now covers new drafts, replies and forwards.
  • For replies and forwards the note says to open the draft from the Drafts mailbox.
  • The default (drafts left open for review) is unchanged.

Why hide instead of close

The issue suggested close newMessage saving yes. On macOS 27.2 (Mail 16) that loses the draft:

After save, the script does Draft in Drafts?
close the message or its window straight away No, deleted
close 1 to 3 seconds later Yes
set visible to false Yes

The save runs in the background and Mail gives no signal when it finishes, so any close is a race that can delete the draft. Hiding can't lose it. The cost: Mail keeps a hidden draft loaded until it next quits. Quitting with hidden drafts loaded was clean, with no prompt.

A draft with from_account still starts in a window, because the From pop-up fallback needs one and Mail ignores set visible to true on a draft created hidden.

Testing

  • Live through the real stdio server on macOS 27.2, reading each saved draft back from Drafts: new draft (with and without from_account), reply and forward, each with the setting off and on. Body, quoted original, sender and the forwarded attachment were intact; no window was left with the setting off.
  • Unknown from_account still fails with ACCOUNT_NOT_FOUND and leaves nothing behind.
  • Not tested live: the From pop-up fallback (Mail accepted the sender directly every time).
  • 227 Mail tests pass, including new ones for the save-then-hide order and the flag positions.

🤖 Generated with Claude Code

APPLE_MAIL_MCP_VISIBLE_DRAFTS=false left draft windows on screen: a new
draft with from_account was forced visible, and replies and forwards
saved as drafts always kept their window. A hidden draft was also never
saved, so it reached Drafts only at Mail's next autosave.

Every draft is now saved straight away, and with the setting off its
window is then hidden. The draft is hidden, not closed: on macOS 27
closing a draft or its window while the save is still running deletes
it, and Mail gives no signal for when the save has finished.

Fixes #103. Reported by MVMcris, whose diagnosis of both gaps this
follows.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T05:35:17.954604Z 5cc5aba New commits
🔒 Security Review ✅ Completed 2026-11-14T05:26:23.221818Z 217105a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Review follow-up. A failed `save` or a failed hide was still reported as
a hidden, saved draft.

- A draft is hidden only after its save succeeded. One Mail could not
  save stays on screen; a new draft with no window fails with
  DRAFT_SAVE_UNCONFIRMED and says to check Drafts before retrying.
- Replies and forwards saved as drafts now report `visible`, read from
  Mail after the save and hide, and their note follows it instead of
  the setting.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@JonathanRReed

Copy link
Copy Markdown
Owner Author

Pushed a follow-up after an independent review (no blockers; two points about reporting, both taken):

  • A draft is now hidden only after Mail saved it. If the save fails, the window stays open and the result says visible: true. A new draft that has no window fails with DRAFT_SAVE_UNCONFIRMED and says to check Drafts before retrying.
  • Replies and forwards saved as drafts now report visible, read from Mail after the save and hide, and their note follows that instead of the setting.

Re-ran the eight live cases (new draft with and without from_account, reply, forward; setting off and on) through the real server on macOS 27.2 and read each draft back. All intact. The save-failure paths can't be forced live, so they are covered by script and bridge tests only.

@JonathanRReed
JonathanRReed merged commit 06154ff into main Nov 14, 2026
12 checks passed
@JonathanRReed
JonathanRReed deleted the fix/mail-hidden-drafts-103 branch November 14, 2026 05:36
@MVMcris

MVMcris commented Nov 14, 2026

Copy link
Copy Markdown

Thanks for the quick fix, and for testing the close approach properly. You were right about close: my local patch closed the draft after a 1-second delay. It happened to work in my tests, but that’s exactly the race you describe, so I’ve dropped it in favor of 1.1.7.

I’ve run 1.1.7 with APPLE_MAIL_MCP_VISIBLE_DRAFTS=false on macOS 27.0.1 (26A434), Mail 16.0, iCloud account, safe_manage:

mail_compose_draft with from_account: works. The result says visible: false, the draft is in Drafts, no window is left, and Mail keeps answering afterwards (tested twice).
mail_reply_message to a message in the Drafts mailbox: Mail hangs. The tool call never returns, every later call that talks to Mail times out, and Mail has to be force-quit. Same result with and without from_account, so it isn’t the From pop-up path. No reply draft reached Drafts (tested twice, Mail force-quit each time).

The same reply under 1.1.6 (save, then a delayed close) returned normally, so I suspect the new save-then-hide step for replies: set visible of replyMessage to false, or the visible read right after it, on a window opened by reply ... with opening window. Since no draft survived, the save itself may not have finished either. I haven’t yet tested a reply to a message in the Inbox, or a forward.

Maybe worth a with timeout around the hide and the read, or skipping the hide for replies and forwards on this macOS version. For now I’ve set the variable back to true there. Happy to test a build.

@MVMcris

MVMcris commented Nov 14, 2026

Copy link
Copy Markdown

Follow-up: same result on a second Mac running macOS 27.2.1 (26B131), Mail 16.0, iCloud account, 1.1.7 with APPLE_MAIL_MCP_VISIBLE_DRAFTS=false. mail_compose_draft with from_account returned visible: false and the draft was in Drafts; mail_reply_message to that draft (with from_account) never returned and Mail had to be force-quit. [The reply draft did / did not reach Drafts.] So it doesn’t look tied to macOS 27.0.1. One difference from your tests may be that I’m replying to a message in the Drafts mailbox rather than one in the Inbox.

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.

Apple Mail: option to save and close the compose window after creating a draft

2 participants