Displaying a Gmail ATOM Feed In Google Reader

So, not too long back, I thought I’d solve the “bacn” issue by having my notification emails automatically labelled “bacn” in Gmail, and then automatically archived. Trouble is, I’d then need to remember to check that label from time to time, so that I wouldn’t miss something I might actually want to know (ie, a Basecamp project has a new note, etc).

The obvious solution seemed to be an RSS feed; GMail does automatically supply feeds of all your mail, or of just one label; perfect!

It turns out, not so perfect. Because your email is, for obvious reasons, secure, getting at the feed requires authentication. Well, I’ve been using Google Reader (for so long that I really don’t want to bother switching), and Google Reader does not support authentication for feeds.

That’s right: Google’s RSS reader can’t read Gmail’s own feeds.

So, I finally got sick of reading my bacn label from time to time, and set up Magpie RSS in a directory on another server.

Now, Magpie reads RSS or ATOM feeds (Gmail is ATOM, I believe), but it returns an Object. So to have Google Reader read the feed, I basically just had to parse it back into a feed again: the script I used is below:

<?php

require_once('rss_fetch.inc');

$url = 'https://username:password@mail.google.com/mail/feed/atom/bacn/';
$rss = fetch_rss( $url );

$count = 0; // init counter for header elements

foreach ($rss->channel as $element) {
        $el[$count] = $element;
        $count++; //increment counter
}

echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<feed xmlns=\"http://www.w3.org/2005/Atom\">\n";

echo "<title>$el[0]</title>\n";
echo "<tagline>$el[1]</tagline>\n";
echo "<fullcount>$el[2]</fullcount>\n";
echo "<link href='$el[3]' />\n";
echo "<modified>$el[4]</modified>\n";
echo "<description>$el[5]</description>\n";

foreach ($rss->items as $item) {
        echo "<entry>\n";
        $title = $item['title'];
        $link = $item['link'];
	$summary = $item['summary'];
        $modified = $item['modified'];
        $issued = $item['issued'];
        $id = $item['id'];
        $author_name = $item['author_name'];
        $author_email = $item['author_email'];
        $description = $item['description'];
        echo "<title>$title</title>\n";
        echo "<summary>$summary</summary>\n";
        echo "<link href=\"$link\" />\n";
        echo "<modified>$modified</modified>\n";
        echo "<issued>$issued</issued>\n";
        echo "<id>$id</id>\n";
        echo "<author_name>$author_name</author_name>\n";
        echo "<author_email>$author_email</author_email>\n";
        echo "<description>$description</description>\n";
        echo "</entry>\n";
}
echo "</feed>\n";
?>

Now, unless Google changes the format of their feeds, you ought to be able to use the above script as is; this assumes that you replace “username:password” with your own. You should change “bacn” to whatever label you have used.

Now, whether it’s really that much easier to check the feed in Google reader or the check the label in Gmail is debatable; but I routinely look through my feeds, so to me, it seems easier. If you like it, use it.

7 Responses to “Displaying a Gmail ATOM Feed In Google Reader”


  1. 1 Gus

    Type your comment here.So say I wanted to write the output to teh screen, or a file, for use with Geektool, how would I do that with the above?

  2. 2 Gus

    Type your comment here.So say I wanted to write the output to teh screen, or a file, for use with Geektool, how would I do that with the above?

  3. 3 philcrissman

    If you mean a downloadable file, you'd have to look up the PHP docs on file IO, I don't think it should be too hard. If you just need a feed, you don't need to do anything different; say the above file was your-url.com/bacn.php, you would just use that address, and an atom feed should be returned.

    Even better might be SimplePie (http://simplepie.org/), which was not around when I wrote this and looks very easy to use.

  4. 4 Travis Spencer

    I too can't believe that Google Reader can't read other Google-created secure feeds. I think it is fine that reader doesn't support authenticating to feeds, in fact, I think that is desirable. However, reader secure feeds from the same company ought to be supported IMO.

    I also don't think it is a good solution to create this sort of proxy unless the info in the feed is already public. If that's the case though, a more secure approach might be to expose the data as an RSS feed at the source. In your case, perhaps you could get the owners of the bacn property (whatever that is) to expose the data in RSS directly. Long shot in many cases, I know.

    Just my $0.02.

  5. 5 philcrissman

    Well, even after creating the RSS feed mentioned above, I eventually found it just as easy (almost equivalent, really) to simply look in the label in gmail.

    It still seems that it would be nice if you could pipe gmail feeds, or any feed requiring authentication, into your google reader, just out of principle.

  6. 6 KitzKikz

    Even easier –>
    <?php readfile(”https://username:password@mail.google.com/mail/feed/atom/bacn/”); ?>

    No need for Magpie or Simplepie or any other php parsing & reformatting. This simply reads the feed and spits it back out. Then let Google Reader do it's job.

  7. 7 philcrissman

    Nice. Simper the better.

Comments are currently closed.



Fork me on GitHub