#!/bin/bash

if [ "$4" ] ; then
	label=/${4}
fi

if [ "$1" = "-c" ] ; then
	wget -q -O - https://mail.google.com/mail/feed/atom${label} \
	--http-user=${2}@gmail.com --http-password="${3}" --no-check-certificate | \
	grep fullcount | sed 's/<[^0-9]*>//g'
elif [ "$1" = "-l" ] ; then
	wget -q -O - https://mail.google.com/mail/feed/atom${label} \
	--http-user=${2}@gmail.com --http-password="${3}" --no-check-certificate | \
	grep title | grep -v 'Gmail - Label' | grep -v 'Gmail - Inbox for' | head -n 5 | sed -e 's/<[^>]*>//g' -e 's/\&[^;]*;//g'
fi
