diff --git a/config.sample/karma_tlds b/config.sample/karma_tlds new file mode 100644 index 0000000..0ba228f --- /dev/null +++ b/config.sample/karma_tlds @@ -0,0 +1,14 @@ +# Karma to apply depending on the tld of the envelope sender +# Used by the karma plugin +# Warning: setting karma too low can blacklist the entire tld +work:-4 +rocks:-3 +ninja:-3 +info:-2 +biz:-2 +pw:-2 +me:-1 +us:-5 +eu:-4 +link:-3 +science:-6 diff --git a/plugins/karma b/plugins/karma index 669aba0..2d2bbd6 100644 --- a/plugins/karma +++ b/plugins/karma @@ -102,6 +102,20 @@ following list will be used: Adjust the quantity of logging for this plugin. See docs/logging.pod +=head1 CONFIG FILES + +This plugin uses the following configuration files. All are optional. + +=head2 karma_tlds + +This file can contain semicolon separated tlds and the corresponding +karma adjustment to apply when the envelope sender match. It can be used to +penalize "spammy" tlds, or to raise the karma from (mostly) good tlds. + +jp:-4 +ch:-3 +fr:+1 + =head1 BENEFITS Karma reduces the resources wasted by naughty mailers. When used with @@ -352,18 +366,14 @@ sub from_handler { my $full_from = $self->connection->notes('envelope_from'); $self->illegal_envelope_format( $full_from ); - my %spammy_tlds = ( - map { $_ => 4 } qw/ info pw /, - map { $_ => 3 } qw/ tw biz /, - map { $_ => 2 } qw/ cl br fr be jp no se sg /, - ); - foreach my $tld ( keys %spammy_tlds ) { + my $karma_tlds = $self->get_karma_tlds() or return DECLINED; + foreach my $tld ( keys %$karma_tlds ) { my $len = length $tld; - my $score = $spammy_tlds{$tld} or next; + my $score = $karma_tlds->{$tld} or next; $len ++; if ( $sender->host && ".$tld" eq substr($sender->host,-$len,$len) ) { - $self->log(LOGINFO, "penalizing .$tld envelope sender"); - $self->adjust_karma(-$score); + $self->log(LOGINFO, "adjusting karma for .$tld envelope sender"); + $self->adjust_karma($score); } } @@ -479,6 +489,19 @@ sub illegal_envelope_format { } } +sub get_karma_tlds { + my $self = shift; + + my %karma_tlds = + map { (split /:/, $_, 2)[0, 1] } $self->qp->config('karma_tlds'); + if (!%karma_tlds) { + $self->log(LOGDEBUG, "no specific karma for tlds defined"); + return; + } + + return \%karma_tlds; +} + sub parse_db_record { my ($self, $value) = @_;