| 1 | # This code is part of Perl distribution Mail-Box-POP3 version 4.02. | ||||||||||||||||||||||||||||
| 2 | # The POD got stripped from this file by OODoc version 3.06. | ||||||||||||||||||||||||||||
| 3 | # For contributors see file ChangeLog. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # This software is copyright (c) 2001-2026 by Mark Overmeer. | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 8 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 9 | # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | package Mail::Transport::POP3;{ | ||||||||||||||||||||||||||||
| 13 | 4 | our $VERSION = '4.02'; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use parent 'Mail::Transport::Receive'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 4 | ▶ | use Log::Report 'mail-box-pop3', import => [ qw/error fault __x/ ]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 4 | ▶ | use IO::Socket (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 4 | ▶ | use IO::Socket::IP (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 4 | ▶ | use IO::Socket::SSL qw/SSL_VERIFY_NONE/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 4 | ▶ | use Socket qw/$CRLF/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 4 | ▶ | use Digest::MD5 qw/md5_hex/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 4 | ▶ | use MIME::Base64 qw/encode_base64/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | #-------------------- | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub _OK($) { substr(shift // '', 0, 3) eq '+OK' } | ||||||||||||||||||||||||||
|
Subroutine
_OK: not called CC=2 SCAR=17.9
Condition0%0/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | sub init($) | ||||||||||||||||||||||||||||
| 35 | 0 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 0 | $args->{via} = 'pop3'; | |||||||||||||||||||||||||||
| 37 | 0 | ▶ | $args->{port} ||= 110; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{"port"} ||= 110
MC/DC0%0/1
$args->{"port"} ||= 110
$args->{"port"}
Truth table0%0/2
A
A= $args->{"port"}
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | $self->SUPER::init($args) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | $self->{MTP_auth} = $args->{authenticate} || 'AUTO'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'authenticate'} || 'AUTO'
MC/DC0%0/1
$args->{'authenticate'} || 'AUTO'
$args->{'authenticate'}
Truth table0%0/2
A
A= $args->{'authenticate'}
| |||||||||||||||||||||||||||||
| 42 | 0 | $self->{MTP_ssl} = $args->{use_ssl}; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my $opts = $self->{MTP_ssl_opts} = $args->{ssl_options} || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'ssl_options'} || {}
MC/DC0%0/1
$args->{'ssl_options'} || {}
$args->{'ssl_options'}
Truth table0%0/2
A
A= $args->{'ssl_options'}
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | $opts->{verify_hostname} ||= 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts->{"verify_hostname"} ||= 0
MC/DC0%0/1
$opts->{"verify_hostname"} ||= 0
$opts->{"verify_hostname"}
Truth table0%0/2
A
A= $opts->{"verify_hostname"}
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $opts->{SSL_verify_mode} ||= SSL_VERIFY_NONE; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts->{"SSL_verify_mode"} ||= 0
MC/DC0%0/1
$opts->{"SSL_verify_mode"} ||= 0
$opts->{"SSL_verify_mode"}
Truth table0%0/2
A
A= $opts->{"SSL_verify_mode"}
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | $self->socket or return; # establish connection | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | $self; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | #-------------------- | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub useSSL() { $_[0]->{MTP_ssl} } | ||||||||||||||||||||||||||
|
Subroutine
useSSL: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub SSLOptions() { $_[0]->{MTP_ssl_opts} } | ||||||||||||||||||||||||||
|
Subroutine
SSLOptions: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub supportsUIDL() { ! exists $_[0]->{MTP_nouidl} } | ||||||||||||||||||||||||||
|
Subroutine
supportsUIDL: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | #-------------------- | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | sub ids(;@) | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
ids: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | $self->socket or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | wantarray ? @{$self->{MTP_n2uidl}} : $self->{MTP_n2uidl}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub messages() | ||||||||||||||||||||||||||||
| 72 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
messages: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | ! wantarray | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | or error __x"cannot get all messages of pop3 at once via messages()."; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | $self->{MTP_messages}; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub folderSize() { $_[0]->{MTP_folder_size} } | ||||||||||||||||||||||||||
|
Subroutine
folderSize: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub header($;$) | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | { my ($self, $uidl, $bodylines) = @_; | ||||||||||||||||||||||||||
|
Subroutine
header: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $uidl or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | $bodylines //= 0;; | ||||||||||||||||||||||||||
|
Condition0%0/2
$bodylines //= 0
MC/DC0%0/1
$bodylines //= 0
$bodylines
Truth table0%0/2
A
A= $bodylines
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my $socket = $self->socket or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my $n = $self->id2n($uidl) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | $self->sendList($socket, "TOP $n $bodylines$CRLF"); | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | sub message($;$) | ||||||||||||||||||||||||||||
| 97 | 0 | ▶ | { my ($self, $uidl) = @_; | ||||||||||||||||||||||||||
|
Subroutine
message: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | $uidl or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | my $socket = $self->socket or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my $n = $self->id2n($uidl) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my $message = $self->sendList($socket, "RETR $n$CRLF") or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | # Some POP3 servers add a trailing empty line | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | pop @$message if @$message && $message->[-1] =~ m/^[\012\015]*$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@$message and $message->[-1] =~ /^[\012\015]*$/
MC/DC0%0/2
@$message and $message->[-1] =~ /^[\012\015]*$/
@$message
$message->[-1] =~ /^[\012\015]*$/
Truth table0%0/3
A and B
A= @$messageB= $message->[-1] =~ /^[\012\015]*$/
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | $self->{MTP_fetched}{$uidl} = undef # mark this ID as fetched | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | if $self->supportsUIDL; | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | $message; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | sub messageSize($) | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | { my ($self, $uidl) = @_; | ||||||||||||||||||||||||||
|
Subroutine
messageSize: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | $uidl or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | my $list; | |||||||||||||||||||||||||||
| 119 | 0 | ▶ | unless($list = $self->{MTP_n2length}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | { my $socket = $self->socket or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | my $raw = $self->sendList($socket, "LIST$CRLF") or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | my @n2length; | |||||||||||||||||||||||||||
| 123 | 0 | foreach (@$raw) | |||||||||||||||||||||||||||
| 124 | 0 | { m#^(\d+) (\d+)#; | |||||||||||||||||||||||||||
| 125 | 0 | $n2length[$1] = $2; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | 0 | $self->{MTP_n2length} = $list = \@n2length; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | my $n = $self->id2n($uidl) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 0 | $list->[$n]; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | sub deleted($@) | ||||||||||||||||||||||||||||
| 136 | 0 | ▶ | { my $dele = shift->{MTP_dele} ||= {}; | ||||||||||||||||||||||||||
|
Subroutine
deleted: not called CC=3 SCAR=24.8
Pod
documented
Condition0%0/2
+(shift())->{"MTP_dele"} ||= {}
MC/DC0%0/1
+(shift())->{"MTP_dele"} ||= {}
+(shift())->{"MTP_dele"}
Truth table0%0/2
A
A= +(shift())->{"MTP_dele"}
| |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | (shift) ? @$dele{ @_ } = () : delete @$dele{ @_ }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | sub deleteFetched() | ||||||||||||||||||||||||||||
| 142 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
deleteFetched: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 143 | 0 | $self->deleted(1, keys %{$self->{MTP_fetched}}); | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | sub disconnect() | ||||||||||||||||||||||||||||
| 148 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
disconnect: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | my $quit; | |||||||||||||||||||||||||||
| 151 | 0 | ▶ | if($self->{MTP_socket}) # can only disconnect once | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | { if(my $socket = $self->socket) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 0 | ▶ | { my $dele = $self->{MTP_dele} || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'MTP_dele'} || {}
MC/DC0%0/1
$self->{'MTP_dele'} || {}
$self->{'MTP_dele'}
Truth table0%0/2
A
A= $self->{'MTP_dele'}
| |||||||||||||||||||||||||||||
| 154 | 0 | ▶ | while(my $uidl = each %$dele) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 0 | ▶ | { my $n = $self->id2n($uidl) or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 0 | ▶ | $self->send($socket, "DELE $n$CRLF") or last; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | $quit = $self->send($socket, "QUIT$CRLF"); | |||||||||||||||||||||||||||
| 160 | 0 | close $socket; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | delete @$self{ qw(MTP_socket MTP_dele MTP_uidl2n MTP_n2uidl MTP_n2length MTP_fetched) }; | |||||||||||||||||||||||||||
| 165 | 0 | _OK $quit; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | sub fetched(;$) | ||||||||||||||||||||||||||||
| 170 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
fetched: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | $self->supportsUIDL ? $self->{MTP_fetched} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 0 | ▶ | sub id2n($$) { $_[0]->{MTP_uidl2n}{$_[1]} } | ||||||||||||||||||||||||||
|
Subroutine
id2n: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | #-------------------- | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | sub socket() | ||||||||||||||||||||||||||||
| 180 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
socket: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | # Do we (still) have a working connection which accepts commands? | ||||||||||||||||||||||||||||
| 183 | 0 | my $socket = $self->_connection; | |||||||||||||||||||||||||||
| 184 | 0 | ▶ | return $socket if defined $socket; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 0 | ▶ | $self->supportsUIDL | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | or error __x"can not re-connect reliably to server which doesn't support UIDL."; | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | # (Re-)establish the connection | ||||||||||||||||||||||||||||
| 190 | 0 | ▶ | $socket = $self->login or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | 0 | ▶ | $self->status($socket) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | 0 | $self->{MTP_socket} = $socket; | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | sub send($$) | ||||||||||||||||||||||||||||
| 198 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
send: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 199 | 0 | my $socket = shift; | |||||||||||||||||||||||||||
| 200 | 0 | my $response; | |||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if(eval { print $socket @_} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 0 | { $response = <$socket>; | |||||||||||||||||||||||||||
| 204 | 0 | ▶ | defined $response or fault __x"cannot read POP3 from socket"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | else | ||||||||||||||||||||||||||||
| 207 | 0 | { error __x"cannot write POP3 to socket: {error}", error => $@; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | 0 | $response; | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | sub sendList($$) | ||||||||||||||||||||||||||||
| 214 | 0 | ▶ | { my ($self, $socket) = (shift, shift); | ||||||||||||||||||||||||||
|
Subroutine
sendList: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 215 | 0 | my $response = $self->send($socket, @_); | |||||||||||||||||||||||||||
| 216 | 0 | ▶ | $response && _OK $response or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$response and &_OK($response)
MC/DC0%0/2
$response and &_OK($response)
$response
&_OK($response)
Truth table0%0/3
A and B
A= $responseB= &_OK($response)
| |||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 0 | my @list; | |||||||||||||||||||||||||||
| 219 | 0 | ▶ | while(my $line = <$socket>) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 0 | ▶ | { last if $line =~ m#^\.\r?\n#s; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 0 | $line =~ s#^\.##; | |||||||||||||||||||||||||||
| 222 | 0 | push @list, $line; | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 0 | \@list; | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | sub DESTROY() | ||||||||||||||||||||||||||||
| 229 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 230 | 0 | $self->SUPER::DESTROY; | |||||||||||||||||||||||||||
| 231 | 0 | ▶ | $self->disconnect if $self->{MTP_socket}; # only when open | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | sub _connection() | ||||||||||||||||||||||||||||
| 235 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_connection: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 236 | 0 | ▶ | my $socket = $self->{MTP_socket} // return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"MTP_socket"} // (return)
MC/DC0%0/1
$self->{"MTP_socket"} // (return)
$self->{"MTP_socket"}
Truth table0%0/2
A
A= $self->{"MTP_socket"}
| |||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | # Check if we (still) got a connection | ||||||||||||||||||||||||||||
| 239 | 0 | eval { print $socket "NOOP$CRLF" }; | |||||||||||||||||||||||||||
| 240 | 0 | ▶ | if($@ || ! <$socket> ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ or not readline $socket
MC/DC0%0/2
$@ or not readline $socket
$@
not readline $socket
Truth table0%0/3
A or not(B)
A= $@B= not readline $socket
| |||||||||||||||||||||||||||||
| 241 | 0 | { delete $self->{MTP_socket}; | |||||||||||||||||||||||||||
| 242 | 0 | return undef; | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 0 | $socket; | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | sub login(;$) | ||||||||||||||||||||||||||||
| 251 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
login: not called CC=24 SCAR=64.0
Pod
documented
| |||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | # Check if we can make a connection | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 0 | my ($host, $port, $username, $password) = $self->remoteHost; | |||||||||||||||||||||||||||
| 256 | 0 | ▶ | $username && $password | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$username and $password
MC/DC0%0/2
$username and $password
$username
$password
Truth table0%0/3
A and B
A= $usernameB= $password
| |||||||||||||||||||||||||||||
| 257 | or error __x"POP3 requires a username and password."; | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 0 | my $socket; | |||||||||||||||||||||||||||
| 260 | 0 | ▶ | if($self->useSSL) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 261 | 0 | { my $opts = $self->SSLOptions; | |||||||||||||||||||||||||||
| 262 | 0 | $socket = eval { IO::Socket::SSL->new(PeerAddr => "$host:$port", %$opts) }; | |||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||
| 264 | else | ||||||||||||||||||||||||||||
| 265 | 0 | { $socket = eval { IO::Socket::IP->new("$host:$port") }; | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 0 | ▶ | $socket | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | or fault __x"cannot connect to {service} for POP3", service => "$host:$port"; | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | # Check if it looks like a POP server | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 0 | my $connected; | |||||||||||||||||||||||||||
| 274 | 0 | my $authenticate = $self->{MTP_auth}; | |||||||||||||||||||||||||||
| 275 | 0 | my $welcome = <$socket>; | |||||||||||||||||||||||||||
| 276 | 0 | ▶ | _OK $welcome | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | or error __x"server at {service} does not seem to be talking POP3.", service => "$host:$port"; | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | # Check APOP login if automatic or APOP specifically requested | ||||||||||||||||||||||||||||
| 280 | 0 | ▶ | if($authenticate eq 'AUTO' || $authenticate eq 'APOP') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$authenticate eq "AUTO" or $authenticate eq "APOP"
MC/DC0%0/2
$authenticate eq "AUTO" or $authenticate eq "APOP"
$authenticate eq "AUTO"
$authenticate eq "APOP"
Truth table0%0/3
A or B
A= $authenticate eq "AUTO"B= $authenticate eq "APOP"
| |||||||||||||||||||||||||||||
| 281 | 0 | ▶ | { if($welcome =~ m#^\+OK .*(<\d+\.\d+\@[^>]+>)#) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 282 | 0 | { my $md5 = md5_hex $1.$password; | |||||||||||||||||||||||||||
| 283 | 0 | my $response = $self->send($socket, "APOP $username $md5$CRLF"); | |||||||||||||||||||||||||||
| 284 | 0 | $connected = _OK $response; | |||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | # Check USER/PASS login if automatic and failed or LOGIN specifically | ||||||||||||||||||||||||||||
| 289 | # requested. | ||||||||||||||||||||||||||||
| 290 | 0 | ▶ | unless($connected) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 291 | 0 | ▶ | { if($authenticate eq 'AUTO' || $authenticate eq 'LOGIN') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$authenticate eq "AUTO" or $authenticate eq "LOGIN"
MC/DC0%0/2
$authenticate eq "AUTO" or $authenticate eq "LOGIN"
$authenticate eq "AUTO"
$authenticate eq "LOGIN"
Truth table0%0/3
A or B
A= $authenticate eq "AUTO"B= $authenticate eq "LOGIN"
| |||||||||||||||||||||||||||||
| 292 | 0 | ▶ | { my $response = $self->send($socket, "USER $username$CRLF") or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 0 | ▶ | if(_OK $response) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | 0 | ▶ | { my $response2 = $self->send($socket, "PASS $password$CRLF") or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | 0 | $connected = _OK $response2; | |||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | # Try OAUTH2 login | ||||||||||||||||||||||||||||
| 302 | 0 | ▶ | if(! $connected && $authenticate =~ /^OAUTH2/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $connected and $authenticate =~ /^OAUTH2/
MC/DC0%0/2
not $connected and $authenticate =~ /^OAUTH2/
not $connected
$authenticate =~ /^OAUTH2/
Truth table0%0/3
not(A) and B
A= not $connectedB= $authenticate =~ /^OAUTH2/
| |||||||||||||||||||||||||||||
| 303 | { # Borrowed from Net::POP3::XOAuth2 0.0.2 by Kizashi Nagata (also Perl license) | ||||||||||||||||||||||||||||
| 304 | 0 | my $token = encode_base64 "user=$username\001auth=Bearer $password\001\001"; | |||||||||||||||||||||||||||
| 305 | 0 | $token =~ s/[\r\n]//g; # no base64 newlines, anywhere | |||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | 0 | ▶ | if($authenticate eq 'OAUTH2_SEP') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 308 | { # Microsofts way | ||||||||||||||||||||||||||||
| 309 | # https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth | ||||||||||||||||||||||||||||
| 310 | 0 | ▶ | my $response = $self->send($socket, "AUTH XOAUTH2$CRLF") or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | 0 | ▶ | if($response =~ /^\+/) # Office365 sends + here, not +OK | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | 0 | ▶ | { my $response2 = $self->send($socket, "$token$CRLF") or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 314 | 0 | $connected = _OK $response2; | |||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||
| 317 | else | ||||||||||||||||||||||||||||
| 318 | 0 | ▶ | { my $response = $self->send($socket, "AUTH XOAUTH2 $token$CRLF") or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 319 | 0 | $connected = _OK $response; | |||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | # If we're still not connected now, we have an error | ||||||||||||||||||||||||||||
| 324 | 0 | ▶ | unless($connected) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 325 | 0 | ▶ | { $authenticate eq 'AUTO' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 326 | ? (error __x"could not authenticate using any login method.") | ||||||||||||||||||||||||||||
| 327 | : (error __x"could not authenticate using '{type}' method", type => $authenticate); | ||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | 0 | $socket; | |||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | sub status($;$) | ||||||||||||||||||||||||||||
| 336 | 0 | ▶ | { my ($self, $socket) = @_; | ||||||||||||||||||||||||||
|
Subroutine
status: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | # Check if we can do a STAT | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 0 | ▶ | my $stat = $self->send($socket, "STAT$CRLF") or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 341 | 0 | ▶ | if($stat !~ m#^\+OK (\d+) (\d+)#) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 342 | 0 | { delete $self->{MTP_messages}; | |||||||||||||||||||||||||||
| 343 | 0 | delete $self->{MTP_size}; | |||||||||||||||||||||||||||
| 344 | 0 | error __x"POP3 Could not do a STAT"; | |||||||||||||||||||||||||||
| 345 | 0 | return; | |||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||
| 347 | 0 | $self->{MTP_messages} = my $nr_msgs = $1; | |||||||||||||||||||||||||||
| 348 | 0 | $self->{MTP_folder_size} = $2; | |||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | # Check if we can do a UIDL | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 0 | ▶ | my $uidl = $self->send($socket, "UIDL$CRLF") or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 353 | 0 | $self->{MTP_nouidl} = undef; | |||||||||||||||||||||||||||
| 354 | 0 | delete $self->{MTP_uidl2n}; # drop the reverse lookup: UIDL -> number | |||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | 0 | ▶ | if(_OK $uidl) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 357 | 0 | { my @n2uidl; | |||||||||||||||||||||||||||
| 358 | 0 | $n2uidl[$nr_msgs] = undef; # pre-alloc | |||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | 0 | ▶ | while(my $line = <$socket>) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 361 | 0 | ▶ | { last if substr($line, 0, 1) eq '.'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 362 | 0 | ▶ | $line =~ m#^(\d+) (.+?)\r?\n# or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | 0 | $n2uidl[$1] = $2; | |||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 0 | shift @n2uidl; # make message 1 into index 0 | |||||||||||||||||||||||||||
| 367 | 0 | $self->{MTP_n2uidl} = \@n2uidl; | |||||||||||||||||||||||||||
| 368 | 0 | delete $self->{MTP_n2length}; | |||||||||||||||||||||||||||
| 369 | 0 | delete $self->{MTP_nouidl}; | |||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||
| 371 | else | ||||||||||||||||||||||||||||
| 372 | { # We can't do UIDL, we need to fake it | ||||||||||||||||||||||||||||
| 373 | 0 | ▶ | my $list = $self->send($socket, "LIST$CRLF") or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 374 | 0 | my (@n2length, @n2uidl); | |||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | 0 | ▶ | if(_OK $list) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 377 | 0 | { $n2length[$nr_msgs] = $n2uidl[$nr_msgs] = undef; # alloc all | |||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | 0 | my ($host, $port) = $self->remoteHost; | |||||||||||||||||||||||||||
| 380 | 0 | ▶ | while(my $line = <$socket>) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 381 | 0 | ▶ | { last if substr($line, 0, 1) eq '.'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 382 | 0 | ▶ | $line =~ m#^(\d+) (\d+)# or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 383 | 0 | $n2length[$1] = $2; | |||||||||||||||||||||||||||
| 384 | 0 | $n2uidl[$1] = "$host:$port:$1"; # fake UIDL, for id only | |||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | 0 | shift @n2length; shift @n2uidl; # make 1st message in index 0 | |||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||
| 388 | 0 | $self->{MTP_n2length} = \@n2length; | |||||||||||||||||||||||||||
| 389 | 0 | $self->{MTP_n2uidl} = \@n2uidl; | |||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | 0 | my $i = 1; | |||||||||||||||||||||||||||
| 393 | 0 | my %uidl2n = map +($_ => $i++), @{$self->{MTP_n2uidl}}; | |||||||||||||||||||||||||||
| 394 | 0 | $self->{MTP_uidl2n} = \%uidl2n; | |||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | 0 | 1; | |||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | #-------------------- | ||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | sub url(;$) | ||||||||||||||||||||||||||||
| 402 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
url: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 403 | 0 | my ($host, $port, $user, $pwd) = $self->remoteHost; | |||||||||||||||||||||||||||
| 404 | 0 | ▶ | my $proto = $self->useSSL ? 'pop3s' : 'pop3'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 405 | 0 | "$proto://$user:$pwd\@$host:$port"; | |||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | #-------------------- | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | 4 | 1; | |||||||||||||||||||||||||||