diff --git a/app/assets/javascripts/app/lib/app_post/utils.coffee b/app/assets/javascripts/app/lib/app_post/utils.coffee index 730d5e408..85756ceca 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.coffee @@ -952,18 +952,25 @@ class App.Utils article_created_by_email = article_created_by.email.toLowerCase() # check if article sender is local + senderIsLocal = false if !_.isEmpty(article.from) - senderIsLocal = false senders = emailAddresses.parseAddressList(article.from) if senders && senders[0] && senders[0].address senderIsLocal = isLocalAddress(senders[0].address) + # check if article recipient is local + recipientIsLocal = false + if !_.isEmpty(article.to) + recipients = emailAddresses.parseAddressList(article.to) + if recipients && recipients[0] && recipients[0].address + recipientIsLocal = isLocalAddress(recipients[0].address) + # sender is local if senderIsLocal articleNew.to = article.to - # sender is agent from is different (sender was system) - else if article.sender.name is 'Agent' && article_created_by_email && article.from && !article.from.match(article_created_by_email) + # sender is agent - sent via system + else if article.sender.name is 'Agent' && article_created_by_email && article.from && article.from.toString().toLowerCase().match(article_created_by_email) && !recipientIsLocal articleNew.to = article.to # sender was regular customer diff --git a/public/assets/tests/html_utils.js b/public/assets/tests/html_utils.js index d75ce71fa..1e2ebe41e 100644 --- a/public/assets/tests/html_utils.js +++ b/public/assets/tests/html_utils.js @@ -1984,11 +1984,11 @@ test('check getRecipientArticle format', function() { sender: { name: 'Agent', }, - from: 'zammad@example.com', + from: 'customer2@example.com', to: 'customer@example.com', } result = { - to: 'customer@example.com', + to: 'customer2@example.com', cc: '', body: '', in_reply_to: 'message_id7', @@ -2024,7 +2024,7 @@ test('check getRecipientArticle format', function() { to: 'customer@example.com', } result = { - to: 'agent@example.com', + to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id8', @@ -2295,7 +2295,7 @@ test('check getRecipientArticle format', function() { cc: '', } result = { - to: 'customer@example.com, customer1@example.com, customer2@example.com', + to: 'customer1@example.com, customer2@example.com, customer@example.com', cc: '', body: '', in_reply_to: 'message_id15', @@ -2334,7 +2334,7 @@ test('check getRecipientArticle format', function() { cc: '', } result = { - to: 'customer@example.com, customer1@example.com, customer2@example.com, customer2+2@example.com', + to: 'customer1@example.com, customer2@example.com, customer2+2@example.com, customer@example.com', cc: '', body: '', in_reply_to: 'message_id16', @@ -2440,6 +2440,45 @@ test('check getRecipientArticle format', function() { verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, false) deepEqual(verify, result) + agent = { + login: 'login', + firstname: 'firstname', + lastname: 'lastname', + email: 'agent@example.com', + } + ticket = { + customer: agent, + } + article = { + message_id: 'message_id19', + created_by: agent, + type: { + name: 'email', + }, + sender: { + name: 'Agent', + }, + from: 'Agent ', + to: 'Sender ', + cc: '', + } + result = { + to: 'agent@example.com', + cc: '', + body: '', + in_reply_to: 'message_id19', + } + email_addresses = [ + { + email: 'zammad@example.com', + }, + { + email: 'zammad2@example.com', + } + ] + verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, false) + deepEqual(verify, result) + }); }