Mailmun...Greylist(3)

πŸ“¦ version 3.20, in alpine 3.24

πŸ’… Mailmunge::Test::Greylist β€” the greylisting one, bestie

okay so this is a page from the User Contributed Perl Documentation manual (that's the manual name, we're not typing the whole header line out again, we're not monsters) and it's all about Mailmunge::Test::Greylist, a Perl class that does greylisting. Let's get into it ✨


🌸 NAME

Mailmunge::Test::Greylist β€” the implementation of greylist. that's it, that's the name, she's literally named what she does πŸ’…

πŸŽ€ ABSTRACT

So what does this class actually do? It implements greylisting: it temporarily-fails a combination of machine, sender, and recipient (and possibly other data, iykyk) that it has never seen before. Like, it's giving "new phone who dis" but for SMTP. 🫢

Also important: Mailmunge::Test::Greylist is a subclass of Mailmunge::Test. family tree, established. πŸ‘‘

✨ SYNOPSIS

here's the whole vibe in code form. no cap, this is the real thing:

# 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;
    # ...
}

okay but the first thing, before any of that: a database must have already been created beforehand with that schema up there. ⚠️ the two CREATE TABLE lines β€” one for greylist and one for ips_known_to_retry β€” that's the setup, don't skip it.

🌈 CONSTRUCTOR

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

Constructs and returns a new Mailmunge::Test::Greylist object. that's it. she's born. iconic. πŸŽ€

πŸ”₯ METHODS

πŸ’œ evaluate($dbh, $min_delay, $max_delay, $ip, @remaining_args)

This is the main character method. It evaluates greylisting and returns a Mailmunge::Response object that will either be CONTINUE or TEMPFAIL. Those are the only two options, bestie, pick a lane. πŸ¦‹

here's what every argument is doing at the function:

  • $dbh is a DBI handle connected to the greylisting database. database said hi. πŸ‘‹
  • $min_delay and $max_delay are the imposed minimum and maximum retry delays respectively. so here's the tea: if an SMTP client tries faster than the minimum delay, it continues to get greylisted (sorry babe, too eager πŸ’€). and if it waits longer than the maximum delay, it begins the greylisting test from scratch (back to square one, we love a reset πŸ”„).
  • $ip is the IP address of the connecting SMTP client. that's the machine in the machine/sender/recipient combo. πŸ–₯️
  • @remaining_args are any other arguments that should be considered to make the greylist tuple specific. typically you'd call evaluate from filter_recipient and would pass the sender and recipient as @remaining_args. so like, the extra seasoning that makes this tuple this tuple. πŸ“

🌟 AUTHOR

Dianne Skoll <dianne@skollsoft.com> β€” mother of this code, we stan. πŸ‘‘

🧚 LICENSE

This code is licenced under the terms of the GNU General Public License, version 2. periodt. πŸ“œ (note: the original spells it "licenced", spelling icon behavior, we don't correct legends)


πŸ’– quick reminder before you go: the synopsis schema is not optional, always connect in the initialize callback, and tidy up with $dbh->disconnect in cleanup. the vibes are immaculate but the database has to exist first, fr fr.

okay that's the page!! this was rendered by perl v5.42.2 on 2025-10-05, and hey, if a manual page like this can slay, so can you. mwah πŸ’…πŸ’–πŸŒΈ

πŸ“¦ where this page comes from