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

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

sub check_good_rcpt {
    my ($self, $transaction, $rcpt) = @_;

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

    my $user = lc $rcpt->user;
    my $full = lc $rcpt->address;
    foreach my $addr (@goodrcptto) {
	$addr =~ s/^\s*(\S+)/$1/; # remove any leading spaces

	if ($addr =~ m/\@/) {
	    return OK if ($full eq lc $addr);
	} else {
	    return OK if ($user eq lc $addr);
	}
    }

    return DECLINED;
}

__END__

=head1 NAME

check_goodrcptto - Allow good C<RCPT TO> addresses through

=head1 DESCRIPTION

Allow certain addresses through regardless of any other C<RCPT TO> tests.
This is mostly useful for allowing C<abuse> and C<postmaster> mail through
even if the site would normally be blocked by a DNSBL or RHSBL.

=head1 USAGE

Place this plugin B<before> all other C<RCPT TO> plugins since it needs to
allow the message before any other plugin can deny it.

=head1 FILES

=over

=item F<config/goodrcptto>

A list of email addresses than can be allowed through.  The address can
either be a full email address, or just the user name.

=back

=head1 HISTORY

=over

=item 1.0 - 2003-09-04

Initial release

=back

=head1 AUTHOR

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

=cut
