Notes on seeking wisdom and crafting software

New mail notification with Procmail

Problem: I have my local mail setup with mutt, fetchmail and procmail. And I would need a way to run an arbitrary script when new mail arrives and not loose the mail from my inbox.

**Solution:** Procmail supports a nice feature called nesting. With nested blocks a procmail recipe can be assigned more than action.

e.g: Here’s a recipe to filter all my email from gmail:

:0:

* ^To:.*gmail.com

{

:0 c

$MAILDIR

`:0 h`

| grep “From:” | ~/src/_scripts/ratpoison/newmail.sh

}

And the newmail.sh script

#!/bin/bash

read from

ratpoison -c “echo Mail $from”

**Discussion:** Here's the breakup

- `*^To:*gmail.com` Catch all mails which have their **To:** field containing **gmail.com** - Nesting: specify the actions inside { .. } - `:0 c - `Copy the mail into \$MAILDIR - `:0 h` - Pipe the header into **grep**. And pipe the output ("From:\*") into newmail script - In newmail.sh script, read the piped content into variable **\$from** and display that in ratpoison message bar

If your window manager has a notification tray, you may be interested in [this](http://pugio.net/2006/12/new-mail-notifier-for-evolutio.html "New mail notification for evolution"). New to procmail, go [here](http://userpages.umbc.edu/~ian/procmail.html "Awesome procmail tutorial").

/me is having bit overdose of [cookbooks](http://oreilly.com/images/cookbooks/spread.gif "Oreilly cookbook presentation format") these days ;)