From 89b34b57484d5dfba7913b9bf2c56c1ec5c80763 Mon Sep 17 00:00:00 2001 From: Lukas <35193662+NixNotCastey@users.noreply.github.com> Date: Wed, 13 Oct 2021 18:05:18 +0200 Subject: [PATCH] Use double curly brackets and sanity check for customSubject --- server/notification-providers/smtp.js | 24 ++++++++++++++---------- src/components/notifications/SMTP.vue | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/server/notification-providers/smtp.js b/server/notification-providers/smtp.js index dd1cd10a..a74b48cc 100644 --- a/server/notification-providers/smtp.js +++ b/server/notification-providers/smtp.js @@ -21,19 +21,23 @@ class SMTP extends NotificationProvider { pass: notification.smtpPassword, }; } - // Lets start with default subject + // Lets start with default subject and empty string for custom one let subject = msg; + let customSubject = ""; // Our subject cannot end with whitespace it's often raise spam score - let customsubject = notification.customsubject.trim() + // Once I got "Cannot read property 'trim' of undefined", better be safe than sorry + if (notification.customSubject) { + customSubject = notification.customSubject.trim() + } // If custom subject is not empty, change subject for notification - if (customsubject !== "") { + if (customSubject !== "") { // Replace "MACROS" with coresponding variable - let replaceName = new RegExp("{NAME}", "g"); - let replaceHostname = new RegExp("{HOSTNAME}", "g"); - let replaceStatus = new RegExp("{STATUS}", "g"); + let replaceName = new RegExp("{{NAME}}", "g"); + let replaceHostname = new RegExp("{{HOSTNAME}}", "g"); + let replaceStatus = new RegExp("{{STATUS}}", "g"); // Lets start with dummy values to simplify code let monitorName = "Test" @@ -50,11 +54,11 @@ class SMTP extends NotificationProvider { } // Break replace to one by line for better readability - customsubject = customsubject.replace(replaceStatus, serviceStatus); - customsubject = customsubject.replace(replaceName, monitorName); - customsubject = customsubject.replace(replaceHostname, monitorHostname); + customSubject = customSubject.replace(replaceStatus, serviceStatus); + customSubject = customSubject.replace(replaceName, monitorName); + customSubject = customSubject.replace(replaceHostname, monitorHostname); - subject = customsubject + subject = customSubject } let transporter = nodemailer.createTransport(config); diff --git a/src/components/notifications/SMTP.vue b/src/components/notifications/SMTP.vue index 01bdf860..79efd9f9 100644 --- a/src/components/notifications/SMTP.vue +++ b/src/components/notifications/SMTP.vue @@ -45,7 +45,7 @@
- +