daaki-message 0.2.0

RFC 5322 email message parser and builder
Documentation
//! RFC 5322 email message parser and builder.
//!
//! Provides three main operations:
//! - [`parse_email`]: Parse raw RFC 5322 message bytes into a structured [`ParsedEmail`]
//! - [`build_message`]: Construct RFC 5322 message bytes from an [`OutgoingEmail`]
//! - [`parse_address_list`]: Liberally parse a comma-separated address list
//!   (e.g., a user-typed recipient string or a decoded header value) into
//!   [`Address`] records, without enforcing strict outgoing-mail validation
//!
//! # References
//! - RFC 5322 (Internet Message Format)
//! - RFC 2045 (MIME Part One — body format, Content-Transfer-Encoding)
//! - RFC 2046 (MIME Part Two — media types, multipart boundaries)
//! - RFC 2047 (MIME Part Three — encoded words in headers)
//! - RFC 2183 (Content-Disposition)
//! - RFC 2231 (MIME parameter encoding)
//! - RFC 6532 (Internationalized email headers)

// `fuzzing` cfg is set by cargo-fuzz (nightly) — not known to check-cfg.
#![cfg_attr(not(fuzzing), allow(unexpected_cfgs))]

pub mod error;
pub mod types;

mod builder;
mod parser;

pub use builder::build_message;
pub use error::Error;
pub use parser::{parse_address_list, parse_email, parse_headers_only};
pub use types::{
    Address, BuiltMessage, DateTime, HeaderName, MessageId, OutgoingAttachment, OutgoingEmail,
    ParsedAttachment, ParsedEmail, TlsMode, ValidationError,
};

/// Crate-level `Result` alias using [`Error`].
pub type Result<T> = std::result::Result<T, Error>;

/// Fuzz-only entry points. Not part of the public API.
///
/// Exposed behind `#[cfg(fuzzing)]` (set automatically by `cargo-fuzz`) so
/// that out-of-crate fuzz harnesses can reach `pub(crate)` parser helpers.
#[allow(unexpected_cfgs)]
#[cfg(fuzzing)]
#[doc(hidden)]
pub mod fuzz {
    /// Thin wrapper around [`crate::parser::decode_encoded_words`].
    ///
    /// Decodes RFC 2047 encoded words in a header value.
    pub fn decode_encoded_words(input: &str) -> String {
        crate::parser::decode_encoded_words(input)
    }

    /// Thin wrapper around [`crate::parser::parse_rfc5322_date`].
    ///
    /// Parses an RFC 5322 date-time string (RFC 5322 Section 3.3).
    pub fn parse_rfc5322_date(input: &str) -> Option<crate::types::DateTime> {
        crate::parser::parse_rfc5322_date(input)
    }

    /// Thin wrapper around [`crate::builder::encode_rfc2047_if_needed`].
    ///
    /// Encodes a string using RFC 2047 encoded words if it contains non-ASCII
    /// characters (RFC 2047 Section 5).
    pub fn encode_rfc2047_if_needed(text: &str) -> String {
        crate::builder::encode_rfc2047_if_needed(text)
    }
}

/// Consumer-facing README examples must compile against the current public API.
///
/// This turns the README into executable doctests so stale field names or
/// helper signatures are caught during `cargo test --doc`.
#[cfg(doctest)]
#[doc = include_str!("../README.md")]
mod readme_doctests {}