Skip to main content

Module draft_edit

Module draft_edit 

Source
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 by mail-builder exactly as draft create encodes 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/mixed message 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 by mail-builder and the parts are re-joined under a fresh boundary. A body edit replaces “the body” whole: with plain text alone, or with a multipart/alternative of 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§

DraftEdit
The changes to make to a draft’s message. A None or empty field leaves that part of the message exactly as it is.
EditedMessage
The edited message, plus anything the caller should warn about.