From 894b2e733e213185885f8cff9f67664c1212accc Mon Sep 17 00:00:00 2001 From: zefie Date: Sat, 15 Oct 2022 20:03:30 -0400 Subject: [PATCH] make welcome message templatable --- .../templates/wtv-mail/welcomeMail.txt | 14 +++++ .../ServiceVault/wtv-mail/readmail.js | 7 ++- .../ServiceVault/wtv-setup/add-user.js | 2 + zefie_wtvp_minisrv/includes/WTVMail.js | 56 ++++++++++++++++--- zefie_wtvp_minisrv/includes/WTVShared.js | 12 ++-- 5 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 zefie_wtvp_minisrv/ServiceDeps/templates/wtv-mail/welcomeMail.txt diff --git a/zefie_wtvp_minisrv/ServiceDeps/templates/wtv-mail/welcomeMail.txt b/zefie_wtvp_minisrv/ServiceDeps/templates/wtv-mail/welcomeMail.txt new file mode 100644 index 00000000..c2926f2d --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceDeps/templates/wtv-mail/welcomeMail.txt @@ -0,0 +1,14 @@ +From: zefie +Subject: Welcome to minisrv! + +Thank you for test driving minisrv! + +minisrv aims to provide a simalar experience as the production WebTV Services. +You can enjoy fun features as they are released, such as WebTV Mail, WebTV Chat, Usenet, customing your signature settings which also support custom HTML abilities. + +You can use Mail to send internal email to others by emailing theirusername@${service_name}, replacing "theirusername" with the user's actual username. +Others within the same minisrv network can also email you by sending a message to ${user_address} + +You can also save webpages to your Favorites, as well as join discussion groups on usenet! + +To report trouble of any kind please contact ${service_owner_contact} via ${service_owner_contact_method}. \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-mail/readmail.js b/zefie_wtvp_minisrv/ServiceVault/wtv-mail/readmail.js index afcd6b1f..863b1114 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-mail/readmail.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-mail/readmail.js @@ -274,8 +274,8 @@ ${(message.subject) ? wtvshared.htmlEntitize(message.subject) : '(No subject)'} if (typeof message.body === "object" && message.body) { message.body = wtvshared.decodeBufferText(message.body); } - data += ` -${wtvshared.htmlEntitize(message.body, true)} + message.body = message.body.replace(/\n/g, "

"); + data += `${(message.allow_html) ? message.body : wtvshared.htmlEntitize(message.body, true)}

`; if (message.signature) { @@ -283,7 +283,8 @@ ${wtvshared.htmlEntitize(message.body, true)} } data += `

`; - if (message.attachments) { + console.log(message.allow_html) + if (Array.isArray(message.attachments)) { message.attachments.forEach((v, k) => { if (v) { console.log("*****************", v['Content-Type']); diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-setup/add-user.js b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/add-user.js index bda36f7b..947ddf46 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-setup/add-user.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/add-user.js @@ -98,6 +98,8 @@ Display name
bgcolor=#444444 text=#ffdd33 cursor=#cc9933 TYPE="text" ASCIIONLY SIZE="18" +selected +autoactivate MAXLENGTH="18"> diff --git a/zefie_wtvp_minisrv/includes/WTVMail.js b/zefie_wtvp_minisrv/includes/WTVMail.js index 28720507..2b17fb40 100644 --- a/zefie_wtvp_minisrv/includes/WTVMail.js +++ b/zefie_wtvp_minisrv/includes/WTVMail.js @@ -156,7 +156,7 @@ class WTVMail { return this.uuid.v1(); } - createMessage(mailboxid, from_addr, to_addr, msgbody, subject = null, from_name = null, to_name = null, signature = null, date = null, known_sender = false, attachments = [], url = null, url_title = null) { + createMessage(mailboxid, from_addr, to_addr, msgbody, subject = null, from_name = null, to_name = null, signature = null, date = null, known_sender = false, attachments = [], url = null, url_title = null, allow_html = false) { if (this.createMailbox(mailboxid)) { if (!date) date = Math.floor(Date.now() / 1000); @@ -177,7 +177,8 @@ class WTVMail { "unread": true, "attachments": attachments, "url": url, - "url_title": url_title + "url_title": url_title, + "allow_html": allow_html } try { if (this.fs.existsSync(message_file_out)) { @@ -202,14 +203,53 @@ class WTVMail { } createWelcomeMessage() { - var from_addr = (this.minisrv_config.config.service_owner_account) ? this.minisrv_config.config.service_owner_account : this.minisrv_config.config.service_owner; - from_addr += "@" + this.minisrv_config.config.service_name; - var from_name = this.minisrv_config.config.service_owner + var welcomeTemplate = this.wtvshared.getTemplate("wtv-mail", "welcomeMail.txt").toString('ascii'); + var end_of_headers = false; + var msg = ""; + var self = this; var to_addr = this.wtvclient.getSessionData("subscriber_username") + "@" + this.minisrv_config.config.service_name; var to_name = this.wtvclient.getSessionData("subscriber_name"); - var subj = "Welcome to " + this.minisrv_config.config.service_name; - var msg = "poop"; - return this.createMessage(0, from_addr, to_addr, msg, subj, from_name, to_name, null, null, true); + var available_tags = { + ...this.minisrv_config.config, + "user_address": to_addr, + "user_name": to_name + } + var from_name, from_addr, subj = null; + var lines = welcomeTemplate.replace(/\r/g, '').split("\n"); + lines.forEach((line) => { + if (line.indexOf(": ") > 1 && !end_of_headers) { + var header = [line.slice(0, line.indexOf(':')), line.slice(line.indexOf(':') + 2).trim()]; + switch (header[0].toLowerCase()) { + case "from": + if (header[1].indexOf("<") >= 0) { + var email = header[1].match(/(.+) \<(.+)\>/); + if (email) { + from_name = email[1]; + from_addr = email[2]; + } else { + var email = header[1].match(/\<(.+)\>/); + from_addr = email[1]; + } + } else if (header[1].indexOf('@') >= 0) { + from_addr = header[1]; + } + break; + + case "subject": + subj = header[1]; + break; + } + } else if (line == '') end_of_headers = true; + else { + msg += line.replace(/\$\{(\w{1,})\}/g, function (x) { + var out = ''; + var tag = x.replace("${", '').replace('}', ''); + if (available_tags[tag]) out = available_tags[tag]; + return out + }) + "\n"; + } + }); + return this.createMessage(0, from_addr, to_addr, msg, subj, from_name, to_name, null, null, true, [], null, null, true); } getMessage(mailboxid, messageid) { diff --git a/zefie_wtvp_minisrv/includes/WTVShared.js b/zefie_wtvp_minisrv/includes/WTVShared.js index ba371348..570bfb23 100644 --- a/zefie_wtvp_minisrv/includes/WTVShared.js +++ b/zefie_wtvp_minisrv/includes/WTVShared.js @@ -678,26 +678,26 @@ class WTVShared { var minisrv_config = this.minisrv_config; switch (code) { case 401: - if (data === null) data = minisrv_config.config.errorMessages[code].replace(/\$\{(.+)\}/g, function (x) { return minisrv_config.config[x.replace("${", '').replace('}', '')] }); + if (data === null) data = minisrv_config.config.errorMessages[code].replace(/\$\{(\w{1,})\}/g, function (x) { return minisrv_config.config[x.replace("${", '').replace('}', '')] }); if (pc_mode) headers = "401 Unauthorized\n"; else headers = code + " " + data + "\n"; headers += "Content-Type: text/html\n"; break; case 403: - if (data === null) data = minisrv_config.config.errorMessages[code].replace(/\$\{(.+)\}/g, function (x) { return minisrv_config.config[x.replace("${", '').replace('}', '')] }); + if (data === null) data = minisrv_config.config.errorMessages[code].replace(/\$\{(\w{1,})\}/g, function (x) { return minisrv_config.config[x.replace("${", '').replace('}', '')] }); if (pc_mode) headers = "403 Forbidden\n"; else headers = code + " " + data + "\n"; headers += "Content-Type: text/html\n"; break; case 404: - if (data === null) data = minisrv_config.config.errorMessages[code].replace(/\$\{(.+)\}/g, function (x) { return minisrv_config.config[x.replace("${", '').replace('}', '')] }); + if (data === null) data = minisrv_config.config.errorMessages[code].replace(/\$\{(\w{1,})\}/g, function (x) { return minisrv_config.config[x.replace("${", '').replace('}', '')] }); if (pc_mode) headers = "404 Not Found\n"; else headers = code + " " + data + "\n"; headers += "Content-Type: text/html\n"; break; case 400: case 500: - if (data === null) data = minisrv_config.config.errorMessages[code].replace(/\$\{(.+)\}/g, function (x) { return minisrv_config.config[x.replace("${", '').replace('}', '')] }); + if (data === null) data = minisrv_config.config.errorMessages[code].replace(/\$\{(\w{1,})\}/g, function (x) { return minisrv_config.config[x.replace("${", '').replace('}', '')] }); if (details) data += "
Details:
" + details; if (pc_mode) headers = "500 Internal Server Error\n"; else headers = code + " " + data + "\n"; @@ -771,7 +771,7 @@ class WTVShared { return this.zlib.deflateSync(data, { 'level': 9 }).toString('base64'); } - getTemplate(service_name, path, path_only = true) { + getTemplate(service_name, path, path_only = false) { var self = this; var outdata = null; var found = false @@ -780,7 +780,7 @@ class WTVShared { var search = self.getAbsolutePath(template_vault_dir + self.path.sep + service_name + self.path.sep + path); if (self.fs.existsSync(search)) { if (path_only) outdata = search; - else outdata = fs.readFileSync(search).toString('ascii'); + else outdata = self.fs.readFileSync(search); if (!self.minisrv_config.config.debug_flags.quiet) console.log(" * Found " + search + " to handle template"); found = true; return false;