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.

GitHub: https://github.com/lefcha/imapfilter

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 =
     MYLIBS =
    
     INCDIRS =
    -LIBDIRS =
    +LIBDIRS = -L /usr/lib
    
    -LIBLUA = -llua
    +LIBLUA = -llua5.2
     LIBPCRE = -lpcre
     LIBSSL = -lssl
     LIBCRYPTO = -lcrypto
    
    -CFLAGS = -Wall -Wextra -O -DCONFIG_SHAREDIR='"$(SHAREDIR)"' $(INCDIRS) $(MYCFLAGS)
    +CFLAGS = -I/usr/include/lua5.2 -Wall -Wextra -O -DCONFIG_SHAREDIR='"$(SHAREDIR)"' $(INCDIRS) $(MYCFLAGS)
     LDFLAGS = $(LIBDIRS) $(MYLDFLAGS)
     LIBS = -lm $(LIBLUA) $(LIBPCRE) $(LIBSSL) $(LIBCRYPTO) $(MYLIBS)
    

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 = 'remote.host',
      username = 'lukas@remote.host',
      password = 's3cr3t'
    }
    
    github = server.INBOX:contain_from('notifications@github.com') +  
             server.INBOX:contain_from('noreply@github.com')
    
    github:move_messages(gandi['INBOX/Git/Github'])  
    

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 notifications@github.com and noreply@github.com will be moved to INBOX/Git/Github!

Happy filtering!

Call me ghost

Since yesterday I am using Ghost instead of tumblr.

echo "Hello World";  
    

It served me well, but self-hosted has a sweeter flavor :)

I modified the default ghost theme for having different icons (e.g. diaspora icons) and adding diaspora share functionality to the post section.

You'll find the theme code here: zabica.git
For sharing posts to diaspora I am using: sharetodiaspora.github.io

corkboard snippets

A while ago I posted on sechat.org some one-liner I should remember... here we go:

I have more then hundred commits and I need from every single commit a specific file! In my case it is a file called snortrules-snapshot:

for COUNT in {1..142}  
    do  
      git checkout HEAD~$COUNT; 
      fname=$(git log -1 |grep Date |cut -c 7- |tr -d ' '); 
      mkdir -p /tmp/$fname;
      cp */snortrules-snapshot* /tmp/$fname/;
      git checkout master; 
    done  
    

change global commit-author in git:

git filter-branch --commit-filter '  
      if [ "$GIT_AUTHOR_EMAIL" = "lukas@work.com" ];
      then export GIT_AUTHOR_NAME="Lukas Matt";
        export GIT_AUTHOR_EMAIL=lukas@zauberstuhl.de;
      fi;
      git commit-tree "$@"'
    

nice little shell one liner for transferring files:

while true;  
      do {
        echo -e 'HTTP/1.1 200 OK\r\n';
        cat File-name;
      } | nc -l 8080;
    done