#!/usr/bin/perl # read emails I sent myself containing just a link # and make a HTML-redirect based bookmark out of them # # SPEC # read given files as internet messages # use subject as title and filename, escape as needed # use one URL in body as href (if there a two they are both the same) # and output one HTML file for each bookmark use strict; use warnings; use Encode; use Path::Tiny; use Email::Simple; use HTML::Entities; use URI::Find; use version; our $VERSION = qv('0.0.1'); foreach my $in_filepath (@ARGV) { my $in_file = Path::Tiny->new($in_filepath)->slurp; my $message = Email::Simple->new($in_file); my $subject = decode( 'MIME-Header', $message->header('Subject') ); my $title = HTML::Entities::encode($subject); my $out_filepart = $subject =~ s/[%\/\?<>\\:\*\|":]/_/gr; my @uris; # TODO URL::Search might be nicer than URI::Find for some cases # TODO $finder = URI::Find->new(sub { push @uris, $_[0] }); my $finder = URI::Find->new( sub { my $uri = shift; push @uris, $uri; }, ); $finder->find( \$message->body ); path("$out_filepart.URL.HTML") ->spew( "