From f2a2b9efe97e3b65848472d39297c8737afeb080 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 25 Nov 2016 13:43:28 +0100 Subject: [PATCH] Fixed issue#402 - Missing quotation marks on sender address. --- app/models/channel/email_build.rb | 15 +++++++++++++++ .../observer/ticket/article/fillup_from_email.rb | 10 +++++----- test/controllers/tickets_controller_test.rb | 6 +++--- test/unit/email_build_test.rb | 16 ++++++++++++++++ 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/app/models/channel/email_build.rb b/app/models/channel/email_build.rb index 31eb5f60d..8302228e5 100644 --- a/app/models/channel/email_build.rb +++ b/app/models/channel/email_build.rb @@ -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\"" ' + +=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. diff --git a/app/models/observer/ticket/article/fillup_from_email.rb b/app/models/observer/ticket/article/fillup_from_email.rb index 1d89764f5..2770e9206 100644 --- a/app/models/observer/ticket/article/fillup_from_email.rb +++ b/app/models/observer/ticket/article/fillup_from_email.rb @@ -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}" + seperator = Setting.get('ticket_define_email_from_seperator') + sender = User.find(record.created_by_id) + 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 diff --git a/test/controllers/tickets_controller_test.rb b/test/controllers/tickets_controller_test.rb index 21b8ccee5..ef9bc478f 100644 --- a/test/controllers/tickets_controller_test.rb +++ b/test/controllers/tickets_controller_test.rb @@ -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 ', result['from']) + assert_equal('"Tickets Agent via Zammad" ', 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 ', result['from']) + assert_equal('"Tickets Agent via Zammad" ', 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 ', result['from']) + assert_equal('"Tickets Admin via Zammad" ', result['from']) assert_equal('some subject', result['subject']) assert_equal('some body', result['body']) assert_equal('text/plain', result['content_type']) diff --git a/test/unit/email_build_test.rb b/test/unit/email_build_test.rb index 326408785..5566ac2b9 100644 --- a/test/unit/email_build_test.rb +++ b/test/unit/email_build_test.rb @@ -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\"" ', quoted_in_one_line) + + quoted_in_one_line = Channel::EmailBuild.recipient_line('Somebody', 'some.body@example.com') + assert_equal('Somebody ', quoted_in_one_line) + + quoted_in_one_line = Channel::EmailBuild.recipient_line('Somebody | Some Org', 'some.body@example.com') + assert_equal('"Somebody | Some Org" ', 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" ', quoted_in_one_line) + + end + end