| 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::Index; | ||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 9 | $VERSION = '3.009'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 9 | ▶ | use base 'Mail::Reporter'; | ||||||||||||||||||||||||||
|
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 | |||||||||||||||||||||||||||||
| 18 | 9 | ▶ | use Mail::Message::Head::Subset; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 9 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | sub init($) | ||||||||||||||||||||||||||||
| 26 | 0 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 27 | 0 | $self->SUPER::init($args); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | $self->{MBMI_filename} = $args->{filename} | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | or croak "No index filename specified."; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | $self->{MBMI_head_wrap} = $args->{head_wrap} || 72; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'head_wrap'} || 72
MC/DC0%0/1
$args->{'head_wrap'} || 72
$args->{'head_wrap'}
Truth table0%0/2
A
A= $args->{'head_wrap'}
| |||||||||||||||||||||||||||||
| 33 | $self->{MBMI_head_type} | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | = $args->{head_type} || 'Mail::Message::Head::Subset'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'head_type'} || 'Mail::Message::Head::Subset'
MC/DC0%0/1
$args->{'head_type'} || 'Mail::Message::Head::Subset'
$args->{'head_type'}
Truth table0%0/2
A
A= $args->{'head_type'}
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | $self; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub filename() {shift->{MBMI_filename}} | ||||||||||||||||||||||||||
|
Subroutine
filename: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | sub write(@) | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
write: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | my $index = $self->filename or return $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # Remove empty index-file. | ||||||||||||||||||||||||||||
| 52 | 0 | ▶ | unless(@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | { unlink $index; | |||||||||||||||||||||||||||
| 54 | 0 | return $self; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | local *INDEX; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | open INDEX, '>:raw', $index | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | or return $self; | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | my $fieldtype = 'Mail::Message::Field'; | |||||||||||||||||||||||||||
| 62 | 0 | my $written = 0; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | foreach my $msg (@_) | |||||||||||||||||||||||||||
| 65 | 0 | { my $head = $msg->head; | |||||||||||||||||||||||||||
| 66 | 0 | ▶ | next if $head->isDelayed && $head->isa('Mail::Message::Head::Subset'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$head->isDelayed and $head->isa("Mail::Message::Head::Subset")
MC/DC0%0/2
$head->isDelayed and $head->isa("Mail::Message::Head::Subset")
$head->isDelayed
$head->isa("Mail::Message::Head::Subset")
Truth table0%0/3
A and B
A= $head->isDelayedB= $head->isa("Mail::Message::Head::Subset")
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | my $filename = $msg->filename; | |||||||||||||||||||||||||||
| 69 | 0 | print INDEX "X-MailBox-Filename: $filename\n" | |||||||||||||||||||||||||||
| 70 | , 'X-MailBox-Size: ', (-s $filename), "\n"; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | $head->print(\*INDEX); | |||||||||||||||||||||||||||
| 73 | 0 | $written++; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | close INDEX; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $written or unlink $index; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | $self; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | sub append(@) | ||||||||||||||||||||||||||||
| 87 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
append: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | my $index = $self->filename or return $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | local *INDEX; | |||||||||||||||||||||||||||
| 91 | 0 | ▶ | open INDEX, '>>:raw', $index | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | or return $self; | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | my $fieldtype = 'Mail::Message::Field'; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | foreach my $msg (@_) | |||||||||||||||||||||||||||
| 97 | 0 | { my $head = $msg->head; | |||||||||||||||||||||||||||
| 98 | 0 | ▶ | next if $head->isDelayed && $head->isa('Mail::Message::Head::Subset'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$head->isDelayed and $head->isa("Mail::Message::Head::Subset")
MC/DC0%0/2
$head->isDelayed and $head->isa("Mail::Message::Head::Subset")
$head->isDelayed
$head->isa("Mail::Message::Head::Subset")
Truth table0%0/3
A and B
A= $head->isDelayedB= $head->isa("Mail::Message::Head::Subset")
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | my $filename = $msg->filename; | |||||||||||||||||||||||||||
| 101 | 0 | print INDEX "X-MailBox-Filename: $filename\n" | |||||||||||||||||||||||||||
| 102 | , 'X-MailBox-Size: ', (-s $filename), "\n"; | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | $head->print(\*INDEX); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | close INDEX; | |||||||||||||||||||||||||||
| 108 | 0 | $self; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | sub read(;$) | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
read: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 116 | 0 | my $filename = $self->{MBMI_filename}; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | my $parser = Mail::Box::Parser->new | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | ( filename => $filename | ||||||||||||||||||||||||||||
| 120 | , mode => 'r' | ||||||||||||||||||||||||||||
| 121 | ) or return; | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | my @options = ($self->logSettings, wrap_length => $self->{MBMI_head_wrap}); | |||||||||||||||||||||||||||
| 124 | 0 | my $type = $self->{MBMI_head_type}; | |||||||||||||||||||||||||||
| 125 | 0 | my $index_age= -M $filename; | |||||||||||||||||||||||||||
| 126 | 0 | my %index; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | while(my $head = $type->new(@options)->read($parser)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | { | ||||||||||||||||||||||||||||
| 130 | # cleanup the index from files which were renamed | ||||||||||||||||||||||||||||
| 131 | 0 | my $msgfile = $head->get('x-mailbox-filename'); | |||||||||||||||||||||||||||
| 132 | 0 | my $size = int $head->get('x-mailbox-size'); | |||||||||||||||||||||||||||
| 133 | 0 | ▶ | next unless -f $msgfile && -s _ == $size; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $msgfile and -s _ == $size
MC/DC0%0/2
-f $msgfile and -s _ == $size
-f $msgfile
-s _ == $size
Truth table0%0/3
A and B
A= -f $msgfileB= -s _ == $size
| |||||||||||||||||||||||||||||
| 134 | 0 | ▶ | next if defined $index_age && -M _ < $index_age; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $index_age and -M _ < $index_age
MC/DC0%0/2
defined $index_age and -M _ < $index_age
defined $index_age
-M _ < $index_age
Truth table0%0/3
A and B
A= defined $index_ageB= -M _ < $index_age
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | # keep this one | ||||||||||||||||||||||||||||
| 137 | 0 | $index{$msgfile} = $head; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | $parser->stop; | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | $self->{MBMI_index} = \%index; | |||||||||||||||||||||||||||
| 143 | 0 | $self; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | sub get($) | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | { my ($self, $msgfile) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 151 | 0 | $self->{MBMI_index}{$msgfile}; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 9 | 1; | |||||||||||||||||||||||||||