#!/bin/sh

total=""
while read label search; do
    read=$(notmuch count "(${search}) AND NOT tag:unread" </dev/null 2>/dev/null)
    unread=$(notmuch count "(${search}) AND tag:unread" </dev/null 2>/dev/null)
    output=""
    if [ "${read}" != "" -a "${read}" != 0 ]; then
	output="${output}${read}"
    fi
    if [ "${unread}" != "" -a "${unread}" != 0 ]; then
	output="${output}+${unread}"
    fi
    if [ "${output}" != "" ]; then
	space=" "
	if [ "${total}" = "" ]; then
	    space=""
	fi
	total="${total}${space}${label}:${output}"
    fi
done <<EOF
inbox tag:inbox
mine tag:inbox and tag:mine
rss tag:inbox AND tag:rss
notmuch tag:inbox AND tag:notmuch
flagged tag:flagged
EOF

if [ "${total}" != "" ]; then
    echo "${total}"
fi
