karma: add recipient limits for bad senders

This commit is contained in:
Matt Simerson 2013-04-20 23:53:27 -04:00
parent 1cd1486d37
commit 5881f2a662

View File

@ -24,9 +24,9 @@ custom connection policies such as these two examples:
=over 4 =over 4
Hi there, well behaved sender. Please help yourself to greater concurrency, multiple recipients, no delays, and other privileges. Hi there, well known and well behaved sender. Please help yourself to greater concurrency (hosts_allow), multiple recipients (karma), and no delays (early_sender).
Hi there, naughty sender. You get a max concurrency of 1, and SMTP delays. Hi there, naughty sender. You get a max concurrency of 1, max recipients of 2, and SMTP delays.
=back =back
@ -245,6 +245,7 @@ sub register {
$self->register_hook('connect', 'connect_handler'); $self->register_hook('connect', 'connect_handler');
$self->register_hook('data', 'data_handler' ); $self->register_hook('data', 'data_handler' );
$self->register_hook('disconnect', 'disconnect_handler'); $self->register_hook('disconnect', 'disconnect_handler');
$self->register_hook('received_line', 'rcpt_handler');
} }
sub hook_pre_connection { sub hook_pre_connection {
@ -317,6 +318,19 @@ sub connect_handler {
return $self->get_reject( $mess, $karma ); return $self->get_reject( $mess, $karma );
} }
sub rcpt_handler {
my ($self, $transaction, $recipient, %args) = @_;
my $recipients = scalar $self->transaction->recipients;
return DECLINED if $recipients < 2; # only one recipient
my $karma = $self->connection->notes('karma_history');
return DECLINED if $karma > 0; # good karma, no limit
# limit # of recipients if host has negative or unknown karma
return $self->get_reject( "too many recipients");
};
sub data_handler { sub data_handler {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
return DECLINED if ! $self->qp->connection->relay_client; return DECLINED if ! $self->qp->connection->relay_client;