Skip to content

Save drafts without a window, address drafts by id, forward draft/open modes (carries #154) - #158

Merged
patrickfreyer merged 7 commits into
mainfrom
carry/154-windowless-drafts
Nov 25, 2026
Merged

patrickfreyer merged 7 commits into
mainfrom
carry/154-windowless-drafts

Conversation

@patrickfreyer

Copy link
Copy Markdown
Owner

Carries #154 by @planttltd (its two commits are kept unchanged, with authorship).

What it does

  • compose_email(mode="draft") (plain text) and manage_drafts(action="create") save the hidden message with save instead of close window 1 saving yes. That command acted on whichever Mail window was in front, which could close or save the user's own window. Neither path opens a window now, and both report the new draft's id.
  • manage_drafts takes draft_id, so open, send and delete can target one exact draft, and list shows each draft's id. This is id-first targeting, per Epic: reply-safety redesign (verified drafts, body placement, simpler compose surface) #80.
  • forward_email takes mode (send default, draft, open) and message_id. Under --read-only it stays registered and refuses only mode="send".

Maintainer changes on top

  • Attachment names from incoming mail (forward draft): "/" is replaced with "_", and empty, "." or ".." names become "attachment", so save can't write outside the per-attachment temp folder.
  • Verified save reporting (from the second review): the Drafts snapshot runs in its own try, lookups after save can't raise (an error there would make an agent retry into a duplicate), several new matching drafts are reported as ambiguous, and the success line plus draft id print only when the draft was actually found in Drafts. Otherwise the output says "not verified, check Drafts before retrying".
  • Forward draft attachments: one that can't be saved (e.g. not downloaded yet on IMAP) is skipped and reported instead of losing the whole draft.
  • CHANGELOG credit, and a merge of current main (CHANGELOG sections merged).

Testing

Not changed here: HTML drafts and reply_to_email(mode="draft") still need a compose window. The reply path still uses window 1, tracked in #157.


Generated by Claude Code

Plantt Ltd and others added 7 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.
…edit #154 in CHANGELOG

Attachment names come from incoming mail; a "/" in one would let
'save' write outside the per-attachment temp folder. Replace "/" with "_"
and fall back to "attachment" for empty, "." or ".." names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CoqrHaj3Ru8RUcwAATtUT1
…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
…dn't be read

Second-review follow-ups: new drafts sharing a Message-ID count as one
(matching the reply-draft path), a failed snapshot reports that Drafts
could not be read, and VerifiedSaveTests moves above the __main__ guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CoqrHaj3Ru8RUcwAATtUT1

Copy link
Copy Markdown
Owner Author

Posted by Claude (AI maintainer agent) on Patrick's behalf.

Merging. What: plain-text drafts from compose_email(mode="draft") and manage_drafts(action="create") are now saved with save on the hidden message. They no longer run close window 1 saving yes, which acted on whichever Mail window was in front. Drafts can be addressed by id. forward_email gains draft/open modes and message_id. Why this approach: it removes the window 1 hazard and moves drafts to id-first targeting (#80). A save is reported as successful only once the new draft is found in Drafts; otherwise the tool says it's unverified, so an agent checks Drafts instead of retrying into a duplicate. Why it's safe: under --read-only, forward_email refuses mode="send" before any script is built, and draft/open never deliver. Attachment names from incoming mail are confined to a temp folder. An independent second review returned MERGE twice, on the original changes and on the follow-up fixes. 345 tests pass on fastmcp 4.2.6 and on the 3.1.0 floor, and CI is green.

Thanks again @planttltd. The live checks on iCloud made this much easier to trust.


Generated by Claude Code

@patrickfreyer
patrickfreyer merged commit a6d6cf5 into main Nov 25, 2026
5 checks passed
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