| 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::MH; | ||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 9 | $VERSION = '3.009'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 9 | ▶ | use base 'Mail::Box::Dir'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 9 | ▶ | use filetest 'access'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 9 | ▶ | use Mail::Box::MH::Index; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 9 | ▶ | use Mail::Box::MH::Message; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 9 | ▶ | use Mail::Box::MH::Labels; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 9 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 9 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 9 | ▶ | use File::Basename 'basename'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 9 | ▶ | use IO::Handle (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # Since MailBox 2.052, the use of File::Spec is reduced to the minimum, | ||||||||||||||||||||||||||||
| 29 | # because it is too slow. The '/' directory separators do work on | ||||||||||||||||||||||||||||
| 30 | # Windows too. | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 9 | ▶ | my $default_folder_dir = exists $ENV{HOME} ? "$ENV{HOME}/.mh" : '.'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub init($) | ||||||||||||||||||||||||||||
| 36 | 5 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=13 SCAR=46.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 5 | ▶ | $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
| |||||||||||||||||||||||||||||
| 39 | 5 | ▶ | $args->{lock_file} ||= $args->{index_filename}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args->{"lock_file"} ||= $args->{"index_filename"}
MC/DC0%0/2
$args->{"lock_file"} ||= $args->{"index_filename"}
$args->{"lock_file"}
$args->{"index_filename"}
Truth table33%1/3
A ||= B
A= $args->{"lock_file"}B= $args->{"index_filename"}
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 5 | $self->SUPER::init($args); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | my $folderdir = $self->folderdir; | |||||||||||||||||||||||||||
| 44 | 0 | my $directory = $self->directory; | |||||||||||||||||||||||||||
| 45 | 0 | ▶ | return unless -d $directory; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # About the index | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $self->{MBM_keep_index} = $args->{keep_index} || 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'keep_index'} || 0
MC/DC0%0/1
$args->{'keep_index'} || 0
$args->{'keep_index'}
Truth table0%0/2
A
A= $args->{'keep_index'}
| |||||||||||||||||||||||||||||
| 50 | 0 | $self->{MBM_index} = $args->{index}; | |||||||||||||||||||||||||||
| 51 | 0 | ▶ | $self->{MBM_index_type} = $args->{index_type} || 'Mail::Box::MH::Index'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'index_type'} || 'Mail::Box::MH::Index'
MC/DC0%0/1
$args->{'index_type'} || 'Mail::Box::MH::Index'
$args->{'index_type'}
Truth table0%0/2
A
A= $args->{'index_type'}
| |||||||||||||||||||||||||||||
| 52 | 0 | for($args->{index_filename}) | |||||||||||||||||||||||||||
| 53 | { $self->{MBM_index_filename} | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | = !defined $_ ? "$directory/.index" # default | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 55 | : File::Spec->file_name_is_absolute($_) ? $_ # absolute | ||||||||||||||||||||||||||||
| 56 | : "$directory/$_"; # relative | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # About labels | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | $self->{MBM_labels} = $args->{labels}; | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | $self->{MBM_labels_type} = $args->{labels_type} || 'Mail::Box::MH::Labels'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'labels_type'} || 'Mail::Box::MH::Labels'
MC/DC0%0/1
$args->{'labels_type'} || 'Mail::Box::MH::Labels'
$args->{'labels_type'}
Truth table0%0/2
A
A= $args->{'labels_type'}
| |||||||||||||||||||||||||||||
| 63 | 0 | for($args->{labels_filename}) | |||||||||||||||||||||||||||
| 64 | { $self->{MBM_labels_filename} | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | = !defined $_ ? "$directory/.mh_sequences" | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 66 | : File::Spec->file_name_is_absolute($_) ? $_ # absolute | ||||||||||||||||||||||||||||
| 67 | : "$directory/$_"; # relative | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | $self; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | sub create($@) | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | { my ($thingy, $name, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
create: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 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
| |||||||||||||||||||||||||||||
| 77 | 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
| |||||||||||||||||||||||||||||
| 78 | 0 | my $directory = $class->folderToDirectory($name, $folderdir); | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | return $class if -d $directory; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if(mkdir $directory, 0700) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | { $class->log(PROGRESS => "Created folder $name."); | |||||||||||||||||||||||||||
| 84 | 0 | return $class; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | else | ||||||||||||||||||||||||||||
| 87 | 0 | { $class->log(ERROR => "Cannot create MH folder $name: $!"); | |||||||||||||||||||||||||||
| 88 | 0 | return; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | sub foundIn($@) | ||||||||||||||||||||||||||||
| 93 | 5 | ▶ | { my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
foundIn: called CC=8 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 5 | ▶ | my $name = @_ % 2 ? shift : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 5 | my %args = @_; | |||||||||||||||||||||||||||
| 96 | 5 | ▶ | my $folderdir = $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
| |||||||||||||||||||||||||||||
| 97 | 5 | my $directory = $class->folderToDirectory($name, $folderdir); | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 5 | ▶ | return 0 unless -d $directory; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 5 | ▶ | return 1 if -f "$directory/1"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | # More thorough search required in case some numbered messages | ||||||||||||||||||||||||||||
| 103 | # disappeared (lost at fsck or copy?) | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 1 | ▶ | return unless opendir DIR, $directory; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 1 | foreach (readdir DIR) | |||||||||||||||||||||||||||
| 107 | 5 | ▶ | { next unless m/^\d+$/; # Look for filename which is a number. | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | closedir DIR; | |||||||||||||||||||||||||||
| 109 | 0 | return 1; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 1 | closedir DIR; | |||||||||||||||||||||||||||
| 113 | 1 | 0; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | sub type() {'mh'} | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | sub listSubFolders(@) | ||||||||||||||||||||||||||||
| 123 | 22 | ▶ | { my ($class, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
listSubFolders: called CC=20 SCAR=45.9
Pod
documented
| |||||||||||||||||||||||||||||
| 124 | 22 | my $dir; | |||||||||||||||||||||||||||
| 125 | 22 | ▶ | if(ref $class) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | { $dir = $class->directory; | |||||||||||||||||||||||||||
| 127 | 0 | $class = ref $class; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | else | ||||||||||||||||||||||||||||
| 130 | 22 | ▶ | { my $folder = $args{folder} || '='; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{'folder'} || '='
MC/DC0%0/1
$args{'folder'} || '='
$args{'folder'}
Truth table50%1/2
A
A= $args{'folder'}
| |||||||||||||||||||||||||||||
| 131 | 22 | ▶ | 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
| |||||||||||||||||||||||||||||
| 132 | 22 | $dir = $class->folderToDirectory($folder, $folderdir); | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 22 | ▶ | $args{skip_empty} ||= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{"skip_empty"} ||= 0
MC/DC0%0/1
$args{"skip_empty"} ||= 0
$args{"skip_empty"}
Truth table50%1/2
A
A= $args{"skip_empty"}
| |||||||||||||||||||||||||||||
| 136 | 22 | ▶ | $args{check} ||= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{"check"} ||= 0
MC/DC0%0/1
$args{"check"} ||= 0
$args{"check"}
Truth table50%1/2
A
A= $args{"check"}
| |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | # Read the directories from the directory, to find all folders | ||||||||||||||||||||||||||||
| 139 | # stored here. Some directories have to be removed because they | ||||||||||||||||||||||||||||
| 140 | # are created by all kinds of programs, but are no folders. | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 22 | ▶ | return () unless -d $dir && opendir DIR, $dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-d $dir and opendir DIR, $dir
MC/DC0%0/2
-d $dir and opendir DIR, $dir
-d $dir
opendir DIR, $dir
Truth table33%1/3
A and B
A= -d $dirB= opendir DIR, $dir
| |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 22 | ▶ | my @dirs = grep { !/^\d+$|^\./ && -d "$dir/$_" && -r _ } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not /^\d+$|^\./ and -d "$dir/$_"
MC/DC50%1/2
not /^\d+$|^\./ and -d "$dir/$_"
not /^\d+$|^\./
-d "$dir/$_"
Truth table66%2/3
not(A) and B
A= not /^\d+$|^\./B= -d "$dir/$_"
| |||||||||||||||||||||||||||||
| 145 | readdir DIR; | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 22 | closedir DIR; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | # Skip empty folders. If a folder has sub-folders, then it is not | ||||||||||||||||||||||||||||
| 150 | # empty. | ||||||||||||||||||||||||||||
| 151 | 22 | ▶ | if($args{skip_empty}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | 0 | { my @not_empty; | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | foreach my $subdir (@dirs) | |||||||||||||||||||||||||||
| 155 | 0 | ▶ | { if(-f "$dir/$subdir/1") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | { # Fast found: the first message of a filled folder. | ||||||||||||||||||||||||||||
| 157 | 0 | push @not_empty, $subdir; | |||||||||||||||||||||||||||
| 158 | 0 | next; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | opendir DIR, "$dir/$subdir" or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 0 | my @entities = grep !/^\./, readdir DIR; | |||||||||||||||||||||||||||
| 163 | 0 | closedir DIR; | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | if(grep /^\d+$/, @entities) # message 1 was not there, but | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 0 | { push @not_empty, $subdir; # other message-numbers exist. | |||||||||||||||||||||||||||
| 167 | 0 | next; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 0 | foreach (@entities) | |||||||||||||||||||||||||||
| 171 | 0 | ▶ | { next unless -d "$dir/$subdir/$_"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 0 | push @not_empty, $subdir; | |||||||||||||||||||||||||||
| 173 | 0 | last; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 0 | @dirs = @not_empty; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | # Check if the files we want to return are really folders. | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 22 | ▶ | @dirs = map { m/(.*)/ && $1 ? $1 : () } @dirs; # untaint | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
/(.*)/ and $1
MC/DC0%0/2
/(.*)/ and $1
/(.*)/
$1
Truth table33%1/3
A and B
A= /(.*)/B= $1
| |||||||||||||||||||||||||||||
| 184 | 22 | ▶ | return @dirs unless $args{check}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 0 | grep { $class->foundIn("$dir/$_") } @dirs; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | sub openSubFolder($) | ||||||||||||||||||||||||||||
| 192 | 0 | ▶ | { my ($self, $name) = @_; | ||||||||||||||||||||||||||
|
Subroutine
openSubFolder: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 0 | my $subdir = $self->nameOfSubFolder($name); | |||||||||||||||||||||||||||
| 195 | 0 | ▶ | unless(-d $subdir || mkdir $subdir, 0755) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-d $subdir or mkdir $subdir, 493
MC/DC0%0/2
-d $subdir or mkdir $subdir, 493
-d $subdir
mkdir $subdir, 493
Truth table0%0/3
A or B
A= -d $subdirB= mkdir $subdir, 493
| |||||||||||||||||||||||||||||
| 196 | 0 | { warn "Cannot create subfolder $name for $self: $!\n"; | |||||||||||||||||||||||||||
| 197 | 0 | return; | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 0 | $self->SUPER::openSubFolder($name, @_); | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | sub topFolderWithMessages() { 1 } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | sub appendMessages(@) | ||||||||||||||||||||||||||||
| 211 | 0 | ▶ | { my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
appendMessages: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 212 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | my @messages = exists $args{message} ? $args{message} | ||||||||||||||||||||||||||||
| 215 | 0 | ▶ | : exists $args{messages} ? @{$args{messages}} | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 216 | : return (); | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 0 | ▶ | my $self = $class->new(@_, access => 'r') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | or return (); | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 0 | my $directory= $self->directory; | |||||||||||||||||||||||||||
| 222 | 0 | ▶ | return unless -d $directory; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | my $locker = $self->locker; | |||||||||||||||||||||||||||
| 225 | 0 | ▶ | unless($locker->lock) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | 0 | { $self->log(ERROR => "Cannot append message without lock on $self."); | |||||||||||||||||||||||||||
| 227 | 0 | return; | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 0 | my $msgnr = $self->highestMessageNumber +1; | |||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 0 | foreach my $message (@messages) | |||||||||||||||||||||||||||
| 233 | 0 | { my $filename = "$directory/$msgnr"; | |||||||||||||||||||||||||||
| 234 | 0 | ▶ | $message->create($filename) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | or $self->log(ERROR => | ||||||||||||||||||||||||||||
| 236 | "Unable to write message for $self to $filename: $!\n"); | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 0 | $msgnr++; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 0 | $self->labels->append(@messages); | |||||||||||||||||||||||||||
| 242 | 0 | $self->index->append(@messages); | |||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 0 | $locker->unlock; | |||||||||||||||||||||||||||
| 245 | 0 | $self->close(write => 'NEVER'); | |||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 0 | @messages; | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | sub highestMessageNumber() | ||||||||||||||||||||||||||||
| 254 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
highestMessageNumber: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | return $self->{MBM_highest_msgnr} | ||||||||||||||||||||||||||||
| 257 | 0 | ▶ | if exists $self->{MBM_highest_msgnr}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 0 | my $directory = $self->directory; | |||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 0 | ▶ | opendir DIR, $directory or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | 0 | my @messages = sort {$a <=> $b} grep /^\d+$/, readdir DIR; | |||||||||||||||||||||||||||
| 263 | 0 | closedir DIR; | |||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 0 | $messages[-1]; | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | sub index() | ||||||||||||||||||||||||||||
| 272 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
index: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 273 | 0 | ▶ | return () unless $self->{MBM_keep_index}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 274 | 0 | ▶ | return $self->{MBM_index} if defined $self->{MBM_index}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | $self->{MBM_index} = $self->{MBM_index_type}->new | ||||||||||||||||||||||||||||
| 277 | ( filename => $self->{MBM_index_filename} | ||||||||||||||||||||||||||||
| 278 | 0 | , $self->logSettings | |||||||||||||||||||||||||||
| 279 | ) | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | sub labels() | ||||||||||||||||||||||||||||
| 287 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
labels: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 288 | 0 | ▶ | return $self->{MBM_labels} if defined $self->{MBM_labels}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | $self->{MBM_labels} = $self->{MBM_labels_type}->new | ||||||||||||||||||||||||||||
| 291 | ( filename => $self->{MBM_labels_filename} | ||||||||||||||||||||||||||||
| 292 | 0 | , $self->logSettings | |||||||||||||||||||||||||||
| 293 | ); | ||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | sub readMessageFilenames | ||||||||||||||||||||||||||||
| 299 | 0 | ▶ | { my ($self, $dirname) = @_; | ||||||||||||||||||||||||||
|
Subroutine
readMessageFilenames: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | 0 | ▶ | opendir DIR, $dirname or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | # list of numerically sorted, untainted filenames. | ||||||||||||||||||||||||||||
| 304 | my @msgnrs | ||||||||||||||||||||||||||||
| 305 | 0 | = sort {$a <=> $b} | |||||||||||||||||||||||||||
| 306 | 0 | ▶ | map { /^(\d+)$/ && -f "$dirname/$1" ? $1 : () } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
/^(\d+)$/ and -f "$dirname/$1"
MC/DC0%0/2
/^(\d+)$/ and -f "$dirname/$1"
/^(\d+)$/
-f "$dirname/$1"
Truth table0%0/3
A and B
A= /^(\d+)$/B= -f "$dirname/$1"
| |||||||||||||||||||||||||||||
| 307 | readdir DIR; | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | 0 | closedir DIR; | |||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | 0 | @msgnrs; | |||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | sub readMessages(@) | ||||||||||||||||||||||||||||
| 317 | 0 | ▶ | { my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
readMessages: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 0 | my $directory = $self->directory; | |||||||||||||||||||||||||||
| 320 | 0 | ▶ | return unless -d $directory; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 0 | my $locker = $self->locker; | |||||||||||||||||||||||||||
| 323 | 0 | ▶ | $locker->lock or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 0 | my @msgnrs = $self->readMessageFilenames($directory); | |||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 0 | my $index = $self->{MBM_index}; | |||||||||||||||||||||||||||
| 328 | 0 | ▶ | unless($index) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | 0 | { $index = $self->index; | |||||||||||||||||||||||||||
| 330 | 0 | ▶ | $index->read if $index; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 0 | my $labels = $self->{MBM_labels}; | |||||||||||||||||||||||||||
| 334 | 0 | ▶ | unless($labels) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 335 | 0 | { $labels = $self->labels; | |||||||||||||||||||||||||||
| 336 | 0 | ▶ | $labels->read if $labels; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | 0 | my $body_type = $args{body_delayed_type}; | |||||||||||||||||||||||||||
| 340 | 0 | my $head_type = $args{head_delayed_type}; | |||||||||||||||||||||||||||
| 341 | 0 | my @log = $self->logSettings; | |||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | 0 | foreach my $msgnr (@msgnrs) | |||||||||||||||||||||||||||
| 344 | { | ||||||||||||||||||||||||||||
| 345 | 0 | my $msgfile = "$directory/$msgnr"; | |||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 0 | my $head; | |||||||||||||||||||||||||||
| 348 | 0 | ▶ | $head = $index->get($msgfile) if $index; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 349 | 0 | ▶ | $head ||= $head_type->new(@log); | ||||||||||||||||||||||||||
|
Condition0%0/3
$head ||= $head_type->new(@log)
MC/DC0%0/2
$head ||= $head_type->new(@log)
$head
$head_type->new(@log)
Truth table0%0/3
A ||= B
A= $headB= $head_type->new(@log)
| |||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | my $message = $args{message_type}->new | ||||||||||||||||||||||||||||
| 352 | ( head => $head | ||||||||||||||||||||||||||||
| 353 | , filename => $msgfile | ||||||||||||||||||||||||||||
| 354 | , folder => $self | ||||||||||||||||||||||||||||
| 355 | , fix_header => $self->{MB_fix_headers} | ||||||||||||||||||||||||||||
| 356 | 0 | ); | |||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | 0 | ▶ | my $labref = $labels ? $labels->get($msgnr) : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 359 | 0 | ▶ | $message->label(seen => 1, $labref ? @$labref : ()); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | 0 | $message->storeBody($body_type->new(@log, message => $message)); | |||||||||||||||||||||||||||
| 362 | 0 | $self->storeMessage($message); | |||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | 0 | $self->{MBM_highest_msgnr} = $msgnrs[-1]; | |||||||||||||||||||||||||||
| 366 | 0 | $locker->unlock; | |||||||||||||||||||||||||||
| 367 | 0 | $self; | |||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | sub delete(@) | ||||||||||||||||||||||||||||
| 373 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 374 | 0 | $self->SUPER::delete(@_); | |||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | 0 | my $dir = $self->directory; | |||||||||||||||||||||||||||
| 377 | 0 | ▶ | return 1 unless opendir DIR, $dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | 0 | IO::Handle::untaint \*DIR; | |||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | # directories (subfolders) are not removed, as planned | ||||||||||||||||||||||||||||
| 381 | 0 | unlink "$dir/$_" for readdir DIR; | |||||||||||||||||||||||||||
| 382 | 0 | closedir DIR; | |||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | 0 | rmdir $dir; # fails when there are subdirs (without recurse) | |||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | sub writeMessages($) | ||||||||||||||||||||||||||||
| 391 | 0 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
writeMessages: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | # Write each message. Two things complicate life: | ||||||||||||||||||||||||||||
| 394 | # 1 - we may have a huge folder, which should not be on disk twice | ||||||||||||||||||||||||||||
| 395 | # 2 - we may have to replace a message, but it is unacceptable | ||||||||||||||||||||||||||||
| 396 | # to remove the original before we are sure that the new version | ||||||||||||||||||||||||||||
| 397 | # is on disk. | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | 0 | my $locker = $self->locker; | |||||||||||||||||||||||||||
| 400 | 0 | ▶ | $self->log(ERROR => "Cannot write folder $self without lock."), return | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 401 | unless $locker->lock; | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | 0 | ▶ | my $renumber = exists $args->{renumber} ? $args->{renumber} : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 404 | 0 | my $directory = $self->directory; | |||||||||||||||||||||||||||
| 405 | 0 | my @messages = @{$args->{messages}}; | |||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | 0 | my $writer = 0; | |||||||||||||||||||||||||||
| 408 | 0 | foreach my $message (@messages) | |||||||||||||||||||||||||||
| 409 | { | ||||||||||||||||||||||||||||
| 410 | 0 | my $filename = $message->filename; | |||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | 0 | my $newfile; | |||||||||||||||||||||||||||
| 413 | 0 | ▶ | if($renumber || !$filename) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$renumber or not $filename
MC/DC0%0/2
$renumber or not $filename
$renumber
not $filename
Truth table0%0/3
A or not(B)
A= $renumberB= not $filename
| |||||||||||||||||||||||||||||
| 414 | 0 | { $newfile = $directory . '/' . ++$writer; | |||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||
| 416 | else | ||||||||||||||||||||||||||||
| 417 | 0 | { $newfile = $filename; | |||||||||||||||||||||||||||
| 418 | 0 | $writer = basename $filename; | |||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | 0 | $message->create($newfile); | |||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | # Write the labels- and the index-file. | ||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | 0 | my $labels = $self->labels; | |||||||||||||||||||||||||||
| 427 | 0 | ▶ | $labels->write(@messages) if $labels; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | 0 | my $index = $self->index; | |||||||||||||||||||||||||||
| 430 | 0 | ▶ | $index->write(@messages) if $index; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | 0 | $locker->unlock; | |||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | # Remove an empty folder. This is done last, because the code before | ||||||||||||||||||||||||||||
| 435 | # in this method will have cleared the contents of the directory. | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | 0 | ▶ | if(!@messages && $self->{MB_remove_empty}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not @messages and $self->{"MB_remove_empty"}
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"}
| |||||||||||||||||||||||||||||
| 438 | { # If something is still in the directory, this will fail, but I | ||||||||||||||||||||||||||||
| 439 | # don't mind. | ||||||||||||||||||||||||||||
| 440 | 0 | rmdir $directory; | |||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | 0 | $self; | |||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | 9 | 1; | |||||||||||||||||||||||||||