#!/usr/local/bin/perl -w #### # # vox2mail - backup your Vox blog to a local mail directory # ### use strict; use DateTime; use DateTime::Format::Mail; use DateTime::Format::ISO8601; use MIME::Lite; use XML::Atom::Feed; use Email::LocalDelivery; use HTML::FormatText::WithLinks; =head1 NAME vox2mail - backup your Vox blog to a local mail directory =head1 USAGE vox2mail Messages will be delivered to local mail. vox2mail deflatermouse vox will download to an mbox vox2mail deflatermouse vox/ will download to maildir. =head1 AUTHOR Simon Wistow =head1 COPYRIGHT Copyright, 2006 - Simon Wistow Destributed under the same terms as Perl itself. =cut my $user = shift || die "You must pass a username\n"; my $box = shift || die "You must pass in a mail box\n"; my $page = 1; print "Starting ...\n"; while ($page) { my $url = "http://${user}.vox.com/library/posts/page/$page/atom-full.xml"; my $feed = eval { XML::Atom::Feed->new($url) }; last if $@; print "Fetching page $page\n"; foreach my $entry ($feed->entries) { print "\t".$entry->title."\n"; my $mail = entry_to_mail($entry); Email::LocalDelivery->deliver($mail, $box); } $page++; } print "Done\n"; sub entry_to_mail { my $entry = shift; my $pf = DateTime::Format::Mail->new(); my $name = $entry->author->name; my $mail = "${user}\@vox.com"; # From my $from = "$name <$mail>"; # To my $to = $from; # Subject my $subject = $entry->title; # Date my $date = $pf->format_datetime( DateTime::Format::ISO8601->parse_datetime( $entry->updated ) ); # Body my $html = $entry->content->body; # Text Body my $f = HTML::FormatText::WithLinks->new( before_link => '', after_link => ' [%n]', footnote => '%n. %l' ); my $text = $f->parse($html); # Tags my @tags; foreach my $cat ($entry->category) { push @tags, $cat->get_attr('term'); } my $tags = join(", ", @tags); # URI my $uri; foreach my $link ($entry->link) { next unless $link->type eq 'text/html'; $uri = $link->href; last; } # TODO strip tag stuff off start? my $id = $entry->id.'@vox.com'; # TODO extract attachments? my $msg = MIME::Lite->new( From => $from, To => $to, Subject => $subject, Date => $date, Type => "multipart/mixed", 'X-Link' => $uri, 'X-Tags' => $tags, 'Message-ID' => $id, ); $msg->attach(Type => 'TEXT', Data => $text); $msg->attach(Type => 'text/html', Data => $html); return $msg->as_string; }