Box/Search.pm

filter: Statementstmt 92.2% 83 / 90 Branchbran 71.0% 54 / 76 Conditioncond 67.3% 33 / 49 MC/DCmcdc 33.3% 10 / 30 Subroutinesub 75.0% 12 / 16 Podpod 90.0% 9 / 10 totaltotal 74.1% 201 / 271 CC 60 SCAR 30.8
CC
60
Cov
79%
search
31.6
init
21.8
searchPart
21.8
CRAP 21.7
« Box/Manage/User.pm ↑ Summary Message/Head/Subset.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::Search;{
13 2 our $VERSION = '4.02';
14 }
15  
16 2 ▶use parent 'Mail::Reporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 ▶use Log::Report 'mail-box', import => [ qw/__x error/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 #--------------------
24  
25 sub init($)
26 12 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=18 SCAR=30.8
Pod undocumented
27  
28 12 $self->SUPER::init($args);
29  
30 12 ▶ my $in = $args->{in} || 'BODY';
Condition50%1/2
$args->{'in'} || 'BODY'
l!l
120
MC/DC0%0/1
$args->{'in'} || 'BODY'
$args->{'in'}
Truth table50%1/2
A
A= $args->{'in'}
Aresult
11
00
31 12 ▶ @$self{ qw/MBS_check_head MBS_check_body/ }
Branch: 3 branches
BranchTrueFalseTotal
$in eq 'BODY' ? : 5 7 12
$in eq 'HEAD' ? : 2 5 7
$in eq 'MESSAGE' ? : 5 0 5
32 = $in eq 'BODY' ? (0,1)
33 : $in eq 'HEAD' ? (1,0)
34 : $in eq 'MESSAGE' ? (1,1)
35 : error __x"search in BODY, HEAD or MESSAGE, not {what UNKNOWN}.", what => $in;
36  
37 12 ▶ ! $self->{MBS_check_head} || $self->can('inHead') or error __x"cannot search in header.";
Branch: 1 branch
BranchTrueFalseTotal
not $self->{"MBS_check_head"} or $self->can("inHead") or &error(&__x("cannot search in header.")) 12 0 12
Condition66%2/3
not $self->{"MBS_check_head"} or $self->can("inHead")
l!l&&r!l&&!r
570
MC/DC0%0/2
not $self->{"MBS_check_head"} or $self->can("inHead")
not $self->{"MBS_check_head"} $self->can("inHead")
Truth table66%2/3
not(A) or B
A= not $self->{"MBS_check_head"}B= $self->can("inHead")
ABresult
1X1
011
000
38 12 ▶ ! $self->{MBS_check_body} || $self->can('inBody') or error __x"cannot search in body.";
Branch: 1 branch
BranchTrueFalseTotal
not $self->{"MBS_check_body"} or $self->can("inBody") or &error(&__x("cannot search in body.")) 12 0 12
Condition66%2/3
not $self->{"MBS_check_body"} or $self->can("inBody")
l!l&&r!l&&!r
2100
MC/DC0%0/2
not $self->{"MBS_check_body"} or $self->can("inBody")
not $self->{"MBS_check_body"} $self->can("inBody")
Truth table66%2/3
not(A) or B
A= not $self->{"MBS_check_body"}B= $self->can("inBody")
ABresult
1X1
011
000
39  
40 12 my $deliver = $args->{deliver};
41 $self->{MBS_deliver}
42 518 ▶ = ref $deliver eq 'CODE' ? sub { $deliver->($self, $_[0]) }
Subroutine __ANON__: called CC=1 SCAR=0.0
43 : !defined $deliver ? undef
44 0 ▶ : $deliver eq 'DELETE' ? sub { $_[0]->{part}->toplevel->label(deleted => 1) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
45 12 ▶ : error __x"don't know how to deliver results in {what UNKNOWN}.", what => $deliver;
Branch: 3 branches
BranchTrueFalseTotal
ref $deliver eq 'CODE' ? : 11 1 12
!defined($deliver) ? : 1 0 1
$deliver eq 'DELETE' ? : 0 0 0
46  
47 12 ▶ my $logic = $args->{logical} || 'REPLACE';
Condition50%1/2
$args->{'logical'} || 'REPLACE'
l!l
012
MC/DC0%0/1
$args->{'logical'} || 'REPLACE'
$args->{'logical'}
Truth table50%1/2
A
A= $args->{'logical'}
Aresult
11
00
48 12 $self->{MBS_negative} = $logic =~ s/\s*NOT\s*$//;
49 12 $self->{MBS_logical} = $logic;
50  
51 12 $self->{MBS_label} = $args->{label};
52 12 ▶ $self->{MBS_binaries} = $args->{binaries} || 0;
Condition100%2/2
$args->{'binaries'} || 0
l!l
111
MC/DC100%1/1
$args->{'binaries'} || 0
$args->{'binaries'}
Truth table100%2/2
A
A= $args->{'binaries'}
Aresult
11
00
53 12 ▶ $self->{MBS_limit} = $args->{limit} || 0;
Condition100%2/2
$args->{'limit'} || 0
l!l
111
MC/DC100%1/1
$args->{'limit'} || 0
$args->{'limit'}
Truth table100%2/2
A
A= $args->{'limit'}
Aresult
11
00
54 12 ▶ $self->{MBS_decode} = $args->{decode} || 1;
Condition50%1/2
$args->{'decode'} || 1
l!l
012
MC/DC0%0/1
$args->{'decode'} || 1
$args->{'decode'}
Truth table50%1/2
A
A= $args->{'decode'}
Aresult
11
00
55 12 $self->{MBS_no_deleted} = not $args->{deleted};
56 12 ▶ $self->{MBS_delayed} = exists $args->{delayed} ? $args->{delayed} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'delayed'} ? : 0 12 12
57 12 ▶ $self->{MBS_multiparts} = exists $args->{multiparts} ? $args->{multiparts} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'multiparts'} ? : 1 11 12
58  
59 12 $self;
60 }
61  
62 #--------------------
63  
64 63 ▶sub deliver() { $_[0]->{MBS_deliver} }
Subroutine deliver: called CC=1 SCAR=0.0
Pod documented
65 25 ▶sub doMultiparts() { $_[0]->{MBS_multiparts} }
Subroutine doMultiparts: called CC=1 SCAR=0.0
Pod documented
66 343 ▶sub parseDelayed() { $_[0]->{MBS_delayed} }
Subroutine parseDelayed: called CC=1 SCAR=0.0
Pod documented
67 376 ▶sub skipDeleted() { $_[0]->{MBS_no_deleted} }
Subroutine skipDeleted: called CC=1 SCAR=0.0
Pod documented
68  
69 #--------------------
70  
71 sub search(@)
72 14 ▶{ my ($self, $object) = @_;
Subroutine search: called CC=26 SCAR=34.5
Pod documented
73  
74 14 my $label = $self->{MBS_label};
75 14 my $limit = $self->{MBS_limit};
76  
77 my @messages
78 14 ▶ = ref $object eq 'ARRAY' ? @$object
Branch: 4 branches
BranchTrueFalseTotal
ref $object eq 'ARRAY' ? : 1 13 14
$object->isa('Mail::Box') ? : 10 3 13
$object->isa('Mail::Message') ? : 1 2 3
$object->isa('Mail::Box::Thread::Node') ? : 2 0 2
79 : $object->isa('Mail::Box') ? $object->messages
80 : $object->isa('Mail::Message') ? ($object)
81 : $object->isa('Mail::Box::Thread::Node') ? $object->threadMessages
82 : error __x"expect messages to search, not {what UNKNOWN}.", what => $object;
83  
84 14 my $take = 0;
85 14 ▶ if($limit < 0) { $take = -$limit; @messages = reverse @messages }
Branch: 3 branches
BranchTrueFalseTotal
if ($limit < 0) { } 1 13 14
elsif ($limit > 0) { } 0 13 13
elsif (not defined $label || wantarray || $self->deliver) { } 1 12 13
86 0 elsif($limit > 0) { $take = $limit }
87 1 ▶ elsif(!defined $label && !wantarray && !$self->deliver) {$take = 1 }
Condition83%5/6
defined $label || wantarray || $self->deliver
l!l&&r!l&&!r
931
defined $label or wantarray
l!l&&r!l&&!r
094
MC/DC66%2/3
defined $label || wantarray || $self->deliver
defined $label wantarray $self->deliver
Truth table75%3/4
A or B || C
A= defined $labelB= wantarrayC= $self->deliver
ABCresult
1XX1
01X1
0011
0000
88  
89 14 my $logic = $self->{MBS_logical};
90 14 my @selected;
91 14 my $count = 0;
92  
93 14 foreach my $message (@messages)
94 376 ▶ { next if $self->skipDeleted && $message->isDeleted;
Branch: 1 branch
BranchTrueFalseTotal
if $self->skipDeleted and $message->isDeleted 33 343 376
Condition100%3/3
$self->skipDeleted and $message->isDeleted
!ll&&!rl&&r
4529833
MC/DC100%2/2
$self->skipDeleted and $message->isDeleted
$self->skipDeleted $message->isDeleted
Truth table100%3/3
A and B
A= $self->skipDeletedB= $message->isDeleted
ABresult
0X0
100
111
95 343 ▶ next unless $self->parseDelayed || !$message->isDelayed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->parseDelayed or not $message->isDelayed 0 343 343
Condition33%1/3
$self->parseDelayed or not $message->isDelayed
l!l&&r!l&&!r
34300
MC/DC0%0/2
$self->parseDelayed or not $message->isDelayed
$self->parseDelayed not $message->isDelayed
Truth table33%1/3
A or not(B)
A= $self->parseDelayedB= not $message->isDelayed
ABresult
1X1
011
000
96  
97 343 ▶ my $set = defined $label ? $message->label($label) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $label ? : 0 343 343
98  
99 my $selected
100 = $set && $logic eq 'OR' ? 1
101 : !$set && $logic eq 'AND' ? 0
102 343 ▶ : $self->{MBS_negative} ? ! $self->searchPart($message)
Branch: 3 branches
BranchTrueFalseTotal
$set && $logic eq 'OR' ? : 0 343 343
!$set && $logic eq 'AND' ? : 0 343 343
$self->{'MBS_negative'} ? : 0 343 343
Condition33%2/6
$set and $logic eq "OR"
!ll&&!rl&&r
34300
not $set and $logic eq "AND"
!ll&&!rl&&r
03430
MC/DC0%0/2
$set and $logic eq "OR"
$set $logic eq "OR"
MC/DC0%0/2
not $set and $logic eq "AND"
not $set $logic eq "AND"
Truth table33%1/3
A and B
A= $setB= $logic eq "OR"
ABresult
0X0
100
111
Truth table33%1/3
not(A) and B
A= not $setB= $logic eq "AND"
ABresult
0X0
100
111
103 : $self->searchPart($message);
104  
105 343 ▶ $message->label($label => $selected) if defined $label;
Branch: 1 branch
BranchTrueFalseTotal
if defined $label 0 343 343
106 343 ▶ if($selected)
Branch: 1 branch
BranchTrueFalseTotal
if ($selected) 167 176 343
107 167 { push @selected, $message;
108 167 $count++;
109 167 ▶ last if $take && $count == $take;
Branch: 1 branch
BranchTrueFalseTotal
if $take and $count == $take 2 165 167
Condition100%3/3
$take and $count == $take
!ll&&!rl&&r
16232
MC/DC100%2/2
$take and $count == $take
$take $count == $take
Truth table100%3/3
A and B
A= $takeB= $count == $take
ABresult
0X0
100
111
110 }
111 }
112  
113 14 ▶ $limit < 0 ? reverse @selected : @selected;
Branch: 1 branch
BranchTrueFalseTotal
$limit < 0 ? : 1 13 14
114 }
115  
116  
117  
118 sub searchPart($)
119 376 ▶{ my ($self, $part) = @_;
Subroutine searchPart: called CC=18 SCAR=30.8
Pod documented
120  
121 376 my $matched = 0;
122 $matched = $self->inHead($part, $part->head)
123 376 ▶ if $self->{MBS_check_head};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MBS_check_head"} 231 145 376
124  
125 376 ▶ return $matched unless $self->{MBS_check_body};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"MBS_check_body"} 41 335 376
126 335 ▶ return $matched if $matched && !$self->deliver;
Branch: 1 branch
BranchTrueFalseTotal
if $matched and not $self->deliver 0 335 335
Condition66%2/3
$matched and not $self->deliver
!ll&&!rl&&r
293420
MC/DC0%0/2
$matched and not $self->deliver
$matched not $self->deliver
Truth table66%2/3
A and not(B)
A= $matchedB= not $self->deliver
ABresult
0X0
100
111
127  
128 335 my $body = $part->body;
129 335 my @bodies;
130  
131 # Handle multipart parts.
132  
133 335 ▶ if($body->isMultipart)
Branch: 2 branches
BranchTrueFalseTotal
if ($body->isMultipart) { } 25 310 335
elsif ($body->isNested) { } 0 310 310
134 25 ▶ { $self->doMultiparts or return $matched;
Branch: 1 branch
BranchTrueFalseTotal
$self->doMultiparts or return $matched 24 1 25
135  
136 24 @bodies = ($body->preamble, $body->epilogue);
137  
138 24 foreach my $piece (grep defined, $body->parts)
139 33 ▶ { next if $piece->isDelayed && ! $self->parseDelayed;
Branch: 1 branch
BranchTrueFalseTotal
if $piece->isDelayed and not $self->parseDelayed 0 33 33
Condition33%1/3
$piece->isDelayed and not $self->parseDelayed
!ll&&!rl&&r
3300
MC/DC0%0/2
$piece->isDelayed and not $self->parseDelayed
$piece->isDelayed not $self->parseDelayed
Truth table33%1/3
A and not(B)
A= $piece->isDelayedB= not $self->parseDelayed
ABresult
0X0
100
111
140  
141 33 $matched += $self->searchPart($piece);
142 33 ▶ return $matched if $matched && !$self->deliver;
Branch: 1 branch
BranchTrueFalseTotal
if $matched and not $self->deliver 0 33 33
Condition66%2/3
$matched and not $self->deliver
!ll&&!rl&&r
16170
MC/DC0%0/2
$matched and not $self->deliver
$matched not $self->deliver
Truth table66%2/3
A and not(B)
A= $matchedB= not $self->deliver
ABresult
0X0
100
111
143 }
144 }
145 elsif($body->isNested)
146 0 ▶ { $self->doMultiparts or return $matched;
Branch: 1 branch
BranchTrueFalseTotal
$self->doMultiparts or return $matched 0 0 0
147 0 $matched += $self->searchPart($body->nested);
148 }
149 else
150 310 { @bodies = ($body);
151 }
152  
153 # Handle normal bodies.
154  
155 334 foreach (grep defined, @bodies)
156 349 ▶ { next if !$self->{MBS_binaries} && $_->isBinary;
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"MBS_binaries"} and $_->isBinary 23 326 349
Condition100%3/3
not $self->{"MBS_binaries"} and $_->isBinary
!ll&&!rl&&r
332323
MC/DC100%2/2
not $self->{"MBS_binaries"} and $_->isBinary
not $self->{"MBS_binaries"} $_->isBinary
Truth table100%3/3
not(A) and B
A= not $self->{"MBS_binaries"}B= $_->isBinary
ABresult
0X0
100
111
157 326 ▶ my $body = $self->{MBS_decode} ? $_->decoded : $_;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'MBS_decode'} ? : 326 0 326
158 326 my $inbody = $self->inBody($part, $body);
159 326 $matched += $inbody;
160 }
161  
162 334 $matched;
163 }
164  
165  
166 0 ▶sub inHead(@) { $_[0]->notImplemented }
Subroutine inHead: not called CC=1 SCAR=6.9
Pod documented
167  
168  
169 0 ▶sub inBody(@) { $_[0]->notImplemented }
Subroutine inBody: not called CC=1 SCAR=6.9
Pod documented
170  
171 #--------------------
172  
173 0 ▶sub printMatch($) { $_[0]->notImplemented }
Subroutine printMatch: not called CC=1 SCAR=6.9
Pod documented
174  
175 2 1;
« Box/Manage/User.pm ↑ Summary Message/Head/Subset.pm »