~derf / interblag / entry / Checking Maildirs on the Commandline
dark mode

I have a set of maildirs (one for each mailing list / other context) and want to know which of them contains unread mail without firing up my MUA.

Luckily, this is easy to do on the commandline without even looking at mail contents, as there's (mostly?) two kinds of unread mail:

  • new and unprocessed mail. These messages are stored in Maildir/new, so if there's anything in there, it's an unread mail
  • new but no longer "Recent" mail. These messages have not been read yet, but have already been transferred to a MUA using a Read-Write operation, causing them to be marked as no longer new on the server side. They are stored in Maildir/cur alongside read mail, but do not have the "Seen" (S) flag set.

This is easy to check with zsh globbing: new/*(N) expands to a non-empty list if new and unprocessed mail is present, and cur/*~*,*S*(N) expands to a non-empty list if old but unread mail is present. Note that it requires the extended_glob zsh option to be set.