Catching up on useperl journals

ziggy on 2003-02-19T04:56:10

Every so often, I leave the net for a few days. A lot of email piles up, most of which is from mailing lists, and gets promptly deleted when I return.

I have useperl journal notifications mailed to me, so there's often a few dozen journal postings to read when I come back online. My procmail set up stores these in a separate mailbox at my ISP. When I have time, I can get all of the URLs for journal postings I've missed and catch up on them all at once using this script, view-useperl. It loads a single journal entry at a time in a new browser window/tab.

#!/usr/bin/perl

use strict;

my @urls;

if (-f "useperl") {
        open (my $fh, "useperl");
        @urls = <$fh>;
        chomp(@urls);
        close($fh);
} else {
        `scp $ENV{useperlmailbox} useperl`;
        local $/ = undef;
        open(my $fh, 'useperl');
        @urls = map {m/(http:[\S]+)\s/s; $1} 
                      split("\n\nFrom ", <$fh>);
        close($fh);
}

do {
        my $url = shift(@urls);
        print STDERR $url;
        system "open \"$url\"";
} while (<> and @urls);


if (@urls) {
        open(my $fh, ">useperl");
        print $fh join("\n", @urls);
} else {
        unlink "useperl";
}
This is my current version which uses open to open a new URL. I've had different versions of this script over the last few months, including one that uses netscape -remote. I used to use Mail::Box to load all of the messages from the mailbox and find the first URL in the message body. Realistically, it's much easier to split out the messages one by one and find the first URL in each message. For these messages, there will be no URLs in the header, so the first URL found will be the URL in the message body. It's not a perfect solution, but it's a quick hack, it works, and it doesn't break when I forget to install Mail::Box. :-)

With a script like this, it's also easier to ignore useperl journals while I'm focusing on a project, and catch up later in the week. (Something I should do more often...)