Skip to main content

Module compose

Module compose 

Source
Expand description

RFC 5322 message composition for gmail draft create (#1923).

The encoding itself (RFC 2047 encoded words for non-ASCII subjects and display names, RFC 2231 filename*= parameters, multipart/mixed assembly and base64 transfer encoding) is mail-builder’s. This module owns what that crate leaves to its caller:

  • Input validation. A CR or LF in a subject, display name or address would let a caller inject a header, so Mailbox::parse and Composition::build reject them outright rather than relying on the encoder to neutralise them.

  • Reply threading. Gmail only files a draft into an existing thread when three things agree: the draft’s threadId, its In-Reply-To / References headers, and its Subject. ReplyContext derives the last two from the original message’s headers.

  • Reply recipients. ReplyContext::default_recipients works out who a reply goes to when the caller names nobody, as a mail client’s Reply and Reply All do (#1954). The original’s address headers are decoded with mail-parser, and every address is re-validated by Mailbox::from_parts before it can reach a header.

  • The Message-ID. mail-builder always writes one, and with its gethostname feature off its host part is localhost. A Composition::message_id_domain replaces that with the account’s own domain (#1953). This is the uploaded id only: Gmail gives the stored draft an id of its own on every save (#1966).

  • HTML bodies. An HTML body always goes out as multipart/alternative beside a plain-text part (#1955). plain_text_from_html derives that part when the caller has none, and inline_image_warning flags HTML that expects inline images nothing here attaches.

From is set only when the caller names one (Composition::from, checked against the account’s send-as aliases by the caller, #1956); otherwise Gmail fills in the authenticated account’s address.

Structs§

Attachment
A file attached to a composed message.
Composition
A message to build: text/plain, or multipart/alternative when it has an HTML body.
Mailbox
One recipient: an address with an optional display name.
ReplyContext
What a reply needs from the message it replies to.

Constants§

REPLY_HEADERS
The headers ReplyContext::from_message reads, for the caller’s messages.get(format=metadata) request.

Functions§

check_subject
Refuses a subject that would break the header.
inline_image_warning
A warning when html refers to an inline image (cid:), which no command here attaches, so the image would show as broken.
message_id_domain
The domain part of email, when it can serve as a Message-ID’s right half: a dot-separated run of letters, digits and hyphens.
plain_text_from_html
The plain-text alternative for an HTML body, as Markdown.
subject_matches_reply
Whether subject keeps a reply in the original’s thread.