# $DUH: helo_regex,v 1.2 2002/12/16 05:14:33 tv Exp $
#
# Copyright (c) 2002 Todd Vierling <tv@pobox.com> <tv@duh.org>.
# All rights reserved.
# Please see the COPYRIGHT file, part of the PMilter distribution,
# for full copyright and license terms.

##### helo_regex #####
#
# Rejects HELO commands that match a list of regular expressions.

use PMilter::Modules;

my @regexes = regex_list(shift @_, 'i');
my $errmsg = shift_errmsg(@_, 'Domain name "%1" not allowed');

+{
	helo => sub {
		my $ctx = shift;
		my $helo = shift;

		foreach my $rx (@regexes) {
			if ($helo =~ $rx) {
				my $err = $errmsg;
				$err =~ s/%1/$helo/g; # interpolate HELO arg

				return $ctx->reject("554 HELO/EHLO command rejected: $err");
			}
		}

		return SMFIS_ACCEPT;
	}
};
