blib/lib/Email/ARF/Hotmail.pm

filter: Statementstmt 95.4% 63 / 66 Branchbran 83.3% 10 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 92.4% 86 / 93 CC 9 SCAR 12.2
CC
9
Cov
93%
_is_hotmail_report
5.0
create_report
5.0
BEGIN
1.0
CRAP 3.4
↑ Summary
1 package Email::ARF::Hotmail;
2  
3 6 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Email::ARF::Report;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Email::MIME;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Regexp::Common qw/net/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 require Exporter;
11  
12 6 our @ISA = qw(Exporter);
13  
14 # Items to export into callers namespace by default. Note: do not export
15 # names by default without a very good reason. Use EXPORT_OK instead.
16 # Do not simply export all your public functions/methods/constants.
17  
18 # This allows declaration use Email::ARF::Hotmail ':all';
19 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
20 # will save memory.
21 6 our %EXPORT_TAGS = ( 'all' => [ qw(
22
23 ) ] );
24  
25 6 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
26  
27 6 our @EXPORT = qw(
28
29 );
30  
31 6 our $VERSION = '0.12';
32 6 $VERSION = eval $VERSION;
33  
34 6 ▶use constant HOTMAIL_SENDER => 'staff@hotmail.com';
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 4 ▶sub _is_hotmail_report {
Subroutine _is_hotmail_report: called CC=5 SCAR=16.2
37 4 my $parsed = shift;
38 4 foreach my $field (('X-Original-Sender', 'Sender', 'From')) {
39 8 my $val = $parsed->header($field);
40 8 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 4 4 8
41 4 $val =~ s/^\<//;
42 4 $val =~ s/\>$//;
43 }
44  
45 8 ▶ if (defined($val) and $val eq HOTMAIL_SENDER) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and $val eq "staff\@hotmail.com") 4 4 8
Condition66%2/3
defined $val and $val eq "staff\@hotmail.com"
!ll&&!rl&&r
404
MC/DC50%1/2
defined $val and $val eq "staff\@hotmail.com"
defined $val $val eq "staff\@hotmail.com"
Truth table66%2/3
A and B
A= defined $valB= $val eq "staff\@hotmail.com"
ABresult
0X0
100
111
46 4 return 1;
47 }
48 }
49  
50 0 return 0;
51 }
52  
53 4 ▶sub create_report {
Subroutine create_report: called CC=5 SCAR=16.2
Pod documented
54 4 my $class = shift;
55 4 my $message = shift;
56  
57 4 my $parsed = Email::MIME->new($message);
58
59 4 ▶ if (_is_hotmail_report($parsed)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_hotmail_report($parsed)) { } 4 0 4
60 # Get the original email and strip off all the extra header bits
61 4 my $part = ($parsed->parts)[0];
62 4 my $orig_email = $part->body;
63 4 my $hotmail_headers;
64 4 ▶ if ($orig_email =~ /Received: /) {
Branch: 1 branch
BranchTrueFalseTotal
if ($orig_email =~ /Received: /) { } 1 3 4
65 1 $orig_email =~ s/^(.*?)\n(Received: )/$2/s;
66 1 $hotmail_headers = Email::Simple::Header->new($1);
67 } else {
68 3 $hotmail_headers = Email::Simple::Header->new($orig_email);
69 }
70  
71 4 my $description = "An email abuse report from hotmail";
72 4 my %fields;
73 4 $fields{"Feedback-Type"} = "abuse";
74 4 $fields{"User-Agent"} = "Email::ARF::Hotmail-conversion";
75 4 $fields{"Version"} = "0.1";
76  
77 4 my $subject = $parsed->header("Subject");
78  
79 4 my $source_ip;
80  
81 4 ▶ if ($subject =~ /complaint about message from ($RE{net}{IPv4})$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subject =~ /complaint about message from ($Email::ARF::Hotmail::RE{'net'}{'IPv4'})$/) { } 4 0 4
82 4 $source_ip = $1;
83 } else {
84 0 die "Couldn't match subject: " . $subject;
85 }
86  
87 4 $fields{"Source-IP"} = $source_ip;
88
89 4 my $or = $hotmail_headers->header('X-HmXmrOriginalRecipient');
90  
91 4 ▶ if ($or) {
Branch: 1 branch
BranchTrueFalseTotal
if ($or) 1 3 4
92 1 $fields{'Original-Rcpt-To'} = $or;
93 }
94
95 4 my $original_email = Email::MIME->new($orig_email);
96
97 4 return Email::ARF::Report->create(
98 original_email => $original_email,
99 description => $description,
100 fields => \%fields
101 );
102
103 } else {
104 0 die "Not a hotmail abuse report";
105 }
106 }
107  
108 6 1;
109 __END__
↑ Summary