| 1 | # | ||||||||||
| 2 | # Mail::SPF::Mech::IP4 | ||||||||||
| 3 | # SPF record "ip4" mechanism class. | ||||||||||
| 4 | # | ||||||||||
| 5 | # (C) 2005-2012 Julian Mehnle <julian@mehnle.net> | ||||||||||
| 6 | # 2005 Shevek <cpan@anarres.org> | ||||||||||
| 7 | # $Id: IP4.pm 57 2012-01-30 08:15:31Z julian $ | ||||||||||
| 8 | # | ||||||||||
| 9 | ############################################################################## | ||||||||||
| 10 | |||||||||||
| 11 | package Mail::SPF::Mech::IP4; | ||||||||||
| 12 | |||||||||||
| 13 | =head1 NAME | ||||||||||
| 14 | |||||||||||
| 15 | Mail::SPF::Mech::IP4 - SPF record C<ip4> 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 => 'ip4'; | ||||||||
|
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::IP4> represents an SPF record mechanism | ||||||||||
| 39 | of type C<ip4>. | ||||||||||
| 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::IP4> | ||||||||||
| 48 | |||||||||||
| 49 | Creates a new SPF record C<ip4> 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<ip_network> | ||||||||||
| 59 | |||||||||||
| 60 | See L<Mail::SPF::Mech/new>. | ||||||||||
| 61 | |||||||||||
| 62 | =back | ||||||||||
| 63 | |||||||||||
| 64 | =item B<new_from_string($text, %options)>: returns I<Mail::SPF::Mech::IP4>; | ||||||||||
| 65 | throws I<Mail::SPF::ENothingToParse>, I<Mail::SPF::EInvalidMech> | ||||||||||
| 66 | |||||||||||
| 67 | Creates a new SPF record C<ip4> mechanism object by parsing the string and | ||||||||||
| 68 | any options given. | ||||||||||
| 69 | |||||||||||
| 70 | =back | ||||||||||
| 71 | |||||||||||
| 72 | =head2 Class methods | ||||||||||
| 73 | |||||||||||
| 74 | The following class methods are provided: | ||||||||||
| 75 | |||||||||||
| 76 | =over | ||||||||||
| 77 | |||||||||||
| 78 | =item B<default_qualifier> | ||||||||||
| 79 | |||||||||||
| 80 | =item B<default_ipv4_prefix_length> | ||||||||||
| 81 | |||||||||||
| 82 | =item B<qualifier_pattern> | ||||||||||
| 83 | |||||||||||
| 84 | See L<Mail::SPF::Mech/Class methods>. | ||||||||||
| 85 | |||||||||||
| 86 | =item B<name>: returns I<string> | ||||||||||
| 87 | |||||||||||
| 88 | Returns B<'ip4'>. | ||||||||||
| 89 | |||||||||||
| 90 | =item B<name_pattern>: returns I<Regexp> | ||||||||||
| 91 | |||||||||||
| 92 | Returns a regular expression that matches a mechanism name of B<'ip4'>. | ||||||||||
| 93 | |||||||||||
| 94 | =back | ||||||||||
| 95 | |||||||||||
| 96 | See L<Mail::SPF::Mech> for other supported class methods. | ||||||||||
| 97 | |||||||||||
| 98 | =head2 Instance methods | ||||||||||
| 99 | |||||||||||
| 100 | The following instance methods are provided: | ||||||||||
| 101 | |||||||||||
| 102 | =over | ||||||||||
| 103 | |||||||||||
| 104 | =cut | ||||||||||
| 105 | |||||||||||
| 106 | 3 | ▶ | sub parse_params { | ||||||||
|
Subroutine
parse_params: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 107 | 3 | my ($self) = @_; | |||||||||
| 108 | 3 | $self->parse_ipv4_network(TRUE); | |||||||||
| 109 | 3 | return; | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | =item B<text> | ||||||||||
| 113 | |||||||||||
| 114 | =item B<qualifier> | ||||||||||
| 115 | |||||||||||
| 116 | =item B<params> | ||||||||||
| 117 | |||||||||||
| 118 | =cut | ||||||||||
| 119 | |||||||||||
| 120 | 3 | ▶ | sub params { | ||||||||
|
Subroutine
params: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 121 | 3 | my ($self) = @_; | |||||||||
| 122 | 3 | my $params = ':' . $self->{ip_network}->addr; | |||||||||
| 123 | $params .= '/' . $self->{ip_network}->masklen | ||||||||||
| 124 | 3 | ▶ | if $self->{ip_network}->masklen != $self->default_ipv4_prefix_length; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 125 | 3 | return $params; | |||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | =item B<stringify> | ||||||||||
| 129 | |||||||||||
| 130 | See L<Mail::SPF::Mech/Instance methods>. | ||||||||||
| 131 | |||||||||||
| 132 | =item B<ip_network>: returns I<NetAddr::IP> | ||||||||||
| 133 | |||||||||||
| 134 | Returns the IP address network parameter of the mechanism. | ||||||||||
| 135 | |||||||||||
| 136 | =cut | ||||||||||
| 137 | |||||||||||
| 138 | # Make read-only accessors: | ||||||||||
| 139 | __PACKAGE__->make_accessor($_, TRUE) | ||||||||||
| 140 | 5 | foreach qw(ip_network ip_address ipv4_prefix_length); | |||||||||
| 141 | |||||||||||
| 142 | =item B<match($server, $request)>: returns I<boolean> | ||||||||||
| 143 | |||||||||||
| 144 | Returns B<true> if the mechanism's C<ip_network> equals or contains the given | ||||||||||
| 145 | request's IP address, or B<false> otherwise. See RFC 4408, 5.6, for details. | ||||||||||
| 146 | |||||||||||
| 147 | =cut | ||||||||||
| 148 | |||||||||||
| 149 | 3 | ▶ | sub match { | ||||||||
|
Subroutine
match: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 150 | 3 | my ($self, $server, $request) = @_; | |||||||||
| 151 | 3 | ▶ | my $ip_network_v6 = | ||||||||
|
Branch: 1 branch
| |||||||||||
| 152 | $self->ip_network->version == 4 ? | ||||||||||
| 153 | Mail::SPF::Util->ipv4_address_to_ipv6($self->ip_network) | ||||||||||
| 154 | : $self->ip_network; | ||||||||||
| 155 | 3 | return $ip_network_v6->contains($request->ip_address_v6); | |||||||||
| 156 | } | ||||||||||
| 157 | |||||||||||
| 158 | =back | ||||||||||
| 159 | |||||||||||
| 160 | =head1 SEE ALSO | ||||||||||
| 161 | |||||||||||
| 162 | L<Mail::SPF>, L<Mail::SPF::Record>, L<Mail::SPF::Term>, L<Mail::SPF::Mech> | ||||||||||
| 163 | |||||||||||
| 164 | L<http://tools.ietf.org/html/rfc4408> | ||||||||||
| 165 | |||||||||||
| 166 | For availability, support, and license information, see the README file | ||||||||||
| 167 | included with Mail::SPF. | ||||||||||
| 168 | |||||||||||
| 169 | =head1 AUTHORS | ||||||||||
| 170 | |||||||||||
| 171 | Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org> | ||||||||||
| 172 | |||||||||||
| 173 | =cut | ||||||||||
| 174 | |||||||||||
| 175 | 5 | TRUE; | |||||||||