Loading
May 8, 2016

If you can’t beat ‘em..clean ’em. Using imapfilter for remote rules to an IMAP mailbox

Software engineers receive tons of e-mails. Academics do, too. I am both. As several users do, I use inbox rules to flow my incoming messages. For example, e-mails concerning call for papers go straight to an inbox folder called CFP. E-mails related to editorial concerns go to a folder called EDITORIAL. E-mails sent to several distribution lists go to..the trash.

And so on.

When using systems such as Gmail and Exchange, creating inbox rules (or filters) is rather simple. However, there are several scenarios in which server-side rules do not apply, nor would importing the e-mails to services such as Gmail. One could do client-side filtering, for example by creating rules in clients such as Apple.mail. However, what about a smartphone or a tablet? I wanted to have a way to simulate server-side mail filtering with rules so that e-mails on my Macbook Pro, my iPhone, and my iPad are synchronized and already processed when downloaded.

Turns out that somebody has thought about this issue. Imapfilter is indeed a console-based IMAP filtering system. The program connects to one or more IMAP server and processes the e-mails based on some rules. The following diagram conceptualizes the process (yes, I did it for testing the Apple Pencil):

imapfilter

Each two minutes, the imapfilter connects to my work IMAP server, filters the e-mails according to my rules, and exits. Every 15 minutes, the e-mail clients on my devices download the mail. That is it. The system is not perfect, as it might rarely happen that the e-mails are downloaded before imapfilter processes them. However, they will get sorted out anyway at the next run. I am happy with it.

So this post is basically advertisement for imapfilter, as it made me much, much happy but it was not easy to find about it. Perhaps I was looking for wrong terms such as “serverless email filtering” or “cloud based email filter system”. Glad I found it. Imapfilter installation was just a matter of doing

The configuration was easy. I took inspirations from imapfilter man page and the posts in here and in here. The configuration has to be placed in the file config.lua within the directory ~/.imapfilter.

Here is a reduced and anonymized version of my config.lua file:

For running imapfilter each two minutes, I created the file ~/bin/cleanimap.sh, which uses a PID file system to run imapfilter only when it is not running already (for sessions longer than two minutes).

Finally, for excuting the script each two minutes, I run the command crontab -e, and I added the following line.

written by dgraziotin

Dr. Daniel Graziotin received his PhD in computer science, software engineering at the Free University of Bozen-Bolzano, Italy. His research interests include human aspects in empirical software engineering with psychological measurements, Web engineering, and open science. He researches, publishes, and reviews for venues in software engineering, human-computer interaction, and psychology. Daniel is the founder of the psychoempirical software engineering discipline and guidelines. He is associate editor at the Journal of Open Research Software, academic editor at the Research Ideas and Outcomes (RIO) journal, and academic editor at the Open Communications in Computer Science journal. He is the local coordinator of the Italian Open science local group for the Open Knowledge Foundation. He is a member of ACM, SIGSOFT, and IEEE.