Fix: edit_draft no longer corrupts the other body on a partial edit#82
Merged
MadLlama25 merged 1 commit intoJul 6, 2026
Merged
Conversation
updateDraft extracted the existing body values with a `|| true` predicate that always matched, so both the text and html bodies resolved to the first bodyValue (Object.values(bodyValues)[0]). A subject-only edit, or an edit touching only one body, therefore overwrote or lost the other format -- and because mail clients render the HTML alternative (RFC 2046 5.1.4), recipients could see the wrong content. Select each existing body value by MIME type (text/plain, text/html), keyed into bodyValues by the matched part's partId. The MIME-type match also avoids synthesising a phantom part on a single-format draft, which the server aliases into both the textBody and htmlBody lists. Adds 3 unit tests covering the aliased single-format and dual-format shapes.
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.
The bug
updateDraftrebuilds a draft's body to re-send it (JMAP bodies are immutable, so an edit is a destroy + recreate). It reads the existing bodies back from the fetched email:The
|| truemakes the predicate unconditionally true — and the bodyValue objects fromObject.values()have nopartIdfield anyway (partId is the map key). So bothexistingTextBodyandexistingHtmlBodyresolve toObject.values(bodyValues)[0], the first part.Consequences on an edit that doesn't explicitly set a given body:
textBodyandhtmlBodylists (a text-only draft'shtmlBodyentry hastype: "text/plain"), so the lookup pulls that value into the missing format and a phantom part is synthesised on recreate.The fix
Select each existing body value by MIME type, keyed into
bodyValuesby the matched part'spartId:Matching by MIME type (rather than only keying by partId) is what handles the single-format aliasing: a text-only draft's
htmlBodyentry istext/plain, so it correctly yields no HTML value and no phantom part.typeis already requested in theEmail/getbodyProperties, so there is no request change.Verified against a live Fastmail account (text-only, html-only, and dual-part drafts):
Tests
Adds 3 unit tests to the
updateDraftsuite covering the aliased single-format and dual-format shapes, asserting on the recreate output. Each fails before the fix and passes after.(The 2 pre-existing
safeWritePathsymlink tests fail locally on Windows — EPERM, symlink creation needs elevation — but are untouched by this change and pass on CI.)