Box/Maildir.pm

filter: Statementstmt 23.5% 48 / 204 Branchbran 3.3% 3 / 90 Conditioncond 8.1% 6 / 74 MC/DCmcdc 0.0% 0 / 47 Subroutinesub 52.0% 13 / 25 Podpod 92.8% 13 / 14 totaltotal 18.2% 83 / 454 CC 77 SCAR 44.9
CC
77
Cov
15%
listSubFolders
240.0
appendMessages
156.0
createDirs
90.0
CRAP 89.4
« Box/Search/Grep.pm ↑ Summary Box/MH/Labels.pm »
1 # Copyrights 2001-2020 by [Mark Overmeer].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.02.
5 # This code is part of distribution Mail-Box. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package Mail::Box::Maildir;
10 5 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 $VERSION = '3.009';
12  
13 5 ▶use base 'Mail::Box::Dir';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use filetest 'access';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 5 ▶use Mail::Box::Maildir::Message;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶use File::Copy 'move';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 ▶use File::Basename 'basename';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 5 ▶use Sys::Hostname 'hostname';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 5 ▶use File::Remove 'remove';
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 # Maildir is only supported on UNIX, because the filenames probably
28 # do not work on other platforms. Since MailBox 2.052, the use of
29 # File::Spec to create filenames has been removed: benchmarks showed
30 # that catfile() consumed 20% of the time of a folder open(). And
31 # '/' file separators work on Windows too!
32  
33  
34 5 ▶my $default_folder_dir = exists $ENV{HOME} ? "$ENV{HOME}/.maildir" : '.';
Branch: 1 branch
BranchTrueFalseTotal
exists $ENV{'HOME'} ? : 5 0 5
35  
36 sub init($)
37 4 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=7 SCAR=27.0
Pod undocumented
38  
39 croak "No locking possible for maildir folders."
40 if exists $args->{locker}
41 4 ▶ || (defined $args->{lock_type} && $args->{lock_type} ne 'NONE');
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"locker"} or defined $args->{"lock_type"} and $args->{"lock_type"} ne "NONE" 0 4 4
Condition33%2/6
exists $args->{"locker"} or defined $args->{"lock_type"} and $args->{"lock_type"} ne "NONE"
l!l&&r!l&&!r
004
defined $args->{"lock_type"} and $args->{"lock_type"} ne "NONE"
!ll&&!rl&&r
400
MC/DC0%0/3
exists $args->{"locker"} or defined $args->{"lock_type"} and $args->{"lock_type"} ne "NONE"
exists $args->{"locker"} defined $args->{"lock_type"} $args->{"lock_type"} ne "NONE"
Truth table0%0/4
A or B and C
A= exists $args->{"locker"}B= defined $args->{"lock_type"}C= $args->{"lock_type"} ne "NONE"
ABCresult
1XX1
0111
00X0
0100
42  
43 4 $args->{lock_type} = 'NONE';
44 4 ▶ $args->{folderdir} ||= $default_folder_dir;
Condition66%2/3
$args->{"folderdir"} ||= $default_folder_dir
l!l&&r!l&&!r
130
MC/DC0%0/2
$args->{"folderdir"} ||= $default_folder_dir
$args->{"folderdir"} $default_folder_dir
Truth table66%2/3
A ||= B
A= $args->{"folderdir"}B= $default_folder_dir
ABresult
1X1
011
000
45  
46 return undef
47 4 ▶ unless $self->SUPER::init($args);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->SUPER::init($args) 0 0 0
48  
49 0 ▶ $self->acceptMessages if $args->{accept_new};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"accept_new"} 0 0 0
50 0 $self;
51 }
52  
53  
54 sub create($@)
55 0 ▶{ my ($thingy, $name, %args) = @_;
Subroutine create: not called CC=4 SCAR=30.0
Pod documented
56 0 ▶ my $class = ref $thingy || $thingy;
Condition0%0/3
ref $thingy || $thingy
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $thingy || $thingy
ref $thingy $thingy
Truth table0%0/3
A || B
A= ref $thingyB= $thingy
ABresult
1X1
011
000
57 0 ▶ my $folderdir = $args{folderdir} || $default_folder_dir;
Condition0%0/3
$args{'folderdir'} || $default_folder_dir
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'folderdir'} || $default_folder_dir
$args{'folderdir'} $default_folder_dir
Truth table0%0/3
A || B
A= $args{'folderdir'}B= $default_folder_dir
ABresult
1X1
011
000
58 0 my $directory = $class->folderToDirectory($name, $folderdir);
59  
60 0 ▶ if($class->createDirs($directory))
Branch: 1 branch
BranchTrueFalseTotal
if ($class->createDirs($directory)) { } 0 0 0
61 0 { $class->log(PROGRESS => "Created folder Maildir $name.");
62 0 return $class;
63 }
64 else
65 0 { $class->log(ERROR => "Cannot create Maildir folder $name.");
66 0 return undef;
67 }
68 }
69  
70 sub foundIn($@)
71 3 ▶{ my $class = shift;
Subroutine foundIn: called CC=3 SCAR=11.2
Pod documented
72 3 ▶ my $name = @_ % 2 ? shift : undef;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 ? : 3 0 3
73 3 my %args = @_;
74 3 ▶ my $folderdir = $args{folderdir} || $default_folder_dir;
Condition66%2/3
$args{'folderdir'} || $default_folder_dir
l!l&&r!l&&!r
120
MC/DC0%0/2
$args{'folderdir'} || $default_folder_dir
$args{'folderdir'} $default_folder_dir
Truth table66%2/3
A || B
A= $args{'folderdir'}B= $default_folder_dir
ABresult
1X1
011
000
75 3 my $directory = $class->folderToDirectory($name, $folderdir);
76  
77 3 -d "$directory/cur";
78 }
79  
80 sub type() {'maildir'}
81  
82 sub listSubFolders(@)
83 0 ▶{ my ($class, %args) = @_;
Subroutine listSubFolders: not called CC=15 SCAR=54.8
Pod documented
84 0 my $dir;
85  
86 0 ▶ if(ref $class)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) { } 0 0 0
87 0 { $dir = $class->directory;
88 0 $class = ref $class;
89 }
90 else
91 0 ▶ { my $folder = $args{folder} || '=';
Condition0%0/2
$args{'folder'} || '='
l!l
00
MC/DC0%0/1
$args{'folder'} || '='
$args{'folder'}
Truth table0%0/2
A
A= $args{'folder'}
Aresult
11
00
92 0 ▶ my $folderdir = $args{folderdir} || $default_folder_dir;
Condition0%0/3
$args{'folderdir'} || $default_folder_dir
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'folderdir'} || $default_folder_dir
$args{'folderdir'} $default_folder_dir
Truth table0%0/3
A || B
A= $args{'folderdir'}B= $default_folder_dir
ABresult
1X1
011
000
93 0 $dir = $class->folderToDirectory($folder, $folderdir);
94 }
95  
96 0 ▶ $args{skip_empty} ||= 0;
Condition0%0/2
$args{"skip_empty"} ||= 0
l!l
00
MC/DC0%0/1
$args{"skip_empty"} ||= 0
$args{"skip_empty"}
Truth table0%0/2
A
A= $args{"skip_empty"}
Aresult
11
00
97 0 ▶ $args{check} ||= 0;
Condition0%0/2
$args{"check"} ||= 0
l!l
00
MC/DC0%0/1
$args{"check"} ||= 0
$args{"check"}
Truth table0%0/2
A
A= $args{"check"}
Aresult
11
00
98  
99 # Read the directories from the directory, to find all folders
100 # stored here. Some directories have to be removed because they
101 # are created by all kinds of programs, but are no folders.
102  
103 0 ▶ return () unless -d $dir && opendir DIR, $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir and opendir DIR, $dir 0 0 0
Condition0%0/3
-d $dir and opendir DIR, $dir
!ll&&!rl&&r
000
MC/DC0%0/2
-d $dir and opendir DIR, $dir
-d $dir opendir DIR, $dir
Truth table0%0/3
A and B
A= -d $dirB= opendir DIR, $dir
ABresult
0X0
100
111
104  
105 0 my @dirs;
106 0 ▶ while(my $d = readdir DIR)
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $d = readdir DIR)) 0 0 0
107 0 ▶ { next if $d =~ m/^(new|tmp|cur|\.\.?)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $d =~ /^(new|tmp|cur|\.\.?)$/ 0 0 0
108  
109 0 my $dir = "$dir/$d";
110 0 ▶ push @dirs, $d if -d $dir && -r _;
Branch: 1 branch
BranchTrueFalseTotal
if -d $dir and -r _ 0 0 0
Condition0%0/3
-d $dir and -r _
!ll&&!rl&&r
000
MC/DC0%0/2
-d $dir and -r _
-d $dir -r _
Truth table0%0/3
A and B
A= -d $dirB= -r _
ABresult
0X0
100
111
111 }
112  
113 0 closedir DIR;
114  
115 # Skip empty folders.
116  
117 0 @dirs = grep {!$class->folderIsEmpty("$dir/$_")} @dirs
118 0 ▶ if $args{skip_empty};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"skip_empty"} 0 0 0
119  
120 # Check if the files we want to return are really folders.
121  
122 0 ▶ @dirs = map { m/(.*)/ && $1 } @dirs; # untaint
Branch: 1 branch
BranchTrueFalseTotal
/(.*)/ and $1 0 0 0
123 0 ▶ return @dirs unless $args{check};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"check"} 0 0 0
124  
125 0 grep { $class->foundIn("$dir/$_") } @dirs;
126 }
127  
128 sub openSubFolder($@)
129 0 ▶{ my ($self, $name) = (shift, shift);
Subroutine openSubFolder: not called CC=1 SCAR=6.9
Pod documented
130 0 $self->createDirs($self->nameOfSubFolder($name));
131 0 $self->SUPER::openSubFolder($name, @_);
132 }
133  
134 sub topFolderWithMessages() { 1 }
135  
136 5 my $uniq = rand 1000;
137  
138  
139 sub coerce($)
140 0 ▶{ my ($self, $message) = (shift, shift);
Subroutine coerce: not called CC=6 SCAR=37.4
Pod documented
141  
142 0 my $is_native = $message->isa('Mail::Box::Maildir::Message');
143 0 my $coerced = $self->SUPER::coerce($message, @_);
144  
145 0 ▶ my $basename = $is_native ? basename($message->filename)
Branch: 1 branch
BranchTrueFalseTotal
$is_native ? : 0 0 0
Condition0%0/3
$message->timestamp || time
l!l&&r!l&&!r
000
MC/DC0%0/2
$message->timestamp || time
$message->timestamp time
Truth table0%0/3
A || B
A= $message->timestampB= time
ABresult
1X1
011
000
146 : ($message->timestamp || time) .'.'. hostname .'.'. $uniq++;
147  
148 0 my $dir = $self->directory;
149 0 my $tmp = "$dir/tmp/$basename";
150 0 my $new = "$dir/new/$basename";
151  
152 0 ▶ if($coerced->create($tmp) && $coerced->create($new))
Branch: 1 branch
BranchTrueFalseTotal
if ($coerced->create($tmp) and $coerced->create($new)) { } 0 0 0
Condition0%0/3
$coerced->create($tmp) and $coerced->create($new)
!ll&&!rl&&r
000
MC/DC0%0/2
$coerced->create($tmp) and $coerced->create($new)
$coerced->create($tmp) $coerced->create($new)
Truth table0%0/3
A and B
A= $coerced->create($tmp)B= $coerced->create($new)
ABresult
0X0
100
111
153 0 {$self->log(PROGRESS => "Added Maildir message in $new") }
154 0 else {$self->log(ERROR => "Cannot create Maildir message file $new.") }
155  
156 0 ▶ $coerced->labelsToFilename unless $is_native;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_native 0 0 0
157 0 $coerced;
158 }
159  
160 #-------------------------------------------
161  
162  
163 sub createDirs($)
164 0 ▶{ my ($thing, $dir) = @_;
Subroutine createDirs: not called CC=9 SCAR=45.0
Pod documented
165  
166 0 ▶ $thing->log(ERROR => "Cannot create Maildir folder directory $dir: $!"), return
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir or mkdir $dir 0 0 0
Condition0%0/3
-d $dir or mkdir $dir
l!l&&r!l&&!r
000
MC/DC0%0/2
-d $dir or mkdir $dir
-d $dir mkdir $dir
Truth table0%0/3
A or B
A= -d $dirB= mkdir $dir
ABresult
1X1
011
000
167 unless -d $dir || mkdir $dir;
168  
169 0 my $tmp = "$dir/tmp";
170 0 ▶ $thing->log(ERROR => "Cannot create Maildir folder subdir $tmp: $!"), return
Branch: 1 branch
BranchTrueFalseTotal
unless -d $tmp or mkdir $tmp 0 0 0
Condition0%0/3
-d $tmp or mkdir $tmp
l!l&&r!l&&!r
000
MC/DC0%0/2
-d $tmp or mkdir $tmp
-d $tmp mkdir $tmp
Truth table0%0/3
A or B
A= -d $tmpB= mkdir $tmp
ABresult
1X1
011
000
171 unless -d $tmp || mkdir $tmp;
172  
173 0 my $new = "$dir/new";
174 0 ▶ $thing->log(ERROR => "Cannot create Maildir folder subdir $new: $!"), return
Branch: 1 branch
BranchTrueFalseTotal
unless -d $new or mkdir $new 0 0 0
Condition0%0/3
-d $new or mkdir $new
l!l&&r!l&&!r
000
MC/DC0%0/2
-d $new or mkdir $new
-d $new mkdir $new
Truth table0%0/3
A or B
A= -d $newB= mkdir $new
ABresult
1X1
011
000
175 unless -d $new || mkdir $new;
176  
177 0 my $cur = "$dir/cur";
178 0 ▶ $thing->log(ERROR => "Cannot create Maildir folder subdir $cur: $!"), return
Branch: 1 branch
BranchTrueFalseTotal
unless -d $cur or mkdir $cur 0 0 0
Condition0%0/3
-d $cur or mkdir $cur
l!l&&r!l&&!r
000
MC/DC0%0/2
-d $cur or mkdir $cur
-d $cur mkdir $cur
Truth table0%0/3
A or B
A= -d $curB= mkdir $cur
ABresult
1X1
011
000
179 unless -d $cur || mkdir $cur;
180  
181 0 $thing;
182 }
183  
184  
185 sub folderIsEmpty($)
186 0 ▶{ my ($self, $dir) = @_;
Subroutine folderIsEmpty: not called CC=9 SCAR=45.0
Pod documented
187 0 ▶ return 1 unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 0 0
188  
189 0 foreach (qw/tmp new cur/)
190 0 { my $subdir = "$dir/$_";
191 0 ▶ next unless -d $subdir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $subdir 0 0 0
192  
193 0 ▶ opendir DIR, $subdir or return 0;
Branch: 1 branch
BranchTrueFalseTotal
opendir DIR, $subdir or return 0 0 0 0
194 0 my $first = readdir DIR;
195 0 closedir DIR;
196  
197 0 ▶ return 0 if defined $first;
Branch: 1 branch
BranchTrueFalseTotal
if defined $first 0 0 0
198 }
199  
200 0 ▶ opendir DIR, $dir or return 1;
Branch: 1 branch
BranchTrueFalseTotal
opendir DIR, $dir or return 1 0 0 0
201 0 ▶ while(my $entry = readdir DIR)
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entry = readdir DIR)) 0 0 0
202 0 ▶ { next if $entry =~
Branch: 1 branch
BranchTrueFalseTotal
if $entry =~ /^(?:tmp|cur|new|bulletin(?:time|lock)|seriallock|\..?)$/ 0 0 0
203 m/^(?:tmp|cur|new|bulletin(?:time|lock)|seriallock|\..?)$/;
204  
205 0 closedir DIR;
206 0 return 0;
207 }
208  
209 0 closedir DIR;
210 0 1;
211 }
212  
213 sub delete(@)
214 0 ▶{ my $self = shift;
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
215  
216 # Subfolders are not nested in the directory structure
217 0 remove \1, $self->directory;
218 }
219  
220 sub readMessageFilenames
221 0 ▶{ my ($self, $dirname) = @_;
Subroutine readMessageFilenames: not called CC=8 SCAR=42.8
Pod documented
222  
223 0 ▶ opendir DIR, $dirname or return ();
Branch: 1 branch
BranchTrueFalseTotal
opendir DIR, $dirname or return () 0 0 0
224  
225 0 my @files;
226 0 ▶ if(${^TAINT})
Branch: 1 branch
BranchTrueFalseTotal
if (${^TAINT}) { } 0 0 0
227 { # unsorted list of untainted filenames.
228 0 ▶ @files = map { m/^([0-9][\w.:,=\-]+)$/ && -f "$dirname/$1" ? $1 : () }
Branch: 1 branch
BranchTrueFalseTotal
/^([0-9][\w.:,=\-]+)$/ && -f "$dirname/$1" ? : 0 0 0
Condition0%0/3
/^([0-9][\w.:,=\-]+)$/ and -f "$dirname/$1"
!ll&&!rl&&r
000
MC/DC0%0/2
/^([0-9][\w.:,=\-]+)$/ and -f "$dirname/$1"
/^([0-9][\w.:,=\-]+)$/ -f "$dirname/$1"
Truth table0%0/3
A and B
A= /^([0-9][\w.:,=\-]+)$/B= -f "$dirname/$1"
ABresult
0X0
100
111
229 readdir DIR;
230 }
231 else
232 { # not running tainted
233 0 ▶ @files = grep /^([0-9][\w.:,=\-]+)$/ && -f "$dirname/$1", readdir DIR;
Condition0%0/3
/^([0-9][\w.:,=\-]+)$/ && -f "$dirname/$1"
!ll&&!rl&&r
000
MC/DC0%0/2
/^([0-9][\w.:,=\-]+)$/ && -f "$dirname/$1"
/^([0-9][\w.:,=\-]+)$/ -f "$dirname/$1"
Truth table0%0/3
A && B
A= /^([0-9][\w.:,=\-]+)$/B= -f "$dirname/$1"
ABresult
0X0
100
111
234 }
235 0 closedir DIR;
236  
237 # Sort the names. Solve the Y2K (actually the 1 billion seconds
238 # since 1970 bug) which hunts Maildir. The timestamp, which is
239 # the start of the filename will have some 0's in front, so each
240 # timestamp has the same length.
241  
242 0 my %unified;
243 m/^(\d+)/ and $unified{ ('0' x (10-length($1))).$_ } = $_
244 0 ▶ for @files;
Branch: 1 branch
BranchTrueFalseTotal
/^(\d+)/ and $unified{0 x (10 - length($1)) . $_} = $_ 0 0 0
245  
246 0 map "$dirname/$unified{$_}",
247 sort keys %unified;
248 }
249  
250 sub readMessages(@)
251 0 ▶{ my ($self, %args) = @_;
Subroutine readMessages: not called CC=4 SCAR=30.0
Pod documented
252  
253 0 my $directory = $self->directory;
254 0 ▶ return unless -d $directory;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $directory 0 0 0
255  
256 #
257 # Read all messages
258 #
259  
260 0 my $curdir = "$directory/cur";
261 0 my @cur = map +[$_, 1], $self->readMessageFilenames($curdir);
262  
263 0 my $newdir = "$directory/new";
264 0 my @new = map +[$_, 0], $self->readMessageFilenames($newdir);
265 0 my @log = $self->logSettings;
266  
267 0 foreach (@cur, @new)
268 0 { my ($filename, $accepted) = @$_;
269 my $message = $args{message_type}->new
270 ( head => $args{head_delayed_type}->new(@log)
271 , filename => $filename
272 , folder => $self
273 , fix_header=> $self->{MB_fix_headers}
274 0 , labels => [ accepted => $accepted ]
275 );
276  
277 0 my $body = $args{body_delayed_type}->new(@log, message => $message);
278 0 ▶ $message->storeBody($body) if $body;
Branch: 1 branch
BranchTrueFalseTotal
if $body 0 0 0
279 0 $self->storeMessage($message);
280 }
281  
282 0 $self;
283 }
284
285  
286 sub acceptMessages($)
287 0 ▶{ my ($self, %args) = @_;
Subroutine acceptMessages: not called CC=2 SCAR=17.9
Pod documented
288 0 my @accept = $self->messages('!accepted');
289 0 $_->accept foreach @accept;
290 0 @accept;
291 }
292  
293 sub writeMessages($)
294 0 ▶{ my ($self, $args) = @_;
Subroutine writeMessages: not called CC=9 SCAR=45.0
Pod documented
295  
296 # Write each message. Two things complicate life:
297 # 1 - we may have a huge folder, which should not be on disk twice
298 # 2 - we may have to replace a message, but it is unacceptable
299 # to remove the original before we are sure that the new version
300 # is on disk.
301  
302 0 my $writer = 0;
303  
304 0 my $directory = $self->directory;
305 0 my @messages = @{$args->{messages}};
306  
307 0 my $tmpdir = "$directory/tmp";
308 0 ▶ die "Cannot create directory $tmpdir: $!"
Branch: 1 branch
BranchTrueFalseTotal
unless -d $tmpdir or mkdir $tmpdir 0 0 0
Condition0%0/3
-d $tmpdir or mkdir $tmpdir
l!l&&r!l&&!r
000
MC/DC0%0/2
-d $tmpdir or mkdir $tmpdir
-d $tmpdir mkdir $tmpdir
Truth table0%0/3
A or B
A= -d $tmpdirB= mkdir $tmpdir
ABresult
1X1
011
000
309 unless -d $tmpdir || mkdir $tmpdir;
310  
311 0 foreach my $message (@messages)
312 0 ▶ { next unless $message->isModified;
Branch: 1 branch
BranchTrueFalseTotal
unless $message->isModified 0 0 0
313  
314 0 my $filename = $message->filename;
315 0 my $basename = basename $filename;
316  
317 0 my $newtmp = "$directory/tmp/$basename";
318 0 ▶ open my $new, '>', $newtmp
Branch: 1 branch
BranchTrueFalseTotal
open my $new, ">", $newtmp or croak("Cannot create file ${newtmp}: $!") 0 0 0
319 or croak "Cannot create file $newtmp: $!";
320  
321 0 $message->write($new);
322 0 close $new;
323  
324 0 unlink $filename;
325 0 ▶ move $newtmp, $filename
Branch: 1 branch
BranchTrueFalseTotal
move($newtmp, $filename) or warn "Cannot move $newtmp to ${filename}: $!\n" 0 0 0
326 or warn "Cannot move $newtmp to $filename: $!\n";
327 }
328  
329 # Remove an empty folder. This is done last, because the code before
330 # in this method will have cleared the contents of the directory.
331  
332 0 ▶ if(!@messages && $self->{MB_remove_empty})
Branch: 1 branch
BranchTrueFalseTotal
if (not @messages and $self->{"MB_remove_empty"}) 0 0 0
Condition0%0/3
not @messages and $self->{"MB_remove_empty"}
!ll&&!rl&&r
000
MC/DC0%0/2
not @messages and $self->{"MB_remove_empty"}
not @messages $self->{"MB_remove_empty"}
Truth table0%0/3
not(A) and B
A= not @messagesB= $self->{"MB_remove_empty"}
ABresult
0X0
100
111
333 { # If something is still in the directory, this will fail, but I
334 # don't mind.
335 0 rmdir "$directory/cur";
336 0 rmdir "$directory/tmp";
337 0 rmdir "$directory/new";
338 0 rmdir $directory;
339 }
340  
341 0 $self;
342 }
343  
344  
345 sub appendMessages(@)
346 0 ▶{ my $class = shift;
Subroutine appendMessages: not called CC=12 SCAR=50.5
Pod documented
347 0 my %args = @_;
348  
349 my @messages = exists $args{message} ? $args{message}
350 0 ▶ : exists $args{messages} ? @{$args{messages}}
Branch: 2 branches
BranchTrueFalseTotal
exists $args{'message'} ? : 0 0 0
exists $args{'messages'} ? : 0 0 0
351 : return ();
352  
353 0 my $self = $class->new(@_, access => 'a');
354 0 my $directory= $self->directory;
355 0 ▶ return unless -d $directory;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $directory 0 0 0
356  
357 0 my $tmpdir = "$directory/tmp";
358 0 ▶ croak "Cannot create directory $tmpdir: $!", return
Branch: 1 branch
BranchTrueFalseTotal
unless -d $tmpdir or mkdir $tmpdir 0 0 0
Condition0%0/3
-d $tmpdir or mkdir $tmpdir
l!l&&r!l&&!r
000
MC/DC0%0/2
-d $tmpdir or mkdir $tmpdir
-d $tmpdir mkdir $tmpdir
Truth table0%0/3
A or B
A= -d $tmpdirB= mkdir $tmpdir
ABresult
1X1
011
000
359 unless -d $tmpdir || mkdir $tmpdir;
360  
361 0 ▶ my $msgtype = $args{message_type} || 'Mail::Box::Maildir::Message';
Condition0%0/2
$args{'message_type'} || 'Mail::Box::Maildir::Message'
l!l
00
MC/DC0%0/1
$args{'message_type'} || 'Mail::Box::Maildir::Message'
$args{'message_type'}
Truth table0%0/2
A
A= $args{'message_type'}
Aresult
11
00
362  
363 0 foreach my $message (@messages)
364 0 { my $is_native = $message->isa($msgtype);
365 0 my ($basename, $coerced);
366  
367 0 ▶ if($is_native)
Branch: 1 branch
BranchTrueFalseTotal
if ($is_native) { } 0 0 0
368 0 { $coerced = $message;
369 0 $basename = basename $message->filename;
370 }
371 else
372 0 { $coerced = $self->SUPER::coerce($message);
373 0 ▶ $basename = ($message->timestamp||time).'.'. hostname.'.'.$uniq++;
Condition0%0/3
$message->timestamp || time
l!l&&r!l&&!r
000
MC/DC0%0/2
$message->timestamp || time
$message->timestamp time
Truth table0%0/3
A || B
A= $message->timestampB= time
ABresult
1X1
011
000
374 }
375  
376 0 my $dir = $self->directory;
377 0 my $tmp = "$dir/tmp/$basename";
378 0 my $new = "$dir/new/$basename";
379  
380 0 ▶ if($coerced->create($tmp) && $coerced->create($new))
Branch: 1 branch
BranchTrueFalseTotal
if ($coerced->create($tmp) and $coerced->create($new)) { } 0 0 0
Condition0%0/3
$coerced->create($tmp) and $coerced->create($new)
!ll&&!rl&&r
000
MC/DC0%0/2
$coerced->create($tmp) and $coerced->create($new)
$coerced->create($tmp) $coerced->create($new)
Truth table0%0/3
A and B
A= $coerced->create($tmp)B= $coerced->create($new)
ABresult
0X0
100
111
381 0 {$self->log(PROGRESS => "Appended Maildir message in $new") }
382 0 else {$self->log(ERROR =>
383 "Cannot append Maildir message in $new to folder $self.") }
384 }
385
386 0 $self->close;
387  
388 0 @messages;
389 }
390  
391 #-------------------------------------------
392  
393  
394 5 1;
« Box/Search/Grep.pm ↑ Summary Box/MH/Labels.pm »