File Coverage

blib/lib/Mail/SPF/Mod/Redirect.pm
Criterion Covered Total %
statement 28 41 68.2
branch 0 4 0.0
condition n/a
subroutine 9 12 75.0
pod 2 3 66.6
total 39 60 65.0


line stmt bran cond sub pod time code
1             #
2             # Mail::SPF::Mod::Redirect
3             # SPF record "redirect" modifier class.
4             #
5             # (C) 2005-2012 Julian Mehnle
6             # 2005 Shevek
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 modifier class
16              
17             =head1 VERSION
18              
19             version 3.20250505
20              
21             =cut
22              
23 1     1   1734 use warnings;
  1         3  
  1         116  
24 1     1   8 use strict;
  1         3  
  1         30  
25              
26 1     1   6 use Mail::SPF::Mod;
  1         2  
  1         27  
27 1     1   5 use base 'Mail::SPF::GlobalMod';
  1         2  
  1         405  
28              
29 1     1   11 use constant TRUE => (0 == 0);
  1         3  
  1         101  
30 1     1   8 use constant FALSE => not TRUE;
  1         2  
  1         62  
31              
32 1     1   7 use constant name => 'redirect';
  1         3  
  1         88  
33 1     1   7 use constant name_pattern => qr/${\name}/i;
  1         3  
  1         4  
  1         76  
34              
35 1     1   8 use constant precedence => 0.8;
  1         3  
  1         408  
36              
37             =head1 DESCRIPTION
38              
39             An object of class B represents an SPF record
40             modifier of type C.
41              
42             =head2 Constructors
43              
44             The following constructors are provided:
45              
46             =over
47              
48             =item B: returns I
49              
50             Creates a new SPF record C 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
58              
59             See L.
60              
61             =back
62              
63             =item B: returns I;
64             throws I, I
65              
66             Creates a new SPF record C 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: returns I
78              
79             Returns B<'redirect'>.
80              
81             =item B: returns I
82              
83             Returns a regular expression that matches a modifier name of B<'redirect'>.
84              
85             =item B: returns I
86              
87             Returns a precedence value of B<0.8>. See L.
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     0 0   my ($self) = @_;
101 0           $self->parse_domain_spec(TRUE);
102 0           return;
103             }
104              
105             =item B
106              
107             See L.
108              
109             =cut
110              
111             sub params {
112 0     0 1   my ($self) = @_;
113 0           return $self->{domain_spec};
114             }
115              
116             =item B: returns I
117              
118             Returns the C parameter of the modifier.
119              
120             =cut
121              
122             # Make read-only accessor:
123             __PACKAGE__->make_accessor('domain_spec', TRUE);
124              
125             =item B: throws I
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 result is thrown. See RFC 4408, 6.1, for
133             details.
134              
135             =cut
136              
137             sub process {
138 0     0 1   my ($self, $server, $request, $result) = @_;
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 0         $result->isa('Mail::SPF::Result::NeutralByDefault')
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 0         $server->throw_result('permerror', $request,
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 for other supported instance methods.
165              
166             =head1 SEE ALSO
167              
168             L, L, L, L
169              
170             L
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 , Shevek
178              
179             =cut
180              
181             TRUE;