What the script does

The script reads mailaddresses from the alias file which is used by mutt
and generates from these mailaddresses a whitelist entry in Spamassassin's
preferences-file in order to avoid false-positives from known senders.

The name of the aliasfile is searched in the following order: in
~/.muttrc, in all files sourced from ~/.muttrc by
mutt, in /etc/Muttrc. If it is defined in none of these files, the
filename defaults to ~/.muttrc.

Aliases have to be written in one of the following ways:

alias somealias Name <address@domain.tld>

alias somealias 1stName 2ndName <address@domain.tld>

alias groupaliasname <address1@domain1.tld>, <address2@domain2.tld>

NB: Group aliases, which are referencing user aliases, are ignored, since
expanding them would mean producing dupes, which are afterwards dropped
anyway

The script will read the alias-definitions, isolate the e-mailaddresses
(recognized as such is everything between < and >) and replace all
newline-characters with space-characters. It will then write these
mailaddresses into a whitelist-definition, which will be written to
~/.spamassassin/user_prefs1,
the preferences-file for Spamassassin.

When run for the first time the script will copy the 'old'
~/.spamassassin/user_prefs to
~/.spamassassin/user_prefs.temp, which will be used as a template
when including the generated whitelist in the 'new'
~/.spamassassin/user_prefs.So all future modifications have to
be written to ~/.spamassassin/user_prefs.temp since
~/.spamassassin/user_prefs will be overwritten each time the
script is run.

Why I wrote the script

Because I did not find a similar script on the 'Net. :-)

I was fed up with the spam I received which I could not filter effectively
because of the risk of false positives, ie mails from persons I know (whose
mailaddresses I have aliased in my ~/.muttalias) which are
certainly not spam.So I considered it necessary to automate the process of
generating a whitelist for Spamassassin and keeping it up-to-date , which can
now be easily done by running the script from a cronjob once a day.

The advantage of an automatically generated whitelist is that I now can
lower the number of hits required by spamassassin before a mail is considered
spam.I set 'required_hits 1.2' (default was 5) in
~/.spamassassin/user_prefs, so eg a mail which contains 'To:
undisclosed-recipients: ;' is already considered as spam, if it has no
whitelisted mailaddress in the 'From:', and thus will be filtered.

What the script does

The script reads mailaddresses from the alias file which is used by mutt
and generates from these mailaddresses a procmail-rule, which is written to
~/.procmailrc1, in order
to directly deliver mails from theses senders to a file to avoid any further
filtering by procmail.

The name of the aliasfile is searched in the following order: in
~/.muttrc, in all files sourced from ~/.muttrc by
mutt, in /etc/Muttrc. If it is defined in none of these files, the
filename defaults to ~/.muttrc.

Aliases have to be written in one of the following ways:

alias somealias Name <address@domain.tld>

alias somealias 1stName 2ndName <address@domain.tld>

alias groupaliasname <address1@domain1.tld>, <address2@domain2.tld>

NB: Group aliases, which are referencing user aliases, are ignored, since
expanding them would mean producing dupes, which are afterwards dropped
anyway

The script will read the alias-definitions, isolate the e-mailaddresses
(recognized as such is everything between < and >) and replace all
space-characters with newline-characters. It will then build from these
mailaddresses a procmail-rule, which will be written to
~/.procmailrc.

When run for the first time the script will write a backup of the 'old'
~/.procmailrc to ~/.procmailrc.bakxxx.It will
copy ~/.procmailrc to ~/.procmailrc3 so per default
the procmail-rule generated by the script will be written at the beginning of
the 'new' ~/.procmailrc.If you don't want the new procmail-rule
at the beginning of the 'new' ~/.procmailrc you have to split up
your ~/.procmailrc in ~/.procmailrc1 and
~/.procmailrc3 which are written before and after the generated procmail-rule.

~/.procmailrc : 'new' ~/.procmailrc, output of the script~/.procmailrc1 : first part of the 'old' ~/.procmailrc~/.procmailrc2 : generated procmail-rule~/.procmailrc3 : second part of the 'old' ~/.procmailrc, without manual changes complete 'old' ~/.procmailrc

This is the best way to implement a logical OR in
~/.procmailrc. As an alternative one could only create a separate
rule for each address.For details see the Procmail-manpage.

The target file $DEFAULT would make procmail write the mails to
$MAIL, ie usually /var(/spool)/mail/$USER. The target
file can be easily altered in the script by editing TARGET=

NB:
you can also whitelist whole domains by using the following line in the
alias-file (necessary eg if you communicate with several persons in a
company):
alias somecompany* <@somecompany.tld>

Why I wrote the script

When I had installed Spamassassin and played around a bit I discovered that
each mail caused a CPU-load of 100% for about 4-5 seconds on my P133, which
caused delays when several mails were arriving at once. So I decided I had to
sort out mails from known senders before they reached Spamassassin. The best
place to do so was ~/.procmailrc.