chris blogs

August 2010

06aug2010 · xlbiff with maildir

I am not a friend of popup notification nor mail checking, and for years I followed a rather strict rule of only actively checking mail and then reading it.

This post by Chris Siebenmann changed my view of that, and I decided to give xlbiff a try.

A short overview of my custom mail setup: I use offlineimap to sync a set of local maildirs with Gmail. I run a local Dovecot and then access my mail with Gnus (or theoretically any other IMAP client). Outbound mail is handled by Postfix with a Gmail as smart-host.

This sounds like a contrived setup for a notebook, but it actually is very useful. I can read and write mail offline, as well as use classic Unix tools and scripts such as mail(1) to send mail.

Anyway, xlbiff by default monitors a Unix mailbox which I don’t use. I have thus adjusted it to use my local maildirs as input. xlbiff makes this rather easy as it can use user-supplied “check” and “scan” scripts.

The check script, called xlmdcheck, sees if the state of mail has changed. It returns 1 if nothing has changed, 2 if no unread mail exists and 0 if it should popup the window with the output of the scan script.

# xlmdcheck - xlbiff script to check maildirs

HASH=$(ls ~/Mail/*/*/*2, | grep -v "Sent Mail" | cksum | cut -b1-9)
echo $HASH
if [ $2 -ne $HASH ]; then
  if [ $HASH -eq 429496729 ]; then  # empty output
    exit 2
    exit 0
exit 1

Then, the scan script, called xlmdscan, to output a summary line for each unread mail:

# xlmdscan - xlbiff script to output summary of maildirs

ls ~/Mail/*/*/*2, | grep -v "Sent Mail" |
  xargs -i scan -file '{}' -width $(expr $2 + 7) -form scan.timely | cut -b7-

This uses MH’s scan(1) to parse the headers, but we cut off the initial numbering which gets lost due to the xargs. Oh well.

Finally we can run it:

% xlbiff -scanCommand "xlmdscan %s %d" -checkCommand "xlmdcheck %s %d"

A screenshot of the thing in action:

xlbiff in action

NP: Love—The Good Humor Man He Sees Everything Like This

Copyright © 2004–2016