Exporting Mail.app XML Feeds to Google Reader
RSS feeds are awesome for keeping up-to-date on the latest news and posts from your favourite sites. Up until now I’ve been using Mail.app as my primary RSS reader—and I really like it—but with an iPad and an iPhone always nearby, I’ve been meaning to set up Reeder instead.
Reeder uses Google Reader as a backend but there wasn’t an easy way to export my Mail.app RSS feeds into Google Reader—until I wrote the little script below to do it for me.
This PHP script reads the Mail.app settings and generates a MailAppToGoogleReader.opml file suitable for importing directly into Google Reader’s settings pane. All you have to do is copy the script to a file such as MailToGoogleReader.php and run the Terminal command:
$ php -e MailToGoogleReader.php
Now I can sit back and relax with Reeder on the iPad.
<?php
$opml = '<?xml version="1.0" encoding="ISO-8859-1"?>
<opml version="1.0">
<head>
<dateCreated>'.date('d-M-Y').'</dateCreated>
</head>
<body>
';
foreach (glob("/Users/jsambells/Library/Mail/RSS/*/Info.plist") as $plist) {
$xml = new SimpleXmlElement(file_get_contents($plist));
$results = $xml->xpath('//plist/dict[1]/key[.="RSSFeedURLString"]/following-sibling::*[1]/text()');
$url = (string)$results[0][0];
$opml .= '<outline type="rss" xmlUrl="' . $url . '"/>' . "\n";
}
$opml .= '
</body>
</head>
';
file_put_contents( "MailAppToGoogleReader.opml", $opml );
echo "done!";
`open .`;
UPDATED:
Mail.app in Mountain Lion no longer supports RSS feeds so use this to grab all your feeds before you upgrade. I’ve also copied the above to a Gist so you can improve it as necessary: