]> Sergey Matveev's repositories - public-inbox.git/commitdiff
view: generate links for common protocols in browsers
authorEric Wong <e@80x24.org>
Mon, 9 Feb 2015 22:33:50 +0000 (22:33 +0000)
committerEric Wong <e@80x24.org>
Mon, 9 Feb 2015 22:34:46 +0000 (22:34 +0000)
SpamAssassin queries URI blacklists, so it's probably OK
to enable this without being used as a linkfarm.

lib/PublicInbox/View.pm

index b09c3ba1404df6542eeb5334365af15221ac7d6e..3bb385376ba9d481bbc877fe340ab45b0a433055 100644 (file)
@@ -218,10 +218,17 @@ sub add_filename_line {
        "$pad " . ascii_html($fn) . " $pad\n";
 }
 
+my $LINK_RE = qr!\b((?:ftp|https?|nntp)://[@\w\+\&\?\.\%\;/#=-]+)!;
+
+sub linkify {
+       $_[0] =~ s!$LINK_RE!<a\nhref="$1"\n>$1</a>!g;
+}
+
 sub add_text_body_short {
        my ($enc, $part, $part_nr, $full_pfx) = @_;
        my $n = 0;
        my $s = ascii_html($enc->decode($part->body));
+       linkify($s);
        $s =~ s!^((?:(?:&gt;[^\n]*)\n)+)!
                my $cur = $1;
                my @lines = split(/\n/, $cur);
@@ -255,6 +262,7 @@ sub add_text_body_full {
        my ($enc, $part, $part_nr) = @_;
        my $n = 0;
        my $s = ascii_html($enc->decode($part->body));
+       linkify($s);
        $s =~ s!^((?:(?:&gt;[^\n]*)\n)+)!
                my $cur = $1;
                my @lines = split(/\n/, $cur);