Skip to main content

mailrs_mail_builder/
lib.rs

1#![deny(missing_docs)]
2#![deny(rustdoc::broken_intra_doc_links)]
3
4//! Outbound mail builder — the inverse of the mailrs parse stones.
5//!
6//! Constructs canonically-compliant RFC 5322 / 2046 / 2047 / 2231
7//! raw bytes for outbound delivery. Lives across from the parse
8//! stones ([`mailrs-rfc5322`], [`mailrs-rfc2047`], [`mailrs-mime`])
9//! so the same MIME compliance invariants we enforce on inbound
10//! can be enforced on outbound — the same canonical envelope, the
11//! same encoded-word boundaries, the same CTE-selection heuristics.
12//!
13//! ## Why a builder stone
14//!
15//! Outbound message construction in mail servers tends to grow
16//! ad-hoc string formatting that drifts toward MIME non-compliance
17//! over time (lone LF, mis-folded headers, bad boundaries, missing
18//! `Content-Transfer-Encoding`). When a message looks merely
19//! "weird" rather than "broken", receiving MTAs silently lower
20//! reputation rather than reject — the failure mode is "we got
21//! banned without ever seeing a 5xx". A canonical builder closes
22//! that whole class of bug at the source.
23//!
24//! ## Scope
25//!
26//! - Plain-text single-part messages.
27//! - `multipart/alternative` (text + html).
28//! - `multipart/mixed` (body + attachments).
29//! - Encoded-word (RFC 2047) for non-ASCII header values.
30//! - Soft-fold (RFC 5322 §2.2.3) at 78 chars.
31//! - CTE auto-selection: 7bit / quoted-printable / base64.
32//! - Boundary collision-scan (regenerate if body contains it).
33//!
34//! Out of scope (deliberate): S/MIME, OpenPGP/MIME, calendar
35//! invites (use [`mailrs-ical`]), DKIM signing (use
36//! [`mailrs-dkim`]), DSN formatting (use
37//! [`mailrs-outbound-queue::dsn`] — to be migrated onto this
38//! builder in ckpt 1).
39//!
40//! ## Status
41//!
42//! 0.1 — initial MVP. The API is intentionally narrow to match
43//! the three internal mailrs use cases (DSN, DMARC report, future
44//! TLS-RPT). Wider API surface lands in 1.0 after the deliverability
45//! hardening pass (ckpt 2 in the v8 RFC).
46//!
47//! [`mailrs-rfc5322`]: https://crates.io/crates/mailrs-rfc5322
48//! [`mailrs-rfc2047`]: https://crates.io/crates/mailrs-rfc2047
49//! [`mailrs-mime`]: https://crates.io/crates/mailrs-mime
50//! [`mailrs-ical`]: https://crates.io/crates/mailrs-ical
51//! [`mailrs-dkim`]: https://crates.io/crates/mailrs-dkim
52
53mod builder;
54mod encode;
55mod multipart;
56mod strict;
57
58pub use builder::{Attachment, MessageBuilder};
59pub use encode::{ContentTransferEncoding, choose_cte};
60pub use multipart::{generate_boundary, multipart_envelope};
61pub use strict::{LintError, lint};