os/arch (lemonbar): individual email notifications

This commit is contained in:
Henrik Lissner 2017-01-03 18:17:53 -05:00
parent 0f329f78cc
commit 069044edfd

View file

@ -11,36 +11,78 @@ fi
. $CWD/../panel-config . $CWD/../panel-config
get_mail() { get_mail() {
local feed=$(curl -u "$1:$2" --silent https://mail.google.com/mail/feed/atom) local maildatatmp=/tmp/mail-data-"$1"
local mailtmp=/tmp/mail-count-"$1"
if true; then
# if curl -u "$1:$2" --silent https://mail.google.com/mail/feed/atom > "$maildatatmp"; then
[[ -f "$mailtmp" ]] || echo "0" >"$mailtmp"
local feed=$(<"$maildatatmp")
if [[ "${feed//\<fullcount\>/}" != "$feed" ]]; then if [[ "${feed//\<fullcount\>/}" != "$feed" ]]; then
echo "$feed" | grep -o "<entry>" | wc -l local lastnum=$(<"$mailtmp")
local total=$(echo "$feed" | grep -o "<entry>" | wc -l)
local new=0
echo "$total" > "$mailtmp"
if [[ $total > $lastnum ]]; then
new=$(( $total - $lastnum ))
NOTIFY=1
fi
parse_xml "$new" <<<"$feed"
echo $total
return
fi
>&2 echo "lemon/mail: malformed input ($1)"
else else
>&2 echo "mail.sh: error with $1" >&2 echo "lemon/mail: failed to connect ($1)"
fi
ERROR=! ERROR=!
echo 0 echo 0
fi
} }
mailtmp=/tmp/mail-count # Oh man. I really did this in bash. Don't try this at home.
touch "$mailtmp" parse_xml() {
[[ $1 == 0 ]] && return
echo 1 > /tmp/notify
local n="${1:-1}"
tr '<>' '\n' | sed -e '/^\(?xml \|feed \|\/\|link rel=\|$\)/d;s/^entry$/----/;s/^author$/====/' | \
{
while read line; do
[[ $line == "----" ]] && break
done
while [[ $n > 0 ]] && read line; do
case $line in
name) read name ;;
email) read email ;;
title) read title ;;
esac
if [[ $title && $name && $email ]]; then
let n--
notify-send --icon="mail-message-new" "$name\n&lt;${email/-/_}&gt;" "$title"
title=
name=
email=
fi
done
}
}
#
a=$(get_mail "${MAIL1_USER}" "${MAIL1_PASS}") a=$(get_mail "${MAIL1_USER}" "${MAIL1_PASS}")
b=$(get_mail "${MAIL2_USER}" "${MAIL2_PASS}") b=$(get_mail "${MAIL2_USER}" "${MAIL2_PASS}")
c=$(get_mail "${MAIL3_USER}" "${MAIL3_PASS}") c=$(get_mail "${MAIL3_USER}" "${MAIL3_PASS}")
total=$(( $a + $b + $c ))
num=$(( $a + $b + $c ))
icon="${ICON_MAIL}" icon="${ICON_MAIL}"
color="${COLOR_FG}" color="${COLOR_FG}"
case $num in case $total in
[1-9]*) [1-9]*)
icon="$icon $num" icon="$icon $total"
lastnum=$(cat "$mailtmp") if [[ -f /tmp/notify ]]; then
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 aplay -N -q /usr/share/sounds/ding.wav
fi rm -f /tmp/notify
fi fi
;; ;;
0) color="${COLOR_DIM}" 0) color="${COLOR_DIM}"