| 1 | # | ||||||||||||||||||||||||||||
| 2 | # Mail::SPF::Mech::MX | ||||||||||||||||||||||||||||
| 3 | # SPF record "mx" mechanism class. | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # (C) 2005-2012 Julian Mehnle <julian@mehnle.net> | ||||||||||||||||||||||||||||
| 6 | # 2005 Shevek <cpan@anarres.org> | ||||||||||||||||||||||||||||
| 7 | # $Id: MX.pm 57 2012-01-30 08:15:31Z julian $ | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | ############################################################################## | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | package Mail::SPF::Mech::MX; | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Mail::SPF::Mech::MX - SPF record C<mx> mechanism class | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 VERSION | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | version 3.20261105 | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =cut | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 5 | our $VERSION = '3.20261105'; # VERSION | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 5 | ▶ | use base 'Mail::SPF::SenderIPAddrMech'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 5 | ▶ | use constant TRUE => (0 == 0); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 5 | ▶ | use constant FALSE => not TRUE; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 5 | ▶ | use constant name => 'mx'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 5 | ▶ | use constant name_pattern => qr/${\name}/i; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | An object of class B<Mail::SPF::Mech::MX> represents an SPF record mechanism of | ||||||||||||||||||||||||||||
| 39 | type C<mx>. | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head2 Constructors | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | The following constructors are provided: | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =over | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =item B<new(%options)>: returns I<Mail::SPF::Mech::MX> | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | Creates a new SPF record C<mx> mechanism object. | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | %options is a list of key/value pairs representing any of the following | ||||||||||||||||||||||||||||
| 52 | options: | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =over | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =item B<qualifier> | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =item B<domain_spec> | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =item B<ipv4_prefix_length> | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =item B<ipv6_prefix_length> | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | See L<Mail::SPF::Mech/new>. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =back | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =item B<new_from_string($text, %options)>: returns I<Mail::SPF::Mech::MX>; | ||||||||||||||||||||||||||||
| 69 | throws I<Mail::SPF::ENothingToParse>, I<Mail::SPF::EInvalidMech> | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | Creates a new SPF record C<mx> mechanism object by parsing the string and | ||||||||||||||||||||||||||||
| 72 | any options given. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =back | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =head2 Class methods | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | The following class methods are provided: | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =over | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =item B<default_qualifier> | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =item B<default_ipv4_prefix_length> | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =item B<default_ipv6_prefix_length> | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =item B<qualifier_pattern> | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | See L<Mail::SPF::Mech/Class methods>. | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =item B<name>: returns I<string> | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | Returns B<'mx'>. | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =item B<name_pattern>: returns I<Regexp> | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | Returns a regular expression that matches a mechanism name of B<'mx'>. | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =back | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =head2 Instance methods | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | The following instance methods are provided: | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =over | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub parse_params { | ||||||||||||||||||||||||||
|
Subroutine
parse_params: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 111 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 112 | 0 | $self->parse_domain_spec(); | |||||||||||||||||||||||||||
| 113 | 0 | $self->parse_ipv4_ipv6_prefix_lengths(); | |||||||||||||||||||||||||||
| 114 | 0 | return; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =item B<text> | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =item B<qualifier> | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =item B<params> | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =cut | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub params { | ||||||||||||||||||||||||||
|
Subroutine
params: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 127 | 0 | my $params; | |||||||||||||||||||||||||||
| 128 | $params .= ':' . $self->{domain_spec} | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if defined($self->{domain_spec}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | $params .= '/' . $self->{ipv4_prefix_length} | ||||||||||||||||||||||||||||
| 131 | if defined($self->{ipv4_prefix_length}) | ||||||||||||||||||||||||||||
| 132 | 0 | ▶ | and $self->{ipv4_prefix_length} != $self->default_ipv4_prefix_length; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"ipv4_prefix_length"} and $self->{"ipv4_prefix_length"} != $self->default_ipv4_prefix_length
MC/DC0%0/2
defined $self->{"ipv4_prefix_length"} and $self->{"ipv4_prefix_length"} != $self->default_ipv4_prefix_length
defined $self->{"ipv4_prefix_length"}
$self->{"ipv4_prefix_length"} != $self->default_ipv4_prefix_length
Truth table0%0/3
A and B
A= defined $self->{"ipv4_prefix_length"}B= $self->{"ipv4_prefix_length"} != $self->default_ipv4_prefix_length
| |||||||||||||||||||||||||||||
| 133 | $params .= '//' . $self->{ipv6_prefix_length} | ||||||||||||||||||||||||||||
| 134 | if defined($self->{ipv6_prefix_length}) | ||||||||||||||||||||||||||||
| 135 | 0 | ▶ | and $self->{ipv6_prefix_length} != $self->default_ipv6_prefix_length; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"ipv6_prefix_length"} and $self->{"ipv6_prefix_length"} != $self->default_ipv6_prefix_length
MC/DC0%0/2
defined $self->{"ipv6_prefix_length"} and $self->{"ipv6_prefix_length"} != $self->default_ipv6_prefix_length
defined $self->{"ipv6_prefix_length"}
$self->{"ipv6_prefix_length"} != $self->default_ipv6_prefix_length
Truth table0%0/3
A and B
A= defined $self->{"ipv6_prefix_length"}B= $self->{"ipv6_prefix_length"} != $self->default_ipv6_prefix_length
| |||||||||||||||||||||||||||||
| 136 | 0 | return $params; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =item B<stringify> | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =item B<domain> | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =item B<match_in_domain> | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | See L<Mail::SPF::Mech/Instance methods>. | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =item B<domain_spec>: returns I<Mail::SPF::MacroString> | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | Returns the C<domain-spec> parameter of the mechanism. | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =item B<ipv4_prefix_length>: returns I<integer> | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | Returns the IPv4 network prefix length of the mechanism. | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =item B<ipv6_prefix_length>: returns I<integer> | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | Returns the IPv6 network prefix length of the mechanism. | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =cut | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | # Make read-only accessors: | ||||||||||||||||||||||||||||
| 162 | __PACKAGE__->make_accessor($_, TRUE) | ||||||||||||||||||||||||||||
| 163 | 5 | foreach qw(domain_spec ipv4_prefix_length ipv6_prefix_length); | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =item B<match($server, $request)>: returns I<boolean> | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | Checks whether any MX hosts of the mechanism's target domain name (that is, any | ||||||||||||||||||||||||||||
| 168 | of the host addresses of its DNS C<MX> records) matches the given request's IP | ||||||||||||||||||||||||||||
| 169 | address (see L<Mail::SPF::Request/ip_address>), and returns B<true> if it does, | ||||||||||||||||||||||||||||
| 170 | or B<false> otherwise. The mechanism's IP network prefix lengths are respected | ||||||||||||||||||||||||||||
| 171 | when matching address records against the request's IP address. See RFC 4408, | ||||||||||||||||||||||||||||
| 172 | 5 and 5.4, for the exact algorithm used. | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =cut | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | ▶ | sub match { | ||||||||||||||||||||||||||
|
Subroutine
match: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 177 | 0 | my ($self, $server, $request) = @_; | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | $server->count_dns_interactive_term($request); | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 0 | my $target_domain = $self->domain($server, $request); | |||||||||||||||||||||||||||
| 182 | 0 | my $mx_packet = $server->dns_lookup($target_domain, 'MX'); | |||||||||||||||||||||||||||
| 183 | 0 | ▶ | my @mx_rrs = $mx_packet->answer | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | or $server->count_void_dns_lookup($request); | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | # RFC 7208 ยง4.6.4/2: more than 10 MX records is a permerror. | ||||||||||||||||||||||||||||
| 187 | 0 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $server->max_name_lookups_per_mx_mech and @mx_rrs > $server->max_name_lookups_per_mx_mech
MC/DC0%0/2
defined $server->max_name_lookups_per_mx_mech and @mx_rrs > $server->max_name_lookups_per_mx_mech
defined $server->max_name_lookups_per_mx_mech
@mx_rrs > $server->max_name_lookups_per_mx_mech
Truth table0%0/3
A and B
A= defined $server->max_name_lookups_per_mx_mechB= @mx_rrs > $server->max_name_lookups_per_mx_mech
| |||||||||||||||||||||||||||||
| 188 | defined($server->max_name_lookups_per_mx_mech) and | ||||||||||||||||||||||||||||
| 189 | @mx_rrs > $server->max_name_lookups_per_mx_mech | ||||||||||||||||||||||||||||
| 190 | ) { | ||||||||||||||||||||||||||||
| 191 | 0 | throw Mail::SPF::EProcessingLimitExceeded( | |||||||||||||||||||||||||||
| 192 | sprintf("Maximum MX look-ups limit (%d) exceeded", | ||||||||||||||||||||||||||||
| 193 | $server->max_name_lookups_per_mx_mech)); | ||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | # TODO Use A records from packet's "additional" section? Probably not. | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | # Check MX records: | ||||||||||||||||||||||||||||
| 199 | 0 | foreach my $rr (@mx_rrs) { | |||||||||||||||||||||||||||
| 200 | 0 | ▶ | if ($rr->type eq 'MX') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | 0 | ▶ | return TRUE | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | if $self->match_in_domain($server, $request, $rr->exchange); | ||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | else { | ||||||||||||||||||||||||||||
| 205 | # Unexpected RR type. | ||||||||||||||||||||||||||||
| 206 | # TODO Generate debug info or ignore silently. | ||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 0 | return FALSE; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | =back | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | L<Mail::SPF>, L<Mail::SPF::Record>, L<Mail::SPF::Term>, L<Mail::SPF::Mech> | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | L<http://tools.ietf.org/html/rfc4408> | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | For availability, support, and license information, see the README file | ||||||||||||||||||||||||||||
| 222 | included with Mail::SPF. | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org> | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | =cut | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 5 | TRUE; | |||||||||||||||||||||||||||