diff --git a/src/helpers/configValidator.js b/src/helpers/configValidator.js index bf97cee1..3bac2236 100644 --- a/src/helpers/configValidator.js +++ b/src/helpers/configValidator.js @@ -14,6 +14,14 @@ ajv.addFormat('comma-separated-emails', { return emails.split(',').every((email) => emailRegex.test(email.trim())); }, }); +ajv.addFormat('email-with-name', { + type: 'string', + validate: (email) => { + // this is Ajv's regex for email format (https://github.com/ajv-validator/ajv-formats/blob/master/src/formats.ts#L106) + const emailRegex = new RegExp(/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i); + return emailRegex.test(email.trim().split(' ').pop()); + }, +}); const validator = ajv.addSchema(configSchema, 'config'); diff --git a/src/helpers/schemas/config.schema.json b/src/helpers/schemas/config.schema.json index fd66a709..660e9c28 100644 --- a/src/helpers/schemas/config.schema.json +++ b/src/helpers/schemas/config.schema.json @@ -44,7 +44,8 @@ "type": "integer" }, "from": { - "type": "string" + "type": "string", + "format": "email-with-name" }, "to": { "anyOf": [