| 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::Dir; | ||||||||||||||||||||||||||||||||||||||||||
| 10 | 12 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 12 | $VERSION = '3.009'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 12 | ▶ | use base 'Mail::Box'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 12 | ▶ | use filetest 'access'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 12 | ▶ | use Mail::Box::Dir::Message; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 12 | ▶ | use Mail::Message::Body::Lines; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 12 | ▶ | use Mail::Message::Body::File; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 12 | ▶ | use Mail::Message::Body::Delayed; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 12 | ▶ | use Mail::Message::Body::Multipart; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 12 | ▶ | use Mail::Message::Head; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 12 | ▶ | use Mail::Message::Head::Delayed; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 12 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 12 | ▶ | use File::Copy; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 12 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 12 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | sub init($) | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 9 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=13 SCAR=49.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 9 | ▶ | $args->{body_type} ||= sub {'Mail::Message::Body::Lines'}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.0
Condition33%1/3
$args->{"body_type"} ||= sub {
"Mail::Message::Body::Lines";
}
MC/DC0%0/2
$args->{"body_type"} ||= sub {
"Mail::Message::Body::Lines";
}
$args->{"body_type"}
sub {
"Mail::Message::Body::Lines";
}
Truth table33%1/3
A ||= B
A= $args->{"body_type"}B= sub {
"Mail::Message::Body::Lines";
}
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | return undef | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 9 | ▶ | unless $self->SUPER::init($args); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $class = ref $self; | |||||||||||||||||||||||||||||||||||||||||
| 44 | my $directory = $self->{MBD_directory} | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | = $args->{directory} || $self->directory; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$args->{'directory'} || $self->directory
MC/DC0%0/2
$args->{'directory'} || $self->directory
$args->{'directory'}
$self->directory
Truth table0%0/3
A || B
A= $args->{'directory'}B= $self->directory
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if(-d $directory) {;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | ▶ | elsif($args->{create} && $class->create($directory, %$args)) {;} | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$args->{"create"} and $class->create($directory, %$args)
MC/DC0%0/2
$args->{"create"} and $class->create($directory, %$args)
$args->{"create"}
$class->create($directory, %$args)
Truth table0%0/3
A and B
A= $args->{"create"}B= $class->create($directory, %$args)
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | else | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | { $self->log(NOTICE => "No directory $directory for folder of $class"); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | # About locking | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | for($args->{lock_file}) | |||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | { $self->locker->filename | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | ( !defined $_ ? File::Spec->catfile($directory, '.lock') # default | ||||||||||||||||||||||||||||||||||||||||||
| 59 | : File::Spec->file_name_is_absolute($_) ? $_ # absolute | ||||||||||||||||||||||||||||||||||||||||||
| 60 | : File::Spec->catfile($directory, $_) # relative | ||||||||||||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | # Check if we can write to the folder, if we need to. | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if($self->writable && -e $directory && ! -w $directory) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->writable and -e $directory and not -w $directory
$self->writable and -e $directory
MC/DC0%0/3
$self->writable and -e $directory and not -w $directory
$self->writable
-e $directory
not -w $directory
Truth table0%0/4
A and B and not(C)
A= $self->writableB= -e $directoryC= not -w $directory
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | { $self->log(WARNING=> "Folder directory $directory is write-protected."); | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $self->{MB_access} = 'r'; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | #------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | sub organization() { 'DIRECTORY' } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | #------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | sub directory() | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
directory: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | $self->{MBD_directory} | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | ||= $self->folderToDirectory($self->name, $self->folderdir); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"MBD_directory"} ||= $self->folderToDirectory($self->name, $self->folderdir)
MC/DC0%0/2
$self->{"MBD_directory"} ||= $self->folderToDirectory($self->name, $self->folderdir)
$self->{"MBD_directory"}
$self->folderToDirectory($self->name, $self->folderdir)
Truth table0%0/3
A ||= B
A= $self->{"MBD_directory"}B= $self->folderToDirectory($self->name, $self->folderdir)
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | #------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | sub nameOfSubFolder($;$) | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 52 | ▶ | { my ($thing, $name) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nameOfSubFolder: called CC=4 SCAR=16.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 52 | ▶ | my $parent = @_ ? shift : ref $thing ? $thing->directory : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 52 | ▶ | defined $parent ? "$parent/$name" : $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | #------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | sub folderToDirectory($$) | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 30 | ▶ | { my ($class, $name, $folderdir) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
folderToDirectory: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 30 | ▶ | my $dir = ( $name =~ m#^=\/?(.*)# ? "$folderdir/$1" : $name); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 30 | $dir =~ s!/$!!; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 30 | $dir; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | sub storeMessage($) | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | { my ($self, $message) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
storeMessage: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $self->SUPER::storeMessage($message); | |||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | my $fn = $message->filename or return $message; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $self->{MBD_by_fn}{$fn} = $message; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub messageInFile($) { $_[0]->{MBD_by_fn}{$_[1]} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
messageInFile: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub readMessageFilenames() {shift->notImplemented} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readMessageFilenames: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | #------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||