diff --git a/server/src/email_extract.rs b/server/src/email_extract.rs index 85e3c29..680880c 100644 --- a/server/src/email_extract.rs +++ b/server/src/email_extract.rs @@ -362,7 +362,7 @@ pub fn extract_mixed(m: &ParsedMail, part_addr: &mut Vec) -> Result) -> Result, pub policy_published: Option, pub record: Option>, + pub has_envelope_to: bool, } #[derive(Debug, serde::Deserialize)] @@ -999,6 +1001,7 @@ pub struct FormattedTlsRptFailureDetails { #[derive(Debug, serde::Deserialize)] pub struct Identifiers { pub header_from: Option, + pub envelope_to: Option, } #[derive(Debug, serde::Deserialize)] pub struct AuthResults { @@ -1109,6 +1112,11 @@ pub fn parse_dmarc_report(xml: &str) -> Result { .as_ref() .and_then(|i| i.header_from.clone()) .unwrap_or_else(|| "".to_string()), + envelope_to: rec + .identifiers + .as_ref() + .and_then(|i| i.envelope_to.clone()) + .unwrap_or_else(|| "".to_string()), disposition: rec .row .as_ref() @@ -1166,10 +1174,17 @@ pub fn parse_dmarc_report(xml: &str) -> Result { pct: pol.pct.unwrap_or_else(|| "".to_string()), }); + let has_envelope_to = formatted_record + .as_ref() + .map_or(false, |r: &Vec| { + r.iter().any(|rec| !rec.envelope_to.is_empty()) + }); + let formatted_feedback = FormattedFeedback { report_metadata: formatted_report_metadata, policy_published: formatted_policy_published, record: formatted_record, + has_envelope_to, }; let template = DmarcReportTemplate { @@ -1217,3 +1232,25 @@ pub fn pretty_print_xml_with_trimming(xml_input: &str) -> ResultSource IP Count Header From + {% if report.has_envelope_to %} + Envelope To + {% endif %} Disposition DKIM SPF @@ -52,6 +55,9 @@ {{ rec.source_ip }} {{ rec.count }} {{ rec.header_from }} + {% if report.has_envelope_to %} + {{ rec.envelope_to }} + {% endif %} {{ rec.disposition }} {{ rec.dkim }} {{ rec.spf }} diff --git a/server/testdata/dmarc-example-no-envelope-to.xml b/server/testdata/dmarc-example-no-envelope-to.xml new file mode 100644 index 0000000..f503fe4 --- /dev/null +++ b/server/testdata/dmarc-example-no-envelope-to.xml @@ -0,0 +1,48 @@ + + + 1.0 + + google.com + noreply-dmarc-support@google.com + https://support.google.com/a/answer/2466580 + 5142106658860834914 + + 1755302400 + 1755388799 + + + + xinu.tv + s + s +

quarantine

+ reject + 100 + reject +
+ + + 74.207.253.222 + 1 + + none + pass + pass + + + + xinu.tv + + + + xinu.tv + pass + mail + + + xinu.tv + pass + + + +
\ No newline at end of file diff --git a/server/testdata/dmarc-example.xml b/server/testdata/dmarc-example.xml new file mode 100644 index 0000000..bf9c5c0 --- /dev/null +++ b/server/testdata/dmarc-example.xml @@ -0,0 +1,78 @@ + + + 1.0 + + Outlook.com + dmarcreport@microsoft.com + e6c5a2ce6e074d7d8cd041a0d6f32a3d + + 1755302400 + 1755388800 + + + + xinu.tv + s + s +

quarantine

+ reject + 100 + 1 +
+ + + 74.207.253.222 + 1 + + none + pass + pass + + + + msn.com + xinu.tv + xinu.tv + + + + xinu.tv + mail + pass + + + xinu.tv + mfrom + pass + + + + + + 74.207.253.222 + 1 + + none + pass + pass + + + + hotmail.com + xinu.tv + xinu.tv + + + + xinu.tv + mail + pass + + + xinu.tv + mfrom + pass + + + +
\ No newline at end of file