#[non_exhaustive]pub struct Message { /* private fields */ }Expand description
Parsed message content and headers.
§Validation
Message validation is split between this crate and the wire layer:
Message::validate_basicenforces structural invariants:Fromis set,Senderis not set withoutFrom, at least one recipient inTo/Cc/Bcc, the subject contains no raw\r,\n, or non-tab control characters, and no custom header collides with a structured field (Subject,Message-ID, …).- Per-field RFC 5322 invariants (line length, RFC 2047 encoded-word
wrapping, ASCII-after-encoding, header folding) are enforced by
email_message_wire::render_rfc822for SMTP paths. - HTTP-API adapters (Postmark, Resend, Mailgun, Loops) bypass the
wire renderer and rely on
serde_jsonstring-escaping for control-char neutralization in JSON bodies.
Adapters that bypass both the wire renderer and a JSON-encoded transport must validate header values themselves.
Implementations§
Source§impl Message
impl Message
Sourcepub const fn new(from: Mailbox, to: Vec<Address>, body: Body) -> Self
pub const fn new(from: Mailbox, to: Vec<Address>, body: Body) -> Self
Creates a message with required semantic fields.
Sourcepub const fn builder(body: Body) -> MessageBuilder
pub const fn builder(body: Body) -> MessageBuilder
Returns a builder for incrementally constructing messages.
Sourcepub const fn from_mailbox(&self) -> Option<&Mailbox>
pub const fn from_mailbox(&self) -> Option<&Mailbox>
Returns the optional From mailbox, if one has been set.
OutboundMessage validation guarantees From is present; for
already-validated messages, prefer OutboundMessage::from_mailbox
which returns &Mailbox directly.
pub const fn sender(&self) -> Option<&Mailbox>
pub fn to(&self) -> &[Address]
pub fn cc(&self) -> &[Address]
pub fn bcc(&self) -> &[Address]
pub fn reply_to(&self) -> &[Address]
pub fn subject(&self) -> Option<&str>
pub const fn date(&self) -> Option<&OffsetDateTime>
pub const fn message_id(&self) -> Option<&MessageId>
pub fn headers(&self) -> &[Header]
pub const fn body(&self) -> &Body
pub fn attachments(&self) -> &[Attachment]
pub fn with_attachments<I>(self, attachments: I) -> Selfwhere
I: IntoIterator<Item = Attachment>,
Sourcepub fn into_attachments(self) -> (Self, Vec<Attachment>)
pub fn into_attachments(self) -> (Self, Vec<Attachment>)
Split the message into an attachment-free message and its attachments.
Sourcepub fn validate_basic(&self) -> Result<(), MessageValidationError>
pub fn validate_basic(&self) -> Result<(), MessageValidationError>
Validates baseline message invariants.
§Coverage
The gate covers top-level message fields (from, sender,
recipients, subject, custom headers) and the attachments
list (filename and content-id byte discipline). It does not
recurse into Body::Mime payloads: MIME-tree fields the typed
wrappers leave unvalidated at construction (notably
MimePart::Multipart’s boundary: Option<String>, which is
lazy-checked by the wire renderer’s validate_boundary at
render time, and MimePart::Leaf’s raw body: Vec<u8>, which
is transfer-encoded at render time) are not inspected here.
Such bytes are caught by the wire renderer at
email_message_wire::render_rfc822’s header-emission and
boundary-validation stages, which reject raw CR/LF and non-ASCII
at write time. Walking the entire MimePart tree in this method
would make the gate quadratic on attacker-controlled depth, the
inverse of the renderer’s own MAX_MULTIPART_DEPTH cap.
§Errors
Returns MessageValidationError when required message fields are
missing or inconsistent.
Sourcepub fn derive_envelope(&self) -> Result<Envelope, MessageValidationError>
pub fn derive_envelope(&self) -> Result<Envelope, MessageValidationError>
Derives an SMTP envelope from message semantics.
§Errors
Returns MessageValidationError when the message does not contain the
fields needed to derive an envelope.
Trait Implementations§
Source§impl<'a> Arbitrary<'a> for Message
Available on crate feature arbitrary only.
impl<'a> Arbitrary<'a> for Message
arbitrary only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<OutboundMessage> for Message
impl From<OutboundMessage> for Message
Source§fn from(value: OutboundMessage) -> Self
fn from(value: OutboundMessage) -> Self
Source§impl JsonSchema for Message
impl JsonSchema for Message
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more