unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH] view: generate links for common protocols in browsers
@ 2015-02-09 22:33 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-02-09 22:33 UTC (permalink / raw)
  To: meta; +Cc: Eric Wong

SpamAssassin queries URI blacklists, so it's probably OK
to enable this without being used as a linkfarm.
---
 lib/PublicInbox/View.pm | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index b09c3ba..3bb3853 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -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);
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-02-09 22:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-09 22:33 [PATCH] view: generate links for common protocols in browsers Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).