dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

mailsync (713B)


      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 mbsync -c /Users/alex/.config/mbsync/mbsyncrc -Va
      6 notmuch-hook
      7 notification_str=""
      8 for i in ~/.local/share/mail/*/[Ii][Nn][Bb][Oo][Xx]/new; do
      9   mailbox_name="$(printf "%s" "$i" | sed 's:^.*mail/::; s:/[Ii][Nn][Bb][Oo][Xx]/new.*$::')"
     10   num_new_messages="$(find "$i"/* -type f 2>/dev/null | wc -l)"
     11   [ "$num_new_messages" -gt 0 ] \
     12     && notification_str="${notification_str}
     13 $(printf "%s: %d" "$mailbox_name" "$num_new_messages")"
     14 
     15 done
     16 
     17 { [ -n "$notification_str" ] && notify "Mail synced" "$notification_str" mail; } \
     18   || notify "Mail synced" "No new messages" mail