| 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::Search::Grep; | ||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | $VERSION = '3.009'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use base 'Mail::Box::Search'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | sub init($) | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=16 SCAR=56.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | $args->{in} ||= ($args->{field} ? 'HEAD' : 'BODY'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args->{"in"} ||= $args->{"field"} ? "HEAD" : "BODY"
MC/DC0%0/2
$args->{"in"} ||= $args->{"field"} ? "HEAD" : "BODY"
$args->{"in"}
$args->{"field"} ? "HEAD" : "BODY"
Truth table0%0/3
A ||= B
A= $args->{"in"}B= $args->{"field"} ? "HEAD" : "BODY"
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | my $deliver = $args->{deliver} || $args->{details}; # details is old name | ||||||||||||||||||||||||||
|
Condition0%0/3
$args->{'deliver'} || $args->{'details'}
MC/DC0%0/2
$args->{'deliver'} || $args->{'details'}
$args->{'deliver'}
$args->{'details'}
Truth table0%0/3
A || B
A= $args->{'deliver'}B= $args->{'details'}
| |||||||||||||||||||||||||||||
| 29 | $args->{deliver} | ||||||||||||||||||||||||||||
| 30 | = !defined $deliver ? $deliver | ||||||||||||||||||||||||||||
| 31 | : ref $deliver eq 'CODE' ? $deliver | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | : $deliver eq 'PRINT' ? sub { $_[0]->printMatch($_[1]) } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | : ref $deliver eq 'ARRAY' ? sub { push @$deliver, $_[1] } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | : $deliver; | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | $self->SUPER::init($args); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | my $take = $args->{field}; | |||||||||||||||||||||||||||
| 39 | $self->{MBSG_field_check} | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | = !defined $take ? sub {1} | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | : !ref $take ? do {$take = lc $take; sub { $_[1] eq $take }} | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | : ref $take eq 'Regexp' ? sub { $_[1] =~ $take } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | : ref $take eq 'CODE' ? $take | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 44 | : croak "Illegal field selector $take."; | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | my $match = $args->{match} | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | or croak "No match pattern specified.\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | $self->{MBSG_match_check} | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | = !ref $match ? sub { index("$_[1]", $match) >= $[ } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | : ref $match eq 'Regexp' ? sub { "$_[1]" =~ $match } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | : ref $match eq 'CODE' ? $match | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 52 | : croak "Illegal match pattern $match."; | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | $self; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | sub search(@) | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | { my ($self, $object, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
search: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 0 | delete $self->{MBSG_last_printed}; | |||||||||||||||||||||||||||
| 60 | 0 | $self->SUPER::search($object, %args); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | sub inHead(@) | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | { my ($self, $part, $head, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
inHead: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | my @details = (message => $part->toplevel, part => $part); | |||||||||||||||||||||||||||
| 67 | my ($field_check, $match_check, $deliver) | ||||||||||||||||||||||||||||
| 68 | 0 | = @$self{ qw/MBSG_field_check MBSG_match_check MBS_deliver/ }; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | my $matched = 0; | |||||||||||||||||||||||||||
| 71 | LINES: | ||||||||||||||||||||||||||||
| 72 | 0 | foreach my $field ($head->orderedFields) | |||||||||||||||||||||||||||
| 73 | 0 | ▶ | { next unless $field_check->($head, $field->name) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
&$field_check($head, $field->name) and &$match_check($head, $field)
MC/DC0%0/2
&$field_check($head, $field->name) and &$match_check($head, $field)
&$field_check($head, $field->name)
&$match_check($head, $field)
Truth table0%0/3
A and B
A= &$field_check($head, $field->name)B= &$match_check($head, $field)
| |||||||||||||||||||||||||||||
| 74 | && $match_check->($head, $field); | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | $matched++; | |||||||||||||||||||||||||||
| 77 | 0 | ▶ | last LINES unless $deliver; # no deliver: only one match needed | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | $deliver->( {@details, field => $field} ); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | $matched; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub inBody(@) | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | { my ($self, $part, $body, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
inBody: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | my @details = (message => $part->toplevel, part => $part); | |||||||||||||||||||||||||||
| 88 | my ($field_check, $match_check, $deliver) | ||||||||||||||||||||||||||||
| 89 | 0 | = @$self{ qw/MBSG_field_check MBSG_match_check MBS_deliver/ }; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | my $matched = 0; | |||||||||||||||||||||||||||
| 92 | 0 | my $linenr = 0; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | LINES: | ||||||||||||||||||||||||||||
| 95 | 0 | foreach my $line ($body->lines) | |||||||||||||||||||||||||||
| 96 | 0 | { $linenr++; | |||||||||||||||||||||||||||
| 97 | 0 | ▶ | next unless $match_check->($body, $line); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | $matched++; | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | last LINES unless $deliver; # no deliver: only one match needed | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | $deliver->( {@details, linenr => $linenr, line => $line} ); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | $matched; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | sub printMatch($;$) | ||||||||||||||||||||||||||||
| 111 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
printMatch: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | my ($out, $match) = @_==2 ? @_ : (select, shift); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | $match->{field} | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | ? $self->printMatchedHead($out, $match) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | : $self->printMatchedBody($out, $match) | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | sub printMatchedHead($$) | ||||||||||||||||||||||||||||
| 121 | 0 | ▶ | { my ($self, $out, $match) = @_; | ||||||||||||||||||||||||||
|
Subroutine
printMatchedHead: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | 0 | my $message = $match->{message}; | |||||||||||||||||||||||||||
| 123 | 0 | my $msgnr = $message->seqnr; | |||||||||||||||||||||||||||
| 124 | 0 | my $folder = $message->folder->name; | |||||||||||||||||||||||||||
| 125 | 0 | ▶ | my $lp = $self->{MBSG_last_printed} || ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'MBSG_last_printed'} || ''
MC/DC0%0/1
$self->{'MBSG_last_printed'} || ''
$self->{'MBSG_last_printed'}
Truth table0%0/2
A
A= $self->{'MBSG_last_printed'}
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | unless($lp eq "$folder $msgnr") # match in new message | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | { my $subject = $message->subject; | |||||||||||||||||||||||||||
| 129 | 0 | $out->print("$folder, message $msgnr: $subject\n"); | |||||||||||||||||||||||||||
| 130 | 0 | $self->{MBSG_last_printed} = "$folder $msgnr"; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | my @lines = $match->{field}->string; | |||||||||||||||||||||||||||
| 134 | 0 | ▶ | my $inpart = $match->{part}->isPart ? 'p ' : ' '; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 0 | $out->print($inpart, join $inpart, @lines); | |||||||||||||||||||||||||||
| 136 | 0 | $self; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | sub printMatchedBody($$) | ||||||||||||||||||||||||||||
| 141 | 0 | ▶ | { my ($self, $out, $match) = @_; | ||||||||||||||||||||||||||
|
Subroutine
printMatchedBody: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 142 | 0 | my $message = $match->{message}; | |||||||||||||||||||||||||||
| 143 | 0 | my $msgnr = $message->seqnr; | |||||||||||||||||||||||||||
| 144 | 0 | my $folder = $message->folder->name; | |||||||||||||||||||||||||||
| 145 | 0 | ▶ | my $lp = $self->{MBSG_last_printed} || ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'MBSG_last_printed'} || ''
MC/DC0%0/1
$self->{'MBSG_last_printed'} || ''
$self->{'MBSG_last_printed'}
Truth table0%0/2
A
A= $self->{'MBSG_last_printed'}
| |||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | unless($lp eq "$folder $msgnr") # match in new message | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 0 | { my $subject = $message->subject; | |||||||||||||||||||||||||||
| 149 | 0 | $out->print("$folder, message $msgnr: $subject\n"); | |||||||||||||||||||||||||||
| 150 | 0 | $self->{MBSG_last_printed} = "$folder $msgnr"; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | ▶ | my $inpart = $match->{part}->isPart ? 'p ' : ' '; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 0 | $out->print(sprintf "$inpart %2d: %s", $match->{linenr}, $match->{line}); | |||||||||||||||||||||||||||
| 155 | 0 | $self; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 2 | 1; | |||||||||||||||||||||||||||