From b58c3fd4677d7a3d1ed78868ee9e103fece57fc1 Mon Sep 17 00:00:00 2001 From: prafull-opensignlabs Date: Thu, 8 Feb 2024 20:03:15 +0530 Subject: [PATCH] add replacemailvaribles function to change varibale from custom mail --- apps/OpenSignServer/Utils.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/apps/OpenSignServer/Utils.js b/apps/OpenSignServer/Utils.js index 98c1a4366..8fc705ceb 100644 --- a/apps/OpenSignServer/Utils.js +++ b/apps/OpenSignServer/Utils.js @@ -17,3 +17,24 @@ export const color = [ '#66ccff', '#ffffcc', ]; + +export function replaceMailVaribles(subject, body, variables) { + let replacedSubject = subject; + let replacedBody = body; + + for (const variable in variables) { + const regex = new RegExp(`{{${variable}}}`, 'g'); + if (subject) { + replacedSubject = replacedSubject.replace(regex, variables[variable]); + } + if (body) { + replacedBody = replacedBody.replace(regex, variables[variable]); + } + } + + const result = { + subject: replacedSubject, + body: replacedBody, + }; + return result; +}