Box/MH/Index.pm

filter: Statementstmt 90.1% 64 / 71 Branchbran 41.6% 10 / 24 Conditioncond 33.3% 6 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 100% 11 / 11 Podpod 83.3% 5 / 6 totaltotal 68.0% 96 / 141 CC 22 SCAR 20.5
CC
22
Cov
71%
read
15.9
write
9.2
append
6.6
CRAP 7.8
« Box/Locker/DotLock.pm ↑ Summary Box/Collection.pm »
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
BranchTrueFalseTotal
$self->{"MBMI_filename"} = $args->{"filename"} or &error(&__x("MH index requires a filename.")) 4 0 4
33  
34 4 ▶ $self->{MBMI_head_wrap} = $args->{head_wrap} || 72;
Condition50%1/2
$args->{'head_wrap'} || 72
l!l
04
MC/DC0%0/1
$args->{'head_wrap'} || 72
$args->{'head_wrap'}
Truth table50%1/2
A
A= $args->{'head_wrap'}
Aresult
11
00
35 4 ▶ $self->{MBMI_head_type} = $args->{head_type} || 'Mail::Message::Head::Subset';
Condition50%1/2
$args->{'head_type'} || 'Mail::Message::Head::Subset'
l!l
04
MC/DC0%0/1
$args->{'head_type'} || 'Mail::Message::Head::Subset'
$args->{'head_type'}
Truth table50%1/2
A
A= $args->{'head_type'}
Aresult
11
00
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)
l!l
50
MC/DC0%0/1
$self->filename // (return $self)
$self->filename
Truth table50%1/2
A
A= $self->filename
Aresult
11
00
48  
49 # Remove empty index-file.
50 5 ▶ unless(@messages)
Branch: 1 branch
BranchTrueFalseTotal
unless (@messages) 0 5 5
51 0 { unlink $indexfn;
52 0 return $self;
53 }
54  
55 5 ▶ open my $index, '>:raw', $indexfn
Branch: 1 branch
BranchTrueFalseTotal
open my $index, ">:raw", $indexfn or return $self 5 0 5
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
BranchTrueFalseTotal
if $head->isDelayed and $head->isa("Mail::Message::Head::Subset") 0 178 178
Condition66%2/3
$head->isDelayed and $head->isa("Mail::Message::Head::Subset")
!ll&&!rl&&r
133450
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")
ABresult
0X0
100
111
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
BranchTrueFalseTotal
$written or unlink $indexfn 5 0 5
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
BranchTrueFalseTotal
my $indexfn = $self->filename or return $self 1 0 1
83  
84 1 ▶ open my $index, '>>:raw', $indexfn
Branch: 1 branch
BranchTrueFalseTotal
open my $index, ">>:raw", $indexfn or return $self 1 0 1
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
BranchTrueFalseTotal
if $head->isDelayed and $head->isa("Mail::Message::Head::Subset") 0 1 1
Condition33%1/3
$head->isDelayed and $head->isa("Mail::Message::Head::Subset")
!ll&&!rl&&r
100
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")
ABresult
0X0
100
111
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
BranchTrueFalseTotal
my $parser = "Mail::Box::Parser"->new("filename", $filename, "mode", "r") or return 4 0 4
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
BranchTrueFalseTotal
if (my $head = $type->new(@options)->read($parser)) 0 4 4
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
BranchTrueFalseTotal
unless -f $msgfile and -s _ == $size 0 0 0
Condition0%0/3
-f $msgfile and -s _ == $size
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
119 0 ▶ next if defined $index_age && -M _ < $index_age;
Branch: 1 branch
BranchTrueFalseTotal
if defined $index_age and -M _ < $index_age 0 0 0
Condition0%0/3
defined $index_age and -M _ < $index_age
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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;
« Box/Locker/DotLock.pm ↑ Summary Box/Collection.pm »