Box/Search.pm

filter: Statementstmt 18.6% 17 / 91 Branchbran 0.0% 0 / 80 Conditioncond 0.0% 0 / 49 MC/DCmcdc 0.0% 0 / 30 Subroutinesub 38.4% 5 / 13 Podpod 83.3% 5 / 6 totaltotal 10.0% 27 / 269 CC 62 SCAR 60.9
CC
62
Cov
8%
search
702.0
searchPart
420.0
init
342.0
CRAP 443.6
« Box/Manager.pm ↑ Summary Box/Maildir/Message.pm »
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;
10 2 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 $VERSION = '3.009';
12  
13 2 ▶use base 'Mail::Reporter';
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 sub init($)
22 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=18 SCAR=58.3
Pod undocumented
23  
24 0 $self->SUPER::init($args);
25  
26 0 ▶ my $in = $args->{in} || 'BODY';
Condition0%0/2
$args->{'in'} || 'BODY'
l!l
00
MC/DC0%0/1
$args->{'in'} || 'BODY'
$args->{'in'}
Truth table0%0/2
A
A= $args->{'in'}
Aresult
11
00
27 0 ▶ @$self{ qw/MBS_check_head MBS_check_body/ }
Branch: 3 branches
BranchTrueFalseTotal
$in eq 'BODY' ? : 0 0 0
$in eq 'HEAD' ? : 0 0 0
$in eq 'MESSAGE' ? : 0 0 0
28 = $in eq 'BODY' ? (0,1)
29 : $in eq 'HEAD' ? (1,0)
30 : $in eq 'MESSAGE' ? (1,1)
31 : ($self->log(ERROR => "Search in BODY, HEAD or MESSAGE not $in."), return);
32  
33 $self->log(ERROR => "Cannot search in header."), return
34 0 ▶ if $self->{MBS_check_head} && !$self->can('inHead');
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MBS_check_head"} and not $self->can("inHead") 0 0 0
Condition0%0/3
$self->{"MBS_check_head"} and not $self->can("inHead")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"MBS_check_head"} and not $self->can("inHead")
$self->{"MBS_check_head"} not $self->can("inHead")
Truth table0%0/3
A and not(B)
A= $self->{"MBS_check_head"}B= not $self->can("inHead")
ABresult
0X0
100
111
35  
36 $self->log(ERROR => "Cannot search in body."), return
37 0 ▶ if $self->{MBS_check_body} && !$self->can('inBody');
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MBS_check_body"} and not $self->can("inBody") 0 0 0
Condition0%0/3
$self->{"MBS_check_body"} and not $self->can("inBody")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"MBS_check_body"} and not $self->can("inBody")
$self->{"MBS_check_body"} not $self->can("inBody")
Truth table0%0/3
A and not(B)
A= $self->{"MBS_check_body"}B= not $self->can("inBody")
ABresult
0X0
100
111
38  
39 0 my $deliver = $args->{deliver};
40 $self->{MBS_deliver}
41 0 ▶ = ref $deliver eq 'CODE' ? sub { $deliver->($self, $_[0]) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
42 : !defined $deliver ? undef
43 : $deliver eq 'DELETE'
44 0 ▶ ? sub {$_[0]->{part}->toplevel->label(deleted => 1)}
Subroutine __ANON__: not called CC=1 SCAR=6.9
45 0 ▶ : $self->log(ERROR => "Don't know how to deliver results in $deliver.");
Branch: 3 branches
BranchTrueFalseTotal
ref $deliver eq 'CODE' ? : 0 0 0
!defined($deliver) ? : 0 0 0
$deliver eq 'DELETE' ? : 0 0 0
46  
47 0 ▶ my $logic = $args->{logical} || 'REPLACE';
Condition0%0/2
$args->{'logical'} || 'REPLACE'
l!l
00
MC/DC0%0/1
$args->{'logical'} || 'REPLACE'
$args->{'logical'}
Truth table0%0/2
A
A= $args->{'logical'}
Aresult
11
00
48 0 $self->{MBS_negative} = $logic =~ s/\s*NOT\s*$//;
49 0 $self->{MBS_logical} = $logic;
50  
51 0 $self->{MBS_label} = $args->{label};
52 0 ▶ $self->{MBS_binaries} = $args->{binaries} || 0;
Condition0%0/2
$args->{'binaries'} || 0
l!l
00
MC/DC0%0/1
$args->{'binaries'} || 0
$args->{'binaries'}
Truth table0%0/2
A
A= $args->{'binaries'}
Aresult
11
00
53 0 ▶ $self->{MBS_limit} = $args->{limit} || 0;
Condition0%0/2
$args->{'limit'} || 0
l!l
00
MC/DC0%0/1
$args->{'limit'} || 0
$args->{'limit'}
Truth table0%0/2
A
A= $args->{'limit'}
Aresult
11
00
54 0 ▶ $self->{MBS_decode} = $args->{decode} || 1;
Condition0%0/2
$args->{'decode'} || 1
l!l
00
MC/DC0%0/1
$args->{'decode'} || 1
$args->{'decode'}
Truth table0%0/2
A
A= $args->{'decode'}
Aresult
11
00
55 0 $self->{MBS_no_deleted} = not $args->{deleted};
56 0 ▶ $self->{MBS_delayed} = defined $args->{delayed} ? $args->{delayed} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{'delayed'} ? : 0 0 0
57 $self->{MBS_multiparts}
58 0 ▶ = defined $args->{multiparts} ? $args->{multiparts} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{'multiparts'} ? : 0 0 0
59  
60 0 $self;
61 }
62  
63 #-------------------------------------------
64  
65  
66 sub search(@)
67 0 ▶{ my ($self, $object) = @_;
Subroutine search: not called CC=26 SCAR=65.5
Pod documented
68  
69 0 my $label = $self->{MBS_label};
70 0 my $limit = $self->{MBS_limit};
71  
72 my @messages
73 0 ▶ = ref $object eq 'ARRAY' ? @$object
Branch: 4 branches
BranchTrueFalseTotal
ref $object eq 'ARRAY' ? : 0 0 0
$object->isa('Mail::Box') ? : 0 0 0
$object->isa('Mail::Message') ? : 0 0 0
$object->isa('Mail::Box::Thread::Node') ? : 0 0 0
74 : $object->isa('Mail::Box') ? $object->messages
75 : $object->isa('Mail::Message') ? ($object)
76 : $object->isa('Mail::Box::Thread::Node') ? $object->threadMessages
77 : croak "Expect messages to search, not $object.";
78  
79 0 my $take = 0;
80 0 ▶ if($limit < 0) { $take = -$limit; @messages = reverse @messages }
Branch: 3 branches
BranchTrueFalseTotal
if ($limit < 0) { } 0 0 0
elsif ($limit > 0) { } 0 0 0
elsif (not defined $label || wantarray || $self->{'MBS_deliver'}) { } 0 0 0
81 0 elsif($limit > 0) { $take = $limit }
82 0 ▶ elsif(!defined $label && !wantarray && !$self->{MBS_deliver}) {$take = 1 }
Condition0%0/6
defined $label || wantarray || $self->{'MBS_deliver'}
l!l&&r!l&&!r
000
defined $label or wantarray
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $label || wantarray || $self->{'MBS_deliver'}
defined $label wantarray $self->{'MBS_deliver'}
Truth table0%0/4
A or B || C
A= defined $labelB= wantarrayC= $self->{'MBS_deliver'}
ABCresult
1XX1
01X1
0011
0000
83  
84 0 my $logic = $self->{MBS_logical};
85 0 my @selected;
86 0 my $count = 0;
87  
88 0 foreach my $message (@messages)
89 0 ▶ { next if $self->{MBS_no_deleted} && $message->isDeleted;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MBS_no_deleted"} and $message->isDeleted 0 0 0
Condition0%0/3
$self->{"MBS_no_deleted"} and $message->isDeleted
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"MBS_no_deleted"} and $message->isDeleted
$self->{"MBS_no_deleted"} $message->isDeleted
Truth table0%0/3
A and B
A= $self->{"MBS_no_deleted"}B= $message->isDeleted
ABresult
0X0
100
111
90 0 ▶ next unless $self->{MBS_delayed} || !$message->isDelayed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"MBS_delayed"} or not $message->isDelayed 0 0 0
Condition0%0/3
$self->{"MBS_delayed"} or not $message->isDelayed
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"MBS_delayed"} or not $message->isDelayed
$self->{"MBS_delayed"} not $message->isDelayed
Truth table0%0/3
A or not(B)
A= $self->{"MBS_delayed"}B= not $message->isDelayed
ABresult
1X1
011
000
91  
92 0 ▶ my $set = defined $label ? $message->label($label) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $label ? : 0 0 0
93  
94 my $selected
95 = $set && $logic eq 'OR' ? 1
96 : !$set && $logic eq 'AND' ? 0
97 0 ▶ : $self->{MBS_negative} ? ! $self->searchPart($message)
Branch: 3 branches
BranchTrueFalseTotal
$set && $logic eq 'OR' ? : 0 0 0
!$set && $logic eq 'AND' ? : 0 0 0
$self->{'MBS_negative'} ? : 0 0 0
Condition0%0/6
$set and $logic eq "OR"
!ll&&!rl&&r
000
not $set and $logic eq "AND"
!ll&&!rl&&r
000
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 table0%0/3
A and B
A= $setB= $logic eq "OR"
ABresult
0X0
100
111
Truth table0%0/3
not(A) and B
A= not $setB= $logic eq "AND"
ABresult
0X0
100
111
98 : $self->searchPart($message);
99  
100 0 ▶ $message->label($label => $selected) if defined $label;
Branch: 1 branch
BranchTrueFalseTotal
if defined $label 0 0 0
101 0 ▶ if($selected)
Branch: 1 branch
BranchTrueFalseTotal
if ($selected) 0 0 0
102 0 { push @selected, $message;
103 0 $count++;
104 0 ▶ last if $take && $count == $take;
Branch: 1 branch
BranchTrueFalseTotal
if $take and $count == $take 0 0 0
Condition0%0/3
$take and $count == $take
!ll&&!rl&&r
000
MC/DC0%0/2
$take and $count == $take
$take $count == $take
Truth table0%0/3
A and B
A= $takeB= $count == $take
ABresult
0X0
100
111
105 }
106 }
107  
108 0 ▶ $limit < 0 ? reverse @selected : @selected;
Branch: 1 branch
BranchTrueFalseTotal
$limit < 0 ? : 0 0 0
109 }
110  
111  
112 #-------------------------------------------
113  
114  
115 sub searchPart($)
116 0 ▶{ my ($self, $part) = @_;
Subroutine searchPart: not called CC=20 SCAR=60.4
Pod documented
117  
118 0 my $matched = 0;
119 $matched = $self->inHead($part, $part->head)
120 0 ▶ if $self->{MBS_check_head};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MBS_check_head"} 0 0 0
121  
122 0 ▶ return $matched unless $self->{MBS_check_body};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"MBS_check_body"} 0 0 0
123 0 ▶ return $matched if $matched && !$self->{MBS_deliver};
Branch: 1 branch
BranchTrueFalseTotal
if $matched and not $self->{"MBS_deliver"} 0 0 0
Condition0%0/3
$matched and not $self->{"MBS_deliver"}
!ll&&!rl&&r
000
MC/DC0%0/2
$matched and not $self->{"MBS_deliver"}
$matched not $self->{"MBS_deliver"}
Truth table0%0/3
A and not(B)
A= $matchedB= not $self->{"MBS_deliver"}
ABresult
0X0
100
111
124  
125 0 my $body = $part->body;
126 0 my @bodies;
127  
128 # Handle multipart parts.
129  
130 0 ▶ if($body->isMultipart)
Branch: 2 branches
BranchTrueFalseTotal
if ($body->isMultipart) { } 0 0 0
elsif ($body->isNested) { } 0 0 0
131 0 ▶ { return $matched unless $self->{MBS_multiparts};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"MBS_multiparts"} 0 0 0
132 0 my $no_delayed = not $self->{MBS_delayed};
133 0 @bodies = ($body->preamble, $body->epilogue);
134  
135 0 foreach my $piece ($body->parts)
136 0 ▶ { next unless defined $piece;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $piece 0 0 0
137 0 ▶ next if $no_delayed && $piece->isDelayed;
Branch: 1 branch
BranchTrueFalseTotal
if $no_delayed and $piece->isDelayed 0 0 0
Condition0%0/3
$no_delayed and $piece->isDelayed
!ll&&!rl&&r
000
MC/DC0%0/2
$no_delayed and $piece->isDelayed
$no_delayed $piece->isDelayed
Truth table0%0/3
A and B
A= $no_delayedB= $piece->isDelayed
ABresult
0X0
100
111
138  
139 0 $matched += $self->searchPart($piece);
140 0 ▶ return $matched if $matched && !$self->{MBS_deliver};
Branch: 1 branch
BranchTrueFalseTotal
if $matched and not $self->{"MBS_deliver"} 0 0 0
Condition0%0/3
$matched and not $self->{"MBS_deliver"}
!ll&&!rl&&r
000
MC/DC0%0/2
$matched and not $self->{"MBS_deliver"}
$matched not $self->{"MBS_deliver"}
Truth table0%0/3
A and not(B)
A= $matchedB= not $self->{"MBS_deliver"}
ABresult
0X0
100
111
141 }
142 }
143 elsif($body->isNested)
144 0 ▶ { return $matched unless $self->{MBS_multiparts};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"MBS_multiparts"} 0 0 0
145 0 $matched += $self->searchPart($body->nested);
146 }
147 else
148 0 { @bodies = ($body);
149 }
150  
151 # Handle normal bodies.
152  
153 0 foreach (@bodies)
154 0 ▶ { next unless defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 0 0
155 0 ▶ next if !$self->{MBS_binaries} && $_->isBinary;
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"MBS_binaries"} and $_->isBinary 0 0 0
Condition0%0/3
not $self->{"MBS_binaries"} and $_->isBinary
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->{"MBS_binaries"} and $_->isBinary
not $self->{"MBS_binaries"} $_->isBinary
Truth table0%0/3
not(A) and B
A= not $self->{"MBS_binaries"}B= $_->isBinary
ABresult
0X0
100
111
156 0 ▶ my $body = $self->{MBS_decode} ? $_->decoded : $_;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'MBS_decode'} ? : 0 0 0
157 0 my $inbody = $self->inBody($part, $body);
158 0 $matched += $inbody;
159 }
160  
161 0 $matched;
162 }
163  
164 #-------------------------------------------
165  
166  
167 0 ▶sub inHead(@) {shift->notImplemented}
Subroutine inHead: not called CC=1 SCAR=6.9
Pod documented
168  
169 #-------------------------------------------
170  
171  
172 0 ▶sub inBody(@) {shift->notImplemented}
Subroutine inBody: not called CC=1 SCAR=6.9
Pod documented
173  
174 #-------------------------------------------
175  
176  
177 0 ▶sub printMatch($) {shift->notImplemented}
Subroutine printMatch: not called CC=1 SCAR=6.9
Pod documented
178  
179 #-------------------------------------------
180  
181  
182 2 1;
« Box/Manager.pm ↑ Summary Box/Maildir/Message.pm »