msg_auth_status/alloc_yes/
auth_results.rs1use crate::auth::SmtpAuthResult;
4use crate::dkim::DkimResult;
5use crate::iprev::IpRevResult;
6use crate::spf::SpfResult;
7
8use crate::auth_results::*;
9
10use crate::error::AuthResultsError;
11
12#[derive(Clone, Debug, Default, PartialEq)]
14pub struct UnknownResult<'hdr> {
15 pub raw: &'hdr str,
17}
18
19#[derive(Clone, Debug, Default, PartialEq)]
21pub struct AuthenticationResults<'hdr> {
22 pub host: Option<HostVersion<'hdr>>,
24 pub smtp_auth_result: Vec<SmtpAuthResult<'hdr>>,
26 pub spf_result: Vec<SpfResult<'hdr>>,
28 pub dkim_result: Vec<DkimResult<'hdr>>,
30 pub iprev_result: Vec<IpRevResult<'hdr>>,
32 pub unknown_result: Vec<UnknownResult<'hdr>>,
34 pub none_done: bool,
36 pub raw: Option<&'hdr str>,
38 pub errors: Vec<AuthResultsError<'hdr>>,
40}
41
42#[cfg(any(feature = "alloc", feature = "std"))]
44#[derive(Debug, Default)]
45pub struct MessageAuthStatus<'hdr> {
46 pub auth_results: Vec<AuthenticationResults<'hdr>>,
48}
49
50#[derive(Debug, PartialEq)]
52pub enum MessageAuthStatusError {}
53
54impl<'hdr> MessageAuthStatus<'hdr> {
55 #[cfg(feature = "mail_parser")]
57 pub fn from_mail_parser(
58 msg: &'hdr mail_parser::Message<'hdr>,
59 ) -> Result<Self, MessageAuthStatusError> {
60 let mut new_self = Self {
61 auth_results: vec![],
62 };
63
64 new_self.auth_results = msg
65 .header_values("Authentication-Results")
66 .map(|mh| mh.into())
67 .collect();
68
69 Ok(new_self)
70 }
71}
72
73#[cfg(test)]
74#[cfg(feature = "mail_parser")]
75mod test {
76 use super::*;
77 use insta::assert_debug_snapshot;
78 use rstest::rstest;
79 use std::{fs::File, io::Read, path::PathBuf};
80
81 fn load_test_data(file_location: &str) -> Vec<u8> {
82 let mut file = File::open(file_location).unwrap();
83 let mut data: Vec<u8> = vec![];
84 file.read_to_end(&mut data).unwrap();
85 data
86 }
87
88 #[rstest]
89 fn from_mail_parser(#[files("test_data/*.eml")] file_path: PathBuf) {
90 let new_snapshot_path = file_path.with_extension("snap");
91
92 insta::with_settings!({snapshot_path => new_snapshot_path}, {
93 insta::allow_duplicates! {
94 let raw = load_test_data(file_path.to_str().unwrap());
95 let parser = mail_parser::MessageParser::default();
96 let parsed_message = parser.parse(&raw).unwrap();
97 let status = MessageAuthStatus::from_mail_parser(&parsed_message).unwrap();
98 assert_debug_snapshot!(&status);
99 }
100 });
101 }
102}