Fixed issue#402 - Missing quotation marks on sender address.

This commit is contained in:
Martin Edenhofer 2016-11-25 13:43:28 +01:00
parent f43261d292
commit f2a2b9efe9
4 changed files with 39 additions and 8 deletions

View file

@ -126,6 +126,21 @@ module Channel::EmailBuild
mail
end
=begin
quoted_in_one_line = Channel::EmailBuild.recipient_line('Somebody @ "Company"', 'some.body@example.com')
returnes
'"Somebody @ \"Company\"" <some.body@example.com>'
=end
def self.recipient_line(realname, email)
return "#{realname} <#{email}>" if realname =~ /^[A-z]+$/i
"\"#{realname.gsub('"', '\"')}\" <#{email}>"
end
=begin
Check if string is a complete html document. If not, add head and css styles.

View file

@ -46,13 +46,13 @@ class Observer::Ticket::Article::FillupFromEmail < ActiveRecord::Observer
if !email_address
raise "No email address found for group '#{ticket.group.name}'"
end
system_sender = "#{email_address.realname} <#{email_address.email}>"
if record.created_by_id != 1 && Setting.get('ticket_define_email_from') == 'AgentNameSystemAddressName'
seperator = Setting.get('ticket_define_email_from_seperator')
sender = User.find(record.created_by_id)
record.from = "#{sender.firstname} #{sender.lastname} #{seperator} #{system_sender}"
realname = "#{sender.firstname} #{sender.lastname} #{seperator} #{email_address.realname}"
record.from = Channel::EmailBuild.recipient_line(realname, email_address.email)
else
record.from = system_sender
record.from = Channel::EmailBuild.recipient_line(email_address.realname, email_address.email)
end
end
end

View file

@ -318,7 +318,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
result = JSON.parse(@response.body)
assert_equal(Hash, result.class)
assert_equal(ticket.id, result['ticket_id'])
assert_equal('Tickets Agent via Zammad <zammad@localhost>', result['from'])
assert_equal('"Tickets Agent via Zammad" <zammad@localhost>', result['from'])
assert_equal('some subject', result['subject'])
assert_equal('some body', result['body'])
assert_equal('text/plain', result['content_type'])
@ -335,7 +335,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
result = JSON.parse(@response.body)
assert_equal(Hash, result.class)
assert_equal(ticket.id, result['ticket_id'])
assert_equal('Tickets Agent via Zammad <zammad@localhost>', result['from'])
assert_equal('"Tickets Agent via Zammad" <zammad@localhost>', result['from'])
assert_equal('new subject', result['subject'])
assert_equal('some body', result['body'])
assert_equal('text/plain', result['content_type'])
@ -444,7 +444,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
result = JSON.parse(@response.body)
assert_equal(Hash, result.class)
assert_equal(ticket.id, result['ticket_id'])
assert_equal('Tickets Admin via Zammad <zammad@localhost>', result['from'])
assert_equal('"Tickets Admin via Zammad" <zammad@localhost>', result['from'])
assert_equal('some subject', result['subject'])
assert_equal('some body', result['body'])
assert_equal('text/plain', result['content_type'])

View file

@ -211,4 +211,20 @@ text
assert_equal(html_should, html_with_fixes)
end
test 'from checks' do
quoted_in_one_line = Channel::EmailBuild.recipient_line('Somebody @ "Company"', 'some.body@example.com')
assert_equal('"Somebody @ \"Company\"" <some.body@example.com>', quoted_in_one_line)
quoted_in_one_line = Channel::EmailBuild.recipient_line('Somebody', 'some.body@example.com')
assert_equal('Somebody <some.body@example.com>', quoted_in_one_line)
quoted_in_one_line = Channel::EmailBuild.recipient_line('Somebody | Some Org', 'some.body@example.com')
assert_equal('"Somebody | Some Org" <some.body@example.com>', quoted_in_one_line)
quoted_in_one_line = Channel::EmailBuild.recipient_line('Test Master Agent via Support', 'some.body@example.com')
assert_equal('"Test Master Agent via Support" <some.body@example.com>', quoted_in_one_line)
end
end