SPF/Result.pm

filter: Statementstmt 95.6% 152 / 159 Branchbran 77.5% 31 / 40 Conditioncond 36.3% 4 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 92.1% 35 / 38 Podpod 66.6% 6 / 9 totaltotal 86.3% 228 / 264 CC 25 SCAR 12.1
CC
25
Cov
89%
received_spf_header
8.2
new
7.0
local_explanation
4.2
CRAP 3.4
« SPF/Mod/Redirect.pm ↑ Summary SPF/Mech/PTR.pm »
1 #
2 # Mail::SPF::Result
3 # SPF result class.
4 #
5 # (C) 2005-2012 Julian Mehnle <julian@mehnle.net>
6 # $Id: Result.pm 57 2012-01-30 08:15:31Z julian $
7 #
8 ##############################################################################
9  
10 package Mail::SPF::Result;
11  
12 =head1 NAME
13  
14 Mail::SPF::Result - SPF result class
15  
16 =head1 VERSION
17  
18 version 3.20261105
19  
20 =cut
21  
22 6 our $VERSION = '3.20261105'; # VERSION
23  
24 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 6 ▶use utf8; # Hack to keep Perl 5.6 from whining about /[\p{}]/.
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 6 ▶use base 'Error', 'Mail::SPF::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 # An SPF result is not really a code exception in ideology, but in form.
31 # The Error base class fits our purpose, anyway.
32  
33 6 ▶use Mail::SPF::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 6 ▶use Error ':try';
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 6 ▶use constant TRUE => (0 == 0);
Subroutine BEGIN: called CC=1 SCAR=0.0
38 6 ▶use constant FALSE => not TRUE;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 6 ▶use constant result_classes => {
Subroutine BEGIN: called CC=1 SCAR=0.0
41 pass => 'Mail::SPF::Result::Pass',
42 fail => 'Mail::SPF::Result::Fail',
43 softfail => 'Mail::SPF::Result::SoftFail',
44 neutral => 'Mail::SPF::Result::Neutral',
45 'neutral-by-default'
46 => 'Mail::SPF::Result::NeutralByDefault',
47 none => 'Mail::SPF::Result::None',
48 error => 'Mail::SPF::Result::Error',
49 permerror => 'Mail::SPF::Result::PermError',
50 temperror => 'Mail::SPF::Result::TempError'
51 6 };
52  
53 6 ▶use constant received_spf_header_name => 'Received-SPF';
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 6 ▶use constant received_spf_header_scope_names_by_scope => {
Subroutine BEGIN: called CC=1 SCAR=0.0
56 helo => 'helo',
57 mfrom => 'mailfrom',
58 pra => 'pra'
59 6 };
60  
61 6 ▶use constant received_spf_header_identity_key_names_by_scope => {
Subroutine BEGIN: called CC=1 SCAR=0.0
62 helo => 'helo',
63 mfrom => 'envelope-from',
64 pra => 'pra'
65 6 };
66  
67 6 ▶use constant atext_pattern => qr/[\p{IsAlnum}!#\$%&'*+\-\/=?^_`{|}~]/;
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69 6 ▶use constant dot_atom_pattern => qr/
Subroutine BEGIN: called CC=1 SCAR=0.0
70 6 (${\atext_pattern})+ ( \. (${\atext_pattern})+ )*
71 6 /x;
72  
73 # Interface:
74 ##############################################################################
75  
76 =head1 SYNOPSIS
77  
78 For the general usage of I<Mail::SPF::Result> objects in code that calls
79 Mail::SPF, see L<Mail::SPF>. For the detailed interface of I<Mail::SPF::Result>
80 and its derivatives, see below.
81  
82 =head2 Throwing results
83  
84 package Mail::SPF::Foo;
85 use Error ':try';
86 use Mail::SPF::Result;
87  
88 sub foo {
89 if (...) {
90 $server->throw_result('pass', $request)
91 }
92 else {
93 $server->throw_result('permerror', $request, 'Invalid foo');
94 }
95 }
96  
97 =head2 Catching results
98  
99 package Mail::SPF::Bar;
100 use Error ':try';
101 use Mail::SPF::Foo;
102  
103 try {
104 Mail::SPF::Foo->foo();
105 }
106 catch Mail::SPF::Result with {
107 my ($result) = @_;
108 ...
109 };
110  
111 =head2 Using results
112  
113 my $result_name = $result->name;
114 my $result_code = $result->code;
115 my $request = $result->request;
116 my $local_exp = $result->local_explanation;
117 my $authority_exp = $result->authority_explanation
118 if $result->can('authority_explanation');
119 my $spf_header = $result->received_spf_header;
120  
121 =cut
122  
123 # Implementation:
124 ##############################################################################
125  
126 =head1 DESCRIPTION
127  
128 An object of class B<Mail::SPF::Result> represents the result of an SPF
129 request.
130  
131 There is usually no need to construct an SPF result object directly using the
132 C<new> constructor. Instead, use the C<throw> class method to signal to the
133 calling code that a definite SPF result has been determined. In other words,
134 use Mail::SPF::Result and its derivatives just like exceptions. See L<Error>
135 or L<perlfunc/eval> for how to handle exceptions in Perl.
136  
137 =head2 Constructor
138  
139 The following constructor is provided:
140  
141 =over
142  
143 =item B<new($server, $request)>: returns I<Mail::SPF::Result>
144  
145 =item B<new($server, $request, $text)>: returns I<Mail::SPF::Result>
146  
147 Creates a new SPF result object and associates the given I<Mail::SPF::Server>
148 and I<Mail::SPF::Request> objects with it. An optional result text may be
149 specified.
150  
151 =cut
152  
153 131 ▶sub new {
Subroutine new: called CC=7 SCAR=19.5
Pod documented
154 131 my ($self, @args) = @_;
155  
156 131 local $Error::Depth = $Error::Depth + 1;
157  
158 131 ▶ $self =
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 79 52 131
159 ref($self) ? # Was new() invoked on a class or an object?
160 bless({ %$self }, ref($self)) # Object: clone source result object.
161 : $self->SUPER::new(); # Class: create new result object.
162  
163 # Set/override fields:
164 131 ▶ $self->{server} = shift(@args) if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 53 78 131
165 defined($self->{server})
166 131 ▶ or throw Mail::SPF::EOptionRequired('Mail::SPF server object required');
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"server"} or "Mail::SPF::EOptionRequired"->throw("Mail::SPF server object required") 131 0 131
167 131 ▶ $self->{request} = shift(@args) if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 53 78 131
168 defined($self->{request})
169 131 ▶ or throw Mail::SPF::EOptionRequired('Request object required');
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"request"} or "Mail::SPF::EOptionRequired"->throw("Request object required") 131 0 131
170 131 ▶ $self->{'-text'} = shift(@args) if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 48 83 131
171  
172 131 return $self;
173 }
174  
175 =back
176  
177 =head2 Class methods
178  
179 The following class methods are provided:
180  
181 =over
182  
183 =item B<throw($server, $request)>: throws I<Mail::SPF::Result>
184  
185 =item B<throw($server, $request, $text)>: throws I<Mail::SPF::Result>
186  
187 Throws a new SPF result object, associating the given I<Mail::SPF::Server> and
188 I<Mail::SPF::Request> objects with it. An optional result text may be
189 specified.
190  
191 I<Note>: Do not write code invoking C<throw> on I<literal> result class names
192 as this would ignore any derivative result classes provided by B<Mail::SPF>
193 extension modules. Invoke the L<C<throw_result>|Mail::SPF::Server/throw_result>
194 method on a I<Mail::SPF::Server> object instead.
195  
196 =cut
197  
198 84 ▶sub throw {
Subroutine throw: called CC=1 SCAR=0.0
Pod documented
199 84 my ($self, @args) = @_;
200 84 local $Error::Depth = $Error::Depth + 1;
201 84 $self = $self->new(@args);
202 # Always create/clone a new result object, not just when throwing for the first time!
203 84 die($Error::THROWN = $self);
204 }
205  
206 =item B<name>: returns I<string>
207  
208 I<Abstract>. Returns the result name of the result class (or object). For
209 classes of the I<Mail::SPF::Result::*> hierarchy, this roughly corresponds to
210 the trailing part of the class name. For example, returns C<neutral-by-default>
211 if invoked on I<Mail::SPF::Result::NeutralByDefault>. Also see the L</code>
212 method. This method may also be used as an instance method.
213  
214 This method must be implemented by sub-classes of Mail::SPF::Result for which
215 the result I<name> differs from the result I<code>.
216  
217 =cut
218  
219 # This method being implemented here does not make it any less abstract,
220 # because the code() method it uses is still abstract.
221 0 ▶sub name {
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
222 0 my ($self) = @_;
223 0 return $self->code;
224 }
225  
226 =item B<class>: returns I<class>
227  
228 =item B<class($name)>: returns I<class>
229  
230 Maps the given result name to the corresponding I<Mail::SPF::Result::*> class,
231 or returns the result base class (the class on which it is invoked) if no
232 result name is given. If an unknown result name is specified, returns
233 B<undef>.
234  
235 =cut
236  
237 9 ▶sub class {
Subroutine class: called CC=3 SCAR=11.7
Pod documented
238 9 my ($self, $name) = @_;
239 9 ▶ return defined($name) ? $self->result_classes->{lc($name)} : (ref($self) || $self);
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 8 1 9
Condition33%1/3
ref $self or $self
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $self or $self
ref $self $self
Truth table33%1/3
A or B
A= ref $selfB= $self
ABresult
1X1
011
000
240 }
241  
242 =item B<isa_by_name($name)>: returns I<boolean>
243  
244 If the class (or object) on which this method is invoked represents the given
245 result name (or a derivative name), returns B<true>. Returns B<false>
246 otherwise. This method may also be used as an instance method.
247  
248 For example, C<< Mail::SPF::Result::NeutralByDefault->isa_by_name('neutral') >>
249 returns B<true>.
250  
251 =cut
252  
253 6 ▶sub isa_by_name {
Subroutine isa_by_name: called CC=2 SCAR=6.9
Pod documented
254 6 my ($self, $name) = @_;
255 6 my $suspect_class = $self->class($name);
256 6 ▶ return FALSE if not defined($suspect_class);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $suspect_class 2 4 6
257 4 return $self->isa($suspect_class);
258 }
259  
260 =item B<code>: returns I<string>
261  
262 I<Abstract>. Returns the basic SPF result code (C<"pass">, C<"fail">,
263 C<"softfail">, C<"neutral">, C<"none">, C<"error">, C<"permerror">,
264 C<"temperror">) of the result class on which it is invoked. All valid result
265 codes are valid result names as well, the reverse however does not apply. This
266 method may also be used as an instance method.
267  
268 This method is abstract and must be implemented by sub-classes of
269 Mail::SPF::Result.
270  
271 =item B<is_code($code)>: returns I<boolean>
272  
273 If the class (or object) on which this method is invoked represents the given
274 result code, returns B<true>. Returns B<false> otherwise. This method may
275 also be used as an instance method.
276  
277 I<Note>: The L</isa_by_name> method provides a superset of this method's
278 functionality.
279  
280 =cut
281  
282 2 ▶sub is_code {
Subroutine is_code: called CC=1 SCAR=0.0
Pod documented
283 2 my ($self, $code) = @_;
284 2 return $self->isa_by_name($code);
285 }
286  
287 =item B<received_spf_header_name>: returns I<string>
288  
289 Returns B<'Received-SPF'> as the field name for C<Received-SPF> header fields.
290 This method should be overridden by B<Mail::SPF> extension modules that provide
291 non-standard features (such as local policy) with the capacity to dilute the
292 purity of SPF results, in order not to deceive users of the header field into
293 mistaking it as an indication of a natural SPF result.
294  
295 =back
296  
297 =head2 Instance methods
298  
299 The following instance methods are provided:
300  
301 =over
302  
303 =item B<throw>: throws I<Mail::SPF::Result>
304  
305 =item B<throw($server, $request)>: throws I<Mail::SPF::Result>
306  
307 =item B<throw($server, $request, $text)>: throws I<Mail::SPF::Result>
308  
309 Re-throws an existing SPF result object. If I<Mail::SPF::Server> and
310 I<Mail::SPF::Request> objects are specified, associates them with the result
311 object, replacing the prior server and request objects. If a result text is
312 specified as well, overrides the prior result text.
313  
314 =item B<server>: returns I<Mail::SPF::Server>
315  
316 Returns the Mail::SPF server object that produced the result at hand.
317  
318 =item B<request>: returns I<Mail::SPF::Request>
319  
320 Returns the SPF request that led to the result at hand.
321  
322 =cut
323  
324 # Read-only accessors:
325 __PACKAGE__->make_accessor($_, TRUE)
326 6 foreach qw(server request);
327  
328 =item B<text>: returns I<string>
329  
330 Returns the text message of the result object.
331  
332 Be aware that the text message may contain untrusted data, such as the text of
333 a malformed SPF record published by the authority domain, including control
334 characters. Use L</local_explanation> or L</stringify>, which escape such
335 characters, when the text is to be included in a header field, SMTP response,
336 or log.
337  
338 =item B<stringify>: returns I<string>
339  
340 Returns the result's name and text message formatted as a string. You can
341 simply use a Mail::SPF::Result object as a string for the same effect, see
342 L</OVERLOADING>.
343  
344 =cut
345  
346 0 ▶sub stringify {
Subroutine stringify: not called CC=1 SCAR=6.9
Pod documented
347 0 my ($self) = @_;
348 0 return sprintf(
349 "%s (%s)",
350 $self->name,
351 Mail::SPF::Util->sanitize_string($self->SUPER::stringify)
352 );
353 }
354  
355 =item B<local_explanation>: returns I<string>; throws I<Mail::SPF::EDNSError>,
356 I<Mail::SPF::EInvalidMacroString>
357  
358 Returns a locally generated explanation for the result.
359  
360 The local explanation is prefixed with the authority domain whose sender policy
361 is responsible for the result. If the responsible sender policy referred to
362 another domain's policy (using the C<include> mechanism or the C<redirect>
363 modifier), that other domain which is I<directly> responsible for the result is
364 also included in the local explanation's head. For example:
365  
366 example.com: <local-explanation>
367  
368 The authority domain C<example.com>'s sender policy is directly responsible for
369 the result.
370  
371 example.com ... other.example.org: <local-explanation>
372  
373 The authority domain C<example.com> (directly or indirectly) referred to the
374 domain C<other.example.org>, whose sender policy then led to the result.
375  
376 =cut
377  
378 1 ▶sub local_explanation {
Subroutine local_explanation: called CC=4 SCAR=14.4
Pod undocumented
379 1 my ($self) = @_;
380 1 my $local_explanation = $self->{local_explanation};
381  
382 1 ▶ return $local_explanation
Branch: 1 branch
BranchTrueFalseTotal
if defined $local_explanation 0 1 1
383 if defined($local_explanation);
384  
385 # Prepare local explanation:
386 1 my $request = $self->{request};
387 1 $local_explanation = $request->state('local_explanation');
388 1 ▶ if (defined($local_explanation)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $local_explanation) { } 0 1 1
389 0 $local_explanation = sprintf("%s (%s)", $local_explanation->expand, lcfirst($self->text));
390 }
391 else {
392 1 $local_explanation = $self->text;
393 }
394  
395 # Resolve authority domains of root-request and bottom sub-request:
396 1 my $root_request = $request->root_request;
397 1 ▶ $local_explanation =
Branch: 1 branch
BranchTrueFalseTotal
$request == $root_request ? : 1 0 1
398 $request == $root_request ?
399 sprintf("%s: %s", $request->authority_domain, $local_explanation)
400 : sprintf("%s ... %s: %s",
401 $root_request->authority_domain, $request->authority_domain, $local_explanation);
402  
403 1 return $self->{local_explanation} = Mail::SPF::Util->sanitize_string($local_explanation);
404 }
405  
406 =item B<received_spf_header>: returns I<string>
407  
408 Returns a string containing an appropriate C<Received-SPF> header field for the
409 result object. The header field is not line-wrapped and contains no trailing
410 newline character.
411  
412 =cut
413  
414 1 ▶sub received_spf_header {
Subroutine received_spf_header: called CC=8 SCAR=21.1
Pod undocumented
415 1 my ($self) = @_;
416 return $self->{received_spf_header}
417 1 ▶ if defined($self->{received_spf_header});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"received_spf_header"} 0 1 1
418 my $scope_name =
419 1 $self->received_spf_header_scope_names_by_scope->{$self->{request}->scope};
420 my $identity_key_name =
421 1 $self->received_spf_header_identity_key_names_by_scope->{$self->{request}->scope};
422 my @info_pairs = (
423 receiver => $self->{server}->hostname || 'unknown',
424 identity => $scope_name,
425 $identity_key_name => $self->{request}->identity,
426 (
427 ($self->{request}->scope ne 'helo' and defined($self->{request}->helo_identity)) ?
428 (helo => $self->{request}->helo_identity)
429 : ()
430 ),
431 'client-ip' => Mail::SPF::Util->ip_address_to_string($self->{request}->ip_address)
432 1 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$self->{'request'}->scope ne 'helo' && defined $self->{'request'}->helo_identity ? : 1 0 1
Condition40%2/5
$self->{'server'}->hostname || 'unknown'
l!l
10
$self->{"request"}->scope ne "helo" and defined $self->{"request"}->helo_identity
!ll&&!rl&&r
001
MC/DC0%0/1
$self->{'server'}->hostname || 'unknown'
$self->{'server'}->hostname
MC/DC0%0/2
$self->{"request"}->scope ne "helo" and defined $self->{"request"}->helo_identity
$self->{"request"}->scope ne "helo" defined $self->{"request"}->helo_identity
Truth table50%1/2
A
A= $self->{'server'}->hostname
Aresult
11
00
Truth table33%1/3
A and B
A= $self->{"request"}->scope ne "helo"B= defined $self->{"request"}->helo_identity
ABresult
0X0
100
111
433 1 my $info_string;
434 1 ▶ while (@info_pairs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@info_pairs) 5 1 6
435 5 my $key = shift(@info_pairs);
436 5 my $value = Mail::SPF::Util->sanitize_string(shift(@info_pairs)); # Escape CR/LF etc.
437 5 ▶ $info_string .= '; ' if defined($info_string);
Branch: 1 branch
BranchTrueFalseTotal
if defined $info_string 4 1 5
438 5 ▶ if ($value !~ /^${\dot_atom_pattern}$/o) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value =~ m[^${\qr/ ((?^:[\p{IsAlnum}!#\$%&'*+\-\/=?^_`{|}~]))+ ( \. ((?^:[\p{IsAlnum}!#\$%&'*+\-\/=?^_`{|}~]))+ )* /ux;}$]o) 2 3 5
439 2 $value =~ s/(["\\])/\\$1/g; # Escape '\' and '"' characters.
440 2 $value = '"' . $value . '"'; # Double-quote value.
441 }
442 5 $info_string .= "$key=$value";
443 }
444 # The explanation may contain untrusted text (e.g. record text in permerror
445 # messages, or the sender identity), so escape it as an RFC 5322 comment to
446 # prevent it from closing the comment early and injecting fields:
447 1 my $comment = $self->local_explanation;
448 1 $comment =~ s/([()\\])/\\$1/g;
449 1 return $self->{received_spf_header} = sprintf(
450 "%s: %s (%s) %s",
451 $self->received_spf_header_name,
452 $self->code,
453 $comment,
454 $info_string
455 );
456 }
457  
458 =back
459  
460 =head1 OVERLOADING
461  
462 If a Mail::SPF::Result object is used as a I<string>, the L</stringify> method
463 is used to convert the object into a string.
464  
465 =head1 RESULT CLASSES
466  
467 The following result classes are provided:
468  
469 =over
470  
471 =item *
472  
473 I<Mail::SPF::Result::Pass>
474  
475 =item *
476  
477 I<Mail::SPF::Result::Fail>
478  
479 =item *
480  
481 I<Mail::SPF::Result::SoftFail>
482  
483 =item *
484  
485 I<Mail::SPF::Result::Neutral>
486  
487 =over
488  
489 =item *
490  
491 I<Mail::SPF::Result::NeutralByDefault>
492  
493 This is a special case of the C<neutral> result that is thrown as a default
494 when "falling off" the end of the record during evaluation. See RFC 4408,
495 4.7.
496  
497 =back
498  
499 =item *
500  
501 I<Mail::SPF::Result::None>
502  
503 =item *
504  
505 I<Mail::SPF::Result::Error>
506  
507 =over
508  
509 =item *
510  
511 I<Mail::SPF::Result::PermError>
512  
513 =item *
514  
515 I<Mail::SPF::Result::TempError>
516  
517 =back
518  
519 =back
520  
521 The following result classes have additional functionality:
522  
523 =over
524  
525 =item I<Mail::SPF::Result::Fail>
526  
527 The following additional instance method is provided:
528  
529 =over
530  
531 =item B<authority_explanation>: returns I<string>; throws I<Mail::SPF::EDNSError>,
532 I<Mail::SPF::EInvalidMacroString>
533  
534 Returns the authority domain's explanation for the result. Be aware that the
535 authority domain may be a malicious party and thus the authority explanation
536 should not be trusted blindly. See RFC 4408, 10.5, for a detailed discussion
537 of this issue. Control characters (such as CR and LF) and non-ASCII characters
538 in the explanation are escaped (see L<Mail::SPF::Util/sanitize_string>).
539  
540 =back
541  
542 =back
543  
544 =cut
545  
546 package Mail::SPF::Result::Pass;
547 6 our @ISA = 'Mail::SPF::Result';
548 6 ▶use constant code => 'pass';
Subroutine BEGIN: called CC=1 SCAR=0.0
549  
550 package Mail::SPF::Result::Fail;
551 6 our @ISA = 'Mail::SPF::Result';
552 6 ▶use Error ':try';
Subroutine BEGIN: called CC=1 SCAR=0.0
553 6 ▶use Mail::SPF::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
554 6 ▶use constant code => 'fail';
Subroutine BEGIN: called CC=1 SCAR=0.0
555  
556 9 ▶sub authority_explanation {
Subroutine authority_explanation: called CC=4 SCAR=14.3
557 9 my ($self) = @_;
558 9 my $authority_explanation = $self->{authority_explanation};
559  
560 9 ▶ return $authority_explanation
Branch: 1 branch
BranchTrueFalseTotal
if defined $authority_explanation 0 9 9
561 if defined($authority_explanation);
562  
563 9 my $server = $self->{server};
564 9 my $request = $self->{request};
565  
566 9 my $authority_explanation_macrostring = $request->state('authority_explanation');
567  
568 # If an explicit explanation was specified by the authority domain...
569 9 ▶ if (defined($authority_explanation_macrostring)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $authority_explanation_macrostring) 5 4 9
570 5 ▶ try {
Subroutine __ANON__: called CC=3 SCAR=14.2
571 # ... then try to expand it:
572 5 $authority_explanation = $authority_explanation_macrostring->expand;
573 # SPF explanation text is restricted to 7-bit ascii
574 3 ▶ if(defined $authority_explanation and utf8::is_utf8($authority_explanation)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $authority_explanation and utf8::is_utf8($authority_explanation)) 0 3 3
Condition33%1/3
defined $authority_explanation and utf8::is_utf8($authority_explanation)
!ll&&!rl&&r
030
MC/DC0%0/2
defined $authority_explanation and utf8::is_utf8($authority_explanation)
defined $authority_explanation utf8::is_utf8($authority_explanation)
Truth table33%1/3
A and B
A= defined $authority_explanationB= utf8::is_utf8($authority_explanation)
ABresult
0X0
100
111
575 0 $authority_explanation = $server->default_authority_explanation->new(request => $request)->expand;
576 }
577 }
578 # Ignore expansion errors (e.g. invalid macros, or the void look-ups
579 # limit being exceeded by 'p' macros) and leave authority explanation
580 # undefined:
581 2 ▶ catch Mail::SPF::Exception with {
Subroutine __ANON__: called CC=1 SCAR=0.0
582 2 $authority_explanation = undef;
583 }
584 0 ▶ catch Mail::SPF::Result with {
Subroutine __ANON__: not called CC=1 SCAR=6.9
585 0 $authority_explanation = undef;
586 5 };
587 }
588  
589 # If no authority explanation could be determined so far...
590 9 ▶ if (not defined($authority_explanation)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $authority_explanation) 6 3 9
591 # ... then use the server's default authority explanation:
592 6 $authority_explanation =
593 $server->default_authority_explanation->new(request => $request)->expand;
594 }
595  
596 9 return $self->{authority_explanation} = Mail::SPF::Util->sanitize_string($authority_explanation);
597 }
598  
599 package Mail::SPF::Result::SoftFail;
600 6 our @ISA = 'Mail::SPF::Result';
601 6 ▶use constant code => 'softfail';
Subroutine BEGIN: called CC=1 SCAR=0.0
602  
603 package Mail::SPF::Result::Neutral;
604 6 our @ISA = 'Mail::SPF::Result';
605 6 ▶use constant code => 'neutral';
Subroutine BEGIN: called CC=1 SCAR=0.0
606  
607 package Mail::SPF::Result::NeutralByDefault;
608 6 our @ISA = 'Mail::SPF::Result::Neutral';
609 6 ▶use constant name => 'neutral-by-default';
Subroutine BEGIN: called CC=1 SCAR=0.0
610 # This is a special-case of the Neutral result that is thrown as a default
611 # when "falling off" the end of the record. See Mail::SPF::Record::eval().
612  
613 package Mail::SPF::Result::None;
614 6 our @ISA = 'Mail::SPF::Result';
615 6 ▶use constant code => 'none';
Subroutine BEGIN: called CC=1 SCAR=0.0
616  
617 package Mail::SPF::Result::Error;
618 6 our @ISA = 'Mail::SPF::Result';
619 6 ▶use constant code => 'error';
Subroutine BEGIN: called CC=1 SCAR=0.0
620  
621 package Mail::SPF::Result::PermError;
622 6 our @ISA = 'Mail::SPF::Result::Error';
623 6 ▶use constant code => 'permerror';
Subroutine BEGIN: called CC=1 SCAR=0.0
624  
625 package Mail::SPF::Result::TempError;
626 6 our @ISA = 'Mail::SPF::Result::Error';
627 6 ▶use constant code => 'temperror';
Subroutine BEGIN: called CC=1 SCAR=0.0
628  
629 =head1 SEE ALSO
630  
631 L<Mail::SPF>, L<Mail::SPF::Server>, L<Error>, L<perlfunc/eval>
632  
633 L<http://tools.ietf.org/html/rfc4408>
634  
635 For availability, support, and license information, see the README file
636 included with Mail::SPF.
637  
638 =head1 AUTHORS
639  
640 Julian Mehnle <julian@mehnle.net>
641  
642 =cut
643  
644 package Mail::SPF::Result;
645  
646 6 TRUE;
« SPF/Mod/Redirect.pm ↑ Summary SPF/Mech/PTR.pm »