summaryrefslogtreecommitdiffstats
path: root/network/opendmarc/patches/ticket207.patch
blob: e86b8c770466fa2382df16d76b1eeb538540aeb3 (plain)
Index: opendmarc/reports/opendmarc-reports.in
===================================================================
--- opendmarc.orig/reports/opendmarc-reports.in	2018-12-17 01:41:49.094337107 -0500
+++ opendmarc/reports/opendmarc-reports.in	2018-12-17 01:41:49.090337107 -0500
@@ -65,6 +65,7 @@
 my $forcedomain;
 my @skipdomains;
 
+my $poldomain;
 my $policy;
 my $spolicy;
 my $policystr;
@@ -441,7 +442,7 @@
 		next;
 	}
 
-	$dbi_s = $dbi_h->prepare("SELECT repuri, adkim, aspf, policy, spolicy, pct, UNIX_TIMESTAMP(lastsent) FROM requests WHERE domain = ?");
+	$dbi_s = $dbi_h->prepare("SELECT repuri, adkim, aspf, requests.policy, spolicy, pct, UNIX_TIMESTAMP(lastsent), domains.name FROM requests JOIN messages ON messages.from_domain=requests.domain LEFT JOIN domains ON messages.policy_domain = domains.id WHERE domain = ? GROUP BY policy_domain");
 	if (!$dbi_s->execute($domainid))
 	{
 		print STDERR "$progname: can't get reporting URI for domain $domain: " . $dbi_h->errstr . "\n";
@@ -451,6 +452,7 @@
 	}
 
 	undef $repuri;
+	$poldomain=$domain;
 
 	while ($dbi_a = $dbi_s->fetchrow_arrayref())
 	{
@@ -482,6 +484,10 @@
 		{
 			$lastsent = $dbi_a->[6];
 		}
+		if (defined($dbi_a->[7]))
+		{
+			$poldomain = $dbi_a->[7];
+		}
 	}
 
 	$dbi_s->finish;
@@ -564,7 +570,7 @@
 	print $tmpout " </report_metadata>\n";
 
 	print $tmpout " <policy_published>\n";
-	print $tmpout "  <domain>$domain</domain>\n";
+	print $tmpout "  <domain>$poldomain</domain>\n";
 	print $tmpout "  <adkim>$adkimstr</adkim>\n";
 	print $tmpout "  <aspf>$aspfstr</aspf>\n";
 	print $tmpout "  <p>$policystr</p>\n";