[opendmarc-dev] multiple rua adresses

Murray S. Kucherawy msk at blackops.org
Sun Sep 9 11:32:10 PDT 2012


On Sun, 9 Sep 2012, Andreas Schulze wrote:
> last days I changed my dmarc record. It now contain two rua uris. The 
> history file doeas contain now both rua uris but the importscript does 
> not change the database. It does not update the field "repuri" in the 
> table "requests"

The code currently keeps only one URI.  Try the attached (untested, sorry) 
patch.

-MSK
-------------- next part --------------
diff --git a/reports/opendmarc-import.in b/reports/opendmarc-import.in
index f827c5b..3797f56 100755
--- a/reports/opendmarc-import.in
+++ b/reports/opendmarc-import.in
@@ -73,6 +73,7 @@ my $pdomain;
 my $policy;
 my $received;
 my $reporter;
+my $repuri;
 my $sigcount = 0;
 my $sp;
 my $spf;
@@ -278,9 +279,10 @@ sub update_db
 	{
 		if (scalar @rua > 0)
 		{
+			$repuri = join(",", @rua);
 			$dbi_s = $dbi_h->prepare("UPDATE requests SET repuri = ? WHERE id = ?");
 
-			if (!$dbi_s->execute($rua[0], $request_id))
+			if (!$dbi_s->execute($repuri, $request_id))
 			{
 				print STDERR "$progname: failed to update reporting URI for $fdomain: " . $dbi_h->errstr . "\n";
 				$dbi_s->finish;
diff --git a/reports/opendmarc-reports.in b/reports/opendmarc-reports.in
index f0489f4..02576ae 100755
--- a/reports/opendmarc-reports.in
+++ b/reports/opendmarc-reports.in
@@ -439,14 +439,6 @@ foreach (@$domainset)
 		next;
 	}
 
-	# decode the URI
-	$uri = URI->new($repuri);
-	if (!defined($uri))
-	{
-		print STDERR "$progname: can't parse reporting URI for domain $domain\n";
-		next;
-	}
-
 	# construct the temporary file
 	$repfile = $repdom . "!" . $domain . "!" . $lastsent . "!" . time() . ".xml";
 	$zipfile = $repdom . "!" . $domain . "!" . $lastsent . "!" . time() . ".zip";
@@ -726,99 +718,112 @@ foreach (@$domainset)
 		print STDERR "$progname: keeping report file \"$repfile\"\n";
 	}
 
-	# Test mode, just report what would have been done
-	if ($testmode)
-	{
-		print STDERR "$progname: would email $domain report for " .
-		             "$rowcount records to " .  $uri->opaque . "\n";
-	}
-	# ensure a scheme is present
-	elsif (!defined($uri->scheme))
+	# decode the URI
+	@repuris = split(',', $repuri);
+
+	for $repuri (@repuris)
 	{
-		if ($verbose >= 2)
+		$uri = URI->new($repuri);
+		if (!defined($uri))
 		{
-			print STDERR "$progname: unknown URI scheme in '$repuri' for domain $domain\n";
+			print STDERR "$progname: can't parse reporting URI for domain $domain\n";
+			next;
 		}
 
-		next;
-	}
-	# send/post report
-	elsif ($uri->scheme eq "mailto")
-	{
-		my $now;
-		my $datestr;
-		my $report_id;
-
-		if (!open($zipin, $zipfile))
+		# Test mode, just report what would have been done
+		if ($testmode)
+		{
+			print STDERR "$progname: would email $domain report for " .
+			             "$rowcount records to " .  $uri->opaque . "\n";
+		}
+		# ensure a scheme is present
+		elsif (!defined($uri->scheme))
 		{
-			print STDERR "$progname: can't read zipped report for $domain: $!\n";
+			if ($verbose >= 2)
+			{
+				print STDERR "$progname: unknown URI scheme in '$repuri' for domain $domain\n";
+			}
+
 			next;
 		}
+		# send/post report
+		elsif ($uri->scheme eq "mailto")
+		{
+			my $now;
+			my $datestr;
+			my $report_id;
+
+			if (!open($zipin, $zipfile))
+			{
+				print STDERR "$progname: can't read zipped report for $domain: $!\n";
+				next;
+			}
 		
-		$repdest = $uri->opaque;
-
-		$boundary = "report_section";
-
-		$now = time();
- 		$report_id = $domain . "-" . $now . "@" . $repdom;
-		$datestr = strftime("%a, %e %b %Y %H:%M:%S %z (%Z)",
-		                    localtime);
-
-		$mailout  = "To: $repdest\n";
-		$mailout .= "From: $repemail\n";
-		$mailout .= "Subject: Report Domain: " . $domain . " Submitter: " . $repdom . " Report-ID: " . $report_id . "\n";
-		$mailout .= "X-Mailer: " . $progname . " v" . $version ."\n";
-		$mailout .= "Date: " . $datestr . "\n";
-		$mailout .= "Message-ID: <$report_id>\n";
-		$mailout .= "Auto-Submitted: auto-generated\n";
-		$mailout .= "MIME-Version: 1.0\n";
-		$mailout .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
-		$mailout .= "\n";
-		$mailout .= "This is a MIME-encapsulated message.\n";
-		$mailout .= "\n";
-		$mailout .= "--$boundary\n";
-		$mailout .= "Content-Type: text/plain;\n";
-		$mailout .= "\n";
-		$mailout .= "This is a DMARC aggregate report for $domain\n";
-		$mailout .= "generated at " . localtime() . "\n";
-		$mailout .= "\n";
-		$mailout .= "--$boundary\n";
-		$mailout .= "Content-Type: application/zip\n";
-		$mailout .= "Content-Disposition: attachment; filename=\"$zipfile\"\n";
-		$mailout .= "Content-Transfer-Encoding: base64\n";
-		$mailout .= "\n";
-
-		while (read($zipin, $buf, 60*57))
-		{
-			$mailout .= encode_base64($buf);
-		}
-
-		$mailout .= "\n";
-		$mailout .= "--$boundary--\n";
-
-		# TODO: check return value of each smtp call
-		$smtp->mail($repemail);
-		$smtp->to($repdest);
-		$smtp->data();
-		$smtp->datasend($mailout);
-		$smtp->dataend();
-
-		if ($verbose)
-		{
-			# now perl voodoo:
-			$answer = ${${*$smtp}{'net_cmd_resp'}}[1];
-			chomp($answer);
-			print STDERR "$progname: sent report for $domain to $repdest ($answer)\n";
-		}
-
-		$smtp->reset();
-
-		close($zipin);
-	}
-	else
-	{
-		print STDERR "$progname: unsupported reporting URI scheme " . $uri->scheme . " for domain $domain\n";
-		next;
+			$repdest = $uri->opaque;
+
+			$boundary = "report_section";
+
+			$now = time();
+ 			$report_id = $domain . "-" . $now . "@" . $repdom;
+			$datestr = strftime("%a, %e %b %Y %H:%M:%S %z (%Z)",
+			                    localtime);
+
+			$mailout  = "To: $repdest\n";
+			$mailout .= "From: $repemail\n";
+			$mailout .= "Subject: Report Domain: " . $domain . " Submitter: " . $repdom . " Report-ID: " . $report_id . "\n";
+			$mailout .= "X-Mailer: " . $progname . " v" . $version ."\n";
+			$mailout .= "Date: " . $datestr . "\n";
+			$mailout .= "Message-ID: <$report_id>\n";
+			$mailout .= "Auto-Submitted: auto-generated\n";
+			$mailout .= "MIME-Version: 1.0\n";
+			$mailout .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
+			$mailout .= "\n";
+			$mailout .= "This is a MIME-encapsulated message.\n";
+			$mailout .= "\n";
+			$mailout .= "--$boundary\n";
+			$mailout .= "Content-Type: text/plain;\n";
+			$mailout .= "\n";
+			$mailout .= "This is a DMARC aggregate report for $domain\n";
+			$mailout .= "generated at " . localtime() . "\n";
+			$mailout .= "\n";
+			$mailout .= "--$boundary\n";
+			$mailout .= "Content-Type: application/zip\n";
+			$mailout .= "Content-Disposition: attachment; filename=\"$zipfile\"\n";
+			$mailout .= "Content-Transfer-Encoding: base64\n";
+			$mailout .= "\n";
+
+			while (read($zipin, $buf, 60*57))
+			{
+				$mailout .= encode_base64($buf);
+			}
+
+			$mailout .= "\n";
+			$mailout .= "--$boundary--\n";
+
+			# TODO: check return value of each smtp call
+			$smtp->mail($repemail);
+			$smtp->to($repdest);
+			$smtp->data();
+			$smtp->datasend($mailout);
+			$smtp->dataend();
+
+			if ($verbose)
+			{
+				# now perl voodoo:
+				$answer = ${${*$smtp}{'net_cmd_resp'}}[1];
+				chomp($answer);
+				print STDERR "$progname: sent report for $domain to $repdest ($answer)\n";
+			}
+
+			$smtp->reset();
+
+			close($zipin);
+		}
+		else
+		{
+			print STDERR "$progname: unsupported reporting URI scheme " . $uri->scheme . " for domain $domain\n";
+			next;
+		}
 	}
 
 	# update "last sent" timestamp


More information about the opendmarc-dev mailing list