# -*- cperl -*-
#
# Copyright (c) 2003  Robert James Kaes <rjkaes@flarenet.com>
#   All rights reserved.
#
# This code is released under the same license as Qpsmtpd itself.
#

sub register {
    my ($self, $qp) = @_;
    $self->register_hook("rcpt", "domain_regexp");
}

sub domain_regexp {
    my ($self, $transaction, $rcpt) = @_;
    my $remote_host = $self->qp->connection->remote_host;

    my @regexps = $self->qp->config('domain_regexp');
    return DECLINED unless @regexps;

    foreach my $regex (@regexps) {
	$self->log(6, "checking $remote_host against $regex");
	if ($remote_host =~ m/$regex/) {
	    return (DENYSOFT, "Domain [$remote_host] blocked by regular expression");
	}
    }

    return DECLINED;
}

__END__

=head1 NAME

check_domain_regexp

=head1 DESCRIPTION

Compare the domain name against a list of regular expressions.

=head1 CONFIG

Regular expressions are listed one per line in F<config/domain_regexp>.
Full Perl regexp can be used.

=head1 TODO

Make the return code configurable from C<DENYSOFT> to C<DENY>.  Currently
it's only C<DENYSOFT>.

=head1 HISTORY

=over

=item 1.2 - 2003-09-04

Removed the F<config/rfcrequired> file and support code since it doesn't
really belong here.  The concept of F<config/rfcrequired> is really a
white-list, and should be it's own plugin that is called B<before> any
plugins that could deny based on the C<MAIL FROM>.

=item 1.1 - 2003-08-29

Changed from a mail handler to a rcpt handler.  Added support for the
F<config/rfcrequired> file.

=item 1.0 - 2003-08-28

Initial version.

=back

=head1 AUTHOR

Copyright (c) 2003  L<Robert James Kaes|mailto:rjkaes@flarenet.com>

=cut
