Repository navigation
Save drafts without a window, address drafts by id, and add draft/open modes to forward_email - #154
Merged
patrickfreyer merged 2 commits intoNov 25, 2026
Conversation
added 2 commits
November 20, 2026 14:44
compose_email(mode="draft") made a hidden message (visible:false) and
then ran "close window 1 saving yes". The message has no window, so that
acted on whichever Mail window was in front. It now calls "save" on the
hidden message, which files it in Drafts without opening anything, and
reports the new draft's id. manage_drafts(action="create") had no save
step at all; it now saves the same way and reports the id.
The id is found by snapshotting the ids in Mail's Drafts mailbox before
the message is made and taking the one new draft with the same subject.
manage_drafts takes draft_id, so open, send and delete can act on one
draft by its Mail id ("«class mssg» id N", re-read to catch a miss)
instead of the first subject match. action="list" shows each id.
With body_html, compose_email still pastes the body into a compose
window, so that draft path is unchanged.
forward_email could only send. It now takes mode ("send", the default,
"draft" or "open") and message_id, which looks the message up directly
instead of taking the first subject match.
mode="open" runs Mail's own forward and leaves its compose window up for
review without sending.
mode="draft" saves to Drafts without opening a window. Mail's forward
command opens a compose window even "without opening window", so the
draft is a new hidden message instead: the original's plain-text content
under a "Begin forwarded message:" header, with a copy of each original
attachment (saved to a temporary folder, attached, then removed). It is
saved and its id found as compose_email's drafts are. It has no HTML
formatting.
With a non-sending mode, forward_email no longer needs to be removed
under --read-only; like compose_email and reply_to_email it stays
registered and refuses only mode="send". Its "to" parameter now comes
second, since subject_keyword is optional when message_id is given.
This was referenced Nov 25, 2026
Closed
Closed
patrickfreyer
pushed a commit
that referenced
this pull request
Nov 25, 2026
…the snapshot and lookups; skip attachments that can't be copied From the second review of #154: - The Drafts snapshot runs in its own try, so a Drafts mailbox Mail can't read no longer stops a draft from being saved (main didn't need it). - Lookups after 'save' can't raise: an error there made the tool report 'Error' for a saved draft, and a retry created a duplicate. - More than one new matching draft (Gmail sync copies) is reported as ambiguous instead of picking the first id. - compose/create/forward print the success line and draft id only when the draft was found; otherwise they say the save is not verified. - forward draft: an attachment that can't be saved (e.g. not downloaded on IMAP) is skipped and reported instead of losing the whole draft. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CoqrHaj3Ru8RUcwAATtUT1
Owner
|
Posted by Claude (AI maintainer agent) on Patrick's behalf. Thank you @planttltd! This landed via #158, which keeps your two commits as-is. Changes on top: attachment names from incoming mail are kept inside the temp folder; a draft is reported as saved (with its id) only once it's found in Drafts, otherwise as unverified; Gmail sync copies count once; and an attachment that can't be copied is skipped and reported instead of losing the whole forward draft. Closing in favor of #158. Generated by Claude Code |
patrickfreyer
added a commit
that referenced
this pull request
Nov 25, 2026
Save drafts without a window, address drafts by id, forward draft/open modes (carries #154)
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
compose_email(mode="draft")(plain text) makes the message withvisible:falseand then runsclose window 1 saving yes. The message has no window, so that line acts on whichever Mail window is in front: a viewer gets closed, or another compose window gets saved and closed.manage_drafts(action="create")has no save step. It leaves the hidden message for Mail to autosave and cannot say which draft it made.manage_draftsopen,sendanddeleteact on the first draft whose subject containsdraft_subject, andlistshows no ids, so there is no way to point at one draft exactly.search_emails,read_email,move_emailandmanage_trashalready work by Mail id.forward_emailcan only send. There is no way to save a forward for review, so it is removed under--read-only.Changes
Two commits.
Save drafts without a window and address drafts by id
compose_email(mode="draft")(plain text) andmanage_drafts(action="create")callsaveon the hidden message. That files it in Drafts with no window. Both reportDraft id: N.drafts mailboxbefore the message is made and taking the one new draft with the same subject. Using the app-level Drafts mailbox covers a draft that lands in another account's Drafts because of the sender alias.manage_draftstakesdraft_id. With it,open,sendanddeletelook the draft up as«class mssg» id N of draftsMailboxand read its id back, so a miss is reported as "No draft found" rather than acting on a stale reference.draft_subjectworks as before.listshows each draft's id.forward_email: draft and open modes, andmessage_idmode="send"(default) is unchanged.mode="open"runs Mail's own forward and leaves its compose window up for review. Nothing is sent.mode="draft"saves to Drafts without opening a window. Mail'sforwardcommand opens a compose window evenwithout opening window, so the draft is a new hidden message: the original's plain-text content under aBegin forwarded message:header (From, Subject, Date, To), with a copy of each original attachment. Attachments are saved to a temporary folder, one subfolder each so equal names cannot clash, attached, and the folder is removed afterwards. The draft is saved and its id reported as above.message_idlooks the original up directly, as inread_email.subject_keywordis now optional, sotomoves to second place. Callers using keyword arguments are unaffected.--read-only,forward_emailstays registered likecompose_emailandreply_to_emailand refuses onlymode="send".All new paths go through
run_applescript, so they holdmail_automation_lock.What can and can't be done without a window
compose_email(mode="draft"), plain textmanage_drafts(action="create")forward_email(mode="draft")compose_email(mode="draft", body_html=...)reply_to_email(mode="draft")forward_email(mode="open"),manage_drafts(action="open")Replies are left as they are on purpose. Mail's
replycommand opens a compose window evenwithout opening window, and it is the only way AppleScript getsIn-Reply-ToandReferences. A windowless reply would have to be a new, unthreaded message, which is a worse reply than the current one. The same limit is why a windowless forward is rebuilt rather than made withforward: it is not threaded and carries no HTML formatting. Callers who want Mail's own forward can usemode="open".Testing
PYTHONPATH=plugin python -m pytest tests/ -q: 340 passed (325 before), 194 subtests. New tests intests/test_windowless_drafts.pycheck that the draft scripts contain noactivate,keystroke, System Events, pasteboard,close windoworwith opening window, that the Drafts snapshot comes before the message is made andsaveafter it, that id lookups never scan the mailbox, that bad ids are rejected before any AppleScript runs, that the attachment folder is removed, and that--read-onlystill allowsdraftandopen.python scripts/check_versions.py,python -m buildandpython scripts/verify_wheel.pypass.manage_draftslist, create, open, send and delete by id and by subject, forward draft, open and send) compiles withosacompile.manage_drafts(action="delete", draft_id=...):compose_email(mode="draft")with an attachment,manage_drafts(action="create"), andforward_email(mode="draft", message_id=...)of a message with two PDF attachments. Each draft appeared in Drafts with its id, recipients and attachments; Mail's window count did not change. A second delete of the same id returned "No draft found matching: id N".openpaths and anything that sends.