This repository has been archived on 2024-04-07. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/dotfiles/scripts/checkmail

55 lines
918 B
Plaintext
Raw Normal View History

2019-12-05 15:28:02 +01:00
#!/bin/sh
2019-12-02 19:57:45 +01:00
set -e
2020-04-17 06:54:35 +02:00
if test -z "$SWAYSOCK" && pidof gnome-shell &> /dev/null
then
2021-03-12 19:29:44 +01:00
exit 0
2021-03-02 06:01:31 +01:00
fi
2020-12-04 03:53:41 +01:00
2020-10-20 21:56:33 +02:00
test -z "$XDG_RUNTIME_DIR" &&
export XDG_RUNTIME_DIR=/run/user/$(id -u)
2021-03-02 06:01:31 +01:00
die() {
test "$?" = 0 ||
notify-send "Failed to sync mail" "try unlocking your gpg key"
}
trap die EXIT
2021-03-12 19:29:44 +01:00
getnew() {
pushd "$HOME/.local/share/mail/" >/dev/null
2020-12-04 03:53:41 +01:00
2021-03-02 06:01:31 +01:00
find */INBOX*/new -type f |
sed -E '/Duolingo|LBRY/d' |
2020-12-04 03:53:41 +01:00
wc -l
2021-03-12 19:29:44 +01:00
popd >/dev/null
2020-05-22 02:34:08 +02:00
}
OLD=$(getnew)
2021-04-22 17:56:56 +02:00
if test "$1" = "update" && ! pidof mbsync; then
if ! ping -c3 {{@@ mail.personal.mail @@}} &> /dev/null
then
exit 0
fi
2021-03-02 06:01:31 +01:00
mbsync -a ||
2021-04-22 17:56:56 +02:00
mbsync -a ||
mbsync -a
2021-03-02 06:01:31 +01:00
fi
2020-04-17 06:54:35 +02:00
2020-05-22 02:34:08 +02:00
NEW=$(getnew)
2021-03-12 19:29:44 +01:00
if test "$NEW" -gt "$OLD"; then
2020-10-20 21:56:33 +02:00
notify-send " New E-Mails!"
2021-03-02 06:01:31 +01:00
fi
2019-11-23 02:23:15 +01:00
2019-12-02 19:57:45 +01:00
echo $NEW | sed 's/^0$//'
2019-11-23 02:23:15 +01:00
2021-03-12 19:29:44 +01:00
caller=$(ps -o comm= $PPID)
if test "$caller" != "waybar"; then
pidof waybar >/dev/null &&
2021-03-02 06:01:31 +01:00
pkill -SIGRTMIN+4 waybar
fi
2020-12-04 03:53:41 +01:00
2019-12-01 17:36:00 +01:00
# vim:ft=sh