use std::collections::HashMap; use chrono::{DateTime,FixedOffset,ParseError}; #[derive(Debug, PartialEq, Default)] pub enum HeaderDate { Parsed(DateTime), Unknown(String, ParseError), #[default] None, } #[derive(Debug, PartialEq)] pub struct AddrSpec { pub local_part: String, pub domain: String, } impl AddrSpec { pub fn fully_qualified(&self) -> String { format!("{}@{}", self.local_part, self.domain) } } #[derive(Debug, PartialEq)] pub struct MailboxRef { // The actual "email address" like hello@example.com pub addrspec: AddrSpec, pub name: Option, } impl From for MailboxRef { fn from(addr: AddrSpec) -> Self { MailboxRef { name: None, addrspec: addr, } } } #[derive(Debug, PartialEq)] pub struct GroupRef { pub name: String, pub participants: Vec, } #[derive(Debug, PartialEq)] pub enum AddressRef { Single(MailboxRef), Many(GroupRef), } impl From for AddressRef { fn from(mx: MailboxRef) -> Self { AddressRef::Single(mx) } } impl From for AddressRef { fn from(grp: GroupRef) -> Self { AddressRef::Many(grp) } } #[derive(Debug, PartialEq)] pub struct MessageId<'a> { pub left: &'a str, pub right: &'a str, } #[derive(Debug, PartialEq, Default)] pub struct Trace<'a> { // 3.6.7 Traces pub received: Vec<&'a str>, pub return_path: Option, // 3.6.6. Resent Fields pub resent_date: HeaderDate, pub resent_from: Vec, pub resent_sender: Option, pub resent_to: Vec, pub resent_cc: Vec, pub resent_bcc: Vec, pub resent_msg_id: Option>, // 3.6.8. Optional Fields pub optional: HashMap<&'a str, String>, //pub failed: HashMap<&'a str, String>, //pub garbage: &'a str, } /// Permissive Header Section /// /// This is a structure intended for parsing/decoding, /// hence it's support cases where the email is considered /// as invalid according to RFC5322 but for which we can /// still extract some data. #[derive(Debug, Default)] pub struct CommonFields<'a> { // 3.6.1. The Origination Date Field pub date: HeaderDate, // 3.6.2. Originator Fields pub from: Vec, pub sender: Option, pub reply_to: Vec, // 3.6.3. Destination Address Fields pub to: Vec, pub cc: Vec, pub bcc: Vec, // 3.6.4. Identification Fields pub msg_id: Option>, pub in_reply_to: Vec>, pub references: Vec>, // 3.6.5. Informational Fields pub subject: Option, pub comments: Vec, pub keywords: Vec, // 3.6.8. Optional Fields pub optional: HashMap<&'a str, String>, //pub failed: HashMap<&'a str, String>, //pub garbage: &'a str, } pub struct HeaderSection<'a> { // 3.6.7 Traces pub traces: Vec>, // 3.6.x pub common: CommonFields<'a>, }