#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
pub enum Details {
Mechanism(String),
Problem(String),
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
pub struct Result {
pub result: String,
pub details: Details,
}
impl From<viaspf::QueryResult> for Result {
fn from(other: viaspf::QueryResult) -> Self {
Self {
result: other.spf_result.to_string(),
details: other.cause.map_or_else(
|| Details::Mechanism("default".to_string()),
|cause| match cause {
viaspf::SpfResultCause::Match(mechanism) => {
Details::Mechanism(mechanism.to_string())
}
viaspf::SpfResultCause::Error(error) => Details::Problem(error.to_string()),
},
),
}
}
}
pub async fn evaluate(
resolver: &trust_dns_resolver::TokioAsyncResolver,
ip: std::net::IpAddr,
sender: &viaspf::Sender,
) -> Result {
viaspf::evaluate_sender(resolver, &viaspf::Config::default(), ip, sender, None)
.await
.into()
}