BASH script for viewing unread GMail
By michael | February 22nd, 2011 | Published in SysAdmin
I spend most of my day in BASH lately. When my phone buzzes I know I have new mail but I don’t want to go check it. Placing the following function in your .bash_profile allows you to quickly view unread email and summaries from terminal by typing ‘gmail’ and pressing enter. Thought I would share:
function gmail() {
curl -u yourgamilusername --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | perl -pe 's/^<title>(.*)<\/title><summary>(.*)<\/summary>.*?<name>(.*?)<\/name>.*$/\n$3\n\t$1\n\t$2/'
}