server: add envelope_to support to DMARC report
This commit is contained in:
@@ -362,7 +362,7 @@ pub fn extract_mixed(m: &ParsedMail, part_addr: &mut Vec<String>) -> Result<Body
|
||||
.subparts
|
||||
.iter()
|
||||
.map(|sp| sp.ctype.mimetype.as_str())
|
||||
.filter(|mt| !handled_types.contains(&mt))
|
||||
.filter(|mt| !handled_types.contains(mt))
|
||||
.collect();
|
||||
unhandled_types.sort();
|
||||
if !unhandled_types.is_empty() {
|
||||
@@ -500,7 +500,7 @@ pub fn extract_related(m: &ParsedMail, part_addr: &mut Vec<String>) -> Result<Bo
|
||||
.subparts
|
||||
.iter()
|
||||
.map(|sp| sp.ctype.mimetype.as_str())
|
||||
.filter(|mt| !handled_types.contains(&mt))
|
||||
.filter(|mt| !handled_types.contains(mt))
|
||||
.collect();
|
||||
unhandled_types.sort();
|
||||
if !unhandled_types.is_empty() {
|
||||
@@ -774,6 +774,7 @@ pub struct FormattedRecord {
|
||||
pub source_ip: String,
|
||||
pub count: String,
|
||||
pub header_from: String,
|
||||
pub envelope_to: String,
|
||||
pub disposition: String,
|
||||
pub dkim: String,
|
||||
pub spf: String,
|
||||
@@ -811,6 +812,7 @@ pub struct FormattedFeedback {
|
||||
pub report_metadata: Option<FormattedReportMetadata>,
|
||||
pub policy_published: Option<FormattedPolicyPublished>,
|
||||
pub record: Option<Vec<FormattedRecord>>,
|
||||
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<String>,
|
||||
pub envelope_to: Option<String>,
|
||||
}
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
pub struct AuthResults {
|
||||
@@ -1109,6 +1112,11 @@ pub fn parse_dmarc_report(xml: &str) -> Result<String, ServerError> {
|
||||
.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<String, ServerError> {
|
||||
pct: pol.pct.unwrap_or_else(|| "".to_string()),
|
||||
});
|
||||
|
||||
let has_envelope_to = formatted_record
|
||||
.as_ref()
|
||||
.map_or(false, |r: &Vec<FormattedRecord>| {
|
||||
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) -> Result<String, ServerE
|
||||
let result = writer.into_inner().into_inner();
|
||||
Ok(String::from_utf8(result)?)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::fs;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_parse_dmarc_report() {
|
||||
let xml = fs::read_to_string("testdata/dmarc-example.xml").unwrap();
|
||||
let html = parse_dmarc_report(&xml).unwrap();
|
||||
assert!(html.contains("hotmail.com"));
|
||||
assert!(html.contains("msn.com"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_dmarc_report_no_envelope_to() {
|
||||
let xml = fs::read_to_string("testdata/dmarc-example-no-envelope-to.xml").unwrap();
|
||||
let html = parse_dmarc_report(&xml).unwrap();
|
||||
assert!(!html.contains("Envelope To"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user