-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
report_dmarc_generate.rs
109 lines (106 loc) · 4.54 KB
/
report_dmarc_generate.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* Copyright (c) 2020-2023, Stalwart Labs Ltd.
*
* Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
* https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
* <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
* option. This file may not be copied, modified, or distributed
* except according to those terms.
*/
use mail_auth::report::{
ActionDisposition, Alignment, DKIMAuthResult, Disposition, DkimResult, DmarcResult,
PolicyOverride, PolicyOverrideReason, Record, Report, SPFAuthResult, SPFDomainScope, SpfResult,
};
fn main() {
// Generate DMARC aggregate report
let report = Report::new()
.with_version(1.0)
.with_org_name("Initech Industries Incorporated")
.with_email("dmarc@initech.net")
.with_extra_contact_info("XMPP:dmarc@initech.net")
.with_report_id("abc-123")
.with_date_range_begin(12345)
.with_date_range_end(12346)
.with_error("Did not include TPS report cover.")
.with_domain("example.org")
.with_version_published(1.0)
.with_adkim(Alignment::Relaxed)
.with_aspf(Alignment::Strict)
.with_p(Disposition::Quarantine)
.with_sp(Disposition::Reject)
.with_testing(false)
.with_record(
Record::new()
.with_source_ip("192.168.1.2".parse().unwrap())
.with_count(3)
.with_action_disposition(ActionDisposition::Pass)
.with_dmarc_dkim_result(DmarcResult::Pass)
.with_dmarc_spf_result(DmarcResult::Fail)
.with_policy_override_reason(
PolicyOverrideReason::new(PolicyOverride::Forwarded)
.with_comment("it was forwarded"),
)
.with_policy_override_reason(
PolicyOverrideReason::new(PolicyOverride::MailingList)
.with_comment("sent from mailing list"),
)
.with_envelope_from("hello@example.org")
.with_envelope_to("other@example.org")
.with_header_from("bye@example.org")
.with_dkim_auth_result(
DKIMAuthResult::new()
.with_domain("test.org")
.with_selector("my-selector")
.with_result(DkimResult::PermError)
.with_human_result("failed to parse record"),
)
.with_spf_auth_result(
SPFAuthResult::new()
.with_domain("test.org")
.with_scope(SPFDomainScope::Helo)
.with_result(SpfResult::SoftFail)
.with_human_result("dns timed out"),
),
)
.with_record(
Record::new()
.with_source_ip("a:b:c::e:f".parse().unwrap())
.with_count(99)
.with_action_disposition(ActionDisposition::Reject)
.with_dmarc_dkim_result(DmarcResult::Fail)
.with_dmarc_spf_result(DmarcResult::Pass)
.with_policy_override_reason(
PolicyOverrideReason::new(PolicyOverride::LocalPolicy)
.with_comment("on the white list"),
)
.with_policy_override_reason(
PolicyOverrideReason::new(PolicyOverride::SampledOut)
.with_comment("it was sampled out"),
)
.with_envelope_from("hello2example.org")
.with_envelope_to("other2@example.org")
.with_header_from("bye2@example.org")
.with_dkim_auth_result(
DKIMAuthResult::new()
.with_domain("test2.org")
.with_selector("my-other-selector")
.with_result(DkimResult::Neutral)
.with_human_result("something went wrong"),
)
.with_spf_auth_result(
SPFAuthResult::new()
.with_domain("test.org")
.with_scope(SPFDomainScope::MailFrom)
.with_result(SpfResult::None)
.with_human_result("no policy found"),
),
)
.to_rfc5322(
"initech.net",
("Initech Industries", "noreply-dmarc@initech.net"),
["dmarc-reports@example.org"].iter().copied(),
)
.unwrap();
// Print report to stdout
println!("{report}");
}