Mail-SpamAssassin
view release on metacpan or search on metacpan
spamassassin.raw view on Meta::CPAN
EX_NOUSER => 67, # addressee unknown
EX_NOHOST => 68, # host name unknown
EX_UNAVAILABLE => 69, # service unavailable
EX_SOFTWARE => 70, # internal software error
EX_OSERR => 71, # system error (e.g., can't fork)
EX_OSFILE => 72, # critical OS file missing
EX_CANTCREAT => 73, # can't create (user) output file
EX_IOERR => 74, # input/output error
EX_TEMPFAIL => 75, # temp failure; user is invited to retry
EX_PROTOCOL => 76, # remote error in protocol
EX_NOPERM => 77, # permission denied
EX_CONFIG => 78, # configuration error
);
sub print_version {
printf("SpamAssassin version %s\n running on Perl version %s\n",
Mail::SpamAssassin::Version(),
join(".", map( 0+($_||0), ($] =~ /(\d)\.(\d{3})(\d{3})?/ ))))
or die "error writing: $!";
}
sub print_usage_and_exit {
my ( $message, $respnam ) = @_;
$respnam ||= 'EX_USAGE';
if ($respnam eq 'EX_OK' ) {
print_version();
print("\n") or die "error writing: $!";
}
pod2usage(
-verbose => 0,
-message => $message,
-exitval => $resphash{$respnam},
-input => "spamassassin-run.pod",
-pathlist => \@INC,
);
}
sub usage {
my ( $verbose, $message ) = @_;
my $ver = Mail::SpamAssassin::Version();
print "SpamAssassin version $ver\n" or die "error writing: $!";
pod2usage( -verbose => $verbose, -message => $message, -exitval => 64, -input => "spamassassin-run.pod", -pathlist => \@INC );
}
# Check to make sure the script version and the module version matches.
# If not, die here! Also, deal with unchanged VERSION macro.
if ($Mail::SpamAssassin::VERSION ne '@@VERSION@@' && '@@VERSION@@' ne "\@\@VERSION\@\@") {
die 'spamassassin: spamassassin script is v@@VERSION@@, but using modules v'.$Mail::SpamAssassin::VERSION."\n";
}
# by default:
# - create user preference files
# - have ArchiveIterator detect the input message format (file vs dir)
#
my %opt = ( 'create-prefs' => 1, 'format' => 'detect', pre => [], cf => [] );
my $doing_welcomelist_operation = 0;
my $count = 0;
my @targets = ();
my $exitvalue;
my $init_results = 0;
my $progress;
my $total_messages = 0;
# gnu_getopt is not available in Getopt::Long 2.24, see bug 732
# gnu_compat neither.
Getopt::Long::Configure(
qw(bundling no_getopt_compat no_auto_abbrev no_ignore_case));
GetOptions(
'add-addr-to-blocklist=s' => \$opt{'add-addr-to-blocklist'},
'add-addr-to-welcomelist=s' => \$opt{'add-addr-to-welcomelist'},
'add-addr-to-blacklist=s' => \$opt{'add-addr-to-blocklist'}, # removed in 4.1
'add-addr-to-whitelist=s' => \$opt{'add-addr-to-welcomelist'}, # removed in 4.1
'add-to-blocklist' => \$opt{'add-to-blocklist'},
'add-to-welcomelist|W' => \$opt{'add-to-welcomelist'},
'add-to-blacklist' => \$opt{'add-to-blocklist'}, # removed in 4.1
'add-to-whitelist' => \$opt{'add-to-welcomelist'}, # removed in 4.1
'username|u=s' => \$opt{'username'},
'configpath|config-file|config-dir|c|C=s' => \$opt{'configpath'},
'create-prefs!' => \$opt{'create-prefs'},
'pre=s' => \@{$opt{'pre'}},
'cf=s' => \@{$opt{'cf'}},
'debug|D:s' => \$opt{'debug'},
'error-code|exit-code|e:i' => \$opt{'error-code'},
'help|h|?' => \$opt{'help'},
'4|ipv4only|ipv4-only|ipv4' => sub { $opt{'force_ipv4'} = 1;
$opt{'force_ipv6'} = 0; },
'6' => sub { $opt{'force_ipv6'} = 1;
$opt{'force_ipv4'} = 0; },
'lint' => \$opt{'lint'},
'net' => \$opt{'net'},
'local-only|local|L' => \$opt{'local'},
'mbox' => sub { $opt{'format'} = 'mbox'; },
'mbx' => sub { $opt{'format'} = 'mbx'; },
'prefspath|prefs-file|p=s' => \$opt{'prefspath'},
'remove-addr-from-welcomelist=s' => \$opt{'remove-addr-from-welcomelist'},
'remove-addr-from-blocklist=s' => \$opt{'remove-addr-from-blocklist'},
'remove-from-welcomelist|R' => \$opt{'remove-from-welcomelist'},
'remove-addr-from-whitelist=s' => \$opt{'remove-addr-from-welcomelist'}, # removed in 4.1
'remove-from-whitelist' => \$opt{'remove-from-welcomelist'}, # removed in 4.1
'remove-markup|despamassassinify|d' => \$opt{'remove-markup'},
'report|r' => \$opt{'report'},
'revoke|k' => \$opt{'revoke'},
'siteconfigpath=s' => \$opt{'siteconfigpath'},
'test-mode|test|t' => \$opt{'test-mode'},
'progress' => \$opt{'progress'},
'version|V' => \$opt{'version'},
'x' => sub { $opt{'create-prefs'} = 0 },
#
# NOTE: These are old options. We should ignore (but warn about)
# the ones that are now defaults. Everything else gets a die (see note2)
# so the user doesn't get us doing something they didn't expect.
#
# NOTE2: 'die' doesn't actually stop the process, GetOptions() catches
# it, then passes the error on, so we'll end up doing a Usage statement.
# You can avoid that by doing an explicit exit in the sub.
#
# last in 2.3
'pipe|P' => sub { warn "The -P option is deprecated as 'pipe mode' is now the default behavior, ignoring.\n" },
'F:i' => sub { warn "The -F option has been removed from spamassassin, please remove from your commandline and re-run.\n"; exit 2; },
'add-from!' => sub { warn "The --add-from option has been removed from spamassassin, please remove from your commandline and re-run.\n"; exit 2; },
# last in 2.4
'stop-at-threshold|S' => sub { warn "The -S option has been deprecated and is no longer supported, ignoring.\n" },
# last in 2.6
'log-to-mbox|l:s' => sub { warn "The -l option has been deprecated and is no longer supported, ignoring.\n" },
'warning-from|w:s' => sub { warn "The -w option has been removed from spamassassin, please remove from your commandline and re-run.\n"; exit 2; },
'whitelist-factory|M:s' => sub { warn "The -M option has been removed from spamassassin, please remove from your commandline and re-run.\n"; exit 2; },
) or print_usage_and_exit();
if ( defined $opt{'help'} ) {
print_usage_and_exit("For more information read the spamassassin man page.\n", 'EX_OK');
}
if ( defined $opt{'version'} ) {
print_version();
exit($resphash{'EX_OK'});
}
# set debug areas, if any specified (only useful for command-line tools)
if (defined $opt{'debug'}) {
$opt{'debug'} ||= 'all';
}
if (Mail::SpamAssassin::Util::am_running_on_windows()) {
binmode(STDIN) or die "cannot set binmode on STDIN: $!"; # bug 4363
binmode(STDOUT) or die "cannot set binmode on STDOUT: $!";
}
# bug 5048: --lint should not cause network accesses
# allow --net to override for testing
if ($opt{'lint'} && !$opt{'net'}) { $opt{'local'} = 1; }
# create the tester factory
my $spamtest = Mail::SpamAssassin->new(
{
rules_filename => $opt{'configpath'},
site_rules_filename => $opt{'siteconfigpath'},
userprefs_filename => $opt{'prefspath'},
username => $opt{'username'},
force_ipv4 => $opt{'force_ipv4'},
force_ipv6 => $opt{'force_ipv6'},
local_tests_only => $opt{'local'},
debug => $opt{'debug'},
dont_copy_prefs => ( $opt{'create-prefs'} ? 0 : 1 ),
pre_config_text => join("\n", @{$opt{'pre'}})."\n",
post_config_text => join("\n", @{$opt{'cf'}})."\n",
require_rules => 1,
PREFIX => $PREFIX,
DEF_RULES_DIR => $DEF_RULES_DIR,
LOCAL_RULES_DIR => $LOCAL_RULES_DIR,
LOCAL_STATE_DIR => $LOCAL_STATE_DIR,
}
);
if ($opt{'lint'}) {
$spamtest->debug_diagnostics();
my $res = $spamtest->lint_rules();
$spamtest->finish();
warn "lint: $res issues detected, please rerun with debug enabled for more information\n" if ($res and !$opt{'debug'});
# make sure we notice any write errors while flushing output buffer
close STDOUT or die "error closing STDOUT: $!";
close STDIN or die "error closing STDIN: $!";
exit($res ? 1 : 0);
}
if ($opt{'remove-addr-from-welcomelist'} ||
$opt{'remove-addr-from-blocklist'} ||
$opt{'add-addr-to-welcomelist'} ||
$opt{'add-addr-to-blocklist'})
{
$spamtest->init(1);
if ( $opt{'add-addr-to-welcomelist'} ) {
$spamtest->add_address_to_welcomelist($opt{'add-addr-to-welcomelist'}, 1);
}
elsif ( $opt{'remove-addr-from-welcomelist'} ) {
$spamtest->remove_address_from_welcomelist($opt{'remove-addr-from-welcomelist'}, 1);
}
elsif ( $opt{'add-addr-to-blocklist'} ) {
$spamtest->add_address_to_blocklist($opt{'add-addr-to-blocklist'}, 1);
}
elsif ( $opt{'remove-addr-from-blocklist'} ) {
$spamtest->remove_address_from_blocklist($opt{'remove-addr-from-blocklist'}, 1);
}
else {
die "spamassassin: oops! unhandled welcomelist operation";
}
$spamtest->finish();
# make sure we notice any write errors while flushing output buffer
close STDOUT or die "error closing STDOUT: $!";
close STDIN or die "error closing STDIN: $!";
exit(0);
}
# if we're going to do welcome/block-listing, let's prep now...
if ( $opt{'remove-from-welcomelist'}
or $opt{'add-to-welcomelist'}
or $opt{'add-to-blocklist'} )
{
$doing_welcomelist_operation = 1;
$spamtest->init(1);
}
spamassassin.raw view on Meta::CPAN
SpamAssassin web site: https://spamassassin.apache.org/
Wiki-based documentation: https://wiki.apache.org/spamassassin/
=head1 USER MAILING LIST
A users mailing list exists where other experienced users are often able
to help and provide tips and advice. Subscription instructions are
located on the SpamAssassin web site.
=head1 CONFIGURATION FILES
The SpamAssassin rule base, text templates, and rule description text
are loaded from configuration files.
Default configuration data is loaded from the first existing directory
in:
=over 4
=item @@LOCAL_STATE_DIR@@/@@VERSION@@
=item @@DEF_RULES_DIR@@
=item @@PREFIX@@/share/spamassassin
=item /usr/local/share/spamassassin
=item /usr/share/spamassassin
=back
Site-specific configuration data is used to override any values which had
already been set. This is loaded from the first existing directory in:
=over 4
=item @@LOCAL_RULES_DIR@@
=item @@PREFIX@@/etc/mail/spamassassin
=item @@PREFIX@@/etc/spamassassin
=item /usr/local/etc/spamassassin
=item /usr/pkg/etc/spamassassin
=item /usr/etc/spamassassin
=item /etc/mail/spamassassin
=item /etc/spamassassin
=back
From those directories, SpamAssassin will first read files ending in
".pre" in lexical order and then it will read files ending in ".cf" in
lexical order (most files begin with two numbers to make the sorting
order obvious).
In other words, it will read F<init.pre> first, then F<10_default_prefs.cf> before
F<50_scores.cf> and F<20_body_tests.cf> before F<20_head_tests.cf>.
Options in later files will override earlier files.
Individual user preferences are loaded from the location specified on
the C<spamassassin>, C<sa-learn>, or C<spamd> command line (see respective
manual page for details). If the location is not specified,
F<~/.spamassassin/user_prefs> is used if it exists. SpamAssassin will
create that file if it does not already exist, using
F<user_prefs.template> as a template. That file will be looked for in:
=over 4
=item @@LOCAL_RULES_DIR@@
=item @@PREFIX@@/etc/mail/spamassassin
=item @@PREFIX@@/share/spamassassin
=item /etc/spamassassin
=item /etc/mail/spamassassin
=item /usr/local/share/spamassassin
=item /usr/share/spamassassin
=back
=head1 TAGGING
The following two sections detail the default tagging and markup that
takes place for messages when running C<spamassassin> or C<spamc> with
C<spamd> in the default configuration.
Note: before header modification and addition, all headers beginning
with C<X-Spam-> are removed to prevent spammer mischief and also to
avoid potential problems caused by prior invocations of SpamAssassin.
=head2 TAGGING FOR SPAM MAILS
By default, all messages with a calculated score of 5.0 or higher are
tagged as spam.
If an incoming message is tagged as spam, instead of modifying the
original message, SpamAssassin will create a new report message and
attach the original message as a message/rfc822 MIME part (ensuring the
original message is completely preserved and easier to recover).
The new report message inherits the following headers (if they are
present) from the original spam message:
=over 4
=item From: header
=item To: header
=item Cc: header
=item Subject: header
=item Date: header
=item Message-ID: header
=back
The above headers can be modified if the relevant C<rewrite_header>
option is given (see C<Mail::SpamAssassin::Conf> for more information).
( run in 1.013 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )