From e24d5b8f5e1ce26f64c4af6120055e99c388019e Mon Sep 17 00:00:00 2001 From: abhigyan-mohanta Date: Wed, 6 Nov 2024 13:06:22 +0530 Subject: [PATCH] fix #5314 Email Address Friendly Name Error --- src/components/notifications/SendGrid.vue | 105 ++++++++++++++++++++-- 1 file changed, 100 insertions(+), 5 deletions(-) diff --git a/src/components/notifications/SendGrid.vue b/src/components/notifications/SendGrid.vue index 18118f469..01d4f453b 100644 --- a/src/components/notifications/SendGrid.vue +++ b/src/components/notifications/SendGrid.vue @@ -5,21 +5,65 @@
- + +
+ {{ $t("Please use format: Friendly Name or just email@domain.com") }} +
- + +
+ {{ $t("Please use format: Friendly Name or just email@domain.com") }} +
- +
{{ $t("Separate multiple email addresses with commas") }}
+
+ {{ $t("Please use format: Friendly Name or just email@domain.com for each address") }} +
- - {{ $t("Separate multiple email addresses with commas") }} + +
{{ $t("Separate multiple email addresses with commas") }}
+
+ {{ $t("Please use format: Friendly Name or just email@domain.com for each address") }} +
@@ -38,6 +82,46 @@ export default { components: { HiddenInput, }, + + data() { + return { + errors: { + from: false, + to: false, + cc: false, + bcc: false + } + } + }, + + methods: { + isValidEmailFormat(value) { + const friendlyEmailRegex = /^[^<>]+ <[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}>$/; + const emailOnlyRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; + return friendlyEmailRegex.test(value) || emailOnlyRegex.test(value); + }, + + validateEmail(event, field) { + const value = event.target.value; + + if (!value) { + this.errors[field] = false; + return; + } + + if (field === 'cc' || field === 'bcc') { + if (value.includes(',')) { + this.errors[field] = !value.split(',') + .map(email => email.trim()) + .every(email => this.isValidEmailFormat(email)); + return; + } + } + + this.errors[field] = !this.isValidEmailFormat(value); + } + }, + mounted() { if (typeof this.$parent.notification.sendgridSubject === "undefined") { this.$parent.notification.sendgridSubject = "Notification from Your Uptime Kuma"; @@ -45,3 +129,14 @@ export default { }, }; + + \ No newline at end of file