-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-spf-strict.rs
63 lines (55 loc) · 2.06 KB
/
build-spf-strict.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use decon_spf::mechanism::{Kind, Mechanism, ParsedMechanism, Qualifier};
use decon_spf::{Builder, SpfBuilder};
fn main() {
let mut spf1: SpfBuilder<Builder> = SpfBuilder::new();
spf1.set_v1();
let ip_m_1 = ParsedMechanism::new("+ip4:203.32.160.0/24");
let ip_m_2 = ParsedMechanism::new("+ip4:203.32.166.0/24");
if let Ok(ip1) = ip_m_1 {
spf1.append_mechanism(ip1.network());
}
if let Ok(ip2) = ip_m_2 {
spf1.append_mechanism(ip2.network());
}
if let Ok(mx) = ParsedMechanism::new("mx") {
spf1.append_mechanism(mx.txt());
}
// example.xx is not a valid domain. There is no TLD of xx
if let Ok(m) = "a:test.xx".parse::<Mechanism<String>>() {
// Append does not occur
spf1.append_mechanism(m);
}
println!("New spf 1: >{}<", spf1);
assert_eq!(
spf1.to_string(),
"v=spf1 mx ip4:203.32.160.0/24 ip4:203.32.166.0/24"
);
let mut spf2: SpfBuilder<Builder> = SpfBuilder::new();
spf2.set_v1();
let ip = "203.32.166.0/24".parse().unwrap();
spf2.append_mechanism(Mechanism::ip(Qualifier::Pass, ip));
println!("\nNew spf 2: >{}<", spf2);
println!("Attempt to create invalid mx to spf2");
match Mechanism::mx(Qualifier::Pass).with_rrdata("example.xx") {
Ok(m) => {
spf2.append_mechanism(m);
}
Err(e) => {
println!("Error creating Mechanism: \"{}\"", e.to_string());
}
};
println!("Add mx to spf2");
spf2.append_mechanism(Mechanism::mx(Qualifier::Pass));
println!("Altered spf 2: >{}<", spf2);
println!("Clear mx from spf2");
spf2.clear_mechanism(Kind::MX);
println!("Altered spf 2: >{}<", spf2);
let mut spf3: SpfBuilder<Builder> = SpfBuilder::new();
spf3.set_v2_pra();
spf3.append_mechanism(Mechanism::a(Qualifier::Pass));
spf3.append_mechanism(Mechanism::all_with_qualifier(Qualifier::Neutral));
println!("\nNew spf 3: >{}<", spf3);
println!("Change spf3 all to Fail");
spf3.append_mechanism(Mechanism::all());
println!("Altered spf 3: >{}<", spf3);
}