{
$Mail::DMARC::Report::Send::VERSION
=
'0.20130524'
;
}
sub
send_rua {
my
(
$self
,
$report
,
$xml
) =
@_
;
my
$shrunk
=
$self
->compress_report(
$xml
);
my
$bytes
=
length
Encode::encode_utf8(
$shrunk
);
my
$uri_ref
=
$self
->uri->parse(
$$report
->{policy_published}{rua} );
my
$sent
= 0;
foreach
my
$u_ref
(
@$uri_ref
) {
my
$method
=
$u_ref
->{uri};
my
$max
=
$u_ref
->{max_bytes};
if
(
$max
&&
$bytes
>
$max
) {
carp
"skipping $method: report size ($bytes) larger than $max\n"
;
next
;
}
if
(
'mailto:'
eq
substr
(
$method
, 0, 7 ) ) {
$self
->send_via_smtp(
$method
,
$report
,
$shrunk
) and
$sent
++;
}
if
(
'http:'
eq
substr
(
$method
, 0, 5 ) ) {
$self
->http->post(
$method
,
$report
,
$shrunk
) and
$sent
++;
}
}
return
$sent
;
}
sub
human_summary {
my
(
$self
,
$report
) =
@_
;
my
$rows
=
scalar
@{
$$report
->{rows} };
my
$OrgName
=
$self
->config->{organization}{org_name};
my
$pass
=
grep
{
$_
->{dkim} eq
'pass'
||
$_
->{spf} eq
'pass'
}
@{
$$report
->{rows} };
my
$fail
=
grep
{
$_
->{dkim} ne
'pass'
&&
$_
->{spf} ne
'pass'
}
@{
$$report
->{rows} };
my
$ver
=
$Mail::DMARC::VERSION
||
''
;
my
$from
=
$$report
->{domain};
return
<<"EO_REPORT"
This is a DMARC aggregate report for $from
$rows rows.
$pass passed.
$fail failed.
Submitted by $OrgName
Generated with Mail::DMARC $ver
EO_REPORT
;
}
sub
compress_report {
my
(
$self
,
$xml
) =
@_
;
my
$shrunk
;
my
$zipper
= {
gz
=> \
&IO::Compress::Gzip::gzip
,
zip
=> \
&IO::Compress::Zip::zip
,
};
my
$cf
= (
time
> 1372662000 ) ?
'gz'
:
'zip'
;
$zipper
->{
$cf
}->(
$xml
, \
$shrunk
) or croak
"unable to compress: $!"
;
return
$shrunk
;
}
sub
send_via_smtp {
my
(
$self
,
$method
,
$report
,
$shrunk
) =
@_
;
my
$rid
=
$$report
->{id};
my
$dom
=
$$report
->{domain};
my
(
$to
) = (
split
/:/,
$method
)[-1];
carp
"sending mailto $to\n"
;
return
$self
->smtp->email(
to
=>
$to
,
subject
=>
$self
->smtp->get_subject(
{
report_id
=>
$rid
,
policy_domain
=>
$dom
}
),
body
=>
$self
->human_summary(
$report
),
report
=>
$shrunk
,
policy_domain
=>
$dom
,
begin
=>
$$report
->{begin},
end
=>
$$report
->{end},
report_id
=>
$rid
,
);
}
sub
http {
my
$self
=
shift
;
return
$self
->{http}
if
ref
$self
->{http};
return
$self
->{http} = Mail::DMARC::Report::Send::HTTP->new();
}
sub
smtp {
my
$self
=
shift
;
return
$self
->{smtp}
if
ref
$self
->{smtp};
return
$self
->{smtp} = Mail::DMARC::Report::Send::SMTP->new();
}
sub
uri {
my
$self
=
shift
;
return
$self
->{uri}
if
ref
$self
->{uri};
return
$self
->{uri} = Mail::DMARC::Report::URI->new();
}
1;