File Coverage

blib/lib/Mail/SPF/Mech/IP4.pm
Criterion Covered Total %
statement 22 32 68.7
branch 0 4 0.0
condition n/a
subroutine 7 10 70.0
pod 2 3 66.6
total 31 49 63.2


line stmt bran cond sub pod time code
1             #
2             # Mail::SPF::Mech::IP4
3             # SPF record "ip4" mechanism class.
4             #
5             # (C) 2005-2012 Julian Mehnle
6             # 2005 Shevek
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 mechanism class
16              
17             =head1 VERSION
18              
19             version 3.20250505
20              
21             =cut
22              
23 1     1   1154 use warnings;
  1         1  
  1         56  
24 1     1   6 use strict;
  1         1  
  1         41  
25              
26 1     1   5 use base 'Mail::SPF::SenderIPAddrMech';
  1         1  
  1         494  
27              
28 1     1   4 use constant TRUE => (0 == 0);
  1         1  
  1         59  
29 1     1   4 use constant FALSE => not TRUE;
  1         2  
  1         48  
30              
31 1     1   8 use constant name => 'ip4';
  1         2  
  1         79  
32 1     1   6 use constant name_pattern => qr/${\name}/i;
  1         2  
  1         2  
  1         360  
33              
34             =head1 DESCRIPTION
35              
36             An object of class B represents an SPF record mechanism
37             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             =item B
81              
82             See L.
83              
84             =item B: returns I
85              
86             Returns B<'ip4'>.
87              
88             =item B: returns I
89              
90             Returns a regular expression that matches a mechanism name of B<'ip4'>.
91              
92             =back
93              
94             See L for other supported class methods.
95              
96             =head2 Instance methods
97              
98             The following instance methods are provided:
99              
100             =over
101              
102             =cut
103              
104             sub parse_params {
105 0     0 0   my ($self) = @_;
106 0           $self->parse_ipv4_network(TRUE);
107 0           return;
108             }
109              
110             =item B
111              
112             =item B
113              
114             =item B
115              
116             =cut
117              
118             sub params {
119 0     0 1   my ($self) = @_;
120 0           my $params = ':' . $self->{ip_network}->addr;
121             $params .= '/' . $self->{ip_network}->masklen
122 0 0         if $self->{ip_network}->masklen != $self->default_ipv4_prefix_length;
123 0           return $params;
124             }
125              
126             =item B
127              
128             See L.
129              
130             =item B: returns I
131              
132             Returns the IP address network parameter of the mechanism.
133              
134             =cut
135              
136             # Make read-only accessors:
137             __PACKAGE__->make_accessor($_, TRUE)
138             foreach qw(ip_network ip_address ipv4_prefix_length);
139              
140             =item B: returns I
141              
142             Returns B if the mechanism's C equals or contains the given
143             request's IP address, or B otherwise. See RFC 4408, 5.6, for details.
144              
145             =cut
146              
147             sub match {
148 0     0 1   my ($self, $server, $request) = @_;
149 0 0         my $ip_network_v6 =
150             $self->ip_network->version == 4 ?
151             Mail::SPF::Util->ipv4_address_to_ipv6($self->ip_network)
152             : $self->ip_network;
153 0           return $ip_network_v6->contains($request->ip_address_v6);
154             }
155              
156             =back
157              
158             =head1 SEE ALSO
159              
160             L, L, L, L
161              
162             L
163              
164             For availability, support, and license information, see the README file
165             included with Mail::SPF.
166              
167             =head1 AUTHORS
168              
169             Julian Mehnle , Shevek
170              
171             =cut
172              
173             TRUE;