SPF/Mod/Redirect.pm

filter: Statementstmt 69.7% 30 / 43 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 9 / 12 Podpod 66.6% 2 / 3 totaltotal 66.1% 41 / 62 CC 3 SCAR 12.5
CC
3
Cov
64%
process
12.0
parse_params
2.0
params
2.0
CRAP 3.5
« SPF/Base.pm ↑ Summary SPF/Mech/IP6.pm »
1 #
2 # Mail::SPF::Mod::Redirect
3 # SPF record "redirect" modifier class.
4 #
5 # (C) 2005-2012 Julian Mehnle <julian@mehnle.net>
6 # 2005 Shevek <cpan@anarres.org>
7 # $Id: Redirect.pm 57 2012-01-30 08:15:31Z julian $
8 #
9 ##############################################################################
10  
11 package Mail::SPF::Mod::Redirect;
12  
13 =head1 NAME
14  
15 Mail::SPF::Mod::Redirect - SPF record C<redirect> modifier class
16  
17 =head1 VERSION
18  
19 version 3.20250505
20  
21 =cut
22  
23 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 1 ▶use Mail::SPF::Mod;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use base 'Mail::SPF::GlobalMod';
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 1 ▶use constant TRUE => (0 == 0);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use constant FALSE => not TRUE;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 1 ▶use constant name => 'redirect';
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use constant name_pattern => qr/${\name}/i;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 1 ▶use constant precedence => 0.8;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 =head1 DESCRIPTION
38  
39 An object of class B<Mail::SPF::Mod::Redirect> represents an SPF record
40 modifier of type C<redirect>.
41  
42 =head2 Constructors
43  
44 The following constructors are provided:
45  
46 =over
47  
48 =item B<new(%options)>: returns I<Mail::SPF::Mod::Redirect>
49  
50 Creates a new SPF record C<redirect> modifier object.
51  
52 %options is a list of key/value pairs representing any of the following
53 options:
54  
55 =over
56  
57 =item B<domain_spec>
58  
59 See L<Mail::SPF::Mod/new>.
60  
61 =back
62  
63 =item B<new_from_string($text, %options)>: returns I<Mail::SPF::Mod::Redirect>;
64 throws I<Mail::SPF::ENothingToParse>, I<Mail::SPF::EInvalidMod>
65  
66 Creates a new SPF record C<redirect> modifier object by parsing the string and
67 any options given.
68  
69 =back
70  
71 =head2 Class methods
72  
73 The following class methods are provided:
74  
75 =over
76  
77 =item B<name>: returns I<string>
78  
79 Returns B<'redirect'>.
80  
81 =item B<name_pattern>: returns I<Regexp>
82  
83 Returns a regular expression that matches a modifier name of B<'redirect'>.
84  
85 =item B<precedence>: returns I<real>
86  
87 Returns a precedence value of B<0.8>. See L<Mail::SPF::Mod/precedence>.
88  
89 =back
90  
91 =head2 Instance methods
92  
93 The following instance methods are provided:
94  
95 =over
96  
97 =cut
98  
99 sub parse_params {
100 0 ▶ my ($self) = @_;
Subroutine parse_params: not called CC=1 SCAR=6.9
Pod undocumented
101 0 $self->parse_domain_spec(TRUE);
102 0 return;
103 }
104  
105 =item B<params>
106  
107 See L<Mail::SPF::Mod/params>.
108  
109 =cut
110  
111 sub params {
112 0 ▶ my ($self) = @_;
Subroutine params: not called CC=1 SCAR=6.9
Pod documented
113 0 return $self->{domain_spec};
114 }
115  
116 =item B<domain_spec>: returns I<Mail::SPF::MacroString>
117  
118 Returns the C<domain-spec> parameter of the modifier.
119  
120 =cut
121  
122 # Make read-only accessor:
123 1 __PACKAGE__->make_accessor('domain_spec', TRUE);
124  
125 =item B<process($server, $request, $result)>: throws I<Mail::SPF::Result>
126  
127 If no mechanism matched during the evaluation of the current SPF record,
128 performs a recursive SPF check using the given SPF server and request objects
129 and substituting the modifier's target domain name for the request's authority
130 domain. The result of the recursive SPF check is then thrown as the result of
131 the current record's evaluation. However, if the target domain has no
132 acceptable SPF record, a C<permerror> result is thrown. See RFC 4408, 6.1, for
133 details.
134  
135 =cut
136  
137 sub process {
138 0 ▶ my ($self, $server, $request, $result) = @_;
Subroutine process: not called CC=3 SCAR=24.8
Pod documented
139  
140 0 $server->count_dns_interactive_term($request);
141  
142 # Only perform redirection if no mechanism matched (RFC 4408, 6.1/1):
143 0 ▶ $result->isa('Mail::SPF::Result::NeutralByDefault')
Branch: 1 branch
BranchTrueFalseTotal
$result->isa("Mail::SPF::Result::NeutralByDefault") or return 0 0 0
144 or return;
145  
146 # Create sub-request with mutated authority domain:
147 0 my $authority_domain = $self->{domain_spec}->new(server => $server, request => $request);
148 0 my $sub_request = $request->new_sub_request(authority_domain => $authority_domain);
149  
150 # Process sub-request:
151 0 $result = $server->process($sub_request);
152  
153 # Translate result of sub-request (RFC 4408, 6.1/4):
154 0 ▶ $server->throw_result('permerror', $request,
Branch: 1 branch
BranchTrueFalseTotal
if $result->isa("Mail::SPF::Result::None") 0 0 0
155 "Redirect domain '$authority_domain' has no applicable sender policy")
156 if $result->isa('Mail::SPF::Result::None');
157  
158 # Propagate any other results as-is:
159 0 $result->throw();
160 }
161  
162 =back
163  
164 See L<Mail::SPF::Mod> for other supported instance methods.
165  
166 =head1 SEE ALSO
167  
168 L<Mail::SPF>, L<Mail::SPF::Mod>, L<Mail::SPF::Term>, L<Mail::SPF::Record>
169  
170 L<http://tools.ietf.org/html/rfc4408>
171  
172 For availability, support, and license information, see the README file
173 included with Mail::SPF.
174  
175 =head1 AUTHORS
176  
177 Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org>
178  
179 =cut
180  
181 1 TRUE;
« SPF/Base.pm ↑ Summary SPF/Mech/IP6.pm »