Improve 'URL' parsing in Avatar model (fixes #2199)

This commit is contained in:
Ryan Lue 2018-08-28 14:51:01 +02:00
parent f0690f8754
commit f046c80c79
3 changed files with 39 additions and 4 deletions

View file

@ -123,7 +123,7 @@ add avatar by url
data[:full][:content] = content data[:full][:content] = content
data[:full][:mime_type] = mime_type data[:full][:mime_type] = mime_type
elsif data[:url].to_s.match?(/^http/) elsif data[:url].to_s.match?(%r{^https?://})
url = data[:url].to_s url = data[:url].to_s
# check if source ist already updated within last 2 minutes # check if source ist already updated within last 2 minutes
@ -168,7 +168,7 @@ add avatar by url
data[:full][:mime_type] = mime_type data[:full][:mime_type] = mime_type
# try zammad backend to find image based on email # try zammad backend to find image based on email
elsif data[:url].to_s.match?(/@/) elsif data[:url].to_s.match?(URI::MailTo::EMAIL_REGEXP)
url = data[:url].to_s url = data[:url].to_s
# check if source ist already updated within last 3 minutes # check if source ist already updated within last 3 minutes
@ -179,9 +179,7 @@ add avatar by url
# fetch image # fetch image
image = Service::Image.user(url) image = Service::Image.user(url)
return if !image return if !image
data[:resize] ||= {}
data[:resize] = image data[:resize] = image
data[:full] ||= {}
data[:full] = image data[:full] = image
end end
end end

View file

@ -0,0 +1,16 @@
Return-Path: <http.abc@example.com>
Delivered-To: xxx
Received: from xxx
for <xxx>; Tue, 21 Aug 2018 09:49:58 +0000
To: xxx
From: "http.abc" <http.abc@example.com>
Subject: test
Message-ID: <xxx>
Date: Tue, 21 Aug 2018 11:49:57 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:xxx) Gecko/xxx
Thunderbird/xxx
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: clamav-milter 0.100.1
X-Virus-Status: Clean

View file

@ -3094,6 +3094,27 @@ Content-Type: text/html; charset=us-ascii; format=flowed
], ],
}, },
}, },
{ # See https://github.com/zammad/zammad/issues/2199
data: File.read(Rails.root.join('test', 'data', 'mail', 'mail070.box')),
success: true,
result: {
1 => {
from: '"http.abc" <http.abc@example.com>',
sender: 'Customer',
type: 'email',
},
},
verify: {
users: [
{
firstname: 'http.abc',
lastname: '',
fullname: 'http.abc',
email: 'http.abc@example.com',
},
],
},
},
] ]
assert_process(files) assert_process(files)
end end