Inside Out

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:


* ^To:.*


:0 c


`:0 h`

| grep “From:” | ~/src/_scripts/ratpoison/


And the script


read from

ratpoison -c “echo Mail $from”

**Discussion:** Here's the breakup

- `*^To:*` Catch all mails which have their **To:** field containing **** - 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 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]( "New mail notification for evolution"). New to procmail, go [here]( "Awesome procmail tutorial").

/me is having bit overdose of [cookbooks]( "Oreilly cookbook presentation format") these days ;)