Box/Manager.pm

filter: Statementstmt 76.1% 214 / 281 Branchbran 58.6% 88 / 150 Conditioncond 39.5% 57 / 144 MC/DCmcdc 20.0% 17 / 85 Subroutinesub 90.0% 27 / 30 Podpod 90.4% 19 / 21 totaltotal 59.3% 422 / 711 CC 146 SCAR 54.0
CC
146
Cov
62%
open
591.0
appendMessages
52.7
copyMessage
30.2
CRAP 222.5
↑ Summary Box/Net.pm »
1 # This code is part of Perl distribution Mail-Box version 4.02.
2 # The POD got stripped from this file by OODoc version 3.06.
3 # For contributors see file ChangeLog.
4  
5 # This software is copyright (c) 2001-2026 by Mark Overmeer.
6  
7 # This is free software; you can redistribute it and/or modify it under
8 # the same terms as the Perl 5 programming language system itself.
9 # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10  
11  
12 package Mail::Box::Manager;{
13 14 our $VERSION = '4.02';
14 }
15  
16 14 ▶use parent 'Mail::Reporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 14 ▶use Log::Report 'mail-box', import => [ qw/__x error info trace warning/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 14 ▶use Mail::Box ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 14 ▶use List::Util qw/first/;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 14 ▶use Scalar::Util qw/weaken blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 # failed compilation will not complain a second time
29 # so we need to keep track.
30 14 my %require_failed;
31  
32 #--------------------
33  
34 14 my @basic_folder_types = (
35 [ mbox => 'Mail::Box::Mbox' ],
36 [ mh => 'Mail::Box::MH' ],
37 [ maildir => 'Mail::Box::Maildir' ],
38 [ pop => 'Mail::Box::POP3' ],
39 [ pop3 => 'Mail::Box::POP3' ],
40 [ pops => 'Mail::Box::POP3s' ],
41 [ pop3s => 'Mail::Box::POP3s' ],
42 [ imap => 'Mail::Box::IMAP4' ],
43 [ imap4 => 'Mail::Box::IMAP4' ],
44 [ imaps => 'Mail::Box::IMAP4s' ],
45 [ imap4s => 'Mail::Box::IMAP4s' ],
46 );
47  
48 14 my @managers; # usually only one, but there may be more around :(
49  
50 sub init($)
51 13 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=11 SCAR=28.8
Pod undocumented
52 13 $self->SUPER::init($args);
53  
54 # Register all folder-types. There may be some added later.
55  
56 13 my @new_types;
57 13 ▶ if(my $ft = $args->{folder_types})
Branch: 1 branch
BranchTrueFalseTotal
if (my $ft = $args->{"folder_types"}) 0 13 13
58 0 ▶ { @new_types = ref($ft->[0]) eq 'ARRAY' ? @$ft : $ft;
Branch: 1 branch
BranchTrueFalseTotal
ref $ft->[0] eq 'ARRAY' ? : 0 0 0
59 }
60  
61 13 my @basic_types = reverse @basic_folder_types;
62 13 ▶ if(my $basic = $args->{autodetect})
Branch: 1 branch
BranchTrueFalseTotal
if (my $basic = $args->{"autodetect"}) 0 13 13
63 0 ▶ { my %types = map +($_ => 1), ref $basic ? @$basic : $basic;
Branch: 1 branch
BranchTrueFalseTotal
ref $basic ? : 0 0 0
64 0 @basic_types = grep $types{$_->[0]}, @basic_types;
65 }
66  
67 13 $self->{MBM_folder_types} = [];
68 13 $self->registerType(@$_) for @new_types, @basic_types;
69  
70 13 ▶ $self->{MBM_default_type} = $args->{default_folder_type} || 'mbox';
Condition100%2/2
$args->{'default_folder_type'} || 'mbox'
l!l
112
MC/DC100%1/1
$args->{'default_folder_type'} || 'mbox'
$args->{'default_folder_type'}
Truth table100%2/2
A
A= $args->{'default_folder_type'}
Aresult
11
00
71  
72 # Inventory on existing folder-directories.
73 13 my $fd = $self->{MBM_folderdirs} = [ ];
74 13 ▶ if(exists $args->{folderdir})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"folderdir"}) 1 12 13
75 1 { my @dirs = $args->{folderdir};
76 0 ▶ @dirs = @{$dirs[0]} if ref $dirs[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $dirs[0] eq "ARRAY" 0 1 1
77 1 push @$fd, @dirs;
78 }
79  
80 13 ▶ if(exists $args->{folderdirs})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"folderdirs"}) 0 13 13
81 0 { my @dirs = $args->{folderdirs};
82 0 ▶ @dirs = @{$dirs[0]} if ref $dirs[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $dirs[0] 0 0 0
83 0 push @$fd, @dirs;
84 }
85 13 push @$fd, '.';
86  
87 13 $self->{MBM_folders} = [];
88 13 $self->{MBM_threads} = [];
89  
90 13 push @managers, $self;
91 13 weaken $managers[-1];
92  
93 13 $self;
94 }
95  
96 #--------------------
97  
98 sub registerType($$@)
99 143 ▶{ my ($self, $name, $class, @options) = @_;
Subroutine registerType: called CC=1 SCAR=0.0
Pod documented
100 143 unshift @{$self->{MBM_folder_types}}, [$name, $class, @options];
101 143 $self;
102 }
103  
104  
105 sub folderdir()
106 2 ▶{ my $dirs = shift->{MBM_folderdirs} or return ();
Subroutine folderdir: called CC=3 SCAR=12.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $dirs = +(shift())->{"MBM_folderdirs"} or return () 2 0 2
107 2 ▶ wantarray ? @$dirs : $dirs->[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 2 2
108 }
109  
110  
111 sub folderTypes()
112 0 ▶{ my $self = shift;
Subroutine folderTypes: not called CC=2 SCAR=17.9
Pod documented
113 0 my %uniq;
114 0 $uniq{$_->[0]}++ for $self->folderTypeDefs;
115 0 sort keys %uniq;
116 }
117  
118  
119 sub defaultFolderType()
120 3 ▶{ my $self = shift;
Subroutine defaultFolderType: called CC=5 SCAR=16.7
Pod documented
121 3 my $name = $self->{MBM_default_type};
122 3 ▶ return $name if $name =~ m/\:\:/; # obviously a class name
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\:\:/ 0 3 3
123  
124 3 foreach my $def ($self->folderTypeDefs)
125 5 ▶ { return $def->[1] if $def->[0] eq $name || $def->[1] eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if $def->[0] eq $name or $def->[1] eq $name 3 2 5
Condition66%2/3
$def->[0] eq $name or $def->[1] eq $name
l!l&&r!l&&!r
302
MC/DC50%1/2
$def->[0] eq $name or $def->[1] eq $name
$def->[0] eq $name $def->[1] eq $name
Truth table66%2/3
A or B
A= $def->[0] eq $nameB= $def->[1] eq $name
ABresult
1X1
011
000
126 }
127  
128 0 undef;
129 }
130  
131  
132 617 ▶sub threads(@) { my $self = shift; @_ ? $self->discoverThreads(@_) : @{$self->{MBM_threads}} }
Subroutine threads: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 3 614 617
133  
134  
135 45 ▶sub folderTypeDefs() { @{$_[0]->{MBM_folder_types}} }
Subroutine folderTypeDefs: called CC=1 SCAR=0.0
Pod documented
136  
137 #--------------------
138  
139 sub open(@)
140 40 ▶{ my $self = shift;
Subroutine open: called CC=62 SCAR=63.8
Pod documented
141 40 ▶ my $name = @_ % 2 ? shift : undef;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 ? : 8 32 40
142 40 my %args = @_;
143  
144 40 ▶ $args{authentication} ||= 'AUTO';
Condition100%2/2
$args{"authentication"} ||= "AUTO"
l!l
1921
MC/DC100%1/1
$args{"authentication"} ||= "AUTO"
$args{"authentication"}
Truth table100%2/2
A
A= $args{"authentication"}
Aresult
11
00
145 40 ▶ $name //= defined $args{folder} ? $args{folder} : ($ENV{MAIL} || '');
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'folder'} ? : 32 0 32
Condition40%2/5
$name //= defined $args{"folder"} ? $args{"folder"} : $ENV{"MAIL"} || ""
l!l&&r!l&&!r
8320
$ENV{"MAIL"} or ""
l!l
00
MC/DC0%0/2
$name //= defined $args{"folder"} ? $args{"folder"} : $ENV{"MAIL"} || ""
$name defined $args{"folder"} ? $args{"folder"} : $ENV{"MAIL"} || ""
MC/DC0%0/1
$ENV{"MAIL"} or ""
$ENV{"MAIL"}
Truth table66%2/3
A //= B
A= $nameB= defined $args{"folder"} ? $args{"folder"} : $ENV{"MAIL"} || ""
ABresult
1X1
011
000
Truth table0%0/2
A
A= $ENV{"MAIL"}
Aresult
11
00
146  
147 40 ▶ if($name =~ m/^(\w+)\:/ && grep $_ eq $1, $self->folderTypes)
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^(\w+)\:/ and grep(($_ eq $1), $self->folderTypes)) { } 0 40 40
Condition33%1/3
$name =~ /^(\w+)\:/ and grep(($_ eq $1), $self->folderTypes)
!ll&&!rl&&r
4000
MC/DC0%0/2
$name =~ /^(\w+)\:/ and grep(($_ eq $1), $self->folderTypes)
$name =~ /^(\w+)\:/ grep(($_ eq $1), $self->folderTypes)
Truth table33%1/3
A and B
A= $name =~ /^(\w+)\:/B= grep(($_ eq $1), $self->folderTypes)
ABresult
0X0
100
111
148 { # Complicated folder URL
149 0 my %decoded = $self->decodeFolderURL($name);
150 0 ▶ keys %decoded
Branch: 1 branch
BranchTrueFalseTotal
keys %decoded or &error(&__x("illegal folder URL '{name}'.", "name", $name)) 0 0 0
151 or error __x"illegal folder URL '{name}'.", name => $name;
152  
153 # accept decoded info
154 0 @args{keys %decoded} = values %decoded;
155 }
156 else
157 { # Simple folder name
158 40 $args{folder} = $name;
159 }
160  
161 # Do not show password in folder name
162 40 my $type = $args{type};
163 40 ▶ if(!defined $type) { ; }
Branch: 5 branches
BranchTrueFalseTotal
if (not defined $type) { } 14 26 40
elsif ($type eq 'pop3' or $type eq 'pop') { } 0 26 26
elsif ($type eq 'pop3s' or $type eq 'pops') { } 0 26 26
elsif ($type eq 'imap4' or $type eq 'imap') { } 0 26 26
elsif ($type eq 'imap4s' or $type eq 'imaps') { } 0 26 26
164 ▶ elsif($type eq 'pop3' || $type eq 'pop')
Condition33%1/3
$type eq "pop3" or $type eq "pop"
l!l&&r!l&&!r
0026
MC/DC0%0/2
$type eq "pop3" or $type eq "pop"
$type eq "pop3" $type eq "pop"
Truth table33%1/3
A or B
A= $type eq "pop3"B= $type eq "pop"
ABresult
1X1
011
000
165 0 ▶ { my $un = $args{username} ||= $ENV{USER} || $ENV{LOGIN};
Condition0%0/6
$args{"username"} ||= $ENV{"USER"} || $ENV{"LOGIN"}
l!l&&r!l&&!r
000
$ENV{'USER'} || $ENV{'LOGIN'}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{"username"} ||= $ENV{"USER"} || $ENV{"LOGIN"}
$args{"username"} $ENV{'USER'} $ENV{'LOGIN'}
Truth table0%0/4
A ||= B || C
A= $args{"username"}B= $ENV{'USER'}C= $ENV{'LOGIN'}
ABCresult
1XX1
01X1
0011
0000
166 0 ▶ my $srv = $args{server_name} ||= 'localhost';
Condition0%0/2
$args{"server_name"} ||= "localhost"
l!l
00
MC/DC0%0/1
$args{"server_name"} ||= "localhost"
$args{"server_name"}
Truth table0%0/2
A
A= $args{"server_name"}
Aresult
11
00
167 0 ▶ my $port = $args{server_port} ||= 110;
Condition0%0/2
$args{"server_port"} ||= 110
l!l
00
MC/DC0%0/1
$args{"server_port"} ||= 110
$args{"server_port"}
Truth table0%0/2
A
A= $args{"server_port"}
Aresult
11
00
168 0 $args{folderdir} = $name = "pop3://$un\@$srv:$port";
169 }
170 ▶ elsif($type eq 'pop3s' || $type eq 'pops')
Condition33%1/3
$type eq "pop3s" or $type eq "pops"
l!l&&r!l&&!r
0026
MC/DC0%0/2
$type eq "pop3s" or $type eq "pops"
$type eq "pop3s" $type eq "pops"
Truth table33%1/3
A or B
A= $type eq "pop3s"B= $type eq "pops"
ABresult
1X1
011
000
171 0 ▶ { my $un = $args{username} ||= $ENV{USER} || $ENV{LOGIN};
Condition0%0/6
$args{"username"} ||= $ENV{"USER"} || $ENV{"LOGIN"}
l!l&&r!l&&!r
000
$ENV{'USER'} || $ENV{'LOGIN'}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{"username"} ||= $ENV{"USER"} || $ENV{"LOGIN"}
$args{"username"} $ENV{'USER'} $ENV{'LOGIN'}
Truth table0%0/4
A ||= B || C
A= $args{"username"}B= $ENV{'USER'}C= $ENV{'LOGIN'}
ABCresult
1XX1
01X1
0011
0000
172 0 ▶ my $srv = $args{server_name} ||= 'localhost';
Condition0%0/2
$args{"server_name"} ||= "localhost"
l!l
00
MC/DC0%0/1
$args{"server_name"} ||= "localhost"
$args{"server_name"}
Truth table0%0/2
A
A= $args{"server_name"}
Aresult
11
00
173 0 ▶ my $port = $args{server_port} ||= 995;
Condition0%0/2
$args{"server_port"} ||= 995
l!l
00
MC/DC0%0/1
$args{"server_port"} ||= 995
$args{"server_port"}
Truth table0%0/2
A
A= $args{"server_port"}
Aresult
11
00
174 0 $args{folderdir} = $name = "pop3s://$un\@$srv:$port";
175 }
176 ▶ elsif($type eq 'imap4' || $type eq 'imap')
Condition33%1/3
$type eq "imap4" or $type eq "imap"
l!l&&r!l&&!r
0026
MC/DC0%0/2
$type eq "imap4" or $type eq "imap"
$type eq "imap4" $type eq "imap"
Truth table33%1/3
A or B
A= $type eq "imap4"B= $type eq "imap"
ABresult
1X1
011
000
177 0 ▶ { my $un = $args{username} ||= $ENV{USER} || $ENV{LOGIN};
Condition0%0/6
$args{"username"} ||= $ENV{"USER"} || $ENV{"LOGIN"}
l!l&&r!l&&!r
000
$ENV{'USER'} || $ENV{'LOGIN'}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{"username"} ||= $ENV{"USER"} || $ENV{"LOGIN"}
$args{"username"} $ENV{'USER'} $ENV{'LOGIN'}
Truth table0%0/4
A ||= B || C
A= $args{"username"}B= $ENV{'USER'}C= $ENV{'LOGIN'}
ABCresult
1XX1
01X1
0011
0000
178 0 ▶ my $srv = $args{server_name} ||= 'localhost';
Condition0%0/2
$args{"server_name"} ||= "localhost"
l!l
00
MC/DC0%0/1
$args{"server_name"} ||= "localhost"
$args{"server_name"}
Truth table0%0/2
A
A= $args{"server_name"}
Aresult
11
00
179 0 ▶ my $port = $args{server_port} ||= 143;
Condition0%0/2
$args{"server_port"} ||= 143
l!l
00
MC/DC0%0/1
$args{"server_port"} ||= 143
$args{"server_port"}
Truth table0%0/2
A
A= $args{"server_port"}
Aresult
11
00
180 0 $args{folderdir} = $name = "imap4://$un\@$srv:$port";
181 }
182 ▶ elsif($type eq 'imap4s' || $type eq 'imaps')
Condition33%1/3
$type eq "imap4s" or $type eq "imaps"
l!l&&r!l&&!r
0026
MC/DC0%0/2
$type eq "imap4s" or $type eq "imaps"
$type eq "imap4s" $type eq "imaps"
Truth table33%1/3
A or B
A= $type eq "imap4s"B= $type eq "imaps"
ABresult
1X1
011
000
183 0 ▶ { my $un = $args{username} ||= $ENV{USER} || $ENV{LOGIN};
Condition0%0/6
$args{"username"} ||= $ENV{"USER"} || $ENV{"LOGIN"}
l!l&&r!l&&!r
000
$ENV{'USER'} || $ENV{'LOGIN'}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{"username"} ||= $ENV{"USER"} || $ENV{"LOGIN"}
$args{"username"} $ENV{'USER'} $ENV{'LOGIN'}
Truth table0%0/4
A ||= B || C
A= $args{"username"}B= $ENV{'USER'}C= $ENV{'LOGIN'}
ABCresult
1XX1
01X1
0011
0000
184 0 ▶ my $srv = $args{server_name} ||= 'localhost';
Condition0%0/2
$args{"server_name"} ||= "localhost"
l!l
00
MC/DC0%0/1
$args{"server_name"} ||= "localhost"
$args{"server_name"}
Truth table0%0/2
A
A= $args{"server_name"}
Aresult
11
00
185 0 ▶ my $port = $args{server_port} ||= 993;
Condition0%0/2
$args{"server_port"} ||= 993
l!l
00
MC/DC0%0/1
$args{"server_port"} ||= 993
$args{"server_port"}
Truth table0%0/2
A
A= $args{"server_port"}
Aresult
11
00
186 0 $args{folderdir} = $name = "imap4s://$un\@$srv:$port";
187 }
188  
189 40 ▶ defined $name && length $name
Branch: 1 branch
BranchTrueFalseTotal
defined $name and length $name or &error(&__x("no foldername specified to open.")) 40 0 40
Condition33%1/3
defined $name and length $name
!ll&&!rl&&r
0040
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table33%1/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
190 or error __x"no foldername specified to open.";
191  
192 $args{folderdir} ||= $self->{MBM_folderdirs}->[0]
193 40 ▶ if $self->{MBM_folderdirs};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MBM_folderdirs"} 40 0 40
Condition66%2/3
$args{"folderdir"} ||= $self->{"MBM_folderdirs"}[0]
l!l&&r!l&&!r
26140
MC/DC0%0/2
$args{"folderdir"} ||= $self->{"MBM_folderdirs"}[0]
$args{"folderdir"} $self->{"MBM_folderdirs"}[0]
Truth table66%2/3
A ||= B
A= $args{"folderdir"}B= $self->{"MBM_folderdirs"}[0]
ABresult
1X1
011
000
194  
195 40 ▶ $args{access} ||= 'r';
Condition100%2/2
$args{"access"} ||= "r"
l!l
355
MC/DC100%1/1
$args{"access"} ||= "r"
$args{"access"}
Truth table100%2/2
A
A= $args{"access"}
Aresult
11
00
196  
197 40 ▶ if($args{create} && $args{access} !~ m/w|a/)
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"create"} and not $args{"access"} =~ /w|a/) 0 40 40
Condition66%2/3
$args{"create"} and not $args{"access"} =~ /w|a/
!ll&&!rl&&r
26140
MC/DC0%0/2
$args{"create"} and not $args{"access"} =~ /w|a/
$args{"create"} not $args{"access"} =~ /w|a/
Truth table66%2/3
A and not(B)
A= $args{"create"}B= not $args{"access"} =~ /w|a/
ABresult
0X0
100
111
198 0 { warning __x"will never create a folder {name} without having write access.", name => $name;
199 0 undef $args{create};
200 }
201  
202 # Do not open twice.
203 40 ▶ my $folder = $self->isOpenFolder($name)
Branch: 1 branch
BranchTrueFalseTotal
my $folder = $self->isOpenFolder($name) and &error(&__x("folder {name} is already open.", "name", $name)) 1 39 40
204 and error __x"folder {name} is already open.", name => $name;
205  
206 #
207 # Which folder type do we need?
208 #
209  
210 39 my ($folder_type, $class, @defaults);
211 39 my @typedefs = $self->folderTypeDefs;
212 39 ▶ if($type)
Branch: 1 branch
BranchTrueFalseTotal
if ($type) 26 13 39
213 { # User-specified foldertype prevails.
214 26 foreach (@typedefs)
215 39 { (my $abbrev, $class, @defaults) = @$_;
216  
217 39 ▶ if($type eq $abbrev || $type eq $class)
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq $abbrev or $type eq $class) 26 13 39
Condition100%3/3
$type eq $abbrev or $type eq $class
l!l&&r!l&&!r
17913
MC/DC100%2/2
$type eq $abbrev or $type eq $class
$type eq $abbrev $type eq $class
Truth table100%3/3
A or B
A= $type eq $abbrevB= $type eq $class
ABresult
1X1
011
000
218 26 { $folder_type = $abbrev;
219 26 last;
220 }
221 }
222  
223 $folder_type
224 26 ▶ or warning __x"folder type {type} is unknown, using autodetect.", $type => $type;
Branch: 1 branch
BranchTrueFalseTotal
$folder_type or &warning(&__x("folder type {type} is unknown, using autodetect.", $type, $type)) 26 0 26
225 }
226  
227 39 ▶ unless($folder_type)
Branch: 1 branch
BranchTrueFalseTotal
unless ($folder_type) 13 26 39
228 { # Try to autodetect foldertype.
229 13 foreach (@typedefs)
230 29 { (my $abbrev, $class, @defaults) = @$_;
231 29 ▶ next if $require_failed{$class};
Branch: 1 branch
BranchTrueFalseTotal
if $require_failed{$class} 0 29 29
232  
233 29 eval "require $class";
234 29 ▶ if($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 29 29
235 0 { $require_failed{$class}++;
236 0 next;
237 }
238  
239 29 ▶ if($class->foundIn($name, @defaults, %args))
Branch: 1 branch
BranchTrueFalseTotal
if ($class->foundIn($name, @defaults, %args)) 12 17 29
240 12 { $folder_type = $abbrev;
241 12 last;
242 }
243 }
244 }
245  
246 39 ▶ unless($folder_type)
Branch: 1 branch
BranchTrueFalseTotal
unless ($folder_type) 1 38 39
247 { # Use specified default
248 1 ▶ if(my $type = $self->{MBM_default_type})
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = $self->{"MBM_default_type"}) 1 0 1
249 1 { foreach (@typedefs)
250 1 { (my $abbrev, $class, @defaults) = @$_;
251 1 ▶ if($type eq $abbrev || $type eq $class)
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq $abbrev or $type eq $class) 1 0 1
Condition33%1/3
$type eq $abbrev or $type eq $class
l!l&&r!l&&!r
100
MC/DC0%0/2
$type eq $abbrev or $type eq $class
$type eq $abbrev $type eq $class
Truth table33%1/3
A or B
A= $type eq $abbrevB= $type eq $class
ABresult
1X1
011
000
252 1 { $folder_type = $abbrev;
253 1 last;
254 }
255 }
256 }
257 }
258  
259 39 ▶ unless($folder_type)
Branch: 1 branch
BranchTrueFalseTotal
unless ($folder_type) 0 39 39
260 { # use first type (last defined)
261 0 ($folder_type, $class, @defaults) = @{$typedefs[0]};
262 }
263  
264 #
265 # Try to open the folder
266 #
267  
268 39 ▶ return if $require_failed{$class};
Branch: 1 branch
BranchTrueFalseTotal
if $require_failed{$class} 0 39 39
269 39 eval "require $class";
270 39 ▶ if($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 39 39
271 0 { error __x"failed for folder default {class}: {errors}", class => $class, errors => $@;
272 0 $require_failed{$class}++;
273 0 return ();
274 }
275  
276 39 push @defaults, manager => $self;
277 39 $folder = $class->new(@defaults, %args);
278 38 ▶ unless(defined $folder)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $folder) 0 38 38
279 0 ▶ { $args{access} eq 'd'
Branch: 1 branch
BranchTrueFalseTotal
$args{"access"} eq "d" or &error(&__x("folder {name} does not exist, failed opening {type}.", "type", $folder_type, "name", $name)) 0 0 0
280 or error __x"folder {name} does not exist, failed opening {type}.", type => $folder_type, name => $name;
281 0 return;
282 }
283  
284 38 trace "Opened folder $name ($folder_type).";
285 38 push @{$self->{MBM_folders}}, $folder;
286 38 $folder;
287 }
288  
289  
290 99 ▶sub openFolders() { @{ $_[0]->{MBM_folders}} }
Subroutine openFolders: called CC=1 SCAR=0.0
Pod documented
291  
292  
293 sub isOpenFolder($)
294 46 ▶{ my ($self, $name) = @_;
Subroutine isOpenFolder: called CC=1 SCAR=0.0
Pod documented
295 46 ▶ first { $name eq $_->name } $self->openFolders;
Subroutine __ANON__: called CC=1 SCAR=0.0
296 }
297  
298  
299 sub close($@)
300 37 ▶{ my ($self, $folder, %options) = @_;
Subroutine close: called CC=5 SCAR=16.1
Pod documented
301 37 ▶ return unless $folder;
Branch: 1 branch
BranchTrueFalseTotal
unless $folder 0 37 37
302  
303 37 my $name = $folder->name;
304 37 my @folders = $self->openFolders;
305 37 my @remaining = grep $name ne $_->name, @folders;
306  
307 # folder opening failed:
308 37 ▶ return if @folders == @remaining;
Branch: 1 branch
BranchTrueFalseTotal
if @folders == @remaining 1 36 37
309  
310 36 $self->{MBM_folders} = [ @remaining ];
311 36 $_->removeFolder($folder) for $self->threads;
312  
313 $options{close_by_self}
314 36 ▶ or $folder->close(close_by_manager => 1, %options);
Branch: 1 branch
BranchTrueFalseTotal
$options{"close_by_self"} or $folder->close("close_by_manager", 1, %options) 33 3 36
315  
316 36 $self;
317 }
318  
319  
320 sub closeAllFolders(@)
321 5 ▶{ my ($self, @options) = @_;
Subroutine closeAllFolders: called CC=2 SCAR=6.9
Pod documented
322 5 $_->close(@options) for $self->openFolders;
323 5 $self;
324 }
325  
326 14 ▶END { map defined $_ && $_->closeAllFolders, @managers }
Subroutine END: called CC=2 SCAR=7.2
Condition66%2/3
defined $_ && $_->closeAllFolders
!ll&&!rl&&r
805
MC/DC50%1/2
defined $_ && $_->closeAllFolders
defined $_ $_->closeAllFolders
Truth table66%2/3
A && B
A= defined $_B= $_->closeAllFolders
ABresult
0X0
100
111
327  
328 #--------------------
329  
330 sub delete($@)
331 0 ▶{ my ($self, $name, %args) = @_;
Subroutine delete: not called CC=2 SCAR=17.9
Pod documented
332 0 my $recurse = delete $args{recursive};
333  
334 0 ▶ my $folder = $self->open(folder => $name, access => 'd', %args)
Branch: 1 branch
BranchTrueFalseTotal
my $folder = $self->open("folder", $name, "access", "d", %args) or return $self 0 0 0
335 or return $self; # still successful
336  
337 0 $folder->delete(recursive => $recurse);
338 }
339  
340 #--------------------
341  
342 sub appendMessage(@)
343 6 ▶{ my $self = shift;
Subroutine appendMessage: called CC=2 SCAR=6.9
Pod documented
344 6 my @appended = $self->appendMessages(@_);
345 6 ▶ wantarray ? @appended : $appended[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 4 6
346 }
347  
348 sub appendMessages(@)
349 6 ▶{ my $self = shift;
Subroutine appendMessages: called CC=23 SCAR=39.6
Pod undocumented
350 6 my $folder;
351 6 ▶ $folder = shift if ! blessed $_[0] || $_[0]->isa('Mail::Box');
Branch: 1 branch
BranchTrueFalseTotal
if not builtin::blessed($_[0]) or $_[0]->isa("Mail::Box") 6 0 6
Condition33%1/3
not builtin::blessed($_[0]) or $_[0]->isa("Mail::Box")
l!l&&r!l&&!r
600
MC/DC0%0/2
not builtin::blessed($_[0]) or $_[0]->isa("Mail::Box")
not builtin::blessed($_[0]) $_[0]->isa("Mail::Box")
Truth table33%1/3
not(A) or B
A= not builtin::blessed($_[0])B= $_[0]->isa("Mail::Box")
ABresult
1X1
011
000
352  
353 6 my @messages;
354 6 ▶ push @messages, shift while @_ && blessed $_[0];
Branch: 1 branch
BranchTrueFalseTotal
@_ and builtin::blessed($_[0]) and do { push @messages, shift() } 6 6 12
Condition100%3/3
@_ and builtin::blessed($_[0])
!ll&&!rl&&r
336
MC/DC100%2/2
@_ and builtin::blessed($_[0])
@_ builtin::blessed($_[0])
Truth table100%3/3
A and B
A= @_B= builtin::blessed($_[0])
ABresult
0X0
100
111
355  
356 6 my %options = @_;
357 6 ▶ $folder ||= $options{folder};
Condition33%1/3
$folder ||= $options{"folder"}
l!l&&r!l&&!r
600
MC/DC0%0/2
$folder ||= $options{"folder"}
$folder $options{"folder"}
Truth table33%1/3
A ||= B
A= $folderB= $options{"folder"}
ABresult
1X1
011
000
358  
359 # Try to resolve filenames into opened-files.
360 6 ▶ $folder = $self->isOpenFolder($folder) || $folder
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($folder) 6 0 6
Condition66%2/3
$self->isOpenFolder($folder) || $folder
l!l&&r!l&&!r
330
MC/DC0%0/2
$self->isOpenFolder($folder) || $folder
$self->isOpenFolder($folder) $folder
Truth table66%2/3
A || B
A= $self->isOpenFolder($folder)B= $folder
ABresult
1X1
011
000
361 unless blessed $folder;
362  
363 6 ▶ if(blessed $folder)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($folder)) 3 3 6
364 { # An open file.
365 3 ▶ $folder->isa('Mail::Box')
Branch: 1 branch
BranchTrueFalseTotal
$folder->isa("Mail::Box") or &error(&__x("folder {name} is not a Mail::Box; cannot add a message.", "name", $folder)) 3 0 3
366 or error __x"folder {name} is not a Mail::Box; cannot add a message.", name => $folder;
367  
368 3 foreach my $msg (@messages)
369 3 ▶ { $msg->isa('Mail::Box::Message') && $msg->folder or next;
Branch: 1 branch
BranchTrueFalseTotal
$msg->isa("Mail::Box::Message") and $msg->folder or next 0 3 3
Condition33%1/3
$msg->isa("Mail::Box::Message") and $msg->folder
!ll&&!rl&&r
300
MC/DC0%0/2
$msg->isa("Mail::Box::Message") and $msg->folder
$msg->isa("Mail::Box::Message") $msg->folder
Truth table33%1/3
A and B
A= $msg->isa("Mail::Box::Message")B= $msg->folder
ABresult
0X0
100
111
370 0 warning __x"use moveMessage() or copyMessage() to move between open folders.";
371 }
372  
373 3 return $folder->addMessages(@messages);
374 }
375  
376 # Not an open file.
377 # Try to autodetect the folder-type and then add the message.
378  
379 3 my ($name, $class, @gen_options, $found);
380 3 my @typedefs = $self->folderTypeDefs;
381  
382 3 foreach (@typedefs)
383 6 { ($name, $class, @gen_options) = @$_;
384 6 ▶ next if $require_failed{$class};
Branch: 1 branch
BranchTrueFalseTotal
if $require_failed{$class} 0 6 6
385 6 eval "require $class";
386 6 ▶ if($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 6 6
387 0 { $require_failed{$class}++;
388 0 next;
389 }
390  
391 6 ▶ if($class->foundIn($folder, @gen_options, access => 'a'))
Branch: 1 branch
BranchTrueFalseTotal
if ($class->foundIn($folder, @gen_options, "access", "a")) 3 3 6
392 3 { $found++;
393 3 last;
394 }
395 }
396  
397 # The folder was not found at all, so we take the default folder-type.
398 3 my $type = $self->{MBM_default_type};
399 3 ▶ if(!$found && $type)
Branch: 1 branch
BranchTrueFalseTotal
if (not $found and $type) 0 3 3
Condition33%1/3
not $found and $type
!ll&&!rl&&r
300
MC/DC0%0/2
not $found and $type
not $found $type
Truth table33%1/3
not(A) and B
A= not $foundB= $type
ABresult
0X0
100
111
400 0 { foreach (@typedefs)
401 0 { ($name, $class, @gen_options) = @$_;
402 0 ▶ if($type eq $name || $type eq $class)
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq $name or $type eq $class) 0 0 0
Condition0%0/3
$type eq $name or $type eq $class
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq $name or $type eq $class
$type eq $name $type eq $class
Truth table0%0/3
A or B
A= $type eq $nameB= $type eq $class
ABresult
1X1
011
000
403 0 { $found++;
404 0 last;
405 }
406 }
407 }
408  
409 # Even the default foldertype was not found (or nor defined).
410 0 ▶ ($name, $class, @gen_options) = @{$typedefs[0]}
Branch: 1 branch
BranchTrueFalseTotal
unless $found 0 3 3
411 unless $found;
412  
413 3 $class->appendMessages(
414 type => $name,
415 messages => \@messages,
416 @gen_options,
417 %options,
418 folder => $folder,
419 );
420 }
421  
422  
423  
424 sub copyMessage(@)
425 42 ▶{ my $self = shift;
Subroutine copyMessage: called CC=16 SCAR=34.1
Pod documented
426 42 my $folder;
427 42 ▶ $folder = shift if ! blessed $_[0] || $_[0]->isa('Mail::Box');
Branch: 1 branch
BranchTrueFalseTotal
if not builtin::blessed($_[0]) or $_[0]->isa("Mail::Box") 42 0 42
Condition33%1/3
not builtin::blessed($_[0]) or $_[0]->isa("Mail::Box")
l!l&&r!l&&!r
0420
MC/DC0%0/2
not builtin::blessed($_[0]) or $_[0]->isa("Mail::Box")
not builtin::blessed($_[0]) $_[0]->isa("Mail::Box")
Truth table33%1/3
not(A) or B
A= not builtin::blessed($_[0])B= $_[0]->isa("Mail::Box")
ABresult
1X1
011
000
428  
429 42 my @messages;
430 42 ▶ while(@_ && blessed $_[0])
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and builtin::blessed($_[0])) 42 42 84
Condition100%3/3
@_ and builtin::blessed($_[0])
!ll&&!rl&&r
41142
MC/DC100%2/2
@_ and builtin::blessed($_[0])
@_ builtin::blessed($_[0])
Truth table100%3/3
A and B
A= @_B= builtin::blessed($_[0])
ABresult
0X0
100
111
431 42 { my $message = shift;
432 42 ▶ $message->isa('Mail::Box::Message')
Branch: 1 branch
BranchTrueFalseTotal
$message->isa("Mail::Box::Message") or &error(&__x("use appendMessage() to add messages which are not in a folder.")) 42 0 42
433 or error __x"use appendMessage() to add messages which are not in a folder.";
434 42 push @messages, $message;
435 }
436  
437 42 my %args = @_;
438  
439 42 ▶ $folder ||= $args{folder};
Condition33%1/3
$folder ||= $args{"folder"}
l!l&&r!l&&!r
4200
MC/DC0%0/2
$folder ||= $args{"folder"}
$folder $args{"folder"}
Truth table33%1/3
A ||= B
A= $folderB= $args{"folder"}
ABresult
1X1
011
000
440 42 ▶ my $share = exists $args{share} ? $args{share} : $args{_delete};
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'share'} ? : 0 42 42
441  
442 # Try to resolve filenames into opened-files.
443 42 ▶ $folder = $self->isOpenFolder($folder) || $folder
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($folder) 0 42 42
Condition0%0/3
$self->isOpenFolder($folder) || $folder
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->isOpenFolder($folder) || $folder
$self->isOpenFolder($folder) $folder
Truth table0%0/3
A || B
A= $self->isOpenFolder($folder)B= $folder
ABresult
1X1
011
000
444 unless blessed $folder;
445  
446 42 ▶ unless(blessed $folder)
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($folder)) 0 42 42
447 0 { my @c = $self->appendMessages(@messages, %args, folder => $folder);
448 0 ▶ if($args{_delete})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"_delete"}) 0 0 0
449 0 { $_->label(deleted => 1) for @messages;
450 }
451 0 return @c;
452 }
453  
454 42 my @coerced;
455 42 foreach my $msg (@messages)
456 42 ▶ { if($msg->folder eq $folder) # ignore move to same folder
Branch: 1 branch
BranchTrueFalseTotal
if ($msg->folder eq $folder) 0 42 42
457 0 { push @coerced, $msg;
458 0 next;
459 }
460 42 push @coerced, $msg->copyTo($folder, share => $args{share});
461 42 ▶ $msg->label(deleted => 1) if $args{_delete};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"_delete"} 1 41 42
462 }
463 42 @coerced;
464 }
465  
466  
467  
468 sub moveMessage(@)
469 1 ▶{ my $self = shift;
Subroutine moveMessage: called CC=1 SCAR=0.0
Pod documented
470 1 $self->copyMessage(@_, _delete => 1);
471 }
472  
473 #--------------------
474  
475 sub discoverThreads(@)
476 3 ▶{ my $self = shift;
Subroutine discoverThreads: called CC=13 SCAR=27.7
Pod documented
477 3 my @folders;
478 3 ▶ push @folders, shift while @_ && ref $_[0] && $_[0]->isa('Mail::Box');
Branch: 1 branch
BranchTrueFalseTotal
@_ and ref $_[0] and $_[0]->isa("Mail::Box") and do { push @folders, shift() } 1 3 4
Condition83%5/6
@_ and ref $_[0] and $_[0]->isa("Mail::Box")
!ll&&!rl&&r
301
@_ and ref $_[0]
!ll&&!rl&&r
121
MC/DC66%2/3
@_ and ref $_[0] and $_[0]->isa("Mail::Box")
@_ ref $_[0] $_[0]->isa("Mail::Box")
Truth table75%3/4
A and B and C
A= @_B= ref $_[0]C= $_[0]->isa("Mail::Box")
ABCresult
0XX0
10X0
1100
1111
479 3 my %args = @_;
480  
481 3 my $base = 'Mail::Box::Thread::Manager';
482 3 ▶ my $type = $args{threader_type} || $base;
Condition33%1/3
$args{'threader_type'} || $base
l!l&&r!l&&!r
030
MC/DC0%0/2
$args{'threader_type'} || $base
$args{'threader_type'} $base
Truth table33%1/3
A || B
A= $args{'threader_type'}B= $base
ABresult
1X1
011
000
483  
484 3 ▶ my $folders = delete $args{folder} || delete $args{folders};
Condition66%2/3
delete $args{'folder'} || delete $args{'folders'}
l!l&&r!l&&!r
201
MC/DC50%1/2
delete $args{'folder'} || delete $args{'folders'}
delete $args{'folder'} delete $args{'folders'}
Truth table66%2/3
A || B
A= delete $args{'folder'}B= delete $args{'folders'}
ABresult
1X1
011
000
485 3 ▶ push @folders, ( !$folders ? () : ref $folders eq 'ARRAY' ? @$folders : $folders );
Branch: 2 branches
BranchTrueFalseTotal
!$folders ? : 1 2 3
ref $folders eq 'ARRAY' ? : 0 2 2
486  
487 3 my $threads;
488 3 ▶ if(blessed $type) # Already prepared object?
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($type)) { } 0 3 3
489 0 ▶ { $type->isa($base)
Branch: 1 branch
BranchTrueFalseTotal
$type->isa($base) or &error(&__x("you need to pass a {base} derived threader, got {class}.", "base", $base, "class", ref $type)) 0 0 0
490 or error __x"you need to pass a {base} derived threader, got {class}.", base => $base, class => ref $type;
491 0 $threads = $type;
492 }
493 else
494 { # Create an object. The code is compiled, which safes us the
495 # need to compile Mail::Box::Thread::Manager when no threads are needed.
496 3 eval "require $type";
497 3 ▶ $@ and error __x"unusable threader {class}: {errors}", class => $type, errors => $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and &error(&__x("unusable threader {class}: {errors}", "class", $type, "errors", $@)) 0 3 3
498  
499 3 ▶ $type->isa($base)
Branch: 1 branch
BranchTrueFalseTotal
$type->isa($base) or &error(&__x("threader {class} is not derived from {base}.", "class", $type, "base", $base)) 3 0 3
500 or error __x"threader {class} is not derived from {base}.", class => $type, base => $base;
501  
502 3 $threads = $type->new(manager => $self, %args);
503 }
504  
505 3 $threads->includeFolder($_) for @folders;
506 3 push @{$self->{MBM_threads}}, $threads;
507 3 $threads;
508 }
509  
510 #--------------------
511  
512 sub toBeThreaded($@)
513 578 ▶{ my $self = shift;
Subroutine toBeThreaded: called CC=2 SCAR=6.9
Pod documented
514 578 $_->toBeThreaded(@_) for $self->threads;
515 }
516  
517  
518 sub toBeUnthreaded($@)
519 0 ▶{ my $self = shift;
Subroutine toBeUnthreaded: not called CC=2 SCAR=17.9
Pod documented
520 0 $_->toBeUnthreaded(@_) for $self->threads;
521 }
522  
523  
524 sub decodeFolderURL($)
525 16 ▶{ my ($self, $name) = @_;
Subroutine decodeFolderURL: called CC=8 SCAR=21.1
Pod documented
526  
527 return unless
528 16 ▶ my ($type, $username, $password, $hostname, $port, $path)
Branch: 1 branch
BranchTrueFalseTotal
unless () = $name =~ m[^ (\w+) \: # protocol (?: \/\/ (?: ([^:\@/]* ) # username (?: \: ([^\@/]*) )? # password \@ )? ([\w.-]+)? # hostname (?: \: (\d+) )? # port number )? (.*) # foldername ]x 1 15 16
529 = $name =~ m!^
530 (\w+) \: # protocol
531 (?: \/\/
532 (?: ([^:@/]* ) # username
533 (?: \: ([^@/]*) )? # password
534 \@
535 )?
536 ([\w.-]+)? # hostname
537 (?: \: (\d+) )? # port number
538 )?
539 (.*) # foldername
540 !x;
541  
542 15 ▶ $username ||= $ENV{USER} || $ENV{LOGNAME};
Condition50%3/6
$username ||= $ENV{"USER"} || $ENV{"LOGNAME"}
l!l&&r!l&&!r
870
$ENV{'USER'} || $ENV{'LOGNAME'}
l!l&&r!l&&!r
700
MC/DC0%0/3
$username ||= $ENV{"USER"} || $ENV{"LOGNAME"}
$username $ENV{'USER'} $ENV{'LOGNAME'}
Truth table0%0/4
A ||= B || C
A= $usernameB= $ENV{'USER'}C= $ENV{'LOGNAME'}
ABCresult
1XX1
01X1
0011
0000
543 15 ▶ $password ||= '';
Condition100%2/2
$password ||= ""
l!l
510
MC/DC100%1/1
$password ||= ""
$password
Truth table100%2/2
A
A= $password
Aresult
11
00
544  
545 15 for($username, $password)
546 30 { s/\+/ /g;
547 0 s/\%([A-Fa-f0-9]{2})/chr hex $1/ge;
548 }
549  
550 15 ▶ $hostname ||= 'localhost';
Condition100%2/2
$hostname ||= "localhost"
l!l
78
MC/DC100%1/1
$hostname ||= "localhost"
$hostname
Truth table100%2/2
A
A= $hostname
Aresult
11
00
551 15 ▶ $path ||= '=';
Condition100%2/2
$path ||= "="
l!l
123
MC/DC100%1/1
$path ||= "="
$path
Truth table100%2/2
A
A= $path
Aresult
11
00
552  
553 15 ( type => $type, folder => $path,
554 username => $username, password => $password,
555 server_name => $hostname, server_port => $port
556 );
557 }
558  
559 #--------------------
560  
561 14 1;
↑ Summary Box/Net.pm »