make welcome message templatable

This commit is contained in:
zefie
2022-10-15 20:03:30 -04:00
parent 47e87a4ebc
commit 894b2e733e
5 changed files with 74 additions and 17 deletions

View File

@@ -0,0 +1,14 @@
From: zefie <zefie@zefie.net>
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 <a href="wtv-setup:/mail-signature">signature settings</a> which also support custom HTML abilities.
You can use Mail to send internal email to others by emailing <b>theirusername@${service_name}</b>, replacing "theirusername" with the user's actual username.
Others within the same minisrv network can also email you by sending a message to <b>${user_address}</b>
You can also save webpages to your <a href="wtv-favorite:/favorite">Favorites</a>, as well as join <a href="wtv-news:/lobby">discussion groups on usenet</a>!
To report trouble of any kind please contact <b>${service_owner_contact}</b> via <b>${service_owner_contact_method}</b>.

View File

@@ -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, "<br><br>");
data += `${(message.allow_html) ? message.body : wtvshared.htmlEntitize(message.body, true)}
<br>
<br>`;
if (message.signature) {
@@ -283,7 +283,8 @@ ${wtvshared.htmlEntitize(message.body, true)}
}
data += `<p>
`;
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']);

View File

@@ -98,6 +98,8 @@ Display name<br>
bgcolor=#444444 text=#ffdd33 cursor=#cc9933
TYPE="text" ASCIIONLY
SIZE="18"
selected
autoactivate
MAXLENGTH="18">
</a>
</table>

View File

@@ -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) {

View File

@@ -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 += "<br>Details:<br>" + 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;