miltr_common/optneg/
capability.rs

1bitflags::bitflags! {
2    /// What this milter can do.
3    ///
4    /// Some sendmail docs call this an 'action'.
5    #[derive(Debug, PartialEq, Eq, Clone, Copy)]
6    pub struct Capability: u32 {
7        /// Add headers (SMFIR_ADDHEADER)
8        const SMFIF_ADDHDRS = 0x0000_0001;
9        /// Change body chunks (SMFIR_REPLBODY)
10        const SMFIF_CHGBODY = 0x0000_0002;
11        /// Add recipients (SMFIR_ADDRCPT)
12        const SMFIF_ADDRCPT = 0x0000_0004;
13        /// Remove recipients (SMFIR_DELRCPT)
14        const SMFIF_DELRCPT = 0x0000_0008;
15        /// Change or delete headers (SMFIR_CHGHEADER)
16        const SMFIF_CHGHDRS = 0x0000_0010;
17        /// Quarantine message (SMFIR_QUARANTINE)
18        const SMFIF_QUARANTINE = 0x0000_0020;
19        /// Change the from address
20        const SMFIF_CHGFROM = 0x0000_0040;
21        /// Add a recipient
22        const SMFIF_ADDRCPT_PAR = 0x0000_0080;
23        // SMFIF_SETSYMLIST currently not supported
24        // const SMFIF_SETSYMLIST = 0x0000_0100;
25
26    }
27}
28
29impl Default for Capability {
30    /// Enables all capabilities per default
31    fn default() -> Self {
32        Capability::all()
33    }
34}
35
36impl Capability {
37    /// Merge `other` capabilities with `self`
38    ///
39    /// Currently no version dependent merging implemented
40    #[must_use]
41    pub fn merge_regarding_version(self, _version: u32, other: Self) -> Self {
42        self.intersection(other)
43    }
44}
45
46#[cfg(test)]
47mod test {
48    use super::*;
49
50    #[test]
51    fn test_create_valid() {
52        let input: u32 = 0x0000_0001;
53
54        let bitflags = Capability::from_bits(input);
55
56        assert!(bitflags.is_some());
57    }
58
59    #[test]
60    fn test_create_invalid() {
61        // SMFIF_SETSYMLIST is currently not supported
62        let input: u32 = 0x0000_0100;
63
64        let bitflags = Capability::from_bits(input);
65
66        assert!(bitflags.is_none());
67    }
68}