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.
 
 
 
 

29 lines
898 B

  1. #!/bin/sh
  2. # This script will run offlineimap and check
  3. # for new email if there is an internet connection.
  4. #
  5. # If it detects new mail, it uses mpv to play a
  6. # notification sound: notify.opus
  7. #
  8. # I have this run as a cronjob every 5 minutes.
  9. # Check for internet connection. Exit script if none. (timeout in mac is `-t`)
  10. if [ "$(uname)" == "Darwin" ]
  11. then
  12. ping -q -t 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` >/dev/null || exit
  13. else
  14. ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` >/dev/null || exit
  15. fi
  16. # Get current number of new mail, then begin sync.
  17. ori=$(find ~/.mail -wholename '*/new/*' | grep -vi "spam\|trash\|junk" | wc -l)
  18. offlineimap -o "$@"
  19. # Recount new mail.
  20. new=$(find ~/.mail -wholename '*/new/*' | grep -vi "spam\|trash\|junk" | wc -l)
  21. # If new mail has grown, play a notification.
  22. if [ "$new" -gt "$ori" ]; then
  23. mpv --quiet ~/.config/mutt/etc/notify.opus
  24. fi