Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

yetiboy

macrumors member
Original poster
Mar 23, 2011
35
0
Little script I put together to track the number of new messages in my inbox. Could probably be fairly easily added to to actually output subjects and/or senders, but all I need it for is to tell me when I have new messages.

yeti

Code:
<?php

date_default_timezone_set('America/Toronto');
$username='YOUR_USERNAME';
$password='YOUR_PASSWORD';
$url='https://mail.google.com/mail/feed/atom';

$context = stream_context_create(array(
    'http' => array(
        'header'  => "Authorization: Basic " . base64_encode("$username:$password")
    )
));
$data = file_get_contents($url, false, $context);

file_put_contents('/path/to/your/file/gmail.xml',$data);

$xml=simplexml_load_file('/path/to/your/file/gmail.xml', 'SimpleXMLElement', LIBXML_NOCDATA);

$new_message=$xml->fullcount;

if ($new_message=='0'){
	echo 'No messages';
	}
elseif ($new_message=='1'){
	echo '1 new message';
	}
else {
	echo "$new_message new messages";
	}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.