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.
 
 
 
 

44 line
1.5 KiB

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