Mail::SPF::Mech::IP4 - SPF record C<ip4> mechanism class


Mail-SPF documentation Contained in the Mail-SPF distribution.

Index


Code Index:

NAME

Top

Mail::SPF::Mech::IP4 - SPF record ip4 mechanism class

DESCRIPTION

Top

An object of class Mail::SPF::Mech::IP4 represents an SPF record mechanism of type ip4.

Constructors

The following constructors are provided:

new(%options): returns Mail::SPF::Mech::IP4

Creates a new SPF record ip4 mechanism object.

%options is a list of key/value pairs representing any of the following options:

qualifier
ip_network

See new in Mail::SPF::Mech.

new_from_string($text, %options): returns Mail::SPF::Mech::IP4; throws Mail::SPF::ENothingToParse, Mail::SPF::EInvalidMech

Creates a new SPF record ip4 mechanism object by parsing the string and any options given.

Class methods

The following class methods are provided:

default_qualifier
default_ipv4_prefix_length
qualifier_pattern

See Class methods in Mail::SPF::Mech.

name: returns string

Returns 'ip4'.

name_pattern: returns Regexp

Returns a regular expression that matches a mechanism name of 'ip4'.

See Mail::SPF::Mech for other supported class methods.

Instance methods

The following instance methods are provided:

text
qualifier
params
stringify

See Instance methods in Mail::SPF::Mech.

ip_network: returns NetAddr::IP

Returns the IP address network parameter of the mechanism.

match($server, $request): returns boolean

Returns true if the mechanism's ip_network equals or contains the given request's IP address, or false otherwise. See RFC 4408, 5.6, for details.

SEE ALSO

Top

Mail::SPF, Mail::SPF::Record, Mail::SPF::Term, Mail::SPF::Mech

http://www.ietf.org/rfc/rfc4408.txt

For availability, support, and license information, see the README file included with Mail::SPF.

AUTHORS

Top

Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org>


Mail-SPF documentation Contained in the Mail-SPF distribution.
#
# Mail::SPF::Mech::IP4
# SPF record "ip4" mechanism class.
#
# (C) 2005-2008 Julian Mehnle <julian@mehnle.net>
#     2005      Shevek <cpan@anarres.org>
# $Id: IP4.pm 50 2008-08-17 21:28:15Z Julian Mehnle $
#
##############################################################################

package Mail::SPF::Mech::IP4;

use warnings;
use strict;

use base 'Mail::SPF::SenderIPAddrMech';

use constant TRUE   => (0 == 0);
use constant FALSE  => not TRUE;

use constant name           => 'ip4';
use constant name_pattern   => qr/${\name}/i;

sub parse_params {
    my ($self) = @_;
    $self->parse_ipv4_network(TRUE);
    return;
}

sub params {
    my ($self) = @_;
    my $params = ':' . $self->{ip_network}->addr;
    $params .= '/' . $self->{ip_network}->masklen
        if $self->{ip_network}->masklen != $self->default_ipv4_prefix_length;
    return $params;
}

# Make read-only accessors:
__PACKAGE__->make_accessor($_, TRUE)
    foreach qw(ip_network ip_address ipv4_prefix_length);

sub match {
    my ($self, $server, $request) = @_;
    my $ip_network_v6 =
        $self->ip_network->version == 4 ?
            Mail::SPF::Util->ipv4_address_to_ipv6($self->ip_network)
        :   $self->ip_network;
    return $ip_network_v6->contains($request->ip_address_v6);
}

TRUE;