mailbourne_core/message.rs
1//! # message — the letter inside
2//!
3//! The message is everything transmitted after SMTP's `DATA` command: the
4//! headers (`From:`, `To:`, `Subject:`, `Date:`) and the body, in the format
5//! RFC 5322 defines. DKIM signs *this* (or parts of it); the envelope is
6//! never signed because it is rewritten at every hop.
7
8/// A raw RFC 5322 message as bytes.
9///
10/// Held as bytes rather than a parsed structure because DKIM verification
11/// is canonicalization-sensitive: the signature covers the *exact* bytes,
12/// so re-serializing a parsed form would break it. Parsing (via
13/// `mail-parser`) is done on demand, never destructively.
14#[derive(Debug, Clone)]
15pub struct Message {
16 raw: Vec<u8>,
17}
18
19impl Message {
20 /// Wraps raw RFC 5322 bytes without validating them.
21 ///
22 /// Validation and construction helpers arrive with the builder
23 /// integration (`mail-builder`).
24 pub fn from_raw(raw: Vec<u8>) -> Self {
25 Self { raw }
26 }
27
28 /// The exact bytes of the message — what travels inside `DATA`, and
29 /// what DKIM signatures are computed over.
30 pub fn raw(&self) -> &[u8] {
31 &self.raw
32 }
33}