helm/os/arch/.config/panel/lemons/mail

57 lines
1.2 KiB
Plaintext
Raw Normal View History

2016-11-02 16:58:47 -07:00
#!/usr/bin/env bash
set -e
CWD=$(dirname $0)
if [[ ! -f ~/.private/config/email.conf ]]; then
>&2 echo "Couldn't load account settings"
exit 1
fi
. ~/.private/config/email.conf
. $CWD/../panel-config
2016-11-02 16:58:47 -07:00
2016-11-06 16:40:02 -08:00
ICON_MAIL=""
get_mail() {
local feed=$(curl -u "$1:$2" --silent https://mail.google.com/mail/feed/atom)
if [[ "${feed//\<fullcount\>/}" != "$feed" ]]; then
echo "$feed" | grep -o "<entry>" | wc -l
else
>&2 echo "mail.sh: error with $1"
2016-11-06 16:40:02 -08:00
ERROR=!
echo 0
fi
}
2016-11-02 16:58:47 -07:00
mailtmp=/tmp/mail-count
touch "$mailtmp"
a=$(get_mail "${MAIL1_USER}" "${MAIL1_PASS}")
b=$(get_mail "${MAIL2_USER}" "${MAIL2_PASS}")
c=$(get_mail "${MAIL3_USER}" "${MAIL3_PASS}")
2016-11-06 16:40:02 -08:00
num=$(( $a + $b + $c ))
icon="${ICON_MAIL}"
color="${COLOR_FG}"
case $num in
2016-11-06 16:40:02 -08:00
[1-9]*)
icon="$icon$num"
lastnum=$(cat "$mailtmp")
if [[ $num != $lastnum ]]; then
echo "$num" > "$mailtmp"
if (( $num > $lastnum )); then
notify-send "New messages" "You have $(( $num - $lastnum )) new messages"
aplay -N -q /usr/share/sounds/ding.wav
fi
fi
2016-11-06 16:40:02 -08:00
;;
0) color="${COLOR_DIM}"
;;
esac
[[ $ERROR ]] && color=${COLOR_1}
2016-11-06 16:40:02 -08:00
echo "M%{F$color}$icon%{F-}"
# vim:set ft=sh: