By Alan Schwartz
Book Price: $24.95 USD
£17.50 GBP
PDF Price: $19.99
Cover | Table of Contents | Colophon
http://spf.pobox.com) to determine if that
system is permitted to send messages from users at that domain. This
feature requires SpamAssassin 3.0.
http://www.hashcash.org). Spammers cannot do
these computations and still send out huge amounts of mail rapidly.
This feature requires SpamAssassin 3.0.
http://www.cpan.org.http://www.cpan.org.$ su Password: XXXXXXX # perl -MCPAN -e shell cpan shell -- CPAN exploration and modules installation (v1.61) ReadLine support enabled cpan> o conf prerequisites_policy ask prerequisites_policy ask cpan> install Mail::SpamAssassin CPAN: Storable loaded ok CPAN: LWP::UserAgent loaded ok Fetching with LWP: ftp://ftp.perl.org/pub/CPAN/authors/01mailrc.txt.gz ... Running install for module Mail::SpamAssassin Running make for J/JM/JMASON/Mail-SpamAssassin-2.60.tar.gz Fetching with LWP: ftp://ftp.perl.org/pub/CPAN/authors/id/J/JM/JMASON/Mail-SpamAssassin-2.60.tar.gz CPAN: Digest::MD5 loaded ok Fetching with LWP: ftp://ftp.perl.org/pub/CPAN/authors/id/J/JM/JMASON/CHECKSUMS Checksum for /root/.cpan/sources/authors/id/J/JM/JMASON/Mail-SpamAssassin-2.60.tar.gz ok Scanning cache /root/.cpan/build for sizes Mail-SpamAssassin-2.60/ Mail-SpamAssassin-2.60/ninjabutton.png ... Mail-SpamAssassin-2.60/sample-spam.txt CPAN.pm: Going to build J/JM/JMASON/Mail-SpamAssassin-2.60.tar.gz What email address or URL should be used in the suspected-spam report text for users who want more information on your filter installation? (In particular, ISPs should change this to a local Postmaster contact) default text: [the administrator of that system] postmaster@example.com Checking if your kit is complete... Looks good Writing Makefile for Mail::SpamAssassin Makefile written by ExtUtils::MakeMaker 6.03 /usr/bin/perl build/preprocessor -Mconditional -Mbytes -DPERL_VERSION=5.8.0 -Mvars - DVERSION=2.60 -DPREFIX=/usr <lib/Mail/SpamAssassin/AutoWhitelist.pm >blib/lib/Mail/ SpamAssassin/AutoWhitelist.pm ... gcc -g -O2 spamd/spamc.c spamd/libspamc.c spamd/utils.c \ -o spamd/spamc -ldl ... Manifying blib/man3/Mail::SpamAssassin::PerMsgLearner.3pm /usr/bin/make -- OK Running make test PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/basic_lint................ok ... t/zz_cleanup................ok All tests successful, 1 test skipped. Files=40, Tests=301, 426 wallclock secs (238.53 cusr + 14.19 csys = 252.72 CPU) /usr/bin/make test -- OK Running make install Installing /usr/lib/perl5/site_perl/5.8.0/Mail/SpamAssassin.pm Installing /usr/lib/perl5/site_perl/5.8.0/Mail/SpamAssassin/PerMsgLearner.pm ... Installing /usr/bin/spamc Installing /usr/bin/spamd Installing /usr/bin/sa-learn Installing /usr/bin/spamassassin Writing /usr/lib/perl5/site_perl/5.8.0/i586-linux-thread-multi/auto/Mail/ SpamAssassin/.packlist Appending installation info to /usr/lib/perl5/5.8.0/i586-linux-thread-multi/ perllocal.pod /usr/bin/perl "-MExtUtils::Command" -e mkpath /etc/mail/spamassassin ... /usr/bin/make install -- OK cpan>
spamassassin from
a shell is a handy way to test the system, but for daily use
you'd like to have it automatically run on every
incoming email message that's being delivered to
your system's mailboxes. One easy way to do this is
to have your system's MDA program filter all
messages through SpamAssassin as part of the delivery process.
DROPPRIVS=yes PATH=/bin:/usr/bin:/usr/local/bin SHELL=/bin/sh # Spamassassin :0fw * <300000 |/usr/bin/spamassassin
# Spamassassin. The first line
tells procmail that the message should be filtered
(f) and that procmail should wait
(w) for the filter's successful
exit before considering the message filtered. The second line
indicates that this recipe should be applied to messages less than
300,000 bytes in length and serves to prevent a lengthy SpamAssassin
invocation on a long message that is unlikely to be spam. The third
line directs procmail to pipe the message to
spamassassin script (and starting the
Perl interpreter) for each message can become prohibitive. An
alternative approach is to run the SpamAssassin daemon,
spamd. spamd is started once at
system boot and loads the SpamAssassin Perl modules to perform
spam-checking. Instead of running the spamassassin
script on each message, messages are piped to the
spamc program. spamc is a
lightweight client, written in C and compiled to an executable that
simply takes messages, relays them to spamd, and
returns the results.spamd has several important command-line arguments
that control its operation. Once it's properly set
up, however, using spamc is simple.spamd is installed in
/usr/bin. It is typically started by
root from a system boot script but can also be
started by root from the shell for testing. The
simplest invocation of spamd is:/usr/bin/spamd --daemonize --pidfile /var/run/spamd.pid
--daemonize
command-line option directs spamd to operate as a
daemon in the background. The --pidfile
command-line option specifies the file to which
spamd will write its process ID number. This
option is important because spamd must be signaled
with a HUP signal to its process ID whenever the systemwide
SpamAssassin configuration is changed (you'll find
an example later in this chapter).spamd receives a connection, it forks a child
process to handle the connection. Typically, the child process reads
a request to perform spam-checking from the client (including the
account name of the user making the request, the message to check,
and other data), performs the requested check, returns the (possibly
tagged) message back to the client, and exits.spamd in many
environments. The most common are detailed in the following sections.spamassassin script, accepting a
message on standard input, checking it, and producing the (possibly
rewritten) message on standard output. Example 2-8
illustrates the process for SpamAssassin
2.63.
#!/usr/bin/perl use Mail::SpamAssassin; my @lines = <STDIN>; my $mail = Mail::SpamAssassin::NoMailAudit->new(data => \@lines); my $spamtest = Mail::SpamAssassin->new( ); my $status = $spamtest->check($mail); $status->rewrite_mail( ) if $status->is_spam( ); print $status->get_full_message_as_text( );
@lines.
Then, the new( ) method of
Mail::SpamAssassin::NoMailAudit is called, with
a reference to the array provided as the value of the data
parameter. This method returns
a Mail::SpamAssassin::Message object
encapsulating the email message, which I call
$mail in the example.$spamtest is then created, and its check(
) method is called, passing in the message as an argument.
check( ) returns a
Mail::SpamAssassin::PerMsgStatus object, called
$status in the script, that contains a copy of the
message as well as the results of the spam check. In particular, the
is_spam( ) method of
$status returns 1 if the message was judged to be
spam, and 0 otherwise.rewrite_subject is on, SpamAssassin also changes
the subject of the message to begin with *****SPAM*****. Example 2-10 shows these
headers.
Subject: *****SPAM***** Live your dream life!! MPNWSTU
X-Spam-Status: Yes, hits=12.9 required=5.0 tests=CLICK_BELOW,
FORGED_MUA_EUDORA,FROM_ENDS_IN_NUMS,MISSING_OUTLOOK_NAME,
MSGID_OUTLOOK_INVALID,MSGID_SPAM_ZEROES,NORMAL_HTTP_TO_IP,
SUBJ_HAS_SPACES,SUBJ_HAS_UNIQ_ID autolearn=no version=2.60
X-Spam-Flag: YES
X-Spam-Checker-Version: SpamAssassin 2.60 (1.212-2003-09-23-exp)
X-Spam-Level: ************
T_ refer to rules in
testing.T_ refer to rules in
testing.spamassassin
--test-mode, as described in Chapter 2.
score directive
to the configuration file, like this:score HTML_WIN_OPEN 2
describe directives. For example, the
default description for the HOT_NASTY test is
"Possible porn - Hot, Nasty, Wild,
Young". To shorten that to
"Possible porn", add this directive
to the configuration file:
describe HOT_NASTY Possible porn
score directive in per-user preference files to
change the scoring of a test for an individual user. To do so, a user
edits the .spamassassin/user_prefs file in her
home directory and adds score directives. This
approach to customizing scores is the simplest, but it requires users
to have accounts on the system and access to files in their accounts.
spamd is performing spam-checking, unless the
allow_user_rules option is set to 1 in the
systemwide configuration. However, setting this option is dangerous
because spamd runs as root
and a malicious or inexperienced user can construct a custom test
that causes the system to hang or to invoke an arbitrary command as
nobody or as
spamd's uid. Users who want their
own tests on a system that uses spamd should
reinvoke the spamassassin script on their incoming
mail (probably in their .procmailrc). Chapter 2 illustrates this approach.describe directive. For now, do not begin any of
your names with a double underscore (_ _). Test
names that begin with two underscores are not listed in test hit
reports, nor are they added to the spam score on their own; such
names are used for creating sets of subtests that should be applied
in combination. SpamAssassin calls these combinations meta
tests, and they are discussed later in this
section.
|
Message part
|
|---|
loadplugin directive. Plug-ins extend
SpamAssassin's features.check_rbl(
)whitelist_from directive to whitelist a
sender's address. The sender's
address is the address that appears in the
Resent-From header, if that header exists, or in
any of the headers: From,
Envelope-Sender,
Resent-Senderhttp://www.paulgraham.com) and Gary Robinson
(http://www.garyrobinson.net).spamd, and the procmail recipe can use
spamc for faster spam-checking.spamd, and the procmail recipe can use
spamc for faster spam-checking.MAILER(`local') line) and regenerate
sendmail.cf from
it:
FEATURE(`local_procmail',`/path/to/procmail')dnl
DROPPRIVS=yes PATH=/bin:/usr/bin:/usr/local/bin SHELL=/bin/sh # Spamassassin :0fw * <300 000 |/usr/bin/spamassassin
spamd, replace the call to
spamassassin in procmailrc
with a call to sendmail process and defines
functions to call at different points of the SMTP transaction to
accept, reject, discard, temporarily refuse, or modify a message. The
milter library, libmilter, provides most of the
code required to set up a milter and manage the work of calling your
filtering functions during an SMTP
transaction.
HELO or EHLO
commandsMAIL FROM commandRCPT TO command