← Documentation Index

NAME

Mailmunge::Test::GetMX - Get the MX records for a domain and classify them

ABSTRACT

This class performs an MX lookup on a given domain and returns the IPv4 addresses of the MX hosts, classifying each IP address as described below.

Mailmunge::Test::GetMX is a subclass of Mailmunge::Test.

SYNOPSIS

use Mailmunge::Test::GetMX;

sub filter_sender {
    my ($self, $ctx) = @_;
    my $getmx = Mailmunge::Test::GetMX->new($self);
    my $results = $getmx->get_mx_hosts($ctx->sender);
    if (scalar(@{$results->{bogus}}) {
        $self->log($ctx, 'info', "Found reserved IPs in MX for " . $ctx->sender);
    }
    if (scalar(@{$results->{private}}) {
        $self->log($ctx, 'info', "Found RFC 1918 IPs in MX for " . $ctx->sender);
    }
    if (scalar(@{$results->{loopback}}) {
        $self->log($ctx, 'info', "Found RFC loopback IPs in MX for " . $ctx->sender);
    }
    if (scalar(@{$results->{routable}}) {
        $self->log($ctx, 'info', "Found valid routable IPs in MX for " . $ctx->sender);
    }
}

CONSTRUCTOR

Mailmunge::Test::GetMX->new($filter)

Constructs and returns a new Mailmunge::Test::GetMX object.

get_mx_hosts($domain_or_sender)

Given a domain or an email address, looks up the MX hosts of the domain (or domain of the sender) and returns a hash containing the following four elements:

bogus

An arrayref of MX hosts IPs that have bogus unroutable IP addresses (such as 0.0.0.0, 255.255.255.255, or multicast addresses, for example.)

private

An arrayref of MX host IPs that are in the RFC 1918 private use ranges.

loopback

An arrayref of MX host IPs that are in the range 127.0.0.0/8.

routable

An arrayref of MX host IPs that are globally-routable unicast IPv4 addresses.

You may wish to have your filter reject mail from domains that have bogus MX records; make your decision based on the value returned from get_mx_hosts.

ip4_is_loopback($ip)

Given the string representation of an IPv4 address, returns true if it's in the range 127.0.0.0/8 or false otherwise.

ip4_is_private($ip)

Given the string representation of an IPv4 address, returns true if it's in one of the RFC 1918 private ranges or false otherwise.

ip4_is_reserved($ip)

Given the string representation of an IPv4 address, returns true if it's in one of the following ranges:

169.254.0.0/16

IPv4 Multicast

224.0.0.0/4

Class E

240.0.0.0/4

Bogus

0.0.0.0/32 and 255.255.255.255/32

AUTHOR

Dianne Skoll <dianne@skollsoft.com>

LICENSE

This code is licensed under the terms of the GNU General Public License, version 2.

Copyright © 2024 Skoll Software Consulting