diff --git a/app/assets/javascripts/app/lib/app_post/utils.coffee b/app/assets/javascripts/app/lib/app_post/utils.coffee index 01eac6012..278c1121c 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.coffee @@ -938,10 +938,19 @@ class App.Utils return articleNew if type.name is 'email' || type.name is 'web' + localEmailAddresses = [] + for address in email_addresses + if address && !_.isEmpty(address.email) + localEmailAddresses.push address.email.toString().toLowerCase() + + isLocalAddress = (address) -> + return false if _.isEmpty(address) + _.contains(localEmailAddresses, address.toString().toLowerCase()) + article_created_by_email = undefined if article_created_by && article_created_by.email article_created_by_email = article_created_by.email.toLowerCase() - if article.sender.name is 'Agent' && article_created_by_email && article.from && !article.from.match(article_created_by_email) + if article.sender.name is 'Agent' && ((article_created_by_email && article.from && !article.from.match(article_created_by_email)) || isLocalAddress(article.from)) articleNew.to = article.to else if article.reply_to @@ -957,15 +966,6 @@ class App.Utils # filter for uniq recipients recipientAddresses = {} - localEmailAddresses = [] - for address in email_addresses - if address && !_.isEmpty(address.email) - localEmailAddresses.push address.email.toString().toLowerCase() - - isLocalAddress = (address) -> - return false if _.isEmpty(address) - _.contains(localEmailAddresses, address.toString().toLowerCase()) - addAddresses = (addressLine, line) -> lineNew = '' recipients = emailAddresses.parseAddressList(addressLine) diff --git a/public/assets/tests/html_utils.js b/public/assets/tests/html_utils.js index f642eded6..a8bd921d2 100644 --- a/public/assets/tests/html_utils.js +++ b/public/assets/tests/html_utils.js @@ -2321,7 +2321,7 @@ test('check getRecipientArticle format', function() { customer: customer, } article = { - message_id: 'message_id15', + message_id: 'message_id16', created_by: customer, type: { name: 'email', @@ -2337,7 +2337,7 @@ test('check getRecipientArticle format', function() { to: 'customer@example.com, customer1@example.com, customer2@example.com, customer2+2@example.com', cc: '', body: '', - in_reply_to: 'message_id15', + in_reply_to: 'message_id16', } email_addresses = [ { @@ -2360,13 +2360,13 @@ test('check getRecipientArticle format', function() { login: 'login', firstname: 'firstname', lastname: 'lastname', - email: 'agent@example.com', + email: 'zammad@example.com', } ticket = { customer: customer, } article = { - message_id: 'message_id16', + message_id: 'message_id17', created_by: agent, type: { name: 'email', @@ -2382,7 +2382,7 @@ test('check getRecipientArticle format', function() { to: 'customer@example.com', cc: '', body: '', - in_reply_to: 'message_id16', + in_reply_to: 'message_id17', } email_addresses = [ { @@ -2395,6 +2395,51 @@ test('check getRecipientArticle format', function() { verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, true) deepEqual(verify, result) + customer = { + login: 'login', + firstname: 'firstname', + lastname: 'lastname', + email: 'customer@example.com', + } + agent = { + login: 'login', + firstname: 'firstname', + lastname: 'lastname', + email: 'zammad@example.com', + } + ticket = { + customer: customer, + } + article = { + message_id: 'message_id18', + created_by: agent, + type: { + name: 'email', + }, + sender: { + name: 'Agent', + }, + from: 'zammad@example.com', + to: 'customer@example.com', + cc: '', + } + result = { + to: 'customer@example.com', + cc: '', + body: '', + in_reply_to: 'message_id18', + } + 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) + }); }