Procmailgen : Easily classifying mailing lists in folders with procmail

Procmail is a program for filtering electronic mail. It is very useful for pre-sorting and pre-processing large amounts of incoming mail. You can use it to sort out mail from mailing lists, to dispose of junk mail, to send automatic replies, or even to run a mailing list.

I am using it to classify incoming mail from the mailing lists that I am subscribed into folders, and when you are subscribed to a large amount of mailing lists it can be painful to write all the rules and you might end with a copy-paste-monkey-complex. So I wrote an small program in Python that will generate a .procmailrc file for your convenience. You must feed the program with your email address and the path to a file containing the mailing lists that you are subscribed to and the folder you want them to be delivered.

The file has the following format:

[folder1]
list1@example.com
list2@example.com

[folder2]
list3@example.com
list4@example.com

A real example:

[debian-security]
debian-security-announce@lists.debian.org
debian-security@lists.debian.org

[networking]
debian-isp@lists.debian.org
debian-firewall@lists.debian.org
debian-ipv6@lists.debian.org
linux-net@vger.kernel.org
netdev@vger.kernel.org
netfilter@vger.kernel.org
netfilter-devel@vger.kernel.org

[wireless]
hostap@lists.shmoo.com
linux-wireless@vger.kernel.org

[filesystems]
linux-btrfs@vger.kernel.org
linux-raid@vger.kernel.org

And the program will generate a .procmailrc from the templates that are defined within it and output the file to stdout.

The current templates are optimised for Dovecot mailboxes and SpamAssassin filter but you can easily change it to feet your needs by editing them within the program file.

But this way I keep my subscriptions in easy-to-read-and-edit file and each time I change them I simply re-run procmailgen against it:

./procmailgen.py mailinglist-folders my@email.com >~/.procmailrc 

You can download the code here. Hope that you will find it useful. Don’t forget to create the mail folders with your email client.

UPDATE 01-2011: Moved the code to a repository at github and added support for managing RSS Feeds with rss2email

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>