| 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::Message; | ||||||||||||||||||||||||||||
| 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::Message'; | ||||||||||||||||||||||||||
|
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 | |||||||||||||||||||||||||||||
| 18 | 12 | ▶ | use File::Copy qw/move/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 12 | ▶ | use IO::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | sub init($) | ||||||||||||||||||||||||||||
| 23 | 0 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 0 | $self->SUPER::init($args); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | $self->filename($args->{filename}) | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if $args->{filename}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | $self->{MBDM_fix_header} = $args->{fix_header}; | |||||||||||||||||||||||||||
| 30 | 0 | $self; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | sub print(;$) | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
print: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | my $out = shift || select; | ||||||||||||||||||||||||||
|
Condition0%0/3
shift() || select()
MC/DC0%0/2
shift() || select()
shift()
select()
Truth table0%0/3
A || B
A= shift()B= select()
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | return $self->SUPER::print($out) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | if $self->isModified; | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | my $filename = $self->filename; | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | if($filename && -r $filename) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$filename and -r $filename
MC/DC0%0/2
$filename and -r $filename
$filename
-r $filename
Truth table0%0/3
A and B
A= $filenameB= -r $filename
| |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | { if(open my $in, '<:raw', $filename) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | { local $_; | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | print $out $_ while <$in>; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | close $in; | |||||||||||||||||||||||||||
| 51 | 0 | return $self; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | $self->SUPER::print($out); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | 1; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 12 | ▶ | BEGIN { *write = \&print } # simply alias | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | sub filename(;$) | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
filename: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | @_ ? ($self->{MBDM_filename} = shift) : $self->{MBDM_filename}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # Asking the filesystem for the size is faster counting (in | ||||||||||||||||||||||||||||
| 76 | # many situations. It even may be lazy. | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | sub size() | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
size: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | unless($self->isModified) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | { my $filename = $self->filename; | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | if(defined $filename) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | { my $size = -s $filename; | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | return $size if defined $size; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | $self->SUPER::size; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | sub diskDelete() | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
diskDelete: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | 0 | $self->SUPER::diskDelete; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | my $filename = $self->filename; | |||||||||||||||||||||||||||
| 99 | 0 | ▶ | unlink $filename if $filename; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | $self; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | sub parser() | ||||||||||||||||||||||||||||
| 107 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
parser: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | my $parser = Mail::Box::Parser->new | ||||||||||||||||||||||||||||
| 110 | ( filename => $self->{MBDM_filename} | ||||||||||||||||||||||||||||
| 111 | , mode => 'r' | ||||||||||||||||||||||||||||
| 112 | , fix_header_errors => $self->{MBDM_fix_header} | ||||||||||||||||||||||||||||
| 113 | 0 | , $self->logSettings | |||||||||||||||||||||||||||
| 114 | ); | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | unless($parser) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | { $self->log(ERROR => "Cannot create parser for $self->{MBDM_filename}."); | |||||||||||||||||||||||||||
| 118 | 0 | return; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | $parser; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | sub loadHead() | ||||||||||||||||||||||||||||
| 128 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
loadHead: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 129 | 0 | my $head = $self->head; | |||||||||||||||||||||||||||
| 130 | 0 | ▶ | return $head unless $head->isDelayed; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | my $folder = $self->folder; | |||||||||||||||||||||||||||
| 133 | 0 | $folder->lazyPermitted(1); | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | my $parser = $self->parser or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 0 | $self->readFromParser($parser); | |||||||||||||||||||||||||||
| 137 | 0 | $parser->stop; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | $folder->lazyPermitted(0); | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | $self->log(PROGRESS => 'Loaded delayed head.'); | |||||||||||||||||||||||||||
| 142 | 0 | $self->head; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | sub loadBody() | ||||||||||||||||||||||||||||
| 149 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
loadBody: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | my $body = $self->body; | |||||||||||||||||||||||||||
| 152 | 0 | ▶ | return $body unless $body->isDelayed; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | my $head = $self->head; | |||||||||||||||||||||||||||
| 155 | 0 | ▶ | my $parser = $self->parser or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | ▶ | if($head->isDelayed) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 0 | { $head = $self->readHead($parser); | |||||||||||||||||||||||||||
| 159 | 0 | ▶ | if(defined $head) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | 0 | { $self->log(PROGRESS => 'Loaded delayed head.'); | |||||||||||||||||||||||||||
| 161 | 0 | $self->head($head); | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | else | ||||||||||||||||||||||||||||
| 164 | 0 | { $self->log(ERROR => 'Unable to read delayed head.'); | |||||||||||||||||||||||||||
| 165 | 0 | return; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | else | ||||||||||||||||||||||||||||
| 169 | 0 | { my ($begin, $end) = $body->fileLocation; | |||||||||||||||||||||||||||
| 170 | 0 | $parser->filePosition($begin); | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 0 | my $newbody = $self->readBody($parser, $head); | |||||||||||||||||||||||||||
| 174 | 0 | $parser->stop; | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | ▶ | unless(defined $newbody) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 0 | { $self->log(ERROR => 'Unable to read delayed body.'); | |||||||||||||||||||||||||||
| 178 | 0 | return; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 0 | $self->log(PROGRESS => 'Loaded delayed body.'); | |||||||||||||||||||||||||||
| 182 | 0 | $self->storeBody($newbody->contentInfoFrom($head)); | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | sub create($) | ||||||||||||||||||||||||||||
| 189 | 0 | ▶ | { my ($self, $filename) = @_; | ||||||||||||||||||||||||||
|
Subroutine
create: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | ▶ | my $old = $self->filename || ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->filename || ''
MC/DC0%0/1
$self->filename || ''
$self->filename
Truth table0%0/2
A
A= $self->filename
| |||||||||||||||||||||||||||||
| 192 | 0 | ▶ | return $self if $filename eq $old && !$self->isModified; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$filename eq $old and not $self->isModified
MC/DC0%0/2
$filename eq $old and not $self->isModified
$filename eq $old
not $self->isModified
Truth table0%0/3
A and not(B)
A= $filename eq $oldB= not $self->isModified
| |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | # Write the new data to a new file. | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 0 | my $new = $filename . '.new'; | |||||||||||||||||||||||||||
| 197 | 0 | my $newfile = IO::File->new($new, 'w'); | |||||||||||||||||||||||||||
| 198 | 0 | ▶ | $self->log(ERROR => "Cannot write message to $new: $!"), return | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | unless $newfile; | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | $self->write($newfile); | |||||||||||||||||||||||||||
| 202 | 0 | $newfile->close; | |||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | # Accept the new data | ||||||||||||||||||||||||||||
| 205 | # maildir produces warning where not expected... | ||||||||||||||||||||||||||||
| 206 | # $self->log(WARNING => "Failed to remove $old: $!") | ||||||||||||||||||||||||||||
| 207 | # if $old && !unlink $old; | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 0 | ▶ | unlink $old if $old; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | ▶ | $self->log(ERROR => "Failed to move $new to $filename: $!"), return | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | unless move($new, $filename); | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 0 | $self->modified(0); | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | # Do not affect flags for Maildir (and some other) which keep it | ||||||||||||||||||||||||||||
| 217 | # in there. Flags will be processed later. | ||||||||||||||||||||||||||||
| 218 | 0 | $self->Mail::Box::Dir::Message::filename($filename); | |||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 0 | $self; | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 12 | 1; | |||||||||||||||||||||||||||