IMAPClient.pm

filter: Statementstmt 8.8% 154 / 1744 Branchbran 5.2% 69 / 1306 Conditioncond 4.9% 21 / 423 MC/DCmcdc 3.0% 8 / 262 Subroutinesub 12.7% 27 / 212 Podpod 92.5% 125 / 135 totaltotal 9.9% 404 / 4082 CC 829 SCAR 57.4
CC
829
Cov
7%
_read_line
2862.0
authenticate
992.0
append_file
870.0
CRAP 310.7
↑ Summary IMAPClient/BodyStructure/Parse.pm »
1  
2 # _{name} methods are undocumented and meant to be private.
3  
4 3 require 5.008_001;
5  
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  
9 package Mail::IMAPClient;
10 3 our $VERSION = '3.43';
11  
12 3 ▶use Mail::IMAPClient::MessageSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use IO::Socket qw(:crlf SOL_SOCKET SO_KEEPALIVE);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use IO::Select ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use Carp qw(carp); #local $SIG{__WARN__} = \&Carp::cluck; #DEBUG
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 3 ▶use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Errno qw(EAGAIN EBADF ECONNRESET EPIPE);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use List::Util qw(first min max sum);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use MIME::Base64 qw(encode_base64 decode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 3 ▶use constant APPEND_BUFFER_SIZE => 1024 * 1024;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
27 3 Unconnected => 0,
28 Connected => 1, # connected; not logged in
29 Authenticated => 2, # logged in; no mailbox selected
30 Selected => 3, # mailbox selected
31 3 };
32  
33 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
34 3 INDEX => 0, # Array index for output line number
35 TYPE => 1, # Array index for line type (OUTPUT, INPUT, or LITERAL)
36 DATA => 2, # Array index for output line data
37 3 };
38  
39 3 my %SEARCH_KEYS = map { ( $_ => 1 ) } qw(
40 ALL ANSWERED BCC BEFORE BODY CC DELETED DRAFT FLAGGED
41 FROM HEADER KEYWORD LARGER NEW NOT OLD ON OR RECENT
42 SEEN SENTBEFORE SENTON SENTSINCE SINCE SMALLER SUBJECT
43 TEXT TO UID UNANSWERED UNDELETED UNDRAFT UNFLAGGED
44 UNKEYWORD UNSEEN);
45  
46 # modules require(d) during runtime when applicable
47 3 my %Load_Module = (
48 "Compress-Zlib" => "Compress::Zlib",
49 "INET" => "IO::Socket::INET",
50 "IP" => "IO::Socket::IP",
51 "SSL" => "IO::Socket::SSL",
52 "UNIX" => "IO::Socket::UNIX",
53 "BodyStructure" => "Mail::IMAPClient::BodyStructure",
54 "Envelope" => "Mail::IMAPClient::BodyStructure::Envelope",
55 "Thread" => "Mail::IMAPClient::Thread",
56 );
57  
58 0 ▶sub _load_module {
Subroutine _load_module: not called CC=3 SCAR=24.8
59 0 my $self = shift;
60 0 my $modkey = shift;
61 0 ▶ my $module = $Load_Module{$modkey} || $modkey;
Condition0%0/3
$Load_Module{$modkey} || $modkey
l!l&&r!l&&!r
000
MC/DC0%0/2
$Load_Module{$modkey} || $modkey
$Load_Module{$modkey} $modkey
Truth table0%0/3
A || B
A= $Load_Module{$modkey}B= $modkey
ABresult
1X1
011
000
62  
63 0 my $err = do {
64 0 local ($@);
65 0 eval "require $module";
66 0 $@;
67 };
68 0 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
69 0 $self->LastError("Unable to load '$module': $err");
70 0 return undef;
71 }
72 0 return $module;
73 }
74  
75 4 ▶sub _debug {
Subroutine _debug: called CC=3 SCAR=18.7
76 4 my $self = shift;
77 4 ▶ return unless $self->Debug;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->Debug 4 0 4
78  
79 0 my $text = join '', @_;
80 0 $text =~ s/$CRLF/\n /og;
81 0 $text =~ s/\s*$/\n/;
82  
83 #use POSIX (); $text = POSIX::strftime("%F %T ", localtime).$text; #DEBUG
84 0 ▶ my $fh = $self->{Debug_fh} || \*STDERR;
Condition0%0/2
$self->{'Debug_fh'} || \*STDERR
l!l
00
MC/DC0%0/1
$self->{'Debug_fh'} || \*STDERR
$self->{'Debug_fh'}
Truth table0%0/2
A
A= $self->{'Debug_fh'}
Aresult
11
00
85 0 print $fh $text;
86 }
87  
88 3 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
89  
90 # set-up accessors
91 3 foreach my $datum (
92 qw(Authcallback Authmechanism Authuser Buffer Count Compress
93 Debug Debug_fh Domain Folder Ignoresizeerrors Keepalive
94 Maxappendstringlength Maxcommandlength Maxtemperrors
95 Password Peek Port Prewritemethod Proxy Ranges Readmethod
96 Readmoremethod Reconnectretry Server Showcredentials
97 Socketargs Ssl Starttls Supportedflags Timeout Uid User)
98 )
99 {
100 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
101 37 ▶ *$datum = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
102 37 ▶ @_ > 1 ? ( $_[0]->{$datum} = $_[1] ) : $_[0]->{$datum};
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 1 36 37
103 99 };
104 }
105 }
106  
107 0 ▶sub LastError {
Subroutine LastError: not called CC=6 SCAR=37.4
Pod documented
108 0 my $self = shift;
109 0 ▶ @_ or return $self->{LastError};
Branch: 1 branch
BranchTrueFalseTotal
@_ or return $self->{"LastError"} 0 0 0
110 0 my $err = shift;
111  
112 # allow LastError to be reset with undef
113 0 ▶ if ( defined $err ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $err) 0 0 0
114 0 $err =~ s/$CRLF$//og;
115 0 local ($!); # old versions of Carp could reset $!
116 0 $self->_debug( Carp::longmess("ERROR: $err") );
117  
118 # hopefully this is rare...
119 0 ▶ if ( $err =~ /NO not connected/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err =~ /NO not connected/) 0 0 0
120 0 ▶ my $lerr = $self->{LastError} || "";
Condition0%0/2
$self->{'LastError'} || ''
l!l
00
MC/DC0%0/1
$self->{'LastError'} || ''
$self->{'LastError'}
Truth table0%0/2
A
A= $self->{'LastError'}
Aresult
11
00
121 0 my $emsg = "Trying command when NOT connected!";
122 0 ▶ $emsg .= " LastError was: $lerr" if $lerr;
Branch: 1 branch
BranchTrueFalseTotal
if $lerr 0 0 0
123 0 Carp::cluck($emsg);
124 }
125 }
126  
127 # 2.x API support requires setting $@
128 0 $@ = $self->{LastError} = $err;
129 }
130  
131 0 ▶sub Fast_io(;$) {
Subroutine Fast_io: not called CC=7 SCAR=40.3
Pod documented
132 0 my ( $self, $use ) = @_;
133 defined $use
134 0 ▶ or return $self->{Fast_io};
Branch: 1 branch
BranchTrueFalseTotal
defined $use or return $self->{"Fast_io"} 0 0 0
135  
136 my $socket = $self->{Socket}
137 0 ▶ or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $socket = $self->{"Socket"} or return undef 0 0 0
138  
139 0 local ( $@, $! ); # avoid stomping on globals
140 0 ▶ unless ($use) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($use) 0 0 0
141 0 eval { fcntl( $socket, F_SETFL, delete $self->{_fcntl} ) }
142 0 ▶ if exists $self->{_fcntl};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_fcntl"} 0 0 0
143 0 $self->{Fast_io} = 0;
144 0 return undef;
145 }
146  
147 0 my $fcntl = eval { fcntl( $socket, F_GETFL, 0 ) };
148 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
149 0 $self->{Fast_io} = 0;
150 $self->_debug("not using Fast_IO; not available on this platform")
151 0 ▶ unless $self->{_fastio_warning_}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_fastio_warning_"}++ 0 0 0
152 0 return undef;
153 }
154  
155 0 $self->{Fast_io} = 1;
156 0 my $newflags = $self->{_fcntl} = $fcntl;
157 0 $newflags |= O_NONBLOCK;
158 0 fcntl( $socket, F_SETFL, $newflags );
159 }
160  
161 # removed
162 0 ▶sub EnableServerResponseInLiteral { undef }
Subroutine EnableServerResponseInLiteral: not called CC=1 SCAR=6.9
Pod documented
163  
164 0 ▶sub Wrap { shift->Clear(@_) }
Subroutine Wrap: not called CC=1 SCAR=6.9
Pod undocumented
165  
166 # The following class method is for creating valid dates in appended msgs:
167 3 my @dow = qw(Sun Mon Tue Wed Thu Fri Sat);
168 3 my @mnt = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
169  
170 0 ▶sub Rfc822_date {
Subroutine Rfc822_date: not called CC=2 SCAR=17.9
Pod documented
171 0 my $class = shift;
172 0 ▶ my $date = $class =~ /^\d+$/ ? $class : shift; # method or function?
Branch: 1 branch
BranchTrueFalseTotal
$class =~ /^\d+$/ ? : 0 0 0
173 0 my @date = gmtime($date);
174  
175 #Date: Fri, 09 Jul 1999 13:10:55 -0000
176 0 sprintf(
177 "%s, %02d %s %04d %02d:%02d:%02d -%04d",
178 $dow[ $date[6] ],
179 $date[3],
180 $mnt[ $date[4] ],
181 $date[5] + 1900,
182 $date[2], $date[1], $date[0], $date[8]
183 );
184 }
185  
186 # The following methods create valid dates for use in IMAP search strings
187 # - provide Rfc2060* methods/functions for backwards compatibility
188 2 ▶sub Rfc2060_date {
Subroutine Rfc2060_date: called CC=2 SCAR=6.9
Pod undocumented
189 2 ▶ $_[0] =~ /^\d+$/ ? Rfc3501_date(@_) : shift->Rfc3501_date(@_);
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^\d+$/ ? : 1 1 2
190 }
191  
192 4 ▶sub Rfc3501_date {
Subroutine Rfc3501_date: called CC=2 SCAR=6.9
Pod documented
193 4 my $class = shift;
194 4 ▶ my $stamp = $class =~ /^\d+$/ ? $class : shift;
Branch: 1 branch
BranchTrueFalseTotal
$class =~ /^\d+$/ ? : 2 2 4
195 4 my @date = gmtime($stamp);
196  
197 # 11-Jan-2000
198 4 sprintf( "%02d-%s-%04d", $date[3], $mnt[ $date[4] ], $date[5] + 1900 );
199 }
200  
201 4 ▶sub Rfc2060_datetime($;$) {
Subroutine Rfc2060_datetime: called CC=2 SCAR=6.9
Pod undocumented
202 4 ▶ $_[0] =~ /^\d+$/ ? Rfc3501_datetime(@_) : shift->Rfc3501_datetime(@_);
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^\d+$/ ? : 3 1 4
203 }
204  
205 8 ▶sub Rfc3501_datetime($;$) {
Subroutine Rfc3501_datetime: called CC=3 SCAR=11.0
Pod documented
206 8 my $class = shift;
207 8 ▶ my $stamp = $class =~ /^\d+$/ ? $class : shift;
Branch: 1 branch
BranchTrueFalseTotal
$class =~ /^\d+$/ ? : 6 2 8
208 8 ▶ my $zone = shift || '+0000';
Condition100%2/2
shift() || '+0000'
l!l
44
MC/DC100%1/1
shift() || '+0000'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
209 8 my @date = gmtime($stamp);
210  
211 # 11-Jan-2000 04:04:04 +0000
212 8 sprintf(
213 "%02d-%s-%04d %02d:%02d:%02d %s",
214 $date[3],
215 $mnt[ $date[4] ],
216 $date[5] + 1900,
217 $date[2], $date[1], $date[0], $zone
218 );
219 }
220  
221 # Change CRLF into \n
222 0 ▶sub Strip_cr {
Subroutine Strip_cr: not called CC=6 SCAR=37.4
Pod documented
223 0 my $class = shift;
224 0 ▶ if ( !ref $_[0] && @_ == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_[0] and @_ == 1) 0 0 0
Condition0%0/3
not ref $_[0] and @_ == 1
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $_[0] and @_ == 1
not ref $_[0] @_ == 1
Truth table0%0/3
not(A) and B
A= not ref $_[0]B= @_ == 1
ABresult
0X0
100
111
225 0 ( my $string = $_[0] ) =~ s/$CRLF/\n/og;
226 0 return $string;
227 }
228  
229 return wantarray
230 0 ▶ ? map { s/$CRLF/\n/og; $_ } ( ref $_[0] ? @{ $_[0] } : @_ )
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
231 0 ▶ : [ map { s/$CRLF/\n/og; $_ } ( ref $_[0] ? @{ $_[0] } : @_ ) ];
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 0 0 0
ref $_[0] ? : 0 0 0
232 }
233  
234 # The following defines a special method to deal with the Clear parameter:
235 0 ▶sub Clear {
Subroutine Clear: not called CC=3 SCAR=24.8
Pod documented
236 0 my ( $self, $clear ) = @_;
237 0 ▶ defined $clear or return $self->{Clear};
Branch: 1 branch
BranchTrueFalseTotal
defined $clear or return $self->{"Clear"} 0 0 0
238  
239 0 my $oldclear = $self->{Clear};
240 0 $self->{Clear} = $clear;
241  
242 0 my @keys = reverse $self->_trans_index;
243  
244 0 ▶ for ( my $i = $clear ; $i < @keys ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @keys) 0 0 0
245 0 delete $self->{History}{ $keys[$i] };
246 }
247  
248 0 return $oldclear;
249 }
250  
251 # read-only access to the transaction number
252 0 ▶sub Transaction { shift->Count }
Subroutine Transaction: not called CC=1 SCAR=6.9
Pod documented
253  
254 # remove doubles from list
255 0 ▶sub _remove_doubles(@) {
Subroutine _remove_doubles: not called CC=1 SCAR=6.9
256 0 my %seen;
257 0 grep { !$seen{ $_->{name} }++ } @_;
258 }
259  
260 # the constructor:
261 1 ▶sub new {
Subroutine new: called CC=17 SCAR=42.7
Pod documented
262 1 my $class = shift;
263 1 my $self = {
264 LastError => "",
265 Uid => 1,
266 Count => 0,
267 Clear => 2,
268 Keepalive => 0,
269 Maxappendstringlength => 1024**2,
270 Maxcommandlength => 1000,
271 Maxtemperrors => undef,
272 State => Unconnected,
273 Authmechanism => 'LOGIN',
274 Timeout => 600,
275 History => {},
276 };
277 1 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
278 0 my $k = ucfirst lc shift;
279 0 my $v = shift;
280 0 ▶ $self->{$k} = $v if defined $v;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 0 0 0
281 }
282 1 ▶ bless $self, ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
283  
284 # Fast_io is enabled by default when not given a socket
285 1 ▶ unless ( exists $self->{Fast_io} || $self->{Socket} || $self->{Rawsocket} )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"Fast_io"} or $self->{"Socket"} or $self->{"Rawsocket"}) 1 0 1
Condition33%2/6
exists $self->{"Fast_io"} or $self->{"Socket"} or $self->{"Rawsocket"}
l!l&&r!l&&!r
001
exists $self->{"Fast_io"} or $self->{"Socket"}
l!l&&r!l&&!r
001
MC/DC0%0/3
exists $self->{"Fast_io"} or $self->{"Socket"} or $self->{"Rawsocket"}
exists $self->{"Fast_io"} $self->{"Socket"} $self->{"Rawsocket"}
Truth table25%1/4
A or B or C
A= exists $self->{"Fast_io"}B= $self->{"Socket"}C= $self->{"Rawsocket"}
ABCresult
1XX1
01X1
0011
0000
286 {
287 1 $self->{Fast_io} = 1;
288 }
289  
290 1 ▶ if ( my $sup = $self->{Supportedflags} ) { # unpack into case-less HASH
Branch: 1 branch
BranchTrueFalseTotal
if (my $sup = $self->{"Supportedflags"}) 0 1 1
291 0 ▶ my %sup = map { m/^\\?(\S+)/ ? lc $1 : () } @$sup;
Branch: 1 branch
BranchTrueFalseTotal
/^\\?(\S+)/ ? : 0 0 0
292 0 $self->{Supportedflags} = \%sup;
293 }
294  
295 1 ▶ $self->{Debug_fh} ||= \*STDERR;
Condition50%1/2
$self->{"Debug_fh"} ||= \*STDERR
l!l
01
MC/DC0%0/1
$self->{"Debug_fh"} ||= \*STDERR
$self->{"Debug_fh"}
Truth table50%1/2
A
A= $self->{"Debug_fh"}
Aresult
11
00
296 1 CORE::select( ( select( $self->{Debug_fh} ), $|++ )[0] );
297  
298 1 ▶ if ( $self->Debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Debug) 0 1 1
299 0 $self->_debug( "Started at " . localtime() );
300 0 $self->_debug("Using Mail::IMAPClient version $VERSION on perl $]");
301 }
302  
303 # BUG? return undef on Socket() failure?
304 $self->Socket( $self->{Socket} )
305 1 ▶ if $self->{Socket};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Socket"} 0 1 1
306  
307 1 ▶ if ( $self->{Rawsocket} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Rawsocket"}) 0 1 1
308 0 my $sock = delete $self->{Rawsocket};
309  
310 # Ignore Rawsocket if Socket is set. BUG? should we carp/croak?
311 0 ▶ $self->RawSocket($sock) unless $self->{Socket};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Socket"} 0 0 0
312 }
313  
314 1 ▶ if ( !$self->{Socket} && $self->{Server} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"Socket"} and $self->{"Server"}) 0 1 1
Condition33%1/3
not $self->{"Socket"} and $self->{"Server"}
!ll&&!rl&&r
010
MC/DC0%0/2
not $self->{"Socket"} and $self->{"Server"}
not $self->{"Socket"} $self->{"Server"}
Truth table33%1/3
not(A) and B
A= not $self->{"Socket"}B= $self->{"Server"}
ABresult
0X0
100
111
315 0 ▶ $self->connect or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->connect or return undef 0 0 0
316 }
317 1 return $self;
318 }
319  
320 0 ▶sub connect(@) {
Subroutine connect: not called CC=20 SCAR=60.4
Pod documented
321 0 my $self = shift;
322  
323 # BUG? We should restrict which keys can be passed/set here.
324 0 ▶ %$self = ( %$self, @_ ) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
325  
326 0 ▶ my @sockargs = $self->Timeout ? ( Timeout => $self->Timeout ) : ();
Branch: 1 branch
BranchTrueFalseTotal
$self->Timeout ? : 0 0 0
327 0 ▶ push( @sockargs, $self->Debug ? ( Debug => $self->Debug ) : () );
Branch: 1 branch
BranchTrueFalseTotal
$self->Debug ? : 0 0 0
328  
329 # give caller control of IO::Socket::... args to new if desired
330 0 ▶ if ( $self->Socketargs and ref $self->Socketargs eq "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Socketargs and ref $self->Socketargs eq "ARRAY") 0 0 0
Condition0%0/3
$self->Socketargs and ref $self->Socketargs eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->Socketargs and ref $self->Socketargs eq "ARRAY"
$self->Socketargs ref $self->Socketargs eq "ARRAY"
Truth table0%0/3
A and B
A= $self->SocketargsB= ref $self->Socketargs eq "ARRAY"
ABresult
0X0
100
111
331 0 push( @sockargs, @{ $self->Socketargs } );
332 }
333  
334 # if no server, use " " to induce a non-fatal error
335 0 ▶ my $server = $self->Server || " ";
Condition0%0/2
$self->Server || ' '
l!l
00
MC/DC0%0/1
$self->Server || ' '
$self->Server
Truth table0%0/2
A
A= $self->Server
Aresult
11
00
336 0 ▶ my $port = $self->Port || $self->Port( $self->Ssl ? "993" : "143" );
Branch: 1 branch
BranchTrueFalseTotal
$self->Ssl ? : 0 0 0
Condition0%0/3
$self->Port || $self->Port($self->Ssl ? '993' : '143')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->Port || $self->Port($self->Ssl ? '993' : '143')
$self->Port $self->Port($self->Ssl ? '993' : '143')
Truth table0%0/3
A || B
A= $self->PortB= $self->Port($self->Ssl ? '993' : '143')
ABresult
1X1
011
000
337 0 my ( $ioclass, $sock );
338  
339 0 ▶ if ( File::Spec->file_name_is_absolute($server) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ('File::Spec'->file_name_is_absolute($server)) { } 0 0 0
340 0 $ioclass = $self->_load_module("UNIX");
341 0 unshift( @sockargs, Peer => $server );
342 }
343 else {
344 0 unshift(
345 @sockargs,
346 PeerAddr => $server,
347 PeerPort => $port,
348 Proto => "tcp",
349 );
350  
351 # pass SSL args if requested; default to IO::Socket::(IP|INET)
352 0 ▶ if ( $self->Ssl ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Ssl) { } 0 0 0
353 0 $ioclass = $self->_load_module("SSL");
354 0 ▶ push( @sockargs, @{ $self->Ssl } ) if ref $self->Ssl eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->Ssl eq "ARRAY" 0 0 0
355 }
356 else {
357 0 $ioclass = $self->_load_module("IP");
358 0 ▶ $ioclass = $self->_load_module("INET") unless $ioclass;
Branch: 1 branch
BranchTrueFalseTotal
unless $ioclass 0 0 0
359 }
360 }
361  
362 0 ▶ if ($ioclass) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ioclass) 0 0 0
363 0 $self->_debug("Connecting with $ioclass @sockargs");
364 0 $sock = $ioclass->new(@sockargs);
365 }
366  
367 0 ▶ if ($sock) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sock) { } 0 0 0
368 0 ▶ $self->_debug( "Connected to $server" . ( $! ? " errno($!)" : "" ) );
Branch: 1 branch
BranchTrueFalseTotal
$! ? : 0 0 0
369 0 return $self->Socket($sock);
370 }
371 else {
372 0 my $lasterr = $self->LastError;
373 0 ▶ if ( !$lasterr and $self->Ssl and $ioclass ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $lasterr and $self->Ssl and $ioclass) 0 0 0
Condition0%0/6
not $lasterr and $self->Ssl and $ioclass
!ll&&!rl&&r
000
not $lasterr and $self->Ssl
!ll&&!rl&&r
000
MC/DC0%0/3
not $lasterr and $self->Ssl and $ioclass
not $lasterr $self->Ssl $ioclass
Truth table0%0/4
not(A) and B and C
A= not $lasterrB= $self->SslC= $ioclass
ABCresult
0XX0
10X0
1100
1111
374 0 $lasterr = $ioclass->errstr;
375 }
376 0 ▶ $lasterr ||= "";
Condition0%0/2
$lasterr ||= ""
l!l
00
MC/DC0%0/1
$lasterr ||= ""
$lasterr
Truth table0%0/2
A
A= $lasterr
Aresult
11
00
377 0 $self->LastError("Unable to connect to $server: $lasterr");
378 0 return undef;
379 }
380 }
381  
382 0 ▶sub RawSocket(;$) {
Subroutine RawSocket: not called CC=2 SCAR=17.9
Pod documented
383 0 my ( $self, $sock ) = @_;
384 defined $sock
385 0 ▶ or return $self->{Socket};
Branch: 1 branch
BranchTrueFalseTotal
defined $sock or return $self->{"Socket"} 0 0 0
386  
387 0 $self->{Socket} = $sock;
388 0 $self->{_select} = IO::Select->new($sock);
389  
390 0 delete $self->{_fcntl};
391 0 $self->Fast_io( $self->Fast_io );
392  
393 0 return $sock;
394 }
395  
396 0 ▶sub Socket($) {
Subroutine Socket: not called CC=12 SCAR=50.5
Pod documented
397 0 my ( $self, $sock ) = @_;
398 defined $sock
399 0 ▶ or return $self->{Socket};
Branch: 1 branch
BranchTrueFalseTotal
defined $sock or return $self->{"Socket"} 0 0 0
400  
401 0 $self->RawSocket($sock);
402 0 $self->State(Connected);
403  
404 0 ▶ setsockopt( $sock, SOL_SOCKET, SO_KEEPALIVE, 1 ) if $self->Keepalive;
Branch: 1 branch
BranchTrueFalseTotal
if $self->Keepalive 0 0 0
405  
406 # LastError may be set by _read_line via _get_response
407 # look for "* (OK|BAD|NO|PREAUTH)"
408 0 ▶ my $code = $self->_get_response( '*', 'PREAUTH' ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $code = $self->_get_response("*", "PREAUTH") or return undef 0 0 0
409  
410 0 ▶ if ( $code eq 'BYE' || $code eq 'NO' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($code eq 'BYE' or $code eq 'NO') { } 0 0 0
elsif ($code eq 'PREAUTH') { } 0 0 0
Condition0%0/3
$code eq "BYE" or $code eq "NO"
l!l&&r!l&&!r
000
MC/DC0%0/2
$code eq "BYE" or $code eq "NO"
$code eq "BYE" $code eq "NO"
Truth table0%0/3
A or B
A= $code eq "BYE"B= $code eq "NO"
ABresult
1X1
011
000
411 0 $self->State(Unconnected);
412 0 return undef;
413 }
414 elsif ( $code eq 'PREAUTH' ) {
415 0 $self->State(Authenticated);
416 0 return $self;
417 }
418  
419 0 ▶ if ( $self->Starttls ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Starttls) 0 0 0
420 0 ▶ $self->starttls or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->starttls or return undef 0 0 0
421 }
422  
423 0 ▶ if ( defined $self->User && defined $self->Password ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->User and defined $self->Password) 0 0 0
Condition0%0/3
defined $self->User and defined $self->Password
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->User and defined $self->Password
defined $self->User defined $self->Password
Truth table0%0/3
A and B
A= defined $self->UserB= defined $self->Password
ABresult
0X0
100
111
424 0 ▶ $self->login or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->login or return undef 0 0 0
425 }
426  
427 0 return $self->{Socket};
428 }
429  
430 # RFC2595 section 3.1
431 0 ▶sub starttls {
Subroutine starttls: not called CC=6 SCAR=37.4
Pod documented
432 0 my ($self) = @_;
433  
434 # BUG? RFC requirement checks commented out for now...
435 #if ( $self->IsUnconnected or $self->IsAuthenticated ) {
436 # $self->LastError("NO must be connected but not authenticated");
437 # return undef;
438 #}
439  
440 # BUG? strict check on capability commented out for now...
441 #return undef unless $self->has_capability("STARTTLS");
442  
443 0 ▶ $self->_imap_command("STARTTLS") or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command("STARTTLS") or return undef 0 0 0
444  
445 # MUST discard cached capability info; should re-issue capability command
446 0 delete $self->{CAPABILITY};
447  
448 0 ▶ my $ioclass = $self->_load_module("SSL") or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $ioclass = $self->_load_module("SSL") or return undef 0 0 0
449 0 my $sock = $self->RawSocket;
450 0 my $blocking = $sock->blocking;
451  
452 # BUG: force blocking for now
453 0 $sock->blocking(1);
454  
455 # give caller control of args to start_SSL if desired
456 my @sslargs =
457 ( $self->Starttls and ref( $self->Starttls ) eq "ARRAY" )
458 0 ▶ ? ( @{ $self->Starttls } )
Branch: 1 branch
BranchTrueFalseTotal
$self->Starttls && ref $self->Starttls eq 'ARRAY' ? : 0 0 0
Condition0%0/3
$self->Starttls and ref $self->Starttls eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->Starttls and ref $self->Starttls eq "ARRAY"
$self->Starttls ref $self->Starttls eq "ARRAY"
Truth table0%0/3
A and B
A= $self->StarttlsB= ref $self->Starttls eq "ARRAY"
ABresult
0X0
100
111
459 : ( Timeout => 30 );
460  
461 0 ▶ unless ( $ioclass->start_SSL( $sock, @sslargs ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ioclass->start_SSL($sock, @sslargs)) 0 0 0
462 0 $self->LastError( "Unable to start TLS: " . $ioclass->errstr );
463 0 return undef;
464 }
465  
466 # return blocking to previous setting
467 0 $sock->blocking($blocking);
468  
469 0 return $self;
470 }
471  
472 # RFC4978 COMPRESS
473 0 ▶sub compress {
Subroutine compress: not called CC=7 SCAR=40.3
Pod documented
474 0 my ($self) = @_;
475  
476 # BUG? strict check on capability commented out for now...
477 #my $can = $self->has_capability("COMPRESS")
478 #return undef unless $can and $can eq "DEFLATE";
479  
480 0 ▶ $self->_imap_command("COMPRESS DEFLATE") or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command("COMPRESS DEFLATE") or return undef 0 0 0
481  
482 0 ▶ my $zcl = $self->_load_module("Compress-Zlib") or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $zcl = $self->_load_module("Compress-Zlib") or return undef 0 0 0
483  
484 # give caller control of args if desired
485 0 ▶ $self->Compress(
Branch: 1 branch
BranchTrueFalseTotal
unless $self->Compress and ref $self->Compress eq "ARRAY" 0 0 0
Condition0%0/3
$self->Compress and ref $self->Compress eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->Compress and ref $self->Compress eq "ARRAY"
$self->Compress ref $self->Compress eq "ARRAY"
Truth table0%0/3
A and B
A= $self->CompressB= ref $self->Compress eq "ARRAY"
ABresult
0X0
100
111
486 [
487 -WindowBits => -$zcl->MAX_WBITS(),
488 -Level => $zcl->Z_BEST_SPEED()
489 ]
490 ) unless ( $self->Compress and ref( $self->Compress ) eq "ARRAY" );
491  
492 0 my ( $rc, $do, $io );
493  
494 0 ( $do, $rc ) = Compress::Zlib::deflateInit( @{ $self->Compress } );
495 0 ▶ unless ( $rc == $zcl->Z_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rc == $zcl->Z_OK) 0 0 0
496 0 $self->LastError("deflateInit failed (rc=$rc)");
497 0 return undef;
498 }
499  
500 0 ( $io, $rc ) =
501 Compress::Zlib::inflateInit( -WindowBits => -$zcl->MAX_WBITS() );
502 0 ▶ unless ( $rc == $zcl->Z_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rc == $zcl->Z_OK) 0 0 0
503 0 $self->LastError("inflateInit failed (rc=$rc)");
504 0 return undef;
505 }
506  
507 0 ▶ $self->{Prewritemethod} = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
508 0 my ( $self, $string ) = @_;
509  
510 0 my ( $rc, $out1, $out2 );
511 0 ( $out1, $rc ) = $do->deflate($string);
512 0 ▶ ( $out2, $rc ) = $do->flush( $zcl->Z_PARTIAL_FLUSH() )
Branch: 1 branch
BranchTrueFalseTotal
unless $rc != $zcl->Z_OK 0 0 0
513 unless ( $rc != $zcl->Z_OK );
514  
515 0 ▶ unless ( $rc == $zcl->Z_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rc == $zcl->Z_OK) 0 0 0
516 0 $self->LastError("deflate/flush failed (rc=$rc)");
517 0 return undef;
518 }
519  
520 0 return $out1 . $out2;
521 0 };
522  
523 # need to retain some state for Readmoremethod/Readmethod calls
524 0 my ( $Zbuf, $Ibuf ) = ( "", "" );
525  
526 0 ▶ $self->{Readmoremethod} = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
527 0 my $self = shift;
528 0 ▶ return 1 if ( length($Zbuf) || length($Ibuf) );
Branch: 1 branch
BranchTrueFalseTotal
if length $Zbuf or length $Ibuf 0 0 0
Condition0%0/3
length $Zbuf or length $Ibuf
l!l&&r!l&&!r
000
MC/DC0%0/2
length $Zbuf or length $Ibuf
length $Zbuf length $Ibuf
Truth table0%0/3
A or B
A= length $ZbufB= length $Ibuf
ABresult
1X1
011
000
529 0 $self->__read_more(@_);
530 0 };
531  
532 0 ▶ $self->{Readmethod} = sub {
Subroutine __ANON__: not called CC=9 SCAR=45.0
533 0 my ( $self, $fh, $buf, $len, $off ) = @_;
534  
535 # get more data, but empty $Ibuf first if any data is left
536 0 my ( $lz, $li ) = ( length $Zbuf, length $Ibuf );
537 0 ▶ if ( $lz || !$li ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lz or not $li) 0 0 0
Condition0%0/3
$lz or not $li
l!l&&r!l&&!r
000
MC/DC0%0/2
$lz or not $li
$lz not $li
Truth table0%0/3
A or not(B)
A= $lzB= not $li
ABresult
1X1
011
000
538 0 ▶ my $ret = sysread( $fh, $Zbuf, $len || 4096, length $Zbuf );
Condition0%0/2
$len || 4096
l!l
00
MC/DC0%0/1
$len || 4096
$len
Truth table0%0/2
A
A= $len
Aresult
11
00
539 0 $lz = length $Zbuf;
540 0 ▶ return $ret if ( !$ret && !$lz ); # $ret is undef or 0
Branch: 1 branch
BranchTrueFalseTotal
unless $ret or $lz 0 0 0
Condition0%0/3
$ret or $lz
l!l&&r!l&&!r
000
MC/DC0%0/2
$ret or $lz
$ret $lz
Truth table0%0/3
A or B
A= $retB= $lz
ABresult
1X1
011
000
541 }
542  
543 # accumulate inflated data in $Ibuf
544 0 ▶ if ($lz) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lz) 0 0 0
545 0 my ( $tbuf, $rc ) = $io->inflate( \$Zbuf );
546 0 ▶ unless ( $rc == $zcl->Z_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rc == $zcl->Z_OK) 0 0 0
547 0 $self->LastError("inflate failed (rc=$rc)");
548 0 return undef;
549 }
550 0 $Ibuf .= $tbuf;
551 0 $li = length $Ibuf;
552 }
553  
554 0 ▶ if ( !$li ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($li) 0 0 0
555 # note: faking EAGAIN here is only safe with level-triggered
556 # I/O readiness notifications (select, poll). Refactoring
557 # callers will be needed in the unlikely case somebody wants
558 # to use edge-triggered notifications (EV_CLEAR, EPOLLET).
559 0 $! = EAGAIN;
560 0 return undef;
561 }
562  
563 # pull desired length of data from $Ibuf
564 0 my $tbuf = substr( $Ibuf, 0, $len );
565 0 substr( $Ibuf, 0, $len ) = "";
566 0 substr( $$buf, $off ) = $tbuf;
567  
568 0 return length $tbuf;
569 0 };
570  
571 0 return $self;
572 }
573  
574 0 ▶sub login {
Subroutine login: not called CC=12 SCAR=50.5
Pod documented
575 0 my $self = shift;
576 0 my $auth = $self->Authmechanism;
577  
578 0 ▶ if ( $auth && $auth ne 'LOGIN' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($auth and $auth ne 'LOGIN') { } 0 0 0
Condition0%0/3
$auth and $auth ne "LOGIN"
!ll&&!rl&&r
000
MC/DC0%0/2
$auth and $auth ne "LOGIN"
$auth $auth ne "LOGIN"
Truth table0%0/3
A and B
A= $authB= $auth ne "LOGIN"
ABresult
0X0
100
111
579 0 ▶ $self->authenticate( $auth, $self->Authcallback )
Branch: 1 branch
BranchTrueFalseTotal
$self->authenticate($auth, $self->Authcallback) or return undef 0 0 0
580 or return undef;
581 }
582 else {
583 0 my $user = $self->User;
584 0 my $passwd = $self->Password;
585  
586 0 ▶ return undef unless ( defined($passwd) and defined($user) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $passwd and defined $user 0 0 0
Condition0%0/3
defined $passwd and defined $user
!ll&&!rl&&r
000
MC/DC0%0/2
defined $passwd and defined $user
defined $passwd defined $user
Truth table0%0/3
A and B
A= defined $passwdB= defined $user
ABresult
0X0
100
111
587  
588 # if user is passed as a literal:
589 # 1. send passwd as a literal
590 # 2. empty literal passwd are sent as an blank line ($CRLF)
591 0 $user = $self->Quote($user);
592 0 ▶ if ( $user =~ /^{/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user =~ /^{/) { } 0 0 0
593 0 ▶ my $nopasswd = ( $passwd eq "" ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$passwd eq '' ? : 0 0 0
594 0 $passwd = $self->Quote( $passwd, 1 ); # force literal
595 0 ▶ $passwd .= $CRLF if ($nopasswd); # blank line
Branch: 1 branch
BranchTrueFalseTotal
if $nopasswd 0 0 0
596 }
597 else {
598 0 $passwd = $self->Quote($passwd);
599 }
600  
601 0 ▶ $self->_imap_command("LOGIN $user $passwd")
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command("LOGIN $user $passwd") or return undef 0 0 0
602 or return undef;
603 }
604  
605 0 $self->State(Authenticated);
606 0 ▶ if ( $self->Compress ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Compress) 0 0 0
607 0 ▶ $self->compress or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->compress or return undef 0 0 0
608 }
609 0 return $self;
610 }
611  
612 0 ▶sub noop {
Subroutine noop: not called CC=2 SCAR=17.9
Pod documented
613 0 my ($self) = @_;
614 0 ▶ $self->_imap_command("NOOP") ? $self->Results : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command('NOOP') ? : 0 0 0
615 }
616  
617 0 ▶sub proxyauth {
Subroutine proxyauth: not called CC=2 SCAR=17.9
Pod documented
618 0 my ( $self, $user ) = @_;
619 0 $user = $self->Quote($user);
620 0 ▶ $self->_imap_command("PROXYAUTH $user") ? $self->Results : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command("PROXYAUTH $user") ? : 0 0 0
621 }
622  
623 0 ▶sub separator {
Subroutine separator: not called CC=9 SCAR=45.0
Pod documented
624 0 my ( $self, $target ) = @_;
625 0 ▶ unless ( defined $target ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $target) 0 0 0
626  
627 # separator is namespace's 1st thing's 1st thing's 2nd thing:
628 0 ▶ my $ns = $self->namespace or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $ns = $self->namespace or return undef 0 0 0
629 0 ▶ if ($ns) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ns) 0 0 0
630 0 my $sep = $ns->[0][0][1];
631 0 ▶ return $sep if $sep;
Branch: 1 branch
BranchTrueFalseTotal
if $sep 0 0 0
632 }
633 0 $target = '';
634 }
635  
636 return $self->{separators}{$target}
637 0 ▶ if exists $self->{separators}{$target};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"separators"}{$target} 0 0 0
638  
639 0 ▶ my $list = $self->list( undef, $target ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $list = $self->list(undef, $target) or return undef 0 0 0
640  
641 0 foreach my $line (@$list) {
642 0 my $rec = $self->_list_or_lsub_response_parse($line);
643 0 ▶ next unless defined $rec->{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rec->{"name"} 0 0 0
644 0 $self->{separators}{ $rec->{name} } = $rec->{delim};
645 }
646 0 return $self->{separators}{$target};
647 }
648  
649 # BUG? caller gets empty list even if Error
650 # - returning an array with a single undef value seems even worse though
651 0 ▶sub sort {
Subroutine sort: not called CC=6 SCAR=37.4
Pod documented
652 0 my ( $self, $crit, @a ) = @_;
653  
654 0 ▶ $crit =~ /^\(.*\)$/ # wrap criteria in parens
Branch: 1 branch
BranchTrueFalseTotal
$crit =~ /^\(.*\)$/ or $crit = "($crit)" 0 0 0
655 or $crit = "($crit)";
656  
657 0 my @hits;
658 0 ▶ if ( $self->_imap_uid_command( SORT => $crit, @a ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_imap_uid_command("SORT", $crit, @a)) 0 0 0
659 0 my @results = $self->History;
660 0 foreach (@results) {
661 0 chomp;
662 0 s/$CR$//;
663 0 ▶ s/^\*\s+SORT\s+// or next;
Branch: 1 branch
BranchTrueFalseTotal
s/^\*\s+SORT\s+// or next 0 0 0
664 0 push @hits, grep /\d/, split;
665 }
666 }
667 0 ▶ return wantarray ? @hits : \@hits;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
668 }
669  
670 0 ▶sub _list_or_lsub {
Subroutine _list_or_lsub: not called CC=8 SCAR=42.8
671 0 my ( $self, $cmd, $reference, $target ) = @_;
672 0 ▶ defined $reference or $reference = '';
Branch: 1 branch
BranchTrueFalseTotal
defined $reference or $reference = "" 0 0 0
673 0 ▶ defined $target or $target = '*';
Branch: 1 branch
BranchTrueFalseTotal
defined $target or $target = "*" 0 0 0
674 0 ▶ length $target or $target = '""';
Branch: 1 branch
BranchTrueFalseTotal
length $target or $target = "\"\"" 0 0 0
675  
676 0 ▶ $target eq '*' || $target eq '""'
Branch: 1 branch
BranchTrueFalseTotal
$target eq "*" or $target eq "\"\"" or $target = $self->Quote($target) 0 0 0
Condition0%0/3
$target eq "*" or $target eq "\"\""
l!l&&r!l&&!r
000
MC/DC0%0/2
$target eq "*" or $target eq "\"\""
$target eq "*" $target eq "\"\""
Truth table0%0/3
A or B
A= $target eq "*"B= $target eq "\"\""
ABresult
1X1
011
000
677 or $target = $self->Quote($target);
678  
679 0 ▶ $self->_imap_command(qq($cmd "$reference" $target))
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command(qq[$cmd "$reference" $target]) or return undef 0 0 0
680 or return undef;
681  
682 0 ▶ return wantarray ? $self->Escaped_history : $self->Escaped_results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
683 }
684  
685 0 ▶sub list { shift->_list_or_lsub( "LIST", @_ ) }
Subroutine list: not called CC=1 SCAR=6.9
Pod documented
686 0 ▶sub lsub { shift->_list_or_lsub( "LSUB", @_ ) }
Subroutine lsub: not called CC=1 SCAR=6.9
Pod documented
687  
688 # deprecated 3.34
689 0 ▶sub xlist {
Subroutine xlist: not called CC=2 SCAR=17.9
Pod undocumented
690 0 my ($self) = @_;
691 0 ▶ return undef unless $self->has_capability("XLIST");
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_capability("XLIST") 0 0 0
692 0 shift->_list_or_lsub( "XLIST", @_ );
693 }
694  
695 0 ▶sub _folders_or_subscribed {
Subroutine _folders_or_subscribed: not called CC=14 SCAR=53.5
696 0 my ( $self, $method, $what ) = @_;
697 0 my @folders;
698  
699 # do BLOCK allowing use of "last if undef/error" and avoiding dup code
700 0 do {
701 {
702 0 my @list;
703 0 ▶ if ($what) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what) { } 0 0 0
704 0 ▶ my $sep = $self->separator($what) || $self->separator(undef);
Condition0%0/3
$self->separator($what) || $self->separator(undef)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->separator($what) || $self->separator(undef)
$self->separator($what) $self->separator(undef)
Truth table0%0/3
A || B
A= $self->separator($what)B= $self->separator(undef)
ABresult
1X1
011
000
705 0 ▶ last unless defined $sep;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sep 0 0 0
706  
707 0 ▶ my $whatsub = $what =~ m/\Q${sep}\E$/ ? "$what*" : "$what$sep*";
Branch: 1 branch
BranchTrueFalseTotal
$what =~ /\Q$sep\E$/ ? : 0 0 0
708  
709 0 ▶ my $tref = $self->$method( undef, $whatsub ) or last;
Branch: 1 branch
BranchTrueFalseTotal
my $tref = $self->$method(undef, $whatsub) or last 0 0 0
710 0 shift @$tref; # remove command
711 0 push @list, @$tref;
712  
713 # BUG?: this behavior has been around since 2.x, why?
714 0 my $cansel = $self->selectable($what);
715 0 ▶ last unless defined $cansel;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cansel 0 0 0
716 0 ▶ if ($cansel) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cansel) 0 0 0
717 0 ▶ $tref = $self->$method( undef, $what ) or last;
Branch: 1 branch
BranchTrueFalseTotal
$tref = $self->$method(undef, $what) or last 0 0 0
718 0 shift @$tref; # remove command
719 0 push @list, @$tref;
720 }
721 }
722 else {
723 0 ▶ my $tref = $self->$method( undef, undef ) or last;
Branch: 1 branch
BranchTrueFalseTotal
my $tref = $self->$method(undef, undef) or last 0 0 0
724 0 shift @$tref; # remove command
725 0 push @list, @$tref;
726 }
727  
728 0 foreach my $resp (@list) {
729 0 my $rec = $self->_list_or_lsub_response_parse($resp);
730 0 ▶ next unless defined $rec->{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rec->{"name"} 0 0 0
731 0 ▶ next if first { lc($_) eq '\noselect' } @{ $rec->{attrs} };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &first(sub { lc $_ eq "\\noselect"; } , @{$$rec{"attrs"};}) 0 0 0
732 0 push @folders, $rec;
733 }
734 }
735 };
736  
737 0 my @clean = _remove_doubles @folders;
738 0 ▶ return wantarray ? @clean : \@clean;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
739 }
740  
741 0 ▶sub folders {
Subroutine folders: not called CC=2 SCAR=17.9
Pod documented
742 0 my ( $self, $what ) = @_;
743  
744 my @folders =
745 0 map( $_->{name}, $self->_folders_or_subscribed( "list", $what ) );
746 0 ▶ return wantarray ? @folders : \@folders;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
747 }
748  
749 0 ▶sub folders_hash {
Subroutine folders_hash: not called CC=2 SCAR=17.9
Pod documented
750 0 my ( $self, $what ) = @_;
751  
752 0 my @folders_hash = $self->_folders_or_subscribed( "list", $what );
753 0 ▶ return wantarray ? @folders_hash : \@folders_hash;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
754 }
755  
756 # deprecated 3.34
757 0 ▶sub xlist_folders {
Subroutine xlist_folders: not called CC=7 SCAR=40.3
Pod documented
758 0 my ($self) = @_;
759 0 my $xlist = $self->xlist;
760 0 ▶ return undef unless defined $xlist;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $xlist 0 0 0
761  
762 0 my %xlist;
763 0 my $xlist_re = qr/\A\\(Inbox|AllMail|Trash|Drafts|Sent|Spam|Starred)\Z/;
764  
765 0 for my $resp (@$xlist) {
766 0 my $rec = $self->_list_or_lsub_response_parse($resp);
767 0 ▶ next unless defined $rec->{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rec->{"name"} 0 0 0
768 0 for my $attr ( @{ $rec->{attrs} } ) {
769 0 ▶ $xlist{$1} = $rec->{name} if ( $attr =~ $xlist_re );
Branch: 1 branch
BranchTrueFalseTotal
if $attr =~ /$xlist_re/ 0 0 0
770 }
771 }
772  
773 0 ▶ return wantarray ? %xlist : \%xlist;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
774 }
775  
776 0 ▶sub subscribed {
Subroutine subscribed: not called CC=2 SCAR=17.9
Pod documented
777 0 my ( $self, $what ) = @_;
778 my @folders =
779 0 map( $_->{name}, $self->_folders_or_subscribed( "lsub", $what ) );
780 0 ▶ return wantarray ? @folders : \@folders;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
781 }
782  
783 0 ▶sub deleteacl {
Subroutine deleteacl: not called CC=3 SCAR=24.8
Pod documented
784 0 my ( $self, $target, $user ) = @_;
785 0 $target = $self->Quote($target);
786 0 $user = $self->Quote($user);
787  
788 0 ▶ $self->_imap_command(qq(DELETEACL $target $user))
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command("DELETEACL $target $user") or return undef 0 0 0
789 or return undef;
790  
791 0 ▶ return wantarray ? $self->History : $self->Results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
792 }
793  
794 0 ▶sub setacl {
Subroutine setacl: not called CC=5 SCAR=34.0
Pod documented
795 0 my ( $self, $target, $user, $acl ) = @_;
796 0 ▶ $target ||= $self->Folder;
Condition0%0/3
$target ||= $self->Folder
l!l&&r!l&&!r
000
MC/DC0%0/2
$target ||= $self->Folder
$target $self->Folder
Truth table0%0/3
A ||= B
A= $targetB= $self->Folder
ABresult
1X1
011
000
797 0 $target = $self->Quote($target);
798  
799 0 ▶ $user ||= $self->User;
Condition0%0/3
$user ||= $self->User
l!l&&r!l&&!r
000
MC/DC0%0/2
$user ||= $self->User
$user $self->User
Truth table0%0/3
A ||= B
A= $userB= $self->User
ABresult
1X1
011
000
800 0 $user = $self->Quote($user);
801 0 $acl = $self->Quote($acl);
802  
803 0 ▶ $self->_imap_command(qq(SETACL $target $user $acl))
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command("SETACL $target $user $acl") or return undef 0 0 0
804 or return undef;
805  
806 0 ▶ return wantarray ? $self->History : $self->Results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
807 }
808  
809 0 ▶sub getacl {
Subroutine getacl: not called CC=10 SCAR=47.0
Pod documented
810 0 my ( $self, $target ) = @_;
811 0 ▶ defined $target or $target = $self->Folder;
Branch: 1 branch
BranchTrueFalseTotal
defined $target or $target = $self->Folder 0 0 0
812 0 my $mtarget = $self->Quote($target);
813 0 ▶ $self->_imap_command(qq(GETACL $mtarget))
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command("GETACL $mtarget") or return undef 0 0 0
814 or return undef;
815  
816 0 my @history = $self->History;
817 0 my $hash;
818 0 ▶ for ( my $x = 0 ; $x < @history ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < @history) 0 0 0
819 0 ▶ next if $history[$x] !~ /^\* ACL/;
Branch: 1 branch
BranchTrueFalseTotal
unless $history[$x] =~ /^\* ACL/ 0 0 0
820  
821 0 ▶ my $perm =
Branch: 1 branch
BranchTrueFalseTotal
$history[$x] =~ /^\* ACL $/ ? : 0 0 0
822 $history[$x] =~ /^\* ACL $/
823 ? $history[ ++$x ] . $history[ ++$x ]
824 : $history[$x];
825  
826 0 $perm =~ s/\s?$CRLF$//o;
827 0 ▶ until ( $perm =~ /\Q$target\E"?$/ || !$perm ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($perm =~ /\Q$target\E"?$/ or not $perm) 0 0 0
Condition0%0/3
$perm =~ /\Q$target\E"?$/ or not $perm
l!l&&r!l&&!r
000
MC/DC0%0/2
$perm =~ /\Q$target\E"?$/ or not $perm
$perm =~ /\Q$target\E"?$/ not $perm
Truth table0%0/3
A or not(B)
A= $perm =~ /\Q$target\E"?$/B= not $perm
ABresult
1X1
011
000
828 0 ▶ $perm =~ s/\s([^\s]+)\s?$// or last;
Branch: 1 branch
BranchTrueFalseTotal
$perm =~ s/\s([^\s]+)\s?$// or last 0 0 0
829 0 my $p = $1;
830 0 ▶ $perm =~ s/\s([^\s]+)\s?$// or last;
Branch: 1 branch
BranchTrueFalseTotal
$perm =~ s/\s([^\s]+)\s?$// or last 0 0 0
831 0 my $u = $1;
832 0 $hash->{$u} = $p;
833 0 $self->_debug("Permissions: $u => $p");
834 }
835 }
836 0 return $hash;
837 }
838  
839 0 ▶sub listrights {
Subroutine listrights: not called CC=5 SCAR=34.0
Pod documented
840 0 my ( $self, $target, $user ) = @_;
841 0 ▶ $target ||= $self->Folder;
Condition0%0/3
$target ||= $self->Folder
l!l&&r!l&&!r
000
MC/DC0%0/2
$target ||= $self->Folder
$target $self->Folder
Truth table0%0/3
A ||= B
A= $targetB= $self->Folder
ABresult
1X1
011
000
842 0 $target = $self->Quote($target);
843  
844 0 ▶ $user ||= $self->User;
Condition0%0/3
$user ||= $self->User
l!l&&r!l&&!r
000
MC/DC0%0/2
$user ||= $self->User
$user $self->User
Truth table0%0/3
A ||= B
A= $userB= $self->User
ABresult
1X1
011
000
845 0 $user = $self->Quote($user);
846  
847 0 ▶ $self->_imap_command(qq(LISTRIGHTS $target $user))
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command("LISTRIGHTS $target $user") or return undef 0 0 0
848 or return undef;
849  
850 0 ▶ my $resp = first { /^\* LISTRIGHTS/ } $self->History;
Subroutine __ANON__: not called CC=1 SCAR=6.9
851 0 my @rights = split /\s/, $resp;
852 0 my $rights = join '', @rights[ 4 .. $#rights ];
853 0 $rights =~ s/"//g;
854 0 ▶ return wantarray ? split( //, $rights ) : $rights;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
855 }
856  
857 0 ▶sub select {
Subroutine select: not called CC=4 SCAR=30.0
Pod documented
858 0 my ( $self, $target ) = @_;
859 0 ▶ defined $target or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $target or return undef 0 0 0
860  
861 0 my $qqtarget = $self->Quote($target);
862 0 my $old = $self->Folder;
863  
864 0 ▶ $self->_imap_command("SELECT $qqtarget")
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command("SELECT $qqtarget") or return undef 0 0 0
865 or return undef;
866  
867 0 $self->State(Selected);
868 0 $self->Folder($target);
869 0 ▶ return $old || $self; # ??$self??
Condition0%0/3
$old || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$old || $self
$old $self
Truth table0%0/3
A || B
A= $oldB= $self
ABresult
1X1
011
000
870 }
871  
872 0 ▶sub message_string {
Subroutine message_string: not called CC=7 SCAR=40.3
Pod documented
873 0 my ( $self, $msg ) = @_;
874  
875 0 ▶ return undef unless defined $self->imap4rev1;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->imap4rev1 0 0 0
876 0 ▶ my $peek = $self->Peek ? '.PEEK' : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->Peek ? : 0 0 0
877 0 ▶ my $cmd = $self->imap4rev1 ? "BODY$peek\[]" : "RFC822$peek";
Branch: 1 branch
BranchTrueFalseTotal
$self->imap4rev1 ? : 0 0 0
878  
879 0 my $string;
880 0 $self->message_to_file( \$string, $msg );
881  
882 0 ▶ unless ( $self->Ignoresizeerrors ) { # Check size with expected size
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->Ignoresizeerrors) 0 0 0
883 0 my $expected_size = $self->size($msg);
884 0 ▶ return undef unless defined $expected_size;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expected_size 0 0 0
885  
886 # RFC822.SIZE may be wrong, see RFC2683 3.4.5 "RFC822.SIZE"
887 0 ▶ if ( length($string) != $expected_size ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $string != $expected_size) 0 0 0
888 0 $self->LastError( "message_string() "
889 . "expected $expected_size bytes but received "
890 . length($string)
891 . " you may need the IgnoreSizeErrors option" );
892 0 return undef;
893 }
894 }
895  
896 0 return $string;
897 }
898  
899 0 ▶sub bodypart_string {
Subroutine bodypart_string: not called CC=7 SCAR=40.3
Pod documented
900 0 my ( $self, $msg, $partno, $bytes, $offset ) = @_;
901  
902 0 ▶ unless ( $self->imap4rev1 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->imap4rev1) 0 0 0
903 0 ▶ $self->LastError( "Unable to get body part; server "
Branch: 1 branch
BranchTrueFalseTotal
unless $self->LastError 0 0 0
904 . $self->Server
905 . " does not support IMAP4REV1" )
906 unless $self->LastError;
907 0 return undef;
908 }
909  
910 0 ▶ $offset ||= 0;
Condition0%0/2
$offset ||= 0
l!l
00
MC/DC0%0/1
$offset ||= 0
$offset
Truth table0%0/2
A
A= $offset
Aresult
11
00
911 0 ▶ my $cmd = "BODY"
Branch: 2 branches
BranchTrueFalseTotal
$self->Peek ? : 0 0 0
$bytes ? : 0 0 0
912 . ( $self->Peek ? '.PEEK' : '' )
913 . "[$partno]"
914 . ( $bytes ? "<$offset.$bytes>" : '' );
915  
916 0 ▶ $self->fetch( $msg, $cmd )
Branch: 1 branch
BranchTrueFalseTotal
$self->fetch($msg, $cmd) or return undef 0 0 0
917 or return undef;
918  
919 0 $self->_transaction_literals;
920 }
921  
922 # message_to_file( $self, $file, @msgs )
923 0 ▶sub message_to_file {
Subroutine message_to_file: not called CC=10 SCAR=47.0
Pod documented
924 0 my ( $self, $file, @msgs ) = @_;
925  
926 # $file can be a name or a scalar reference (for in memory file)
927 # avoid IO::File bug handling scalar refs in perl <= 5.8.8?
928 # - buggy: $fh = IO::File->new( $file, 'r' )
929 0 my $fh;
930 0 ▶ if ( ref $file and ref $file ne "SCALAR" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $file and ref $file ne 'SCALAR') { } 0 0 0
Condition0%0/3
ref $file and ref $file ne "SCALAR"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $file and ref $file ne "SCALAR"
ref $file ref $file ne "SCALAR"
Truth table0%0/3
A and B
A= ref $fileB= ref $file ne "SCALAR"
ABresult
0X0
100
111
931 0 $fh = $file;
932 }
933 else {
934 0 ▶ $$file = "" if ( ref $file eq "SCALAR" and !defined $$file );
Branch: 1 branch
BranchTrueFalseTotal
if ref $file eq "SCALAR" and not defined $$file 0 0 0
Condition0%0/3
ref $file eq "SCALAR" and not defined $$file
!ll&&!rl&&r
000
MC/DC0%0/2
ref $file eq "SCALAR" and not defined $$file
ref $file eq "SCALAR" not defined $$file
Truth table0%0/3
A and not(B)
A= ref $file eq "SCALAR"B= not defined $$file
ABresult
0X0
100
111
935 0 local ($!);
936 0 open( $fh, ">>", $file );
937 0 ▶ unless ( defined($fh) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fh) 0 0 0
938 0 $self->LastError("Unable to open file '$file': $!");
939 0 return undef;
940 }
941 }
942  
943 0 binmode($fh);
944  
945 0 ▶ unless (@msgs) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@msgs) 0 0 0
946 0 $self->LastError("message_to_file: NO messages specified!");
947 0 return undef;
948 }
949  
950 0 ▶ my $peek = $self->Peek ? '.PEEK' : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->Peek ? : 0 0 0
951 0 ▶ $peek = sprintf( $self->imap4rev1 ? "BODY%s\[]" : "RFC822%s", $peek );
Branch: 1 branch
BranchTrueFalseTotal
$self->imap4rev1 ? : 0 0 0
952  
953 0 my @args = ( join( ",", @msgs ), $peek );
954  
955 0 ▶ return $self->_imap_uid_command( { outref => $fh }, "FETCH" => @args )
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_uid_command({'outref', $fh}, 'FETCH', @args) ? : 0 0 0
956 ? $self
957 : undef;
958 }
959  
960 0 ▶sub message_uid {
Subroutine message_uid: not called CC=4 SCAR=30.0
Pod documented
961 0 my ( $self, $msg ) = @_;
962  
963 0 ▶ my $ref = $self->fetch( $msg, "UID" ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $ref = $self->fetch($msg, "UID") or return undef 0 0 0
964 0 foreach (@$ref) {
965 0 ▶ return $1 if m/\(UID\s+(\d+)\s*\)$CR?$/o;
Branch: 1 branch
BranchTrueFalseTotal
if /\(UID\s+(\d+)\s*\)$Mail::IMAPClient::CR?$/o 0 0 0
966 }
967 0 return undef;
968 }
969  
970 # cleaned up and simplified but see TODO in code...
971 0 ▶sub migrate {
Subroutine migrate: not called CC=19 SCAR=59.4
Pod documented
972 0 my ( $self, $peer, $msgs, $folder ) = @_;
973  
974 0 ▶ unless ( $peer and $peer->IsConnected ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($peer and $peer->IsConnected) 0 0 0
Condition0%0/3
$peer and $peer->IsConnected
!ll&&!rl&&r
000
MC/DC0%0/2
$peer and $peer->IsConnected
$peer $peer->IsConnected
Truth table0%0/3
A and B
A= $peerB= $peer->IsConnected
ABresult
0X0
100
111
975 0 ▶ $self->LastError( ( $peer ? "Invalid" : "Unconnected" )
Branch: 2 branches
BranchTrueFalseTotal
$peer ? : 0 0 0
$peer ? : 0 0 0
976 . " target "
977 . ref($self)
978 . " object in migrate()"
979 . ( $peer ? ( ": " . $peer->LastError ) : "" ) );
980 0 return undef;
981 }
982  
983 # sanity check to see if $self is same object as $peer
984 0 ▶ if ( $self eq $peer ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self eq $peer) 0 0 0
985 0 $self->LastError("dest must not be the same object as self");
986 0 return undef;
987 }
988  
989 0 ▶ $folder = $self->Folder unless ( defined $folder );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $folder 0 0 0
990 0 ▶ unless ($folder) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($folder) 0 0 0
991 0 $self->LastError("No folder selected on source mailbox.");
992 0 return undef;
993 }
994  
995 0 ▶ unless ( $peer->exists($folder) or $peer->create($folder) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($peer->exists($folder) or $peer->create($folder)) 0 0 0
Condition0%0/3
$peer->exists($folder) or $peer->create($folder)
l!l&&r!l&&!r
000
MC/DC0%0/2
$peer->exists($folder) or $peer->create($folder)
$peer->exists($folder) $peer->create($folder)
Truth table0%0/3
A or B
A= $peer->exists($folder)B= $peer->create($folder)
ABresult
1X1
011
000
996 0 $self->LastError( "Create folder '$folder' on target host failed: "
997 . $peer->LastError );
998 0 return undef;
999 }
1000  
1001 0 ▶ if ( !defined $msgs or uc($msgs) eq "ALL" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $msgs or uc $msgs eq "ALL") 0 0 0
Condition0%0/3
not defined $msgs or uc $msgs eq "ALL"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $msgs or uc $msgs eq "ALL"
not defined $msgs uc $msgs eq "ALL"
Truth table0%0/3
not(A) or B
A= not defined $msgsB= uc $msgs eq "ALL"
ABresult
1X1
011
000
1002 0 ▶ $msgs = $self->search("ALL") or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$msgs = $self->search("ALL") or return undef 0 0 0
1003 }
1004  
1005 # message size and (internal) date
1006 0 my @headers = qw(RFC822.SIZE INTERNALDATE FLAGS);
1007 0 my $range = $self->Range($msgs);
1008  
1009 0 $self->_debug("Messages to migrate from '$folder': $range");
1010  
1011 0 foreach my $mid ( $range->unfold ) {
1012  
1013 # fetch size internaldate and flags of original message
1014 # - TODO: add flags here...
1015 0 ▶ my $minfo = $self->fetch_hash( $mid, @headers )
Branch: 1 branch
BranchTrueFalseTotal
my $minfo = $self->fetch_hash($mid, @headers) or return undef 0 0 0
1016 or return undef;
1017  
1018 0 my ( $size, $date ) = @{ $minfo->{$mid} }{@headers};
1019 0 ▶ return undef unless ( defined $size and defined $date );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $size and defined $date 0 0 0
Condition0%0/3
defined $size and defined $date
!ll&&!rl&&r
000
MC/DC0%0/2
defined $size and defined $date
defined $size defined $date
Truth table0%0/3
A and B
A= defined $sizeB= defined $date
ABresult
0X0
100
111
1020  
1021 0 $self->_debug("Copy message $mid (sz=$size,dt=$date) from '$folder'");
1022  
1023 0 my @flags = grep !/\\Recent/i, $self->flags($mid);
1024 0 my $flags = join ' ', $peer->supported_flags(@flags);
1025  
1026 # TODO: - use File::Temp tempfile if $msg > bufferSize?
1027 # read message to $msg
1028 0 my $msg;
1029 0 ▶ $self->message_to_file( \$msg, $mid )
Branch: 1 branch
BranchTrueFalseTotal
$self->message_to_file(\$msg, $mid) or return undef 0 0 0
1030 or return undef;
1031  
1032 0 my $newid = $peer->append_file( $folder, \$msg, undef, $flags, $date );
1033  
1034 0 ▶ unless ( defined $newid ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $newid) 0 0 0
1035 0 $self->LastError(
1036 "Append to '$folder' on target failed: " . $peer->LastError );
1037 0 return undef;
1038 }
1039  
1040 0 $self->_debug("Copied UID $mid in '$folder' to target UID $newid");
1041 }
1042  
1043 0 return $self;
1044 }
1045  
1046 # Optimization of wait time between syswrite calls only runs if syscalls
1047 # run too fast and fill the buffer causing "EAGAIN: Resource Temp. Unavail"
1048 # errors. The premise is that $maxwrite will be approx. the same as the
1049 # smallest buffer between the sending and receiving side. Waiting time
1050 # between syscalls should ideally be exactly as long as it takes the
1051 # receiving side to empty that buffer, minus a little bit to prevent it
1052 # from emptying completely and wasting time in the select call.
1053  
1054 0 ▶sub _optimal_sleep($$$) {
Subroutine _optimal_sleep: not called CC=4 SCAR=30.0
1055 0 my ( $self, $maxwrite, $waittime, $last5writes ) = @_;
1056  
1057 0 push @$last5writes, $waittime;
1058 0 ▶ shift @$last5writes if @$last5writes > 5;
Branch: 1 branch
BranchTrueFalseTotal
if @$last5writes > 5 0 0 0
1059  
1060 0 my $bufferavail = ( sum @$last5writes ) / @$last5writes;
1061  
1062 0 ▶ if ( $bufferavail < .4 * $maxwrite ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($bufferavail < 0.4 * $maxwrite) { } 0 0 0
elsif ($bufferavail > 0.9 * $maxwrite) { } 0 0 0
1063  
1064 # Buffer is staying pretty full; we should increase the wait
1065 # period to reduce transmission overhead/number of packets sent
1066 0 $waittime *= 1.3;
1067 }
1068 elsif ( $bufferavail > .9 * $maxwrite ) {
1069  
1070 # Buffer is nearly or totally empty; we're wasting time in select
1071 # call that could be used to send data, so reduce the wait period
1072 0 $waittime *= .5;
1073 }
1074  
1075 0 CORE::select( undef, undef, undef, $waittime );
1076 0 $waittime;
1077 }
1078  
1079 2 ▶sub body_string {
Subroutine body_string: called CC=13 SCAR=27.4
Pod documented
1080 2 my ( $self, $msg ) = @_;
1081 2 ▶ my $ref =
Branch: 2 branches
BranchTrueFalseTotal
my $ref = $self->fetch($msg, 'BODY' . ($self->Peek ? ".PEEK" : "") . '[TEXT]') or return undef 2 0 2
$self->Peek ? : 0 2 2
1082 $self->fetch( $msg, "BODY" . ( $self->Peek ? ".PEEK" : "" ) . "[TEXT]" )
1083 or return undef;
1084  
1085 0 my $string = join '', map { $_->[DATA] }
1086 2 grep { $self->_is_literal($_) } @$ref;
1087  
1088 2 ▶ return $string
Branch: 1 branch
BranchTrueFalseTotal
if $string 0 2 2
1089 if $string;
1090  
1091 2 my $head;
1092 2 ▶ while ( $head = shift @$ref ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($head = shift @$ref) 4 0 4
1093 4 $self->_debug("body_string: head = '$head'");
1094  
1095 last
1096 4 ▶ if $head =~
Branch: 1 branch
BranchTrueFalseTotal
if $head =~ /(?:.*FETCH .*\(.*BODY\[TEXT\])|(?:^\d+ BAD )|(?:^\d NO )/i 2 2 4
1097 /(?:.*FETCH .*\(.*BODY\[TEXT\])|(?:^\d+ BAD )|(?:^\d NO )/i;
1098 }
1099  
1100 2 ▶ unless (@$ref) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$ref) 0 2 2
1101 0 $self->LastError(
1102 "Unable to parse server response from " . $self->LastIMAPCommand );
1103 0 return undef;
1104 }
1105  
1106 2 my $popped;
1107 2 ▶ $popped = pop @$ref
Branch: 1 branch
BranchTrueFalseTotal
($popped and $popped =~ /^\)$Mail::IMAPClient::CRLF$/o or not grep(/^\)$Mail::IMAPClient::CRLF$/o, @$ref)) or do { $popped = pop @$ref } 2 5 7
Condition83%5/6
$popped and $popped =~ /^\)$Mail::IMAPClient::CRLF$/o or not grep(/^\)$Mail::IMAPClient::CRLF$/o, @$ref)
l!l&&r!l&&!r
205
$popped and $popped =~ /^\)$Mail::IMAPClient::CRLF$/o
!ll&&!rl&&r
232
MC/DC66%2/3
$popped and $popped =~ /^\)$Mail::IMAPClient::CRLF$/o or not grep(/^\)$Mail::IMAPClient::CRLF$/o, @$ref)
$popped $popped =~ /^\)$Mail::IMAPClient::CRLF$/o not grep(/^\)$Mail::IMAPClient::CRLF$/o, @$ref)
Truth table60%3/5
A and B or not(C)
A= $poppedB= $popped =~ /^\)$Mail::IMAPClient::CRLF$/oC= not grep(/^\)$Mail::IMAPClient::CRLF$/o, @$ref)
ABCresult
11X1
0X11
1011
0X00
1000
1108 until ( $popped && $popped =~ /^\)$CRLF$/o )
1109 || !grep /^\)$CRLF$/o, @$ref;
1110  
1111 2 ▶ if ( $head =~ /BODY\[TEXT\]\s*$/i ) { # Next line is a literal
Branch: 1 branch
BranchTrueFalseTotal
if ($head =~ /BODY\[TEXT\]\s*$/i) 2 0 2
1112 2 ▶ $string .= shift @$ref while @$ref;
Branch: 1 branch
BranchTrueFalseTotal
@$ref and do { $string .= shift(@$ref) } 2 2 4
1113 2 ▶ $self->_debug("String is now $string")
Branch: 1 branch
BranchTrueFalseTotal
if $self->Debug 0 2 2
1114 if $self->Debug;
1115 }
1116  
1117 2 $string;
1118 }
1119  
1120 0 ▶sub examine {
Subroutine examine: not called CC=4 SCAR=30.0
Pod documented
1121 0 my ( $self, $target ) = @_;
1122 0 ▶ defined $target or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $target or return undef 0 0 0
1123  
1124 0 ▶ $self->_imap_command( 'EXAMINE ' . $self->Quote($target) )
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command('EXAMINE ' . $self->Quote($target)) or return undef 0 0 0
1125 or return undef;
1126  
1127 0 my $old = $self->Folder;
1128 0 $self->Folder($target);
1129 0 $self->State(Selected);
1130 0 ▶ $old || $self;
Branch: 1 branch
BranchTrueFalseTotal
$old or $self 0 0 0
1131 }
1132  
1133 0 ▶sub idle {
Subroutine idle: not called CC=2 SCAR=17.9
Pod documented
1134 0 my $self = shift;
1135 0 my $good = '+';
1136 0 my $count = $self->Count + 1;
1137 0 ▶ $self->_imap_command( "IDLE", $good ) ? $count : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command('IDLE', $good) ? : 0 0 0
1138 }
1139  
1140 0 ▶sub idle_data {
Subroutine idle_data: not called CC=11 SCAR=48.8
Pod documented
1141 0 my $self = shift;
1142 0 ▶ my $timeout = scalar(@_) ? shift : 0;
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ ? : 0 0 0
1143 0 my $socket = $self->Socket;
1144  
1145 # current index in Results array
1146 0 my $trans_c1 = $self->_next_index;
1147  
1148 # look for all untagged responses
1149 0 my ( $rc, $ret );
1150  
1151 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$ret > 0 and $self->IsConnected and do { do { $ret = $self->_read_more({"error_on_timeout", 0}, $socket, $timeout); $rc = $ret if not defined $rc or $ret < 0; if ($ret > 0) { $self->_get_response("*", qr/(?!BAD|BYE|NO)(?:\d+\s+\w+|\S+)/) or return undef; $timeout = 0; } } } 0 0 0
Condition0%0/3
$ret > 0 and $self->IsConnected
!ll&&!rl&&r
000
MC/DC0%0/2
$ret > 0 and $self->IsConnected
$ret > 0 $self->IsConnected
Truth table0%0/3
A and B
A= $ret > 0B= $self->IsConnected
ABresult
0X0
100
111
1152 0 $ret =
1153 $self->_read_more( { error_on_timeout => 0 }, $socket, $timeout );
1154  
1155 # set rc on first pass or on errors
1156 0 ▶ $rc = $ret if ( !defined($rc) or $ret < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $rc or $ret < 0 0 0 0
Condition0%0/3
not defined $rc or $ret < 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $rc or $ret < 0
not defined $rc $ret < 0
Truth table0%0/3
not(A) or B
A= not defined $rcB= $ret < 0
ABresult
1X1
011
000
1157  
1158 # not using /\S+/ because that can match 0 in "* 0 RECENT"
1159 # leading the library to act as if things failed
1160 0 ▶ if ( $ret > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret > 0) 0 0 0
1161 0 ▶ $self->_get_response( '*', qr/(?!BAD|BYE|NO)(?:\d+\s+\w+|\S+)/ )
Branch: 1 branch
BranchTrueFalseTotal
$self->_get_response("*", qr/(?!BAD|BYE|NO)(?:\d+\s+\w+|\S+)/) or return undef 0 0 0
1162 or return undef;
1163 0 $timeout = 0; # check for more data without blocking!
1164 }
1165 } while $ret > 0 and $self->IsConnected;
1166  
1167 # select returns -1 on errors
1168 0 ▶ return undef if $rc < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $rc < 0 0 0 0
1169  
1170 0 my $trans_c2 = $self->_next_index;
1171  
1172 # if current index in Results array has changed return data
1173 0 my @res;
1174 0 ▶ if ( $trans_c1 < $trans_c2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trans_c1 < $trans_c2) 0 0 0
1175 0 @res = $self->Results;
1176 0 @res = @res[ $trans_c1 .. ( $trans_c2 - 1 ) ];
1177 }
1178 0 ▶ return wantarray ? @res : \@res;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1179 }
1180  
1181 0 ▶sub done {
Subroutine done: not called CC=3 SCAR=24.8
Pod documented
1182 0 my $self = shift;
1183 0 ▶ my $count = shift || $self->Count;
Condition0%0/3
shift() || $self->Count
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->Count
shift() $self->Count
Truth table0%0/3
A || B
A= shift()B= $self->Count
ABresult
1X1
011
000
1184  
1185 # DONE looks like a tag when sent and not already in IDLE
1186 0 ▶ $self->_imap_command(
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command({"addtag", 0, "tag", qr/(?:$count|DONE)/, "doretry", 0}, "DONE") or return undef 0 0 0
1187 { addtag => 0, tag => qr/(?:$count|DONE)/, doretry => 0 }, "DONE" )
1188 or return undef;
1189 0 return $self->Results;
1190 }
1191  
1192 # tag_and_run( $self, $string, $good )
1193 0 ▶sub tag_and_run {
Subroutine tag_and_run: not called CC=2 SCAR=17.9
Pod documented
1194 0 my $self = shift;
1195 0 ▶ $self->_imap_command(@_) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command(@_) or return undef 0 0 0
1196 0 return $self->Results;
1197 }
1198  
1199 0 ▶sub reconnect {
Subroutine reconnect: not called CC=9 SCAR=45.0
Pod documented
1200 0 my $self = shift;
1201  
1202 0 ▶ if ( $self->IsAuthenticated ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->IsAuthenticated) 0 0 0
1203 0 $self->_debug("reconnect called but already authenticated");
1204 0 return 1;
1205 }
1206  
1207 # safeguard from deep recursion via connect
1208 0 ▶ if ( $self->{_doing_reconnect} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_doing_reconnect"}) 0 0 0
1209 0 $self->_debug("recursive call to reconnect, returning 0\n");
1210 0 ▶ $self->LastError("unexpected reconnect recursion")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->LastError 0 0 0
1211 unless $self->LastError;
1212 0 return 0;
1213 }
1214  
1215 0 ▶ my $einfo = $self->LastError || "";
Condition0%0/2
$self->LastError || ''
l!l
00
MC/DC0%0/1
$self->LastError || ''
$self->LastError
Truth table0%0/2
A
A= $self->LastError
Aresult
11
00
1216 0 $self->_debug( "reconnecting to ", $self->Server, ", last error: $einfo" );
1217 0 $self->{_doing_reconnect} = 1;
1218  
1219 # reconnect and select appropriate folder
1220 0 my $ret;
1221 0 ▶ if ( $self->connect ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->connect) 0 0 0
1222 0 $ret = 1;
1223 0 ▶ if ( defined $self->Folder ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->Folder) 0 0 0
1224 0 ▶ $ret = defined( $self->select( $self->Folder ) ) ? 1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->select($self->Folder) ? : 0 0 0
1225 }
1226 }
1227  
1228 0 delete $self->{_doing_reconnect};
1229 0 ▶ return $ret ? 1 : $ret;
Branch: 1 branch
BranchTrueFalseTotal
$ret ? : 0 0 0
1230 }
1231  
1232 # wrapper for _imap_command_do to enable retrying on lost connections
1233 # options:
1234 # doretry => 0|1 - suppress|allow retry after reconnect
1235 0 ▶sub _imap_command {
Subroutine _imap_command: not called CC=27 SCAR=66.3
1236 0 my $self = shift;
1237 0 ▶ my $opt = ref( $_[0] ) eq "HASH" ? $_[0] : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
1238  
1239 0 my $tries = 0;
1240 0 ▶ my $retry = $self->Reconnectretry || 0;
Condition0%0/2
$self->Reconnectretry || 0
l!l
00
MC/DC0%0/1
$self->Reconnectretry || 0
$self->Reconnectretry
Truth table0%0/2
A
A= $self->Reconnectretry
Aresult
11
00
1241 0 my ( $rc, @err );
1242  
1243 # LastError (if set) will be overwritten masking any earlier errors
1244 0 ▶ while ( $tries++ <= $retry ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tries++ <= $retry) 0 0 0
1245  
1246 # do command on the first try or if Connected (reconnect ongoing)
1247 0 ▶ if ( $tries == 1 or $self->IsConnected ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tries == 1 or $self->IsConnected) 0 0 0
Condition0%0/3
$tries == 1 or $self->IsConnected
l!l&&r!l&&!r
000
MC/DC0%0/2
$tries == 1 or $self->IsConnected
$tries == 1 $self->IsConnected
Truth table0%0/3
A or B
A= $tries == 1B= $self->IsConnected
ABresult
1X1
011
000
1248 0 $rc = $self->_imap_command_do(@_);
1249 0 ▶ push( @err, $self->LastError ) if $self->LastError;
Branch: 1 branch
BranchTrueFalseTotal
if $self->LastError 0 0 0
1250 }
1251  
1252 0 ▶ if ( !defined($rc) and $retry and $self->IsUnconnected ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rc and $retry and $self->IsUnconnected) { } 0 0 0
Condition0%0/6
not defined $rc and $retry and $self->IsUnconnected
!ll&&!rl&&r
000
not defined $rc and $retry
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $rc and $retry and $self->IsUnconnected
not defined $rc $retry $self->IsUnconnected
Truth table0%0/4
not(A) and B and C
A= not defined $rcB= $retryC= $self->IsUnconnected
ABCresult
0XX0
10X0
1100
1111
1253 last
1254 unless (
1255 0 ▶ $! == EPIPE
Branch: 1 branch
BranchTrueFalseTotal
unless $! == 32 or $! == 104 or $self->LastError =~ /(?:error\(.*?\)|timeout) waiting\b/ or $self->LastError =~ /(?:socket closed|\* BYE)\b/ 0 0 0
Condition0%0/9
$! == 32 or $! == 104 or $self->LastError =~ /(?:error\(.*?\)|timeout) waiting\b/ or $self->LastError =~ /(?:socket closed|\* BYE)\b/
l!l&&r!l&&!r
000
$! == 32 or $! == 104 or $self->LastError =~ /(?:error\(.*?\)|timeout) waiting\b/
l!l&&r!l&&!r
000
$! == 32 or $! == 104
l!l&&r!l&&!r
000
MC/DC0%0/4
$! == 32 or $! == 104 or $self->LastError =~ /(?:error\(.*?\)|timeout) waiting\b/ or $self->LastError =~ /(?:socket closed|\* BYE)\b/
$! == 32 $! == 104 $self->LastError =~ /(?:error\(.*?\)|timeout) waiting\b/ $self->LastError =~ /(?:socket closed|\* BYE)\b/
Truth table0%0/5
A or B or C or D
A= $! == 32B= $! == 104C= $self->LastError =~ /(?:error\(.*?\)|timeout) waiting\b/D= $self->LastError =~ /(?:socket closed|\* BYE)\b/
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1256 or $! == ECONNRESET
1257 or $self->LastError =~ /(?:error\(.*?\)|timeout) waiting\b/
1258 or $self->LastError =~ /(?:socket closed|\* BYE)\b/
1259  
1260 # BUG? reconnect if caller ignored/missed earlier errors?
1261 # or $self->LastError =~ /NO not connected/
1262 );
1263 0 my $ret = $self->reconnect;
1264 0 ▶ if ($ret) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ret) { } 0 0 0
elsif (defined $ret and $ret == 0) { } 0 0 0
1265 0 $self->_debug("reconnect success($ret) on try #$tries/$retry");
1266 0 ▶ last if exists $opt->{doretry} and !$opt->{doretry};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opt->{"doretry"} and not $opt->{"doretry"} 0 0 0
Condition0%0/3
exists $opt->{"doretry"} and not $opt->{"doretry"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opt->{"doretry"} and not $opt->{"doretry"}
exists $opt->{"doretry"} not $opt->{"doretry"}
Truth table0%0/3
A and not(B)
A= exists $opt->{"doretry"}B= not $opt->{"doretry"}
ABresult
0X0
100
111
1267 }
1268 ▶ elsif ( defined $ret and $ret == 0 ) { # escaping recursion
Condition0%0/3
defined $ret and $ret == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ret and $ret == 0
defined $ret $ret == 0
Truth table0%0/3
A and B
A= defined $retB= $ret == 0
ABresult
0X0
100
111
1269 0 return undef;
1270 }
1271 else {
1272 0 $self->_debug("reconnect failure on try #$tries/$retry");
1273 0 ▶ push( @err, $self->LastError ) if $self->LastError;
Branch: 1 branch
BranchTrueFalseTotal
if $self->LastError 0 0 0
1274 }
1275 }
1276 else {
1277 0 last;
1278 }
1279 }
1280  
1281 0 ▶ unless ($rc) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rc) 0 0 0
1282 0 my ( %seen, @keep, @info );
1283  
1284 0 foreach my $str (@err) {
1285 0 my ( $sz, $len ) = ( 96, length($str) );
1286 0 $str =~ s/$CR?$LF$/\\n/omg;
1287 0 ▶ if ( !$self->Debug and $len > $sz * 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->Debug and $len > $sz * 2) 0 0 0
Condition0%0/3
not $self->Debug and $len > $sz * 2
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->Debug and $len > $sz * 2
not $self->Debug $len > $sz * 2
Truth table0%0/3
not(A) and B
A= not $self->DebugB= $len > $sz * 2
ABresult
0X0
100
111
1288 0 my $beg = substr( $str, 0, $sz );
1289 0 my $end = substr( $str, -$sz, $sz );
1290 0 $str = $beg . "..." . $end;
1291 }
1292 0 ▶ next if $seen{$str}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$str}++ 0 0 0
1293 0 push( @keep, $str );
1294 }
1295 0 foreach my $msg (@keep) {
1296 0 ▶ push( @info, $msg . ( $seen{$msg} > 1 ? " ($seen{$msg}x)" : "" ) );
Branch: 1 branch
BranchTrueFalseTotal
$seen{$msg} > 1 ? : 0 0 0
1297 }
1298 0 $self->LastError( join( "; ", @info ) );
1299 }
1300  
1301 0 return $rc;
1302 }
1303  
1304 # _imap_command_do runs a command, inserting a tag and CRLF as requested
1305 # options:
1306 # addcrlf => 0|1 - suppress adding CRLF to $string
1307 # addtag => 0|1 - suppress adding $tag to $string
1308 # tag => $tag - use this $tag instead of incrementing $self->Count
1309 # outref => ... - see _get_response()
1310 0 ▶sub _imap_command_do {
Subroutine _imap_command_do: not called CC=18 SCAR=58.3
1311 0 my $self = shift;
1312 0 ▶ my $opt = ref( $_[0] ) eq "HASH" ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
1313 0 ▶ my $string = shift or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $string = shift() or return undef 0 0 0
1314 0 my $good = shift;
1315  
1316 0 ▶ my @gropt = ( $opt->{outref} ? { outref => $opt->{outref} } : () );
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'outref'} ? : 0 0 0
1317  
1318 0 ▶ $opt->{addcrlf} = 1 unless exists $opt->{addcrlf};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opt->{"addcrlf"} 0 0 0
1319 0 ▶ $opt->{addtag} = 1 unless exists $opt->{addtag};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opt->{"addtag"} 0 0 0
1320  
1321 # reset error in case the last error was non-fatal but never cleared
1322 0 ▶ if ( $self->LastError ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->LastError) 0 0 0
1323  
1324 #DEBUG $self->_debug( "Reset LastError: " . $self->LastError );
1325 0 $self->LastError(undef);
1326 }
1327  
1328 0 my $clear = $self->Clear;
1329 0 ▶ $self->Clear($clear)
Branch: 1 branch
BranchTrueFalseTotal
if $self->Count >= $clear and $clear > 0 0 0 0
Condition0%0/3
$self->Count >= $clear and $clear > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$self->Count >= $clear and $clear > 0
$self->Count >= $clear $clear > 0
Truth table0%0/3
A and B
A= $self->Count >= $clearB= $clear > 0
ABresult
0X0
100
111
1330 if $self->Count >= $clear && $clear > 0;
1331  
1332 0 my $count = $self->Count( $self->Count + 1 );
1333 0 ▶ my $tag = $opt->{tag} || $count;
Condition0%0/3
$opt->{'tag'} || $count
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt->{'tag'} || $count
$opt->{'tag'} $count
Truth table0%0/3
A || B
A= $opt->{'tag'}B= $count
ABresult
1X1
011
000
1334 0 ▶ $string = "$tag $string" if $opt->{addtag};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"addtag"} 0 0 0
1335  
1336 # for APPEND (append_string) only log first line of command
1337 0 ▶ my $logstr = ( $string =~ /^($tag\s+APPEND\s+.*?)$CR?$LF/ ) ? $1 : $string;
Branch: 1 branch
BranchTrueFalseTotal
$string =~ /^($tag\s+APPEND\s+.*?)$Mail::IMAPClient::CR?$Mail::IMAPClient::LF/ ? : 0 0 0
1338  
1339 # BUG? use $self->_next_index($tag) ? or 0 ???
1340 # $self->_record($tag, [$self->_next_index($tag), "INPUT", $logstr] );
1341 0 $self->_record( $count, [ 0, "INPUT", $logstr ] );
1342  
1343 # $suppress (adding CRLF) set to 0 if $opt->{addcrlf} is TRUE
1344 0 ▶ unless ( $self->_send_line( $string, $opt->{addcrlf} ? 0 : 1 ) ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->_send_line($string, $opt->{"addcrlf"} ? 0 : 1)) 0 0 0
$opt->{'addcrlf'} ? : 0 0 0
1345 0 $self->LastError( "Error sending '$logstr': " . $self->LastError );
1346 0 return undef;
1347 }
1348  
1349 # look for "<tag> (OK|BAD|NO|$good)" (or "+..." if $good is '+')
1350 0 ▶ my $code = $self->_get_response( @gropt, $tag, $good ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $code = $self->_get_response(@gropt, $tag, $good) or return undef 0 0 0
1351  
1352 0 ▶ if ( $code eq 'OK' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($code eq 'OK') { } 0 0 0
elsif ($good and $code eq $good) { } 0 0 0
1353 0 return $self;
1354 }
1355 ▶ elsif ( $good and $code eq $good ) {
Condition0%0/3
$good and $code eq $good
!ll&&!rl&&r
000
MC/DC0%0/2
$good and $code eq $good
$good $code eq $good
Truth table0%0/3
A and B
A= $goodB= $code eq $good
ABresult
0X0
100
111
1356 0 return $self;
1357 }
1358 else {
1359 0 return undef;
1360 }
1361 }
1362  
1363 0 ▶sub _response_code_sub {
Subroutine _response_code_sub: not called CC=5 SCAR=34.0
1364 0 my ( $self, $tag, $good ) = @_;
1365  
1366 # tag/good can be a ref (compiled regex) otherwise quote it
1367 0 ▶ my $qtag = ref($tag) ? $tag : defined($tag) ? quotemeta($tag) : undef;
Branch: 2 branches
BranchTrueFalseTotal
ref $tag ? : 0 0 0
defined $tag ? : 0 0 0
1368 0 ▶ my $qgood = ref($good) ? $good : defined($good) ? quotemeta($good) : undef;
Branch: 2 branches
BranchTrueFalseTotal
ref $good ? : 0 0 0
defined $good ? : 0 0 0
1369  
1370 # using closure, a variable alias, and sub returns on first match
1371 # - $_[0] is $o->[DATA]
1372 # - returns list ( $code, $byemsg )
1373 0 ▶ my $getcodesub = sub {
Subroutine __ANON__: not called CC=13 SCAR=52.0
1374 0 ▶ if ( defined $qgood ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $qgood) 0 0 0
1375 0 ▶ if ( $good eq '+' and $_[0] =~ /^$qgood/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($good eq "+" and $_[0] =~ /^$qgood/) 0 0 0
Condition0%0/3
$good eq "+" and $_[0] =~ /^$qgood/
!ll&&!rl&&r
000
MC/DC0%0/2
$good eq "+" and $_[0] =~ /^$qgood/
$good eq "+" $_[0] =~ /^$qgood/
Truth table0%0/3
A and B
A= $good eq "+"B= $_[0] =~ /^$qgood/
ABresult
0X0
100
111
1376 0 return ($good);
1377 }
1378 0 ▶ if ( defined $qtag and $_[0] =~ /^$qtag\s+($qgood)/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $qtag and $_[0] =~ /^$qtag\s+($qgood)/i) 0 0 0
Condition0%0/3
defined $qtag and $_[0] =~ /^$qtag\s+($qgood)/i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $qtag and $_[0] =~ /^$qtag\s+($qgood)/i
defined $qtag $_[0] =~ /^$qtag\s+($qgood)/i
Truth table0%0/3
A and B
A= defined $qtagB= $_[0] =~ /^$qtag\s+($qgood)/i
ABresult
0X0
100
111
1379 0 ▶ return ( ref($qgood) ? $1 : uc($1) );
Branch: 1 branch
BranchTrueFalseTotal
ref $qgood ? : 0 0 0
1380 }
1381 }
1382 0 ▶ if ( defined $qtag ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $qtag) 0 0 0
1383 0 ▶ if ( $tag eq '+' and $_[0] =~ /^$qtag/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "+" and $_[0] =~ /^$qtag/) 0 0 0
Condition0%0/3
$tag eq "+" and $_[0] =~ /^$qtag/
!ll&&!rl&&r
000
MC/DC0%0/2
$tag eq "+" and $_[0] =~ /^$qtag/
$tag eq "+" $_[0] =~ /^$qtag/
Truth table0%0/3
A and B
A= $tag eq "+"B= $_[0] =~ /^$qtag/
ABresult
0X0
100
111
1384 0 return ($tag);
1385 }
1386 0 ▶ if ( $_[0] =~ /^$qtag\s+(OK|BAD|NO)\b/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^$qtag\s+(OK|BAD|NO)\b/i) 0 0 0
1387 0 my $code = uc($1);
1388 0 ▶ $self->LastError( $_[0] ) unless ( $code eq 'OK' );
Branch: 1 branch
BranchTrueFalseTotal
unless $code eq "OK" 0 0 0
1389 0 return ($code);
1390 }
1391 }
1392 0 ▶ if ( $_[0] =~ /^\*\s+(BYE)\b/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^\*\s+(BYE)\b/i) 0 0 0
1393 0 return ( uc($1), $_[0] ); # ( 'BYE', $byemsg )
1394 }
1395 0 return (undef);
1396 0 };
1397  
1398 0 return $getcodesub;
1399 }
1400  
1401 # _get_response get IMAP response optionally send data somewhere
1402 # options:
1403 # outref => GLOB|CODE - reference to send output to (see _read_line)
1404 0 ▶sub _get_response {
Subroutine _get_response: not called CC=17 SCAR=57.2
1405 0 my $self = shift;
1406 0 ▶ my $opt = ref( $_[0] ) eq "HASH" ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
1407 0 my $tag = shift;
1408 0 my $good = shift;
1409  
1410 0 my $outref = $opt->{outref};
1411 0 ▶ my @readopt = defined($outref) ? ($outref) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $outref ? : 0 0 0
1412 0 my $getcode = $self->_response_code_sub( $tag, $good );
1413  
1414 0 my ( $count, $out, $code, $byemsg ) = ( $self->Count, [], undef, undef );
1415 0 ▶ until ( defined $code ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code) 0 0 0
1416 0 ▶ my $output = $self->_read_line(@readopt) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $output = $self->_read_line(@readopt) or return undef 0 0 0
1417 0 $out = $output; # keep last response just in case
1418  
1419 # not using last on first match? paranoia or right thing?
1420 # only uc() when match is not on case where $tag|$good is a ref()
1421 0 foreach my $o (@$output) {
1422 0 $self->_record( $count, $o );
1423 0 ▶ $self->_is_output($o) or next;
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_output($o) or next 0 0 0
1424 0 my ( $tcode, $tbyemsg ) = $getcode->( $o->[DATA] );
1425 0 ▶ $code = $tcode if ( defined $tcode );
Branch: 1 branch
BranchTrueFalseTotal
if defined $tcode 0 0 0
1426 0 ▶ $byemsg = $tbyemsg if ( defined $tbyemsg );
Branch: 1 branch
BranchTrueFalseTotal
if defined $tbyemsg 0 0 0
1427 }
1428 }
1429  
1430 0 ▶ if ( defined $code ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $code) { } 0 0 0
elsif (not $self->LastError) { } 0 0 0
1431 0 $code =~ s/$CR?$LF?$//o;
1432 0 ▶ $code = uc($code) unless ( $good and $code eq $good );
Branch: 1 branch
BranchTrueFalseTotal
unless $good and $code eq $good 0 0 0
Condition0%0/3
$good and $code eq $good
!ll&&!rl&&r
000
MC/DC0%0/2
$good and $code eq $good
$good $code eq $good
Truth table0%0/3
A and B
A= $goodB= $code eq $good
ABresult
0X0
100
111
1433  
1434 # RFC 3501 7.1.5: $code on successful LOGOUT is OK not BYE
1435 # sometimes we may fail to wait long enough to read a tagged
1436 # OK so don't be strict about setting an error on LOGOUT!
1437 0 ▶ if ( $code eq 'BYE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code eq "BYE") 0 0 0
1438 0 $self->State(Unconnected);
1439 0 ▶ if ($byemsg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($byemsg) 0 0 0
1440 0 ▶ $self->LastError($byemsg)
Branch: 1 branch
BranchTrueFalseTotal
unless $good and $code eq $good 0 0 0
Condition0%0/3
$good and $code eq $good
!ll&&!rl&&r
000
MC/DC0%0/2
$good and $code eq $good
$good $code eq $good
Truth table0%0/3
A and B
A= $goodB= $code eq $good
ABresult
0X0
100
111
1441 unless ( $good and $code eq $good );
1442 }
1443 }
1444 }
1445 elsif ( !$self->LastError ) {
1446 0 my $info = "unexpected response: " . join( " ", @$out );
1447 0 $self->LastError($info);
1448 }
1449  
1450 0 return $code;
1451 }
1452  
1453 0 ▶sub _imap_uid_command {
Subroutine _imap_uid_command: not called CC=4 SCAR=30.0
1454 0 my $self = shift;
1455 0 ▶ my @opt = ref( $_[0] ) eq "HASH" ? (shift) : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
1456 0 my $cmd = shift;
1457  
1458 0 ▶ my $args = @_ ? join( " ", '', @_ ) : '';
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
1459 0 ▶ my $uid = $self->Uid ? 'UID ' : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->Uid ? : 0 0 0
1460 0 $self->_imap_command( @opt, "$uid$cmd$args" );
1461 }
1462  
1463 0 ▶sub run {
Subroutine run: not called CC=6 SCAR=37.4
Pod documented
1464 0 my $self = shift;
1465 0 ▶ my $string = shift or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $string = shift() or return undef 0 0 0
1466  
1467 0 ▶ my $tag = $string =~ /^(\S+) / ? $1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$string =~ /^(\S+) / ? : 0 0 0
1468 0 ▶ unless ($tag) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tag) 0 0 0
1469 0 $self->LastError("No tag found in string passed to run(): $string");
1470 0 return undef;
1471 }
1472  
1473 0 ▶ $self->_imap_command( { addtag => 0, addcrlf => 0, tag => $tag }, $string )
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command({"addtag", 0, "addcrlf", 0, "tag", $tag}, $string) or return undef 0 0 0
1474 or return undef;
1475  
1476 0 ▶ $self->{History}{$tag} = $self->{History}{ $self->Count }
Branch: 1 branch
BranchTrueFalseTotal
unless $tag eq $self->Count 0 0 0
1477 unless $tag eq $self->Count;
1478  
1479 0 return $self->Results;
1480 }
1481  
1482 # _record saves the conversation into the History structure:
1483 0 ▶sub _record {
Subroutine _record: not called CC=3 SCAR=24.8
1484 0 my ( $self, $count, $array ) = @_;
1485 0 ▶ if ( $array->[DATA] =~ /^\d+ LOGIN/i && !$self->Showcredentials ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($array->[2] =~ /^\d+ LOGIN/i and not $self->Showcredentials) 0 0 0
Condition0%0/3
$array->[2] =~ /^\d+ LOGIN/i and not $self->Showcredentials
!ll&&!rl&&r
000
MC/DC0%0/2
$array->[2] =~ /^\d+ LOGIN/i and not $self->Showcredentials
$array->[2] =~ /^\d+ LOGIN/i not $self->Showcredentials
Truth table0%0/3
A and not(B)
A= $array->[2] =~ /^\d+ LOGIN/iB= not $self->Showcredentials
ABresult
0X0
100
111
1486 0 $array->[DATA] =~ s/LOGIN.*/LOGIN XXXXXXXX XXXXXXXX/i;
1487 }
1488  
1489 0 push @{ $self->{History}{$count} }, $array;
1490 }
1491  
1492 # try to avoid exposing auth info via debug unless Showcredentials is true
1493 0 ▶sub _redact_line {
Subroutine _redact_line: not called CC=8 SCAR=42.8
1494 0 my ( $self, $string ) = @_;
1495 0 ▶ $self->Showcredentials and return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->Showcredentials and return undef 0 0 0
1496  
1497 0 my ( $tag, $cmd ) = ( $self->Count, undef );
1498 0 my $retext = "[Redact: Count=$tag Showcredentials=OFF]";
1499 0 my $show = $retext;
1500  
1501 # tagged command?
1502 0 ▶ if ( $string =~ s/^($tag\s+(\S+)\s+)// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ s/^($tag\s+(\S+)\s+)//) 0 0 0
1503 0 ( $show, $cmd ) = ( $1, $2 );
1504  
1505 # login <username|literal> <password|literal>
1506 0 ▶ if ( $cmd =~ /login/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmd =~ /login/i) { } 0 0 0
elsif ($cmd =~ /^auth/i) { } 0 0 0
1507  
1508 # username as literal
1509 0 ▶ if ( $string =~ /^{/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($string =~ /^{/) { } 0 0 0
elsif ($string =~ s/^((?:"(?>(?:(?>[^"\\]+)|\\.)*)"|\S+)\s*)//) { } 0 0 0
1510 0 $show .= $string;
1511 }
1512  
1513 # username (possibly quoted) string, then literal? password
1514 elsif ( $string =~ s/^((?:"(?>(?:(?>[^"\\]+)|\\.)*)"|\S+)\s*)// ) {
1515 0 $show .= $1;
1516 0 ▶ $show .= ( $string =~ /^{/ ) ? $string : $retext;
Branch: 1 branch
BranchTrueFalseTotal
$string =~ /^{/ ? : 0 0 0
1517 }
1518 }
1519 elsif ( $cmd =~ /^auth/i ) {
1520 0 $show .= $string;
1521 }
1522 else {
1523 0 return undef; # show it all
1524 }
1525 }
1526  
1527 0 return $show;
1528 }
1529  
1530 # _send_line handles literal data and supports the Prewritemethod
1531 0 ▶sub _send_line {
Subroutine _send_line: not called CC=16 SCAR=56.1
1532 0 my ( $self, $string, $suppress ) = @_;
1533  
1534 0 ▶ $string =~ s/$CR?$LF?$/$CRLF/o
Branch: 1 branch
BranchTrueFalseTotal
unless $suppress 0 0 0
1535 unless $suppress;
1536  
1537 # handle case where string contains a literal
1538 0 ▶ if ( $string =~ s/^([^$LF\{]*\{\d+\}$CRLF)(?=.)//o ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ s/^([^$Mail::IMAPClient::LF\{]*\{\d+\}$Mail::IMAPClient::CRLF)(?=.)//o) 0 0 0
1539 0 my $first = $1;
1540 0 ▶ if ( $self->Debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Debug) 0 0 0
1541 0 ▶ my $dat =
Branch: 1 branch
BranchTrueFalseTotal
$self->IsConnected && !$self->IsAuthenticated ? : 0 0 0
Condition0%0/3
$self->IsConnected and not $self->IsAuthenticated
!ll&&!rl&&r
000
MC/DC0%0/2
$self->IsConnected and not $self->IsAuthenticated
$self->IsConnected not $self->IsAuthenticated
Truth table0%0/3
A and not(B)
A= $self->IsConnectedB= not $self->IsAuthenticated
ABresult
0X0
100
111
1542 ( $self->IsConnected and !$self->IsAuthenticated )
1543 ? $self->_redact_line($string)
1544 : undef;
1545 0 ▶ $self->_debug( "Sending literal: $first\tthen: ", $dat || $string );
Condition0%0/3
$dat || $string
l!l&&r!l&&!r
000
MC/DC0%0/2
$dat || $string
$dat $string
Truth table0%0/3
A || B
A= $datB= $string
ABresult
1X1
011
000
1546 }
1547 0 ▶ $self->_send_line($first) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_send_line($first) or return undef 0 0 0
1548  
1549 # look for "$tag NO" or "+ ..."
1550 0 ▶ my $code = $self->_get_response( $self->Count, '+' ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $code = $self->_get_response($self->Count, "+") or return undef 0 0 0
1551 0 ▶ return undef unless $code eq '+';
Branch: 1 branch
BranchTrueFalseTotal
unless $code eq "+" 0 0 0
1552 }
1553  
1554 # non-literal part continues...
1555 0 ▶ if ( my $prew = $self->Prewritemethod ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $prew = $self->Prewritemethod) 0 0 0
1556 0 $string = $prew->( $self, $string );
1557 }
1558  
1559 0 ▶ if ( $self->Debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Debug) 0 0 0
1560 0 ▶ my $dat =
Branch: 1 branch
BranchTrueFalseTotal
$self->IsConnected && !$self->IsAuthenticated ? : 0 0 0
Condition0%0/3
$self->IsConnected and not $self->IsAuthenticated
!ll&&!rl&&r
000
MC/DC0%0/2
$self->IsConnected and not $self->IsAuthenticated
$self->IsConnected not $self->IsAuthenticated
Truth table0%0/3
A and not(B)
A= $self->IsConnectedB= not $self->IsAuthenticated
ABresult
0X0
100
111
1561 ( $self->IsConnected and !$self->IsAuthenticated )
1562 ? $self->_redact_line($string)
1563 : undef;
1564 0 ▶ $self->_debug( "Sending: ", $dat || $string );
Condition0%0/3
$dat || $string
l!l&&r!l&&!r
000
MC/DC0%0/2
$dat || $string
$dat $string
Truth table0%0/3
A || B
A= $datB= $string
ABresult
1X1
011
000
1565 }
1566  
1567 0 ▶ unless ( $self->IsConnected ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->IsConnected) 0 0 0
1568 0 $self->LastError("NO not connected");
1569 0 return undef;
1570 }
1571  
1572 0 $self->_send_bytes( \$string );
1573 }
1574  
1575 0 ▶sub _send_bytes($) {
Subroutine _send_bytes: not called CC=12 SCAR=50.5
1576 0 my ( $self, $byteref ) = @_;
1577 0 my ( $total, $temperrs, $maxwrite ) = ( 0, 0, 0 );
1578 0 my $waittime = .02;
1579 0 my @previous_writes;
1580  
1581 0 my $maxagain = $self->Maxtemperrors;
1582 0 ▶ undef $maxagain if $maxagain and lc($maxagain) eq 'unlimited';
Branch: 1 branch
BranchTrueFalseTotal
if $maxagain and lc $maxagain eq "unlimited" 0 0 0
Condition0%0/3
$maxagain and lc $maxagain eq "unlimited"
!ll&&!rl&&r
000
MC/DC0%0/2
$maxagain and lc $maxagain eq "unlimited"
$maxagain lc $maxagain eq "unlimited"
Truth table0%0/3
A and B
A= $maxagainB= lc $maxagain eq "unlimited"
ABresult
0X0
100
111
1583  
1584 0 local $SIG{PIPE} = 'IGNORE'; # handle SIGPIPE as normal error
1585  
1586 0 my $socket = $self->Socket;
1587 0 ▶ while ( $total < length $$byteref ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($total < length $$byteref) 0 0 0
1588 0 my $written =
1589 syswrite( $socket, $$byteref, length($$byteref) - $total, $total );
1590  
1591 0 ▶ if ( defined $written ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $written) 0 0 0
1592 0 $temperrs = 0;
1593 0 $total += $written;
1594 0 next;
1595 }
1596  
1597 0 ▶ if ( $! == EAGAIN ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($! == 11) 0 0 0
1598 0 ▶ if ( defined $maxagain && $temperrs++ > $maxagain ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $maxagain and $temperrs++ > $maxagain) 0 0 0
Condition0%0/3
defined $maxagain and $temperrs++ > $maxagain
!ll&&!rl&&r
000
MC/DC0%0/2
defined $maxagain and $temperrs++ > $maxagain
defined $maxagain $temperrs++ > $maxagain
Truth table0%0/3
A and B
A= defined $maxagainB= $temperrs++ > $maxagain
ABresult
0X0
100
111
1599 0 $self->LastError("Persistent error '$!'");
1600 0 return undef;
1601 }
1602  
1603 $waittime =
1604 0 $self->_optimal_sleep( $maxwrite, $waittime, \@previous_writes );
1605 0 next;
1606 }
1607  
1608 # Unconnected might be apropos for more than just these?
1609 0 ▶ my $emsg = $! ? "$!" : "no error caught";
Branch: 1 branch
BranchTrueFalseTotal
$! ? : 0 0 0
1610 0 ▶ $self->State(Unconnected)
Branch: 1 branch
BranchTrueFalseTotal
if $! == 32 or $! == 104 or $! == 9 0 0 0
Condition0%0/6
$! == 32 or $! == 104 or $! == 9
l!l&&r!l&&!r
000
$! == 32 or $! == 104
l!l&&r!l&&!r
000
MC/DC0%0/3
$! == 32 or $! == 104 or $! == 9
$! == 32 $! == 104 $! == 9
Truth table0%0/4
A or B or C
A= $! == 32B= $! == 104C= $! == 9
ABCresult
1XX1
01X1
0011
0000
1611 if ( $! == EPIPE or $! == ECONNRESET or $! == EBADF );
1612 0 $self->LastError("Write failed '$emsg'");
1613  
1614 0 return undef; # no luck
1615 }
1616  
1617 0 $self->_debug("Sent $total bytes");
1618 0 return $total;
1619 }
1620  
1621 # _read_line: read one line from the socket
1622 #
1623 # $output = $self->_read_line($literal_callback)
1624 # literal_callback is optional, but if supplied it must be either
1625 # be a filehandle, coderef, or undef.
1626 #
1627 # Returns a reference to an array of arrays, i.e.:
1628 # $output = [
1629 # [ $index, 'OUTPUT|LITERAL', $output_line ],
1630 # [ $index, 'OUTPUT|LITERAL', $output_line ],
1631 # ...
1632 # \];
1633  
1634 # BUG?: make memory more efficient
1635 0 ▶sub _read_line {
Subroutine _read_line: not called CC=53 SCAR=79.6
1636 0 my ( $self, $literal_callback ) = @_;
1637  
1638 0 my $socket = $self->Socket;
1639 0 ▶ unless ( $self->IsConnected && $socket ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->IsConnected and $socket) 0 0 0
Condition0%0/3
$self->IsConnected and $socket
!ll&&!rl&&r
000
MC/DC0%0/2
$self->IsConnected and $socket
$self->IsConnected $socket
Truth table0%0/3
A and B
A= $self->IsConnectedB= $socket
ABresult
0X0
100
111
1640 0 $self->LastError("NO not connected");
1641 0 return undef;
1642 }
1643  
1644 0 my $iBuffer = "";
1645 0 my $oBuffer = [];
1646 0 my $index = $self->_next_index;
1647 0 my $timeout = $self->Timeout;
1648 0 ▶ my $readlen = $self->Buffer || 4096;
Condition0%0/2
$self->Buffer || 4096
l!l
00
MC/DC0%0/1
$self->Buffer || 4096
$self->Buffer
Truth table0%0/2
A
A= $self->Buffer
Aresult
11
00
1649 0 my $transno = $self->Transaction;
1650  
1651 0 my $literal_cbtype = "";
1652 0 ▶ if ($literal_callback) {
Branch: 1 branch
BranchTrueFalseTotal
if ($literal_callback) 0 0 0
1653 0 ▶ if ( UNIVERSAL::isa( $literal_callback, "GLOB" ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($literal_callback, 'GLOB')) { } 0 0 0
elsif (UNIVERSAL::isa($literal_callback, 'CODE')) { } 0 0 0
1654 0 $literal_cbtype = "GLOB";
1655 }
1656 elsif ( UNIVERSAL::isa( $literal_callback, "CODE" ) ) {
1657 0 $literal_cbtype = "CODE";
1658 }
1659 else {
1660 0 $self->LastError( "'$literal_callback' is an "
1661 . "invalid callback; must be a filehandle or CODE" );
1662 0 return undef;
1663 }
1664 }
1665  
1666 0 my $temperrs = 0;
1667 0 my $maxagain = $self->Maxtemperrors;
1668 0 ▶ undef $maxagain if $maxagain and lc($maxagain) eq 'unlimited';
Branch: 1 branch
BranchTrueFalseTotal
if $maxagain and lc $maxagain eq "unlimited" 0 0 0
Condition0%0/3
$maxagain and lc $maxagain eq "unlimited"
!ll&&!rl&&r
000
MC/DC0%0/2
$maxagain and lc $maxagain eq "unlimited"
$maxagain lc $maxagain eq "unlimited"
Truth table0%0/3
A and B
A= $maxagainB= lc $maxagain eq "unlimited"
ABresult
0X0
100
111
1669  
1670 0 ▶ until (
Branch: 1 branch
BranchTrueFalseTotal
unless (@$oBuffer and $oBuffer->[-1][1] eq "OUTPUT" and $oBuffer->[-1][2] =~ /$Mail::IMAPClient::CR?$Mail::IMAPClient::LF$/o and not length $iBuffer) 0 0 0
Condition0%0/9
@$oBuffer and $oBuffer->[-1][1] eq "OUTPUT" and $oBuffer->[-1][2] =~ /$Mail::IMAPClient::CR?$Mail::IMAPClient::LF$/o and not length $iBuffer
!ll&&!rl&&r
000
@$oBuffer and $oBuffer->[-1][1] eq "OUTPUT" and $oBuffer->[-1][2] =~ /$Mail::IMAPClient::CR?$Mail::IMAPClient::LF$/o
!ll&&!rl&&r
000
@$oBuffer and $oBuffer->[-1][1] eq "OUTPUT"
!ll&&!rl&&r
000
MC/DC0%0/4
@$oBuffer and $oBuffer->[-1][1] eq "OUTPUT" and $oBuffer->[-1][2] =~ /$Mail::IMAPClient::CR?$Mail::IMAPClient::LF$/o and not length $iBuffer
@$oBuffer $oBuffer->[-1][1] eq "OUTPUT" $oBuffer->[-1][2] =~ /$Mail::IMAPClient::CR?$Mail::IMAPClient::LF$/o not length $iBuffer
Truth table0%0/5
A and B and C and not(D)
A= @$oBufferB= $oBuffer->[-1][1] eq "OUTPUT"C= $oBuffer->[-1][2] =~ /$Mail::IMAPClient::CR?$Mail::IMAPClient::LF$/oD= not length $iBuffer
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1671 @$oBuffer # there's stuff in output buffer:
1672 && $oBuffer->[-1][TYPE] eq 'OUTPUT' # that thing is an output line:
1673 && $oBuffer->[-1][DATA] =~
1674 /$CR?$LF$/o # the last thing there has cr-lf:
1675 && !length $iBuffer # and the input buffer has been MT'ed:
1676 )
1677 {
1678  
1679 0 ▶ if ($timeout) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timeout) 0 0 0
1680 0 my $rc = $self->_read_more( $socket, $timeout );
1681 0 ▶ return undef unless ( $rc > 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless $rc > 0 0 0 0
1682 }
1683  
1684 0 my $emsg;
1685 0 my $ret =
1686 $self->_sysread( $socket, \$iBuffer, $readlen, length $iBuffer );
1687  
1688 0 ▶ if ($timeout) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timeout) 0 0 0
1689 0 ▶ if ( defined $ret ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ret) { } 0 0 0
1690 0 $temperrs = 0;
1691 }
1692 else {
1693 0 $emsg = "error while reading data from server: $!";
1694 0 ▶ if ( $! == ECONNRESET ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($! == 104) { } 0 0 0
elsif ($! == 11) { } 0 0 0
1695 0 $self->State(Unconnected);
1696 }
1697 elsif ( $! == EAGAIN ) {
1698 0 ▶ if ( defined $maxagain && $temperrs++ >= $maxagain ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $maxagain and $temperrs++ >= $maxagain) { } 0 0 0
Condition0%0/3
defined $maxagain and $temperrs++ >= $maxagain
!ll&&!rl&&r
000
MC/DC0%0/2
defined $maxagain and $temperrs++ >= $maxagain
defined $maxagain $temperrs++ >= $maxagain
Truth table0%0/3
A and B
A= defined $maxagainB= $temperrs++ >= $maxagain
ABresult
0X0
100
111
1699 0 $emsg .= " ($temperrs)";
1700 }
1701 else {
1702 0 next; # try again
1703 }
1704 }
1705 }
1706 }
1707  
1708 0 ▶ if ( defined $ret && $ret == 0 ) { # Caught EOF...
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ret and $ret == 0) 0 0 0
Condition0%0/3
defined $ret and $ret == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ret and $ret == 0
defined $ret $ret == 0
Truth table0%0/3
A and B
A= defined $retB= $ret == 0
ABresult
0X0
100
111
1709 0 $emsg = "socket closed while reading data from server";
1710 0 $self->State(Unconnected);
1711 }
1712  
1713 # save errors and return
1714 0 ▶ if ($emsg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($emsg) 0 0 0
1715 0 $self->LastError($emsg);
1716 0 $self->_record(
1717 $transno,
1718 [
1719 $self->_next_index($transno), "ERROR", "$transno * NO $emsg"
1720 ]
1721 );
1722 0 return undef;
1723 }
1724  
1725 0 ▶ while ( $iBuffer =~ s/^(.*?$CR?$LF)//o ) # consume line
Branch: 1 branch
BranchTrueFalseTotal
if ($iBuffer =~ s/^(.*?$Mail::IMAPClient::CR?$Mail::IMAPClient::LF)//o) 0 0 0
1726 {
1727 0 my $current_line = $1;
1728 0 ▶ if ( $current_line !~ s/\{(\d+)\}$CR?$LF$//o ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($current_line =~ s/\{(\d+)\}$Mail::IMAPClient::CR?$Mail::IMAPClient::LF$//o) 0 0 0
1729 0 push @$oBuffer, [ $index++, 'OUTPUT', $current_line ];
1730 0 next;
1731 }
1732  
1733 0 push @$oBuffer, [ $index++, 'OUTPUT', $current_line ];
1734  
1735 ## handle LITERAL
1736 # BLAH BLAH {nnn}$CRLF
1737 # [nnn bytes of literally transmitted stuff]
1738 # [part of line that follows literal data]$CRLF
1739  
1740 0 my $expected_size = $1;
1741  
1742 0 $self->_debug( "LITERAL: received literal in line "
1743 . "$current_line of length $expected_size; attempting to "
1744 . "retrieve from the "
1745 . length($iBuffer)
1746 . " bytes in: $iBuffer<END_OF_iBuffer>" );
1747  
1748 0 my $litstring;
1749 0 ▶ if ( length $iBuffer >= $expected_size ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $iBuffer >= $expected_size) { } 0 0 0
1750  
1751 # already received all data
1752 0 $litstring = substr $iBuffer, 0, $expected_size, '';
1753 }
1754 else { # literal data still to arrive
1755 0 $litstring = $iBuffer;
1756 0 $iBuffer = '';
1757  
1758 0 my $litreadb = length($litstring);
1759 0 my $temperrs = 0;
1760 0 my $maxagain = $self->Maxtemperrors;
1761 0 ▶ undef $maxagain if $maxagain and lc($maxagain) eq 'unlimited';
Branch: 1 branch
BranchTrueFalseTotal
if $maxagain and lc $maxagain eq "unlimited" 0 0 0
Condition0%0/3
$maxagain and lc $maxagain eq "unlimited"
!ll&&!rl&&r
000
MC/DC0%0/2
$maxagain and lc $maxagain eq "unlimited"
$maxagain lc $maxagain eq "unlimited"
Truth table0%0/3
A and B
A= $maxagainB= lc $maxagain eq "unlimited"
ABresult
0X0
100
111
1762  
1763 0 ▶ while ( $expected_size > $litreadb ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expected_size > $litreadb) 0 0 0
1764 0 ▶ if ($timeout) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timeout) { } 0 0 0
1765 0 my $rc = $self->_read_more( $socket, $timeout );
1766 0 ▶ return undef unless ( $rc > 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless $rc > 0 0 0 0
1767 }
1768 else { # 25 ms before retry
1769 0 CORE::select( undef, undef, undef, 0.025 );
1770 }
1771  
1772 # $litstring is emptied when $literal_cbtype is GLOB
1773 0 my $ret =
1774 $self->_sysread( $socket, \$litstring,
1775 $expected_size - $litreadb,
1776 length($litstring) );
1777  
1778 0 ▶ if ($timeout) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timeout) 0 0 0
1779 0 ▶ if ( defined $ret ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ret) { } 0 0 0
1780 0 $temperrs = 0;
1781 }
1782 else {
1783 0 $emsg = "error while reading data from server: $!";
1784 0 ▶ if ( $! == ECONNRESET ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($! == 104) { } 0 0 0
elsif ($! == 11) { } 0 0 0
1785 0 $self->State(Unconnected);
1786 }
1787 elsif ( $! == EAGAIN ) {
1788 0 ▶ if ( defined $maxagain
Branch: 1 branch
BranchTrueFalseTotal
if (defined $maxagain and $temperrs++ >= $maxagain) { } 0 0 0
Condition0%0/3
defined $maxagain and $temperrs++ >= $maxagain
!ll&&!rl&&r
000
MC/DC0%0/2
defined $maxagain and $temperrs++ >= $maxagain
defined $maxagain $temperrs++ >= $maxagain
Truth table0%0/3
A and B
A= defined $maxagainB= $temperrs++ >= $maxagain
ABresult
0X0
100
111
1789 && $temperrs++ >= $maxagain )
1790 {
1791 0 $emsg .= " ($temperrs)";
1792 }
1793 else {
1794 0 undef $emsg;
1795 0 next; # try again
1796 }
1797 }
1798 }
1799 }
1800  
1801 # EOF: note IO::Socket::SSL does not support eof()
1802 0 ▶ if ( defined $ret and $ret == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $ret and $ret == 0) { } 0 0 0
elsif (defined $ret and $ret > 0) { } 0 0 0
Condition0%0/3
defined $ret and $ret == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ret and $ret == 0
defined $ret $ret == 0
Truth table0%0/3
A and B
A= defined $retB= $ret == 0
ABresult
0X0
100
111
1803 0 $emsg = "socket closed while reading data from server";
1804 0 $self->State(Unconnected);
1805 }
1806 ▶ elsif ( defined $ret and $ret > 0 ) {
Condition0%0/3
defined $ret and $ret > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ret and $ret > 0
defined $ret $ret > 0
Truth table0%0/3
A and B
A= defined $retB= $ret > 0
ABresult
0X0
100
111
1807 0 $litreadb += $ret;
1808  
1809 # conserve memory when using literal_callback GLOB
1810 0 ▶ if ( $literal_cbtype eq "GLOB" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($literal_cbtype eq "GLOB") 0 0 0
1811 0 print $literal_callback $litstring;
1812 0 ▶ $litstring = "" unless ($emsg);
Branch: 1 branch
BranchTrueFalseTotal
unless $emsg 0 0 0
1813 }
1814 }
1815  
1816 0 ▶ $self->_debug( "Received ret="
Branch: 1 branch
BranchTrueFalseTotal
defined $ret ? : 0 0 0
1817 . ( defined($ret) ? $ret : "<undef>" )
1818 . " $litreadb of $expected_size" );
1819  
1820 # save errors and return
1821 0 ▶ if ($emsg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($emsg) 0 0 0
1822 0 $self->LastError($emsg);
1823 0 $self->_record(
1824 $transno,
1825 [
1826 $self->_next_index($transno), "ERROR",
1827 "$transno * NO $emsg"
1828 ]
1829 );
1830 0 ▶ $litstring = "" unless defined $litstring;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $litstring 0 0 0
1831 0 $self->_debug( "ERROR while processing LITERAL, "
1832 . " buffer=\n"
1833 . $litstring
1834 . "<END>\n" );
1835 0 return undef;
1836 }
1837 }
1838 }
1839  
1840 0 ▶ if ( defined $litstring ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $litstring) 0 0 0
1841 0 ▶ if ( $literal_cbtype eq "GLOB" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($literal_cbtype eq 'GLOB') { } 0 0 0
elsif ($literal_cbtype eq 'CODE') { } 0 0 0
1842 0 print $literal_callback $litstring;
1843 }
1844 elsif ( $literal_cbtype eq "CODE" ) {
1845 0 $literal_callback->($litstring);
1846 }
1847 }
1848  
1849 0 ▶ push @$oBuffer, [ $index++, 'LITERAL', $litstring ]
Branch: 1 branch
BranchTrueFalseTotal
if $literal_cbtype ne "GLOB" 0 0 0
1850 if ( $literal_cbtype ne "GLOB" );
1851 }
1852 }
1853  
1854 0 ▶ $self->_debug( "Read: " . join "", map { "\t" . $_->[DATA] } @$oBuffer )
Branch: 1 branch
BranchTrueFalseTotal
if $self->Debug 0 0 0
1855 if ( $self->Debug );
1856  
1857 0 ▶ @$oBuffer ? $oBuffer : undef;
Branch: 1 branch
BranchTrueFalseTotal
@$oBuffer ? : 0 0 0
1858 }
1859  
1860 0 ▶sub _sysread {
Subroutine _sysread: not called CC=2 SCAR=17.9
1861 0 my ( $self, $fh, $buf, $len, $off ) = @_;
1862 0 my $rm = $self->Readmethod;
1863 0 ▶ $rm ? $rm->(@_) : sysread( $fh, $$buf, $len, $off );
Branch: 1 branch
BranchTrueFalseTotal
$rm ? : 0 0 0
1864 }
1865  
1866 0 ▶sub _read_more {
Subroutine _read_more: not called CC=2 SCAR=17.9
1867 0 my $self = shift;
1868 0 my $rm = $self->Readmoremethod;
1869 0 ▶ $rm ? $rm->( $self, @_ ) : $self->__read_more(@_);
Branch: 1 branch
BranchTrueFalseTotal
$rm ? : 0 0 0
1870 }
1871  
1872 0 ▶sub __read_more {
Subroutine __read_more: not called CC=10 SCAR=47.0
1873 0 my $self = shift;
1874 0 ▶ my $opt = ref( $_[0] ) eq "HASH" ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
1875 0 my ( $socket, $timeout ) = @_;
1876  
1877 # IO::Socket::SSL buffers some data internally, so there might be some
1878 # data available from the previous sysread of which the file-handle
1879 # (used by select()) doesn't know of.
1880 0 ▶ return 1 if $socket->isa("IO::Socket::SSL") && $socket->pending;
Branch: 1 branch
BranchTrueFalseTotal
if $socket->isa("IO::Socket::SSL") and $socket->pending 0 0 0
Condition0%0/3
$socket->isa("IO::Socket::SSL") and $socket->pending
!ll&&!rl&&r
000
MC/DC0%0/2
$socket->isa("IO::Socket::SSL") and $socket->pending
$socket->isa("IO::Socket::SSL") $socket->pending
Truth table0%0/3
A and B
A= $socket->isa("IO::Socket::SSL")B= $socket->pending
ABresult
0X0
100
111
1881  
1882 0 my $rvec = '';
1883 0 vec( $rvec, fileno($socket), 1 ) = 1;
1884  
1885 0 my $rc = CORE::select( $rvec, undef, $rvec, $timeout );
1886  
1887 # fast track success
1888 0 ▶ return $rc if $rc > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $rc > 0 0 0 0
1889  
1890 # by default set an error on timeout
1891 my $err_on_timeout =
1892 0 ▶ exists $opt->{error_on_timeout} ? $opt->{error_on_timeout} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{'error_on_timeout'} ? : 0 0 0
1893  
1894 # $rc is 0 then we timed out
1895 0 ▶ return $rc if !$rc and !$err_on_timeout;
Branch: 1 branch
BranchTrueFalseTotal
unless $rc or $err_on_timeout 0 0 0
Condition0%0/3
$rc or $err_on_timeout
l!l&&r!l&&!r
000
MC/DC0%0/2
$rc or $err_on_timeout
$rc $err_on_timeout
Truth table0%0/3
A or B
A= $rcB= $err_on_timeout
ABresult
1X1
011
000
1896  
1897 # set the appropriate error and return
1898 0 my $transno = $self->Transaction;
1899 0 ▶ my $msg =
Branch: 2 branches
BranchTrueFalseTotal
$rc ? : 0 0 0
$! ? : 0 0 0
1900 ( $rc ? "error($rc)" : "timeout" )
1901 . " waiting ${timeout}s for data from server"
1902 . ( $! ? ": $!" : "" );
1903 0 $self->LastError($msg);
1904 0 $self->_record( $transno,
1905 [ $self->_next_index($transno), "ERROR", "$transno * NO $msg" ] );
1906 0 $self->_disconnect; # BUG: can not handle timeouts gracefully
1907 0 return $rc;
1908 }
1909  
1910 0 ▶sub _trans_index() {
Subroutine _trans_index: not called CC=1 SCAR=6.9
1911 0 sort { $a <=> $b } keys %{ $_[0]->{History} };
1912 }
1913  
1914 # all default to last transaction
1915 0 ▶sub _transaction(;$) {
Subroutine _transaction: not called CC=3 SCAR=24.8
1916 0 ▶ @{ $_[0]->{History}{ $_[1] || $_[0]->Transaction } || [] };
Condition0%0/5
$_[0]{'History'}{$_[1] or $_[0]->Transaction} || []
l!l
00
$_[1] || $_[0]->Transaction
l!l&&r!l&&!r
000
MC/DC0%0/1
$_[0]{'History'}{$_[1] or $_[0]->Transaction} || []
$_[0]{'History'}{$_[1] or $_[0]->Transaction}
MC/DC0%0/2
$_[1] || $_[0]->Transaction
$_[1] $_[0]->Transaction
Truth table0%0/2
A
A= $_[0]{'History'}{$_[1] or $_[0]->Transaction}
Aresult
11
00
Truth table0%0/3
A || B
A= $_[1]B= $_[0]->Transaction
ABresult
1X1
011
000
1917 }
1918  
1919 0 ▶sub _trans_data(;$) {
Subroutine _trans_data: not called CC=1 SCAR=6.9
1920 0 map { $_->[DATA] } $_[0]->_transaction( $_[1] );
1921 }
1922  
1923 0 ▶sub _escaped_trans_data(;$) {
Subroutine _escaped_trans_data: not called CC=6 SCAR=37.4
1924 0 my ( $self, $trans ) = @_;
1925 0 my @a;
1926 0 my $prevwasliteral = 0;
1927 0 foreach my $line ( $self->_transaction($trans) ) {
1928 0 ▶ next unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
1929  
1930 0 my $data = $line->[DATA];
1931  
1932 # literal is appended to previous data
1933 0 ▶ if ( $self->_is_literal($line) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_literal($line)) { } 0 0 0
1934 0 $data = $self->Escape($data);
1935 0 $a[-1] .= qq("$data");
1936 0 $prevwasliteral = 1;
1937 }
1938 else {
1939 0 ▶ if ($prevwasliteral) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prevwasliteral) { } 0 0 0
1940 0 $a[-1] .= $data;
1941 }
1942 else {
1943 0 push( @a, $data );
1944 }
1945 0 $prevwasliteral = 0;
1946 }
1947 }
1948  
1949 0 ▶ return wantarray ? @a : \@a;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1950 }
1951  
1952 0 ▶sub Report {
Subroutine Report: not called CC=1 SCAR=6.9
Pod documented
1953 0 my $self = shift;
1954 0 map { $self->_trans_data($_) } $self->_trans_index;
1955 }
1956  
1957 0 ▶sub LastIMAPCommand(;$) {
Subroutine LastIMAPCommand: not called CC=2 SCAR=17.9
Pod documented
1958 0 my ( $self, $trans ) = @_;
1959 0 my $msg = ( $self->_transaction($trans) )[0];
1960 0 ▶ $msg ? $msg->[DATA] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$msg ? : 0 0 0
1961 }
1962  
1963 0 ▶sub History(;$) {
Subroutine History: not called CC=2 SCAR=17.9
Pod documented
1964 0 my ( $self, $trans ) = @_;
1965 0 my ( $cmd, @a ) = $self->_trans_data($trans);
1966 0 ▶ return wantarray ? @a : \@a;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1967 }
1968  
1969 0 ▶sub Results(;$) {
Subroutine Results: not called CC=2 SCAR=17.9
Pod documented
1970 0 my ( $self, $trans ) = @_;
1971 0 my @a = $self->_trans_data($trans);
1972 0 ▶ return wantarray ? @a : \@a;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1973 }
1974  
1975 0 ▶sub _transaction_literals() {
Subroutine _transaction_literals: not called CC=1 SCAR=6.9
1976 0 my $self = shift;
1977 0 join '', map { $_->[DATA] }
1978 0 grep { $self->_is_literal($_) } $self->_transaction;
1979 }
1980  
1981 0 ▶sub Escaped_history {
Subroutine Escaped_history: not called CC=2 SCAR=17.9
Pod documented
1982 0 my ( $self, $trans ) = @_;
1983 0 my ( $cmd, @a ) = $self->_escaped_trans_data($trans);
1984 0 ▶ return wantarray ? @a : \@a;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1985 }
1986  
1987 0 ▶sub Escaped_results {
Subroutine Escaped_results: not called CC=2 SCAR=17.9
Pod documented
1988 0 my ( $self, $trans ) = @_;
1989 0 my @a = $self->_escaped_trans_data($trans);
1990 0 ▶ return wantarray ? @a : \@a;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1991 }
1992  
1993 1 ▶sub Escape {
Subroutine Escape: called CC=1 SCAR=0.0
Pod undocumented
1994 1 my $data = $_[1];
1995 1 $data =~ s/([\\\"])/\\$1/og;
1996 1 return $data;
1997 }
1998  
1999 0 ▶sub Unescape {
Subroutine Unescape: not called CC=1 SCAR=6.9
Pod undocumented
2000 0 my $data = $_[1];
2001 0 $data =~ s/\\([\\\"])/$1/og;
2002 0 return $data;
2003 }
2004  
2005 0 ▶sub logout {
Subroutine logout: not called CC=1 SCAR=6.9
Pod documented
2006 0 my $self = shift;
2007 0 my $rc = $self->_imap_command( "LOGOUT", "BYE" );
2008 0 $self->_disconnect;
2009 0 return $rc;
2010 }
2011  
2012 0 ▶sub _disconnect {
Subroutine _disconnect: not called CC=2 SCAR=17.9
2013 0 my $self = shift;
2014  
2015 0 delete $self->{CAPABILITY};
2016 0 delete $self->{_IMAP4REV1};
2017 0 $self->State(Unconnected);
2018 0 ▶ if ( my $sock = delete $self->{Socket} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sock = delete $self->{"Socket"}) 0 0 0
2019 0 local ($@);
2020 0 eval { $sock->close };
2021 }
2022 0 return $self;
2023 }
2024  
2025 # LIST/XLIST/LSUB Response
2026 # Contents: name attributes, hierarchy delimiter, name
2027 # Example: * LIST (\Noselect) "/" ~/Mail/foo
2028 # NOTE: liberal matching as folder name data may be Escape()d
2029 0 ▶sub _list_or_lsub_response_parse {
Subroutine _list_or_lsub_response_parse: not called CC=5 SCAR=34.0
2030 0 my ( $self, $resp ) = @_;
2031  
2032 0 ▶ return undef unless defined $resp;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $resp 0 0 0
2033 0 my %info;
2034  
2035 0 $resp =~ s/\015?\012$//;
2036 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($resp =~ / ^\* \s+ (?:LIST|XLIST|LSUB) \s+ # * LIST|XLIST|LSUB \( ([^\)]*) \) \s+ # (attrs) (?: \" ([^"]*) \" | NIL ) \s # "delimiter" or NIL (?:\s*\" (.*) \" | (.*) ) # "name" or name /xi) 0 0 0
2037 $resp =~ / ^\* \s+ (?:LIST|XLIST|LSUB) \s+ # * LIST|XLIST|LSUB
2038 \( ([^\)]*) \) \s+ # (attrs)
2039 (?: \" ([^"]*) \" | NIL ) \s # "delimiter" or NIL
2040 (?:\s*\" (.*) \" | (.*) ) # "name" or name
2041 /ix
2042 )
2043 {
2044 0 ▶ @info{qw(attrs delim name)} =
Branch: 1 branch
BranchTrueFalseTotal
defined $3 ? : 0 0 0
2045 ( [ split( / /, $1 ) ], $2, defined($3) ? $self->Unescape($3) : $4 );
2046 }
2047 0 ▶ return wantarray ? %info : \%info;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2048 }
2049  
2050 0 ▶sub exists {
Subroutine exists: not called CC=2 SCAR=17.9
Pod documented
2051 0 my ( $self, $folder ) = @_;
2052 0 ▶ $self->status($folder) ? $self : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->status($folder) ? : 0 0 0
2053 }
2054  
2055 # Updated to handle embedded literal strings
2056 0 ▶sub get_bodystructure {
Subroutine get_bodystructure: not called CC=11 SCAR=48.8
Pod documented
2057 0 my ( $self, $msg ) = @_;
2058  
2059 0 ▶ my $class = $self->_load_module("BodyStructure") or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $class = $self->_load_module("BodyStructure") or return undef 0 0 0
2060  
2061 0 ▶ my $out = $self->fetch( $msg, "BODYSTRUCTURE" ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $out = $self->fetch($msg, "BODYSTRUCTURE") or return undef 0 0 0
2062  
2063 0 my $bs = "";
2064 0 ▶ my $output = first { /BODYSTRUCTURE\s+\(/i } @$out;
Subroutine __ANON__: not called CC=1 SCAR=6.9
2065  
2066 0 ▶ unless ( $output =~ /$CRLF$/o ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($output =~ /$Mail::IMAPClient::CRLF$/o) 0 0 0
2067 0 $output = '';
2068 0 $self->_debug("get_bodystructure: reassembling original response");
2069 0 my $started = 0;
2070 0 foreach my $o ( $self->_transaction ) {
2071 0 ▶ next unless $self->_is_output_or_literal($o);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_output_or_literal($o) 0 0 0
2072 0 ▶ $started++ if $o->[DATA] =~ /BODYSTRUCTURE \(/i;
Branch: 1 branch
BranchTrueFalseTotal
if $o->[2] =~ /BODYSTRUCTURE \(/i 0 0 0
2073 0 ▶ $started or next;
Branch: 1 branch
BranchTrueFalseTotal
$started or next 0 0 0
2074  
2075 0 ▶ if ( length($output) && $self->_is_literal($o) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $output and $self->_is_literal($o)) { } 0 0 0
Condition0%0/3
length $output and $self->_is_literal($o)
!ll&&!rl&&r
000
MC/DC0%0/2
length $output and $self->_is_literal($o)
length $output $self->_is_literal($o)
Truth table0%0/3
A and B
A= length $outputB= $self->_is_literal($o)
ABresult
0X0
100
111
2076 0 my $data = $o->[DATA];
2077 0 $data =~ s/"/\\"/g;
2078 0 $data =~ s/\(/\\\(/g;
2079 0 $data =~ s/\)/\\\)/g;
2080 0 $output .= qq("$data");
2081 }
2082 else {
2083 0 $output .= $o->[DATA];
2084 }
2085 }
2086 0 $self->_debug("get_bodystructure: reassembled output=$output<END>");
2087 }
2088  
2089 {
2090 0 local ($@);
2091 0 $bs = eval { $class->new($output) };
2092 }
2093  
2094 $self->_debug(
2095 0 ▶ "get_bodystructure: msg $msg returns: " . ( $bs || "UNDEF" ) );
Condition0%0/2
$bs || 'UNDEF'
l!l
00
MC/DC0%0/1
$bs || 'UNDEF'
$bs
Truth table0%0/2
A
A= $bs
Aresult
11
00
2096 0 $bs;
2097 }
2098  
2099 # Updated to handle embedded literal strings
2100 0 ▶sub get_envelope {
Subroutine get_envelope: not called CC=11 SCAR=48.8
Pod documented
2101 0 my ( $self, $msg ) = @_;
2102  
2103 # Envelope class is defined within BodyStructure
2104 0 ▶ my $class = $self->_load_module("BodyStructure") or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $class = $self->_load_module("BodyStructure") or return undef 0 0 0
2105 0 $class .= "::Envelope";
2106  
2107 0 ▶ my $out = $self->fetch( $msg, 'ENVELOPE' ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $out = $self->fetch($msg, "ENVELOPE") or return undef 0 0 0
2108  
2109 0 my $bs = "";
2110 0 ▶ my $output = first { /ENVELOPE \(/i } @$out;
Subroutine __ANON__: not called CC=1 SCAR=6.9
2111  
2112 0 ▶ unless ( $output =~ /$CRLF$/o ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($output =~ /$Mail::IMAPClient::CRLF$/o) 0 0 0
2113 0 $output = '';
2114 0 $self->_debug("get_envelope: reassembling original response");
2115 0 my $started = 0;
2116 0 foreach my $o ( $self->_transaction ) {
2117 0 ▶ next unless $self->_is_output_or_literal($o);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_output_or_literal($o) 0 0 0
2118 0 ▶ $started++ if $o->[DATA] =~ /ENVELOPE \(/i;
Branch: 1 branch
BranchTrueFalseTotal
if $o->[2] =~ /ENVELOPE \(/i 0 0 0
2119 0 ▶ $started or next;
Branch: 1 branch
BranchTrueFalseTotal
$started or next 0 0 0
2120  
2121 0 ▶ if ( length($output) && $self->_is_literal($o) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $output and $self->_is_literal($o)) { } 0 0 0
Condition0%0/3
length $output and $self->_is_literal($o)
!ll&&!rl&&r
000
MC/DC0%0/2
length $output and $self->_is_literal($o)
length $output $self->_is_literal($o)
Truth table0%0/3
A and B
A= length $outputB= $self->_is_literal($o)
ABresult
0X0
100
111
2122 0 my $data = $o->[DATA];
2123 0 $data =~ s/"/\\"/g;
2124 0 $data =~ s/\(/\\\(/g;
2125 0 $data =~ s/\)/\\\)/g;
2126 0 $output .= qq("$data");
2127 }
2128 else {
2129 0 $output .= $o->[DATA];
2130 }
2131 }
2132 0 $self->_debug("get_envelope: reassembled output=$output<END>");
2133 }
2134  
2135 {
2136 0 local ($@);
2137 0 $bs = eval { $class->new($output) };
2138 }
2139  
2140 0 ▶ $self->_debug( "get_envelope: msg $msg returns: " . ( $bs || "UNDEF" ) );
Condition0%0/2
$bs || 'UNDEF'
l!l
00
MC/DC0%0/1
$bs || 'UNDEF'
$bs
Truth table0%0/2
A
A= $bs
Aresult
11
00
2141 0 $bs;
2142 }
2143  
2144 # fetch( [{option},] [$seq_set|ALL], @msg_data_items )
2145 # options:
2146 # escaped => 0|1 # return Results or Escaped_results
2147 0 ▶sub fetch {
Subroutine fetch: not called CC=14 SCAR=53.5
Pod documented
2148 0 my $self = shift;
2149 0 ▶ my $opt = ref( $_[0] ) eq "HASH" ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
2150 0 ▶ my $what = shift || "ALL";
Condition0%0/2
shift() || 'ALL'
l!l
00
MC/DC0%0/1
shift() || 'ALL'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
2151  
2152 0 my $take = $what;
2153 0 ▶ if ( $what eq 'ALL' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($what eq 'ALL') { } 0 0 0
elsif (ref $what or $what =~ /^[,:\d]+\w*$/) { } 0 0 0
2154 0 ▶ my $msgs = $self->messages or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $msgs = $self->messages or return undef 0 0 0
2155 0 $take = $self->Range($msgs);
2156 }
2157 ▶ elsif ( ref $what || $what =~ /^[,:\d]+\w*$/ ) {
Condition0%0/3
ref $what or $what =~ /^[,:\d]+\w*$/
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $what or $what =~ /^[,:\d]+\w*$/
ref $what $what =~ /^[,:\d]+\w*$/
Truth table0%0/3
A or B
A= ref $whatB= $what =~ /^[,:\d]+\w*$/
ABresult
1X1
011
000
2158 0 $take = $self->Range($what);
2159 }
2160  
2161 0 my ( @data, $cmd );
2162 0 my ( $seq_set, @fetch_att ) = $self->_split_sequence( $take, "FETCH", @_ );
2163  
2164 0 ▶ for ( my $x = 0 ; $x <= $#$seq_set ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x <= $seq_set->$#*) 0 0 0
2165 0 my $seq = $seq_set->[$x];
2166 0 ▶ $self->_imap_uid_command( FETCH => $seq, @fetch_att, @_ )
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_uid_command("FETCH", $seq, @fetch_att, @_) or return undef 0 0 0
2167 or return undef;
2168 0 ▶ my $res = $opt->{escaped} ? $self->Escaped_results : $self->Results;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'escaped'} ? : 0 0 0
2169  
2170 # only keep last command and last response (* OK ...)
2171 0 $cmd = shift(@$res);
2172 0 ▶ pop(@$res) if ( $x != $#{$seq_set} );
Branch: 1 branch
BranchTrueFalseTotal
if $x != $#{$seq_set;} 0 0 0
2173 0 push( @data, @$res );
2174 }
2175  
2176 0 ▶ if ( $cmd and !wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd and not wantarray) 0 0 0
Condition0%0/3
$cmd and not wantarray
!ll&&!rl&&r
000
MC/DC0%0/2
$cmd and not wantarray
$cmd not wantarray
Truth table0%0/3
A and not(B)
A= $cmdB= not wantarray
ABresult
0X0
100
111
2177 0 $cmd =~ s/^(\d+\s+.*?FETCH\s+)\S+(\s*)/$1$take$2/;
2178 0 unshift( @data, $cmd );
2179 }
2180  
2181 #wantarray ? $self->History : $self->Results;
2182 0 ▶ return wantarray ? @data : \@data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2183 }
2184  
2185 # Some servers have a maximum command length. If Maxcommandlength is
2186 # set, split a sequence to fit within the length restriction.
2187 0 ▶sub _split_sequence {
Subroutine _split_sequence: not called CC=7 SCAR=40.3
2188 0 my ( $self, $take, @args ) = @_;
2189  
2190 # split take => sequence-set and (optional) fetch-att
2191 0 my ( $seq, @att ) = split( / /, $take, 2 );
2192  
2193 # use the entire sequence unless Maxcommandlength is set
2194 0 my @seqs;
2195 0 my $maxl = $self->Maxcommandlength;
2196 0 ▶ if ($maxl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($maxl) { } 0 0 0
2197  
2198 # estimate command length, the sum of the lengths of:
2199 # tag, command, fetch-att + $CRLF
2200 0 ▶ push @args, $self->Transaction, $self->Uid ? "UID" : (), "\015\012";
Branch: 1 branch
BranchTrueFalseTotal
$self->Uid ? : 0 0 0
2201  
2202 # do not split on anything smaller than 64 chars
2203 0 my $clen = length join( " ", @att, @args );
2204 0 my $diff = $maxl - $clen;
2205 0 ▶ my $most = $diff > 64 ? $diff : 64;
Branch: 1 branch
BranchTrueFalseTotal
$diff > 64 ? : 0 0 0
2206  
2207 0 ▶ @seqs = ( $seq =~ m/(.{1,$most})(?:,|$)/g ) if defined $seq;
Branch: 1 branch
BranchTrueFalseTotal
if defined $seq 0 0 0
2208 0 ▶ $self->_debug( "split_sequence: length($maxl-$clen) parts: ",
Branch: 1 branch
BranchTrueFalseTotal
if $#seqs != 0 0 0 0
2209 $#seqs + 1 )
2210 if ( $#seqs != 0 );
2211 }
2212 else {
2213 0 ▶ push( @seqs, $seq ) if defined $seq;
Branch: 1 branch
BranchTrueFalseTotal
if defined $seq 0 0 0
2214 }
2215 0 return \@seqs, @att;
2216 }
2217  
2218 # fetch_hash( [$seq_set|ALL], @msg_data_items, [\%msg_by_ids] )
2219 # - TODO: make more efficient use of memory on large fetch results
2220 27 ▶sub fetch_hash {
Subroutine fetch_hash: called CC=32 SCAR=38.1
Pod documented
2221 27 my $self = shift;
2222 27 ▶ my $uids = ref $_[-1] ? pop @_ : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[-1] ? : 0 27 27
2223 27 my @words = @_;
2224  
2225 # take an optional leading list of messages argument or default to
2226 # ALL let fetch turn that list of messages into a msgref as needed
2227 # fetch has similar logic for dealing with message list
2228 27 my $msgs = 'ALL';
2229 27 ▶ if ( defined $words[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $words[0]) 27 0 27
2230 27 ▶ if ( ref $words[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $words[0]) { } 27 0 27
2231 27 $msgs = shift @words;
2232 }
2233 else {
2234 0 ▶ if ( $words[0] eq 'ALL' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($words[0] eq 'ALL') { } 0 0 0
elsif ($words[0] =~ s/^([*,:\d]+)\s*//) { } 0 0 0
2235 0 $msgs = shift @words;
2236 }
2237 elsif ( $words[0] =~ s/^([*,:\d]+)\s*// ) {
2238 0 $msgs = $1;
2239 0 ▶ shift @words if $words[0] eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $words[0] eq "" 0 0 0
2240 }
2241 }
2242 }
2243  
2244 # message list (if any) is now removed from @words
2245 27 ▶ my $what = ( @words > 1 or $words[0] =~ /\s/ ) ? "(@words)" : "@words";
Branch: 1 branch
BranchTrueFalseTotal
@words > 1 || $words[0] =~ /\s/ ? : 7 20 27
Condition100%3/3
@words > 1 or $words[0] =~ /\s/
l!l&&r!l&&!r
6120
MC/DC100%2/2
@words > 1 or $words[0] =~ /\s/
@words > 1 $words[0] =~ /\s/
Truth table100%3/3
A or B
A= @words > 1B= $words[0] =~ /\s/
ABresult
1X1
011
000
2246  
2247 # RFC 3501:
2248 # fetch = "FETCH" SP sequence-set SP ("ALL" / "FULL" / "FAST" /
2249 # fetch-att / "(" fetch-att *(SP fetch-att) ")")
2250 27 ▶ my $output = $self->fetch( $msgs, $what )
Branch: 1 branch
BranchTrueFalseTotal
my $output = $self->fetch($msgs, $what) or return undef 27 0 27
2251 or return undef;
2252  
2253 27 my $asked_for_uid = $what =~ /[\s(]UID[)\s]/i;
2254  
2255 27 ▶ while ( my $l = shift @$output ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $l = shift @$output) 27 27 54
2256 27 ▶ next if $l !~ m/^\*\s(\d+)\sFETCH\s\(/g;
Branch: 1 branch
BranchTrueFalseTotal
unless $l =~ /^\*\s(\d+)\sFETCH\s\(/g 0 27 27
2257 27 my ( $mid, $entry ) = ( $1, {} );
2258 27 my ( $key, $value );
2259 ATTR:
2260 27 ▶ while ( $l and $l !~ m/\G\s*\)\s*$/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l and not $l =~ /\G\s*\)\s*$/cg) 42 27 69
Condition100%3/3
$l and not $l =~ /\G\s*\)\s*$/cg
!ll&&!rl&&r
22542
MC/DC100%2/2
$l and not $l =~ /\G\s*\)\s*$/cg
$l not $l =~ /\G\s*\)\s*$/cg
Truth table100%3/3
A and not(B)
A= $lB= not $l =~ /\G\s*\)\s*$/cg
ABresult
0X0
100
111
2261 42 ▶ if ( $l =~ m/\G\s*([^\s\[]+(?:\[[^\]]*\])?(?:<[^>]*>)?)\s*/gc ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($l =~ /\G\s*([^\s\[]+(?:\[[^\]]*\])?(?:<[^>]*>)?)\s*/cg) { } 42 0 42
elsif (not defined $key) { } 0 0 0
2262 42 $key = uc($1);
2263  
2264 # strip quotes around header names - seen w/outlook.com
2265 42 ▶ if ( $key =~ /^BODY\[HEADER\.FIELDS \("[^"]+".*?\)\]$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^BODY\[HEADER\.FIELDS \("[^"]+".*?\)\]$/) 1 41 42
2266 1 $key =~ s/"//g;
2267 }
2268 }
2269 elsif ( !defined $key ) {
2270  
2271 # some kind of malformed response
2272 0 $self->LastError("Invalid item name in FETCH response: $l");
2273 0 return undef;
2274 }
2275 42 ▶ if ( $l =~ m/\G\s*$/gc ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($l =~ /\G\s*$/cg) { } 8 34 42
elsif ($l =~ /\G(?:"((?>(?:(?>[^"\\]+)|\\.)*))"|([^()\s]+))\s*/cg) { } 18 16 34
elsif ($l =~ /\G\(/cg) { } 16 0 16
2276 8 $value = shift @$output;
2277 8 $entry->{$key} = $value;
2278 8 $l = shift @$output;
2279 8 next ATTR;
2280 }
2281 elsif (
2282 $l =~ m/\G(?:"((?>(?:(?>[^"\\]+)|\\.)*))"|([^()\s]+))\s*/gc )
2283 {
2284 18 ▶ $value = defined $1 ? $1 : $2;
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 4 14 18
2285 18 $entry->{$key} = $value;
2286 18 next ATTR;
2287 }
2288 elsif ( $l =~ m/\G\(/gc ) {
2289 16 my $depth = 1;
2290 16 $value = "";
2291 16 ▶ while ( $l =~
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\G("((?>(?:(?>[^"\\]+)|\\.)*))"\s*|[()]|[^()"]+)/cg) 135 0 135
2292 m/\G("((?>(?:(?>[^"\\]+)|\\.)*))"\s*|[()]|[^()"]+)/gc )
2293 {
2294 135 my $stuff = $1;
2295 135 ▶ if ( $stuff eq "(" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($stuff eq '(') { } 23 112 135
elsif ($stuff eq ')') { } 39 73 112
2296 23 $depth++;
2297 23 $value .= "(";
2298 }
2299 elsif ( $stuff eq ")" ) {
2300 39 $depth--;
2301 39 ▶ if ( $depth == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth == 0) 16 23 39
2302 16 $entry->{$key} = $value;
2303 16 next ATTR;
2304 }
2305 23 $value .= ")";
2306 }
2307 else {
2308 73 $value .= $stuff;
2309 }
2310  
2311 # consume literal data if any
2312 119 ▶ if ( $l =~ m/\G\s*$/gc and scalar(@$output) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\G\s*$/cg and scalar @$output) 1 118 119
Condition100%2/2
$l =~ /\G\s*$/cg and scalar @$output
!ll
1181
MC/DC100%1/1
$l =~ /\G\s*$/cg and scalar @$output
$l =~ /\G\s*$/cg
Truth table100%2/2
A
A= $l =~ /\G\s*$/cg
Aresult
00
11
2313 1 my $elit = $self->Escape( shift @$output );
2314 1 $l = shift @$output;
2315 1 ▶ $value .= ( length($value) ? " " : "" ) . qq{"$elit"};
Branch: 1 branch
BranchTrueFalseTotal
length $value ? : 1 0 1
2316 }
2317 }
2318 0 $l =~ m/\G\s*/gc;
2319 }
2320 else {
2321 0 $self->LastError("Invalid item value in FETCH response: $l");
2322 0 return undef;
2323 }
2324 }
2325  
2326 # NOTE: old code tried to remove any "unrequested" data in $entry
2327 # - UID is sometimes not explicitly requested, are there others?
2328 # - rt#115726: Uid and $entry->{UID} not set, ignore unsolicited data
2329 27 ▶ if ( $self->Uid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Uid) { } 4 23 27
2330 4 ▶ if ( $entry->{UID} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry->{'UID'}) { } 4 0 4
2331 4 $uids->{ $entry->{UID} } = $entry;
2332 4 ▶ delete $entry->{UID} unless $asked_for_uid;
Branch: 1 branch
BranchTrueFalseTotal
unless $asked_for_uid 2 2 4
2333 }
2334 else {
2335 0 $self->_debug("ignoring unsolicited response: $l");
2336 }
2337 }
2338 else {
2339 23 $uids->{$mid} = $entry;
2340 }
2341 }
2342  
2343 27 ▶ return wantarray ? %$uids : $uids;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 27 27
2344 }
2345  
2346 0 ▶sub store {
Subroutine store: not called CC=3 SCAR=24.8
Pod documented
2347 0 my ( $self, @a ) = @_;
2348 0 ▶ $self->_imap_uid_command( STORE => @a )
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_uid_command("STORE", @a) or return undef 0 0 0
2349 or return undef;
2350 0 ▶ return wantarray ? $self->History : $self->Results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2351 }
2352  
2353 0 ▶sub _imap_folder_command($$@) {
Subroutine _imap_folder_command: not called CC=3 SCAR=24.8
2354 0 my ( $self, $command ) = ( shift, shift );
2355 0 my $folder = $self->Quote(shift);
2356  
2357 0 ▶ $self->_imap_command( join ' ', $command, $folder, @_ )
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command(join(" ", $command, $folder, @_)) or return undef 0 0 0
2358 or return undef;
2359  
2360 0 ▶ return wantarray ? $self->History : $self->Results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2361 }
2362  
2363 0 ▶sub subscribe($) { shift->_imap_folder_command( SUBSCRIBE => @_ ) }
Subroutine subscribe: not called CC=1 SCAR=6.9
Pod documented
2364 0 ▶sub unsubscribe($) { shift->_imap_folder_command( UNSUBSCRIBE => @_ ) }
Subroutine unsubscribe: not called CC=1 SCAR=6.9
Pod undocumented
2365 0 ▶sub create($) { shift->_imap_folder_command( CREATE => @_ ) }
Subroutine create: not called CC=1 SCAR=6.9
Pod documented
2366  
2367 0 ▶sub delete($) {
Subroutine delete: not called CC=3 SCAR=24.8
Pod documented
2368 0 my $self = shift;
2369 0 ▶ $self->_imap_folder_command( DELETE => @_ ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_folder_command("DELETE", @_) or return undef 0 0 0
2370 0 $self->Folder(undef);
2371 0 ▶ return wantarray ? $self->History : $self->Results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2372 }
2373  
2374 # rfc2086
2375 0 ▶sub myrights($) { $_[0]->_imap_folder_command( MYRIGHTS => $_[1] ) }
Subroutine myrights: not called CC=1 SCAR=6.9
Pod undocumented
2376  
2377 0 ▶sub close {
Subroutine close: not called CC=3 SCAR=24.8
Pod documented
2378 0 my $self = shift;
2379 0 ▶ $self->_imap_command('CLOSE')
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command("CLOSE") or return undef 0 0 0
2380 or return undef;
2381 0 ▶ return wantarray ? $self->History : $self->Results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2382 }
2383  
2384 0 ▶sub expunge {
Subroutine expunge: not called CC=11 SCAR=48.8
Pod documented
2385 0 my ( $self, $folder ) = @_;
2386  
2387 0 ▶ return undef unless ( defined $folder or defined $self->Folder );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $folder or defined $self->Folder 0 0 0
Condition0%0/3
defined $folder or defined $self->Folder
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $folder or defined $self->Folder
defined $folder defined $self->Folder
Truth table0%0/3
A or B
A= defined $folderB= defined $self->Folder
ABresult
1X1
011
000
2388  
2389 0 ▶ my $old = defined $self->Folder ? $self->Folder : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->Folder ? : 0 0 0
2390  
2391 0 ▶ if ( !defined($folder) || $folder eq $old ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $folder or $folder eq $old) { } 0 0 0
Condition0%0/3
not defined $folder or $folder eq $old
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $folder or $folder eq $old
not defined $folder $folder eq $old
Truth table0%0/3
not(A) or B
A= not defined $folderB= $folder eq $old
ABresult
1X1
011
000
2392 0 ▶ $self->_imap_command('EXPUNGE')
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command("EXPUNGE") or return undef 0 0 0
2393 or return undef;
2394 }
2395 else {
2396 0 ▶ $self->select($folder) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->select($folder) or return undef 0 0 0
2397 0 my $succ = $self->_imap_command('EXPUNGE');
2398  
2399 # if $old eq '' IMAP4 select should close $folder without EXPUNGE
2400 0 ▶ return undef unless ( $self->select($old) and $succ );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->select($old) and $succ 0 0 0
Condition0%0/3
$self->select($old) and $succ
!ll&&!rl&&r
000
MC/DC0%0/2
$self->select($old) and $succ
$self->select($old) $succ
Truth table0%0/3
A and B
A= $self->select($old)B= $succ
ABresult
0X0
100
111
2401 }
2402  
2403 0 ▶ return wantarray ? $self->History : $self->Results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2404 }
2405  
2406 0 ▶sub uidexpunge {
Subroutine uidexpunge: not called CC=11 SCAR=48.8
Pod documented
2407 0 my ( $self, $msgspec ) = ( shift, shift );
2408  
2409 0 ▶ return undef unless $self->has_capability("UIDPLUS");
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_capability("UIDPLUS") 0 0 0
2410 0 ▶ unless ( $self->Uid ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->Uid) 0 0 0
2411 0 $self->LastError("Uid must be enabled for uidexpunge");
2412 0 return undef;
2413 }
2414  
2415 0 ▶ my $msg =
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($msgspec, 'Mail::IMAPClient::MessageSet') ? : 0 0 0
2416 UNIVERSAL::isa( $msgspec, 'Mail::IMAPClient::MessageSet' )
2417 ? $msgspec
2418 : $self->Range($msgspec);
2419  
2420 0 ▶ $msg->cat(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
2421  
2422 0 my ( @data, $cmd );
2423 0 my ($seq_set) = $self->_split_sequence( $msg, "UID EXPUNGE" );
2424  
2425 0 ▶ for ( my $x = 0 ; $x <= $#$seq_set ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x <= $seq_set->$#*) 0 0 0
2426 0 my $seq = $seq_set->[$x];
2427 0 ▶ $self->_imap_uid_command( "EXPUNGE" => $seq )
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_uid_command("EXPUNGE", $seq) or return undef 0 0 0
2428 or return undef;
2429 0 my $res = $self->Results;
2430  
2431 # only keep last command and last response (* OK ...)
2432 0 $cmd = shift(@$res);
2433 0 ▶ pop(@$res) if ( $x != $#{$seq_set} );
Branch: 1 branch
BranchTrueFalseTotal
if $x != $#{$seq_set;} 0 0 0
2434 0 push( @data, @$res );
2435 }
2436  
2437 0 ▶ if ( $cmd and !wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd and not wantarray) 0 0 0
Condition0%0/3
$cmd and not wantarray
!ll&&!rl&&r
000
MC/DC0%0/2
$cmd and not wantarray
$cmd not wantarray
Truth table0%0/3
A and not(B)
A= $cmdB= not wantarray
ABresult
0X0
100
111
2438 0 $cmd =~ s/^(\d+\s+.*?EXPUNGE\s+)\S+(\s*)/$1$msg$2/;
2439 0 unshift( @data, $cmd );
2440 }
2441  
2442 #wantarray ? $self->History : $self->Results;
2443 0 ▶ return wantarray ? @data : \@data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2444 }
2445  
2446 0 ▶sub rename {
Subroutine rename: not called CC=2 SCAR=17.9
Pod documented
2447 0 my ( $self, $from, $to ) = @_;
2448  
2449 0 $from = $self->Quote($from);
2450 0 $to = $self->Quote($to);
2451  
2452 0 ▶ $self->_imap_command(qq(RENAME $from $to)) ? $self : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command("RENAME $from $to") ? : 0 0 0
2453 }
2454  
2455 0 ▶sub status {
Subroutine status: not called CC=5 SCAR=34.0
Pod documented
2456 0 my ( $self, $folder ) = ( shift, shift );
2457 0 ▶ defined $folder or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $folder or return undef 0 0 0
2458  
2459 0 ▶ my $which = @_ ? join( " ", @_ ) : 'MESSAGES';
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
2460  
2461 0 my $box = $self->Quote($folder);
2462 0 ▶ $self->_imap_command("STATUS $box ($which)")
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command("STATUS $box ($which)") or return undef 0 0 0
2463 or return undef;
2464  
2465 0 ▶ return wantarray ? $self->History : $self->Results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2466 }
2467  
2468 0 ▶sub flags {
Subroutine flags: not called CC=11 SCAR=48.8
Pod documented
2469 0 my ( $self, $msgspec ) = ( shift, shift );
2470 0 ▶ my $msg =
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($msgspec, 'Mail::IMAPClient::MessageSet') ? : 0 0 0
2471 UNIVERSAL::isa( $msgspec, 'Mail::IMAPClient::MessageSet' )
2472 ? $msgspec
2473 : $self->Range($msgspec);
2474  
2475 0 ▶ $msg->cat(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
2476  
2477 # Send command
2478 0 ▶ my $ref = $self->fetch( $msg, "FLAGS" ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $ref = $self->fetch($msg, "FLAGS") or return undef 0 0 0
2479  
2480 0 my $u_f = $self->Uid;
2481 0 my $flagset = {};
2482  
2483 # Parse results, setting entry in result hash for each line
2484 0 foreach my $line (@$ref) {
2485 0 $self->_debug("flags: line = '$line'");
2486 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\* \s+ (\d+) \s+ FETCH \s+ # * nnn FETCH \( (?:\s* UID \s+ (\d+) \s* )? # optional: UID nnn <space> FLAGS \s* \( (.*?) \) \s* # FLAGS (\Flag1 \Flag2) <space> (?:\s* UID \s+ (\d+) \s* )? # optional: UID nnn \) /x) 0 0 0
2487 $line =~ /\* \s+ (\d+) \s+ FETCH \s+ # * nnn FETCH
2488 \(
2489 (?:\s* UID \s+ (\d+) \s* )? # optional: UID nnn <space>
2490 FLAGS \s* \( (.*?) \) \s* # FLAGS (\Flag1 \Flag2) <space>
2491 (?:\s* UID \s+ (\d+) \s* )? # optional: UID nnn
2492 \)
2493 /x
2494 )
2495 {
2496 0 ▶ my $mailid = $u_f ? ( $2 || $4 ) : $1;
Branch: 1 branch
BranchTrueFalseTotal
$u_f ? : 0 0 0
Condition0%0/3
$2 or $4
l!l&&r!l&&!r
000
MC/DC0%0/2
$2 or $4
$2 $4
Truth table0%0/3
A or B
A= $2B= $4
ABresult
1X1
011
000
2497 0 $flagset->{$mailid} = [ split " ", $3 ];
2498 }
2499 }
2500  
2501 # Return a hash from msgid to flag array?
2502 0 ▶ return $flagset
Branch: 1 branch
BranchTrueFalseTotal
if ref $msgspec 0 0 0
2503 if ref $msgspec;
2504  
2505 # Or, just one response? Return it if so
2506 0 my $flagsref = $flagset->{$msgspec};
2507 0 ▶ return wantarray ? @{ $flagsref || [] } : $flagsref;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
Condition0%0/2
$flagsref || []
l!l
00
MC/DC0%0/1
$flagsref || []
$flagsref
Truth table0%0/2
A
A= $flagsref
Aresult
11
00
2508 }
2509  
2510 # reduce a list, stripping undeclared flags. Flags with or without
2511 # leading backslash.
2512 0 ▶sub supported_flags(@) {
Subroutine supported_flags: not called CC=4 SCAR=30.0
Pod undocumented
2513 0 my $self = shift;
2514 0 ▶ my $sup = $self->Supportedflags
Branch: 1 branch
BranchTrueFalseTotal
my $sup = $self->Supportedflags or return @_ 0 0 0
2515 or return @_;
2516  
2517 0 ▶ return map { $sup->($_) } @_
Branch: 1 branch
BranchTrueFalseTotal
if ref $sup eq "CODE" 0 0 0
2518 if ref $sup eq 'CODE';
2519  
2520 0 ▶ grep { $sup->{ /^\\(\S+)/ ? lc $1 : () } } @_;
Branch: 1 branch
BranchTrueFalseTotal
/^\\(\S+)/ ? : 0 0 0
2521 }
2522  
2523 0 ▶sub parse_headers {
Subroutine parse_headers: not called CC=23 SCAR=63.1
Pod documented
2524 0 my ( $self, $msgspec, @fields ) = @_;
2525 0 my $fields = join ' ', @fields;
2526 0 ▶ my $msg = ref $msgspec eq 'ARRAY' ? $self->Range($msgspec) : $msgspec;
Branch: 1 branch
BranchTrueFalseTotal
ref $msgspec eq 'ARRAY' ? : 0 0 0
2527 0 ▶ my $peek = !defined $self->Peek || $self->Peek ? '.PEEK' : '';
Branch: 1 branch
BranchTrueFalseTotal
!defined($self->Peek) || $self->Peek ? : 0 0 0
Condition0%0/3
not defined $self->Peek or $self->Peek
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $self->Peek or $self->Peek
not defined $self->Peek $self->Peek
Truth table0%0/3
not(A) or B
A= not defined $self->PeekB= $self->Peek
ABresult
1X1
011
000
2528  
2529 0 ▶ my $string = "$msg BODY$peek"
Branch: 1 branch
BranchTrueFalseTotal
$fields eq 'ALL' ? : 0 0 0
2530 . ( $fields eq 'ALL' ? '[HEADER]' : "[HEADER.FIELDS ($fields)]" );
2531  
2532 0 ▶ my $raw = $self->fetch($string) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $raw = $self->fetch($string) or return undef 0 0 0
2533 0 my $cmd = shift @$raw;
2534  
2535 0 my %headers; # message ids to headers
2536 my $h; # fields for current msgid
2537 0 my $field; # previous field name, for unfolding
2538 0 my %fieldmap = map { ( lc($_) => $_ ) } @fields;
2539 0 my $msgid;
2540  
2541 # BUG: parsing this way is prone to be buggy but works most of the time
2542 # some example responses:
2543 # * OK Message 1 no longer exists
2544 # * 1 FETCH (UID 26535 BODY[HEADER] "")
2545 # * 5 FETCH (UID 30699 BODY[HEADER] {1711}
2546 # header: value...
2547 0 foreach my $header ( map { split /$CR?$LF/o } @$raw ) {
2548  
2549 # Windows2003/Maillennium/others? have UID after headers
2550 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($header =~ s/^\* \s+ (\d+) \s+ FETCH \s+ \( (.*?) BODY\[HEADER (?:\.FIELDS)? .*? \]\s*//xi) 0 0 0
2551 $header =~ s/^\* \s+ (\d+) \s+ FETCH \s+
2552 \( (.*?) BODY\[HEADER (?:\.FIELDS)? .*? \]\s*//ix
2553 )
2554 { # start new message header
2555 0 ( $msgid, my $msgattrs ) = ( $1, $2 );
2556 0 $h = {};
2557 0 ▶ if ( $self->Uid ) { # undef when win2003
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Uid) 0 0 0
2558 0 ▶ $msgid = $msgattrs =~ m/\b UID \s+ (\d+)/x ? $1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$msgattrs =~ /\b UID \s+ (\d+)/x ? : 0 0 0
2559 }
2560 0 ▶ $headers{$msgid} = $h if $msgid;
Branch: 1 branch
BranchTrueFalseTotal
if $msgid 0 0 0
2561 }
2562 0 ▶ $header =~ /\S/ or next; # skip empty lines.
Branch: 1 branch
BranchTrueFalseTotal
$header =~ /\S/ or next 0 0 0
2563  
2564 # ( for vi
2565 0 ▶ if ( $header =~ /^\)/ ) { # end of this message
Branch: 2 branches
BranchTrueFalseTotal
if ($header =~ /^\)/) { } 0 0 0
elsif (not $msgid and $header =~ /^\s*UID\s+(\d+).*\)$/) { } 0 0 0
2566 0 undef $h; # inbetween headers
2567 0 next;
2568 }
2569 ▶ elsif ( !$msgid && $header =~ /^\s*UID\s+(\d+).*\)$/ ) {
Condition0%0/3
not $msgid and $header =~ /^\s*UID\s+(\d+).*\)$/
!ll&&!rl&&r
000
MC/DC0%0/2
not $msgid and $header =~ /^\s*UID\s+(\d+).*\)$/
not $msgid $header =~ /^\s*UID\s+(\d+).*\)$/
Truth table0%0/3
not(A) and B
A= not $msgidB= $header =~ /^\s*UID\s+(\d+).*\)$/
ABresult
0X0
100
111
2570 0 $headers{$1} = $h; # found UID win2003/Maillennium
2571  
2572 0 undef $h;
2573 0 next;
2574 }
2575  
2576 0 ▶ unless ( defined $h ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $h) 0 0 0
2577 0 $self->_debug("found data between fetch headers: $header");
2578 0 next;
2579 }
2580  
2581 0 ▶ if ( $header and $header =~ s/^(\S+?)\:\s*// ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($header and $header =~ s/^(\S+?)\:\s*//) { } 0 0 0
elsif ($field and ref $h->{$field} eq 'ARRAY') { } 0 0 0
Condition0%0/3
$header and $header =~ s/^(\S+?)\:\s*//
!ll&&!rl&&r
000
MC/DC0%0/2
$header and $header =~ s/^(\S+?)\:\s*//
$header $header =~ s/^(\S+?)\:\s*//
Truth table0%0/3
A and B
A= $headerB= $header =~ s/^(\S+?)\:\s*//
ABresult
0X0
100
111
2582 0 ▶ $field = $fieldmap{ lc $1 } || $1;
Condition0%0/3
$fieldmap{lc $1} || $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$fieldmap{lc $1} || $1
$fieldmap{lc $1} $1
Truth table0%0/3
A || B
A= $fieldmap{lc $1}B= $1
ABresult
1X1
011
000
2583 0 push @{ $h->{$field} }, $header;
2584 }
2585 ▶ elsif ( $field and ref $h->{$field} eq 'ARRAY' ) { # folded header
Condition0%0/3
$field and ref $h->{$field} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$field and ref $h->{$field} eq "ARRAY"
$field ref $h->{$field} eq "ARRAY"
Truth table0%0/3
A and B
A= $fieldB= ref $h->{$field} eq "ARRAY"
ABresult
0X0
100
111
2586 0 $h->{$field}[-1] .= $header;
2587 }
2588 else {
2589  
2590 # show data if it is not like '"")' or '{123}'
2591 0 ▶ $self->_debug("non-header data between fetch headers: $header")
Branch: 1 branch
BranchTrueFalseTotal
unless $header =~ /^(?:\s*\"\"\)|\{\d+\})$Mail::IMAPClient::CR?$Mail::IMAPClient::LF$/o 0 0 0
2592 if ( $header !~ /^(?:\s*\"\"\)|\{\d+\})$CR?$LF$/o );
2593 }
2594 }
2595  
2596 # if we asked for one message, just return its hash,
2597 # otherwise, return hash of numbers => header hash
2598 0 ▶ ref $msgspec eq 'ARRAY' ? \%headers : $headers{$msgspec};
Branch: 1 branch
BranchTrueFalseTotal
ref $msgspec eq 'ARRAY' ? : 0 0 0
2599 }
2600  
2601 0 ▶sub subject { $_[0]->get_header( $_[1], "Subject" ) }
Subroutine subject: not called CC=1 SCAR=6.9
Pod documented
2602 0 ▶sub date { $_[0]->get_header( $_[1], "Date" ) }
Subroutine date: not called CC=1 SCAR=6.9
Pod documented
2603 0 ▶sub rfc822_header { shift->get_header(@_) }
Subroutine rfc822_header: not called CC=1 SCAR=6.9
Pod undocumented
2604  
2605 0 ▶sub get_header {
Subroutine get_header: not called CC=2 SCAR=17.9
Pod documented
2606 0 my ( $self, $msg, $field ) = @_;
2607 0 my $headers = $self->parse_headers( $msg, $field );
2608 0 ▶ $headers ? $headers->{$field}[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$headers ? : 0 0 0
2609 }
2610  
2611 0 ▶sub recent_count {
Subroutine recent_count: not called CC=2 SCAR=17.9
Pod documented
2612 0 my ( $self, $folder ) = ( shift, shift );
2613  
2614 0 ▶ $self->status( $folder, 'RECENT' )
Branch: 1 branch
BranchTrueFalseTotal
$self->status($folder, "RECENT") or return undef 0 0 0
2615 or return undef;
2616  
2617 my $r =
2618 0 ▶ first { s/\*\s+STATUS\s+.*\(RECENT\s+(\d+)\s*\)/$1/ } $self->History;
Subroutine __ANON__: not called CC=1 SCAR=6.9
2619 0 chomp $r;
2620 0 $r;
2621 }
2622  
2623 0 ▶sub message_count {
Subroutine message_count: not called CC=5 SCAR=34.0
Pod documented
2624 0 my $self = shift;
2625 0 ▶ my $folder = shift || $self->Folder;
Condition0%0/3
shift() || $self->Folder
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->Folder
shift() $self->Folder
Truth table0%0/3
A || B
A= shift()B= $self->Folder
ABresult
1X1
011
000
2626  
2627 0 ▶ $self->status( $folder, 'MESSAGES' )
Branch: 1 branch
BranchTrueFalseTotal
$self->status($folder, "MESSAGES") or return undef 0 0 0
2628 or return undef;
2629  
2630 0 foreach my $result ( $self->Results ) {
2631 0 ▶ return $1 if $result =~ /\(MESSAGES\s+(\d+)\s*\)/i;
Branch: 1 branch
BranchTrueFalseTotal
if $result =~ /\(MESSAGES\s+(\d+)\s*\)/i 0 0 0
2632 }
2633  
2634 0 undef;
2635 }
2636  
2637 0 ▶sub recent() { shift->search('recent') }
Subroutine recent: not called CC=1 SCAR=6.9
Pod documented
2638 0 ▶sub seen() { shift->search('seen') }
Subroutine seen: not called CC=1 SCAR=6.9
Pod documented
2639 0 ▶sub unseen() { shift->search('unseen') }
Subroutine unseen: not called CC=1 SCAR=6.9
Pod documented
2640 0 ▶sub messages() { shift->search('ALL') }
Subroutine messages: not called CC=1 SCAR=6.9
Pod documented
2641  
2642 0 ▶sub sentbefore($$) { shift->_search_date( sentbefore => @_ ) }
Subroutine sentbefore: not called CC=1 SCAR=6.9
Pod documented
2643 0 ▶sub sentsince($$) { shift->_search_date( sentsince => @_ ) }
Subroutine sentsince: not called CC=1 SCAR=6.9
Pod documented
2644 0 ▶sub senton($$) { shift->_search_date( senton => @_ ) }
Subroutine senton: not called CC=1 SCAR=6.9
Pod documented
2645 0 ▶sub since($$) { shift->_search_date( since => @_ ) }
Subroutine since: not called CC=1 SCAR=6.9
Pod documented
2646 0 ▶sub before($$) { shift->_search_date( before => @_ ) }
Subroutine before: not called CC=1 SCAR=6.9
Pod documented
2647 0 ▶sub on($$) { shift->_search_date( on => @_ ) }
Subroutine on: not called CC=1 SCAR=6.9
Pod documented
2648  
2649 0 ▶sub _search_date($$$) {
Subroutine _search_date: not called CC=7 SCAR=40.3
2650 0 my ( $self, $how, $time ) = @_;
2651 0 my $imapdate;
2652  
2653 0 ▶ if ( $time =~ /\d\d-\D\D\D-\d\d\d\d/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($time =~ /\d\d-\D\D\D-\d\d\d\d/) { } 0 0 0
elsif ($time =~ /^\d+$/) { } 0 0 0
2654 0 $imapdate = $time;
2655 }
2656 elsif ( $time =~ /^\d+$/ ) {
2657 0 my @ltime = localtime $time;
2658 0 $imapdate = sprintf( "%2.2d-%s-%4.4d",
2659 $ltime[3],
2660 $mnt[ $ltime[4] ],
2661 $ltime[5] + 1900 );
2662 }
2663 else {
2664 0 $self->LastError("Invalid date format supplied for '$how': $time");
2665 0 return undef;
2666 }
2667  
2668 0 ▶ $self->_imap_uid_command( SEARCH => $how, $imapdate )
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_uid_command("SEARCH", $how, $imapdate) or return undef 0 0 0
2669 or return undef;
2670  
2671 0 my @hits;
2672 0 foreach ( $self->History ) {
2673 0 chomp;
2674 0 s/$CR?$LF$//o;
2675 0 ▶ s/^\*\s+SEARCH\s+//i or next;
Branch: 1 branch
BranchTrueFalseTotal
s/^\*\s+SEARCH\s+//i or next 0 0 0
2676 0 push @hits, grep /\d/, split;
2677 }
2678 0 $self->_debug("Hits are: @hits");
2679 0 ▶ return wantarray ? @hits : \@hits;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2680 }
2681  
2682 0 ▶sub or {
Subroutine or: not called CC=7 SCAR=40.3
Pod documented
2683 0 my ( $self, @what ) = @_;
2684 0 ▶ if ( @what < 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@what < 2) 0 0 0
2685 0 $self->LastError("Invalid number of arguments passed to or()");
2686 0 return undef;
2687 }
2688  
2689 0 my $or =
2690 "OR " . $self->Quote( shift @what ) . " " . $self->Quote( shift @what );
2691  
2692 0 $or = "OR $or " . $self->Quote($_) for @what;
2693  
2694 0 ▶ $self->_imap_uid_command( SEARCH => $or )
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_uid_command("SEARCH", $or) or return undef 0 0 0
2695 or return undef;
2696  
2697 0 my @hits;
2698 0 foreach ( $self->History ) {
2699 0 chomp;
2700 0 s/$CR?$LF$//o;
2701 0 ▶ s/^\*\s+SEARCH\s+//i or next;
Branch: 1 branch
BranchTrueFalseTotal
s/^\*\s+SEARCH\s+//i or next 0 0 0
2702 0 push @hits, grep /\d/, split;
2703 }
2704 0 $self->_debug("Hits are now: @hits");
2705  
2706 0 ▶ return wantarray ? @hits : \@hits;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2707 }
2708  
2709 0 ▶sub disconnect { shift->logout }
Subroutine disconnect: not called CC=1 SCAR=6.9
Pod documented
2710  
2711 0 ▶sub _quote_search {
Subroutine _quote_search: not called CC=5 SCAR=34.0
2712 0 my ( $self, @args ) = @_;
2713 0 my @ret;
2714 0 foreach my $v (@args) {
2715 0 ▶ if ( ref($v) eq "SCALAR" ) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $v eq 'SCALAR') { } 0 0 0
elsif (exists $SEARCH_KEYS{uc $v}) { } 0 0 0
elsif (@args == 1) { } 0 0 0
2716 0 push( @ret, $$v );
2717 }
2718 elsif ( exists $SEARCH_KEYS{ uc($v) } ) {
2719 0 push( @ret, $v );
2720 }
2721 elsif ( @args == 1 ) {
2722 0 push( @ret, $v ); # <3.17 compat: caller responsible for quoting
2723 }
2724 else {
2725 0 push( @ret, $self->Quote($v) );
2726 }
2727 }
2728 0 return @ret;
2729 }
2730  
2731 0 ▶sub search {
Subroutine search: not called CC=8 SCAR=42.8
Pod documented
2732 0 my ( $self, @args ) = @_;
2733  
2734 0 @args = $self->_quote_search(@args);
2735  
2736 0 ▶ $self->_imap_uid_command( SEARCH => @args )
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_uid_command("SEARCH", @args) or return undef 0 0 0
2737 or return undef;
2738  
2739 0 my @hits;
2740 0 foreach ( $self->History ) {
2741 0 chomp;
2742 0 s/$CR?$LF$//o;
2743 0 ▶ s/^\*\s+SEARCH\s+(?=.*?\d)// or next;
Branch: 1 branch
BranchTrueFalseTotal
s/^\*\s+SEARCH\s+(?=.*?\d)// or next 0 0 0
2744 0 push @hits, grep /^\d+$/, split;
2745 }
2746  
2747 @hits
2748 0 ▶ or $self->_debug("Search successful but found no matching messages");
Branch: 1 branch
BranchTrueFalseTotal
@hits or $self->_debug("Search successful but found no matching messages") 0 0 0
2749  
2750 # return empty list
2751 return
2752 wantarray ? @hits
2753 0 ▶ : !@hits ? \@hits
Branch: 3 branches
BranchTrueFalseTotal
wantarray ? : 0 0 0
!@hits ? : 0 0 0
$self->Ranges ? : 0 0 0
2754 : $self->Ranges ? $self->Range( \@hits )
2755 : \@hits;
2756 }
2757  
2758 # returns a Thread data structure
2759 3 my $thread_parser;
2760  
2761 0 ▶sub thread {
Subroutine thread: not called CC=16 SCAR=56.1
Pod documented
2762 0 my $self = shift;
2763  
2764 0 ▶ return undef unless defined $self->has_capability("THREAD=REFERENCES");
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->has_capability("THREAD=REFERENCES") 0 0 0
2765 0 ▶ my $algorythm = shift
Branch: 1 branch
BranchTrueFalseTotal
$self->has_capability('THREAD=REFERENCES') ? : 0 0 0
Condition0%0/3
shift() || ($self->has_capability('THREAD=REFERENCES') ? 'REFERENCES' : 'ORDEREDSUBJECT')
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || ($self->has_capability('THREAD=REFERENCES') ? 'REFERENCES' : 'ORDEREDSUBJECT')
shift() ($self->has_capability('THREAD=REFERENCES') ? 'REFERENCES' : 'ORDEREDSUBJECT')
Truth table0%0/3
A || B
A= shift()B= ($self->has_capability('THREAD=REFERENCES') ? 'REFERENCES' : 'ORDEREDSUBJECT')
ABresult
1X1
011
000
2766 || (
2767 $self->has_capability("THREAD=REFERENCES")
2768 ? 'REFERENCES'
2769 : 'ORDEREDSUBJECT'
2770 );
2771  
2772 0 ▶ my $charset = shift || 'UTF-8';
Condition0%0/2
shift() || 'UTF-8'
l!l
00
MC/DC0%0/1
shift() || 'UTF-8'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
2773 0 ▶ my @a = @_ ? @_ : 'ALL';
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
2774  
2775 $a[-1] = $self->Quote( $a[-1], 1 )
2776 0 ▶ if @a > 1 && !exists $SEARCH_KEYS{ uc $a[-1] };
Branch: 1 branch
BranchTrueFalseTotal
if @a > 1 and not exists $SEARCH_KEYS{uc $a[-1]} 0 0 0
Condition0%0/3
@a > 1 and not exists $SEARCH_KEYS{uc $a[-1]}
!ll&&!rl&&r
000
MC/DC0%0/2
@a > 1 and not exists $SEARCH_KEYS{uc $a[-1]}
@a > 1 not exists $SEARCH_KEYS{uc $a[-1]}
Truth table0%0/3
A and not(B)
A= @a > 1B= not exists $SEARCH_KEYS{uc $a[-1]}
ABresult
0X0
100
111
2777  
2778 0 ▶ $self->_imap_uid_command( THREAD => $algorythm, $charset, @a )
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_uid_command("THREAD", $algorythm, $charset, @a) or return undef 0 0 0
2779 or return undef;
2780  
2781 0 ▶ unless ($thread_parser) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($thread_parser) 0 0 0
2782 0 ▶ return if ( defined($thread_parser) and $thread_parser == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if defined $thread_parser and $thread_parser == 0 0 0 0
Condition0%0/3
defined $thread_parser and $thread_parser == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $thread_parser and $thread_parser == 0
defined $thread_parser $thread_parser == 0
Truth table0%0/3
A and B
A= defined $thread_parserB= $thread_parser == 0
ABresult
0X0
100
111
2783  
2784 0 my $class = $self->_load_module("Thread");
2785 0 ▶ unless ($class) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class) 0 0 0
2786 0 $thread_parser = 0;
2787 0 return undef;
2788 }
2789 0 $thread_parser = $class->new;
2790 }
2791  
2792 0 my $thread;
2793 0 foreach ( $self->History ) {
2794 0 ▶ /^\*\s+THREAD\s+/ or next;
Branch: 1 branch
BranchTrueFalseTotal
/^\*\s+THREAD\s+/ or next 0 0 0
2795 0 s/$CR?$LF|$LF+/ /og;
2796 0 $thread = $thread_parser->start($_);
2797 }
2798  
2799 0 ▶ unless ($thread) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($thread) 0 0 0
2800 0 $self->LastError(
2801 "Thread search completed successfully but found no matching messages"
2802 );
2803 0 return undef;
2804 }
2805  
2806 0 $thread;
2807 }
2808  
2809 0 ▶sub delete_message {
Subroutine delete_message: not called CC=3 SCAR=24.8
Pod documented
2810 0 my $self = shift;
2811 0 ▶ my @msgs = map { ref $_ eq 'ARRAY' ? @$_ : split /\,/ } @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 0 0 0
2812  
2813 0 ▶ $self->store( join( ',', @msgs ), '+FLAGS.SILENT', '(\Deleted)' )
Branch: 1 branch
BranchTrueFalseTotal
$self->store(join(',', @msgs), '+FLAGS.SILENT', '(\\Deleted)') ? : 0 0 0
2814 ? scalar @msgs
2815 : undef;
2816 }
2817  
2818 0 ▶sub restore_message {
Subroutine restore_message: not called CC=3 SCAR=24.8
Pod documented
2819 0 my $self = shift;
2820 0 ▶ my $msgs = join ',', map { ref $_ eq 'ARRAY' ? @$_ : split /\,/ } @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 0 0 0
2821  
2822 0 ▶ $self->store( $msgs, '-FLAGS', '(\Deleted)' ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->store($msgs, "-FLAGS", "(\\Deleted)") or return undef 0 0 0
2823 0 scalar grep /^\*\s\d+\sFETCH\s\(.*FLAGS.*(?!\\Deleted)/, $self->Results;
2824 }
2825  
2826 0 ▶sub uidvalidity {
Subroutine uidvalidity: not called CC=4 SCAR=30.0
Pod documented
2827 0 my ( $self, $folder ) = @_;
2828 0 ▶ $self->status( $folder, "UIDVALIDITY" ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->status($folder, "UIDVALIDITY") or return undef 0 0 0
2829 0 ▶ my $line = first { /UIDVALIDITY/i } $self->History;
Subroutine __ANON__: not called CC=1 SCAR=6.9
2830 0 ▶ defined $line && $line =~ /\(UIDVALIDITY\s+([^\)]+)/ ? $1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $line && $line =~ /\(UIDVALIDITY\s+([^\)]+)/ ? : 0 0 0
Condition0%0/3
defined $line and $line =~ /\(UIDVALIDITY\s+([^\)]+)/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $line and $line =~ /\(UIDVALIDITY\s+([^\)]+)/
defined $line $line =~ /\(UIDVALIDITY\s+([^\)]+)/
Truth table0%0/3
A and B
A= defined $lineB= $line =~ /\(UIDVALIDITY\s+([^\)]+)/
ABresult
0X0
100
111
2831 }
2832  
2833 0 ▶sub uidnext {
Subroutine uidnext: not called CC=4 SCAR=30.0
Pod documented
2834 0 my ( $self, $folder ) = @_;
2835 0 ▶ $self->status( $folder, "UIDNEXT" ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->status($folder, "UIDNEXT") or return undef 0 0 0
2836 0 ▶ my $line = first { /UIDNEXT/i } $self->History;
Subroutine __ANON__: not called CC=1 SCAR=6.9
2837 0 ▶ defined $line && $line =~ /\(UIDNEXT\s+([^\)]+)/ ? $1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $line && $line =~ /\(UIDNEXT\s+([^\)]+)/ ? : 0 0 0
Condition0%0/3
defined $line and $line =~ /\(UIDNEXT\s+([^\)]+)/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $line and $line =~ /\(UIDNEXT\s+([^\)]+)/
defined $line $line =~ /\(UIDNEXT\s+([^\)]+)/
Truth table0%0/3
A and B
A= defined $lineB= $line =~ /\(UIDNEXT\s+([^\)]+)/
ABresult
0X0
100
111
2838 }
2839  
2840 # sort @caps for consistency?
2841 0 ▶sub capability {
Subroutine capability: not called CC=9 SCAR=45.0
Pod documented
2842 0 my $self = shift;
2843  
2844 0 ▶ if ( $self->{CAPABILITY} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CAPABILITY"}) 0 0 0
2845 0 my @caps = keys %{ $self->{CAPABILITY} };
2846 0 ▶ return wantarray ? @caps : \@caps;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2847 }
2848  
2849 0 ▶ $self->_imap_command('CAPABILITY')
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command("CAPABILITY") or return undef 0 0 0
2850 or return undef;
2851  
2852 0 my @caps = map { split } grep /^\*\s+CAPABILITY\s+/, $self->History;
2853 0 splice( @caps, 0, 2 ); # remove * CAPABILITY from array
2854  
2855 # use iterator as we may append to @caps for CAPA=VALUE
2856 0 ▶ for ( my $i = 0 ; $i < @caps ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @caps) 0 0 0
2857 0 ▶ $self->{CAPABILITY}->{ uc $caps[$i] } ||= [];
Condition0%0/2
$self->{"CAPABILITY"}{uc $caps[$i]} ||= []
l!l
00
MC/DC0%0/1
$self->{"CAPABILITY"}{uc $caps[$i]} ||= []
$self->{"CAPABILITY"}{uc $caps[$i]}
Truth table0%0/2
A
A= $self->{"CAPABILITY"}{uc $caps[$i]}
Aresult
11
00
2858 0 my ( $capa, $cval ) = split( /=/, $caps[$i], 2 );
2859 0 ▶ if ( defined $cval ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cval) 0 0 0
2860 0 $capa = uc $capa;
2861 0 ▶ push( @caps, $capa ) unless exists $self->{CAPABILITY}->{$capa};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"CAPABILITY"}{$capa} 0 0 0
2862 0 push( @{ $self->{CAPABILITY}->{$capa} }, $cval );
2863 }
2864 }
2865  
2866 0 ▶ return wantarray ? @caps : \@caps;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2867 }
2868  
2869 # use "" not undef when lookup fails to differentiate imap command
2870 # failure vs lack of capability
2871 0 ▶sub has_capability {
Subroutine has_capability: not called CC=7 SCAR=40.3
Pod documented
2872 0 my ( $self, $which ) = @_;
2873 0 ▶ $self->capability or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->capability or return undef 0 0 0
2874 0 my $aref = [];
2875  
2876 # exists in CAPABILITIES? possibly in CAPA=VALUE format?
2877 0 ▶ if ( defined $which ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $which) 0 0 0
2878 0 $which = uc $which;
2879 0 ▶ if ( exists $self->{CAPABILITY}{$which} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"CAPABILITY"}{$which}) 0 0 0
2880 0 ▶ if ( @{ $self->{CAPABILITY}{$which} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'CAPABILITY'}{$which};}) { } 0 0 0
2881 0 $aref = $self->{CAPABILITY}{$which};
2882 }
2883 else {
2884 0 $aref = [$which];
2885 }
2886 }
2887 }
2888  
2889 0 ▶ return @$aref if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
2890 0 ▶ return scalar @$aref ? $aref : "";
Branch: 1 branch
BranchTrueFalseTotal
scalar @$aref ? : 0 0 0
2891 }
2892  
2893 0 ▶sub imap4rev1 {
Subroutine imap4rev1: not called CC=2 SCAR=17.9
Pod documented
2894 0 my $self = shift;
2895 0 ▶ return $self->{_IMAP4REV1} if exists $self->{_IMAP4REV1};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_IMAP4REV1"} 0 0 0
2896 0 $self->{_IMAP4REV1} = $self->has_capability('IMAP4REV1');
2897 }
2898  
2899 #??? what a horror!
2900 0 ▶sub namespace {
Subroutine namespace: not called CC=8 SCAR=42.8
Pod documented
2901  
2902 # Returns a nested list as follows:
2903 # [
2904 # [
2905 # [ $user_prefix, $user_delim ] (,[$user_prefix2 ,$user_delim ],...),
2906 # ],
2907 # [
2908 # [ $shared_prefix,$shared_delim] (,[$shared_prefix2,$shared_delim],... ),
2909 # ],
2910 # [
2911 # [$public_prefix, $public_delim] (,[$public_prefix2,$public_delim],...),
2912 # ],
2913 # ];
2914  
2915 0 my $self = shift;
2916 0 ▶ unless ( $self->has_capability("NAMESPACE") ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_capability("NAMESPACE")) 0 0 0
2917 0 ▶ $self->LastError( "NO NAMESPACE not supported by " . $self->Server )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->LastError 0 0 0
2918 unless $self->LastError;
2919 0 return undef;
2920 }
2921  
2922 0 ▶ my $got = $self->_imap_command("NAMESPACE") or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $got = $self->_imap_command("NAMESPACE") or return undef 0 0 0
2923 0 ▶ my @namespaces = map { /^\* NAMESPACE (.*)/ ? $1 : () } $got->Results;
Branch: 1 branch
BranchTrueFalseTotal
/^\* NAMESPACE (.*)/ ? : 0 0 0
2924  
2925 0 my $namespace = shift @namespaces;
2926 0 $namespace =~ s/$CR?$LF$//o;
2927  
2928 0 my ( $personal, $shared, $public ) = $namespace =~ m#
2929 (NIL|\((?:\([^\)]+\)\s*)+\))\s
2930 (NIL|\((?:\([^\)]+\)\s*)+\))\s
2931 (NIL|\((?:\([^\)]+\)\s*)+\))
2932 #xi;
2933  
2934 0 my @ns;
2935 0 $self->_debug("NAMESPACE: pers=$personal, shared=$shared, pub=$public");
2936 0 foreach ( $personal, $shared, $public ) {
2937 0 ▶ uc $_ ne 'NIL' or next;
Branch: 1 branch
BranchTrueFalseTotal
uc $_ ne "NIL" or next 0 0 0
2938 0 s/^\((.*)\)$/$1/;
2939  
2940 0 my @pieces = m#\(([^\)]*)\)#g;
2941 0 $self->_debug("NAMESPACE pieces: @pieces");
2942  
2943 0 push @ns, [ map { [m#"([^"]*)"\s*#g] } @pieces ];
2944 }
2945  
2946 0 ▶ return wantarray ? @ns : \@ns;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
2947 }
2948  
2949 0 ▶sub internaldate {
Subroutine internaldate: not called CC=3 SCAR=24.8
Pod documented
2950 0 my ( $self, $msg ) = @_;
2951 0 ▶ $self->_imap_uid_command( FETCH => $msg, 'INTERNALDATE' )
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_uid_command("FETCH", $msg, "INTERNALDATE") or return undef 0 0 0
2952 or return undef;
2953 0 my $hist = join '', $self->History;
2954 0 ▶ return $hist =~ /\bINTERNALDATE "([^"]*)"/i ? $1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$hist =~ /\bINTERNALDATE "([^"]*)"/i ? : 0 0 0
2955 }
2956  
2957 0 ▶sub is_parent {
Subroutine is_parent: not called CC=11 SCAR=48.8
Pod documented
2958 0 my ( $self, $folder ) = @_;
2959 0 ▶ my $list = $self->list( undef, $folder ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $list = $self->list(undef, $folder) or return undef 0 0 0
2960  
2961 0 my $attrs;
2962 0 foreach my $resp (@$list) {
2963 0 my $rec = $self->_list_or_lsub_response_parse($resp);
2964 0 ▶ next unless defined $rec->{attrs};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rec->{"attrs"} 0 0 0
2965 0 ▶ $self->_debug("unexpected attrs data: @$list\n") if $attrs;
Branch: 1 branch
BranchTrueFalseTotal
if $attrs 0 0 0
2966 0 $attrs = $rec->{attrs};
2967 }
2968  
2969 0 ▶ if ($attrs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrs) { } 0 0 0
2970 0 ▶ return undef if first { lc($_) eq '\noinferiors' } @$attrs;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &first(sub { lc $_ eq "\\noinferiors"; } , @$attrs) 0 0 0
2971 0 ▶ return 1 if first { lc($_) eq '\haschildren' } @$attrs;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &first(sub { lc $_ eq "\\haschildren"; } , @$attrs) 0 0 0
2972 0 ▶ return 0 if first { lc($_) eq '\hasnochildren' } @$attrs;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &first(sub { lc $_ eq "\\hasnochildren"; } , @$attrs) 0 0 0
2973 }
2974 else {
2975 0 $self->_debug( join( "\n\t", "no attrs for '$folder' in:", @$list ) );
2976 }
2977  
2978 # BUG? This may be overkill for normal use cases...
2979 # flag not supported or not returned for some reason, try via folders()
2980 0 ▶ my $sep = $self->separator($folder) || $self->separator(undef);
Condition0%0/3
$self->separator($folder) || $self->separator(undef)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->separator($folder) || $self->separator(undef)
$self->separator($folder) $self->separator(undef)
Truth table0%0/3
A || B
A= $self->separator($folder)B= $self->separator(undef)
ABresult
1X1
011
000
2981 0 ▶ return undef unless defined $sep;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sep 0 0 0
2982  
2983 0 my $lead = $folder . $sep;
2984 0 my $len = length $lead;
2985 0 scalar grep { $lead eq substr( $_, 0, $len ) } $self->folders;
2986 }
2987  
2988 0 ▶sub selectable {
Subroutine selectable: not called CC=2 SCAR=17.9
Pod documented
2989 0 my ( $self, $f ) = @_;
2990 0 ▶ my $info = $self->list( "", $f ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $info = $self->list("", $f) or return undef 0 0 0
2991 0 return not( grep /[\s(]\\Noselect[)\s]/i, @$info );
2992 }
2993  
2994 # append( $self, $folder, $text [, $optmsg] )
2995 # - conserve memory and use $_[0] to avoid copying $text (it may be huge!)
2996 # - BUG?: should deprecate this method in favor of append_string
2997 0 ▶sub append {
Subroutine append: not called CC=2 SCAR=17.9
Pod documented
2998 0 my $self = shift;
2999 0 my $folder = shift;
3000  
3001 # $message_string is whatever is left in @_
3002 0 ▶ $self->append_string( $folder, ( @_ > 1 ? join( $CRLF, @_ ) : $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 0 0 0
3003 }
3004  
3005 0 ▶sub _clean_flags {
Subroutine _clean_flags: not called CC=2 SCAR=17.9
3006 0 my ( $self, $flags ) = @_;
3007 0 $flags =~ s/^\s+//;
3008 0 $flags =~ s/\s+$//;
3009 0 ▶ $flags = "($flags)" if $flags !~ /^\(.*\)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $flags =~ /^\(.*\)$/ 0 0 0
3010 0 return $flags;
3011 }
3012  
3013 # RFC 3501: date-day-fixed = (SP DIGIT) / 2DIGIT
3014 0 ▶sub _clean_date {
Subroutine _clean_date: not called CC=3 SCAR=24.8
3015 0 my ( $self, $date ) = @_;
3016 0 ▶ $date =~ s/^\s+// if $date !~ /^\s\d/;
Branch: 1 branch
BranchTrueFalseTotal
unless $date =~ /^\s\d/ 0 0 0
3017 0 $date =~ s/\s+$//;
3018 0 ▶ $date = qq("$date") if $date !~ /^"/;
Branch: 1 branch
BranchTrueFalseTotal
unless $date =~ /^"/ 0 0 0
3019 0 return $date;
3020 }
3021  
3022 0 ▶sub _append_command {
Subroutine _append_command: not called CC=3 SCAR=24.8
3023 0 my ( $self, $folder, $flags, $date, $length ) = @_;
3024 0 ▶ return join( " ",
Branch: 2 branches
BranchTrueFalseTotal
$flags ? : 0 0 0
$date ? : 0 0 0
3025 "APPEND $folder",
3026 ( $flags ? $flags : () ),
3027 ( $date ? $date : () ),
3028 "{" . $length . "}",
3029 );
3030 }
3031  
3032 # append_string( $self, $folder, $text, $flags, $date )
3033 # - conserve memory and use $_[2] to avoid copying $text (it may be huge!)
3034 0 ▶sub append_string($$$;$$) {
Subroutine append_string: not called CC=9 SCAR=45.0
Pod documented
3035 0 my ( $self, $folder, $flags, $date ) = @_[ 0, 1, 3, 4 ];
3036  
3037 #my $text = $_[2]; # conserve memory and use $_[2] instead!
3038 0 my $maxl = $self->Maxappendstringlength;
3039  
3040 # on "large" strings use append_file to conserve memory
3041 0 ▶ if ( $_[2] and $maxl and length( $_[2] ) > $maxl ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2] and $maxl and length $_[2] > $maxl) 0 0 0
Condition0%0/6
$_[2] and $maxl and length $_[2] > $maxl
!ll&&!rl&&r
000
$_[2] and $maxl
!ll&&!rl&&r
000
MC/DC0%0/3
$_[2] and $maxl and length $_[2] > $maxl
$_[2] $maxl length $_[2] > $maxl
Truth table0%0/4
A and B and C
A= $_[2]B= $maxlC= length $_[2] > $maxl
ABCresult
0XX0
10X0
1100
1111
3042 0 $self->_debug("append_string: using in memory file");
3043 0 return $self->append_file( $folder, \( $_[2] ), undef, $flags, $date );
3044 }
3045  
3046 0 ▶ my $text = defined( $_[2] ) ? $_[2] : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $_[2] ? : 0 0 0
3047  
3048 0 $folder = $self->Quote($folder);
3049 0 ▶ $flags = $self->_clean_flags($flags) if ( defined $flags );
Branch: 1 branch
BranchTrueFalseTotal
if defined $flags 0 0 0
3050 0 ▶ $date = $self->_clean_date($date) if ( defined $date );
Branch: 1 branch
BranchTrueFalseTotal
if defined $date 0 0 0
3051 0 $text =~ s/\r?\n/$CRLF/og;
3052  
3053 0 my $cmd = $self->_append_command( $folder, $flags, $date, length($text) );
3054 0 $cmd .= $CRLF . $text . $CRLF;
3055  
3056 0 ▶ $self->_imap_command( { addcrlf => 0 }, $cmd ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command({"addcrlf", 0}, $cmd) or return undef 0 0 0
3057  
3058 0 my $data = join '', $self->Results;
3059  
3060 # look for append-uid otherwise return self
3061 # <tag> OK [APPENDUID <uidvalidity> <append-uid>] APPEND completed
3062 0 ▶ my $ret = $data =~ m#APPENDUID\s+\S+\s+(\d+)\]# ? $1 : $self;
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /APPENDUID\s+\S+\s+(\d+)\]/ ? : 0 0 0
3063  
3064 0 return $ret;
3065 }
3066  
3067 # BUG?: not much/any savings on cygwin perl 5.10 when using in memory file
3068 # BUG?: we do not retry if sending data fails after getting the OK to send
3069 0 ▶sub append_file {
Subroutine append_file: not called CC=29 SCAR=67.7
Pod documented
3070 0 my ( $self, $folder, $file, $control, $flags, $date ) = @_;
3071  
3072 0 my @err;
3073 0 ▶ push( @err, "folder not specified" )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $folder and $folder ne "" 0 0 0
Condition0%0/3
defined $folder and $folder ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $folder and $folder ne ""
defined $folder $folder ne ""
Truth table0%0/3
A and B
A= defined $folderB= $folder ne ""
ABresult
0X0
100
111
3074 unless ( defined($folder) and $folder ne "" );
3075  
3076 0 my $fh;
3077 0 ▶ if ( !defined($file) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $file) { } 0 0 0
elsif (ref $file and ref $file ne 'SCALAR') { } 0 0 0
elsif (not ref $file || -f $file) { } 0 0 0
3078 0 push( @err, "file not specified" );
3079 }
3080 ▶ elsif ( ref($file) and ref($file) ne "SCALAR" ) {
Condition0%0/3
ref $file and ref $file ne "SCALAR"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $file and ref $file ne "SCALAR"
ref $file ref $file ne "SCALAR"
Truth table0%0/3
A and B
A= ref $fileB= ref $file ne "SCALAR"
ABresult
0X0
100
111
3081 0 $fh = $file; # let the caller pass in their own file handle directly
3082 }
3083 ▶ elsif ( !ref($file) and !-f $file ) {
Condition0%0/3
ref $file || -f $file
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $file || -f $file
ref $file -f $file
Truth table0%0/3
A || B
A= ref $fileB= -f $file
ABresult
1X1
011
000
3084 0 push( @err, "file '$file' not found" );
3085 }
3086 else {
3087  
3088 # $file can be a name or a scalar reference (for in memory file)
3089 # avoid IO::File bug handling scalar refs in perl <= 5.8.8?
3090 # - buggy: $fh = IO::File->new( $file, 'r' )
3091 0 local ($!);
3092 0 ▶ open( $fh, "<", $file )
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $file or push @err, "Unable to open file '${file}': $!" 0 0 0
3093 or push( @err, "Unable to open file '$file': $!" );
3094 }
3095  
3096 0 ▶ if (@err) {
Branch: 1 branch
BranchTrueFalseTotal
if (@err) 0 0 0
3097 0 $self->LastError( join( ", ", @err ) );
3098 0 return undef;
3099 }
3100  
3101 0 binmode($fh);
3102  
3103 0 ▶ $folder = $self->Quote($folder) if ( defined $folder );
Branch: 1 branch
BranchTrueFalseTotal
if defined $folder 0 0 0
3104 0 ▶ $flags = $self->_clean_flags($flags) if ( defined $flags );
Branch: 1 branch
BranchTrueFalseTotal
if defined $flags 0 0 0
3105  
3106 # allow the date to be specified or even use mtime on file
3107 0 ▶ if ($date) {
Branch: 1 branch
BranchTrueFalseTotal
if ($date) 0 0 0
3108 0 ▶ $date = $self->Rfc3501_datetime( ( stat($fh) )[9] ) if ( $date eq "1" );
Branch: 1 branch
BranchTrueFalseTotal
if $date eq 1 0 0 0
3109 0 $date = $self->_clean_date($date);
3110 }
3111  
3112 # BUG? seems wasteful to do this always, provide a "fast path" option?
3113 0 my $length = 0;
3114 {
3115 0 local $/ = "\n"; # just in case global is not default
3116 0 ▶ while ( my $line = <$fh> ) { # do no read the whole file at once!
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
3117 0 $line =~ s/\r?\n$/$CRLF/;
3118 0 $length += length($line);
3119 }
3120 0 seek( $fh, 0, 0 );
3121 }
3122  
3123 0 my $cmd = $self->_append_command( $folder, $flags, $date, $length );
3124 0 my $rc = $self->_imap_command( $cmd, '+' );
3125 0 ▶ unless ($rc) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rc) 0 0 0
3126 0 $self->LastError( "Error sending '$cmd': " . $self->LastError );
3127 0 return undef;
3128 }
3129  
3130 # Now send the message itself
3131 0 my ( $buffer, $buflen ) = ( "", 0 );
3132 0 ▶ until ( !$buflen and eof($fh) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (not $buflen and eof $fh) 0 0 0
Condition0%0/3
not $buflen and eof $fh
!ll&&!rl&&r
000
MC/DC0%0/2
not $buflen and eof $fh
not $buflen eof $fh
Truth table0%0/3
not(A) and B
A= not $buflenB= eof $fh
ABresult
0X0
100
111
3133  
3134 0 ▶ if ( $buflen < APPEND_BUFFER_SIZE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buflen < 1048576) 0 0 0
3135 FILLBUFF:
3136 0 ▶ while ( my $line = <$fh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
3137 0 $line =~ s/\r?\n$/$CRLF/;
3138 0 $buffer .= $line;
3139 0 $buflen = length($buffer);
3140 0 ▶ last FILLBUFF if ( $buflen >= APPEND_BUFFER_SIZE );
Branch: 1 branch
BranchTrueFalseTotal
if $buflen >= 1048576 0 0 0
3141 }
3142 }
3143  
3144 # exit loop entirely if we are out of data
3145 0 ▶ last unless $buflen;
Branch: 1 branch
BranchTrueFalseTotal
unless $buflen 0 0 0
3146  
3147 # save anything over desired buffer size for next iteration
3148 0 ▶ my $savebuff =
Branch: 1 branch
BranchTrueFalseTotal
$buflen > 1048576 ? : 0 0 0
3149 ( $buflen > APPEND_BUFFER_SIZE )
3150 ? substr( $buffer, APPEND_BUFFER_SIZE )
3151 : undef;
3152  
3153 # reduce buffer to desired size
3154 0 $buffer = substr( $buffer, 0, APPEND_BUFFER_SIZE );
3155  
3156 0 my $bytes_written = $self->_send_bytes( \$buffer );
3157 0 ▶ unless ($bytes_written) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bytes_written) 0 0 0
3158 0 $self->LastError( "Error appending message: " . $self->LastError );
3159 0 return undef;
3160 }
3161  
3162 # retain any saved data and continue loop
3163 0 ▶ $buffer = defined($savebuff) ? $savebuff : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $savebuff ? : 0 0 0
3164 0 $buflen = length($buffer);
3165 }
3166  
3167 # finish off append
3168 0 ▶ unless ( $self->_send_bytes( \$CRLF ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_send_bytes(\$Mail::IMAPClient::CRLF)) 0 0 0
3169 0 $self->LastError( "Error appending CRLF: " . $self->LastError );
3170 0 return undef;
3171 }
3172  
3173 # Now for the crucial test: Did the append work or not?
3174 # look for "<tag> (OK|BAD|NO)"
3175 0 ▶ my $code = $self->_get_response( $self->Count ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $code = $self->_get_response($self->Count) or return undef 0 0 0
3176  
3177 0 ▶ if ( $code eq 'OK' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code eq 'OK') { } 0 0 0
3178 0 my $data = join '', $self->Results;
3179  
3180 # look for something like return size or self if no size found:
3181 # <tag> OK [APPENDUID <uid> <size>] APPEND completed
3182 0 ▶ my $ret = $data =~ m#\s+(\d+)\]# ? $1 : $self;
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /\s+(\d+)\]/ ? : 0 0 0
3183  
3184 0 return $ret;
3185 }
3186 else {
3187 0 return undef;
3188 }
3189 }
3190  
3191 # BUG? we should retry if "socket closed while..." but do not currently
3192 0 ▶sub authenticate {
Subroutine authenticate: not called CC=31 SCAR=69.0
Pod documented
3193 0 my ( $self, $scheme, $response ) = @_;
3194 0 ▶ $scheme ||= $self->Authmechanism;
Condition0%0/3
$scheme ||= $self->Authmechanism
l!l&&r!l&&!r
000
MC/DC0%0/2
$scheme ||= $self->Authmechanism
$scheme $self->Authmechanism
Truth table0%0/3
A ||= B
A= $schemeB= $self->Authmechanism
ABresult
1X1
011
000
3195 0 ▶ $response ||= $self->Authcallback;
Condition0%0/3
$response ||= $self->Authcallback
l!l&&r!l&&!r
000
MC/DC0%0/2
$response ||= $self->Authcallback
$response $self->Authcallback
Truth table0%0/3
A ||= B
A= $responseB= $self->Authcallback
ABresult
1X1
011
000
3196 0 my $clear = $self->Clear;
3197 0 ▶ $self->Clear($clear)
Branch: 1 branch
BranchTrueFalseTotal
if $self->Count >= $clear and $clear > 0 0 0 0
Condition0%0/3
$self->Count >= $clear and $clear > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$self->Count >= $clear and $clear > 0
$self->Count >= $clear $clear > 0
Truth table0%0/3
A and B
A= $self->Count >= $clearB= $clear > 0
ABresult
0X0
100
111
3198 if $self->Count >= $clear && $clear > 0;
3199  
3200 0 ▶ if ( !$scheme ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $scheme) { } 0 0 0
elsif ($scheme eq 'LOGIN') { } 0 0 0
3201 0 $self->LastError("Authmechanism not set");
3202 0 return undef;
3203 }
3204 elsif ( $scheme eq 'LOGIN' ) {
3205 0 $self->LastError("Authmechanism LOGIN is invalid, use login()");
3206 0 return undef;
3207 }
3208  
3209 0 my $string = "AUTHENTICATE $scheme";
3210  
3211 # use _imap_command for retry mechanism...
3212 0 ▶ $self->_imap_command( $string, '+' ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command($string, "+") or return undef 0 0 0
3213  
3214 0 my $count = $self->Count;
3215 0 my $code;
3216  
3217 # look for "+ <anyword>" or just "+"
3218 0 foreach my $line ( $self->Results ) {
3219 0 ▶ if ( $line =~ /^\+\s*(.*?)\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\+\s*(.*?)\s*$/) 0 0 0
3220 0 $code = $1;
3221 0 last;
3222 }
3223 }
3224  
3225 # BUG? use _load_module for these too?
3226 0 ▶ if ( $scheme eq 'CRAM-MD5' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($scheme eq 'CRAM-MD5') { } 0 0 0
elsif ($scheme eq 'DIGEST-MD5') { } 0 0 0
elsif ($scheme eq 'PLAIN') { } 0 0 0
elsif ($scheme eq 'NTLM') { } 0 0 0
3227 0 ▶ $response ||= sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
3228 0 my ( $code, $client ) = @_;
3229 0 require Digest::HMAC_MD5;
3230 0 my $hmac =
3231 Digest::HMAC_MD5::hmac_md5_hex( decode_base64($code),
3232 $client->Password );
3233 0 encode_base64( $client->User . " " . $hmac, '' );
3234 0 ▶ };
Condition0%0/3
$response ||= sub { my($code, $client) = @_; require Digest::HMAC_MD5; my $hmac = Digest::HMAC_MD5::hmac_md5_hex(&decode_base64($code), $client->Password); &encode_base64($client->User . ' ' . $hmac, ""); }
l!l&&r!l&&!r
000
MC/DC0%0/2
$response ||= sub { my($code, $client) = @_; require Digest::HMAC_MD5; my $hmac = Digest::HMAC_MD5::hmac_md5_hex(&decode_base64($code), $client->Password); &encode_base64($client->User . ' ' . $hmac, ""); }
$response sub { my($code, $client) = @_; require Digest::HMAC_MD5; my $hmac = Digest::HMAC_MD5::hmac_md5_hex(&decode_base64($code), $client->Password); &encode_base64($client->User . ' ' . $hmac, ""); }
Truth table0%0/3
A ||= B
A= $responseB= sub { my($code, $client) = @_; require Digest::HMAC_MD5; my $hmac = Digest::HMAC_MD5::hmac_md5_hex(&decode_base64($code), $client->Password); &encode_base64($client->User . ' ' . $hmac, ""); }
ABresult
1X1
011
000
3235 }
3236 elsif ( $scheme eq 'DIGEST-MD5' ) {
3237 0 ▶ $response ||= sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
3238 0 my ( $code, $client ) = @_;
3239 0 require Authen::SASL;
3240 0 require Digest::MD5;
3241  
3242 0 ▶ my $authname =
Branch: 1 branch
BranchTrueFalseTotal
defined $client->Authuser ? : 0 0 0
3243 defined $client->Authuser ? $client->Authuser : $client->User;
3244  
3245 0 my $sasl = Authen::SASL->new(
3246 mechanism => 'DIGEST-MD5',
3247 callback => {
3248 user => $client->User,
3249 pass => $client->Password,
3250 authname => $authname
3251 }
3252 );
3253  
3254 # client_new is an empty function for DIGEST-MD5
3255 0 my $conn = $sasl->client_new( 'imap', 'localhost', '' );
3256 0 my $answer = $conn->client_step( decode_base64 $code);
3257  
3258 0 ▶ encode_base64( $answer, '' )
Branch: 1 branch
BranchTrueFalseTotal
if defined $answer 0 0 0
3259 if defined $answer;
3260 0 ▶ };
Condition0%0/3
$response ||= sub { my($code, $client) = @_; require Authen::SASL; require Digest::MD5; my $authname = defined $client->Authuser ? $client->Authuser : $client->User; my $sasl = "Authen::SASL"->new("mechanism", "DIGEST-MD5", "callback", {"user", $client->User, "pass", $client->Password, "authname", $authname}); my $conn = $sasl->client_new("imap", "localhost", ""); my $answer = $conn->client_step(&decode_base64($code)); &encode_base64($answer, "") if defined $answer; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$response ||= sub { my($code, $client) = @_; require Authen::SASL; require Digest::MD5; my $authname = defined $client->Authuser ? $client->Authuser : $client->User; my $sasl = "Authen::SASL"->new("mechanism", "DIGEST-MD5", "callback", {"user", $client->User, "pass", $client->Password, "authname", $authname}); my $conn = $sasl->client_new("imap", "localhost", ""); my $answer = $conn->client_step(&decode_base64($code)); &encode_base64($answer, "") if defined $answer; }
$response sub { my($code, $client) = @_; require Authen::SASL; require Digest::MD5; my $authname = defined $client->Authuser ? $client->Authuser : $client->User; my $sasl = "Authen::SASL"->new("mechanism", "DIGEST-MD5", "callback", {"user", $client->User, "pass", $client->Password, "authname", $authname}); my $conn = $sasl->client_new("imap", "localhost", ""); my $answer = $conn->client_step(&decode_base64($code)); &encode_base64($answer, "") if defined $answer; }
Truth table0%0/3
A ||= B
A= $responseB= sub { my($code, $client) = @_; require Authen::SASL; require Digest::MD5; my $authname = defined $client->Authuser ? $client->Authuser : $client->User; my $sasl = "Authen::SASL"->new("mechanism", "DIGEST-MD5", "callback", {"user", $client->User, "pass", $client->Password, "authname", $authname}); my $conn = $sasl->client_new("imap", "localhost", ""); my $answer = $conn->client_step(&decode_base64($code)); &encode_base64($answer, "") if defined $answer; }
ABresult
1X1
011
000
3261 }
3262 elsif ( $scheme eq 'PLAIN' ) { # PLAIN SASL
3263 0 ▶ $response ||= sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
3264 0 my ( $code, $client ) = @_;
3265 0 ▶ encode_base64( # [authname] user password
Branch: 2 branches
BranchTrueFalseTotal
defined $client->Proxy ? : 0 0 0
defined $client->Password ? : 0 0 0
3266 join(
3267 chr(0),
3268 defined $client->Proxy
3269 ? ( $client->User, $client->Proxy )
3270 : ( "", $client->User ),
3271 defined $client->Password ? $client->Password : "",
3272 ),
3273 ''
3274 );
3275 0 ▶ };
Condition0%0/3
$response ||= sub { my($code, $client) = @_; &encode_base64(join("\0", defined $client->Proxy ? ($client->User, $client->Proxy) : ("", $client->User), defined $client->Password ? $client->Password : ""), ""); }
l!l&&r!l&&!r
000
MC/DC0%0/2
$response ||= sub { my($code, $client) = @_; &encode_base64(join("\0", defined $client->Proxy ? ($client->User, $client->Proxy) : ("", $client->User), defined $client->Password ? $client->Password : ""), ""); }
$response sub { my($code, $client) = @_; &encode_base64(join("\0", defined $client->Proxy ? ($client->User, $client->Proxy) : ("", $client->User), defined $client->Password ? $client->Password : ""), ""); }
Truth table0%0/3
A ||= B
A= $responseB= sub { my($code, $client) = @_; &encode_base64(join("\0", defined $client->Proxy ? ($client->User, $client->Proxy) : ("", $client->User), defined $client->Password ? $client->Password : ""), ""); }
ABresult
1X1
011
000
3276 }
3277 elsif ( $scheme eq 'NTLM' ) {
3278 0 ▶ $response ||= sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
3279 0 my ( $code, $client ) = @_;
3280  
3281 0 require Authen::NTLM;
3282 0 Authen::NTLM::ntlm_user( $client->User );
3283 0 Authen::NTLM::ntlm_password( $client->Password );
3284 0 ▶ Authen::NTLM::ntlm_domain( $client->Domain ) if $client->Domain;
Branch: 1 branch
BranchTrueFalseTotal
if $client->Domain 0 0 0
3285 0 Authen::NTLM::ntlm($code);
3286 0 ▶ };
Condition0%0/3
$response ||= sub { my($code, $client) = @_; require Authen::NTLM; Authen::NTLM::ntlm_user($client->User); Authen::NTLM::ntlm_password($client->Password); Authen::NTLM::ntlm_domain($client->Domain) if $client->Domain; Authen::NTLM::ntlm($code); }
l!l&&r!l&&!r
000
MC/DC0%0/2
$response ||= sub { my($code, $client) = @_; require Authen::NTLM; Authen::NTLM::ntlm_user($client->User); Authen::NTLM::ntlm_password($client->Password); Authen::NTLM::ntlm_domain($client->Domain) if $client->Domain; Authen::NTLM::ntlm($code); }
$response sub { my($code, $client) = @_; require Authen::NTLM; Authen::NTLM::ntlm_user($client->User); Authen::NTLM::ntlm_password($client->Password); Authen::NTLM::ntlm_domain($client->Domain) if $client->Domain; Authen::NTLM::ntlm($code); }
Truth table0%0/3
A ||= B
A= $responseB= sub { my($code, $client) = @_; require Authen::NTLM; Authen::NTLM::ntlm_user($client->User); Authen::NTLM::ntlm_password($client->Password); Authen::NTLM::ntlm_domain($client->Domain) if $client->Domain; Authen::NTLM::ntlm($code); }
ABresult
1X1
011
000
3287 }
3288  
3289 0 my $resp = $response->( $code, $self );
3290 0 ▶ unless ( defined($resp) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $resp) 0 0 0
3291 0 $self->LastError( "Error getting $scheme data: " . $self->LastError );
3292 0 return undef;
3293 }
3294 0 ▶ unless ( $self->_send_line($resp) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_send_line($resp)) 0 0 0
3295 0 $self->LastError( "Error sending $scheme data: " . $self->LastError );
3296 0 return undef;
3297 }
3298  
3299 # this code may be a little too custom to try and use _get_response()
3300 # look for "+ <anyword>" (not just "+") otherwise "<tag> (OK|BAD|NO)"
3301 0 undef $code;
3302 0 ▶ until ($code) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($code) 0 0 0
3303 0 ▶ my $output = $self->_read_line or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $output = $self->_read_line or return undef 0 0 0
3304 0 foreach my $o (@$output) {
3305 0 $self->_record( $count, $o );
3306 0 ▶ $code = $o->[DATA] =~ /^\+\s+(.*?)\s*$/ ? $1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$o->[2] =~ /^\+\s+(.*?)\s*$/ ? : 0 0 0
3307  
3308 0 ▶ if ($code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code) 0 0 0
3309 0 ▶ unless ( $self->_send_line( $response->( $code, $self ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_send_line(&$response($code, $self))) 0 0 0
3310 0 $self->LastError(
3311 "Error sending $scheme data: " . $self->LastError );
3312 0 return undef;
3313 }
3314 0 undef $code; # clear code as we are not finished yet
3315 }
3316  
3317 0 ▶ if ( $o->[DATA] =~ /^$count\s+(OK|NO|BAD)\b/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($o->[2] =~ /^$count\s+(OK|NO|BAD)\b/i) { } 0 0 0
elsif ($o->[2] =~ /^\*\s+BYE/) { } 0 0 0
3318 0 $code = uc($1);
3319 0 ▶ $self->LastError( $o->[DATA] ) unless ( $code eq 'OK' );
Branch: 1 branch
BranchTrueFalseTotal
unless $code eq "OK" 0 0 0
3320 }
3321 elsif ( $o->[DATA] =~ /^\*\s+BYE/ ) {
3322 0 $self->State(Unconnected);
3323 0 $self->LastError( $o->[DATA] );
3324 0 return undef;
3325 }
3326 }
3327 }
3328  
3329 0 ▶ return undef unless $code eq 'OK';
Branch: 1 branch
BranchTrueFalseTotal
unless $code eq "OK" 0 0 0
3330  
3331 0 ▶ Authen::NTLM::ntlm_reset()
Branch: 1 branch
BranchTrueFalseTotal
if $scheme eq "NTLM" 0 0 0
3332 if $scheme eq 'NTLM';
3333  
3334 0 $self->State(Authenticated);
3335 0 return $self;
3336 }
3337  
3338 # UIDPLUS response from a copy: [COPYUID (uidvalidity) (origuid) (newuid)]
3339 0 ▶sub copy {
Subroutine copy: not called CC=8 SCAR=42.8
Pod documented
3340 0 my ( $self, $target, @msgs ) = @_;
3341  
3342 my $msgs =
3343 $self->Ranges
3344 ? $self->Range(@msgs)
3345 0 ▶ : join ',', map { ref $_ ? @$_ : $_ } @msgs;
Branch: 2 branches
BranchTrueFalseTotal
$self->Ranges ? : 0 0 0
ref $_ ? : 0 0 0
3346  
3347 0 ▶ $self->_imap_uid_command( COPY => $msgs, $self->Quote($target) )
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_uid_command("COPY", $msgs, $self->Quote($target)) or return undef 0 0 0
3348 or return undef;
3349  
3350 0 my @results = $self->History;
3351  
3352 0 my @uids;
3353 0 foreach (@results) {
3354 0 chomp;
3355 0 s/$CR?$LF$//o;
3356 0 ▶ s/^.*\[COPYUID\s+\d+\s+[\d:,]+\s+([\d:,]+)\].*/$1/ or next;
Branch: 1 branch
BranchTrueFalseTotal
s/^.*\[COPYUID\s+\d+\s+[\d:,]+\s+([\d:,]+)\].*/$1/ or next 0 0 0
3357 0 ▶ push @uids, /(\d+):(\d+)/ ? ( $1 ... $2 ) : ( split /\,/ );
Branch: 1 branch
BranchTrueFalseTotal
/(\d+):(\d+)/ ? : 0 0 0
3358  
3359 }
3360 0 ▶ return @uids ? join( ",", @uids ) : $self;
Branch: 1 branch
BranchTrueFalseTotal
@uids ? : 0 0 0
3361 }
3362  
3363 0 ▶sub move {
Subroutine move: not called CC=6 SCAR=37.4
Pod documented
3364 0 my ( $self, $target, @msgs ) = @_;
3365  
3366 0 ▶ $self->exists($target)
Branch: 1 branch
BranchTrueFalseTotal
$self->exists($target) or $self->create($target) and $self->subscribe($target) 0 0 0
Condition0%0/6
$self->exists($target) || $self->create($target) && $self->subscribe($target)
l!l&&r!l&&!r
000
$self->create($target) and $self->subscribe($target)
!ll&&!rl&&r
000
MC/DC0%0/3
$self->exists($target) || $self->create($target) && $self->subscribe($target)
$self->exists($target) $self->create($target) $self->subscribe($target)
Truth table0%0/4
A || B and C
A= $self->exists($target)B= $self->create($target)C= $self->subscribe($target)
ABCresult
1XX1
0111
00X0
0100
3367 or $self->create($target) && $self->subscribe($target);
3368  
3369 my $uids =
3370 0 ▶ $self->copy( $target, map { ref $_ eq 'ARRAY' ? @$_ : $_ } @msgs )
Branch: 2 branches
BranchTrueFalseTotal
my $uids = $self->copy($target, map({ref $_ eq "ARRAY" ? @$_ : $_;} @msgs)) or return undef 0 0 0
ref $_ eq 'ARRAY' ? : 0 0 0
3371 or return undef;
3372  
3373 0 ▶ unless ( $self->delete_message(@msgs) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->delete_message(@msgs)) 0 0 0
3374 0 local ($!); # old versions of Carp could reset $!
3375 0 carp $self->LastError;
3376 }
3377  
3378 0 return $uids;
3379 }
3380  
3381 0 ▶sub set_flag {
Subroutine set_flag: not called CC=4 SCAR=30.0
Pod documented
3382 0 my ( $self, $flag, @msgs ) = @_;
3383 0 ▶ @msgs = @{ $msgs[0] } if ref $msgs[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $msgs[0] eq "ARRAY" 0 0 0
3384 0 ▶ $flag = "\\$flag"
Branch: 1 branch
BranchTrueFalseTotal
if $flag =~ /^(?:Answered|Flagged|Deleted|Seen|Draft)$/i 0 0 0
3385 if $flag =~ /^(?:Answered|Flagged|Deleted|Seen|Draft)$/i;
3386  
3387 0 ▶ my $which = $self->Ranges ? $self->Range(@msgs) : join( ',', @msgs );
Branch: 1 branch
BranchTrueFalseTotal
$self->Ranges ? : 0 0 0
3388 0 return $self->store( $which, '+FLAGS.SILENT', "($flag)" );
3389 }
3390  
3391 0 ▶sub see {
Subroutine see: not called CC=2 SCAR=17.9
Pod documented
3392 0 my ( $self, @msgs ) = @_;
3393 0 ▶ @msgs = @{ $msgs[0] } if ref $msgs[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $msgs[0] eq "ARRAY" 0 0 0
3394 0 return $self->set_flag( '\\Seen', @msgs );
3395 }
3396  
3397 0 ▶sub mark {
Subroutine mark: not called CC=2 SCAR=17.9
Pod documented
3398 0 my ( $self, @msgs ) = @_;
3399 0 ▶ @msgs = @{ $msgs[0] } if ref $msgs[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $msgs[0] eq "ARRAY" 0 0 0
3400 0 return $self->set_flag( '\\Flagged', @msgs );
3401 }
3402  
3403 0 ▶sub unmark {
Subroutine unmark: not called CC=2 SCAR=17.9
Pod documented
3404 0 my ( $self, @msgs ) = @_;
3405 0 ▶ @msgs = @{ $msgs[0] } if ref $msgs[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $msgs[0] eq "ARRAY" 0 0 0
3406 0 return $self->unset_flag( '\\Flagged', @msgs );
3407 }
3408  
3409 0 ▶sub unset_flag {
Subroutine unset_flag: not called CC=3 SCAR=24.8
Pod documented
3410 0 my ( $self, $flag, @msgs ) = @_;
3411 0 ▶ @msgs = @{ $msgs[0] } if ref $msgs[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $msgs[0] eq "ARRAY" 0 0 0
3412  
3413 0 ▶ $flag = "\\$flag"
Branch: 1 branch
BranchTrueFalseTotal
if $flag =~ /^(?:Answered|Flagged|Deleted|Seen|Draft)$/i 0 0 0
3414 if $flag =~ /^(?:Answered|Flagged|Deleted|Seen|Draft)$/i;
3415  
3416 0 return $self->store( join( ",", @msgs ), "-FLAGS.SILENT ($flag)" );
3417 }
3418  
3419 0 ▶sub deny_seeing {
Subroutine deny_seeing: not called CC=2 SCAR=17.9
Pod documented
3420 0 my ( $self, @msgs ) = @_;
3421 0 ▶ @msgs = @{ $msgs[0] } if ref $msgs[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $msgs[0] eq "ARRAY" 0 0 0
3422 0 return $self->unset_flag( '\\Seen', @msgs );
3423 }
3424  
3425 0 ▶sub size {
Subroutine size: not called CC=7 SCAR=40.3
Pod documented
3426 0 my ( $self, $msg ) = @_;
3427 0 ▶ my $data = $self->fetch( $msg, "(RFC822.SIZE)" ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $data = $self->fetch($msg, "(RFC822.SIZE)") or return undef 0 0 0
3428  
3429 # beware of response like: * NO Cannot open message $msg
3430 0 my $cmd = shift @$data;
3431 0 my $err;
3432 0 foreach my $line (@$data) {
3433 0 ▶ return $1 if ( $line =~ /RFC822\.SIZE\s+(\d+)/ );
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /RFC822\.SIZE\s+(\d+)/ 0 0 0
3434 0 ▶ $err = $line if ( $line =~ /\* NO\b/ );
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\* NO\b/ 0 0 0
3435 }
3436  
3437 0 ▶ if ($err) {
Branch: 2 branches
BranchTrueFalseTotal
if ($err) { } 0 0 0
elsif (not $self->LastError) { } 0 0 0
3438 0 my $info = "$err was returned for $cmd";
3439 0 $info =~ s/$CR?$LF//og;
3440 0 $self->LastError($info);
3441 }
3442 elsif ( !$self->LastError ) {
3443 0 my $info = "no RFC822.SIZE found in: " . join( " ", @$data );
3444 0 $self->LastError($info);
3445 }
3446 0 return undef;
3447 }
3448  
3449 0 ▶sub getquotaroot {
Subroutine getquotaroot: not called CC=3 SCAR=24.8
Pod documented
3450 0 my ( $self, $what ) = @_;
3451 0 ▶ my $who = defined $what ? $self->Quote($what) : "INBOX";
Branch: 1 branch
BranchTrueFalseTotal
defined $what ? : 0 0 0
3452 0 ▶ return $self->_imap_command("GETQUOTAROOT $who") ? $self->Results : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command("GETQUOTAROOT $who") ? : 0 0 0
3453 }
3454  
3455 # BUG? using user/$User here and INBOX in quota/quota_usage
3456 0 ▶sub getquota {
Subroutine getquota: not called CC=3 SCAR=24.8
Pod documented
3457 0 my ( $self, $what ) = @_;
3458 0 ▶ my $who = defined $what ? $self->Quote($what) : "user/" . $self->User;
Branch: 1 branch
BranchTrueFalseTotal
defined $what ? : 0 0 0
3459 0 ▶ return $self->_imap_command("GETQUOTA $who") ? $self->Results : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command("GETQUOTA $who") ? : 0 0 0
3460 }
3461  
3462 # usage: $self->setquota($quotaroot, storage => 512, ...)
3463 0 ▶sub setquota(@) {
Subroutine setquota: not called CC=4 SCAR=30.0
Pod documented
3464 0 my ( $self, $what ) = ( shift, shift );
3465 0 ▶ my $who = defined $what ? $self->Quote($what) : "user/" . $self->User;
Branch: 1 branch
BranchTrueFalseTotal
defined $what ? : 0 0 0
3466 0 my @limits;
3467 0 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
3468 0 my ( $k, $v ) = ( $self->Quote( uc( shift @_ ) ), shift @_ );
3469 0 push( @limits, "($k $v)" );
3470 }
3471 0 my $limits = join( ' ', @limits );
3472 0 ▶ $self->_imap_command("SETQUOTA $who $limits") ? $self->Results : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_imap_command("SETQUOTA $who $limits") ? : 0 0 0
3473 }
3474  
3475 0 ▶sub quota {
Subroutine quota: not called CC=4 SCAR=30.0
Pod documented
3476 0 ▶ my ( $self, $what ) = ( shift, shift || "INBOX" );
Condition0%0/2
shift() || 'INBOX'
l!l
00
MC/DC0%0/1
shift() || 'INBOX'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3477 0 ▶ my $tref = $self->getquota($what) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $tref = $self->getquota($what) or return undef 0 0 0
3478 0 shift @$tref; # pop off command
3479 0 ▶ return ( map { /.*STORAGE\s+\d+\s+(\d+).*\n$/ ? $1 : () } @$tref )[0];
Branch: 1 branch
BranchTrueFalseTotal
/.*STORAGE\s+\d+\s+(\d+).*\n$/ ? : 0 0 0
3480 }
3481  
3482 0 ▶sub quota_usage {
Subroutine quota_usage: not called CC=4 SCAR=30.0
Pod documented
3483 0 ▶ my ( $self, $what ) = ( shift, shift || "INBOX" );
Condition0%0/2
shift() || 'INBOX'
l!l
00
MC/DC0%0/1
shift() || 'INBOX'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3484 0 ▶ my $tref = $self->getquota($what) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $tref = $self->getquota($what) or return undef 0 0 0
3485 0 shift @$tref; # pop off command
3486 0 ▶ return ( map { /.*STORAGE\s+(\d+)\s+\d+.*\n$/ ? $1 : () } @$tref )[0];
Branch: 1 branch
BranchTrueFalseTotal
/.*STORAGE\s+(\d+)\s+\d+.*\n$/ ? : 0 0 0
3487 }
3488  
3489 # rfc3501:
3490 # atom-specials = "(" / ")" / "{" / SP / CTL / list-wildcards /
3491 # quoted-specials / resp-specials
3492 # list-wildcards = "%" / "*"
3493 # quoted-specials = DQUOTE / "\"
3494 # resp-specials = "]"
3495 # rfc2060:
3496 # CTL ::= <any ASCII control character and DEL, 0x00 - 0x1f, 0x7f>
3497 # Paranoia/safety:
3498 # encode strings with "}" / "[" / "]" / non-ascii chars
3499 0 ▶sub Quote($;$) {
Subroutine Quote: not called CC=5 SCAR=34.0
Pod documented
3500 0 my ( $self, $name, $force ) = @_;
3501 0 ▶ if ( $force or $name =~ /["\\[:^ascii:][:cntrl:]]/s ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($force or $name =~ /["\\[:^ascii:][:cntrl:]]/s) { } 0 0 0
elsif ($name =~ /[(){}\s%*\[\]]/s or $name eq '') { } 0 0 0
Condition0%0/3
$force or $name =~ /["\\[:^ascii:][:cntrl:]]/s
l!l&&r!l&&!r
000
MC/DC0%0/2
$force or $name =~ /["\\[:^ascii:][:cntrl:]]/s
$force $name =~ /["\\[:^ascii:][:cntrl:]]/s
Truth table0%0/3
A or B
A= $forceB= $name =~ /["\\[:^ascii:][:cntrl:]]/s
ABresult
1X1
011
000
3502 0 return "{" . length($name) . "}" . $CRLF . $name;
3503 }
3504 ▶ elsif ( $name =~ /[(){}\s%*\[\]]/s or $name eq "" ) {
Condition0%0/3
$name =~ /[(){}\s%*\[\]]/s or $name eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
$name =~ /[(){}\s%*\[\]]/s or $name eq ""
$name =~ /[(){}\s%*\[\]]/s $name eq ""
Truth table0%0/3
A or B
A= $name =~ /[(){}\s%*\[\]]/sB= $name eq ""
ABresult
1X1
011
000
3505 0 return qq("$name");
3506 }
3507 else {
3508 0 return $name;
3509 }
3510 }
3511  
3512 # legacy behavior: strip double quote around folder name args!
3513 0 ▶sub Massage($;$) {
Subroutine Massage: not called CC=2 SCAR=17.9
Pod documented
3514 0 my ( $self, $name, $notFolder ) = @_;
3515 0 ▶ $name =~ s/^\"(.*)\"$/$1/s unless $notFolder;
Branch: 1 branch
BranchTrueFalseTotal
unless $notFolder 0 0 0
3516 0 return $self->Quote($name);
3517 }
3518  
3519 0 ▶sub unseen_count {
Subroutine unseen_count: not called CC=3 SCAR=24.8
Pod documented
3520 0 my ( $self, $folder ) = ( shift, shift );
3521 0 ▶ $folder ||= $self->Folder;
Condition0%0/3
$folder ||= $self->Folder
l!l&&r!l&&!r
000
MC/DC0%0/2
$folder ||= $self->Folder
$folder $self->Folder
Truth table0%0/3
A ||= B
A= $folderB= $self->Folder
ABresult
1X1
011
000
3522 0 ▶ $self->status( $folder, 'UNSEEN' ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->status($folder, "UNSEEN") or return undef 0 0 0
3523  
3524 my $r =
3525 0 ▶ first { s/\*\s+STATUS\s+.*\(UNSEEN\s+(\d+)\s*\)/$1/ } $self->History;
Subroutine __ANON__: not called CC=1 SCAR=6.9
3526  
3527 0 $r =~ s/\D//g;
3528 0 return $r;
3529 }
3530  
3531 0 ▶sub State($) {
Subroutine State: not called CC=4 SCAR=30.0
Pod documented
3532 0 my ( $self, $state ) = @_;
3533  
3534 0 ▶ if ( defined $state ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $state) 0 0 0
3535 0 $self->{State} = $state;
3536  
3537 # discard cached capability info after authentication
3538 0 ▶ delete $self->{CAPABILITY} if ( $state == Authenticated );
Branch: 1 branch
BranchTrueFalseTotal
if $state == 2 0 0 0
3539 }
3540  
3541 0 ▶ return defined( $self->{State} ) ? $self->{State} : Unconnected;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'State'} ? : 0 0 0
3542 }
3543  
3544 0 ▶sub Status { shift->State }
Subroutine Status: not called CC=1 SCAR=6.9
Pod documented
3545 0 ▶sub IsUnconnected { shift->State == Unconnected }
Subroutine IsUnconnected: not called CC=1 SCAR=6.9
Pod documented
3546 0 ▶sub IsConnected { shift->State >= Connected }
Subroutine IsConnected: not called CC=1 SCAR=6.9
Pod documented
3547 0 ▶sub IsAuthenticated { shift->State >= Authenticated }
Subroutine IsAuthenticated: not called CC=1 SCAR=6.9
Pod documented
3548 0 ▶sub IsSelected { shift->State == Selected }
Subroutine IsSelected: not called CC=1 SCAR=6.9
Pod documented
3549  
3550 # The following private methods all work on an output line array.
3551 # _data returns the data portion of an output array:
3552 0 ▶sub _data { ref $_[1] && defined $_[1]->[TYPE] ? $_[1]->[DATA] : undef }
Subroutine _data: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] && defined $_[1][1] ? : 0 0 0
Condition0%0/3
ref $_[1] and defined $_[1][1]
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[1] and defined $_[1][1]
ref $_[1] defined $_[1][1]
Truth table0%0/3
A and B
A= ref $_[1]B= defined $_[1][1]
ABresult
0X0
100
111
3553  
3554 # _index returns the index portion of an output array:
3555 0 ▶sub _index { ref $_[1] && defined $_[1]->[TYPE] ? $_[1]->[INDEX] : undef }
Subroutine _index: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] && defined $_[1][1] ? : 0 0 0
Condition0%0/3
ref $_[1] and defined $_[1][1]
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[1] and defined $_[1][1]
ref $_[1] defined $_[1][1]
Truth table0%0/3
A and B
A= ref $_[1]B= defined $_[1][1]
ABresult
0X0
100
111
3556  
3557 # _type returns the type portion of an output array:
3558 0 ▶sub _type { ref $_[1] && $_[1]->[TYPE] }
Subroutine _type: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] and $_[1][1] 0 0 0
3559  
3560 # _is_literal returns true if this is a literal:
3561 11 ▶sub _is_literal { ref $_[1] && $_[1]->[TYPE] && $_[1]->[TYPE] eq 'LITERAL' }
Subroutine _is_literal: called CC=3 SCAR=14.2
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] and $_[1][1] and $_[1][1] eq "LITERAL" 0 11 11
Condition33%1/3
ref $_[1] and $_[1][1]
!ll&&!rl&&r
1100
MC/DC0%0/2
ref $_[1] and $_[1][1]
ref $_[1] $_[1][1]
Truth table33%1/3
A and B
A= ref $_[1]B= $_[1][1]
ABresult
0X0
100
111
3562  
3563 # _is_output_or_literal returns true if this is an
3564 # output line (or the literal part of one):
3565  
3566 0 ▶sub _is_output_or_literal {
Subroutine _is_output_or_literal: not called CC=4 SCAR=30.0
3567 0 ▶ ref $_[1]
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] and defined $_[1][1] and $_[1][1] eq "OUTPUT" || $_[1][1] eq "LITERAL" 0 0 0
Condition0%0/9
ref $_[1] && defined $_[1][1] && ($_[1][1] eq 'OUTPUT' || $_[1][1] eq 'LITERAL')
!ll&&!rl&&r
000
ref $_[1] and defined $_[1][1]
!ll&&!rl&&r
000
$_[1][1] eq "OUTPUT" or $_[1][1] eq "LITERAL"
l!l&&r!l&&!r
000
MC/DC0%0/4
ref $_[1] && defined $_[1][1] && ($_[1][1] eq 'OUTPUT' || $_[1][1] eq 'LITERAL')
ref $_[1] defined $_[1][1] $_[1][1] eq "OUTPUT" $_[1][1] eq "LITERAL"
Truth table0%0/5
A and B && C or D
A= ref $_[1]B= defined $_[1][1]C= $_[1][1] eq "OUTPUT"D= $_[1][1] eq "LITERAL"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
3568 && defined $_[1]->[TYPE]
3569 && ( $_[1]->[TYPE] eq "OUTPUT" || $_[1]->[TYPE] eq "LITERAL" );
3570 }
3571  
3572 # _is_output returns true if this is an output line:
3573 0 ▶sub _is_output { ref $_[1] && $_[1]->[TYPE] && $_[1]->[TYPE] eq "OUTPUT" }
Subroutine _is_output: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] and $_[1][1] and $_[1][1] eq "OUTPUT" 0 0 0
Condition0%0/3
ref $_[1] and $_[1][1]
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[1] and $_[1][1]
ref $_[1] $_[1][1]
Truth table0%0/3
A and B
A= ref $_[1]B= $_[1][1]
ABresult
0X0
100
111
3574  
3575 # _is_input returns true if this is an input line:
3576 0 ▶sub _is_input { ref $_[1] && $_[1]->[TYPE] && $_[1]->[TYPE] eq "INPUT" }
Subroutine _is_input: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] and $_[1][1] and $_[1][1] eq "INPUT" 0 0 0
Condition0%0/3
ref $_[1] and $_[1][1]
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[1] and $_[1][1]
ref $_[1] $_[1][1]
Truth table0%0/3
A and B
A= ref $_[1]B= $_[1][1]
ABresult
0X0
100
111
3577  
3578 # _next_index returns next_index for a transaction; may legitimately
3579 # return 0 when successful.
3580 0 ▶sub _next_index { my $r = $_[0]->_transaction( $_[1] ); $r }
Subroutine _next_index: not called CC=1 SCAR=6.9
3581  
3582 0 ▶sub Range {
Subroutine Range: not called CC=2 SCAR=17.9
Pod documented
3583 0 my ( $self, $targ ) = ( shift, shift );
3584  
3585 0 ▶ UNIVERSAL::isa( $targ, 'Mail::IMAPClient::MessageSet' )
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($targ, 'Mail::IMAPClient::MessageSet') ? : 0 0 0
3586 ? $targ->cat(@_)
3587 : Mail::IMAPClient::MessageSet->new( $targ, @_ );
3588 }
3589  
3590 3 1;
↑ Summary IMAPClient/BodyStructure/Parse.pm »