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.
 
 
 
 

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