]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Linkify.pm
www_stream: fix search for new.html endpoint
[public-inbox.git] / lib / PublicInbox / Linkify.pm
index 8f634f482828f64896ee7795e60f0267ee21ee02..25f0b48a34d9b2329b97d857797476f474e7632a 100644 (file)
@@ -15,9 +15,9 @@ use warnings;
 use Digest::SHA qw/sha1_hex/;
 
 my $SALT = rand;
-my $LINK_RE = qr!\b((?:ftp|https?|nntp)://
+my $LINK_RE = qr!\b((?:ftps?|https?|nntps?|gopher)://
                 [\@:\w\.-]+/
-                ?[\@\w\+\&\?\.\%\;/#=-]*)!x;
+                ?[,:~\$\@\w\+\&\?\.\%\;/#=-]*)!x;
 
 sub new { bless {}, shift }
 
@@ -25,6 +25,16 @@ sub linkify_1 {
        my ($self, $s) = @_;
        $s =~ s!$LINK_RE!
                my $url = $1;
+               my $end = '';
+
+               # it's fairly common to end URLs in messages with
+               # '.', ',' or ';' to denote the end of a statement;
+               # assume the intent was to end the statement/sentence
+               # in English
+               if ($url =~ s/([\.,;])\z//) {
+                       $end = $1;
+               }
+
                # salt this, as this could be exploited to show
                # links in the HTML which don't show up in the raw mail.
                my $key = sha1_hex($url . $SALT);
@@ -32,7 +42,7 @@ sub linkify_1 {
                # only escape ampersands, others do not match LINK_RE
                $url =~ s/&/&/g;
                $self->{$key} = $url;
-               'PI-LINK-'. $key;
+               'PI-LINK-'. $key . $end;
        !ge;
        $s;
 }