Repository navigation
fix(drafts): replace a draft by saving anew and deleting the old one - #290
Open
6801318d8d wants to merge 1 commit into
Open
6801318d8d wants to merge 1 commit into
6801318d8d wants to merge 1 commit into
Conversation
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>
This branch has not been deployed
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.
Change
saveDraftwithreplaceMessageIdon a local (mailbox://) Drafts folder does not replace the draft:getMessageon the new Message-ID answers "not found";Cause.
saveDraftpasses the old header tonsIMsgSend.createAndSendMessageasmsgToReplace. For local folders:nsMsgLocalMailFolder::CopyFileMessagekeeps that header in the copy state as the source of a move;EndCopycopies its properties (Message-ID, subject, date, recipients) onto the new header withCopyPropertiesToMsgHdr;Thunderbird's compose window never takes this path.
nsMsgCompose::SendMsgToServerpassesnull, andRemoveCurrentDraftMessagedeletes the previous draft once the new one is saved.Fix.
saveDraftnow does what the compose window does:msgToReplaceis alwaysnull. The parameter ofsendMessageDirectlythat carried it is removed.RemoveCurrentDraftMessagemakes:deleteMessages([hdr], null, true, false, null, false), which deletes storage, with no Trash copy and no undo. If the save fails, the old draft is left untouched.messageId. Each save gets a new Message-ID, so a caller needs it to replace the draft again.warning, since the new draft is already stored.The tool description now says that the old draft is deleted and that the new id is returned.
Validation
Unit tests.
test/save-draft-replace.test.cjspasses 48/48. It now checks that:msgToReplaceisnull;messageIdis returned.Full suite (
npm testwith an isolatedTMPDIR): no new failures. 4 tests fail here, and the same 4 fail onmainin this environment (Windows): one case ofbridge-requests,message-headers,protected-subjects,search-messages-scan.ESLint on the changed files: 0 errors. There are 5 warnings, all on lines this PR does not touch.
Manual check on Thunderbird 160.0, Windows 11, Local Folders/Drafts. One draft was replaced three times in a row. After each replacement:
searchMessageswithdedupByMessageId: falselisted exactly one row, with the new id, subject and recipient;getMessageon the new id returned the new text and headers;Before the fix, the same steps left two index rows carrying the old Message-ID.
Not checked: IMAP Drafts folders. There, the delete is the same call the compose window makes on every draft save.
🤖 Generated with Claude Code