Mail-SpamAssassin

 view release on metacpan or  search on metacpan

lib/Mail/SpamAssassin/Plugin/AWL.pm  view on Meta::CPAN

This plugin module provides support for the auto-welcomelist.  It keeps
track of the average SpamAssassin score for senders.  Senders are
tracked using a combination of their From: address and their IP address.
It then uses that average score to reduce the variability in scoring
from message to message and modifies the final score by pushing the
result towards the historical average.  This improves the accuracy of
filtering for most email.

=head1 TEMPLATE TAGS

This plugin module adds the following C<tags> that can be used as
placeholders in certain options.  See C<Mail::SpamAssassin::Conf>
for more information on TEMPLATE TAGS.

 _AWL_             AWL modifier
 _AWLMEAN_         Mean score on which AWL modification is based
 _AWLCOUNT_        Number of messages on which AWL modification is based
 _AWLPRESCORE_     Score before AWL

=cut

package Mail::SpamAssassin::Plugin::AWL;

use strict;
use warnings;
# use bytes;
use re 'taint';
use Mail::SpamAssassin::Plugin;
use Mail::SpamAssassin::AutoWelcomelist;
use Mail::SpamAssassin::Util qw(untaint_var);
use Mail::SpamAssassin::Logger;

our @ISA = qw(Mail::SpamAssassin::Plugin);

# constructor: register the eval rule
sub new {
  my $class = shift;
  my $mailsaobject = shift;

  # some boilerplate...
  $class = ref($class) || $class;
  my $self = $class->SUPER::new($mailsaobject);
  bless ($self, $class);

  # the important bit!
  $self->register_eval_rule("check_from_in_auto_welcomelist", $Mail::SpamAssassin::Conf::TYPE_HEAD_EVALS);
  $self->register_eval_rule("check_from_in_auto_whitelist", $Mail::SpamAssassin::Conf::TYPE_HEAD_EVALS); # removed in 4.1

  $self->set_config($mailsaobject->{conf});

  return $self;
}

sub set_config {
  my($self, $conf) = @_;
  my @cmds;

=head1 USER PREFERENCES

The following options can be used in both site-wide (C<local.cf>) and
user-specific (C<user_prefs>) configuration files to customize how
SpamAssassin handles incoming email messages.

=over 4

=item use_auto_welcomelist ( 0 | 1 )		(default: 1)

Previously use_auto_whitelist which will work interchangeably until 4.1.

Whether to use auto-welcomelists.  Auto-welcomelists track the long-term
average score for each sender and then shift the score of new messages
toward that long-term average.  This can increase or decrease the score
for messages, depending on the long-term behavior of the particular
correspondent.

For more information about the auto-welcomelist system, please look
at the C<Automatic Welcomelist System> section of the README file.
The auto-welcomelist is not intended as a general-purpose replacement
for static welcomelist entries added to your config files.

Note that certain tests are ignored when determining the final
message score:

 - rules with tflags set to 'noautolearn'

=cut

  push (@cmds, {
		setting => 'use_auto_welcomelist',
		aliases => ['use_auto_whitelist'], # backward compatible - to be removed for 4.1
		default => 1,
		type => $Mail::SpamAssassin::Conf::CONF_TYPE_BOOL
	       });

=item auto_welcomelist_factor n	(default: 0.5, range [0..1])

Previously auto_whitelist_factor which will work interchangeably until 4.1.

How much towards the long-term mean for the sender to regress a message.
Basically, the algorithm is to track the long-term mean score of messages for
the sender (C<mean>), and then once we have otherwise fully calculated the
score for this message (C<score>), we calculate the final score for the
message as:

C<finalscore> = C<score> +  (C<mean> - C<score>) * C<factor>

So if C<factor> = 0.5, then we'll move to half way between the calculated
score and the mean.  If C<factor> = 0.3, then we'll move about 1/3 of the way
from the score toward the mean.  C<factor> = 1 means just use the long-term
mean; C<factor> = 0 mean just use the calculated score.

=cut

  push (@cmds, {
		setting => 'auto_welcomelist_factor',
		aliases => ['auto_whitelist_factor'], # backward compatible - to be removed for 4.1
		default => 0.5,
		type => $Mail::SpamAssassin::Conf::CONF_TYPE_NUMERIC
	       });

=item auto_welcomelist_ipv4_mask_len n	(default: 16, range [0..32])

lib/Mail/SpamAssassin/Plugin/AWL.pm  view on Meta::CPAN

		aliases => ['auto_whitelist_ipv6_mask_len'], # removed in 4.1
		default => 48,
		type => $Mail::SpamAssassin::Conf::CONF_TYPE_NUMERIC,
		code => sub {
		  my ($self, $key, $value, $line) = @_;
		  if (!defined $value || $value eq '') {
		    return $Mail::SpamAssassin::Conf::MISSING_REQUIRED_VALUE;
		  } elsif ($value !~ /^\d+$/ || $value < 0 || $value > 128) {
		    return $Mail::SpamAssassin::Conf::INVALID_VALUE;
		  }
		  $self->{auto_welcomelist_ipv6_mask_len} = $value;
		}
	       });

=item user_awl_sql_override_username

Used by the SQLBasedAddrList storage implementation.

If this option is set the SQLBasedAddrList module will override the set
username with the value given.  This can be useful for implementing global
or group based auto-welcomelist databases.

=cut

  push (@cmds, {
		setting => 'user_awl_sql_override_username',
		default => '',
		type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING
	       });

=item auto_welcomelist_distinguish_signed

Previously auto_whitelist_distinguish_signed which will work interchangeably until 4.1.

Used by the SQLBasedAddrList storage implementation.

If this option is set the SQLBasedAddrList module will keep separate
database entries for DKIM-validated e-mail addresses and for non-validated
ones. A pre-requisite when setting this option is that a field awl.signedby
exists in a SQL table, otherwise SQL operations will fail (which is why we
need this option at all - for compatibility with pre-3.3.0 database schema).
A plugin DKIM should also be enabled, as otherwise there is no benefit from
turning on this option.

=cut

  push (@cmds, {
		setting => 'auto_welcomelist_distinguish_signed',
		aliases => ['auto_whitelist_distinguish_signed'], # removed in 4.1
		default => 0,
		type => $Mail::SpamAssassin::Conf::CONF_TYPE_BOOL
	       });

=back

=head1 ADMINISTRATOR SETTINGS

These settings differ from the ones above, in that they are considered 'more
privileged' -- even more than the ones in the B<PRIVILEGED SETTINGS> section.
No matter what C<allow_user_rules> is set to, these can never be set from a
user's C<user_prefs> file.

=over 4

=item auto_welcomelist_factory module (default: Mail::SpamAssassin::DBBasedAddrList)

Previously auto_whitelist_factory which will work interchangeably until 4.1.

Select alternative welcomelist factory module.

=cut

  push (@cmds, {
		setting => 'auto_welcomelist_factory',
		aliases => ['auto_whitelist_factory'], # removed in 4.1
		is_admin => 1,
		default => 'Mail::SpamAssassin::DBBasedAddrList',
		type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING
	       });

=item auto_welcomelist_path /path/filename (default: ~/.spamassassin/auto-welcomelist)

Previously auto_whitelist_path which will work interchangeably until 4.1.

This is the automatic-welcomelist directory and filename.  By default, each user
has their own welcomelist database in their C<~/.spamassassin> directory with
mode 0700.  For system-wide SpamAssassin use, you may want to share this
across all users, although that is not recommended.

=cut

  push (@cmds, {
		setting => 'auto_welcomelist_path',
		aliases => ['auto_whitelist_path'], # removed in 4.1
		is_admin => 1,
		default => '__userstate__/auto-welcomelist',
		type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING,
		code => sub {
		  my ($self, $key, $value, $line) = @_;
		  unless (defined $value && $value !~ /^$/) {
		    return $Mail::SpamAssassin::Conf::MISSING_REQUIRED_VALUE;
		  }
		  if (-d $value) {
		    return $Mail::SpamAssassin::Conf::INVALID_VALUE;
		  }
		  $self->{auto_welcomelist_path} = $value;
		}
	       });

=item auto_welcomelist_db_modules Module ...	(default: see below)

Previously auto_whitelist_db_modules which will work interchangeably until 4.1.

What database modules should be used for the auto-welcomelist storage database
file.   The first named module that can be loaded from the perl include path
will be used.  The format is:

  PreferredModuleName SecondBest ThirdBest ...

ie. a space-separated list of perl module names.  The default is:



( run in 0.939 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )