| 1 | package Mail::Abuse::Incident::SpamCop; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | require 5.005_62; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use NetAddr::IP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Date::Parse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use base 'Mail::Abuse::Incident'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # The code below should be in a single line | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 3 | our $VERSION = do { my @r = (q$Revision: 1.11 $ =~ /\d+/g); sprintf " %d."."%03d" x $#r, @r }; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =pod | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head1 NAME | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | Mail::Abuse::Incident::SpamCop - Parses SpamCop reports into Mail::Abuse::Reports | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | use Mail::Abuse::Report; | ||||||||||||||||||||||||||||
| 26 | use Mail::Abuse::Incident::SpamCop; | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | my $i = new Mail::Abuse::Incident::SpamCop; | ||||||||||||||||||||||||||||
| 29 | my $report = new Mail::Abuse::Report (incidents => [$i] ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | This class parses SpamCop incidents. See http://www.SpamCop.net/ for | ||||||||||||||||||||||||||||
| 34 | more information regarding their excellent service. | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | The following functions are provided for the customization of the | ||||||||||||||||||||||||||||
| 37 | behavior of the class. | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =over | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =item C<parse($report)> | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | Pushes all instances of SpamCop incidents into the given report, based | ||||||||||||||||||||||||||||
| 46 | on parsing of the text in the report itself. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | Returns a list of objects of the same class, with the incident data | ||||||||||||||||||||||||||||
| 49 | (IP address, timestamp and other information) filled. | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =cut | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | sub parse | ||||||||||||||||||||||||||||
| 54 | 10 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=14 SCAR=27.6
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 56 | 10 | my $rep = shift; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 10 | my @ret = (); # Default return | |||||||||||||||||||||||||||
| 59 | 10 | my $count = 0; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 10 | my $text = undef; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 10 | ▶ | if ($rep->normalized) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||
| 65 | 5 | $text = $rep->body; | |||||||||||||||||||||||||||
| 66 | 5 | ▶ | my $xmailer = $rep->header->get('X-Mailer') || ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$rep->header->get('X-Mailer') || ''
MC/DC0%0/1
$rep->header->get('X-Mailer') || ''
$rep->header->get('X-Mailer')
Truth table50%1/2
A
A= $rep->header->get('X-Mailer')
| |||||||||||||||||||||||||||||
| 67 | 5 | ▶ | my $subject = $rep->header->get('Subject') || ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$rep->header->get('Subject') || ''
MC/DC0%0/1
$rep->header->get('Subject') || ''
$rep->header->get('Subject')
Truth table50%1/2
A
A= $rep->header->get('Subject')
| |||||||||||||||||||||||||||||
| 68 | #warn "# Match 1.a: normalized\n"; | ||||||||||||||||||||||||||||
| 69 | 5 | ▶ | return unless $xmailer =~ m!http://(www\.)?spamcop.net!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | #warn "# Match 1.b: normalized\n"; | ||||||||||||||||||||||||||||
| 71 | 5 | ▶ | return unless $subject =~ m!\[SpamCop!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | #warn "# Match 1: normalized\n"; | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | else | ||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||
| 76 | 5 | $text = $rep->text; | |||||||||||||||||||||||||||
| 77 | #warn "# Match 1.a: non-normalized\n"; | ||||||||||||||||||||||||||||
| 78 | 5 | ▶ | return unless $$text =~ m!^X-Mailer: http://(www\.)?spamcop.net/!m | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$$text =~ m[^X-Mailer: http://(www\.)?spamcop.net/]m or $$text =~ /^X-SpamCop-sourceip: /m
MC/DC0%0/2
$$text =~ m[^X-Mailer: http://(www\.)?spamcop.net/]m or $$text =~ /^X-SpamCop-sourceip: /m
$$text =~ m[^X-Mailer: http://(www\.)?spamcop.net/]m
$$text =~ /^X-SpamCop-sourceip: /m
Truth table66%2/3
A or B
A= $$text =~ m[^X-Mailer: http://(www\.)?spamcop.net/]mB= $$text =~ /^X-SpamCop-sourceip: /m
| |||||||||||||||||||||||||||||
| 79 | or $$text =~ m!^X-SpamCop-sourceip: !m; | ||||||||||||||||||||||||||||
| 80 | #warn "# Match 1.b: non-normalized\n"; | ||||||||||||||||||||||||||||
| 81 | 5 | ▶ | return unless $$text =~ m!^Subject: .*\[SpamCop!m; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | #warn "# Match 1.c: non-normalized\n"; | ||||||||||||||||||||||||||||
| 83 | 5 | ▶ | return unless $$text =~ /[-\[] SpamCop/m; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | #warn "# Match 1: non-normalized\n"; | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 10 | ▶ | return unless $$text =~ m!This message is brief!m; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 10 | ▶ | if ($$text =~ m!Email from (\d+\.\d+\.\d+\.\d+)\s+/\s+(.+)!) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||
| 91 | 10 | my $ip = new NetAddr::IP $1; | |||||||||||||||||||||||||||
| 92 | 10 | my $date = $2; | |||||||||||||||||||||||||||
| 93 | 10 | ▶ | return unless $ip; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | #warn "# Match 2: ip=$ip date=$date\n"; | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # Remove truncated timezones | ||||||||||||||||||||||||||||
| 98 | 10 | $date =~ s/\([^\)]+$//; | |||||||||||||||||||||||||||
| 99 | 10 | $date =~ s/\[.*$//; | |||||||||||||||||||||||||||
| 100 | # Parse the date | ||||||||||||||||||||||||||||
| 101 | 10 | $date = str2time($date, $rep->tz); | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 10 | my $i = $self->new(); | |||||||||||||||||||||||||||
| 104 | 10 | $i->ip($ip); | |||||||||||||||||||||||||||
| 105 | 10 | $i->time($date); | |||||||||||||||||||||||||||
| 106 | 10 | $i->type('spam/SpamCop'); | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 10 | $$text =~ m!(^http://(www\.)?spamcop.net/w3m.+)\s*$!m; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 10 | ▶ | $i->data($1 || 'no data'); | ||||||||||||||||||||||||||
|
Condition50%1/2
$1 || 'no data'
MC/DC0%0/1
$1 || 'no data'
$1
Truth table50%1/2
A
A= $1
| |||||||||||||||||||||||||||||
| 111 | #warn "# Created incident $i\n"; | ||||||||||||||||||||||||||||
| 112 | 10 | push @ret, $i; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 10 | return @ret; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | __END__ | ||||||||||||||||||||||||||||