| 1 | package GMail::Checker; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # Perl interface for a gmail wrapper | ||||||||||||||||||||||||||||
| 4 | # Allows you to check new mails, retrieving new mails and information about them | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # $Id: Checker.pm,v 1.04 2004/12/13 22:52:17 sacred Exp $ | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use IO::Socket::SSL; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | $VERSION = 1.04; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub version { sprintf("%f", $VERSION); } | ||||||||||||||||||||||||||
|
Subroutine
version: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 1 | my $self = {}; | |||||||||||||||||||||||||||
| 19 | 1 | my $proto = shift; | |||||||||||||||||||||||||||
| 20 | 1 | my %params = @_; | |||||||||||||||||||||||||||
| 21 | 1 | $self->{SOCK} = undef; | |||||||||||||||||||||||||||
| 22 | 1 | $self->{NBMSG} = 0; | |||||||||||||||||||||||||||
| 23 | 1 | $self->{USERNAME} = ''; | |||||||||||||||||||||||||||
| 24 | 1 | $self->{PASSWORD} = ''; | |||||||||||||||||||||||||||
| 25 | 1 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 26 | 1 | bless($self,$class); | |||||||||||||||||||||||||||
| 27 | 1 | ▶ | $self->login($params{"USERNAME"}, $params{"PASSWORD"}) if ((exists $params{"USERNAME"}) and (exists $params{"PASSWORD"})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $params{"USERNAME"} and exists $params{"PASSWORD"}
MC/DC0%0/2
exists $params{"USERNAME"} and exists $params{"PASSWORD"}
exists $params{"USERNAME"}
exists $params{"PASSWORD"}
Truth table33%1/3
A and B
A= exists $params{"USERNAME"}B= exists $params{"PASSWORD"}
| |||||||||||||||||||||||||||||
| 28 | 1 | return $self; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||
| 32 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | if (defined $self->{SOCK}) { $self->{SOCK}->close(); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | sub getsize { # Formatting the mail[box] size in a pretty manner | ||||||||||||||||||||||||||
|
Subroutine
getsize: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 38 | 1 | my $size = shift; | |||||||||||||||||||||||||||
| 39 | 1 | $size /= 1024; | |||||||||||||||||||||||||||
| 40 | 1 | my $unit = "Kbytes"; | |||||||||||||||||||||||||||
| 41 | 1 | ▶ | ($size, $unit) = ($size/1024, "Mbytes") if (($size / 1024) > 1) ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 1 | return ($size, $unit); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub login { | ||||||||||||||||||||||||||
|
Subroutine
login: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 47 | 0 | my ($login, $passwd) = @_; | |||||||||||||||||||||||||||
| 48 | 0 | ▶ | my $not = new IO::Socket::SSL "pop.gmail.com:995" or die IO::Socket::SSL->errstr(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | $self->{SOCK} = $not; | |||||||||||||||||||||||||||
| 50 | 0 | my $line = <$not>; # Reading the welcome message | |||||||||||||||||||||||||||
| 51 | 0 | print $not "USER $login\r\n"; | |||||||||||||||||||||||||||
| 52 | 0 | $line = <$not>; | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ($line !~ /^\+OK/) { print "Wrong username, please check your settings.\n"; $self->close(); } # We are not allowing USER on transaction state. | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | print $not "PASS $passwd\r\n"; | |||||||||||||||||||||||||||
| 55 | 0 | $line = <$not>; | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ($line !~ /^\+OK/) { print "Wrong password, please check your settings.\n"; $self->close(); } # Same as above for PASS. | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | $self->{USERNAME} = $login; | |||||||||||||||||||||||||||
| 58 | 0 | $self->{PASSWORD} = $passwd; | |||||||||||||||||||||||||||
| 59 | 0 | return 1; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub get_msg_nb_size { | ||||||||||||||||||||||||||
|
Subroutine
get_msg_nb_size: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 64 | 0 | ▶ | if (defined $self->{SOCK}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | my $gsocket = $self->{SOCK}; | |||||||||||||||||||||||||||
| 66 | 0 | print $gsocket "STAT\r\n"; | |||||||||||||||||||||||||||
| 67 | 0 | my $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | unless ($gans !~ /^\+OK\s(\d+)\s(\d+)(\s.*)?\r\n/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | return ($1,$2); # Sending the number of messages and the size of the mailbox | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 0 | } else { croak "Operation failed, connection to server is not established.\n"; } | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub get_pretty_nb_messages { | ||||||||||||||||||||||||||
|
Subroutine
get_pretty_nb_messages: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 76 | 0 | my %params = @_; | |||||||||||||||||||||||||||
| 77 | 0 | ▶ | $params{"ALERT"} = "TOTAL_MSG" unless exists $params{"ALERT"}; # Making sure we have an alert type. | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if (defined $self->{SOCK}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | my $gsocket = $self->{SOCK}; | |||||||||||||||||||||||||||
| 80 | 0 | print $gsocket "STAT\r\n"; | |||||||||||||||||||||||||||
| 81 | 0 | my $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 82 | 0 | ▶ | unless ($gans !~ /^\+OK\s(\d+)\s(\d+)(\s.*)?\r\n/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ($params{"ALERT"} eq "NEW_MSG_ONLY") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ($1 > $self->{NBMSG}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | return sprintf "You have %d new messages.\n", $1 - $self->{NBMSG}; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | 0 | $self->{NBMSG} = $1; | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | return sprintf "You have $1 messages in your inbox (size %0.2f %s)\n", $self->getsize($2) unless $params{"ALERT"} eq "NEW_MSG_ONLY"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 0 | } else { croak "Operation failed, connection to server is not established.\n"; } | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub get_msg_size { | ||||||||||||||||||||||||||
|
Subroutine
get_msg_size: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 96 | 0 | my %params = @_; | |||||||||||||||||||||||||||
| 97 | 0 | ▶ | if (defined $self->{SOCK}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | my (@msg_size, $gans); | |||||||||||||||||||||||||||
| 99 | 0 | my $gsocket = $self->{SOCK}; | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | if (exists $params{"MSG"}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | print $gsocket "LIST " . $params{"MSG"} . "\r\n"; | |||||||||||||||||||||||||||
| 102 | 0 | $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ($gans =~ /^\+OK\s(\d+)\s(\d+)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | ($msg_size[0]->{nb}, $msg_size[0]->{size}) = ($1, $2); | |||||||||||||||||||||||||||
| 105 | 0 | return @msg_size; | |||||||||||||||||||||||||||
| 106 | 0 | } else { print "No such message number.\r\n"; } | |||||||||||||||||||||||||||
| 107 | } else { | ||||||||||||||||||||||||||||
| 108 | 0 | print $gsocket "LIST\r\n"; | |||||||||||||||||||||||||||
| 109 | 0 | my $i = 0; | |||||||||||||||||||||||||||
| 110 | 0 | ▶ | for ($gans = <$gsocket>; $gans ne ".\r\n"; $gans = <$gsocket>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ($gans =~ /^(\d+)\s(\d+)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | ($msg_size[$i]->{nb}, $msg_size[$i]->{size}) = ($1, $2); | |||||||||||||||||||||||||||
| 113 | 0 | $i++; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | 0 | ▶ | ($msg_size[0]->{nb}, $msg_size[0]->{size}) = (-1,-1) if $i == 0; # Mailbox is empty | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | return @msg_size; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub parse_plain_msg { | ||||||||||||||||||||||||||
|
Subroutine
parse_plain_msg: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 123 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 124 | 0 | my ($gsocket, $msgl) = ($self->{SOCK}, ""); | |||||||||||||||||||||||||||
| 125 | 0 | ▶ | for (my $gans = <$gsocket>; $gans ne ".\r\n"; $gans = <$gsocket>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | $msgl .= $gans; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | 0 | return $msgl; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub msg_to_file { | ||||||||||||||||||||||||||
|
Subroutine
msg_to_file: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 132 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 133 | 0 | my $ind = shift; | |||||||||||||||||||||||||||
| 134 | 0 | my $gsocket = $self->{SOCK}; | |||||||||||||||||||||||||||
| 135 | 0 | print $gsocket "RETR $ind\r\n"; | |||||||||||||||||||||||||||
| 136 | 0 | my $gans = ""; | |||||||||||||||||||||||||||
| 137 | 0 | my @uidl = $self->get_uidl(MSG => $ind); | |||||||||||||||||||||||||||
| 138 | 0 | open(MAILFILE, ">" . $uidl[0]->{hash}); | |||||||||||||||||||||||||||
| 139 | 0 | ▶ | while ($gans ne ".\r\n") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 0 | $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 141 | 0 | print MAILFILE $gans; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | 0 | close(MAILFILE); | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | ▶ | sub parse_multipart_msg { | ||||||||||||||||||||||||||
|
Subroutine
parse_multipart_msg: not called CC=22 SCAR=62.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 147 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 148 | 0 | my ($gsocket, $msgl, $gans) = ($self->{SOCK}, "", ""); | |||||||||||||||||||||||||||
| 149 | 0 | my %msgs = @_; | |||||||||||||||||||||||||||
| 150 | 0 | my @attachments = undef; | |||||||||||||||||||||||||||
| 151 | 0 | my ($content, $opt, $opttype, $encoding, $filename) = (undef, undef, undef, undef, undef); | |||||||||||||||||||||||||||
| 152 | 0 | my $boundary = $msgs{opt}; | |||||||||||||||||||||||||||
| 153 | 0 | ▶ | while ($gans !~ /^--$boundary/) { $gans = <$gsocket>; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | # Retrieving the message body [inline text]. | ||||||||||||||||||||||||||||
| 156 | 0 | ▶ | while ($gans ne "\r\n") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 0 | $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 158 | 0 | ▶ | if ($gans =~ /^Content-Type: ([a-z0-9\/-]+);\s?(?:([a-z0-9-]+)=\"?([a-z0-9._=-]+)\"?)?\r\n/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 0 | $content = $1; | |||||||||||||||||||||||||||
| 160 | 0 | ▶ | if (!defined $2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 162 | 0 | $gans =~ /\s+([a-z0-9-]+)=\"?([a-z0-9._=-]+)\"?\r\n/i; | |||||||||||||||||||||||||||
| 163 | 0 | $opt = $2; | |||||||||||||||||||||||||||
| 164 | 0 | $opttype = $1; | |||||||||||||||||||||||||||
| 165 | 0 | } else { $opt = $3; $opttype = $2; } # Content options (eg. name, charset) | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | 0 | ▶ | if ($gans =~ /^Content-Transfer-Encoding: (7bit|8bit|binary|base64|quote-printable|ietf-token|x-token)\r\n/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | 0 | $encoding = $1; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | 0 | ▶ | do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$gans ne ".\r\n" and not $gans =~ /^--$boundary/i
MC/DC0%0/2
$gans ne ".\r\n" and not $gans =~ /^--$boundary/i
$gans ne ".\r\n"
not $gans =~ /^--$boundary/i
Truth table0%0/3
A and not(B)
A= $gans ne ".\r\n"B= not $gans =~ /^--$boundary/i
| |||||||||||||||||||||||||||||
| 172 | 0 | $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 173 | 0 | ▶ | $msgs{body} .= $gans unless $gans =~ /^--$boundary/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | } while (($gans ne ".\r\n") && ($gans !~ /^--$boundary/i)); | ||||||||||||||||||||||||||||
| 175 | 0 | $msgs{contentmsg} = $content; | |||||||||||||||||||||||||||
| 176 | 0 | $msgs{optmsg} = $opt; | |||||||||||||||||||||||||||
| 177 | 0 | $msgs{opttypemsg} = $opttype; | |||||||||||||||||||||||||||
| 178 | 0 | $msgs{encoding} = $encoding; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | # Retrieving attachements. | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | ▶ | for (my $i = -1; $gans ne ".\r\n";) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 0 | ▶ | if ($gans =~ /^--$boundary/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 0 | $i++; | |||||||||||||||||||||||||||
| 185 | 0 | ($content, $opt, $opttype, $encoding, $filename) = ("","","","",""); | |||||||||||||||||||||||||||
| 186 | 0 | $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 187 | 0 | ▶ | while ($gans !~ /^(?:--$boundary|\.\r\n)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 0 | ▶ | if ($gans =~ /^Content-Type: ([a-z0-9\/-]+);\s?(?:([a-z0-9-]+)=\"?([a-z0-9._=-]+)\"?)?\r\n/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | 0 | $content = $1; | |||||||||||||||||||||||||||
| 190 | 0 | ▶ | if (!defined $2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | 0 | $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 192 | 0 | $gans =~ /\s+([a-z0-9-]+)=\"?([a-z0-9._=-]+)\"?\r\n/i; | |||||||||||||||||||||||||||
| 193 | 0 | $opt = $2; | |||||||||||||||||||||||||||
| 194 | 0 | $opttype = $1; | |||||||||||||||||||||||||||
| 195 | 0 | } else { $opt = $3; $opttype = $2; } # Content options (eg. name, charset) | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | 0 | ▶ | if ($gans =~ /^Content-Transfer-Encoding: (7bit|8bit|binary|base64|quote-printable|ietf-token|x-token)\r\n/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | 0 | $encoding = $1; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | 0 | ▶ | if ($gans =~ /^Content-Disposition: ([a-z]+);(?:\s+filename=\"?(\S+)\"?)?/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | 0 | ▶ | if ($1 eq "attachment") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if (!defined $2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 0 | $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 204 | 0 | ($attachments[$i]->{filename}) = $gans =~ /\s+filename=\"?(\S+)\"?/; | |||||||||||||||||||||||||||
| 205 | 0 | } else {$attachments[$i]->{filename} = $3; } | |||||||||||||||||||||||||||
| 206 | 0 | ▶ | while ($gans ne "\r\n") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 0 | $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 208 | 0 | ▶ | if ($gans =~ /^\s+$/) { next; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | 0 | $attachments[$i]->{body} .= $gans; | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | 0 | $attachments[$i]->{content} = $content; | |||||||||||||||||||||||||||
| 212 | 0 | $attachments[$i]->{opt} = $opt; | |||||||||||||||||||||||||||
| 213 | 0 | $attachments[$i]->{opttype} = $opttype; | |||||||||||||||||||||||||||
| 214 | 0 | $attachments[$i]->{encoding} = $encoding; | |||||||||||||||||||||||||||
| 215 | 0 | $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 216 | 0 | last; | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | 0 | $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | 0 | ▶ | if ($gans !~ /^(--$boundary|\.\r\n)/i) { $gans = <$gsocket>;} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if (@attachments != 0) { $msgs{attachment} = @attachments; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 0 | return %msgs; | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 0 | ▶ | sub parse_msg { | ||||||||||||||||||||||||||
|
Subroutine
parse_msg: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 229 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 230 | 0 | my $ind = shift; | |||||||||||||||||||||||||||
| 231 | 0 | my %msgs; | |||||||||||||||||||||||||||
| 232 | 0 | my $gsocket = $self->{SOCK}; | |||||||||||||||||||||||||||
| 233 | 0 | print $gsocket "RETR $ind\r\n"; | |||||||||||||||||||||||||||
| 234 | 0 | my ($msgl, $msgtype) = ("", 0); | |||||||||||||||||||||||||||
| 235 | 0 | my $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 236 | 0 | ▶ | if ($gans =~ /^\+OK\s/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | 0 | ▶ | do { # Getting the message headers | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 0 | $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 239 | 0 | ▶ | $msgl .= $gans if $gans =~ /^([A-Z][a-zA-Z0-9-]+:\s+|\t)/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | 0 | ▶ | if ($gans =~ /^Content-Type: ([a-z0-9\/-]+);\s?(?:([a-z0-9-]+)=\"?([a-z0-9._=-]+)\"?)?\r\n/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | 0 | $msgs{content} = $1; | |||||||||||||||||||||||||||
| 242 | 0 | ▶ | if ($msgs{content} =~ /^multipart\/mixed/i) { $msgtype = 1; } # Mail content | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 243 | 0 | ▶ | if (!defined $2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | 0 | $msgl .= $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 245 | 0 | $gans =~ /\s+([a-z0-9-]+)=\"?([a-z0-9._=-]+)\"?\r\n/i; | |||||||||||||||||||||||||||
| 246 | 0 | $msgs{opt} = $2; | |||||||||||||||||||||||||||
| 247 | 0 | $msgs{opttype} = $1; | |||||||||||||||||||||||||||
| 248 | 0 | } else { $msgs{opt} = $3; $msgs{opttype} = $2; } # Content options (eg. name, charset) | |||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | # We need to know the encoding type | ||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if ($gans =~ /^Content-Type-Encoding: (7bit|8bit|binary|base64|quote-printable|ietf-token|x-token)\r\n/i) { $msgs{encoding} = $1; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | } while ($gans ne "\r\n"); | ||||||||||||||||||||||||||||
| 253 | 0 | $msgs{headers} = $msgl; | |||||||||||||||||||||||||||
| 254 | 0 | $msgl = ""; | |||||||||||||||||||||||||||
| 255 | 0 | ▶ | if (!$msgtype) { $msgs{body} = $self->parse_plain_msg(); } else { %msgs = $self->parse_multipart_msg(%msgs); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | 0 | return %msgs; | |||||||||||||||||||||||||||
| 257 | 0 | } else { print "No such message number (" . $ind .").\r\n"; } | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 0 | ▶ | sub get_msg { | ||||||||||||||||||||||||||
|
Subroutine
get_msg: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 261 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 262 | 0 | my %params = @_; | |||||||||||||||||||||||||||
| 263 | 0 | ▶ | if (defined $self->{SOCK}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | 0 | my (@msgs, $gans); | |||||||||||||||||||||||||||
| 265 | 0 | my $gsocket = $self->{SOCK}; | |||||||||||||||||||||||||||
| 266 | 0 | ▶ | if (exists $params{"MSG"}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 267 | 0 | my %tmp = $self->parse_msg($params{"MSG"}); | |||||||||||||||||||||||||||
| 268 | 0 | push(@msgs, \%tmp); | |||||||||||||||||||||||||||
| 269 | 0 | ▶ | print $gsocket "DELE " . $params{"MSG"} . "\r\n" if exists $params{"DELETE"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | } else { | ||||||||||||||||||||||||||||
| 271 | 0 | my $total = shift(@{ $self->get_msg_nb_size() } ); | |||||||||||||||||||||||||||
| 272 | 0 | ▶ | for (my $ind = 1; $ind < $total; $ind++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 273 | 0 | my %tmp = $self->parse_msg($ind); | |||||||||||||||||||||||||||
| 274 | 0 | push(@msgs, \%tmp); | |||||||||||||||||||||||||||
| 275 | 0 | ▶ | print $gsocket "DELE $ind\r\n" if exists $params{"DELETE"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | 0 | return @msgs; | |||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 0 | ▶ | sub get_msg_headers { | ||||||||||||||||||||||||||
|
Subroutine
get_msg_headers: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 283 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 284 | 0 | my %params = @_; | |||||||||||||||||||||||||||
| 285 | 0 | ▶ | $params{"HEADERS"} = "MINIMAL" unless exists $params{"HEADERS"}; # Making sure we have headers type for retrieval. | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 286 | 0 | ▶ | my $headregx = ($params{"HEADERS"} eq "FULL") ? '^([A-Z][a-zA-Z0-9-]+:\s+|\t)' : '^(From|Subject|Date):\s+'; # Headers regexp | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | 0 | my @messages = []; | |||||||||||||||||||||||||||
| 288 | 0 | ▶ | if (defined $self->{SOCK}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | 0 | my $gsocket = $self->{SOCK}; | |||||||||||||||||||||||||||
| 290 | 0 | my ($lastmsg, $gans) = (undef, undef); | |||||||||||||||||||||||||||
| 291 | 0 | ▶ | if (!exists $params{"MSG"}) { # By default we get the last message's headers. | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | 0 | print $gsocket "STAT\r\n"; | |||||||||||||||||||||||||||
| 293 | 0 | $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 294 | 0 | ▶ | if ($gans =~ /^\+OK\s(\d+)\s\d+(\s.*)?\r\n/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | 0 | $lastmsg = $1; | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | } else { # Did we specify a message for which we want headers ? | ||||||||||||||||||||||||||||
| 298 | 0 | $lastmsg = $params{"MSG"}; | |||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||
| 300 | 0 | print $gsocket "TOP $lastmsg 1\r\n"; | |||||||||||||||||||||||||||
| 301 | 0 | $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 302 | 0 | ▶ | if ($gans =~ /^\+OK/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 303 | 0 | ▶ | do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | 0 | $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 305 | 0 | ▶ | push(@messages, $gans) if $gans =~ /$headregx/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 306 | } while ($gans ne "\r\n"); | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | 0 | } else { print "No such message number.\r\n"; } # Duh! We received an -ERR | |||||||||||||||||||||||||||
| 309 | 0 | return @messages; | |||||||||||||||||||||||||||
| 310 | 0 | } else { croak "Operation failed, socket is not open.\n"; } | |||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | 0 | ▶ | sub get_uidl { | ||||||||||||||||||||||||||
|
Subroutine
get_uidl: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 314 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 315 | 0 | my %params = @_; | |||||||||||||||||||||||||||
| 316 | 0 | ▶ | if (defined $self->{SOCK}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | 0 | my (@uidls, $gans); | |||||||||||||||||||||||||||
| 318 | 0 | my $gsocket = $self->{SOCK}; | |||||||||||||||||||||||||||
| 319 | 0 | ▶ | if (exists $params{"MSG"}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 320 | 0 | print $gsocket "UIDL " . $params{"MSG"} . "\r\n"; | |||||||||||||||||||||||||||
| 321 | 0 | $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 322 | 0 | ▶ | if ($gans =~ /^\+OK\s\d+\s<([\x21-\x7E]+)>\r\n/) { return $1; } else { print "No such message number (" . $params{"MSG"} .").\r\n"; return -1;} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 323 | } else { | ||||||||||||||||||||||||||||
| 324 | 0 | print $gsocket "UIDL\r\n"; | |||||||||||||||||||||||||||
| 325 | 0 | my $i = 0; | |||||||||||||||||||||||||||
| 326 | 0 | ▶ | for ($gans = <$gsocket>; $gans ne ".\r\n"; $gans = <$gsocket>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 327 | 0 | ▶ | if ($gans =~ /^(\d+)\s<([\x21-\x7E]+)>\r\n/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 328 | 0 | ($uidls[$i]->{nb}, $uidls[$i]->{hash}) = ($1, $2); | |||||||||||||||||||||||||||
| 329 | 0 | $i++; | |||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||
| 332 | 0 | ▶ | ($uidls[0]->{nb}, $uidls[0]->{hash}) = (-1,-1) if $i == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | 0 | return @uidls; | |||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | 0 | } else { croak "Operation failed, socket is not open.\n"; } | |||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | 0 | ▶ | sub rset { | ||||||||||||||||||||||||||
|
Subroutine
rset: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 339 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 340 | 0 | ▶ | if (defined $self->{SOCK}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 341 | 0 | my $gsocket = $self->{SOCK}; | |||||||||||||||||||||||||||
| 342 | 0 | print $gsocket "RSET\r\n"; | |||||||||||||||||||||||||||
| 343 | 0 | my $gans = <$gsocket>; | |||||||||||||||||||||||||||
| 344 | 0 | return $gans; | |||||||||||||||||||||||||||
| 345 | 0 | } else { croak "Operation failed, socket is not open.\n"; } | |||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | 0 | ▶ | sub close { | ||||||||||||||||||||||||||
|
Subroutine
close: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 349 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 350 | 0 | ▶ | if (defined $self->{SOCK}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 351 | 0 | my $gsocket = $self->{SOCK}; | |||||||||||||||||||||||||||
| 352 | 0 | print $gsocket "QUIT\r\n"; # Sending a proper quit to the server so it can make an UPDATE in case DELE requests were sent. | |||||||||||||||||||||||||||
| 353 | 0 | $gsocket->close(SSL_ctx_free => 1); # Freeing the connection context | |||||||||||||||||||||||||||
| 354 | 0 | $self->{SOCK} = undef; | |||||||||||||||||||||||||||
| 355 | 0 | return 1; | |||||||||||||||||||||||||||
| 356 | 0 | } else { croak "Operation failed, socket is not open.\n"; } | |||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | __END__ | ||||||||||||||||||||||||||||