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.

mailsync 1.5 KiB

6 vuotta sitten
5 vuotta sitten
5 vuotta sitten
6 vuotta sitten
6 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
12345678910111213141516171819202122232425262728293031323334353637383940
  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. if [ $# -eq 0 ]; then
  17. mbsync -a
  18. else
  19. mbsync "$@"
  20. fi
  21. rm -f /tmp/imapsyncicon_$USER
  22. pkill -RTMIN+12 i3blocks
  23. # Check all accounts/mailboxes for new mail. Notify if there is new content.
  24. for account in "$HOME/.local/share/mail/"*
  25. do
  26. acc="$(echo "$account" | sed "s/.*\///")"
  27. 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)
  28. [ "$newcount" -gt "0" ] && notify "$acc" "$newcount" &
  29. done
  30. notmuch new 2>/dev/null
  31. #Create a touch file that indicates the time of the last run of mailsync
  32. touch "$HOME/.config/mutt/.mailsynclastrun"