← Documentation Index

NAME

Mailmunge::Test::Greylist - implementation of greylist

ABSTRACT

This class implements greylisting: Temporarily-failing a combination of machine, sender, and recipient (and possibly other data) that has never seen before.

Mailmunge::Test::Greylist is a subclass of Mailmunge::Test

SYNOPSIS

# A database must have been created beforehand with
# the following schema:
#
# CREATE TABLE greylist(hash TEXT PRIMARY KEY NOT NULL, last_seen INTEGER);
# CREATE TABLE ips_known_to_retry(ip TEXT PRIMARY KEY NOT NULL, last_seen INTEGER);

my $dbh;

sub initialize {
    # Always connect to the database in the "initialize" callback
    $dbh = DBI->connect($dsn, $username, $auth, {attr => val});
}

sub cleanup {
    # Tidy up when our filter is about to exit
    $dbh->disconnect;
}

# The actual use of Mailmunge::Test::Greylist
sub filter_recipient {
    my ($ctx) = @_;
    my $gl = Mailmunge::Test::Greylist->new($self);
    my $min_delay = 5;
    my $max_delay = 86400;
    my $result = $gl->evaluate($dbh, $min_delay, $max_delay,
                               $ctx->hostip, $ctx->sender,
                               $ctx->recipients->[0]);
    return $result unless $result->is_success;
    # ...
}

CONSTRUCTOR

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

Constructs and returns a new Mailmunge::Test::Greylist object

METHODS

evaluate($dbh, $min_delay, $max_delay, $ip, @remaining_args)

Evaluates greylisting and returns a Mailmunge::Response object that will either be CONTINUE or TEMPFAIL.

$dbh is a DBI handle connected to the greylisting database.

$min_delay and $max_delay are the imposed minimum and maximum retry delays respectively. If an SMTP client tries faster than the minimum delay, it continues to get greylisted. If it waits longer than the maximum delay, it begins the greylisting test from scratch.

$ip is the IP address of the connecting SMTP client.

@remaining_args are any other arguments that should be considered to make the greylist tuple specific. Typically, you would call evaluate from filter_recipient and would pass the sender and recipient as @remaining_args

AUTHOR

Dianne Skoll <dianne@skollsoft.com>

LICENSE

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

Copyright © 2024 Skoll Software Consulting