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.
 
 
 
 

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