Use double curly brackets and sanity check for customSubject

pull/627/head
Lukas 3 years ago
parent 330cd6e058
commit 89b34b5748

@ -21,19 +21,23 @@ class SMTP extends NotificationProvider {
pass: notification.smtpPassword, pass: notification.smtpPassword,
}; };
} }
// Lets start with default subject // Lets start with default subject and empty string for custom one
let subject = msg; let subject = msg;
let customSubject = "";
// Our subject cannot end with whitespace it's often raise spam score // 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 custom subject is not empty, change subject for notification
if (customsubject !== "") { if (customSubject !== "") {
// Replace "MACROS" with coresponding variable // Replace "MACROS" with coresponding variable
let replaceName = new RegExp("{NAME}", "g"); let replaceName = new RegExp("{{NAME}}", "g");
let replaceHostname = new RegExp("{HOSTNAME}", "g"); let replaceHostname = new RegExp("{{HOSTNAME}}", "g");
let replaceStatus = new RegExp("{STATUS}", "g"); let replaceStatus = new RegExp("{{STATUS}}", "g");
// Lets start with dummy values to simplify code // Lets start with dummy values to simplify code
let monitorName = "Test" let monitorName = "Test"
@ -50,11 +54,11 @@ class SMTP extends NotificationProvider {
} }
// Break replace to one by line for better readability // Break replace to one by line for better readability
customsubject = customsubject.replace(replaceStatus, serviceStatus); customSubject = customSubject.replace(replaceStatus, serviceStatus);
customsubject = customsubject.replace(replaceName, monitorName); customSubject = customSubject.replace(replaceName, monitorName);
customsubject = customsubject.replace(replaceHostname, monitorHostname); customSubject = customSubject.replace(replaceHostname, monitorHostname);
subject = customsubject subject = customSubject
} }
let transporter = nodemailer.createTransport(config); let transporter = nodemailer.createTransport(config);

@ -45,7 +45,7 @@
<div class="mb-3"> <div class="mb-3">
<label for="subject-email" class="form-label">{{ $t("Email Subject") }}</label> <label for="subject-email" class="form-label">{{ $t("Email Subject") }}</label>
<input id="subject-email" v-model="$parent.notification.customsubject" type="text" class="form-control" autocomplete="false" placeholder="Service {NAME} on {HOSTNAME} has changed status to {STATUS}"> <input id="subject-email" v-model="$parent.notification.customSubject" type="text" class="form-control" autocomplete="false" placeholder="Service {{NAME}} on {{HOSTNAME}} has changed status to {{STATUS}}">
</div> </div>
<div class="mb-3"> <div class="mb-3">

Loading…
Cancel
Save