| 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::Labels;{ | ||||||||||||||||||||||||||||
| 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 fault 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 | #-------------------- | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub init($) | ||||||||||||||||||||||||||||
| 30 | 21 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 21 | $self->SUPER::init($args); | |||||||||||||||||||||||||||
| 32 | 21 | ▶ | $self->{MBML_filename} = $args->{filename} or error __x"MH labels require a filename."; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 21 | $self; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | #-------------------- | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 29 | ▶ | sub filename() { $_[0]->{MBML_filename} } | ||||||||||||||||||||||||||
|
Subroutine
filename: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | #-------------------- | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | sub get($) | ||||||||||||||||||||||||||||
| 43 | 434 | ▶ | { my ($self, $msgnr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 434 | $self->{MBML_labels}[$msgnr]; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | sub read() | ||||||||||||||||||||||||||||
| 49 | 17 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
read: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 17 | my $seqfn = $self->filename; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 17 | ▶ | open my $seq, '<:raw', $seqfn | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | or return; | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 9 | my @labels; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 9 | local $_; | |||||||||||||||||||||||||||
| 58 | 9 | ▶ | while(<$seq>) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 16 | { s/\s*\#.*$//; | |||||||||||||||||||||||||||
| 60 | 16 | ▶ | length or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 16 | ▶ | s/^\s*(\w+)\s*\:\s*// or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 16 | my $label = $1; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 16 | my $set = 1; | |||||||||||||||||||||||||||
| 66 | 16 | ▶ | if($label eq 'cur' ) { $label = 'current' } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 67 | 2 | elsif($label eq 'unseen') { $label = 'seen'; $set = 0 } | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 16 | foreach (split /\s+/) | |||||||||||||||||||||||||||
| 70 | 32 | ▶ | { if( /^(\d+)\-(\d+)\s*$/ ) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 71 | 10 | { push @{$labels[$_]}, $label, $set foreach $1..$2; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | elsif( /^\d+\s*$/ ) | ||||||||||||||||||||||||||||
| 74 | 22 | { push @{$labels[$_]}, $label, $set; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | 9 | $seq->close; | |||||||||||||||||||||||||||
| 79 | 9 | $self->{MBML_labels} = \@labels; | |||||||||||||||||||||||||||
| 80 | 9 | $self; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub write(@) | ||||||||||||||||||||||||||||
| 85 | 11 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
write: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 11 | my $filename = $self->filename; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # Remove when no messages are left. | ||||||||||||||||||||||||||||
| 89 | 11 | ▶ | unless(@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | { unlink $filename; | |||||||||||||||||||||||||||
| 91 | 0 | return $self; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 11 | ▶ | open my $out, '>:raw', $filename | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | or fault __x"cannot write MH labels file to {file}", file => $filename; | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 11 | $self->print($out, @_); | |||||||||||||||||||||||||||
| 98 | 11 | ▶ | close $out | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | or fault __x"error while closing MH labels file {file} after write", file => $filename; | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 11 | $self; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | sub append(@) | ||||||||||||||||||||||||||||
| 106 | 1 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
append: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | 1 | my $filename = $self->filename; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 1 | ▶ | open my $out, '>>:raw', $filename | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | or fault __x"cannot append to MH labels file {file}", file => $filename; | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 1 | $self->print($out, @_); | |||||||||||||||||||||||||||
| 113 | 1 | ▶ | close $out | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | or fault __x"error while closing MH labels file {file} after append", file => $filename; | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 1 | $self; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | sub print($@) | ||||||||||||||||||||||||||||
| 121 | 12 | ▶ | { my ($self, $out) = (shift, shift); | ||||||||||||||||||||||||||
|
Subroutine
print: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | # Collect the labels from the selected messages. | ||||||||||||||||||||||||||||
| 124 | 12 | my %labeled; | |||||||||||||||||||||||||||
| 125 | 12 | foreach my $message (@_) | |||||||||||||||||||||||||||
| 126 | 310 | { my $labels = $message->labels; | |||||||||||||||||||||||||||
| 127 | 310 | my $seq = $message->filename =~ s!.*/!!r; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 10 | push @{$labeled{unseen}}, $seq | |||||||||||||||||||||||||||
| 130 | 310 | ▶ | unless $labels->{seen}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 310 | foreach (keys %$labels) | |||||||||||||||||||||||||||
| 133 | 351 | { push @{$labeled{$_}}, $seq | |||||||||||||||||||||||||||
| 134 | 369 | ▶ | if $labels->{$_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | 12 | delete $labeled{seen}; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | # Write it out | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 12 | local $" = ' '; | |||||||||||||||||||||||||||
| 142 | 12 | foreach (sort keys %labeled) | |||||||||||||||||||||||||||
| 143 | { | ||||||||||||||||||||||||||||
| 144 | 12 | my @msgs = @{$labeled{$_}}; #they are ordered already. | |||||||||||||||||||||||||||
| 145 | 12 | ▶ | $_ = 'cur' if $_ eq 'current'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 12 | print $out "$_:"; | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 12 | ▶ | while(@msgs) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 21 | { my $start = shift @msgs; | |||||||||||||||||||||||||||
| 150 | 21 | my $end = $start; | |||||||||||||||||||||||||||
| 151 | 21 | ▶ | $end = shift @msgs while @msgs && $msgs[0]==$end+1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@msgs and $msgs[0] == $end + 1
MC/DC100%2/2
@msgs and $msgs[0] == $end + 1
@msgs
$msgs[0] == $end + 1
Truth table100%3/3
A and B
A= @msgsB= $msgs[0] == $end + 1
| |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 21 | ▶ | print $out ($start==$end ? " $start" : " $start-$end"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | 12 | print $out "\n"; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 12 | $self; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 11 | 1; | |||||||||||||||||||||||||||