1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
|
# Status Badges
[](https://github.com/msimerson/mail-dmarc/actions/workflows/ci.yml)
[](https://coveralls.io/r/msimerson/mail-dmarc)
# NAME
Mail::DMARC - Perl implementation of DMARC
# VERSION
version 1.20240314
# SYNOPSIS
DMARC: Domain-based Message Authentication, Reporting and Conformance
my $dmarc = Mail::DMARC::PurePerl->new(
... # see the documentation for the "new" method for required args
);
my $result = $dmarc->validate();
if ( $result->result eq 'pass' ) {
...continue normal processing...
return;
};
# any result that did not pass is a fail. Now for disposition
if ( $result->evalated->disposition eq 'reject' ) {
...treat the sender to a 550 ...
};
if ( $result->evalated->disposition eq 'quarantine' ) {
...assign a bunch of spam points...
};
if ( $result->evalated->disposition eq 'none' ) {
...continue normal processing...
};
# DESCRIPTION
This module is a suite of tools for implementing DMARC. It adheres to the 2013 DMARC draft, intending to implement every MUST and every SHOULD.
This module can be used by...
- MTAs and filtering tools like SpamAssassin to validate that incoming messages are aligned with the purported sender's policy.
- email senders, to receive DMARC reports from other mail servers and display them via CLI and web interfaces.
- MTA operators to send DMARC reports to DMARC author domains.
When a message arrives via SMTP, the MTA or filtering application can pass in a small amount of metadata about the connection (envelope details, SPF and DKIM results) to Mail::DMARC. When the **validate** method is called, Mail::DMARC will determine if:
a. the header_from domain exists
b. the header_from domain publishes a DMARC policy
c. if a policy is published...
d. does the message conform to the published policy?
e. did the policy request reporting? If so, save details.
The validation results are returned as a [Mail::DMARC::Result](https://metacpan.org/pod/Mail%3A%3ADMARC%3A%3AResult) object. If the author domain requested a report, it was saved to the [Report Store](https://metacpan.org/pod/Mail%3A%3ADMARC%3A%3AReport%3A%3AStore). The Store class includes a SQL implementation that is tested with SQLite, MySQL and PostgreSQL.
There is more information available in the $result object. See [Mail::DMARC::Result](https://metacpan.org/pod/Mail%3A%3ADMARC%3A%3AResult) for complete details.
Reports are viewed with the [dmarc\_view\_reports](https://metacpan.org/pod/dmarc_view_reports) program or with a web browser and the [dmarc\_httpd](https://metacpan.org/pod/dmarc_httpd) program.
Aggregate reports are sent to their requestors with the [dmarc\_send\_reports](https://metacpan.org/pod/dmarc_send_reports) program.
For aggregate reports that you have been sent, the [dmarc\_receive](https://metacpan.org/pod/dmarc_receive) program will parse the email messages (from IMAP, Mbox, or files) and save the report results into the [Report Store](https://metacpan.org/pod/Mail%3A%3ADMARC%3A%3AReport%3A%3AStore).
The report store can use the same database to store reports you have received as well as reports you will send. There are several ways to identify the difference, including:
- received reports will have a null value for report\_policy\_published.rua
- outgoing reports will have null values for report.uuid and report\_record.count
# CLASSES
[Mail::DMARC](https://metacpan.org/pod/Mail%3A%3ADMARC) - the perl interface for DMARC
[Mail::DMARC::Policy](https://metacpan.org/pod/Mail%3A%3ADMARC%3A%3APolicy) - a DMARC policy
[Mail::DMARC::PurePerl](https://metacpan.org/pod/Mail%3A%3ADMARC%3A%3APurePerl) - Pure Perl implementation of DMARC
[Mail::DMARC::Result](https://metacpan.org/pod/Mail%3A%3ADMARC%3A%3AResult) - the results of applying policy
[Mail::DMARC::Report](https://metacpan.org/pod/Mail%3A%3ADMARC%3A%3AReport) - Reporting: the R in DMARC
> [Mail::DMARC::Report::Send](https://metacpan.org/pod/Mail%3A%3ADMARC%3A%3AReport%3A%3ASend) - send reports via SMTP & HTTP
>
> [Mail::DMARC::Report::Receive](https://metacpan.org/pod/Mail%3A%3ADMARC%3A%3AReport%3A%3AReceive) - receive and store reports from email, HTTP
>
> [Mail::DMARC::Report::Store](https://metacpan.org/pod/Mail%3A%3ADMARC%3A%3AReport%3A%3AStore) - a persistent data store for aggregate reports
>
> [Mail::DMARC::Report::View](https://metacpan.org/pod/Mail%3A%3ADMARC%3A%3AReport%3A%3AView) - CLI and CGI methods for viewing reports
[Mail::DMARC::libopendmarc](http://search.cpan.org/~shari/Mail-DMARC-opendmarc) - an XS implementation using libopendmarc
# METHODS
## new
Create a DMARC object.
my $dmarc = Mail::DMARC::PurePerl->new;
Populate it.
$dmarc->source_ip('192.0.1.1');
$dmarc->envelope_to('recipient.example.com');
$dmarc->envelope_from('sender.example.com');
$dmarc->header_from('sender.example.com');
$dmarc->dkim( $dkim_verifier );
$dmarc->spf([
{ domain => 'example.com',
scope => 'mfrom',
result => 'pass',
},
{
scope => 'helo',
domain => 'mta.example.com',
result => 'fail',
},
]);
Run the request:
my $result = $dmarc->validate();
Alternatively, pass in all the required parameters in one shot:
my $dmarc = Mail::DMARC::PurePerl->new(
source_ip => '192.0.1.1',
envelope_to => 'example.com',
envelope_from => 'cars4you.info',
header_from => 'yahoo.com',
dkim => $dkim_results, # same format
spf => $spf_results, # as previous example
);
my $result = $dmarc->validate();
## source\_ip
The remote IP that attempted sending the message. DMARC only uses this data for reporting to domains that request DMARC reports.
## envelope\_to
The domain portion of the RFC5321.RcptTo, (aka, the envelope recipient), and the bold portion in the following example:
> RCPT TO:<user@**example.com**>
## envelope\_from
The domain portion of the RFC5321.MailFrom, (aka, the envelope sender). That is the the bold portion in the following example:
> MAIL FROM:<user@**example.com**>
## header\_from
The domain portion of the RFC5322.From, aka, the From message header.
> From: Ultimate Vacation <sweepstakes@**example.com**>
You can instead pass in the entire From: header with header\_from\_raw.
## header\_from\_raw
Retrieve the header\_from domain by parsing it from a raw From field/header. The domain portion is extracted by [get\_dom\_from\_header](https://metacpan.org/pod/Mail%3A%3ADMARC%3A%3APurePerl%23get_dom_from_header), which is fast, generally effective, but also rather crude. It has limits, so read the description.
## dkim
If Mail::DKIM::Verifier was used to validate the message, just pass in the Mail::DKIM::Verifier object that processed the message:
$dmarc->dkim( $dkim_verifier );
Otherwise, pass in an array reference. Each member of the DKIM array results represents a DKIM signature in the message and consists of the 4 keys shown in this example:
$dmarc->dkim( [
{
domain => 'example.com',
selector => 'apr2013',
result => 'fail',
human_result=> 'fail (body has been altered)',
},
{
# 2nd signature, if present
},
] );
The dkim results can also be build iteratively by passing in key value pairs or hash references for each signature in the message:
$dmarc->dkim( domain => 'sig1.com', result => 'fail' );
$dmarc->dkim( domain => 'sig2.com', result => 'pass' );
$dmarc->dkim( { domain => 'example.com', result => 'neutral' } );
Each hash or hashref is appended to the dkim array.
Finally, you can pass a coderef which won't be called until the dkim method is used to read the dkim results. It must return an array reference as described above.
The dkim result is an array reference.
### domain
The d= parameter in the DKIM signature
### selector
The s= parameter in the DKIM signature
### result
The validation results of this signature. One of: none, pass, fail, policy, neutral, temperror, or permerror
### human result
Additional information about the DKIM result. This is comparable to Mail::DKIM::Verifier->result\_detail.
## spf
The spf method works exactly the same as dkim. It accepts named arguments, a hashref, an arrayref, or a coderef:
$dmarc->spf(
domain => 'example.com',
scope => 'mfrom',
result => 'pass',
);
The SPF domain and result are required for DMARC validation and the scope is used for reporting.
### domain
The SPF checked domain
### scope
The scope of the checked domain: mfrom, helo
### result
The SPF result code: none, neutral, pass, fail, softfail, temperror, or permerror.
# DESIGN & GOALS
## Correct
The DMARC spec is lengthy and evolving, making correctness a moving target. In cases where correctness is ambiguous, options are generally provided.
## Easy to use
Providing an implementation of DMARC that SMTP utilities can utilize will aid DMARC adoption.
The list of dependencies appears long because of reporting. If this module is used without reporting, the number of dependencies not included with perl is about 5.
## Maintainable
Since DMARC is evolving, this implementation aims to be straight forward and easy to alter and extend. The programming style is primarily OO, which carries a small performance penalty but dividends in maintainability.
When multiple options are available, such as when sending reports via SMTP or HTTP, calls should be made to the parent Send class to broker the request. When storing reports, calls are made to the Store class which dispatches to the SQL class. The idea is that if someone desired a data store other than those provided by perl's DBI class, they could easily implement their own. If you do, please fork it on GitHub and share.
## Fast
If you deploy this in an environment where performance is insufficient, please profile the app and submit a report and preferably, patches.
# SEE ALSO
[Mail::DMARC on GitHub](https://github.com/msimerson/mail-dmarc)
2015-03 [RFC 7489](https://tools.ietf.org/html/rfc7489)
DMARC [Best Current Practices](http://tools.ietf.org/html/draft-crocker-dmarc-bcp-03)
# HISTORY
The daddy of this perl module was a [DMARC module for the qpsmtpd MTA](https://github.com/smtpd/qpsmtpd/blob/master/plugins/dmarc).
# AUTHORS
- Matt Simerson <msimerson@cpan.org>
- Davide Migliavacca <shari@cpan.org>
- Marc Bradshaw <marc@marcbradshaw.net>
# CONTRIBUTORS
- Benny Pedersen <me@junc.eu>
- Jean Paul Galea <jeanpaul@yubico.com>
- Marisa Clardy <marisa@clardy.eu>
- Priyadi Iman Nurcahyo <priyadi@priyadi.net>
- Ricardo Signes <rjbs@cpan.org>
# COPYRIGHT AND LICENSE
This software is copyright (c) 2024 by Matt Simerson.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
|