From 84edeb85cd8460cb9ecd2282ffbc2e8ff90b15a3 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Fri, 1 Sep 2017 11:09:24 -0400 Subject: [PATCH] (js) Fix parsing of pasted email addresses Fixes #4258 and fixes #4097 --- NEWS | 1 + .../js/Mailer/MessageEditorController.js | 23 ++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 6707f9108..505b1c0b0 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ Bug fixes - [core] increased column size of settings/defaults for MySQL (#4260) - [web] fixed display of error when the mail editor is in a popup - [web] attachments are not displayed on IOS (#4150) + - [web] fixed parsing of pasted email addresses from Spreadsheet (#4258) 3.2.10 (2017-07-05) ------------------- diff --git a/UI/WebServerResources/js/Mailer/MessageEditorController.js b/UI/WebServerResources/js/Mailer/MessageEditorController.js index c39352145..2f4235262 100644 --- a/UI/WebServerResources/js/Mailer/MessageEditorController.js +++ b/UI/WebServerResources/js/Mailer/MessageEditorController.js @@ -259,14 +259,31 @@ } function addRecipient(contact, field) { - var recipients, recipient, list; + var recipients, recipient, list, i, address; + var emailRE = /([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)/i; recipients = vm.message.editable[field]; if (angular.isString(contact)) { - _.forEach(contact.split(/[,;]/), function(address) { + // Examples that are handled: + // Smith, John + // ; + // foo@bar.com abc@xyz.com + address = ''; + for (i = 0; i < contact.length; i++) { + if ((contact.charCodeAt(i) == 32 || // space + contact.charCodeAt(i) == 44 || // , + contact.charCodeAt(i) == 59) && // ; + emailRE.test(address)) { + recipients.push(address); + address = ''; + } + else { + address += contact.charAt(i); + } + } + if (address) recipients.push(address); - }); return null; }