File Coverage

blib/lib/Mail/SPF/Mech/Exists.pm
Criterion Covered Total %
statement 22 35 62.8
branch 0 6 0.0
condition n/a
subroutine 7 10 70.0
pod 2 3 66.6
total 31 54 57.4


line stmt bran cond sub pod time code
1             #
2             # Mail::SPF::Mech::Exists
3             # SPF record "exists" mechanism class.
4             #
5             # (C) 2005-2012 Julian Mehnle
6             # 2005 Shevek
7             # $Id: Exists.pm 57 2012-01-30 08:15:31Z julian $
8             #
9             ##############################################################################
10              
11             package Mail::SPF::Mech::Exists;
12              
13             =head1 NAME
14              
15             Mail::SPF::Mech::Exists - SPF record C mechanism class
16              
17             =head1 VERSION
18              
19             version 3.20250505
20              
21             =cut
22              
23 1     1   1554 use warnings;
  1         5  
  1         71  
24 1     1   6 use strict;
  1         3  
  1         32  
25              
26 1     1   5 use base 'Mail::SPF::Mech';
  1         3  
  1         160  
27              
28 1     1   8 use constant TRUE => (0 == 0);
  1         2  
  1         94  
29 1     1   8 use constant FALSE => not TRUE;
  1         10  
  1         64  
30              
31 1     1   7 use constant name => 'exists';
  1         3  
  1         122  
32 1     1   7 use constant name_pattern => qr/${\name}/i;
  1         3  
  1         2  
  1         506  
33              
34             =head1 DESCRIPTION
35              
36             An object of class B represents an SPF record
37             mechanism of type C.
38              
39             =head2 Constructors
40              
41             The following constructors are provided:
42              
43             =over
44              
45             =item B: returns I
46              
47             Creates a new SPF record C mechanism object.
48              
49             %options is a list of key/value pairs representing any of the following
50             options:
51              
52             =over
53              
54             =item B
55              
56             =item B
57              
58             See L.
59              
60             =back
61              
62             =item B: returns I;
63             throws I, I
64              
65             Creates a new SPF record C mechanism object by parsing the string and
66             any options given.
67              
68             =back
69              
70             =head2 Class methods
71              
72             The following class methods are provided:
73              
74             =over
75              
76             =item B
77              
78             =item B
79              
80             See L.
81              
82             =item B: returns I
83              
84             Returns B<'exists'>.
85              
86             =item B: returns I
87              
88             Returns a regular expression that matches a mechanism name of B<'exists'>.
89              
90             =back
91              
92             =head2 Instance methods
93              
94             The following instance methods are provided:
95              
96             =over
97              
98             =cut
99              
100             sub parse_params {
101 0     0 0   my ($self) = @_;
102 0           $self->parse_domain_spec(TRUE);
103 0           return;
104             }
105              
106             =item B
107              
108             =item B
109              
110             =item B
111              
112             =cut
113              
114             sub params {
115 0     0 1   my ($self) = @_;
116 0 0         return defined($self->{domain_spec}) ? ':' . $self->{domain_spec} : undef;
117             }
118              
119             =item B
120              
121             See L.
122              
123             =item B: returns I
124              
125             Returns the C parameter of the mechanism.
126              
127             =cut
128              
129             # Make read-only accessor:
130             __PACKAGE__->make_accessor('domain_spec', TRUE);
131              
132             =item B: returns I
133              
134             Checks whether a DNS C record exists for the mechanism's target domain name,
135             and returns B if one does, or B otherwise. See RFC 4408, 5.7, for
136             details.
137              
138             =cut
139              
140             sub match {
141 0     0 1   my ($self, $server, $request) = @_;
142              
143 0           $server->count_dns_interactive_term($request);
144              
145 0           my $domain = $self->domain($server, $request);
146 0           my $packet = $server->dns_lookup($domain, 'A');
147 0 0         my @rrs = $packet->answer
148             or $server->count_void_dns_lookup($request);
149              
150 0           foreach my $rr (@rrs) {
151 0 0         return TRUE
152             if $rr->type eq 'A';
153             }
154 0           return FALSE;
155             }
156              
157             =back
158              
159             =head1 SEE ALSO
160              
161             L, L, L, L
162              
163             L
164              
165             For availability, support, and license information, see the README file
166             included with Mail::SPF.
167              
168             =head1 AUTHORS
169              
170             Julian Mehnle , Shevek
171              
172             =cut
173              
174             TRUE;