Initialen














Change color to default
Change color to red
Change color to blue
Change color to green
Change color to yellow
Change color to cyan
Change color to magenta
Change color to orange
Change color to b/w

fuschlberger.net - Scripts for mutt

Change color to default
Change color to red
Change color to dark red
Change color to blue
Change color to dark blue
Change color to green
Change color to dark green
Change color to yellow
Change color to dark yellow
Change color to cyan
Change color to dark cyan
Change color to magenta
Change color to dark magenta
Change color to magenta
Change color to dark orange
Change color to grey
Change color to b/w

Printme!

Two small scripts for mutt, spamassassin and procmail





On this page you will a find two tiny scripts:

1. muttalias2sawhitelist.sh - mutt's aliases converted to Spamassassin-whitelist
2. muttalias2procmail.sh - mutt's aliases converted to procmail-instant-delivery-rule

Both of them are shellscripts, no perl etc. is needed.

All comments, suggestions etc. are welcome. Please contact me at wf-hp@gmx.net.

Links:
Spamassassin
Mutt
Procmail



1. muttalias2sawhitelist.sh

View the source

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.

Download the script here.


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.



2. muttalias2procmail.sh

View the source

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.

In short:
~/.procmailrc = ~/.procmailrc1 + ~/.procmailrc2 + ~/.procmailrc3.

~/.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 what the generated rule looks like:

:0:
* 1^0 ^From: .*address1@domain1.tld
* 1^0 ^From: .*address2@domain2.tld
* 1^0 ^From: .*@domain3.tld
[...]
$DEFAULT

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.

Download the script here.



[1] all filenames mentioned are the default values which can be easily changed in the scripts

Written 2002-08-09 - last update: 2006-08-10


Change color to defaultChange color to redChange color to blueChange color to greenChange color to yellowChange color to cyanChange color to magentaChange color to orangeChange color to b/w

© 2014 by wf
webslave (at) fuschlberger.net
Medieninhaber:
Wolfgang Fuschlberger, Salzburg

[Valid-HTML-4.01]