Fix splitEmail() when name contains angle brackets

This commit is contained in:
nathan 2024-02-01 14:59:13 -07:00
parent ca443060f4
commit 2695dba4ea

View File

@ -98,10 +98,11 @@ export function splitEmail(email_string) : { name : string, email : string }
if(email_string && email_string.indexOf('<') !== -1) if(email_string && email_string.indexOf('<') !== -1)
{ {
const parts = email_string.split('<'); const parts = email_string.split('<');
if(parts[0]) if(parts.length > 1)
{ {
split.email = parts[1].substring(0, parts[1].length - 1).trim(); split.email = parts.pop();
split.name = parts[0].trim(); split.email = split.email.substring(0, split.email.length - 1).trim();
split.name = parts.join("<").trim();
// remove quotes // remove quotes
while(split.name.length > 1 && (split.name[0] === '"' || split.name[0] === "'") && split.name[0] === split.name.substring(split.name.length - 1)) while(split.name.length > 1 && (split.name[0] === '"' || split.name[0] === "'") && split.name[0] === split.name.substring(split.name.length - 1))
{ {