Friday, November 18, 2005

Notification when mutt Receives New Mail


After several months of using KDE's kmail to access my IMAP account at work, I gave up and decided instead to use the wonderful mail client mutt. I wanted to switch because using 29M of RAM for a mail program seems ridiculous to me, especially when mutt does just fine in under 5M. Additionally, I could never configure kmail's key bindings to be what I like (surely my failure there).




So I created a new .muttrc file to hold all the info about my IMAP mailboxes at work. A simple mutt -F work.muttrc starts up an instance to access my work accounts (I found this more suitable than using account-hook configurations). mutt works like a charm and handles S/MIME attachments even better than kmail does.




But, I couldn't figure out a way for mutt to execute an arbitrary shell script when it finds that I have new mail in my box. It turns out that despite all of mutt's useful hooks and configuration, it is not able to do what I want. From the ridiculous and impolite comments on this thread it seems the behavior is a design decision not an oversight.




I wasn't about to go back to using kmail after having mutt set up so nicely. So, here's a patch that adds the functionality to mutt. The patch is against mutt version 1.5.10i and adds the configuration variable new_mail_notify. Set the variable to the path of a shell script and it will be run as soon as mutt notices that you have new mail in the current folder. The patch is a bit rough, but it's worked for me for about a week now.

8 comments:

Anonymous said...

Great job mndrix! This is awesome... I've always wanted to get Mutt working with libnotify or some other means of letting me know what's up with my mail instead of just looking every now and then. The doors have just swung way open, thanks to you, we can now use libnotify, espeak, dmenu, xmessage or whatever to let ourselves know that we have mail!

Only one problem, I can't get the patch... Looks like a server not found error. Any idea why that might be? Also, would you be interested in porting the patch to the newest revision of mutt? If not I understand, it sounds like the development community gave you a pretty hard time in the past.

Great job again mndrx,

Chrelad

mndrix said...

Hi Chrelad. The server that used to have the patch died a while back. Unfortunately, it looks like I didn't have any backups of it :-( I looked around, but I don't have a copy of that patch anymore either. I'm sorry.

Anonymous said...

Aaahhhhhhhhhhhhhhh! Nooooooooooooooo :( Well, that's how life goes... A pile of gold drops into your lap, and then some little black handed spider monkey hops leaps into your lap and steals it!

If you ever get a chance to... well, re-write the whole thing, let me know and I'd be happy to use it or test it or whatever :)

Thanks mndrix,

Chrelad

Unknown said...

Just a note that you can do this (inefficiently) without a patch, using status_format set to call out to a script (see eg contrib/mutt_xtitle in the mutt source tree).

Anonymous said...

Thanks Brendon, I'll check that out... I'll gladly take a bit of inefficiency over missing emails and being reprimanded for it later :p

Thanks for the great tip :)

Chrelad

Anonymous said...

Also, you can count files in your ~/Maildir or, say, Subject: headers in ~/mail using a background script.

Joerg said...

The link to the patch is no more valid.
Could you provide the mutt-new_mail_notify.patch?

Thanks a lot.

mndrix said...

Hi Joerg. As mentioned in the comments above, the patch has been lost. The other comments also suggest a possible work around using status_format. It's not ideal, but hopefully it helps.