msg_auth_status/
dkim.rs

1//! Method dkim Result and associated types
2
3/// Parsed dkim Result - see RFC 6376 for the header tags
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct DkimResult<'hdr> {
6    /// dkim Result (per RFC)
7    pub code: DkimResultCode,
8    /// Reason if supplied (per RFC)
9    pub reason: Option<&'hdr str>,
10    /// header.d (per RFC)
11    pub header_d: Option<&'hdr str>,
12    /// header.i (per RFC)
13    pub header_i: Option<&'hdr str>,
14    /// header_b (per RFC)
15    pub header_b: Option<&'hdr str>,
16    /// header.a (per RFC)
17    pub header_a: Option<DkimAlgorithm<'hdr>>,
18    /// header.s (per RFC)
19    pub header_s: Option<&'hdr str>,
20    /// Unparsed raw
21    pub raw: Option<&'hdr str>,
22}
23
24impl<'hdr> DkimResult<'hdr> {
25    pub(crate) fn set_header(&mut self, prop: &DkimHeader<'hdr>) -> bool {
26        match prop {
27            DkimHeader::D(val) => self.header_d = Some(val),
28            DkimHeader::I(val) => self.header_i = Some(val),
29            DkimHeader::B(val) => self.header_b = Some(val),
30            DkimHeader::A(val) => self.header_a = Some(val.clone()),
31            DkimHeader::S(val) => self.header_s = Some(val),
32            _ => {}
33        }
34        true
35    }
36    // TODO: Not supported
37    pub(crate) fn set_policy(&mut self, _prop: &ptypes::DkimPolicy<'hdr>) -> bool {
38        true
39    }
40}
41
42/// DKIM Result Codes - s.2.7.1
43#[derive(Clone, Debug, Default, PartialEq)]
44pub enum DkimResultCode {
45    /// Result code not seen
46    #[default]
47    Unknown,
48    /// The message was not signed.
49    NoneDkim,
50    /// The message was signed, the signature or signatures were
51    /// acceptable to the ADMD, and the signature(s) passed verification
52    /// tests.
53    Pass,
54    /// The message was signed and the signature or signatures were acceptable
55    /// to the ADMD, but they failed the verification test(s).
56    Fail,
57    /// The message was signed, but some aspect of the signature or
58    /// signatures was not acceptable to the ADMD.
59    Policy,
60    /// The message was signed, but the signature or signatures
61    /// contained syntax errors or were not otherwise able to be
62    /// processed.  This result is also used for other failures not
63    /// covered elsewhere in this list.
64    Neutral,
65    /// The message could not be verified due to some error that
66    /// is likely transient in nature, such as a temporary inability to
67    /// retrieve a public key.  A later attempt may produce a final
68    /// result.
69    TempError,
70    /// The message could not be verified due to some error that
71    /// is unrecoverable, such as a required header field being absent.
72    /// A later attempt is unlikely to produce a final result.
73    PermError,
74}
75
76/// The 'q' Tag - see RFC 6376 s. 3.5
77#[derive(Clone, Debug, Default, PartialEq)]
78pub enum DkimQueryMethod<'hdr> {
79    /// Domain Name System (DNS)
80    #[default]
81    DnsTxt,
82    /// Unknown
83    Unknown(&'hdr str),
84}
85
86pub mod ptypes;
87pub use ptypes::DkimProperty;
88
89mod algorithm;
90pub use algorithm::DkimAlgorithm;
91
92mod canonicalization;
93pub use canonicalization::DkimCanonicalization;
94
95mod signature;
96pub use signature::DkimSignature;
97
98mod header;
99pub use header::DkimHeader;
100
101mod timestamp;
102pub use timestamp::DkimTimestamp;
103
104mod version;
105pub use version::DkimVersion;