mailsync (824B)
1 #!/bin/sh 2 3 die() { printf '%s\n' "$@" >&2 ;} 4 notify() { notify-send "mu-wizard" "$2 new mail(s) in '$1' account." ;} 5 cac_dir=${XDG_CACHE_HOME:-$HOME/.cache} 6 7 pgrep -x mbsync >/dev/null && die "mbsync is already running." 8 9 [ "$1" ] || { 10 while read -r chan name; do 11 case "$chan" in Channel) ;; *) continue; esac 12 accounts="$accounts '$name'" 13 done < "$HOME/.mbsyncrc" 14 eval set -- "$accounts" 15 } 16 17 for acc; do mbsync "${acc##*/}" & done; wait 18 for acc; do 19 newcount=$(find "${MU_MAILDIR:-$HOME/.local/share/mail}/$acc/"*/new \ 20 -type f -newer "$cac_dir/.mailsynclastrun" | wc -l) 21 [ "$newcount" -gt 0 ] && notify "$acc" "$newcount" 22 done 23 24 # Run index update if emacs is available. 25 emacsclient -e "(mu4e-update-index)" >/dev/null 2>&1 || 26 mu index 27 28 touch "$cac_dir/.mailsynclastrun"