Repository navigation
fix(mail): hide and save drafts when visible drafts are turned off - #104
Conversation
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>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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>
|
Pushed a follow-up after an independent review (no blockers; two points about reporting, both taken):
Re-ran the eight live cases (new draft with and without |
|
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). 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. |
|
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. |
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_draftwithfrom_accountforced the window visible and left it open.safe_manage) always left their window open.On a Mac nobody watches, the windows piled up.
What changes
notesays to open the draft from the Drafts mailbox.Why hide instead of close
The issue suggested
close newMessage saving yes. On macOS 27.2 (Mail 16) that loses the draft:save, the script doesclosethe message or its window straight awayclose1 to 3 seconds laterset visible to falseThe 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_accountstill starts in a window, because the From pop-up fallback needs one and Mail ignoresset visible to trueon a draft created hidden.Testing
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.from_accountstill fails withACCOUNT_NOT_FOUNDand leaves nothing behind.🤖 Generated with Claude Code