I use wget for the same. I usually call it from gnu screen, to update the status line with the no. of unread mails
unread="$(wget --secure-protocol=TLSv1 --timeout=3 -t 1 -q -O - \
https://${gmail_login}:${gmail_password}@mail.google.com/mail/feed/atom |
sed -n "s/<fullcount>\(.*\)<\/fullcount>/\1/p")"
unread=${unread:-0}
echo $unread
And also worth checking out
http://groups.google.com/group/emacs-g-client?pli=1 if you are into emacs side of the things.