How can I determine if there is unread mail on my OSX box?
Mail is fetched from a variety of places with fetchmail, and delivered to my local user in /var/mail/user. I am searching for a way to find out if there is unread mail, or if I have read the mail (using alpine). I prefer a solution that uses unix tools, but am open to AppleScript or any other solution for the unread count part, but it must work with unix mail readers (/var/mail/user).
I'd like to have a command line tool that says if there is unread mail in the inbox, so that I can run it with a cron job, and use the keyboard_leds tool to set subtle notifiers. I prefer this to MacBiff, growlnotify, etc.
I thought I figured out one possible solution:
mail -H | grep -c '^.[NU]'
seems to sometimes return the number of unread messages. But if I read a message in alpine, it doesn't update until I quit alpine.
Another approach might be to use my mail client (alpine) directly. I have a clean .pinerc which has no colors, etc trying to make the display as simple as possible, and then run this command:
alpine -o -x .pinerc.clean -I i,q >& foo
Which runs alpine, goes to the Inbox, and then quits (leaving the inbox in read-only mode so as to not disrupt my main alpine process which is viewing the inbox). The screen dump of the inbox is stored in the file "foo".
However, foo the last screen (quitting message, not inbox) and is a binary file in this case, and I cannot figure out how to parse it for the "N" in the column that designates unread mail, even if it were there...