Resolving unread mail count with different mail clients

While looking for a new MUA, I’ve had to come up with different ways for displaying an unread mail count on my desktop.

notmuch

Naturally, notmuch is the easiest, as long as you’ve finalized your policy as to what consitutes new mail.

notmuch search tag:inbox and <OTHER CONDITIONS> | wc -l

claws

claws has excellent command line switches for just about everything.

claws-mail --status-full | awk '/INBOX$/ { sum+=$2 } END { print sum; }'",

evolution

evolution doesn’t have a good command line interface. One has to go through its cache, which seems to be kept up-to-date.

for i in ~/.cache/evolution/mail/*; do
    sqlite3 "$i/folders.db" "select count(*) read from INBOX where read == 0";
done | awk '{ sum += $1; } END { print sum; }'")

“Work offline” status

It’s easy to flip the “work offline” switch in evolution without noticing. Luckily you can get its value easily.

gsettings get org.gnome.evolution.shell start-offline

thunderbird

thunderbird has no interface either. You should avoid reading global-messages-db.sqlite, because thunderbird doesn’t really update it:

sqlite3 ~/.thunderbird/*/global-messages-db.sqlite 'SELECT count(*) FROM messageAttributes where attributeID=58 and value=1'

Instead, grab Unread Count (yes, it works with versions >= 31) and run this instead:

awk -F: '{ sum += $1; } END { print sum; }' ~/.thunderbird/*/unread-counts