Box.pm

filter: Statementstmt 84.5% 312 / 369 Branchbran 64.2% 144 / 224 Conditioncond 53.7% 64 / 119 MC/DCmcdc 25.3% 17 / 67 Subroutinesub 75.2% 64 / 85 Podpod 87.5% 49 / 56 totaltotal 70.6% 650 / 920 CC 166 SCAR 25.5
CC
166
Cov
73%
messageId
38.2
init
33.1
scanForMessages
26.2
CRAP 12.8
« Box/Net/Message.pm ↑ Summary Box/Maildir/Message.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;{
13 34 our $VERSION = '4.02';
14 }
15  
16 34 ▶use parent 'Mail::Reporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 34 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 34 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 34 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 34 ▶use Log::Report 'mail-box', import => [ qw/__x error info mistake panic trace warning/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 34 ▶use Mail::Box::Message ();
Subroutine BEGIN: called CC=1 SCAR=0.0
25 34 ▶use Mail::Box::Locker ();
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 34 ▶use Scalar::Util qw/weaken/;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 34 ▶use List::Util qw/sum first/;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 34 ▶use Devel::GlobalDestruction 'in_global_destruction';
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 #--------------------
32  
33 #--------------------
34  
35 use overload
36 0 ▶ '@{}' => sub { $_[0]->{MB_messages} },
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine __ANON__: not called CC=1 SCAR=6.9
37 '""' => 'name',
38 34 ▶ 'cmp' => sub { $_[0]->name cmp "${_[1]}" };
Subroutine __ANON__: called CC=1 SCAR=0.0
39  
40 #--------------------
41  
42 sub new(@)
43 84 ▶{ my ($class, %args) = @_;
Subroutine new: called CC=4 SCAR=15.2
Pod documented
44  
45 84 ▶ if($class eq __PACKAGE__)
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq __PACKAGE__) 0 84 84
46 0 { my $package = __PACKAGE__;
47  
48 0 print STDERR <<USAGE;
49 You should not instantiate $package directly, but rather one of the
50 sub-classes, such as Mail::Box::Mbox. If you need automatic folder
51 type detection then use Mail::Box::Manager.
52 USAGE
53 0 exit 1;
54 }
55  
56 84 weaken $args{manager}; # otherwise, the manager object may live too long
57 84 my $self = $class->SUPER::new(%args, init_options => \%args);
58  
59 $self->read or return
60 83 ▶ if $self->{MB_access} =~ /r|a/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MB_access"} =~ /r|a/ 63 20 83
Condition60%3/5
$self->{'MB_access'} =~ /r|a/ && ($self->read || (return))
!ll&&!rl&&r
20630
$self->read or return
l!l
630
MC/DC0%0/2
$self->{'MB_access'} =~ /r|a/ && ($self->read || (return))
$self->{'MB_access'} =~ /r|a/ $self->read
Truth table33%1/3
A && B
A= $self->{'MB_access'} =~ /r|a/B= $self->read
ABresult
0X0
100
111
61  
62 83 $self;
63 }
64  
65 sub init($)
66 84 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=26 SCAR=35.0
Pod undocumented
67 84 $self->SUPER::init($args);
68  
69 84 my $class = ref $self;
70 my $foldername = $args->{folder} || $ENV{MAIL}
71 84 ▶ or error __x"no folder name specified.";
Branch: 1 branch
BranchTrueFalseTotal
my $foldername = $args->{"folder"} || $ENV{"MAIL"} or &error(&__x("no folder name specified.")) 84 0 84
Condition33%1/3
$args->{'folder'} || $ENV{'MAIL'}
l!l&&r!l&&!r
8400
MC/DC0%0/2
$args->{'folder'} || $ENV{'MAIL'}
$args->{'folder'} $ENV{'MAIL'}
Truth table33%1/3
A || B
A= $args->{'folder'}B= $ENV{'MAIL'}
ABresult
1X1
011
000
72  
73 84 $self->{MB_foldername} = $foldername;
74 84 $self->{MB_init_options} = $args->{init_options};
75 84 ▶ $self->{MB_coerce_opts} = $args->{coerce_options} || [];
Condition50%1/2
$args->{'coerce_options'} || []
l!l
084
MC/DC0%0/1
$args->{'coerce_options'} || []
$args->{'coerce_options'}
Truth table50%1/2
A
A= $args->{'coerce_options'}
Aresult
11
00
76 84 ▶ $self->{MB_access} = $args->{access} || 'r';
Condition100%2/2
$args->{'access'} || 'r'
l!l
7311
MC/DC100%1/1
$args->{'access'} || 'r'
$args->{'access'}
Truth table100%2/2
A
A= $args->{'access'}
Aresult
11
00
77 84 ▶ $self->{MB_remove_empty} = exists $args->{remove_when_empty} ? $args->{remove_when_empty} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'remove_when_empty'} ? : 0 84 84
78 84 ▶ $self->{MB_save_on_exit} = exists $args->{save_on_exit} ? $args->{save_on_exit} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'save_on_exit'} ? : 8 76 84
79 84 $self->{MB_messages} = [];
80 84 $self->{MB_msgid} = {};
81 84 ▶ $self->{MB_organization} = $args->{organization} || 'FILE';
Condition50%1/2
$args->{'organization'} || 'FILE'
l!l
084
MC/DC0%0/1
$args->{'organization'} || 'FILE'
$args->{'organization'}
Truth table50%1/2
A
A= $args->{'organization'}
Aresult
11
00
82 84 $self->{MB_linesep} = "\n";
83 84 $self->{MB_keep_dups} = $args->{keep_dups};
84 84 $self->{MB_fix_headers} = $args->{fix_headers};
85  
86 84 my $folderdir = $self->folderdir($args->{folderdir});
87 $self->{MB_trusted} = exists $args->{trusted} ? $args->{trusted}
88 84 ▶ : substr($foldername, 0, 1) eq '=' ? 1
Branch: 3 branches
BranchTrueFalseTotal
exists $args->{'trusted'} ? : 0 84 84
substr($foldername, 0, 1) eq '=' ? : 34 50 84
!defined($folderdir) ? : 0 50 50
89 : !defined $folderdir ? 0
90 : substr($foldername, 0, length $folderdir) eq $folderdir;
91  
92 84 ▶ if(exists $args->{manager})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"manager"}) 39 45 84
93 39 { $self->{MB_manager} = $args->{manager};
94 39 weaken($self->{MB_manager});
95 }
96  
97 84 ▶ $self->{MB_message_type} = $args->{message_type} || $class . '::Message';
Condition50%1/2
$args->{'message_type'} || $class . '::Message'
l!l
084
MC/DC0%0/1
$args->{'message_type'} || $class . '::Message'
$args->{'message_type'}
Truth table50%1/2
A
A= $args->{'message_type'}
Aresult
11
00
98 84 ▶ $self->{MB_head_type} = $args->{head_type} || 'Mail::Message::Head::Complete';
Condition50%1/2
$args->{'head_type'} || 'Mail::Message::Head::Complete'
l!l
084
MC/DC0%0/1
$args->{'head_type'} || 'Mail::Message::Head::Complete'
$args->{'head_type'}
Truth table50%1/2
A
A= $args->{'head_type'}
Aresult
11
00
99 84 ▶ $self->{MB_body_type} = $args->{body_type} || 'Mail::Message::Body::Lines';
Condition50%1/2
$args->{'body_type'} || 'Mail::Message::Body::Lines'
l!l
840
MC/DC0%0/1
$args->{'body_type'} || 'Mail::Message::Body::Lines'
$args->{'body_type'}
Truth table50%1/2
A
A= $args->{'body_type'}
Aresult
11
00
100 84 ▶ $self->{MB_body_delayed_type} = $args->{body_delayed_type} || 'Mail::Message::Body::Delayed';
Condition50%1/2
$args->{'body_delayed_type'} || 'Mail::Message::Body::Delayed'
l!l
084
MC/DC0%0/1
$args->{'body_delayed_type'} || 'Mail::Message::Body::Delayed'
$args->{'body_delayed_type'}
Truth table50%1/2
A
A= $args->{'body_delayed_type'}
Aresult
11
00
101 84 ▶ $self->{MB_head_delayed_type} = $args->{head_delayed_type} || 'Mail::Message::Head::Delayed';
Condition50%1/2
$args->{'head_delayed_type'} || 'Mail::Message::Head::Delayed'
l!l
084
MC/DC0%0/1
$args->{'head_delayed_type'} || 'Mail::Message::Head::Delayed'
$args->{'head_delayed_type'}
Truth table50%1/2
A
A= $args->{'head_delayed_type'}
Aresult
11
00
102 84 ▶ $self->{MB_multipart_type} = $args->{multipart_type} || 'Mail::Message::Body::Multipart';
Condition50%1/2
$args->{'multipart_type'} || 'Mail::Message::Body::Multipart'
l!l
084
MC/DC0%0/1
$args->{'multipart_type'} || 'Mail::Message::Body::Multipart'
$args->{'multipart_type'}
Truth table50%1/2
A
A= $args->{'multipart_type'}
Aresult
11
00
103 84 $self->{MB_field_type} = $args->{field_type};
104  
105 84 ▶ my $extract = $args->{extract} || 'extractDefault';
Condition100%2/2
$args->{'extract'} || 'extractDefault'
l!l
3648
MC/DC100%1/1
$args->{'extract'} || 'extractDefault'
$args->{'extract'}
Truth table100%2/2
A
A= $args->{'extract'}
Aresult
11
00
106 $self->{MB_extract}
107 = ref $extract eq 'CODE' ? $extract
108 486 ▶ : $extract eq 'ALWAYS' ? sub { 1 }
Subroutine __ANON__: called CC=1 SCAR=0.0
109 600 ▶ : $extract eq 'LAZY' ? sub { 0 }
Subroutine __ANON__: called CC=1 SCAR=0.0
110 0 ▶ : $extract eq 'NEVER' ? sub { 1 } # compatibility
Subroutine __ANON__: not called CC=1 SCAR=6.9
111 34 ▶ : $extract =~ m/\D/ ? sub { no strict 'refs'; shift->$extract(@_) }
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
112 84 ▶ : sub { my $size = $_[1]->guessBodySize; defined $size && $size < $extract };
Subroutine __ANON__: called CC=2 SCAR=7.1
Branch: 6 branches
BranchTrueFalseTotal
ref $extract eq 'CODE' ? : 0 84 84
$extract eq 'ALWAYS' ? : 11 73 84
$extract eq 'LAZY' ? : 23 50 73
$extract eq 'NEVER' ? : 0 50 50
$extract =~ /\D/ ? : 48 2 50
defined $size and $size < $extract 18 0 18
113  
114 #
115 # Create a locker.
116 #
117  
118 $self->{MB_locker} = $args->{locker} || Mail::Box::Locker->new(
119 folder => $self,
120 method => $args->{lock_type},
121 timeout => $args->{lock_timeout},
122 expires => $args->{lock_wait},
123 84 ▶ file => ($args->{lockfile} || $args->{lock_file}),
Condition50%3/6
$args->{'locker'} || 'Mail::Box::Locker'->new('folder', $self, 'method', $args->{'lock_type'}, 'timeout', $args->{'lock_timeout'}, 'expires', $args->{'lock_wait'}, 'file', $args->{'lockfile'} || $args->{'lock_file'})
l!l&&r!l&&!r
0840
$args->{'lockfile'} || $args->{'lock_file'}
l!l&&r!l&&!r
04935
MC/DC0%0/2
$args->{'locker'} || 'Mail::Box::Locker'->new('folder', $self, 'method', $args->{'lock_type'}, 'timeout', $args->{'lock_timeout'}, 'expires', $args->{'lock_wait'}, 'file', $args->{'lockfile'} || $args->{'lock_file'})
$args->{'locker'} 'Mail::Box::Locker'->new('folder', $self, 'method', $args->{'lock_type'}, 'timeout', $args->{'lock_timeout'}, 'expires', $args->{'lock_wait'}, 'file', $args->{'lockfile'} || $args->{'lock_file'})
MC/DC50%1/2
$args->{'lockfile'} || $args->{'lock_file'}
$args->{'lockfile'} $args->{'lock_file'}
Truth table33%1/3
A || B
A= $args->{'locker'}B= 'Mail::Box::Locker'->new('folder', $self, 'method', $args->{'lock_type'}, 'timeout', $args->{'lock_timeout'}, 'expires', $args->{'lock_wait'}, 'file', $args->{'lockfile'} || $args->{'lock_file'})
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $args->{'lockfile'}B= $args->{'lock_file'}
ABresult
1X1
011
000
124 );
125  
126 84 $self;
127 }
128  
129 #--------------------
130  
131 14 ▶sub removeEmpty() { $_[0]->{MB_remove_empty} }
Subroutine removeEmpty: called CC=1 SCAR=0.0
Pod documented
132  
133  
134 196 ▶sub folderdir(;$) { my $self = shift; @_ ? $self->{MB_folderdir} = shift : $self->{MB_folderdir} }
Subroutine folderdir: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 84 112 196
135  
136  
137 0 ▶sub type() { $_[0]->notImplemented }
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
138  
139  
140 2504 ▶sub name() { $_[0]->{MB_foldername} }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
141  
142  
143 103 ▶sub isTrusted() { $_[0]->{MB_trusted} }
Subroutine isTrusted: called CC=1 SCAR=0.0
Pod documented
144 776 ▶sub fixHeaders() { $_[0]->{MB_fix_headers} }
Subroutine fixHeaders: called CC=1 SCAR=0.0
Pod documented
145  
146 #--------------------
147  
148 0 ▶sub foundIn($@) { $_[0]->notImplemented }
Subroutine foundIn: not called CC=1 SCAR=6.9
Pod documented
149  
150  
151 sub url()
152 0 ▶{ my $self = shift;
Subroutine url: not called CC=1 SCAR=6.9
Pod documented
153 0 $self->type . ':' . $self->name;
154 }
155  
156  
157 0 ▶sub size() { sum 0, map $_->size, $_[0]->messages('ACTIVE') }
Subroutine size: not called CC=1 SCAR=6.9
Pod documented
158  
159  
160 sub update(@)
161 1 ▶{ my $self = shift;
Subroutine update: called CC=1 SCAR=0.0
Pod documented
162  
163 $self->updateMessages(
164 trusted => $self->isTrusted,
165 head_type => $self->{MB_head_type},
166 field_type => $self->{MB_field_type},
167 message_type => $self->{MB_message_type},
168 body_delayed_type => $self->{MB_body_delayed_type},
169 head_delayed_type => $self->{MB_head_delayed_type},
170 1 @_,
171 );
172  
173 1 $self;
174 }
175  
176  
177 0 ▶sub organization() { $_[0]->notImplemented }
Subroutine organization: not called CC=1 SCAR=6.9
Pod documented
178  
179  
180 sub addMessage($@)
181 142 ▶{ my $self = shift;
Subroutine addMessage: called CC=7 SCAR=20.1
Pod documented
182 142 ▶ my $message = shift or return $self;
Branch: 1 branch
BranchTrueFalseTotal
my $message = shift() or return $self 142 0 142
183 142 my %args = @_;
184  
185 142 ▶ $message->can('folder') && defined $message->folder
Branch: 1 branch
BranchTrueFalseTotal
$message->can("folder") and defined $message->folder and &error(&__x("you cannot add a message which is already part of a folder to a new one. Please use moveTo or copyTo.")) 0 142 142
Condition33%1/3
$message->can("folder") and defined $message->folder
!ll&&!rl&&r
14200
MC/DC0%0/2
$message->can("folder") and defined $message->folder
$message->can("folder") defined $message->folder
Truth table33%1/3
A and B
A= $message->can("folder")B= defined $message->folder
ABresult
0X0
100
111
186 and error __x"you cannot add a message which is already part of a folder to a new one. Please use moveTo or copyTo.";
187  
188 # Force the message into the right folder-type.
189 142 my $coerced = $self->coerce($message);
190 142 $coerced->folder($self);
191  
192 142 ▶ unless($coerced->head->isDelayed)
Branch: 1 branch
BranchTrueFalseTotal
unless ($coerced->head->isDelayed) 142 0 142
193 { # Do not add the same message twice, unless keep_dups.
194 142 my $msgid = $coerced->messageId;
195  
196 142 ▶ unless($self->{MB_keep_dups})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"MB_keep_dups"}) 142 0 142
197 142 ▶ { if(my $found = $self->messageId($msgid))
Branch: 1 branch
BranchTrueFalseTotal
if (my $found = $self->messageId($msgid)) 5 137 142
198 5 { $coerced->label(deleted => 1);
199 5 return $found;
200 }
201 }
202  
203 137 $self->messageId($msgid, $coerced);
204 137 $self->toBeThreaded($coerced);
205 }
206  
207 137 $self->storeMessage($coerced);
208 137 $coerced;
209 }
210  
211  
212 sub addMessages(@)
213 7 ▶{ my $self = shift;
Subroutine addMessages: called CC=1 SCAR=0.0
Pod documented
214 7 map $self->addMessage($_), @_;
215 }
216  
217  
218 sub copyTo($@)
219 4 ▶{ my ($self, $to, %args) = @_;
Subroutine copyTo: called CC=9 SCAR=24.0
Pod documented
220  
221 4 ▶ my $select = $args{select} || 'ACTIVE';
Condition50%1/2
$args{'select'} || 'ACTIVE'
l!l
40
MC/DC0%0/1
$args{'select'} || 'ACTIVE'
$args{'select'}
Truth table50%1/2
A
A= $args{'select'}
Aresult
11
00
222 4 ▶ my $subfolders = exists $args{subfolders} ? $args{subfolders} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'subfolders'} ? : 4 0 4
223 4 my $can_recurse = not $self->isa('Mail::Box::POP3');
224  
225 4 ▶ my ($flatten, $recurse)
Branch: 4 branches
BranchTrueFalseTotal
$subfolders eq 'FLATTEN' ? : 1 3 4
$subfolders eq 'RECURSE' ? : 1 2 3
!$subfolders ? : 2 0 2
$can_recurse ? : 0 0 0
226 = $subfolders eq 'FLATTEN' ? (1, 0)
227 : $subfolders eq 'RECURSE' ? (0, 1)
228 : !$subfolders ? (0, 0)
229 : $can_recurse ? (0, 1)
230 : (1, 0);
231  
232 4 ▶ my $delete = $args{delete_copied} || 0;
Condition50%1/2
$args{'delete_copied'} || 0
l!l
04
MC/DC0%0/1
$args{'delete_copied'} || 0
$args{'delete_copied'}
Truth table50%1/2
A
A= $args{'delete_copied'}
Aresult
11
00
233 4 ▶ my $share = $args{share} || 0;
Condition50%1/2
$args{'share'} || 0
l!l
04
MC/DC0%0/1
$args{'share'} || 0
$args{'share'}
Truth table50%1/2
A
A= $args{'share'}
Aresult
11
00
234  
235 4 $self->_copy_to($to, $select, $flatten, $recurse, $delete, $share);
236 }
237  
238 # Interface may change without warning.
239 sub _copy_to($@)
240 10 ▶{ my ($self, $to, @options) = @_;
Subroutine _copy_to: called CC=11 SCAR=25.6
241 10 my ($select, $flatten, $recurse, $delete, $share) = @options;
242  
243 10 ▶ $to->writable
Branch: 1 branch
BranchTrueFalseTotal
$to->writable or &error(&__x("destination folder {name} is not writable.", "name", $to)) 10 0 10
244 or error __x"destination folder {name} is not writable.", name => $to;
245  
246 # Take messages from this folder.
247 10 my @select = $self->messages($select);
248 10 trace "Copying ".@select." messages from $self to $to.";
249  
250 10 foreach my $msg (@select)
251 87 ▶ { $msg->copyTo($to, share => $share)
Branch: 1 branch
BranchTrueFalseTotal
$msg->copyTo($to, "share", $share) or &error(&__x("copying failed for one message.")) 87 0 87
252 or error __x"copying failed for one message.";
253  
254 87 ▶ $msg->label(deleted => 1) if $delete;
Branch: 1 branch
BranchTrueFalseTotal
if $delete 0 87 87
255 }
256  
257 10 ▶ $flatten || $recurse
Branch: 1 branch
BranchTrueFalseTotal
$flatten or $recurse or return $self 8 2 10
Condition100%3/3
$flatten or $recurse
l!l&&r!l&&!r
442
MC/DC100%2/2
$flatten or $recurse
$flatten $recurse
Truth table100%3/3
A or B
A= $flattenB= $recurse
ABresult
1X1
011
000
258 or return $self;
259  
260 # Take subfolders
261  
262 SUBFOLDER:
263 8 foreach my $subf ($self->listSubFolders(check => 1))
264 6 { my $subfolder = $self->openSubFolder($subf, access => 'r');
265  
266 6 ▶ if($flatten) # flatten
Branch: 1 branch
BranchTrueFalseTotal
if ($flatten) { } 3 3 6
267 3 ▶ { unless($subfolder->_copy_to($to, @options))
Branch: 1 branch
BranchTrueFalseTotal
unless ($subfolder->_copy_to($to, @options)) 0 3 3
268 0 { $subfolder->close;
269 0 return;
270 }
271 }
272 else # recurse
273 3 { my $subto = $to->openSubFolder($subf, create => 1, access => 'rw');
274 3 ▶ unless($subfolder->_copy_to($subto, @options))
Branch: 1 branch
BranchTrueFalseTotal
unless ($subfolder->_copy_to($subto, @options)) 0 3 3
275 0 { $subfolder->close;
276 0 $subto->close;
277 0 return;
278 }
279  
280 3 $subto->close;
281 }
282  
283 6 $subfolder->close;
284 }
285  
286 8 $self;
287 }
288  
289  
290 sub close(@)
291 90 ▶{ my ($self, %args) = @_;
Subroutine close: called CC=16 SCAR=30.0
Pod documented
292 90 ▶ my $force = $args{force} || 0;
Condition50%1/2
$args{'force'} || 0
l!l
090
MC/DC0%0/1
$args{'force'} || 0
$args{'force'}
Truth table50%1/2
A
A= $args{'force'}
Aresult
11
00
293  
294 90 ▶ return 1 if $self->{MB_is_closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MB_is_closed"} 2 88 90
295 88 $self->{MB_is_closed}++;
296  
297 # Inform manager that the folder is closed.
298 88 my $manager = delete $self->{MB_manager};
299 $manager->close($self, close_by_self =>1)
300 88 ▶ if defined $manager && !$args{close_by_manager};
Branch: 1 branch
BranchTrueFalseTotal
if defined $manager and not $args{"close_by_manager"} 34 54 88
Condition100%3/3
defined $manager and not $args{"close_by_manager"}
!ll&&!rl&&r
51334
MC/DC100%2/2
defined $manager and not $args{"close_by_manager"}
defined $manager not $args{"close_by_manager"}
Truth table100%3/3
A and not(B)
A= defined $managerB= not $args{"close_by_manager"}
ABresult
0X0
100
111
301  
302 88 ▶ my $when = $args{write} // 'MODIFIED';
Condition100%2/2
$args{"write"} // "MODIFIED"
l!l
3058
MC/DC100%1/1
$args{"write"} // "MODIFIED"
$args{"write"}
Truth table100%2/2
A
A= $args{"write"}
Aresult
11
00
303 88 ▶ my $write
Branch: 3 branches
BranchTrueFalseTotal
$when eq 'MODIFIED' ? : 58 30 88
$when eq 'ALWAYS' ? : 1 29 30
$when eq 'NEVER' ? : 29 0 29
304 = $when eq 'MODIFIED' ? $self->isModified
305 : $when eq 'ALWAYS' ? 1
306 : $when eq 'NEVER' ? 0
307 : error __x"unknown value to folder->close(write => {when}).", when => $when;
308  
309 88 my $locker = $self->locker;
310 88 ▶ if($write && !$force && !$self->writable)
Branch: 1 branch
BranchTrueFalseTotal
if ($write and not $force and not $self->writable) 0 88 88
Condition66%4/6
$write and not $force and not $self->writable
!ll&&!rl&&r
68200
$write and not $force
!ll&&!rl&&r
68020
MC/DC0%0/3
$write and not $force and not $self->writable
$write not $force not $self->writable
Truth table50%2/4
A and not(B) and not(C)
A= $writeB= not $forceC= not $self->writable
ABCresult
0XX0
10X0
1100
1111
311 0 { warning __x"changes not written to read-only folder {name}; suggestion: \$folder->close(write => 'NEVER')", name => $self->name;
312 0 ▶ $locker->unlock if $locker;
Branch: 1 branch
BranchTrueFalseTotal
if $locker 0 0 0
313 0 $self->{MB_messages} = []; # Boom!
314 0 return 0;
315 }
316  
317 my $rc = ! $write ||
318 88 ▶ $self->write(force => $force, save_deleted => $args{save_deleted} || 0);
Condition60%3/5
!$write || $self->write('force', $force, 'save_deleted', $args{'save_deleted'} || 0)
l!l&&r!l&&!r
68200
$args{'save_deleted'} || 0
l!l
020
MC/DC0%0/2
!$write || $self->write('force', $force, 'save_deleted', $args{'save_deleted'} || 0)
!$write $self->write('force', $force, 'save_deleted', $args{'save_deleted'} || 0)
MC/DC0%0/1
$args{'save_deleted'} || 0
$args{'save_deleted'}
Truth table66%2/3
not(A) || B
A= !$writeB= $self->write('force', $force, 'save_deleted', $args{'save_deleted'} || 0)
ABresult
1X1
011
000
Truth table50%1/2
A
A= $args{'save_deleted'}
Aresult
11
00
319  
320 88 ▶ $locker->unlock if $locker;
Branch: 1 branch
BranchTrueFalseTotal
if $locker 83 5 88
321 88 $self->{MB_messages} = []; # Boom!
322 88 $rc;
323 }
324  
325  
326 sub delete(@)
327 21 ▶{ my ($self, %args) = @_;
Subroutine delete: called CC=6 SCAR=20.2
Pod documented
328 21 ▶ my $recurse = exists $args{recursive} ? $args{recursive} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'recursive'} ? : 0 21 21
329  
330 # Extra protection: do not remove read-only folders.
331 21 ▶ unless($self->writable)
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->writable) 0 21 21
332 0 { warning __x"folder {name} not deleted: not writable.", name => $self->name;
333 0 $self->close(write => 'NEVER');
334 0 return;
335 }
336  
337 # Sub-directories need to be removed first.
338 21 ▶ if($recurse)
Branch: 1 branch
BranchTrueFalseTotal
if ($recurse) 21 0 21
339 21 { foreach ($self->listSubFolders)
340 14 { my $sub = $self->openRelatedFolder (folder => "$self/$_", access => 'd', create => 0);
341 14 ▶ defined $sub && $sub->delete(%args);
Branch: 1 branch
BranchTrueFalseTotal
defined $sub and $sub->delete(%args) 14 0 14
342 }
343 }
344  
345 21 $self->close(write => 'NEVER');
346 21 $self;
347 }
348  
349  
350 0 ▶sub appendMessages(@) { $_[0]->notImplemented }
Subroutine appendMessages: not called CC=1 SCAR=6.9
Pod documented
351  
352 #--------------------
353  
354 165 ▶sub writable() { $_[0]->access =~ /w|a|d/ }
Subroutine writable: called CC=1 SCAR=0.0
Pod documented
355 0 ▶sub writeable() { $_[0]->writable } # compatibility [typo]
Subroutine writeable: not called CC=1 SCAR=6.9
Pod undocumented
356 sub readable() { 1 } # compatibility
357  
358  
359 252 ▶sub access(;$) { my $self = shift; @_ ? $self->{MB_access} = shift : $self->{MB_access} }
Subroutine access: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 252 252
360  
361  
362 sub modified(;$)
363 42 ▶{ my $self = shift;
Subroutine modified: called CC=4 SCAR=13.9
Pod documented
364 42 ▶ @_ or return $self->isModified; # compat 2.036
Branch: 1 branch
BranchTrueFalseTotal
@_ or return $self->isModified 38 4 42
365  
366 return
367 38 ▶ if $self->{MB_modified} = shift; # force modified flag
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MB_modified"} = shift() 8 30 38
368  
369 # Unmodify all messages as well
370 30 $_->modified(0) for $self->messages;
371 30 0;
372 }
373  
374  
375 sub isModified()
376 83 ▶{ my $self = shift;
Subroutine isModified: called CC=5 SCAR=16.1
Pod documented
377 83 ▶ return 1 if $self->{MB_modified};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MB_modified"} 22 61 83
378  
379 61 foreach my $msg (@{$self->{MB_messages}})
380 1485 ▶ { return $self->{MB_modified} = 1
Branch: 1 branch
BranchTrueFalseTotal
if $msg->isDeleted or $msg->isModified 19 1466 1485
Condition100%3/3
$msg->isDeleted or $msg->isModified
l!l&&r!l&&!r
5141466
MC/DC100%2/2
$msg->isDeleted or $msg->isModified
$msg->isDeleted $msg->isModified
Truth table100%3/3
A or B
A= $msg->isDeletedB= $msg->isModified
ABresult
1X1
011
000
381 if $msg->isDeleted || $msg->isModified;
382 }
383 42 ▶$self->{MB_modified} = first { $_->isModified } @{$self->{MB_messages}};
Subroutine __ANON__: called CC=1 SCAR=0.0
384  
385 42 0;
386 }
387  
388 #--------------------
389  
390 sub message(;$$)
391 541 ▶{ my ($self, $index) = (shift, shift);
Subroutine message: called CC=2 SCAR=7.2
Pod documented
392 541 ▶ @_ ? $self->{MB_messages}[$index] = shift : $self->{MB_messages}[$index];
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 541 541
393 }
394  
395  
396 sub messageId($;$)
397 2024 ▶{ my ($self, $msgid) = (shift, shift);
Subroutine messageId: called CC=13 SCAR=36.4
Pod documented
398  
399 2024 ▶ if($msgid =~ m/\<([^>]+)\>/s )
Branch: 1 branch
BranchTrueFalseTotal
if ($msgid =~ /\<([^>]+)\>/s) 2 2022 2024
400 2 { $msgid = $1 =~ s/\s//grs;
401  
402 2 ▶ index($msgid, '@') >= 0
Branch: 1 branch
BranchTrueFalseTotal
index($msgid, "\@") != -1 or &warning(&__x("message-id '{msgid}' does not contain a domain.", "msgid", $msgid)) 2 0 2
403 or warning __x"message-id '{msgid}' does not contain a domain.", msgid => $msgid;
404 }
405  
406 2024 ▶ @_ or return $self->{MB_msgid}{$msgid};
Branch: 1 branch
BranchTrueFalseTotal
@_ or return $self->{"MB_msgid"}{$msgid} 1737 287 2024
407  
408 1737 my $message = shift;
409  
410 # Undefine message?
411 1737 ▶ unless($message)
Branch: 1 branch
BranchTrueFalseTotal
unless ($message) 55 1682 1737
412 55 { delete $self->{MB_msgid}{$msgid};
413 55 return;
414 }
415  
416 1682 my $double = $self->{MB_msgid}{$msgid};
417 1682 ▶ if(defined $double && !$self->{MB_keep_dups})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $double and not $self->{"MB_keep_dups"}) 0 1682 1682
Condition33%1/3
defined $double and not $self->{"MB_keep_dups"}
!ll&&!rl&&r
168200
MC/DC0%0/2
defined $double and not $self->{"MB_keep_dups"}
defined $double not $self->{"MB_keep_dups"}
Truth table33%1/3
A and not(B)
A= defined $doubleB= not $self->{"MB_keep_dups"}
ABresult
0X0
100
111
418 0 { my $head1 = $message->head;
419 0 my $head2 = $double->head;
420  
421 0 ▶ my $subj1 = $head1->get('subject') || '';
Condition0%0/2
$head1->get('subject') || ''
l!l
00
MC/DC0%0/1
$head1->get('subject') || ''
$head1->get('subject')
Truth table0%0/2
A
A= $head1->get('subject')
Aresult
11
00
422 0 ▶ my $subj2 = $head2->get('subject') || '';
Condition0%0/2
$head2->get('subject') || ''
l!l
00
MC/DC0%0/1
$head2->get('subject') || ''
$head2->get('subject')
Truth table0%0/2
A
A= $head2->get('subject')
Aresult
11
00
423  
424 0 ▶ my $to1 = $head1->get('to') || '';
Condition0%0/2
$head1->get('to') || ''
l!l
00
MC/DC0%0/1
$head1->get('to') || ''
$head1->get('to')
Truth table0%0/2
A
A= $head1->get('to')
Aresult
11
00
425 0 ▶ my $to2 = $head2->get('to') || '';
Condition0%0/2
$head2->get('to') || ''
l!l
00
MC/DC0%0/1
$head2->get('to') || ''
$head2->get('to')
Truth table0%0/2
A
A= $head2->get('to')
Aresult
11
00
426  
427 # Auto-delete doubles.
428 0 ▶ return $message->label(deleted => 1)
Branch: 1 branch
BranchTrueFalseTotal
if $subj1 eq $subj2 and $to1 eq $to2 0 0 0
Condition0%0/3
$subj1 eq $subj2 and $to1 eq $to2
!ll&&!rl&&r
000
MC/DC0%0/2
$subj1 eq $subj2 and $to1 eq $to2
$subj1 eq $subj2 $to1 eq $to2
Truth table0%0/3
A and B
A= $subj1 eq $subj2B= $to1 eq $to2
ABresult
0X0
100
111
429 if $subj1 eq $subj2 && $to1 eq $to2;
430  
431 0 warning __x"different messages with id {msgid}.", msgid => $msgid;
432 0 $msgid = $message->takeMessageId(undef);
433 }
434  
435 1682 $self->{MB_msgid}{$msgid} = $message;
436 1682 weaken($self->{MB_msgid}{$msgid});
437 1682 $message;
438 }
439  
440 4 ▶sub messageID(@) { shift->messageId(@_) } # compatibility
Subroutine messageID: called CC=1 SCAR=0.0
Pod undocumented
441  
442  
443 sub find($)
444 1 ▶{ my ($self, $msgid) = (shift, shift);
Subroutine find: called CC=3 SCAR=12.3
Pod documented
445 1 my $msgids = $self->{MB_msgid};
446  
447 1 ▶ if($msgid =~ m/\<([^>]*)\>/s)
Branch: 1 branch
BranchTrueFalseTotal
if ($msgid =~ /\<([^>]*)\>/s) { } 0 1 1
448 0 { $msgid = $1 =~ s/\s//grs;
449 }
450 else
451 { # Illegal message-id
452 1 $msgid =~ s/\s/+/gs;
453 }
454  
455 1 ▶ $msgids->{$msgid} // $self->scanForMessages(undef, $msgid, 'EVER', 'ALL');
Condition33%1/3
$msgids->{$msgid} // $self->scanForMessages(undef, $msgid, "EVER", "ALL")
l!l&&r!l&&!r
010
MC/DC0%0/2
$msgids->{$msgid} // $self->scanForMessages(undef, $msgid, "EVER", "ALL")
$msgids->{$msgid} $self->scanForMessages(undef, $msgid, "EVER", "ALL")
Truth table33%1/3
A // B
A= $msgids->{$msgid}B= $self->scanForMessages(undef, $msgid, "EVER", "ALL")
ABresult
1X1
011
000
456 }
457  
458  
459 sub messages($;$)
460 478 ▶{ my $self = shift;
Subroutine messages: called CC=13 SCAR=27.5
Pod documented
461 478 my $msgs = $self->{MB_messages};
462  
463 478 ▶ @_ or return @$msgs;
Branch: 1 branch
BranchTrueFalseTotal
@_ or return @$msgs 14 464 478
464  
465 14 ▶ if(@_==2) # range
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) 2 12 14
466 2 { my ($begin, $end) = @_;
467 2 my $nr = @$msgs;
468 2 ▶ $begin += $nr if $begin < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $begin < 0 0 2 2
469 2 ▶ $begin = 0 if $begin < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $begin < 0 0 2 2
470 2 ▶ $end += $nr if $end < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $end < 0 0 2 2
471 2 ▶ $end = $nr-1 if $end >= $nr;
Branch: 1 branch
BranchTrueFalseTotal
if $end >= $nr 0 2 2
472 2 ▶ return $begin > $end ? () : @{$msgs}[$begin..$end];
Branch: 1 branch
BranchTrueFalseTotal
$begin > $end ? : 0 2 2
473 }
474  
475 12 my $what = shift;
476 my $action
477 = ref $what eq 'CODE'? $what
478 55 ▶ : $what eq 'DELETED' ? sub { $_[0]->isDeleted }
Subroutine __ANON__: called CC=1 SCAR=0.0
479 125 ▶ : $what eq 'ACTIVE' ? sub { not $_[0]->isDeleted }
Subroutine __ANON__: called CC=1 SCAR=0.0
480 10 ▶ : $what eq 'ALL' ? sub { 1 }
Subroutine __ANON__: called CC=1 SCAR=0.0
481 0 ▶ : $what =~ s/^\!// ? sub { not $_[0]->label($what) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
482 0 ▶ : sub { $_[0]->label($what) };
Subroutine __ANON__: not called CC=1 SCAR=0.7
Branch: 5 branches
BranchTrueFalseTotal
ref $what eq 'CODE' ? : 0 12 12
$what eq 'DELETED' ? : 2 10 12
$what eq 'ACTIVE' ? : 9 1 10
$what eq 'ALL' ? : 1 0 1
$what =~ s/^\!// ? : 0 0 0
483  
484 12 grep $action->($_), @$msgs;
485 }
486  
487  
488 2 ▶sub nrMessages(@) { scalar shift->messages(@_) }
Subroutine nrMessages: called CC=1 SCAR=0.0
Pod documented
489  
490  
491 0 ▶sub messageIds() { map $_->messageId, $_[0]->messages }
Subroutine messageIds: not called CC=1 SCAR=6.9
Pod documented
492 0 ▶sub allMessageIds() { $_[0]->messageIds } # compatibility
Subroutine allMessageIds: not called CC=1 SCAR=6.9
Pod undocumented
493 0 ▶sub allMessageIDs() { $_[0]->messageIds } # compatibility
Subroutine allMessageIDs: not called CC=1 SCAR=6.9
Pod undocumented
494  
495  
496 sub current(;$)
497 2 ▶{ my $self = shift;
Subroutine current: called CC=7 SCAR=20.9
Pod documented
498  
499 2 ▶ unless(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 1 1 2
500 { return $self->{MB_current}
501 1 ▶ if exists $self->{MB_current};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"MB_current"} 0 1 1
502  
503 # Which one becomes current?
504 1 ▶ my $current
Condition37%3/8
$self->findFirstLabeled('current', 1) || $self->findFirstLabeled('seen', 0) || $self->message(-1) || (return undef)
l!l
10
$self->findFirstLabeled("current", 1) or $self->findFirstLabeled("seen", 0) or $self->message(-1)
l!l&&r!l&&!r
100
$self->findFirstLabeled("current", 1) or $self->findFirstLabeled("seen", 0)
l!l&&r!l&&!r
100
MC/DC0%0/3
$self->findFirstLabeled('current', 1) || $self->findFirstLabeled('seen', 0) || $self->message(-1) || (return undef)
$self->findFirstLabeled("current", 1) $self->findFirstLabeled("seen", 0) $self->message(-1)
Truth table25%1/4
A or B or C
A= $self->findFirstLabeled("current", 1)B= $self->findFirstLabeled("seen", 0)C= $self->message(-1)
ABCresult
1XX1
01X1
0011
0000
505 = $self->findFirstLabeled(current => 1)
506 || $self->findFirstLabeled(seen => 0)
507 || $self->message(-1)
508 || return undef;
509  
510 1 $current->label(current => 1);
511 1 return $self->{MB_current} = $current;
512 }
513  
514 1 my $next = shift;
515 1 ▶ if(my $previous = $self->{MB_current})
Branch: 1 branch
BranchTrueFalseTotal
if (my $previous = $self->{"MB_current"}) 1 0 1
516 1 { $previous->label(current => 0);
517 }
518  
519 1 ($self->{MB_current} = $next)->label(current => 1);
520 1 $next;
521 }
522  
523  
524 sub scanForMessages($$$$)
525 2 ▶{ my ($self, $startid, $msgids, $moment, $window) = @_;
Subroutine scanForMessages: called CC=18 SCAR=32.6
Pod documented
526  
527 # Set-up msgid-list
528 2 ▶ my %search = map +($_ => 1), ref $msgids ? @$msgids : $msgids;
Branch: 1 branch
BranchTrueFalseTotal
ref $msgids ? : 0 2 2
529 2 ▶ keys %search or return ();
Branch: 1 branch
BranchTrueFalseTotal
keys %search or return () 2 0 2
530  
531 # do not run on empty folder
532 2 ▶ my $nr_messages = $self->messages
Branch: 1 branch
BranchTrueFalseTotal
my $nr_messages = $self->messages or return keys %search 2 0 2
533 or return keys %search;
534  
535 2 ▶ my $startmsg = defined $startid ? $self->messageId($startid) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $startid ? : 1 1 2
536  
537 # Set-up window-bound.
538 2 my $bound = 0;
539 2 ▶ if($window ne 'ALL' && defined $startmsg)
Branch: 1 branch
BranchTrueFalseTotal
if ($window ne "ALL" and defined $startmsg) 1 1 2
Condition66%2/3
$window ne "ALL" and defined $startmsg
!ll&&!rl&&r
101
MC/DC50%1/2
$window ne "ALL" and defined $startmsg
$window ne "ALL" defined $startmsg
Truth table66%2/3
A and B
A= $window ne "ALL"B= defined $startmsg
ABresult
0X0
100
111
540 1 { $bound = $startmsg->seqnr - $window;
541 1 ▶ $bound = 0 if $bound < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $bound < 0 0 1 1
542 }
543  
544 2 ▶ my $last = ($self->{MBM_last} || $nr_messages) -1;
Condition33%1/3
$self->{'MBM_last'} || $nr_messages
l!l&&r!l&&!r
020
MC/DC0%0/2
$self->{'MBM_last'} || $nr_messages
$self->{'MBM_last'} $nr_messages
Truth table33%1/3
A || B
A= $self->{'MBM_last'}B= $nr_messages
ABresult
1X1
011
000
545 2 ▶ return keys %search if defined $bound && $bound > $last;
Branch: 1 branch
BranchTrueFalseTotal
if defined $bound and $bound > $last 0 2 2
Condition33%1/3
defined $bound and $bound > $last
!ll&&!rl&&r
020
MC/DC0%0/2
defined $bound and $bound > $last
defined $bound $bound > $last
Truth table33%1/3
A and B
A= defined $boundB= $bound > $last
ABresult
0X0
100
111
546  
547 # Set-up time-bound
548 2 ▶ my $after
Branch: 3 branches
BranchTrueFalseTotal
$moment eq 'EVER' ? : 1 1 2
$moment =~ /^\d+$/ ? : 1 0 1
!$startmsg ? : 0 0 0
549 = $moment eq 'EVER' ? 0
550 : $moment =~ m/^\d+$/ ? $moment
551 : !$startmsg ? 0
552 : $startmsg->timestamp - $self->timespan2seconds($moment);
553  
554 2 ▶ while($last >= $bound)
Branch: 1 branch
BranchTrueFalseTotal
if ($last >= $bound) 82 1 83
555 82 { my $message = $self->message($last);
556 82 my $msgid = $message->messageId; # triggers load
557  
558 82 ▶ if(delete $search{$msgid}) # where we looking for this one?
Branch: 1 branch
BranchTrueFalseTotal
if (delete $search{$msgid}) 0 82 82
559 0 ▶ { keys %search or last;
Branch: 1 branch
BranchTrueFalseTotal
keys %search or last 0 0 0
560 }
561  
562 82 ▶ last if $message->timestamp < $after;
Branch: 1 branch
BranchTrueFalseTotal
if $message->timestamp < $after 1 81 82
563 81 $last--;
564 }
565  
566 2 $self->{MBM_last} = $last;
567 2 keys %search;
568 }
569  
570  
571 sub findFirstLabeled($;$$)
572 1 ▶{ my ($self, $label, $set, $msgs) = @_;
Subroutine findFirstLabeled: called CC=5 SCAR=21.9
Pod documented
573  
574 !defined $set || $set
575 5 ▶ ? (first { $_->label($label) } (defined $msgs ? @$msgs : $self->messages))
Subroutine __ANON__: called CC=1 SCAR=0.0
576 0 ▶ : (first { not $_->label($label) } (defined $msgs ? @$msgs : $self->messages));
Subroutine __ANON__: not called CC=1 SCAR=2.3
Branch: 3 branches
BranchTrueFalseTotal
!defined($set) || $set ? : 1 0 1
defined $msgs ? : 0 1 1
defined $msgs ? : 0 0 0
Condition33%1/3
not defined $set or $set
l!l&&r!l&&!r
010
MC/DC0%0/2
not defined $set or $set
not defined $set $set
Truth table33%1/3
not(A) or B
A= not defined $setB= $set
ABresult
1X1
011
000
577 }
578  
579 #--------------------
580  
581 0 ▶sub listSubFolders(@) { () } # by default no sub-folders
Subroutine listSubFolders: not called CC=1 SCAR=6.9
Pod documented
582  
583  
584 sub openRelatedFolder(@)
585 27 ▶{ my $self = shift;
Subroutine openRelatedFolder: called CC=2 SCAR=6.9
Pod documented
586 27 my @options = (%{$self->{MB_init_options}}, @_);
587  
588 $self->{MB_manager}
589 27 ▶ ? $self->{MB_manager}->open(type => ref($self), @options)
Branch: 1 branch
BranchTrueFalseTotal
$self->{'MB_manager'} ? : 19 8 27
590 : (ref $self)->new(@options);
591 }
592  
593  
594 sub openSubFolder($@)
595 13 ▶{ my $self = shift;
Subroutine openSubFolder: called CC=1 SCAR=0.0
Pod documented
596 13 my $name = $self->nameOfSubFolder(shift);
597 13 $self->openRelatedFolder(@_, folder => $name);
598 }
599  
600  
601 sub nameOfSubFolder($;$)
602 4 ▶{ my ($thing, $name) = (shift, shift);
Subroutine nameOfSubFolder: called CC=4 SCAR=15.2
Pod documented
603 4 ▶ my $parent = @_ ? shift : ref $thing ? $thing->name : undef;
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 4 4
ref $thing ? : 4 0 4
604 4 ▶ defined $parent ? "$parent/$name" : $name;
Branch: 1 branch
BranchTrueFalseTotal
defined $parent ? : 4 0 4
605 }
606  
607  
608 sub topFolderWithMessages() { 1 }
609  
610 #--------------------
611  
612 sub read(@)
613 63 ▶{ my $self = shift;
Subroutine read: called CC=3 SCAR=11.2
Pod documented
614 63 $self->{MB_open_time} = time;
615  
616 63 local $self->{MB_lazy_permitted} = 1;
617  
618 # Read from existing folder.
619 $self->readMessages(
620 trusted => $self->isTrusted,
621 head_type => $self->{MB_head_type},
622 field_type => $self->{MB_field_type},
623 message_type => $self->{MB_message_type},
624 body_delayed_type => $self->{MB_body_delayed_type},
625 head_delayed_type => $self->{MB_head_delayed_type},
626 @_
627 63 ▶ ) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->readMessages("trusted", $self->isTrusted, "head_type", $self->{"MB_head_type"}, "field_type", $self->{"MB_field_type"}, "message_type", $self->{"MB_message_type"}, "body_delayed_type", $self->{"MB_body_delayed_type"}, "head_delayed_type", $self->{"MB_head_delayed_type"}, @_) or return 63 0 63
628  
629 63 ▶ $self->{MB_modified} and panic "Modified $self->{MB_modified}";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"MB_modified"} and &panic(qq[Modified $self->{"MB_modified"}]) 0 63 63
630 63 $self;
631 }
632  
633  
634 sub write(@)
635 31 ▶{ my ($self, %args) = @_;
Subroutine write: called CC=8 SCAR=21.2
Pod documented
636  
637 31 ▶ $args{force} || $self->writable
Branch: 1 branch
BranchTrueFalseTotal
$args{"force"} or $self->writable or &error(&__x("folder {name} is opened read-only.", "name", $self->name)) 31 0 31
Condition33%1/3
$args{"force"} or $self->writable
l!l&&r!l&&!r
0310
MC/DC0%0/2
$args{"force"} or $self->writable
$args{"force"} $self->writable
Truth table33%1/3
A or B
A= $args{"force"}B= $self->writable
ABresult
1X1
011
000
638 or error __x"folder {name} is opened read-only.", name => $self->name;
639  
640 31 my (@keep, @destroy);
641 31 ▶ if($args{save_deleted})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'save_deleted'}) { } 0 31 31
642 0 { @keep = $self->messages;
643 }
644 else
645 31 { foreach my $msg ($self->messages)
646 964 ▶ { if($msg->isDeleted)
Branch: 1 branch
BranchTrueFalseTotal
if ($msg->isDeleted) { } 28 936 964
647 28 { push @destroy, $msg;
648 28 $msg->diskDelete;
649 }
650 936 else { push @keep, $msg }
651 }
652 }
653  
654 31 ▶ @destroy || $self->isModified
Branch: 1 branch
BranchTrueFalseTotal
@destroy or $self->isModified or &trace("Folder $self not changed, so not updated."), (return $self) 30 1 31
Condition100%3/3
@destroy or $self->isModified
l!l&&r!l&&!r
10201
MC/DC100%2/2
@destroy or $self->isModified
@destroy $self->isModified
Truth table100%3/3
A or B
A= @destroyB= $self->isModified
ABresult
1X1
011
000
655 or trace("Folder $self not changed, so not updated."), return $self;
656  
657 30 $args{messages} = \@keep;
658 30 $self->writeMessages(\%args);
659 30 $self->modified(0);
660 30 $self->{MB_messages} = \@keep;
661 30 $self;
662 }
663  
664  
665 sub determineBodyType($$)
666 1658 ▶{ my ($self, $message, $head) = @_;
Subroutine determineBodyType: called CC=5 SCAR=16.1
Pod documented
667  
668 return $self->{MB_body_delayed_type}
669 if $self->{MB_lazy_permitted}
670 && ! $message->isPart
671 1658 ▶ && ! $self->{MB_extract}->($self, $head);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MB_lazy_permitted"} and not $message->isPart and not $self->{"MB_extract"}->($self, $head) 614 1044 1658
Condition100%6/6
$self->{"MB_lazy_permitted"} and not $message->isPart and not $self->{"MB_extract"}->($self, $head)
!ll&&!rl&&r
114930614
$self->{"MB_lazy_permitted"} and not $message->isPart
!ll&&!rl&&r
30841544
MC/DC100%3/3
$self->{"MB_lazy_permitted"} and not $message->isPart and not $self->{"MB_extract"}->($self, $head)
$self->{"MB_lazy_permitted"} not $message->isPart not $self->{"MB_extract"}->($self, $head)
Truth table100%4/4
A and not(B) and not(C)
A= $self->{"MB_lazy_permitted"}B= not $message->isPartC= not $self->{"MB_extract"}->($self, $head)
ABCresult
0XX0
10X0
1100
1111
672  
673 1044 my $bodytype = $self->{MB_body_type};
674 1044 ▶ ref $bodytype ? $bodytype->($head) : $bodytype;
Branch: 1 branch
BranchTrueFalseTotal
ref $bodytype ? : 1044 0 1044
675 }
676  
677 sub extractDefault($)
678 440 ▶{ my ($self, $head) = @_;
Subroutine extractDefault: called CC=2 SCAR=7.1
Pod undocumented
679 440 my $size = $head->guessBodySize;
680 440 ▶ defined $size ? $size < 10000 : 0 # immediately extract < 10kb
Branch: 1 branch
BranchTrueFalseTotal
defined $size ? : 440 0 440
681 }
682  
683 sub lazyPermitted($)
684 562 ▶{ my $self = shift;
Subroutine lazyPermitted: called CC=1 SCAR=0.0
Pod undocumented
685 562 $self->{MB_lazy_permitted} = shift;
686 }
687  
688  
689 sub storeMessage($)
690 2138 ▶{ my ($self, $message) = @_;
Subroutine storeMessage: called CC=1 SCAR=0.0
Pod documented
691  
692 2138 push @{$self->{MB_messages}}, $message;
693 2138 $message->seqnr( @{$self->{MB_messages}} -1);
694 2138 $message;
695 }
696  
697  
698 34 my %seps = (CR => "\015", LF => "\012", CRLF => "\015\012");
699  
700 sub lineSeparator(;$)
701 0 ▶{ my $self = shift;
Subroutine lineSeparator: not called CC=4 SCAR=30.0
Pod documented
702 0 ▶ @_ or return $self->{MB_linesep};
Branch: 1 branch
BranchTrueFalseTotal
@_ or return $self->{"MB_linesep"} 0 0 0
703  
704 0 my $sep = shift;
705 0 ▶ $sep = $seps{$sep} if exists $seps{$sep};
Branch: 1 branch
BranchTrueFalseTotal
if exists $seps{$sep} 0 0 0
706  
707 0 $self->{MB_linesep} = $sep;
708 0 $_->lineSeparator($sep) for $self->messages;
709 0 $sep;
710 }
711  
712  
713 0 ▶sub create($@) { $_[0]->notImplemented }
Subroutine create: not called CC=1 SCAR=6.9
Pod documented
714  
715  
716  
717 sub coerce($@)
718 142 ▶{ my ($self, $message) = (shift, shift);
Subroutine coerce: called CC=2 SCAR=7.1
Pod documented
719 142 my $mmtype = $self->{MB_message_type};
720 142 ▶ $message->isa($mmtype) ? $message : $mmtype->coerce($message, @_);
Branch: 1 branch
BranchTrueFalseTotal
$message->isa($mmtype) ? : 0 142 142
721 }
722  
723  
724 0 ▶sub readMessages(@) { $_[0]->notImplemented }
Subroutine readMessages: not called CC=1 SCAR=6.9
Pod documented
725  
726  
727 0 ▶sub updateMessages(@) { $_[0] }
Subroutine updateMessages: not called CC=1 SCAR=6.9
Pod documented
728  
729  
730 0 ▶sub writeMessages(@) { $_[0]->notImplemented }
Subroutine writeMessages: not called CC=1 SCAR=6.9
Pod documented
731  
732  
733 200 ▶sub locker() { $_[0]->{MB_locker} }
Subroutine locker: called CC=1 SCAR=0.0
Pod documented
734  
735  
736 sub toBeThreaded(@)
737 1682 ▶{ my $self = shift;
Subroutine toBeThreaded: called CC=2 SCAR=6.9
Pod documented
738 1682 ▶ my $manager = $self->{MB_manager} or return $self;
Branch: 1 branch
BranchTrueFalseTotal
my $manager = $self->{"MB_manager"} or return $self 578 1104 1682
739 578 $manager->toBeThreaded($self, @_);
740 578 $self;
741 }
742  
743  
744 sub toBeUnthreaded(@)
745 55 ▶{ my $self = shift;
Subroutine toBeUnthreaded: called CC=2 SCAR=9.2
Pod documented
746 55 ▶ my $manager = $self->{MB_manager} or return $self;
Branch: 1 branch
BranchTrueFalseTotal
my $manager = $self->{"MB_manager"} or return $self 0 55 55
747 0 $manager->toBeThreaded($self, @_);
748 0 $self;
749 }
750  
751 #--------------------
752  
753 sub timespan2seconds($)
754 3 ▶{
Subroutine timespan2seconds: called CC=4 SCAR=15.8
Pod documented
755 3 ▶ $_[1] =~ /^\s*(\d+\.?\d*|\.\d+)\s*(hour|day|week)s?\s*$/
Branch: 1 branch
BranchTrueFalseTotal
$_[1] =~ /^\s*(\d+\.?\d*|\.\d+)\s*(hour|day|week)s?\s*$/ or &error(&__x("invalid timespan '{span}'.", "span", $_[1])), (return undef) 3 0 3
756 or error(__x"invalid timespan '{span}'.", span => $_[1]), return undef;
757  
758 3 ▶ $2 eq 'hour' ? $1 * 3600
Branch: 2 branches
BranchTrueFalseTotal
$2 eq 'hour' ? : 0 3 3
$2 eq 'day' ? : 3 0 3
759 : $2 eq 'day' ? $1 * 86400
760 : $1 * 604800; # week
761 }
762  
763 #--------------------
764  
765 sub DESTROY
766 88 ▶{ my $self = shift;
Subroutine DESTROY: called CC=3 SCAR=11.1
767 in_global_destruction || $self->{MB_is_closed}
768 88 ▶ or $self->close;
Branch: 1 branch
BranchTrueFalseTotal
&in_global_destruction() or $self->{"MB_is_closed"} or $self->close 69 19 88
Condition66%2/3
&in_global_destruction() or $self->{"MB_is_closed"}
l!l&&r!l&&!r
06919
MC/DC50%1/2
&in_global_destruction() or $self->{"MB_is_closed"}
&in_global_destruction() $self->{"MB_is_closed"}
Truth table66%2/3
A or B
A= &in_global_destruction()B= $self->{"MB_is_closed"}
ABresult
1X1
011
000
769 }
770  
771 #--------------------
772  
773 34 1;
« Box/Net/Message.pm ↑ Summary Box/Maildir/Message.pm »