You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

37 lines
1.5 KiB

  1. #!/usr/bin/env sh
  2. # Sync mail and give notification if there is new mail.
  3. # Checks for internet connection and set notification script.
  4. ping -q -c 1 1.1.1.1 > /dev/null || exit
  5. pgrep -x mbsync >/dev/null && echo "mbsync already running." && exit
  6. command -v notify-send >/dev/null || echo "Note that \`libnotify\` or \`libnotify-send\` should be installed for pop-up mail notifications with this script."
  7. export DISPLAY=:0.0
  8. # Settings are different for MacOS (Darwin) systems.
  9. if [ "$(uname)" = "Darwin" ]; then
  10. notify() { osascript -e "display notification \"$2 in $1\" with title \"You've got Mail\" subtitle \"Account: $account\"" && sleep 2 ;}
  11. else
  12. notify() { notify-send "mutt-wizard" "📬 $2 new mail(s) in \`$1\` account." ;}
  13. fi
  14. echo " 🔃" > /tmp/imapsyncicon
  15. pkill -RTMIN+12 i3blocks
  16. # Run mbsync. You can feed this script different settings.
  17. mbsync -a "$@"
  18. rm -f /tmp/imapsyncicon
  19. pkill -RTMIN+12 i3blocks
  20. # Check all accounts/mailboxes for new mail. Notify if there is new content.
  21. for account in "$HOME/.local/share/mail/"*
  22. do
  23. acc="$(echo "$account" | sed "s/.*\///")"
  24. newcount=$(find "$HOME/.local/share/mail/$acc/INBOX/new/" "$HOME/.local/share/mail/$acc/Inbox/new/" "$HOME/.local/share/mail/$acc/inbox/new/" -type f -newer "$HOME/.config/mutt/.mailsynclastrun" 2> /dev/null | wc -l)
  25. [ "$newcount" -gt "0" ] && notify "$acc" "$newcount" &
  26. done
  27. notmuch new 2>/dev/null
  28. #Create a touch file that indicates the time of the last run of mailsync
  29. touch "$HOME/.config/mutt/.mailsynclastrun"