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