Fix handling of email addresses with names

- read-only was leaving out quotes on name, failing validation
- Commas in name caused problems when adding in to existing values due to simplistic CSV splitting
This commit is contained in:
nathan 2023-08-03 16:57:53 -06:00
parent 6417aa8777
commit 7a17dcc7cb
2 changed files with 13 additions and 3 deletions

View File

@ -11,7 +11,6 @@
import {IsEmail} from "../Validators/IsEmail"; import {IsEmail} from "../Validators/IsEmail";
import {Et2UrlEmail} from "./Et2UrlEmail"; import {Et2UrlEmail} from "./Et2UrlEmail";
import {Et2UrlReadonly} from "./Et2UrlReadonly"; import {Et2UrlReadonly} from "./Et2UrlReadonly";
import {Et2EmailTag} from "../Et2Select/Tag/Et2EmailTag";
/** /**
* @customElement et2-url-email_ro * @customElement et2-url-email_ro
@ -89,7 +88,7 @@ export class Et2UrlEmailReadonly extends Et2UrlReadonly
{ {
let email; let email;
if (IsEmail.EMAIL_PREG.exec(email=this.value) || if (IsEmail.EMAIL_PREG.exec(email=this.value) ||
IsEmail.EMAIL_PREG.exec(email=this.value+' <'+this.statustext+'>')) IsEmail.EMAIL_PREG.exec(email = '"' + this.value + '" <' + this.statustext + '>'))
{ {
Et2UrlEmail.action(email); Et2UrlEmail.action(email);
} }

View File

@ -57,6 +57,17 @@ egw.extend('open', egw.MODULE_WND_LOCAL, function(_egw, _wnd)
bcc: match['bcc'] || [] bcc: match['bcc'] || []
}; };
// No CSV, split them here and pay attention to quoted commas
const split_regex = /("[^"]*" <[^>]*>)|("[^"]*")|('[^']*')|([^,]+)/g;
for (let index in content)
{
if (typeof content[index] == "string")
{
const matches = content[index].match(split_regex);
content[index] = matches ?? content[index];
}
}
// Encode html entities in the URI, otheerwise server XSS protection wont // Encode html entities in the URI, otheerwise server XSS protection wont
// allow it to pass, because it may get mistaken for some forbiden tags, // allow it to pass, because it may get mistaken for some forbiden tags,
// e.g., "Mathias <mathias@example.com>" the first part of email "<mathias" // e.g., "Mathias <mathias@example.com>" the first part of email "<mathias"
@ -70,7 +81,7 @@ egw.extend('open', egw.MODULE_WND_LOCAL, function(_egw, _wnd)
{ {
if (content[index].length > 0) if (content[index].length > 0)
{ {
var cLen = content[index].split(','); var cLen = content[index];
egw.message(egw.lang('%1 email(s) added into %2', cLen.length, egw.lang(index))); egw.message(egw.lang('%1 email(s) added into %2', cLen.length, egw.lang(index)));
return; return;
} }