use crate::auth::SmtpAuthResult;
use crate::dkim::DkimResult;
use crate::iprev::IpRevResult;
use crate::spf::SpfResult;
use crate::auth_results::*;
use crate::error::AuthResultsError;
#[derive(Clone, Debug, Default, PartialEq)]
pub struct UnknownResult<'hdr> {
pub raw: &'hdr str,
}
#[derive(Clone, Debug, Default, PartialEq)]
pub struct AuthenticationResults<'hdr> {
pub host: Option<HostVersion<'hdr>>,
pub smtp_auth_result: Vec<SmtpAuthResult<'hdr>>,
pub spf_result: Vec<SpfResult<'hdr>>,
pub dkim_result: Vec<DkimResult<'hdr>>,
pub iprev_result: Vec<IpRevResult<'hdr>>,
pub unknown_result: Vec<UnknownResult<'hdr>>,
pub none_done: bool,
pub raw: Option<&'hdr str>,
pub errors: Vec<AuthResultsError<'hdr>>,
}
#[cfg(any(feature = "alloc", feature = "std"))]
#[derive(Debug, Default)]
pub struct MessageAuthStatus<'hdr> {
auth_results: Vec<AuthenticationResults<'hdr>>,
}
#[derive(Debug, PartialEq)]
pub enum MessageAuthStatusError {}
impl<'hdr> MessageAuthStatus<'hdr> {
#[cfg(feature = "mail_parser")]
pub fn from_mail_parser(
msg: &'hdr mail_parser::Message<'hdr>,
) -> Result<Self, MessageAuthStatusError> {
let mut new_self = Self {
auth_results: vec![],
};
new_self.auth_results = msg
.header_values("Authentication-Results")
.map(|mh| mh.into())
.collect();
Ok(new_self)
}
}
#[cfg(test)]
#[cfg(feature = "mail_parser")]
mod test {
use super::*;
use insta::assert_debug_snapshot;
use rstest::rstest;
use std::{fs::File, io::Read, path::PathBuf};
fn load_test_data(file_location: &str) -> Vec<u8> {
let mut file = File::open(file_location).unwrap();
let mut data: Vec<u8> = vec![];
file.read_to_end(&mut data).unwrap();
data
}
#[rstest]
fn from_mail_parser(#[files("test_data/*.eml")] file_path: PathBuf) {
let new_snapshot_path = file_path.with_extension("snap");
insta::with_settings!({snapshot_path => new_snapshot_path}, {
insta::allow_duplicates! {
let raw = load_test_data(file_path.to_str().unwrap());
let parser = mail_parser::MessageParser::default();
let parsed_message = parser.parse(&raw).unwrap();
let status = MessageAuthStatus::from_mail_parser(&parsed_message).unwrap();
assert_debug_snapshot!(&status);
}
});
}
}