| 1 | # | ||||||||||
| 2 | # Mail::SPF::Mech::Exists | ||||||||||
| 3 | # SPF record "exists" mechanism class. | ||||||||||
| 4 | # | ||||||||||
| 5 | # (C) 2005-2012 Julian Mehnle <julian@mehnle.net> | ||||||||||
| 6 | # 2005 Shevek <cpan@anarres.org> | ||||||||||
| 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<exists> mechanism 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 base 'Mail::SPF::Mech'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | |||||||||||
| 28 | 1 | ▶ | use constant TRUE => (0 == 0); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 1 | ▶ | use constant FALSE => not TRUE; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | 1 | ▶ | use constant name => 'exists'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 1 | ▶ | use constant name_pattern => qr/${\name}/i; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | |||||||||||
| 34 | =head1 DESCRIPTION | ||||||||||
| 35 | |||||||||||
| 36 | An object of class B<Mail::SPF::Mech::Exists> represents an SPF record | ||||||||||
| 37 | mechanism of type C<exists>. | ||||||||||
| 38 | |||||||||||
| 39 | =head2 Constructors | ||||||||||
| 40 | |||||||||||
| 41 | The following constructors are provided: | ||||||||||
| 42 | |||||||||||
| 43 | =over | ||||||||||
| 44 | |||||||||||
| 45 | =item B<new(%options)>: returns I<Mail::SPF::Mech::Exists> | ||||||||||
| 46 | |||||||||||
| 47 | Creates a new SPF record C<exists> 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<qualifier> | ||||||||||
| 55 | |||||||||||
| 56 | =item B<domain_spec> | ||||||||||
| 57 | |||||||||||
| 58 | See L<Mail::SPF::Mech/new>. | ||||||||||
| 59 | |||||||||||
| 60 | =back | ||||||||||
| 61 | |||||||||||
| 62 | =item B<new_from_string($text, %options)>: returns I<Mail::SPF::Mech::Exists>; | ||||||||||
| 63 | throws I<Mail::SPF::ENothingToParse>, I<Mail::SPF::EInvalidMech> | ||||||||||
| 64 | |||||||||||
| 65 | Creates a new SPF record C<exists> 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<default_qualifier> | ||||||||||
| 77 | |||||||||||
| 78 | =item B<qualifier_pattern> | ||||||||||
| 79 | |||||||||||
| 80 | See L<Mail::SPF::Mech/Class methods>. | ||||||||||
| 81 | |||||||||||
| 82 | =item B<name>: returns I<string> | ||||||||||
| 83 | |||||||||||
| 84 | Returns B<'exists'>. | ||||||||||
| 85 | |||||||||||
| 86 | =item B<name_pattern>: returns I<Regexp> | ||||||||||
| 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 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
parse_params: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 102 | 0 | $self->parse_domain_spec(TRUE); | |||||||||
| 103 | 0 | return; | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | =item B<text> | ||||||||||
| 107 | |||||||||||
| 108 | =item B<qualifier> | ||||||||||
| 109 | |||||||||||
| 110 | =item B<params> | ||||||||||
| 111 | |||||||||||
| 112 | =cut | ||||||||||
| 113 | |||||||||||
| 114 | sub params { | ||||||||||
| 115 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
params: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 116 | 0 | ▶ | return defined($self->{domain_spec}) ? ':' . $self->{domain_spec} : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | =item B<stringify> | ||||||||||
| 120 | |||||||||||
| 121 | See L<Mail::SPF::Mech/Instance methods>. | ||||||||||
| 122 | |||||||||||
| 123 | =item B<domain_spec>: returns I<Mail::SPF::MacroString> | ||||||||||
| 124 | |||||||||||
| 125 | Returns the C<domain-spec> parameter of the mechanism. | ||||||||||
| 126 | |||||||||||
| 127 | =cut | ||||||||||
| 128 | |||||||||||
| 129 | # Make read-only accessor: | ||||||||||
| 130 | 1 | __PACKAGE__->make_accessor('domain_spec', TRUE); | |||||||||
| 131 | |||||||||||
| 132 | =item B<match($server, $request)>: returns I<boolean> | ||||||||||
| 133 | |||||||||||
| 134 | Checks whether a DNS C<A> record exists for the mechanism's target domain name, | ||||||||||
| 135 | and returns B<true> if one does, or B<false> otherwise. See RFC 4408, 5.7, for | ||||||||||
| 136 | details. | ||||||||||
| 137 | |||||||||||
| 138 | =cut | ||||||||||
| 139 | |||||||||||
| 140 | sub match { | ||||||||||
| 141 | 0 | ▶ | my ($self, $server, $request) = @_; | ||||||||
|
Subroutine
match: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 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 | ▶ | my @rrs = $packet->answer | ||||||||
|
Branch: 1 branch
| |||||||||||
| 148 | or $server->count_void_dns_lookup($request); | ||||||||||
| 149 | |||||||||||
| 150 | 0 | foreach my $rr (@rrs) { | |||||||||
| 151 | 0 | ▶ | return TRUE | ||||||||
|
Branch: 1 branch
| |||||||||||
| 152 | if $rr->type eq 'A'; | ||||||||||
| 153 | } | ||||||||||
| 154 | 0 | return FALSE; | |||||||||
| 155 | } | ||||||||||
| 156 | |||||||||||
| 157 | =back | ||||||||||
| 158 | |||||||||||
| 159 | =head1 SEE ALSO | ||||||||||
| 160 | |||||||||||
| 161 | L<Mail::SPF>, L<Mail::SPF::Record>, L<Mail::SPF::Term>, L<Mail::SPF::Mech> | ||||||||||
| 162 | |||||||||||
| 163 | L<http://tools.ietf.org/html/rfc4408> | ||||||||||
| 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 <julian@mehnle.net>, Shevek <cpan@anarres.org> | ||||||||||
| 171 | |||||||||||
| 172 | =cut | ||||||||||
| 173 | |||||||||||
| 174 | 1 | TRUE; | |||||||||