About Archive Tags RSS Feed


If you read the TV Guide, you don't need a TV

19 April 2008 21:50

So I've written a quick hack. A client-side filter/utility program for working against IMAP servers.

Consider it a general purpose system which is similar to Procmail, but applied after your remote machine has already done the sorting.

Here's a flavour:

  username somebody.like.me
  password yeah.right

        unread exec /usr/local/bin/notify "Livejournal Comment"
        mark read

        mark read


What does that do? It first of all logs into GMail with the given username and password, then selects two folders:


For each unread message in the folder it runs the specified command with STDIN being the message body.

Then it marks each new message as "read".


This simple rule just marks all messages as read.

Why? Well I have a bunch of folders on a bunch of gmail accounts and I don't pay attention to them - but some, specific, mails should result in an SMS being sent to me ... so I need to do something clever.

I'm sure with a bit of effort this could be made IMAP-server independent, and could have a more flexible matching system. The simplicity right now comes about primarily because i dont want to parse a config file.

Anyway, suggestions for potential features are welcome. It does what I need as-is, even if it isn't pretty.

ObQuote: Lost Boys



Comments on this entry

icon JD at 07:41 on 19 April 2008
Just wondered if you'd looked at imapfilter before you wrote this. It's in Debian. The config file is basically a lua script.
icon Steve Kemp at 12:15 on 19 April 2008


I did search, but managed to fail to spot that. It looks great, with one minor exception - I dont want to write a program to process the mails, I want to write a rules file.

Other than that though ideal. I even like/love lua!

My specific goal was do do simple things like:

  • If the folder X
  • Contains a new message.
  • With "foo" in the subject.
  • Then run program Y with the message piped to it
  • And mark the message as read.

I guess there are more general things you could do, such as matching body-text, etc, which would be fun to add, but not required by me personally.

I will need to think which is least effort:

  • Converting imapfilter to read some rules.
  • Adding a rule-language, or different config format to my toy program.

All my code is very clean and minimal, thanks to Net::Imap::Simple[::SSL] so I'd not be too upset to abandon it!