I sync my e-mail to my local laptop automatically with isync/mbsync, not because I want to handle mail locally, but because I’m paranoid and I like a local backup. Also, search functionality of e-mail clients has gotten substantially worse in recent years (what with Thunderbird having two search fields, where one is stupid and the other modifies the term you’re searching for without the possibility to search for an exact match), and I like having a backup e-mail search on the command line. Thus, I use mu to index this local e-mail backup. The plain “mu find” command is enough to find the subject and folder of an e-mail to allow me to find it in Thunderbird, but it’s annoying that reading the e-mail requires an extra search step.

The following snippet allows searching the mu index for terms, provides a somewhat formatted list of matches in fzf, and then shows the found e-mail in w3m. It requires mu, w3m and fzf to be installed.

mufiview() {
    mu find --format json2 "$@" |\
        jq '.[]|{"date-unix", subject, path, from}' |\
        jq '.date = (."date-unix" | (gmtime|strftime("%x, %X")))' |\
        jq '.from |= (map("\(.name) <\(.email)>")|join(", "))' |\
        jq --raw-output0 '"\(.subject)  \(.from)  \(.date)\t\(.path)"' |\
        fzf --read0 --delimiter '\t' --with-nth 1 --preview 'mu view {2}' --accept-nth 2 |\
        xargs mu view -o html |\
        w3m -T text/html
}

Isn’t jq a thing of beauty?