Filter and move emails with imapfilter.pl

imapfilter.pl is a set of perl scripts that can help you to automate filtering emails. The script(s) can run in cron on a regular basis.

First you need to download, unpack and install the scripts some place on your server.

Then, you have to create a rule.txt file which might contain several lines. For example:

From    "Cron *"        Inbox   Trash
Subject    "*error message *"     Inbox   Trash
From    "email.campaign@sg.booking.com" Inbox   Trash

This rule.txt file will filter the Inbox folder, and move the emails matching to Trash.
Important: The field separator is a Tab in the rule.txt file. Normal space would not work. Hint: use vim-editor, and press the tab-key on your keyboard.

In order to filter your messages, you apply this command:

./bin/imapfilter.pl -S yourserver-adress.com:993/your-username/your-password -r rule.txt

By making many rules in different text files, you can run many different filter jobs on your Inbox and other mailboxes if you wish, on your IMAP server(s), on different dates and time.

For instance:

Every day you could run an automated job that would delete all Trash emails at 17:00 when you finish work (cron jobs, advertising, and so on).
And every end of the month, you can filter out your colleagues emails, and store them in a IMAP folder called WORKPEOPLE for instance.

Links:

* https://github.com/andrewnimmo/rick-sanders-imap-tools

* http://www.athensfbc.com/imap_tools/

* https://code.google.com/p/imaputils/

Leave a Reply

Your email address will not be published. Required fields are marked *