Projects & Stories

IMAP filtering for a remote mail server

Today I searched for a simple imap-filter-tool for my hosted mail server.

I found following tool written in C:

IMAPFilter is a mail filtering utility. It connects to remote mail servers using the Internet Message Access Protocol (IMAP), sends searching queries to the server and processes mailboxes based on the results. It can be used to delete, copy, move, flag, etc. messages residing in mailboxes at the same or different mail servers. The 4rev1 and 4 versions of the IMAP protocol are supported.


I had some smaller issues while compiling it, but afterwards the configuration was pretty simple.

If you have problems with finding lua.h header and already installed all dev-libraries you should think about adjusting the Makefile in src/Makefile:

@@ -9,14 +9,14 @@ MYLDFLAGS =

+LIBDIRS = -L /usr/lib

-LIBLUA = -llua
+LIBLUA = -llua5.2
 LIBPCRE = -lpcre
 LIBSSL = -lssl
 LIBCRYPTO = -lcrypto

+CFLAGS = -I/usr/include/lua5.2 -Wall -Wextra -O -DCONFIG_SHAREDIR='"$(SHAREDIR)"' $(INCDIRS) $(MYCFLAGS)

Well, the worst part is over! If you installed imapfilter globally you should be able to execute it and specify a lua config file:

options.timeout = 120  
options.subscribe = true

server = IMAP {  
  server = '',
  username = '',
  password = 's3cr3t'

github = server.INBOX:contain_from('') +  


Black magic is over! After first-time-execution it'll prompt you for certificate validation. After adding the correct certificate permanently you can add it to a cron-job or something similar.

Now every mail from and will be moved to INBOX/Git/Github!

Happy filtering!