1
0
مراية لـ https://github.com/postalserver/postal.git تم المزامنة 2026-01-17 13:39:46 +00:00

fixes for link conversion (#296)

هذا الالتزام موجود في:
Will Power
2021-07-27 23:08:53 +01:00
ملتزم من قبل GitHub
الأصل 351da9e623
التزام 670ea65712

عرض الملف

@@ -1,7 +1,7 @@
module Postal module Postal
class MessageParser class MessageParser
URL_REGEX = /(?<url>(?<protocol>https?)\:\/\/(?<domain>[A-Za-z0-9\-\.]+)(?<path>\/[A-Za-z0-9\/\.\/\+\?\&\-\_\%\=\~\:\;]+)?+)/ URL_REGEX = /(?<url>(?<protocol>https?)\:\/\/(?<domain>[A-Za-z0-9\-\.\:]+)(?<path>\/[A-Za-z0-9\.\/\+\?\&\-\_\%\=\~\:\;\(\)\[\]#]*)?+)/
def initialize(message) def initialize(message)
@message = message @message = message
@@ -93,10 +93,15 @@ module Postal
def insert_links(part, type = nil) def insert_links(part, type = nil)
if type == :text if type == :text
part.gsub!(/#{URL_REGEX}/) do part.gsub!(/(#{URL_REGEX})(?=\s|$)/) do
if track_domain?($~[:domain]) if track_domain?($~[:domain])
@tracked_links += 1 @tracked_links += 1
token = @message.create_link($~[:url]) url = $~[:url]
while url =~ /[^\w]$/ do
theend = url.size - 2
url = url[0..theend]
end
token = @message.create_link(url)
"#{domain}/#{@message.server.token}/#{token}" "#{domain}/#{@message.server.token}/#{token}"
else else
$& $&