Skip to content

feat(drafts): updateDraft edits only the given fields of a draft - #292

Open
6801318d8d wants to merge 2 commits into
TKasperczyk:mainfrom
6801318d8d:feat/update-draft
Open

6801318d8d wants to merge 2 commits into
TKasperczyk:mainfrom
6801318d8d:feat/update-draft

Conversation

@6801318d8d

Copy link
Copy Markdown
Contributor

Depends on #290

This PR builds on #290 and should be merged after it. Until #290 is merged, the diff here also shows #290's commit (fix(drafts): replace a draft by saving anew and deleting the old one). The new work is the second commit only.

Change

To change one field of a draft, a caller has to use saveDraft with replaceMessageId and pass every field again: recipients, subject, the whole body and every attachment. Nothing is merged from the old draft, so a caller that only wants a new subject must first read the draft and send all of it back.

updateDraft changes only the fields it is given and keeps the rest:

  • Arguments. messageId and folderPath of the draft (checked as for saveDraft's replaceMessageId and replaceFolderPath: accessible, Drafts flag, the identity's drafts folder), plus any of to, cc, bcc, subject, body, isHtml, from, addAttachments and removeAttachments.
  • Kept from the stored draft. Every field not given is read from the stored MIME with the raw MIME helpers getMessage already uses:
    • recipients, subject, and the sender identity (X-Identity-Key, else the From address);
    • In-Reply-To and References;
    • the body in its own format. A stored HTML body is saved as stored, with no signature added. formatBodyHtml is skipped for it because it strips newlines, which would join the lines of <pre> blocks such as quoted replies. A new body is formatted as in saveDraft. isHtml without body converts the stored body;
    • every attachment, with its bytes, name and content type, carried over as inline base64.
  • Attachments. addAttachments takes the item shapes of attachments. An added attachment whose name matches an existing one replaces it. removeAttachments takes file names.
  • Save. The merged draft goes through saveDraft's replacement path from fix(drafts): replace a draft by saving anew and deleting the old one #290, so the old draft is deleted only after the new one is stored.
  • Result. { success, messageId, folderPath, changed, attachments }: the new Message-ID, the fields that changed and the final attachment names.
  • Refusals.
    • a draft that is not found, or a folder without the Drafts flag;
    • a removeAttachments name the draft does not have;
    • a call that would change nothing;
    • encrypted or signed drafts;
    • drafts scheduled by Send Later;
    • drafts whose HTML shows inline (cid:) images, which saveDraft cannot embed.
  • Not carried over. Other headers of the old draft, such as return-receipt or priority settings.

Other parts:

  • The Drafts-folder check is shared with saveDraft (findStoredDraft).
  • Tool Access makes updateDraft depend on saveDraft, as dryRunCompose depends on sendMail.
  • The stdio bridge inlines addAttachments paths, with the same limits as attachments, and gives updateDraft the 150 s draft-save timeout.
  • README: the tool is added to the compose table and to the tool count, and the sentence saying saveDraft does not return the saved draft's Message-ID is removed (it does since fix(drafts): replace a draft by saving anew and deleting the old one #290).

Validation

🤖 Generated with Claude Code

6801318d8d and others added 2 commits November 25, 2026 03:56
saveDraft with replaceMessageId passed the old header to
nsIMsgSend.createAndSendMessage as msgToReplace. For a local (mailbox://)
Drafts folder, nsMsgLocalMailFolder::CopyFileMessage treats that header as
the source of a move: EndCopy copies its properties (Message-ID, subject,
date, recipients) onto the new copy's index row, and the old message is
never removed. Each replacement therefore left the old draft in place and
added a second row that looked like the old one while pointing at the new
text, so the new Message-ID was not findable and later deletes left stale
rows behind. Thunderbird's own compose window never uses this path: it
passes null and deletes the previous draft itself.

Do the same: save the replacement as a new draft (msgToReplace is always
null), then, only after the copy has succeeded, delete the old header with
the call nsMsgCompose's RemoveCurrentDraftMessage uses (delete storage, no
Trash copy, no undo). The result reports the new draft's Message-ID as
messageId so the next replacement can name it; a failed delete is reported
as a warning instead of an error, since the new draft is already stored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Changing a draft meant calling saveDraft with replaceMessageId and passing
every field again (recipients, subject, the whole body, every attachment),
because nothing is merged from the old draft.

updateDraft takes the draft's messageId and folderPath and any of to, cc,
bcc, subject, body, isHtml, from, addAttachments and removeAttachments.
Everything not given is read from the stored MIME with the raw MIME helpers
getMessage already uses: recipients, subject, the identity (X-Identity-Key,
else the From address), In-Reply-To/References, the body in its own format,
and every attachment, carried over as inline base64 with its bytes, name
and content type. An added attachment replaces one of the same name. The
merged draft goes through saveDraft's replacement path, so the old draft is
deleted only once the new one is stored; the result lists the new
messageId, the changed fields and the final attachment names.

A stored HTML body is saved as is (saveDraft's keepHtmlBody option):
formatBodyHtml strips newlines for compose windows, which would join the
lines of <pre> blocks such as quoted replies. No signature is appended.

It refuses a missing draft, unknown removeAttachments names, calls that
change nothing, encrypted or unverifiable drafts, drafts scheduled by Send
Later and drafts whose HTML shows cid: images, which saveDraft cannot embed.

The Drafts-folder check is shared with saveDraft (findStoredDraft). Tool
access makes updateDraft depend on saveDraft, like dryRunCompose on
sendMail; the bridge inlines addAttachments paths and gives updateDraft the
150 s draft-save timeout. The README also no longer says saveDraft omits
the saved draft's Message-ID, which it returns since the previous commit.

This builds on the previous commit (TKasperczyk#290): updateDraft relies on its
replacement path (save anew, then delete the old draft) and on saveDraft
returning the new messageId.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant