| 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::File; | ||||||||||||||||||||||||||||
| 10 | 25 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 25 | $VERSION = '3.009'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 25 | ▶ | use base 'Mail::Box'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 25 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 25 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 25 | ▶ | use filetest 'access'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 25 | ▶ | use Mail::Box::File::Message; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 25 | ▶ | use Mail::Message::Body::Lines; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 25 | ▶ | use Mail::Message::Body::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 25 | ▶ | use Mail::Message::Body::Delayed; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 25 | ▶ | use Mail::Message::Body::Multipart; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 25 | ▶ | use Mail::Message::Head; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 25 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 25 | ▶ | use File::Copy; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 25 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 25 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 25 | ▶ | use POSIX ':unistd_h'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # tell() is not available for open(my $fh) on perl versions <= 5.10 So, | ||||||||||||||||||||||||||||
| 36 | # we need to stick to IO::File syntax. | ||||||||||||||||||||||||||||
| 37 | 25 | ▶ | use IO::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 25 | my $windows; | |||||||||||||||||||||||||||
| 40 | 25 | ▶ | BEGIN { $windows = $^O =~ m/mswin32/i } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 25 | ▶ | my $default_folder_dir = exists $ENV{HOME} ? $ENV{HOME} . '/Mail' : '.'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | sub _default_body_type($$) | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | { my $size = shift->guessBodySize || 0; | ||||||||||||||||||||||||||
|
Subroutine
_default_body_type: not called CC=3 SCAR=24.8
Condition0%0/2
(shift())->guessBodySize || 0
MC/DC0%0/1
(shift())->guessBodySize || 0
(shift())->guessBodySize
Truth table0%0/2
A
A= (shift())->guessBodySize
| |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | 'Mail::Message::Body::'.($size > 100000 ? 'File' : 'Lines'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | sub init($) | ||||||||||||||||||||||||||||
| 51 | 15 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=17 SCAR=52.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | 15 | ▶ | $args->{folderdir} ||= $default_folder_dir; | ||||||||||||||||||||||||||
|
Condition66%2/3
$args->{"folderdir"} ||= $default_folder_dir
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
| |||||||||||||||||||||||||||||
| 53 | 15 | ▶ | $args->{body_type} ||= \&_default_body_type; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args->{"body_type"} ||= \&Mail::Box::File::_default_body_type
MC/DC0%0/1
$args->{"body_type"} ||= \&Mail::Box::File::_default_body_type
$args->{"body_type"}
Truth table50%1/2
A
A= $args->{"body_type"}
| |||||||||||||||||||||||||||||
| 54 | 15 | ▶ | $args->{lock_file} ||= '--'; # to be resolved later | ||||||||||||||||||||||||||
|
Condition50%1/2
$args->{"lock_file"} ||= "--"
MC/DC0%0/1
$args->{"lock_file"} ||= "--"
$args->{"lock_file"}
Truth table50%1/2
A
A= $args->{"lock_file"}
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 15 | ▶ | defined $self->SUPER::init($args) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | or return; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | my $class = ref $self; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | my $filename = $self->{MBF_filename} | ||||||||||||||||||||||||||||
| 62 | 0 | = $self->folderToFilename | |||||||||||||||||||||||||||
| 63 | ( $self->name | ||||||||||||||||||||||||||||
| 64 | , $self->folderdir | ||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if(-e $filename) {;} # Folder already exists | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 68 | ▶ | elsif($args->{create} && $class->create($args->{folder}, %$args)) {;} | |||||||||||||||||||||||||||
|
Condition0%0/3
$args->{"create"} and $class->create($args->{"folder"}, %$args)
MC/DC0%0/2
$args->{"create"} and $class->create($args->{"folder"}, %$args)
$args->{"create"}
$class->create($args->{"folder"}, %$args)
Truth table0%0/3
A and B
A= $args->{"create"}B= $class->create($args->{"folder"}, %$args)
| |||||||||||||||||||||||||||||
| 69 | else | ||||||||||||||||||||||||||||
| 70 | 0 | { $self->log(PROGRESS => | |||||||||||||||||||||||||||
| 71 | "File $filename for folder $self does not exist."); | ||||||||||||||||||||||||||||
| 72 | 0 | return; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | $self->{MBF_policy} = $args->{write_policy}; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # Lock the folder. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | my $locker = $self->locker; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | my $lockfile = $locker->filename; | |||||||||||||||||||||||||||
| 82 | 0 | ▶ | if($lockfile eq '--') # filename to be used not resolved yet | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | { my $lockdir = $filename; | |||||||||||||||||||||||||||
| 84 | 0 | $lockdir =~ s!/([^/]*)$!!; | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | my $extension = $args->{lock_extension} || '.lock'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'lock_extension'} || '.lock'
MC/DC0%0/1
$args->{'lock_extension'} || '.lock'
$args->{'lock_extension'}
Truth table0%0/2
A
A= $args->{'lock_extension'}
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | $locker->filename | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 88 | ( File::Spec->file_name_is_absolute($extension) ? $extension | ||||||||||||||||||||||||||||
| 89 | : $extension =~ m!^\.! ? "$filename$extension" | ||||||||||||||||||||||||||||
| 90 | : File::Spec->catfile($lockdir, $extension) | ||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | unless($locker->lock) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | { $self->log(ERROR => "Cannot get a lock on $class folder $self."); | |||||||||||||||||||||||||||
| 96 | 0 | return; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | # Check if we can write to the folder, if we need to. | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if($self->writable && ! -w $filename) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->writable and not -w $filename
MC/DC0%0/2
$self->writable and not -w $filename
$self->writable
not -w $filename
Truth table0%0/3
A and not(B)
A= $self->writableB= not -w $filename
| |||||||||||||||||||||||||||||
| 102 | 0 | { $self->log(WARNING => "Folder $self file $filename is write-protected."); | |||||||||||||||||||||||||||
| 103 | 0 | $self->{MB_access} = 'r'; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | # Start parser if reading is required. | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | $self->{MB_access} !~ m/r/ ? $self | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 109 | : $self->parser ? $self | ||||||||||||||||||||||||||||
| 110 | : undef; | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | sub create($@) | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | { my ($thingy, $name, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
create: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | my $class = ref $thingy || $thingy; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $thingy || $thingy
MC/DC0%0/2
ref $thingy || $thingy
ref $thingy
$thingy
Truth table0%0/3
A || B
A= ref $thingyB= $thingy
| |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | my $folderdir = $args{folderdir} || $default_folder_dir; | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{'folderdir'} || $default_folder_dir
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
| |||||||||||||||||||||||||||||
| 118 | 0 | my $subext = $args{subfolder_extension}; # not always available | |||||||||||||||||||||||||||
| 119 | 0 | my $filename = $class->folderToFilename($name, $folderdir, $subext); | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | return $class if -f $filename; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | my $dir = dirname $filename; | |||||||||||||||||||||||||||
| 124 | 0 | ▶ | if(-f $dir && defined $subext) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $dir and defined $subext
MC/DC0%0/2
-f $dir and defined $subext
-f $dir
defined $subext
Truth table0%0/3
A and B
A= -f $dirB= defined $subext
| |||||||||||||||||||||||||||||
| 125 | 0 | { $dir .= $subext; | |||||||||||||||||||||||||||
| 126 | 0 | $filename = File::Spec->catfile($dir, basename $filename); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | $class->log(ERROR => "Cannot create directory $dir for folder $name: $!"),return | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-d $dir or mkdir $dir, 493
MC/DC0%0/2
-d $dir or mkdir $dir, 493
-d $dir
mkdir $dir, 493
Truth table0%0/3
A or B
A= -d $dirB= mkdir $dir, 493
| |||||||||||||||||||||||||||||
| 130 | unless -d $dir || mkdir $dir, 0755; | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | ▶ | $class->moveAwaySubFolder($filename, $subext) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-d $filename and defined $subext
MC/DC0%0/2
-d $filename and defined $subext
-d $filename
defined $subext
Truth table0%0/3
A and B
A= -d $filenameB= defined $subext
| |||||||||||||||||||||||||||||
| 133 | if -d $filename && defined $subext; | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | my $create = IO::File->new($filename, 'w'); | |||||||||||||||||||||||||||
| 136 | 0 | ▶ | unless($create) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 0 | { $class->log(WARNING => "Cannot create folder file $name: $!"); | |||||||||||||||||||||||||||
| 138 | 0 | return; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | $class->log(PROGRESS => "Created folder $name."); | |||||||||||||||||||||||||||
| 142 | 0 | ▶ | $create->close or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 0 | $class; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | sub foundIn($@) | ||||||||||||||||||||||||||||
| 147 | 0 | ▶ | { my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
foundIn: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 148 | 0 | ▶ | my $name = @_ % 2 ? shift : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 150 | 0 | ▶ | $name ||= $args{folder} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$name ||= $args{"folder"}
MC/DC0%0/2
$name ||= $args{"folder"}
$name
$args{"folder"}
Truth table0%0/3
A ||= B
A= $nameB= $args{"folder"}
| |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | my $folderdir = $args{folderdir} || $default_folder_dir; | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{'folderdir'} || $default_folder_dir
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
| |||||||||||||||||||||||||||||
| 153 | 0 | my $filename = $class->folderToFilename($name, $folderdir); | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 0 | -f $filename; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | sub organization() { 'FILE' } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | sub size() | ||||||||||||||||||||||||||||
| 161 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
size: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 162 | 0 | ▶ | $self->isModified ? $self->SUPER::size : -s $self->filename; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | sub close(@) | ||||||||||||||||||||||||||||
| 166 | 15 | ▶ | { my $self = $_[0]; # be careful, we want to set the calling | ||||||||||||||||||||||||||
|
Subroutine
close: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 167 | 15 | undef $_[0]; # ref to undef, as the SUPER does. | |||||||||||||||||||||||||||
| 168 | 15 | shift; | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 15 | my $rc = $self->SUPER::close(@_); | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 15 | ▶ | if(my $parser = delete $self->{MBF_parser}) { $parser->stop } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 15 | $rc; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | sub appendMessages(@) | ||||||||||||||||||||||||||||
| 179 | 0 | ▶ | { my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
appendMessages: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 180 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | my @messages | ||||||||||||||||||||||||||||
| 183 | = exists $args{message} ? $args{message} | ||||||||||||||||||||||||||||
| 184 | 0 | ▶ | : exists $args{messages} ? @{$args{messages}} | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 185 | : return (); | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 0 | ▶ | my $folder = $class->new(lock_type => 'NONE', @_, access => 'w+') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | or return (); | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | my $filename = $folder->filename; | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 0 | my $out = IO::File->new($filename, 'a'); | |||||||||||||||||||||||||||
| 193 | 0 | ▶ | unless($out) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | 0 | { $class->log(ERROR => "Cannot append messages to folder file $filename: $!"); | |||||||||||||||||||||||||||
| 195 | 0 | return (); | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 0 | my $msgtype = $class.'::Message'; | |||||||||||||||||||||||||||
| 199 | 0 | my @coerced; | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | foreach my $msg (@messages) | |||||||||||||||||||||||||||
| 202 | 0 | ▶ | { my $coerced | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 203 | = $msg->isa($msgtype) ? $msg | ||||||||||||||||||||||||||||
| 204 | : $msg->can('clone') ? $msgtype->coerce($msg->clone) | ||||||||||||||||||||||||||||
| 205 | : $msgtype->coerce($msg); | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 0 | $coerced->write($out); | |||||||||||||||||||||||||||
| 208 | 0 | push @coerced, $coerced; | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | my $ok = $folder->close; | |||||||||||||||||||||||||||
| 212 | 0 | ▶ | $out->close && $ok | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$out->close and $ok
MC/DC0%0/2
$out->close and $ok
$out->close
$ok
Truth table0%0/3
A and B
A= $out->closeB= $ok
| |||||||||||||||||||||||||||||
| 213 | or return 0; | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 0 | @coerced; | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 0 | ▶ | sub filename() { shift->{MBF_filename} } | ||||||||||||||||||||||||||
|
Subroutine
filename: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | sub parser() | ||||||||||||||||||||||||||||
| 227 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
parser: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | return $self->{MBF_parser} | ||||||||||||||||||||||||||||
| 230 | 0 | ▶ | if defined $self->{MBF_parser}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 0 | my $source = $self->filename; | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 0 | ▶ | my $mode = $self->{MB_access} || 'r'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'MB_access'} || 'r'
MC/DC0%0/1
$self->{'MB_access'} || 'r'
$self->{'MB_access'}
Truth table0%0/2
A
A= $self->{'MB_access'}
| |||||||||||||||||||||||||||||
| 235 | 0 | ▶ | $mode = 'r+' if $mode eq 'rw' || $mode eq 'a'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mode eq "rw" or $mode eq "a"
MC/DC0%0/2
$mode eq "rw" or $mode eq "a"
$mode eq "rw"
$mode eq "a"
Truth table0%0/3
A or B
A= $mode eq "rw"B= $mode eq "a"
| |||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | my $parser = $self->{MBF_parser} | ||||||||||||||||||||||||||||
| 238 | = Mail::Box::Parser->new | ||||||||||||||||||||||||||||
| 239 | ( filename => $source | ||||||||||||||||||||||||||||
| 240 | , mode => $mode | ||||||||||||||||||||||||||||
| 241 | , trusted => $self->{MB_trusted} | ||||||||||||||||||||||||||||
| 242 | , fix_header_errors => $self->{MB_fix_headers} | ||||||||||||||||||||||||||||
| 243 | 0 | ▶ | , $self->logSettings | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | ) or return; | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 0 | $parser->pushSeparator('From '); | |||||||||||||||||||||||||||
| 247 | 0 | $parser; | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | sub readMessages(@) | ||||||||||||||||||||||||||||
| 251 | 0 | ▶ | { my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
readMessages: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | $self->messageCreateOptions | ||||||||||||||||||||||||||||
| 254 | ( $args{message_type} | ||||||||||||||||||||||||||||
| 255 | , $self->logSettings | ||||||||||||||||||||||||||||
| 256 | , folder => $self | ||||||||||||||||||||||||||||
| 257 | , head_type => $args{head_type} | ||||||||||||||||||||||||||||
| 258 | , field_type => $args{field_type} | ||||||||||||||||||||||||||||
| 259 | , trusted => $args{trusted} | ||||||||||||||||||||||||||||
| 260 | 0 | ); | |||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 0 | $self->updateMessages; | |||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | sub updateMessages(@) | ||||||||||||||||||||||||||||
| 267 | 0 | ▶ | { my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
updateMessages: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 268 | 0 | ▶ | my $parser = $self->parser or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | # On a directory, simulate an empty folder with only subfolders. | ||||||||||||||||||||||||||||
| 271 | 0 | my $filename = $self->filename; | |||||||||||||||||||||||||||
| 272 | 0 | ▶ | return $self if -d $filename; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 0 | ▶ | if(my $last = $self->message(-1)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | 0 | { (undef, my $end) = $last->fileLocation; | |||||||||||||||||||||||||||
| 276 | 0 | $parser->filePosition($end); | |||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 0 | my ($type, @msgopts) = $self->messageCreateOptions; | |||||||||||||||||||||||||||
| 280 | 0 | my $count = 0; | |||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 0 | while(1) | |||||||||||||||||||||||||||
| 283 | 0 | { my $message = $type->new(@msgopts); | |||||||||||||||||||||||||||
| 284 | 0 | ▶ | last unless $message->readFromParser($parser); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | 0 | $self->storeMessage($message); | |||||||||||||||||||||||||||
| 286 | 0 | $count++; | |||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 0 | ▶ | $self->log(PROGRESS => "Found $count new messages in $filename") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 290 | if $count; | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 0 | $self; | |||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | sub messageCreateOptions(@) | ||||||||||||||||||||||||||||
| 297 | 0 | ▶ | { my ($self, @options) = @_; | ||||||||||||||||||||||||||
|
Subroutine
messageCreateOptions: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 298 | 0 | ▶ | if(@options) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 299 | 0 | ▶ | { ref($_) && ref($_) =~ m/^Mail::/ && weaken $_ for @options; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $_ and ref($_) =~ /^Mail::/
MC/DC0%0/2
ref $_ and ref($_) =~ /^Mail::/
ref $_
ref($_) =~ /^Mail::/
Truth table0%0/3
A and B
A= ref $_B= ref($_) =~ /^Mail::/
| |||||||||||||||||||||||||||||
| 300 | 0 | $self->{MBF_create_options} = \@options; | |||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 0 | @{$self->{MBF_create_options}}; | |||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | sub moveAwaySubFolder($$) | ||||||||||||||||||||||||||||
| 308 | 0 | ▶ | { my ($self, $dir, $extension) = @_; | ||||||||||||||||||||||||||
|
Subroutine
moveAwaySubFolder: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 309 | 0 | ▶ | $self->log(ERROR => "Cannot move away sub-folder $dir") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | unless move $dir, $dir.$extension; | ||||||||||||||||||||||||||||
| 311 | 0 | $self; | |||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | sub delete(@) | ||||||||||||||||||||||||||||
| 315 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 316 | 0 | $self->SUPER::delete(@_); | |||||||||||||||||||||||||||
| 317 | 0 | unlink $self->filename; | |||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | sub writeMessages($) | ||||||||||||||||||||||||||||
| 322 | 0 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
writeMessages: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 0 | my $filename = $self->filename; | |||||||||||||||||||||||||||
| 325 | 0 | ▶ | if( ! @{$args->{messages}} && $self->{MB_remove_empty}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not @{$args->{"messages"};} and $self->{"MB_remove_empty"}
MC/DC0%0/2
not @{$args->{"messages"};} and $self->{"MB_remove_empty"}
not @{$args->{"messages"};}
$self->{"MB_remove_empty"}
Truth table0%0/3
not(A) and B
A= not @{$args->{"messages"};}B= $self->{"MB_remove_empty"}
| |||||||||||||||||||||||||||||
| 326 | 0 | ▶ | { $self->log(WARNING => "Cannot remove folder $self file $filename: $!") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 327 | unless unlink $filename; | ||||||||||||||||||||||||||||
| 328 | 0 | return $self; | |||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 0 | ▶ | my $policy = exists $args->{policy} ? $args->{policy} : $self->{MBF_policy}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 332 | 0 | ▶ | $policy ||= ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$policy ||= ""
MC/DC0%0/1
$policy ||= ""
$policy
Truth table0%0/2
A
A= $policy
| |||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | 0 | ▶ | my $success | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 335 | = ! -e $filename ? $self->_write_new($args) | ||||||||||||||||||||||||||||
| 336 | : $policy eq 'INPLACE' ? $self->_write_inplace($args) | ||||||||||||||||||||||||||||
| 337 | : $policy eq 'REPLACE' ? $self->_write_replace($args) | ||||||||||||||||||||||||||||
| 338 | : $self->_write_replace($args) ? 1 | ||||||||||||||||||||||||||||
| 339 | : $self->_write_inplace($args); | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | 0 | ▶ | unless($success) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 342 | 0 | { $self->log(ERROR => "Unable to update folder $self."); | |||||||||||||||||||||||||||
| 343 | 0 | return; | |||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | # $self->parser->restart; | ||||||||||||||||||||||||||||
| 347 | 0 | $self; | |||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | sub _write_new($) | ||||||||||||||||||||||||||||
| 351 | 0 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_write_new: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 0 | my $filename = $self->filename; | |||||||||||||||||||||||||||
| 354 | 0 | my $new = IO::File->new($filename, 'w'); | |||||||||||||||||||||||||||
| 355 | 0 | ▶ | return 0 unless defined $new; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | 0 | $new->binmode; | |||||||||||||||||||||||||||
| 358 | 0 | $_->write($new) foreach @{$args->{messages}}; | |||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | 0 | ▶ | $new->close or return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | $self->log(PROGRESS => | ||||||||||||||||||||||||||||
| 363 | 0 | "Wrote new folder $self with ".@{$args->{messages}}."msgs."); | |||||||||||||||||||||||||||
| 364 | 0 | 1; | |||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | # First write to a new file, then replace the source folder in one | ||||||||||||||||||||||||||||
| 368 | # move. This is much slower than inplace update, but it is safer, | ||||||||||||||||||||||||||||
| 369 | # The folder is always in the right shape, even if the program is | ||||||||||||||||||||||||||||
| 370 | # interrupted. | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | sub _write_replace($) | ||||||||||||||||||||||||||||
| 373 | 0 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_write_replace: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | 0 | my $filename = $self->filename; | |||||||||||||||||||||||||||
| 376 | 0 | my $tmpnew = $self->tmpNewFolder($filename); | |||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | 0 | ▶ | my $new = IO::File->new($tmpnew, 'w') or return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 379 | 0 | $new->binmode; | |||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | 0 | ▶ | my $old = IO::File->new($filename, 'r') or return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 382 | 0 | $old->binmode; | |||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | 0 | my ($reprint, $kept) = (0,0); | |||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | 0 | foreach my $message ( @{$args->{messages}} ) | |||||||||||||||||||||||||||
| 387 | { | ||||||||||||||||||||||||||||
| 388 | 0 | my $newbegin = $new->tell; | |||||||||||||||||||||||||||
| 389 | 0 | my $oldbegin = $message->fileLocation; | |||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | 0 | ▶ | if($message->isModified) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 392 | 0 | { $message->write($new); | |||||||||||||||||||||||||||
| 393 | 0 | ▶ | $message->moveLocation($newbegin - $oldbegin) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 394 | if defined $oldbegin; | ||||||||||||||||||||||||||||
| 395 | 0 | $reprint++; | |||||||||||||||||||||||||||
| 396 | 0 | next; | |||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | 0 | my ($begin, $end) = $message->fileLocation; | |||||||||||||||||||||||||||
| 400 | 0 | my $need = $end-$begin; | |||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | 0 | $old->seek($begin, 0); | |||||||||||||||||||||||||||
| 403 | 0 | my $whole; | |||||||||||||||||||||||||||
| 404 | 0 | my $size = $old->read($whole, $need); | |||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | 0 | ▶ | $self->log(ERROR => "File too short to get write message " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 407 | . $message->seqnr. " ($size, $need)") | ||||||||||||||||||||||||||||
| 408 | unless $size == $need; | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | 0 | $new->print($whole); | |||||||||||||||||||||||||||
| 411 | 0 | ▶ | $new->print($Mail::Message::crlf_platform ? "\r\n" : "\n"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 0 | $message->moveLocation($newbegin - $oldbegin); | |||||||||||||||||||||||||||
| 414 | 0 | $kept++; | |||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | 0 | my $ok = $new->close; | |||||||||||||||||||||||||||
| 418 | 0 | ▶ | $old->close && $ok | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$old->close and $ok
MC/DC0%0/2
$old->close and $ok
$old->close
$ok
Truth table0%0/3
A and B
A= $old->closeB= $ok
| |||||||||||||||||||||||||||||
| 419 | or return 0; | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | 0 | ▶ | if($windows) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 422 | { # Windows does not like to move to existing filenames | ||||||||||||||||||||||||||||
| 423 | 0 | unlink $filename; | |||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | # Windows cannot move to files which are opened. | ||||||||||||||||||||||||||||
| 426 | 0 | $self->parser->closeFile; | |||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | 0 | ▶ | unless(move $tmpnew, $filename) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 430 | 0 | { $self->log(WARNING => | |||||||||||||||||||||||||||
| 431 | "Cannot replace $filename by $tmpnew, to update folder $self: $!"); | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | 0 | unlink $tmpnew; | |||||||||||||||||||||||||||
| 434 | 0 | return 0; | |||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | 0 | $self->log(PROGRESS => "Folder $self replaced ($kept, $reprint)"); | |||||||||||||||||||||||||||
| 438 | 0 | 1; | |||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | # Inplace is currently very poorly implemented. From the first | ||||||||||||||||||||||||||||
| 442 | # location where changes appear, all messages are rewritten. | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | sub _write_inplace($) | ||||||||||||||||||||||||||||
| 445 | 0 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_write_inplace: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | 0 | my @messages = @{$args->{messages}}; | |||||||||||||||||||||||||||
| 448 | 0 | my $last; | |||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | 0 | my ($msgnr, $kept) = (0, 0); | |||||||||||||||||||||||||||
| 451 | 0 | ▶ | while(@messages) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 452 | 0 | { my $next = $messages[0]; | |||||||||||||||||||||||||||
| 453 | 0 | ▶ | last if $next->isModified || $next->seqnr!=$msgnr++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$next->isModified or $next->seqnr != $msgnr++
MC/DC0%0/2
$next->isModified or $next->seqnr != $msgnr++
$next->isModified
$next->seqnr != $msgnr++
Truth table0%0/3
A or B
A= $next->isModifiedB= $next->seqnr != $msgnr++
| |||||||||||||||||||||||||||||
| 454 | 0 | $last = shift @messages; | |||||||||||||||||||||||||||
| 455 | 0 | $kept++; | |||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | 0 | ▶ | if(@messages==0 && $msgnr==$self->messages) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@messages == 0 and $msgnr == $self->messages
MC/DC0%0/2
@messages == 0 and $msgnr == $self->messages
@messages == 0
$msgnr == $self->messages
Truth table0%0/3
A and B
A= @messages == 0B= $msgnr == $self->messages
| |||||||||||||||||||||||||||||
| 459 | 0 | { $self->log(PROGRESS => "No changes to be written to $self."); | |||||||||||||||||||||||||||
| 460 | 0 | return 1; | |||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | 0 | $_->body->load foreach @messages; | |||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | 0 | ▶ | my $mode = $^O eq 'MSWin32' ? 'a' : 'r+'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 466 | 0 | my $filename = $self->filename; | |||||||||||||||||||||||||||
| 467 | 0 | ▶ | my $old = IO::File->new($filename, $mode) or return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | # Chop the folder after the messages which does not have to change. | ||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | 0 | ▶ | my $end = defined $last ? ($last->fileLocation)[1] : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | 0 | $end =~ m/(.*)/; # untaint, only required by perl5.6.1 | |||||||||||||||||||||||||||
| 474 | 0 | $end = $1; | |||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | 0 | ▶ | unless($old->truncate($end)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 477 | { # truncate impossible: try replace writing | ||||||||||||||||||||||||||||
| 478 | 0 | $old->close; | |||||||||||||||||||||||||||
| 479 | 0 | return 0; | |||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | 0 | ▶ | unless(@messages) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 483 | { # All further messages only are flagged to be deleted | ||||||||||||||||||||||||||||
| 484 | 0 | ▶ | $old->close or return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 485 | 0 | $self->log(PROGRESS => "Folder $self shortened in-place ($kept kept)"); | |||||||||||||||||||||||||||
| 486 | 0 | return 1; | |||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | # go to the end of the truncated output file. | ||||||||||||||||||||||||||||
| 490 | 0 | $old->seek(0, 2); | |||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | # Print the messages which have to move. | ||||||||||||||||||||||||||||
| 493 | 0 | my $printed = @messages; | |||||||||||||||||||||||||||
| 494 | 0 | foreach my $message (@messages) | |||||||||||||||||||||||||||
| 495 | 0 | { my $oldbegin = $message->fileLocation; | |||||||||||||||||||||||||||
| 496 | 0 | my $newbegin = $old->tell; | |||||||||||||||||||||||||||
| 497 | 0 | $message->write($old); | |||||||||||||||||||||||||||
| 498 | 0 | $message->moveLocation($newbegin - $oldbegin); | |||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | 0 | ▶ | $old->close or return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 502 | 0 | $self->log(PROGRESS => "Folder $self updated in-place ($kept, $printed)"); | |||||||||||||||||||||||||||
| 503 | 0 | 1; | |||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | sub folderToFilename($$;$) | ||||||||||||||||||||||||||||
| 510 | 0 | ▶ | { my ($thing, $name, $folderdir) = @_; | ||||||||||||||||||||||||||
|
Subroutine
folderToFilename: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||
| 512 | 0 | ▶ | substr $name, 0, 1, $folderdir | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 513 | if substr $name, 0, 1 eq '='; | ||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | 0 | $name; | |||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | 0 | ▶ | sub tmpNewFolder($) { shift->filename . '.tmp' } | ||||||||||||||||||||||||||
|
Subroutine
tmpNewFolder: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||
| 523 | 25 | 1; | |||||||||||||||||||||||||||