#!/usr/bin/perl use strict; use warnings; =pod =head1 NAME rss_import.pl =head1 DESCRIPTION This script takes an OPML file (much like the one exported by Google Reader) and creates an RSS item in Mail.app for each item. There is really no magic involved. Each RSS feed in Mail.app is stored and configured as a .rssmbox directory with a plist describing the feed. aka, the feed for socklabs.com looks like ~/Library/Mail/RSS/Socklabs Blog.rssmbox ... info.plist ... Messages ... Messages/xxxx.emlx Messages/xxxx.elmx ... This script just creates the directorys and populates a plist for each feed in an opml file. =head1 USAGE mv rss_import.pl.txt rss_import.pl chmod 744 rss_import.pl ./rss_import.pl ~/tmp/some.file.opml =head1 COPYRIGHT & LICENSE Copyright 2007 Nick Gerakines, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut use XML::OPML::LibXML; use IO::File; use IO::All; my @args = @ARGV; my $opml_file = shift @args; if (! $opml_file || ! -f $opml_file) { print "rss_import.pl <.../google-reader-subscriptions.xml>\n"; exit; } my $user = `whoami`; chomp $user; print "Importing subscriptions from $opml_file to $user Mail RSS.\n"; my $parser = XML::OPML::LibXML->new(); my $doc = $parser->parse_file($opml_file); my @outline = $doc->outline; for my $outline (@outline) { my $attrs = $outline->attrs; $outline->title; $outline->text; if ($outline->is_container) { my @children = $outline->children; for (@children) { $_->{path} ||= []; unshift @{ $_->{path} }, $outline->title; } push @outline, @children; # do some recursive stuff, see also walkdown() } else { my ($name, $xml) = ($outline->title, $outline->xml_url); $name = io->catfile(@{ $outline->{path} }, $name)->pathname; print "$name - $xml\n"; new_feed($name, $xml); } } sub new_feed { my ($name, $xml) = @_; my $data = < DisplayInThreadedMode no MailboxHasBeenImported Yes RSSFeedURLString $xml SearchSortDescending YES SearchSortOrder rank SortOrder received-date SortedDescending NO EOF my $loc = "/Users/$user/Library/Mail/RSS/" . $name . '.rssmbox'; if (io($loc)->mkpath) { my $fh = new IO::File "> $loc/Info.plist"; if (defined $fh) { print $fh $data; $fh->close; } else { print "Could not create feed for '$name'.\n"; } } else { print "Could not create feed for '$name'.\n"; } }