Skip to content

Instantly share code, notes, and snippets.

@gauteh
Last active April 17, 2017 09:56
Show Gist options
  • Save gauteh/7942217 to your computer and use it in GitHub Desktop.
Save gauteh/7942217 to your computer and use it in GitHub Desktop.
#! /bin/bash
#
# do a quick check if there are new messages in a gmail account
#
# based on: http://cpbl.wordpress.com/2011/11/16/how-to-alpine-maildir-offlineimap/
#
# Gaute Hope / 2013-12-13 / [email protected]
#
# requires: curl
#
# usage: gmail_new_messages username password
if [ ! $# -eq 2 ]; then
echo "$0 takes two arguments: username and password"
exit 2
fi
mkdir -p $HOME/.cache/new_gmail
newfile="${HOME}/.cache/new_gmail/${1}_new_gmail"
oldfile="${HOME}/.cache/new_gmail/${1}_old_gmail"
curl -u $1:$2 --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if //; print "$2\n" if /(.*)/;' > $newfile
touch $newfile
touch $oldfile
cmp -s $oldfile $newfile > /dev/null
ret=$?
cp $newfile $oldfile
if [ $ret -eq 1 ]; then
echo "$1: new mail"
exit 1
else
echo "$1: no new mail"
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment