| 1 | package Mail::Abuse::Reader::POP3; | ||||||||||||||||||||||||||||||||||||||||||
| 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 Net::POP3; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use NetAddr::IP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use base 'Mail::Abuse::Reader'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | # The code below should be in a single line | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | our $VERSION = do { my @r = (q$Revision: 1.8 $ =~ /\d+/g); sprintf " %d."."%03d" x $#r, @r }; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | Mail::Abuse::Reader::POP3 - Reads a Mail::Abuse::Report out of a POP3 account | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | use Mail::Abuse::Report; | ||||||||||||||||||||||||||||||||||||||||||
| 25 | use Mail::Abuse::Reader::POP3; | ||||||||||||||||||||||||||||||||||||||||||
| 26 | my $r = new Mail::Abuse::Reader::POP3; | ||||||||||||||||||||||||||||||||||||||||||
| 27 | my $report = new Mail::Abuse::Report (reader => $r); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | This class reads in each message in a POP3 mailbox into the text of a | ||||||||||||||||||||||||||||||||||||||||||
| 32 | C<Mail::Abuse::Report> object. | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | A number of configuration keys are used for establishing the | ||||||||||||||||||||||||||||||||||||||||||
| 35 | operational parameters. These config keys are described below: | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | =item B<pop3 server> | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | Must be set to the name or address of the POP3 server where reports | ||||||||||||||||||||||||||||||||||||||||||
| 42 | are to be fetched from. | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | =item B<pop3 username> | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | The username used for the POP3 session. | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | =item B<pop3 password> | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | The corresponding password. | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | =item B<pop3 delete> | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | Set to a true value to cause messages to be deleted after reading them. | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | =item B<pop3 filter> | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | A regular expression that, if matches, discards the current | ||||||||||||||||||||||||||||||||||||||||||
| 59 | message. This is useful to avoid processing bounces. | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | =item B<pop3 debug> | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | If set to a true value, debug messages will be sent through C<warn()>. | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | The following methods are implemented within this class. | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | =item C<read($report)> | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | Populates the text of the given C<$report> using the C<-E<gt>text> | ||||||||||||||||||||||||||||||||||||||||||
| 74 | method. Must return true if succesful or false otherwise. | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | sub read | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: not called CC=23 SCAR=63.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my $rep = shift; | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $config = $rep->config; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | unless ($config->{'pop3 server'} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$config->{"pop3 server"} and $config->{"pop3 username"} and $config->{"pop3 password"}
$config->{"pop3 server"} and $config->{"pop3 username"}
MC/DC0%0/3
$config->{"pop3 server"} and $config->{"pop3 username"} and $config->{"pop3 password"}
$config->{"pop3 server"}
$config->{"pop3 username"}
$config->{"pop3 password"}
Truth table0%0/4
A and B and C
A= $config->{"pop3 server"}B= $config->{"pop3 username"}C= $config->{"pop3 password"}
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | and $config->{'pop3 username'} | ||||||||||||||||||||||||||||||||||||||||||
| 87 | and $config->{'pop3 password'}) | ||||||||||||||||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | carp "Not enough config info for POP3 reader"; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | unless ($self->pop3) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | warn "POP3 establishing session\n" if $config->{'pop3 debug'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $self->debug($config->{'pop3 debug'}); | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $self->pop3(Net::POP3->new($config->{'pop3 server'})); | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | unless ($self->pop3) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | { | ||||||||||||||||||||||||||||||||||||||||||
| 102 | warn "Failed to connect to POP3 server ", | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $config->{'pop3 server'}, ": $!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | unless ($self->pop3->login($config->{'pop3 username'}, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | $config->{'pop3 password'})) | ||||||||||||||||||||||||||||||||||||||||||
| 109 | { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | warn "POP3 authentication failed for user ", | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $config->{'pop3 username'}, "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ($config->{'pop3 filter'}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | { | ||||||||||||||||||||||||||||||||||||||||||
| 117 | my $re = ref $config->{'pop3 filter'} eq 'ARRAY' ? | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | join ' ', @{$config->{'pop3 filter'}} : | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $config->{'pop3 filter'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | warn "POP3 filter set to <$re>\n" if $config->{'pop3 debug'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $self->pop3_filter(qr($re)); | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | $self->msg(0) unless defined $self->msg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | # Here, $self->pop3 is a handle to a | ||||||||||||||||||||||||||||||||||||||||||
| 128 | # pop3 mailbox... | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $ret = undef; | |||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | while (1) | |||||||||||||||||||||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my $msg = $self->msg + 1; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $self->msg($msg); | |||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | warn "POP3 reading message $msg\n" if $config->{'pop3 debug'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $fh = $self->pop3->getfh($msg); | |||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if ($fh) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||||||||||||||||
| 142 | # Slurp the whole thing | ||||||||||||||||||||||||||||||||||||||||||
| 143 | # XXX - It seems that the FH returned | ||||||||||||||||||||||||||||||||||||||||||
| 144 | # by Net::POP3 does not respect $/ | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | local $/; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my $text; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | while (<$fh>) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | { | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $text .= $_; | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | warn "POP3 read ", length($text), " bytes from server\n" | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if $config->{'pop3 debug'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | my $re = $self->pop3_filter(); | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | if ($re and $text =~ m/$re/im) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$re and $text =~ /$re/im
MC/DC0%0/2
$re and $text =~ /$re/im
$re
$text =~ /$re/im
Truth table0%0/3
A and B
A= $reB= $text =~ /$re/im
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | { | ||||||||||||||||||||||||||||||||||||||||||
| 158 | warn "POP3 skip message $msg\n" | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if $config->{'pop3 debug'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | else | ||||||||||||||||||||||||||||||||||||||||||
| 162 | { | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $rep->text(\$text); | |||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $ret = 1; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | else | ||||||||||||||||||||||||||||||||||||||||||
| 168 | { | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | warn "POP3 no message $msg\n" if $config->{'pop3 debug'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $ret = undef; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if ($config->{'pop3 delete'}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | { | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | warn "POP3 deleting message $msg\n" if $config->{'pop3 debug'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | $self->pop3->delete($msg); | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | last if $ret; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | # XXX - Actually, I would prefer to | ||||||||||||||||||||||||||||||||||||||||||
| 183 | # keep the object until we're done with it | ||||||||||||||||||||||||||||||||||||||||||
| 184 | # but this makes it impossible to store | ||||||||||||||||||||||||||||||||||||||||||
| 185 | # the resulting object with Storable | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | $self->pop3->quit; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | $self->pop3(undef); | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | =item C<DESTROY> | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | In order to effectively delete any messages, this method terminates | ||||||||||||||||||||||||||||||||||||||||||
| 197 | gracefully the POP3 session using the C<-E<gt>quit> method of | ||||||||||||||||||||||||||||||||||||||||||
| 198 | C<Net::POP3>. | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | sub DESTROY | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | if ($self->pop3) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | { | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | warn "POP3 issuing QUIT command\n" if $self->debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | $self->pop3->quit; | |||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | __END__ | ||||||||||||||||||||||||||||||||||||||||||