From c68cbe700ba50cc85be8fcd6c8ec5f9cbe2caee3 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 29 Oct 2015 16:01:50 -0400 Subject: [PATCH] FIX: Better link extraction than `URL.regexp` --- lib/email_cook.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/email_cook.rb b/lib/email_cook.rb index d30f4b9f665..494c91fb06d 100644 --- a/lib/email_cook.rb +++ b/lib/email_cook.rb @@ -1,9 +1,11 @@ # A very simple formatter for imported emails -require 'uri' - class EmailCook + def self.url_regexp + /[^\>]*((?:https?:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.])(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\([^\s()<>]+\)|[^`!()\[\]{};:'".,<>?«»\s]))/ + end + def initialize(raw) @raw = raw end @@ -23,6 +25,11 @@ class EmailCook quote_buffer = "" in_quote = false else + + l.scan(regexp).each do |m| + url = m[0] + l.gsub!(url, "#{url}") + end result << l << "
" end end @@ -32,11 +39,6 @@ class EmailCook end result.gsub!(/(
){3,10}/, '

') - - URI.extract(result).each do |m| - result.gsub!(m, "#{m}") - end - result end