kumo_dmarc/types/
results.rs

1use crate::types::identifier::Identifier;
2use crate::types::policy::Policy;
3use crate::types::policy_override::PolicyOverrideReason;
4use instant_xml::{FromXml, ToXml};
5use kumo_spf::SpfDisposition;
6use serde::Serialize;
7use std::fmt;
8use std::net::IpAddr;
9
10#[derive(Debug, Eq, FromXml, PartialEq, ToXml)]
11#[xml(scalar, rename_all = "lowercase")]
12pub enum SpfScope {
13    Helo,
14    Mfrom,
15}
16
17#[derive(Debug, Eq, FromXml, PartialEq, ToXml)]
18#[xml(rename = "spf")]
19pub struct SpfAuthResult {
20    domain: String,
21    scope: SpfScope,
22    result: SpfDisposition,
23}
24
25#[derive(Debug, Eq, PartialEq, ToXml)]
26#[xml(rename = "auth_results")]
27pub struct AuthResults {
28    dkim: Vec<DkimAuthResult>,
29    spf: Vec<SpfAuthResult>,
30}
31
32#[derive(Debug, Eq, PartialEq, ToXml)]
33#[xml(rename = "record")]
34pub struct Results {
35    row: Row,
36    identifiers: Identifier,
37    auth_results: AuthResults,
38}
39
40#[derive(Debug, Eq, PartialEq, ToXml)]
41#[xml(scalar, rename_all = "lowercase")]
42pub enum DkimResult {
43    None,
44    Pass,
45    Fail,
46    Policy,
47    Neutral,
48    TempError,
49    PermError,
50}
51
52#[derive(Debug, Eq, PartialEq, ToXml)]
53pub struct DkimAuthResult {
54    domain: String,
55    selector: Option<String>,
56    result: DkimResult,
57    human_result: Option<String>,
58}
59
60#[derive(Debug, Eq, PartialEq, Clone, Copy, ToXml, Serialize)]
61#[xml(scalar, rename_all = "lowercase")]
62pub enum DmarcResult {
63    Pass,
64    Fail,
65}
66
67impl DmarcResult {
68    pub fn as_str(&self) -> &'static str {
69        match self {
70            Self::Pass => "pass",
71            Self::Fail => "fail",
72        }
73    }
74}
75
76impl fmt::Display for DmarcResult {
77    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
78        write!(f, "{}", self.as_str())
79    }
80}
81
82// A synthetic type to bundle the result with a reason
83#[derive(Debug, Eq, PartialEq, ToXml, Serialize)]
84#[xml(rename_all = "lowercase")]
85pub struct DmarcResultWithContext {
86    pub result: DmarcResult,
87    pub context: String,
88}
89
90#[derive(Debug, Eq, PartialEq, ToXml)]
91#[xml(rename = "policy_evaluated")]
92pub struct PolicyEvaluated {
93    disposition: Policy,
94    dkim: DmarcResult,
95    spf: DmarcResult,
96    reason: Vec<PolicyOverrideReason>,
97}
98
99#[derive(Debug, Eq, PartialEq, ToXml)]
100#[xml(rename = "row")]
101pub struct Row {
102    source_ip: IpAddr,
103    count: u64,
104    policy_evaluated: PolicyEvaluated,
105}