I have found some discussions on this forum regarding email filtering and thought I should give procmail a shot.
I ran across some minor issues when I tried this but they were easily solved and I thought I should share the experience.
First the disclaimer: This howto requires SSH and root access to the Bubba. Do not do attempt this unless you know what you are doing as it may mess up the bubba and/or throw away the incoming emails unless properly configured.
So, here goes:
Install procmail (as root):
Code: Select all
apt-get install procmail
Code: Select all
nano .procmailrc
Here is a sample .procmailrc:
Code: Select all
SHELL=/bin/sh
PATH=/usr/bin:/usr/local/bin
MAILDIR=$HOME/Mail/
DEFAULT=$MAILDIR
PMDIR=$HOME/.pmlog
LOGFILE=$PMDIR/pmlog
VERBOSE=yes
:0: # Facebook
* ^From.*facebook
$DEFAULT.INBOX.Personal.Facebook/
:0: # Newsletters
* ^From.*opencores|\
^From.*avanza|\
^From.*dustin|\
^From.*avagonow|\
^From.*youtube|\
^From.*flysas
$DEFAULT.INBOX.Personal.News/
:0: # All other mail go into INBOX
$DEFAULT
It also tels procmail to store the activity log in a file called 'pmlog' in the folder '.pmlog' in my home (you might have to create the folder fist, not sure about that)
I also tells it to be "verboseive" as that gives me more info in the log on the filtering results which is useful when debugging the filtering.
I have two filters configured. One will grab all facebook mail and store them in a subfolder I have created in my Inbox called "Personal/Facebook". Since Bubba uses maildir format for mails, it is important to add the last '/' to the path or else procmail will assume mbox format and store your mails "incorrectly".
I also have a bigger rule for all mail I consider news, and any hit on the OR:ed list of addresses will send the mail to my "Personal/News" folder.
The rules use reg-exp:s and you can of course set up pretty sophisticated rules here, but this is out of the scope of this howto. Google is good if you want to learn more about "procmail recipies".
My last rule basically takes all mail that fell through the previous rules and put them in my inbox.
When you have finished editing .procmailrc make sure the permissions on the file is good for procmail to use.
I had to change it in order to make it work:
Code: Select all
chmod 640 ~/.procmailrc
This is done by adding this string after the configuration(s) you want to enable procmail for in /etc/fetchmailrc (as root):
mda "/usr/bin/procmail -d %s"
A sample fetchmailrc for gmail retrieval could look something like this:
Code: Select all
set postmaster "postmaster"
set bouncemail
set no spambounce
set properties ""
set daemon 300
set syslog
poll imap.gmail.com with proto IMAP
user 'account@gmail.com' there with password 'secret' is 'bubba-user' here ssl mda "/usr/bin/procmail -d %s"
Replace account with your gmail username and replace secret with the password you use on gmail. Finally replace 'bubba-user' with the bubba user you want to receive the mail.
The last mda-string will tell procmail that it should parse the .procmailrc file in the 'bubba-user' home directory when determining where the mail should go.
Fetchmail will automatically detect changes to /etc/fetchmailrc so the next scheduled poll should now send the mails through the procmail filtering. And this enables server-side mailfiltering also for IMAP.
Make sure you get the recipies right in .procmailrc or procmail might throw away your mail (for me, it sent them to /var/mail/<user> when I messed up my config)
I hope you find the mini-howto useful. Feel free to add any improvements and/or corrections.
Best regards,
Patrick Fallberg