| 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::Dir::Message;{ | ||||||||||||||||||||||||||||
| 13 | 14 | our $VERSION = '4.02'; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 14 | ▶ | use parent 'Mail::Box::Message'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 14 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 14 | ▶ | use Log::Report 'mail-box', import => [ qw/__x error fault trace/ ]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 14 | ▶ | use File::Copy qw/move/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | #-------------------- | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub init($) | ||||||||||||||||||||||||||||
| 28 | 737 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 737 | $self->SUPER::init($args); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 737 | ▶ | $self->filename($args->{filename}) if $args->{filename}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 737 | $self->{MBDM_fix_header} = $args->{fix_header}; | |||||||||||||||||||||||||||
| 33 | 737 | $self; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | #-------------------- | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | sub filename(;$) | ||||||||||||||||||||||||||||
| 39 | 4095 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
filename: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 4095 | ▶ | @_ ? ($self->{MBDM_filename} = shift) : $self->{MBDM_filename}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 289 | ▶ | sub fixHeader() { $_[0]->{MBDM_fix_header} } | ||||||||||||||||||||||||||
|
Subroutine
fixHeader: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | #-------------------- | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | sub print(;$) | ||||||||||||||||||||||||||||
| 49 | 226 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
print: called CC=7 SCAR=21.3
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 226 | ▶ | my $out = shift || select; | ||||||||||||||||||||||||||
|
Condition33%1/3
shift() || select()
MC/DC0%0/2
shift() || select()
shift()
select()
Truth table33%1/3
A || B
A= shift()B= select()
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 226 | ▶ | return $self->SUPER::print($out) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | if $self->isModified; | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 181 | my $filename = $self->filename; | |||||||||||||||||||||||||||
| 56 | 181 | ▶ | if($filename && -r $filename) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$filename and -r $filename
MC/DC0%0/2
$filename and -r $filename
$filename
-r $filename
Truth table33%1/3
A and B
A= $filenameB= -r $filename
| |||||||||||||||||||||||||||||
| 57 | 181 | ▶ | { if(open my $in, '<:raw', $filename) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 181 | { local $_; | |||||||||||||||||||||||||||
| 59 | 181 | ▶ | print $out $_ while <$in>; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 181 | close $in; | |||||||||||||||||||||||||||
| 61 | 181 | return $self; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | $self->SUPER::print($out); | |||||||||||||||||||||||||||
| 66 | 0 | 1; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 14 | ▶ | BEGIN { *write = \&print } # simply alias | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | #-------------------- | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # Asking the filesystem for the size is faster counting (in | ||||||||||||||||||||||||||||
| 74 | # many situations. It even may be lazy. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | sub size() | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
size: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | unless($self->isModified) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | { my $filename = $self->filename; | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | if(defined $filename) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | { my $size = -s $filename; | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | return $size if defined $size; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | $self->SUPER::size; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | sub diskDelete() | ||||||||||||||||||||||||||||
| 91 | 24 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
diskDelete: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 24 | $self->SUPER::diskDelete; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 24 | my $filename = $self->filename; | |||||||||||||||||||||||||||
| 95 | 24 | ▶ | unlink $filename if $filename; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 24 | $self; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | sub parser() | ||||||||||||||||||||||||||||
| 101 | 289 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
parser: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 289 | Mail::Box::Parser->new( | |||||||||||||||||||||||||||
| 104 | filename => $self->filename, | ||||||||||||||||||||||||||||
| 105 | mode => 'r', | ||||||||||||||||||||||||||||
| 106 | fix_header_errors => $self->fixHeader, | ||||||||||||||||||||||||||||
| 107 | ); | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | sub loadHead() | ||||||||||||||||||||||||||||
| 112 | 408 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
loadHead: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 408 | my $head = $self->head; | |||||||||||||||||||||||||||
| 114 | 408 | ▶ | $head->isDelayed or return $head; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 281 | my $folder = $self->folder; | |||||||||||||||||||||||||||
| 117 | 281 | $folder->lazyPermitted(1); | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 281 | ▶ | my $parser = $self->parser or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 281 | $self->readFromParser($parser); | |||||||||||||||||||||||||||
| 121 | 281 | $parser->stop; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 281 | $folder->lazyPermitted(0); | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 281 | trace "Loaded delayed head."; | |||||||||||||||||||||||||||
| 126 | 281 | $self->head; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | sub loadBody() | ||||||||||||||||||||||||||||
| 131 | 150 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
loadBody: called CC=5 SCAR=17.3
Pod
documented
| |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 150 | my $body = $self->body; | |||||||||||||||||||||||||||
| 134 | 150 | ▶ | $body->isDelayed or return $body; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 8 | my $parser = $self->parser; | |||||||||||||||||||||||||||
| 137 | 8 | my $msgid = $self->messageId; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 8 | my $head = $self->head; | |||||||||||||||||||||||||||
| 140 | 8 | ▶ | if($head->isDelayed) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | { $head = $self->readHead($parser) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | or error __x"unable to read delayed head for message {msgid}.", msgid => $msgid; | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | trace "Loaded delayed head for $msgid."; | |||||||||||||||||||||||||||
| 145 | 0 | $self->head($head); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | else | ||||||||||||||||||||||||||||
| 148 | 8 | { my ($begin, $end) = $body->fileLocation; | |||||||||||||||||||||||||||
| 149 | 8 | $parser->filePosition($begin); | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 8 | ▶ | my $newbody = $self->readBody($parser, $head) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | or error __x"unable to read delayed body for message {msgid}.", msgid => $msgid; | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 8 | $parser->stop; | |||||||||||||||||||||||||||
| 156 | 8 | trace "Loaded delayed body for $msgid"; | |||||||||||||||||||||||||||
| 157 | 8 | $self->storeBody($newbody->contentInfoFrom($head)); | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | sub create($) | ||||||||||||||||||||||||||||
| 162 | 316 | ▶ | { my ($self, $filename) = @_; | ||||||||||||||||||||||||||
|
Subroutine
create: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 316 | ▶ | my $old = $self->filename || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->filename || ''
MC/DC100%1/1
$self->filename || ''
$self->filename
Truth table100%2/2
A
A= $self->filename
| |||||||||||||||||||||||||||||
| 165 | 316 | ▶ | return $self if $filename eq $old && !$self->isModified; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$filename eq $old and not $self->isModified
MC/DC50%1/2
$filename eq $old and not $self->isModified
$filename eq $old
not $self->isModified
Truth table66%2/3
A and not(B)
A= $filename eq $oldB= not $self->isModified
| |||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | # Write the new data to a new file. | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 225 | my $new = $filename . '.new'; | |||||||||||||||||||||||||||
| 170 | 225 | ▶ | open my $newfh, '>:raw', $new | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | or fault __x"cannot write message to {file}", file => $new; | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 225 | $self->write($newfh); | |||||||||||||||||||||||||||
| 174 | 225 | $newfh->close; | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 225 | ▶ | unlink $old if $old; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 225 | ▶ | move $new, $filename | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | or error __x"failed to rename file {from} to {to}", from => $new, to => $filename; | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 225 | $self->modified(0); | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | # Do not affect flags for Maildir (and some other) which keep it | ||||||||||||||||||||||||||||
| 184 | # in there. Flags will be processed later. | ||||||||||||||||||||||||||||
| 185 | 225 | $self->Mail::Box::Dir::Message::filename($filename); | |||||||||||||||||||||||||||
| 186 | 225 | $self; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 14 | 1; | |||||||||||||||||||||||||||