mailsync (746B)
1 #!/bin/sh 2 # Sync my email using mbsync, reindex via notmuch, print the amount of new messages. 3 die() { printf '%s\n' "$1" >&2 && exit 1; } 4 5 rbw unlock || die 'Vault locked' 6 mbsync -c /Users/alex/.config/mbsync/mbsyncrc -Va 7 notmuch-hook 8 notification_str="" 9 for i in ~/.local/share/mail/*/[Ii][Nn][Bb][Oo][Xx]/new; do 10 mailbox_name="$(printf "%s" "$i" | sed 's:^.*mail/::; s:/[Ii][Nn][Bb][Oo][Xx]/new.*$::')" 11 num_new_messages="$(find "$i"/* -type f 2>/dev/null | wc -l)" 12 [ "$num_new_messages" -gt 0 ] \ 13 && notification_str="${notification_str} 14 $(printf "%s: %d" "$mailbox_name" "$num_new_messages")" 15 16 done 17 18 { [ -n "$notification_str" ] && notify "Mail synced" "$notification_str" mail; } \ 19 || notify "Mail synced" "No new messages" mail