55 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
#!/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
 | 
						|
 | 
						|
. $HOME/.private/config/email.conf
 | 
						|
. $CWD/../panel-config
 | 
						|
 | 
						|
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"
 | 
						|
        ERROR=!
 | 
						|
        echo 0
 | 
						|
    fi
 | 
						|
}
 | 
						|
 | 
						|
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}")
 | 
						|
 | 
						|
num=$(( $a + $b + $c ))
 | 
						|
icon="${ICON_MAIL}"
 | 
						|
color="${COLOR_FG}"
 | 
						|
case $num in
 | 
						|
    [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
 | 
						|
        ;;
 | 
						|
    0)  color="${COLOR_DIM}"
 | 
						|
        ;;
 | 
						|
esac
 | 
						|
 | 
						|
[[ $ERROR ]] && color=${COLOR_1}
 | 
						|
 | 
						|
echo "M%{F$color}$icon%{F-}"
 | 
						|
 | 
						|
# vim:set ft=sh:
 |