Expand description
In-place editing of a stored draft for gmail draft update (#1924).
drafts.update has no partial form: it replaces the whole message. So a
field-level edit fetches the draft’s RFC 5322 bytes, changes only what was
asked for, and uploads the result. Rebuilding the message from parsed
fields (crate::gmail::compose::Composition) would lose everything that
builder doesn’t model: a draft written in the Gmail UI carries an HTML
alternative, headers of its own, and attachments whose exact encoding
nothing here needs to touch. DraftEdit::apply instead edits the bytes
in place, and everything not named survives byte for byte:
- Header edits (
From,To,Cc,Bcc,Subject) replace just those header fields, encoded bymail-builderexactly asdraft createencodes them. The body is not touched. - Structural edits (the body, adding or removing attachments) work on
the top-level MIME entity only. For a
multipart/mixedmessage the first non-attachment part is “the body” and every other part is kept as it is; any other message is itself “the body”. New parts are written bymail-builderand the parts are re-joined under a fresh boundary. A body edit replaces “the body” whole: with plain text alone, or with amultipart/alternativeof plain text and HTML (#1955). Neither half of an existing alternative is ever kept, so the two can’t drift apart.
Every other top-level header that isn’t a Content-* header (From
unless it is edited, Date, Message-ID, In-Reply-To, References,
…) is always kept in the upload. Gmail then replaces the stored draft’s
Message-ID and Date on every save (#1966), so those two survive only
as far as the request.
Structs§
- Draft
Edit - The changes to make to a draft’s message. A
Noneor empty field leaves that part of the message exactly as it is. - Edited
Message - The edited message, plus anything the caller should warn about.