SPF/Request.pm

filter: Statementstmt 96.9% 94 / 97 Branchbran 87.5% 42 / 48 Conditioncond 65.3% 17 / 26 MC/DCmcdc 43.7% 7 / 16 Subroutinesub 100% 16 / 16 Podpod 83.3% 5 / 6 totaltotal 86.6% 181 / 209 CC 34 SCAR 29.4
CC
34
Cov
89%
new
30.9
state
3.0
root_request
2.3
CRAP 18.9
« SPF/Mech/MX.pm ↑ Summary SPF/v1/Record.pm »
1 #
2 # Mail::SPF::Request
3 # SPF request class.
4 #
5 # (C) 2005-2012 Julian Mehnle <julian@mehnle.net>
6 # 2005 Shevek <cpan@anarres.org>
7 # $Id: Request.pm 57 2012-01-30 08:15:31Z julian $
8 #
9 ##############################################################################
10  
11 package Mail::SPF::Request;
12  
13 =head1 NAME
14  
15 Mail::SPF::Request - SPF request class
16  
17 =head1 VERSION
18  
19 version 3.20261105
20  
21 =cut
22  
23 8 our $VERSION = '3.20261105'; # VERSION
24  
25 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 8 ▶use base 'Mail::SPF::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 8 ▶use NetAddr::IP;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 8 ▶use Mail::SPF::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 8 ▶use constant TRUE => (0 == 0);
Subroutine BEGIN: called CC=1 SCAR=0.0
35 8 ▶use constant FALSE => not TRUE;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 8 ▶use constant versions_for_scope => {
Subroutine BEGIN: called CC=1 SCAR=0.0
38 helo => [1 ],
39 mfrom => [1, 2],
40 pra => [ 2]
41 8 };
42  
43 8 ▶use constant scopes_by_version => {
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 => ['helo', 'mfrom' ],
45 2 => [ 'mfrom', 'pra']
46 8 };
47  
48 8 ▶use constant default_localpart => 'postmaster';
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 # Interface:
51 ##############################################################################
52  
53 =head1 SYNOPSIS
54  
55 use Mail::SPF;
56  
57 my $request = Mail::SPF::Request->new(
58 versions => [1, 2], # optional
59 scope => 'mfrom', # or 'helo', 'pra'
60 identity => 'fred@example.com',
61 ip_address => '192.168.0.1',
62 helo_identity # optional,
63 => 'mta.example.com' # for %{h} macro expansion
64 );
65  
66 my @versions = $request->versions;
67 my $scope = $request->scope;
68 my $authority_domain
69 = $request->authority_domain;
70 my $identity = $request->identity; # 'localpart@domain' or 'domain'
71 my $domain = $request->domain;
72 my $localpart = $request->localpart;
73 my $ip_address = $request->ip_address; # IPv4 or IPv6 address
74 my $ip_address_v6 # native IPv6 address or
75 = $request->ip_address_v6; # IPv4-mapped IPv6 address
76 my $helo_identity # additional HELO identity
77 = $request->helo_identity; # for non-HELO scopes
78  
79 my $record = $request->record;
80 # the record selected during processing of the request, may be undef
81  
82 $request->state(field => 'value');
83 my $value = $request->state('field');
84  
85 =cut
86  
87 # Implementation:
88 ##############################################################################
89  
90 =head1 DESCRIPTION
91  
92 An object of class B<Mail::SPF::Request> represents an SPF request.
93  
94 =head2 Constructors
95  
96 The following constructors are provided:
97  
98 =over
99  
100 =item B<new(%options)>: returns I<Mail::SPF::Request>
101  
102 Creates a new SPF request object. The request is considered the
103 I<root-request> for any subsequent sub-requests (see the L</new_sub_request>
104 constructor).
105  
106 %options is a list of key/value pairs representing any of the following
107 options:
108  
109 =over
110  
111 =item B<versions>
112  
113 A reference to an I<array> of I<integer>s listing the versions of SPF records
114 that may be used for the SPF check. Only those record versions that cover the
115 desired scope will actually be used. At least one applicable version must be
116 specified. For a single record version, a simple scalar may be specified
117 instead of an array-ref. Defaults to all versions that cover the desired scope
118 (see below); defaults to B<[1, 2]> for the default scope of B<'mfrom'>.
119  
120 The following versions are supported:
121  
122 =over
123  
124 =item B<1>
125  
126 Use C<v=spf1> records.
127  
128 =item B<2>
129  
130 Use C<spf2.0> records.
131  
132 =back
133  
134 I<Example>: A value of B<1> (or B<[1]>) means that only C<v=spf1> records
135 should be used for the SPF check. If at the same time a scope of B<'pra'> is
136 specified, a I<Mail::SPF::EInvalidScope> exception will be thrown as C<v=spf1>
137 records do not cover the PRA scope.
138  
139 =item B<scope>
140  
141 A string denoting the authorization scope of the identity that should be
142 checked. Defaults to B<'mfrom'>. The following scope values are supported:
143  
144 =over
145  
146 =item B<'helo'>
147  
148 The given identity is the C<HELO> parameter of an SMTP transaction (RFC 2821)
149 and should be checked against SPF records that cover the C<helo> scope
150 (C<v=spf1>). See the SPFv1 specification (RFC 4408) for the formal definition
151 of the C<HELO> scope.
152  
153 =item B<'mfrom'>
154  
155 The given identity is the C<MAIL FROM> parameter of an SMTP transaction (RFC
156 2821), and should be checked against SPF records that cover the C<mfrom> scope
157 (C<v=spf1> and C<spf2.0/mfrom>). See the SPFv1 specification (RFC 4408) for
158 the formal definition of the C<MAIL FROM> scope.
159  
160 I<Note>: In the case of an empty C<MAIL FROM> SMTP transaction parameter (C<<
161 MAIL FROM:<> >>), the identity checked will be postmaster@helo name as specified
162 in RFC 7208.
163  
164 =item B<'pra'>
165  
166 The given identity is the "Purported Responsible Address" of an internet
167 message (RFC 2822) and should be checked against SPF records that cover the
168 C<pra> scope (C<spf2.0/pra>). See the PRA specification (RFC 4407) for the
169 formal definition of the PRA scope.
170  
171 =back
172  
173 =item B<authority_domain>
174  
175 A string denoting the domain name that should be queried for sender policy
176 records. Defaults to the domain of the C<identity> option. There is usually
177 no need to specify the C<authority_domain> option.
178  
179 =item B<identity>
180  
181 I<Required>. A string denoting the sender identity whose authorization should
182 be checked. This is a domain name for the C<helo> scope, and an e-mail address
183 for the C<mfrom> and C<pra> scopes.
184  
185 I<Note>: An empty identity should not be passed, in the case of an empty
186 C<MAIL FROM> SMTP transaction parameter (C<<MAIL FROM:<> >>),
187 the identity checked will be postmaster@helo name as specified
188 in RFC 7208.
189  
190 =item B<ip_address>
191  
192 I<Required> for checks with the C<helo>, C<mfrom>, and C<pra> scopes. Either a
193 string or a I<NetAddr::IP> object denoting the IP address of the host claiming
194 the identity that is being checked. Can be either an IPv4 or an IPv6 address.
195 An IPv4-mapped IPv6 address (e.g. '::ffff:192.168.0.1') is treated as an IPv4
196 address. It must be a single host address; a network (e.g. '10.0.0.0/8') is
197 rejected with a I<Mail::SPF::EInvalidOptionValue> exception.
198  
199 =item B<helo_identity>
200  
201 A string denoting the C<HELO> SMTP transaction parameter in the case that the
202 main identity is of a scope other than C<helo>. This identity is then used
203 merely for the expansion of C<%{h}> macros during the policy evaluation of the
204 main identity. Defaults to B<undef>, which will be expanded to B<'unknown'>.
205 If the main identity is of the C<helo> scope, this option is unused.
206  
207 =back
208  
209 =cut
210  
211 73 ▶sub new {
Subroutine new: called CC=29 SCAR=34.3
Pod documented
212 73 my ($self, %options) = @_;
213  
214 # Create new object:
215 73 $self = $self->SUPER::new(%options);
216 # If the request object already has a state hash, clone its contents:
217 8 $self->{state} = { %{$self->{state}} }
218 73 ▶ if ref($self->{state}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"state"} eq "HASH" 8 65 73
219  
220 # Scope:
221 73 ▶ $self->{scope} ||= 'mfrom';
Condition100%2/2
$self->{"scope"} ||= "mfrom"
l!l
2746
MC/DC100%1/1
$self->{"scope"} ||= "mfrom"
$self->{"scope"}
Truth table100%2/2
A
A= $self->{"scope"}
Aresult
11
00
222 my $versions_for_scope = $self->versions_for_scope->{$self->{scope}}
223 73 ▶ or throw Mail::SPF::EInvalidScope("Invalid scope '$self->{scope}'");
Branch: 1 branch
BranchTrueFalseTotal
my $versions_for_scope = $self->versions_for_scope->{$self->{"scope"}} or "Mail::SPF::EInvalidScope"->throw(qq[Invalid scope '$self->{"scope"}']) 72 1 73
224  
225 # Versions:
226 72 ▶ if (not defined($self->{versions})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'versions'}) { } 56 16 72
227 # No versions specified, use all versions relevant to scope:
228 56 $self->{versions} = $versions_for_scope;
229 }
230 else {
231 16 ▶ if (not ref($self->{versions})) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $self->{'versions'}) { } 2 14 16
elsif (ref $self->{'versions'} ne 'ARRAY') { } 1 13 14
232 # Single version specified as scalar:
233 2 $self->{versions} = [$self->{versions}];
234 }
235 elsif (ref($self->{versions}) ne 'ARRAY') {
236 # Something other than scalar or array-ref specified:
237 1 throw Mail::SPF::EInvalidOptionValue(
238 "'versions' option must be string or array-ref");
239 }
240  
241 # All requested record versions must be supported:
242 my @unsupported_versions = grep(
243 (not defined($self->scopes_by_version->{$_})),
244 15 @{$self->{versions}}
245 );
246 not @unsupported_versions
247 15 ▶ or throw Mail::SPF::EInvalidOptionValue(
Branch: 1 branch
BranchTrueFalseTotal
@unsupported_versions and "Mail::SPF::EInvalidOptionValue"->throw('Unsupported record version(s) ' . join(", ", map(("'${_}'"), @unsupported_versions))) 1 14 15
248 'Unsupported record version(s) ' .
249 join(', ', map("'$_'", @unsupported_versions)));
250  
251 # Use only those record versions that are relevant to the requested scope:
252 14 my %versions_for_scope;
253 14 @versions_for_scope{@$versions_for_scope} = ();
254 14 my @versions = grep(exists($versions_for_scope{$_}), @{$self->{versions}});
255  
256 # Require at least one relevant record version that covers the scope:
257 @versions
258 or throw Mail::SPF::EInvalidScope(
259 "Invalid scope '$self->{scope}' for record version(s) " .
260 14 ▶ join(', ', @{$self->{versions}}));
Branch: 1 branch
BranchTrueFalseTotal
@versions or "Mail::SPF::EInvalidScope"->throw(qq[Invalid scope '$self->{"scope"}' for record version(s) ] . join(", ", @{$self->{"versions"};})) 13 1 14
261  
262 13 $self->{versions} = \@versions;
263 }
264  
265 # Identity:
266 defined($self->{identity})
267 69 ▶ or throw Mail::SPF::EOptionRequired("Missing required 'identity' option");
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"identity"} or "Mail::SPF::EOptionRequired"->throw("Missing required 'identity' option") 68 1 69
268 68 ▶ if(not length($self->{identity}) and (defined $self->{helo_identity})) {
Branch: 2 branches
BranchTrueFalseTotal
if (not length $self->{'identity'} and defined $self->{'helo_identity'}) { } 0 68 68
elsif (not length $self->{'identity'}) { } 0 68 68
Condition33%1/3
not length $self->{"identity"} and defined $self->{"helo_identity"}
!ll&&!rl&&r
6800
MC/DC0%0/2
not length $self->{"identity"} and defined $self->{"helo_identity"}
not length $self->{"identity"} defined $self->{"helo_identity"}
Truth table33%1/3
not(A) and B
A= not length $self->{"identity"}B= defined $self->{"helo_identity"}
ABresult
0X0
100
111
269 # if identity is <>, try with postmaster@helo as specified in RFC 7208 section 2.4
270 0 $self->{identity} = 'postmaster@' . $self->{helo_identity};
271 } elsif(not length($self->{identity})) {
272 0 throw Mail::SPF::EInvalidOptionValue("'identity' option must not be empty without specifying HELO");
273 }
274  
275 # Extract domain and localpart from identity:
276 68 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'scope'} eq 'mfrom' || $self->{'scope'} eq 'pra' and $self->{'identity'} =~ /^(.*)@(.*?)$/) { } 60 8 68
Condition83%5/6
$self->{"scope"} eq "mfrom" || $self->{"scope"} eq "pra" and $self->{"identity"} =~ /^(.*)@(.*?)$/
!ll&&!rl&&r
5360
$self->{"scope"} eq "mfrom" or $self->{"scope"} eq "pra"
l!l&&r!l&&!r
6305
MC/DC66%2/3
$self->{"scope"} eq "mfrom" || $self->{"scope"} eq "pra" and $self->{"identity"} =~ /^(.*)@(.*?)$/
$self->{"scope"} eq "mfrom" $self->{"scope"} eq "pra" $self->{"identity"} =~ /^(.*)@(.*?)$/
Truth table60%3/5
A or B and C
A= $self->{"scope"} eq "mfrom"B= $self->{"scope"} eq "pra"C= $self->{"identity"} =~ /^(.*)@(.*?)$/
ABCresult
00X0
1X00
0100
1X11
0111
277 ($self->{scope} eq 'mfrom' or $self->{scope} eq 'pra') and
278 $self->{identity} =~ /^(.*)@(.*?)$/
279 ) {
280 60 $self->{domain} = $2;
281 60 $self->{localpart} = $1;
282 }
283 else {
284 8 $self->{domain} = $self->{identity};
285 }
286 68 $self->{domain} =~ s/^(.*?)\.?$/\L$1/;
287 # Lower-case domain and remove eventual trailing dot.
288 $self->{localpart} = $self->default_localpart
289 68 ▶ if not defined($self->{localpart}) or not length($self->{localpart});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"localpart"} and length $self->{"localpart"} 8 60 68
Condition66%2/3
defined $self->{"localpart"} and length $self->{"localpart"}
!ll&&!rl&&r
8060
MC/DC50%1/2
defined $self->{"localpart"} and length $self->{"localpart"}
defined $self->{"localpart"} length $self->{"localpart"}
Truth table66%2/3
A and B
A= defined $self->{"localpart"}B= length $self->{"localpart"}
ABresult
0X0
100
111
290  
291 # HELO identity:
292 68 ▶ if ($self->{scope} eq 'helo') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"scope"} eq "helo") 5 63 68
293 5 ▶ $self->{helo_identity} ||= $self->{identity};
Condition33%1/3
$self->{"helo_identity"} ||= $self->{"identity"}
l!l&&r!l&&!r
050
MC/DC0%0/2
$self->{"helo_identity"} ||= $self->{"identity"}
$self->{"helo_identity"} $self->{"identity"}
Truth table33%1/3
A ||= B
A= $self->{"helo_identity"}B= $self->{"identity"}
ABresult
1X1
011
000
294 }
295  
296 # IP address:
297 throw Mail::SPF::EOptionRequired("Missing required 'ip_address' option")
298 if grep($self->{scope} eq $_, qw(helo mfrom pra))
299 68 ▶ and not defined($self->{ip_address});
Branch: 1 branch
BranchTrueFalseTotal
if grep(($self->{"scope"} eq $_), ("helo", "mfrom", "pra")) and not defined $self->{"ip_address"} 1 67 68
Condition66%2/3
grep(($self->{"scope"} eq $_), ("helo", "mfrom", "pra")) and not defined $self->{"ip_address"}
!ll&&!rl&&r
0671
MC/DC50%1/2
grep(($self->{"scope"} eq $_), ("helo", "mfrom", "pra")) and not defined $self->{"ip_address"}
grep(($self->{"scope"} eq $_), ("helo", "mfrom", "pra")) not defined $self->{"ip_address"}
Truth table66%2/3
A and not(B)
A= grep(($self->{"scope"} eq $_), ("helo", "mfrom", "pra"))B= not defined $self->{"ip_address"}
ABresult
0X0
100
111
300  
301 # Ensure ip_address is a NetAddr::IP object:
302 67 ▶ if (not UNIVERSAL::isa($self->{ip_address}, 'NetAddr::IP')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($self->{"ip_address"}, "NetAddr::IP")) 58 9 67
303 my $ip_address = NetAddr::IP->new($self->{ip_address})
304 58 ▶ or throw Mail::SPF::EInvalidOptionValue("Invalid IP address '$self->{ip_address}'");
Branch: 1 branch
BranchTrueFalseTotal
my $ip_address = "NetAddr::IP"->new($self->{"ip_address"}) or "Mail::SPF::EInvalidOptionValue"->throw(qq[Invalid IP address '$self->{"ip_address"}']) 58 0 58
305 58 $self->{ip_address} = $ip_address;
306 }
307  
308 # The IP address must be a single host, not a network:
309 67 ▶ $self->{ip_address}->masklen == ($self->{ip_address}->version == 4 ? 32 : 128)
Branch: 2 branches
BranchTrueFalseTotal
$self->{"ip_address"}->masklen == ($self->{"ip_address"}->version == 4 ? 32 : 128) or "Mail::SPF::EInvalidOptionValue"->throw(qq[IP address '$self->{"ip_address"}' is not a single host address]) 65 2 67
$self->{'ip_address'}->version == 4 ? : 61 6 67
310 or throw Mail::SPF::EInvalidOptionValue(
311 "IP address '$self->{ip_address}' is not a single host address");
312  
313 # Convert IPv4 address to IPv4-mapped IPv6 address:
314 65 ▶ if (Mail::SPF::Util->ipv6_address_is_ipv4_mapped($self->{ip_address})) {
Branch: 3 branches
BranchTrueFalseTotal
if ('Mail::SPF::Util'->ipv6_address_is_ipv4_mapped($self->{'ip_address'})) { } 2 63 65
elsif ($self->{'ip_address'}->version == 4) { } 60 3 63
elsif ($self->{'ip_address'}->version == 6) { } 3 0 3
315 2 $self->{ip_address_v6} = $self->{ip_address}; # Accept as IPv6 address as-is.
316 2 $self->{ip_address} = Mail::SPF::Util->ipv6_address_to_ipv4($self->{ip_address});
317 }
318 elsif ($self->{ip_address}->version == 4) {
319 60 $self->{ip_address_v6} = Mail::SPF::Util->ipv4_address_to_ipv6($self->{ip_address});
320 }
321 elsif ($self->{ip_address}->version == 6) {
322 3 $self->{ip_address_v6} = $self->{ip_address};
323 }
324 else {
325 throw Mail::SPF::EInvalidOptionValue(
326 0 "Unexpected IP address version '" . $self->{ip_address}->version . "'");
327 }
328  
329 65 return $self;
330 }
331  
332 =item B<new_sub_request(%options)>: returns I<Mail::SPF::Request>
333  
334 Must be invoked on an existing request object. Creates a new sub-request
335 object by cloning the invoked request, which is then considered the new
336 request's I<super-request>. Any specified options (see the L</new>
337 constructor) override the parameters of the super-request. There is usually no
338 need to specify any options I<besides> the C<authority_domain> option.
339  
340 =cut
341  
342 6 ▶sub new_sub_request {
Subroutine new_sub_request: called CC=2 SCAR=7.0
Pod documented
343 6 my ($super_request, %options) = @_;
344 6 ▶ UNIVERSAL::isa($super_request, __PACKAGE__)
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($super_request, __PACKAGE__) or "Mail::SPF::EInstanceMethod"->throw 6 0 6
345 or throw Mail::SPF::EInstanceMethod;
346 6 my $self = $super_request->new(%options);
347 6 $self->{super_request} = $super_request;
348 6 $self->{root_request} = $super_request->root_request;
349 6 return $self;
350 }
351  
352 =back
353  
354 =head2 Instance methods
355  
356 The following instance methods are provided:
357  
358 =over
359  
360 =item B<root_request>: returns I<Mail::SPF::Request>
361  
362 Returns the root of the request's chain of super-requests. Specifically,
363 returns the request itself if it has no super-requests.
364  
365 =cut
366  
367 87 ▶sub root_request {
Subroutine root_request: called CC=2 SCAR=8.1
Pod undocumented
368 87 my ($self) = @_;
369 # Read-only!
370 87 ▶ return $self->{root_request} || $self;
Condition33%1/3
$self->{'root_request'} || $self
l!l&&r!l&&!r
0870
MC/DC0%0/2
$self->{'root_request'} || $self
$self->{'root_request'} $self
Truth table33%1/3
A || B
A= $self->{'root_request'}B= $self
ABresult
1X1
011
000
371 }
372  
373 =item B<super_request>: returns I<Mail::SPF::Request>
374  
375 Returns the super-request of the request, or B<undef> if there is none.
376  
377 =cut
378  
379 # Make read-only accessor:
380 8 __PACKAGE__->make_accessor('super_request', TRUE);
381  
382 =item B<versions>: returns I<list> of I<string>
383  
384 Returns a list of the SPF record versions that are used for request. See the
385 description of the L</new> constructor's C<versions> option.
386  
387 =cut
388  
389 45 ▶sub versions {
Subroutine versions: called CC=1 SCAR=0.0
Pod documented
390 45 my ($self) = @_;
391 # Read-only!
392 45 return @{$self->{versions}};
393 }
394  
395 =item B<scope>: returns I<string>
396  
397 Returns the scope of the request. See the description of the L</new>
398 constructor's C<scope> option.
399  
400 =item B<authority_domain>: returns I<string>
401  
402 Returns the authority domain of the request. See the description of the
403 L</new> constructor's C<authority_domain> option.
404  
405 =cut
406  
407 150 ▶sub authority_domain {
Subroutine authority_domain: called CC=2 SCAR=6.9
Pod documented
408 150 my ($self) = @_;
409 150 ▶ return $self->{authority_domain} || $self->{domain};
Condition100%3/3
$self->{'authority_domain'} || $self->{'domain'}
l!l&&r!l&&!r
171303
MC/DC100%2/2
$self->{'authority_domain'} || $self->{'domain'}
$self->{'authority_domain'} $self->{'domain'}
Truth table100%3/3
A || B
A= $self->{'authority_domain'}B= $self->{'domain'}
ABresult
1X1
011
000
410 }
411  
412 =item B<identity>: returns I<string>
413  
414 Returns the identity of the request. See the description of the L</new>
415 constructor's C<identity> option.
416  
417 =item B<domain>: returns I<string>
418  
419 Returns the identity domain of the request. See the description of the
420 L</new> constructor's C<identity> option.
421  
422 =item B<localpart>: returns I<string>
423  
424 Returns the identity localpart of the request. See the description of the
425 L</new> constructor's C<identity> option.
426  
427 =item B<ip_address>: returns I<NetAddr::IP>
428  
429 Returns the IP address of the request as a I<NetAddr::IP> object. See the
430 description of the L</new> constructor's C<ip_address> option.
431  
432 =item B<ip_address_v6>: returns I<NetAddr::IP>
433  
434 Like the C<ip_address> method, however, an IPv4 address is returned as an
435 IPv4-mapped IPv6 address (e.g. '::ffff:192.168.0.1') to facilitate uniform
436 processing.
437  
438 =item B<helo_identity>: returns I<string>
439  
440 Returns the C<HELO> SMTP transaction parameter of the request. See the
441 description of the L</new> constructor's C<helo_identity> option.
442  
443 =cut
444  
445 # Make read-only accessors:
446 __PACKAGE__->make_accessor($_, TRUE)
447 8 foreach qw(
448 scope identity domain localpart
449 ip_address ip_address_v6 helo_identity
450 );
451  
452 =item B<record>: returns I<Mail::SPF::Record>
453  
454 Returns the SPF record selected during the processing of the request, or
455 B<undef> if there is none.
456  
457 =cut
458  
459 # Make read/write accessor:
460 8 __PACKAGE__->make_accessor('record', FALSE);
461  
462 =item B<state($field)>: returns anything
463  
464 =item B<state($field, $value)>: returns anything
465  
466 Provides an interface for storing temporary state information with the request
467 object. This is primarily meant to be used internally by I<Mail::SPF::Server>
468 and other Mail::SPF classes.
469  
470 If C<$value> is specified, stores it in a state field named C<$field>. Returns
471 the current (new) value of the state field named C<$field>. This method may be
472 used as an lvalue.
473  
474 =cut
475  
476 286 ▶sub state :lvalue {
Subroutine state: called CC=3 SCAR=11.0
Pod documented
477 286 my ($self, $field, @value) = @_;
478 286 ▶ defined($field)
Branch: 1 branch
BranchTrueFalseTotal
defined $field or "Mail::SPF::EOptionRequired"->throw("Field name required") 286 0 286
479 or throw Mail::SPF::EOptionRequired('Field name required');
480 286 ▶ $self->{state}->{$field} = $value[0]
Branch: 1 branch
BranchTrueFalseTotal
if @value 195 91 286
481 if @value;
482 286 $self->{state}->{$field};
483 }
484  
485 =back
486  
487 =head1 SEE ALSO
488  
489 L<Mail::SPF>, L<Mail::SPF::Server>
490  
491 L<http://tools.ietf.org/html/rfc4408>
492  
493 For availability, support, and license information, see the README file
494 included with Mail::SPF.
495  
496 =head1 AUTHORS
497  
498 Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org>
499  
500 =cut
501  
502 8 TRUE;
« SPF/Mech/MX.pm ↑ Summary SPF/v1/Record.pm »