implement mail signature colors

This commit is contained in:
zefie
2022-03-18 16:35:44 -04:00
parent 2ebc2d392b
commit ffa0d7e63e
3 changed files with 71 additions and 28 deletions

View File

@@ -39,6 +39,7 @@ Location: wtv-mail:/listmail`;
headers = `200 OK headers = `200 OK
Content-type: text/html`; Content-type: text/html`;
var message_colors = ssid_sessions[socket.ssid].mailstore.getSignatureColors(message.signature);
if (typeof message.subject == "object" && message.subject) message.subject = wtvshared.decodeBufferText(message.subject); if (typeof message.subject == "object" && message.subject) message.subject = wtvshared.decodeBufferText(message.subject);
data = `<wtvnoscript> data = `<wtvnoscript>
@@ -58,9 +59,9 @@ ${(message.subject) ? wtvshared.htmlEntitize(message.subject) : '(No subject)'}
</title> </title>
</head> </head>
<body <body
bgcolor="#171726" bgcolor="${message_colors.bgcolor}"
text="#82A9D9" text="${message_colors.text}"
link="#BDA73A" vlink="#62B362" vspace=0 hspace=0> link="${message_colors.link}" vlink="${message_colors.vlink}" vspace=0 hspace=0>
<sidebar width=109> <sidebar width=109>
<table cellspacing=0 cellpadding=0> <table cellspacing=0 cellpadding=0>
<tr> <tr>
@@ -187,13 +188,13 @@ id=save
<td width=451 colspan=2 align=center bgcolor=#5B6C81> <td width=451 colspan=2 align=center bgcolor=#5B6C81>
<spacer type=vertical size=13> <spacer type=vertical size=13>
<tr> <tr>
<td height=8 bgcolor=#171726 colspan=2> <td height=8 bgcolor=${message_colors.bgcolor} colspan=2>
<img src="wtv-mail:/content/images/CornerTop.gif" width=8 height=8> <img src="wtv-mail:/content/images/CornerTop.gif" width=8 height=8>
<tr> <tr>
<td bgcolor=#171726 width=451 valign=top> <td bgcolor=${message_colors.bgcolor} width=451 valign=top>
<table cellspacing=0 cellpadding=0 width=451> <table cellspacing=0 cellpadding=0 width=451>
<tr> <tr>
<td bgcolor=#171726 width=13> <td bgcolor=${message_colors.bgcolor} width=13>
<spacer type=horizontal size=13> <spacer type=horizontal size=13>
<td height=9> <td height=9>
</table> </table>

View File

@@ -28,6 +28,7 @@ wtv-expire: wtv-mail:/sendmail
Location: wtv-mail:/sendmail`; Location: wtv-mail:/sendmail`;
} }
var to_addr = request_headers.query.message_to || null; var to_addr = request_headers.query.message_to || null;
var msg_subject = request_headers.query.message_subject || null; var msg_subject = request_headers.query.message_subject || null;
var msg_body = request_headers.query.message_body || null; var msg_body = request_headers.query.message_body || null;
@@ -35,7 +36,7 @@ Location: wtv-mail:/sendmail`;
var msg_url = request_headers.query.message_url || null; var msg_url = request_headers.query.message_url || null;
var msg_url_title = request_headers.query.message_title || null; var msg_url_title = request_headers.query.message_title || null;
var no_signature = false; var no_signature = false;
if (request_headers.query.togglesign == "true") no_signature = false;
var mail_draft_data = ssid_sessions[socket.ssid].getSessionData("mail_draft"); var mail_draft_data = ssid_sessions[socket.ssid].getSessionData("mail_draft");
var mail_draft_attachments = ssid_sessions[socket.ssid].getSessionData("mail_draft_attachments") || {}; var mail_draft_attachments = ssid_sessions[socket.ssid].getSessionData("mail_draft_attachments") || {};
if (mail_draft_data) { if (mail_draft_data) {
@@ -47,6 +48,10 @@ Location: wtv-mail:/sendmail`;
if (mail_draft_data.msg_url) msg_url = mail_draft_data.msg_url; if (mail_draft_data.msg_url) msg_url = mail_draft_data.msg_url;
if (mail_draft_data.msg_url_title) msg_url_title = mail_draft_data.msg_url_title; if (mail_draft_data.msg_url_title) msg_url_title = mail_draft_data.msg_url_title;
} }
if (request_headers.query.togglesign == "true") no_signature = false;
if (request_headers.query.togglesign == "false") no_signature = true;
if (mail_draft_attachments) { if (mail_draft_attachments) {
if (mail_draft_attachments.message_snapshot_data) message_snapshot_data = mail_draft_attachments.message_snapshot_data; if (mail_draft_attachments.message_snapshot_data) message_snapshot_data = mail_draft_attachments.message_snapshot_data;
else if (request_headers.query.message_snapshot_data) message_snapshot_data = request_headers.query.message_snapshot_data; else if (request_headers.query.message_snapshot_data) message_snapshot_data = request_headers.query.message_snapshot_data;
@@ -152,6 +157,10 @@ Content-type: text/html`;
mail_draft_data.message_voicemail_data = request_headers.query.message_voicemail_data mail_draft_data.message_voicemail_data = request_headers.query.message_voicemail_data
ssid_sessions[socket.ssid].setSessionData("mail_draft_attachments", mail_draft_data); ssid_sessions[socket.ssid].setSessionData("mail_draft_attachments", mail_draft_data);
} }
var message_colors = null;
if (no_signature) message_colors = ssid_sessions[socket.ssid].mailstore.getSignatureColors(null, true);
else message_colors = ssid_sessions[socket.ssid].mailstore.getSignatureColors(ssid_sessions[socket.ssid].getSessionData("subscriber_signature"), true);
data = `<HTML> data = `<HTML>
<head> <head>
<display poweroffalert > <display poweroffalert >
@@ -189,7 +198,7 @@ location.reload(); }
Write an e-mail message Write an e-mail message
</title> </title>
</head> </head>
<body bgcolor="#171726" text="#82A9D9" link="#BDA73A" vlink="#62B362" vspace=0 hspace=0> <body bgcolor="#171726" text="${message_colors.text}" link="${message_colors.link}" vlink="${message_colors.vlink}" vspace=0 hspace=0>
<form action="wtv-mail:/sendmail#focus" method="post" name=sendform > <form action="wtv-mail:/sendmail#focus" method="post" name=sendform >
<input type=hidden name="wtv-saved-message-id" value="writemessage-outbox"> <input type=hidden name="wtv-saved-message-id" value="writemessage-outbox">
<input type=hidden name="message_reply_all_cc" value=""> <input type=hidden name="message_reply_all_cc" value="">
@@ -324,7 +333,7 @@ Write an e-mail message
<spacer type=horizontal size=13> <spacer type=horizontal size=13>
<td bgcolor=#171726 width=438 valign=top> <td bgcolor=#171726 width=438 valign=top>
<spacer type=vertical size=5><br> <spacer type=vertical size=5><br>
<table cellspacing=0 cellpadding=0 bgcolor="#1F2033"> <table cellspacing=0 cellpadding=0 bgcolor="${message_colors.bgcolor}">
<tr> <tr>
<td absheight=2 colspan=5 bgcolor=#495360> <td absheight=2 colspan=5 bgcolor=#495360>
<tr> <tr>
@@ -337,14 +346,14 @@ Write an e-mail message
<td abswidth=385> <td abswidth=385>
<table cellspacing=0 cellpadding=0> <tr> <table cellspacing=0 cellpadding=0> <tr>
<td width=80 valign=top align=right> <td width=80 valign=top align=right>
<font color=#82A9D9>From:&nbsp;</font> <font color=${message_colors.text}>From:&nbsp;</font>
<td width=305 valign=top> <td width=305 valign=top>
<font color=#82A9D9><table cellspacing=0 cellpadding=0 border=0> <font color=${message_colors.text}><table cellspacing=0 cellpadding=0 border=0>
<TR><TD maxlines="1"> <TR><TD maxlines="1">
${address} ${address}
</TD></TR> </TD></TR>
</TABLE></font> </TABLE></font>
<font color=#82A9D9>(${userdisplayname})</font> <font color=${message_colors.text}>(${userdisplayname})</font>
<tr> <tr>
<td height=13 valign=middle colspan=2> <td height=13 valign=middle colspan=2>
<img src="wtv-mail:/content/images/sendmail_panel_dots.gif" width=385 height=2> <img src="wtv-mail:/content/images/sendmail_panel_dots.gif" width=385 height=2>
@@ -353,14 +362,14 @@ ${address}
<a href="client:openaddresspanel">To:</a>&nbsp; <a href="client:openaddresspanel">To:</a>&nbsp;
<td width=305 valign=top> <td width=305 valign=top>
<textarea <textarea
bgcolor="#1F2033" bgcolor="${message_colors.bgcolor}"
cursor=#BDA73A cursor="${message_colors.cursor}"
nosoftbreaks nosoftbreaks
borderimage="file://ROM/Borders/textfield.alt1.bif" borderimage="file://ROM/Borders/textfield.alt1.bif"
nohardbreaks nohardbreaks
selected selected
font=proportional font=proportional
text=#82A9D9 text=${message_colors.text}
name="message_to" name="message_to"
border=0 border=0
width=305 rows=1 width=305 rows=1
@@ -375,15 +384,15 @@ nohighlight
<img src="wtv-mail:/content/images/sendmail_panel_dots.gif" width=385 height=2> <img src="wtv-mail:/content/images/sendmail_panel_dots.gif" width=385 height=2>
<tr> <tr>
<td abswidth=83 valign=top align=right> <td abswidth=83 valign=top align=right>
<font color=#82A9D9>Subject:&nbsp;</font> <font color=${message_colors.text}>Subject:&nbsp;</font>
<td width=305 valign=top> <td width=305 valign=top>
<textarea <textarea
bgcolor="#1F2033" bgcolor="${message_colors.bgcolor}"
cursor=#BDA73A cursor="${message_colors.cursor}"
nosoftbreaks nosoftbreaks
borderimage="file://ROM/Borders/textfield.alt1.bif" borderimage="file://ROM/Borders/textfield.alt1.bif"
nohardbreaks nohardbreaks
text=#82A9D9 text=${message_colors.text}
name="message_subject" font=proportional name="message_subject" font=proportional
border=0 border=0
width=305 rows=1 width=305 rows=1
@@ -399,9 +408,9 @@ autohiragana
<tr> <tr>
<td width=305 colspan=2> <td width=305 colspan=2>
<textarea nosoftbreaks <textarea nosoftbreaks
bgcolor="#1F2033" bgcolor="${message_colors.bgcolor}"
text=#82A9D9 text="${message_colors.text}"
cursor=#BDA73A cursor="${message_colors.cursor}"
name="message_body" font=proportional name="message_body" font=proportional
border=0 border=0
rows=4 rows=4
@@ -412,10 +421,10 @@ autohiragana
growable growable
nextdown="Send">${(msg_body) ? msg_body : ''}</textarea> nextdown="Send">${(msg_body) ? msg_body : ''}</textarea>
</table> </table>
<body bgcolor=#1F2033 <body bgcolor=${message_colors.bgcolor}
text=#82A9D9 text=${message_colors.text}
link=#BDA73A link=${message_colors.link}
vlink=#62B362 vlink=${message_colors.vlink}
vspace=0 vspace=0
hspace=0>`; hspace=0>`;
if (ssid_sessions[socket.ssid].getSessionData("subscriber_signature") && ssid_sessions[socket.ssid].getSessionData("subscriber_signature") != "" && !no_signature) { if (ssid_sessions[socket.ssid].getSessionData("subscriber_signature") && ssid_sessions[socket.ssid].getSessionData("subscriber_signature") != "" && !no_signature) {
@@ -473,7 +482,7 @@ USESTYLE NOARGS>
<td absheight="10"> <td absheight="10">
<img src="ROMCache/Spacer.gif" width="1" height="10"> <img src="ROMCache/Spacer.gif" width="1" height="10">
</td></tr></tbody></table> </td></tr></tbody></table>
<table cellspacing="0" cellpadding="0" bgcolor="#1F2033" background=""> <table cellspacing="0" cellpadding="0" bgcolor="${message_colors.bgcolor}" background="">
<tbody><tr> <tbody><tr>
<td rowspan="100" abswidth="10" bgcolor="191919"> <td rowspan="100" abswidth="10" bgcolor="191919">
<img src="ROMCache/Spacer.gif" width="10" height="1"> <img src="ROMCache/Spacer.gif" width="10" height="1">
@@ -537,7 +546,7 @@ USESTYLE NOARGS>
<td absheight="10"> <td absheight="10">
<img src="ROMCache/Spacer.gif" width="1" height="10"> <img src="ROMCache/Spacer.gif" width="1" height="10">
</td></tr></tbody></table> </td></tr></tbody></table>
<table cellspacing="0" cellpadding="0" bgcolor="#1F2033" background=""> <table cellspacing="0" cellpadding="0" bgcolor="${message_colors.bgcolor}" background="">
<tbody><tr> <tbody><tr>
<td rowspan="100" abswidth="10" bgcolor="191919"> <td rowspan="100" abswidth="10" bgcolor="191919">
<img src="ROMCache/Spacer.gif" width="10" height="1"> <img src="ROMCache/Spacer.gif" width="10" height="1">

View File

@@ -17,6 +17,8 @@ class WTVMail {
mailboxes = null; mailboxes = null;
msgFileExt = ".zmsg"; msgFileExt = ".zmsg";
trashMailboxName = "Trash"; trashMailboxName = "Trash";
defaultColors = {};
sendmailDefaultBGColor = "#1F2033"
constructor(minisrv_config, wtvclient) { constructor(minisrv_config, wtvclient) {
if (!minisrv_config) throw ("minisrv_config required"); if (!minisrv_config) throw ("minisrv_config required");
@@ -36,6 +38,12 @@ class WTVMail {
"Saved", "Saved",
this.trashMailboxName this.trashMailboxName
]; ];
this.defaultColors = {
bgcolor: "#171726",
text: "#82A9D9",
link: "#BDA73A",
vlink: "#62B362"
};
} }
checkMailIntroSeen() { checkMailIntroSeen() {
@@ -62,6 +70,31 @@ class WTVMail {
return null; return null;
} }
getSignatureColors(signature = null, sendmail = true) {
var colors = Object.assign({}, this.defaultColors); // start with default colors
if (sendmail) colors.bgcolor = this.sendmailDefaultBGColor;
if (signature) {
if (signature.length > 0) {
if (signature.indexOf('<html>') >= 0) {
if (signature.indexOf('<body') >= 0) {
// parse <body> tag of html signature to get colors
const htmlparser2 = require("htmlparser2");
const dom = htmlparser2.parseDocument(signature);
const body = htmlparser2.DomUtils.getElementsByTagName('body', dom)[0];
if (body.attribs) {
for (const [key, value] of Object.entries(body.attribs)) {
colors[key] = value;
}
}
}
}
}
}
if (!colors.cursor) colors.cursor = colors.link;
return colors;
}
mailboxExists(mailboxid) { mailboxExists(mailboxid) {
if (mailboxid > this.mailboxes.length) return null; if (mailboxid > this.mailboxes.length) return null;
var mailbox_dir = null; var mailbox_dir = null;