Skip to content

Commit 3968b72

Browse files
authored
feat: add --report-body-file to customize aggregate report mail body (#437)
Lets operators replace the hardcoded plain-text body of RUA report emails with the contents of a file, with %DOMAIN%/%DATE% token substitution. Falls back to the existing boilerplate text when unset, so default behavior is unchanged. Works from the command line or opendmarc-reports.conf via the existing generic key=value loader.
1 parent f65c5f3 commit 3968b72

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

reports/opendmarc-reports.8.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,24 @@ Normally this would be done to prevent reports from being sent too close
189189
together. Implied by
190190
.IR --test .
191191
.TP
192+
.I --report-body-file=file
193+
Replaces the default plain-text body of aggregate report e-mail messages
194+
with the contents of
195+
.IR file ,
196+
read once at startup. The tokens
197+
.B %DOMAIN%
198+
and
199+
.B %DATE%
200+
are substituted, if present, with the reporting domain and the message's
201+
.I Date:
202+
header value, respectively. If not specified, the default body is
203+
.RS
204+
.nf
205+
This is a DMARC aggregate report for <domain>
206+
generated at <timestamp>
207+
.fi
208+
.RE
209+
.TP
192210
.I --report-contact=addr
193211
Specifies the contact address written into the
194212
.I <email>

reports/opendmarc-reports.in

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ my $dbscheme = $def_dbscheme;
162162
my $repdom = hostdomain();
163163
my $repemail = "postmaster@" . $repdom;
164164
my $repcontact;
165+
my $repbodyfile;
166+
my $repbodytemplate;
165167

166168
my $smtp_server = '127.0.0.1';
167169
my $smtp_port = 25;
@@ -405,6 +407,8 @@ sub usage
405407
print STDERR "\t--nodomain=name omit a report for named domain\n";
406408
print STDERR "\t--noupdate don't record report transmission\n";
407409
print STDERR "\t--report-bcc bcc address for aggregate reports\n";
410+
print STDERR "\t--report-body-file=file custom plain-text body for aggregate\n";
411+
print STDERR "\t reports (%DOMAIN%/%DATE% tokens substituted)\n";
408412
print STDERR "\t--report-contact contact address for report metadata (default: --report-email)\n";
409413
print STDERR "\t--report-email envelope/From address for outgoing reports [$repemail]\n";
410414
print STDERR "\t--report-org reporting organization [$repdom]\n";
@@ -512,6 +516,7 @@ my $opt_retval = &Getopt::Long::GetOptions ('archive-dir=s' => \$archive_dir,
512516
'n|test' => \$testmode,
513517
'nodomain=s' => \@skipdomains,
514518
'report-bcc=s' => \$repbcc,
519+
'report-body-file=s' => \$repbodyfile,
515520
'report-contact=s' => \$repcontact,
516521
'report-email=s' => \$repemail,
517522
'report-org=s' => \$repdom,
@@ -656,6 +661,14 @@ if (defined($noreports_file))
656661
close($nrf);
657662
}
658663

664+
if (defined($repbodyfile))
665+
{
666+
open(my $rbf, '<', $repbodyfile)
667+
or die "$progname: can't open report body file $repbodyfile: $!\n";
668+
$repbodytemplate = do { local $/; <$rbf> };
669+
close($rbf);
670+
}
671+
659672
# Test mode requested, don't update last sent and keep xml files
660673
$doupdate = ($testmode == 1) ? 0 : $doupdate;
661674
$keepfiles = ($testmode == 1) ? 1 : $keepfiles;
@@ -1700,8 +1713,18 @@ foreach (@$domainset)
17001713
$mailout .= "--$boundary\n";
17011714
$mailout .= "Content-Type: text/plain;\n";
17021715
$mailout .= "\n";
1703-
$mailout .= "This is a DMARC aggregate report for $domain\n";
1704-
$mailout .= "generated at " . localtime() . "\n";
1716+
if (defined($repbodytemplate))
1717+
{
1718+
my $body = $repbodytemplate;
1719+
$body =~ s/%DOMAIN%/$domain/g;
1720+
$body =~ s/%DATE%/$datestr/g;
1721+
$mailout .= $body;
1722+
}
1723+
else
1724+
{
1725+
$mailout .= "This is a DMARC aggregate report for $domain\n";
1726+
$mailout .= "generated at " . localtime() . "\n";
1727+
}
17051728
$mailout .= "\n";
17061729
$mailout .= "--$boundary\n";
17071730
$mailout .= "Content-Type: application/gzip\n";

0 commit comments

Comments
 (0)