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