| 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::MH::Index;{ | ||||||||||||||||||||||||||||
| 13 | 11 | our $VERSION = '4.02'; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 11 | ▶ | use parent 'Mail::Reporter'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 11 | ▶ | use Log::Report 'mail-box', import => [ qw/__x error info/ ]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 11 | ▶ | use Mail::Message::Head::Subset (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | #-------------------- | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub init($) | ||||||||||||||||||||||||||||
| 28 | 4 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 4 | $self->SUPER::init($args); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | $self->{MBMI_filename} = $args->{filename} | ||||||||||||||||||||||||||||
| 32 | 4 | ▶ | or error __x"MH index requires a filename."; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 4 | ▶ | $self->{MBMI_head_wrap} = $args->{head_wrap} || 72; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'head_wrap'} || 72
MC/DC0%0/1
$args->{'head_wrap'} || 72
$args->{'head_wrap'}
Truth table50%1/2
A
A= $args->{'head_wrap'}
| |||||||||||||||||||||||||||||
| 35 | 4 | ▶ | $self->{MBMI_head_type} = $args->{head_type} || 'Mail::Message::Head::Subset'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'head_type'} || 'Mail::Message::Head::Subset'
MC/DC0%0/1
$args->{'head_type'} || 'Mail::Message::Head::Subset'
$args->{'head_type'}
Truth table50%1/2
A
A= $args->{'head_type'}
| |||||||||||||||||||||||||||||
| 36 | 4 | $self; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | #-------------------- | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 10 | ▶ | sub filename() { $_[0]->{MBMI_filename} } | ||||||||||||||||||||||||||
|
Subroutine
filename: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | #-------------------- | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | sub write(@) | ||||||||||||||||||||||||||||
| 46 | 5 | ▶ | { my ($self, @messages) = @_; | ||||||||||||||||||||||||||
|
Subroutine
write: called CC=8 SCAR=22.2
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 5 | ▶ | my $indexfn = $self->filename // return $self; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->filename // (return $self)
MC/DC0%0/1
$self->filename // (return $self)
$self->filename
Truth table50%1/2
A
A= $self->filename
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # Remove empty index-file. | ||||||||||||||||||||||||||||
| 50 | 5 | ▶ | unless(@messages) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | { unlink $indexfn; | |||||||||||||||||||||||||||
| 52 | 0 | return $self; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 5 | ▶ | open my $index, '>:raw', $indexfn | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | or return $self; | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 5 | my $written = 0; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 5 | foreach my $msg (@messages) | |||||||||||||||||||||||||||
| 61 | 178 | { my $head = $msg->head; | |||||||||||||||||||||||||||
| 62 | 178 | ▶ | next if $head->isDelayed && $head->isa('Mail::Message::Head::Subset'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/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 table66%2/3
A and B
A= $head->isDelayedB= $head->isa("Mail::Message::Head::Subset")
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 178 | my $fn = $msg->filename; | |||||||||||||||||||||||||||
| 65 | 178 | $index->print( | |||||||||||||||||||||||||||
| 66 | "X-MailBox-Filename: $fn\n", | ||||||||||||||||||||||||||||
| 67 | 'X-MailBox-Size: ', (-s $fn), "\n", | ||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||
| 69 | 178 | $head->print($index); | |||||||||||||||||||||||||||
| 70 | 178 | $written++; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 5 | $index->close; | |||||||||||||||||||||||||||
| 74 | 5 | ▶ | $written or unlink $indexfn; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 5 | $self; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | sub append(@) | ||||||||||||||||||||||||||||
| 81 | 1 | ▶ | { my ($self, @messages) = @_; | ||||||||||||||||||||||||||
|
Subroutine
append: called CC=6 SCAR=18.8
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 1 | ▶ | my $indexfn = $self->filename or return $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 1 | ▶ | open my $index, '>>:raw', $indexfn | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | or return $self; | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 1 | foreach my $msg (@messages) | |||||||||||||||||||||||||||
| 88 | 1 | { my $head = $msg->head; | |||||||||||||||||||||||||||
| 89 | 1 | ▶ | next if $head->isDelayed && $head->isa('Mail::Message::Head::Subset'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/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 table33%1/3
A and B
A= $head->isDelayedB= $head->isa("Mail::Message::Head::Subset")
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 1 | my $fn = $msg->filename; | |||||||||||||||||||||||||||
| 92 | 1 | $index->print( | |||||||||||||||||||||||||||
| 93 | "X-MailBox-Filename: $fn\n", | ||||||||||||||||||||||||||||
| 94 | 'X-MailBox-Size: ', (-s $fn), "\n", | ||||||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||||||
| 96 | 1 | $head->print($index); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 1 | $index->close; | |||||||||||||||||||||||||||
| 99 | 1 | $self; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | sub read(;$) | ||||||||||||||||||||||||||||
| 104 | 4 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
read: called CC=7 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 4 | my $filename = $self->filename; | |||||||||||||||||||||||||||
| 106 | 4 | ▶ | my $parser = Mail::Box::Parser->new(filename => $filename, mode => 'r') or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 4 | my @options = (wrap_length => $self->{MBMI_head_wrap}); | |||||||||||||||||||||||||||
| 109 | 4 | my $type = $self->{MBMI_head_type}; | |||||||||||||||||||||||||||
| 110 | 4 | my $index_age = -M $filename; | |||||||||||||||||||||||||||
| 111 | 4 | my %index; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 4 | ▶ | while(my $head = $type->new(@options)->read($parser)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||
| 115 | # cleanup the index from files which were renamed | ||||||||||||||||||||||||||||
| 116 | 0 | my $msgfile = $head->get('x-mailbox-filename'); | |||||||||||||||||||||||||||
| 117 | 0 | my $size = int $head->get('x-mailbox-size'); | |||||||||||||||||||||||||||
| 118 | 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
| |||||||||||||||||||||||||||||
| 119 | 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
| |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | # keep this one | ||||||||||||||||||||||||||||
| 122 | 0 | $index{$msgfile} = $head; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 4 | $parser->stop; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 4 | $self->{MBMI_index} = \%index; | |||||||||||||||||||||||||||
| 128 | 4 | $self; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | sub get($) | ||||||||||||||||||||||||||||
| 133 | 94 | ▶ | { my ($self, $msgfile) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 134 | 94 | $self->{MBMI_index}{$msgfile}; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 11 | 1; | |||||||||||||||||||||||||||