enable html mail and usenet bodies

- also move subject for usenet
This commit is contained in:
zefie
2022-11-30 13:33:10 -05:00
parent bb60066100
commit 0bdc16b0cb
3 changed files with 40 additions and 10 deletions

View File

@@ -39,7 +39,16 @@ Location: wtv-mail:/listmail`;
headers = `200 OK headers = `200 OK
Content-type: text/html`; Content-type: text/html`;
var message_colors = session_data.mailstore.getSignatureColors(message.signature);
var message_colors = null;
if (message.body.indexOf("<body")) {
var default_colors = session_data.mailstore.defaultColors;
var message_colors = session_data.mailstore.getSignatureColors(message.body);
if (message_colors == default_colors) message_colors = null;
}
if (!message_colors) message_colors = session_data.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>
@@ -275,7 +284,10 @@ ${(message.subject) ? wtvshared.htmlEntitize(message.subject) : '(No subject)'}
message.body = wtvshared.decodeBufferText(message.body); message.body = wtvshared.decodeBufferText(message.body);
} }
if (message.body) message.body = message.body.replace(/\n/g, "<br><br>"); if (message.body) message.body = message.body.replace(/\n/g, "<br><br>");
data += `${(message.allow_html) ? message.body : wtvshared.htmlEntitize(message.body, true)} if (message.body.indexOf("<html>") >= 0) {
message.allow_html = true;
}
data += `${(message.allow_html) ? wtvshared.sanitizeSignature(message.body) : wtvshared.htmlEntitize(message.body, true)}
<br> <br>
<br>`; <br>`;
if (message.signature) { if (message.signature) {
@@ -283,6 +295,7 @@ ${(message.subject) ? wtvshared.htmlEntitize(message.subject) : '(No subject)'}
} }
data += `<p> data += `<p>
`; `;
console.log(message.body);
console.log(message.allow_html) console.log(message.allow_html)
if (Array.isArray(message.attachments)) { if (Array.isArray(message.attachments)) {
message.attachments.forEach((v, k) => { message.attachments.forEach((v, k) => {

View File

@@ -347,6 +347,14 @@ wtv-expire-all: wtv-news:/news?group=${group}&article=`;
if (signature_index) attachments.splice(signature_index, 1); if (signature_index) attachments.splice(signature_index, 1);
} }
} }
if (message_body.indexOf("<body")) {
var default_colors = session_data.mailstore.defaultColors;
var message_colors = session_data.mailstore.getSignatureColors(message_body);
if ((message_colors == default_colors) && signature) message_colors = null;
}
if (!message_colors && signature) message_colors = session_data.mailstore.getSignatureColors(signature);
if (signature) message_colors = session_data.mailstore.getSignatureColors(signature); if (signature) message_colors = session_data.mailstore.getSignatureColors(signature);
data = `<head> data = `<head>
@@ -580,7 +588,6 @@ ${wtvshared.htmlEntitize(response.article.headers.NEWSGROUPS)}
<td valign=top> <td valign=top>
Date: <td> Date: <td>
${strftime("%a, %b %e, %Y, %I:%M%P", new Date(Date.parse(response.article.headers.DATE)))} ${strftime("%a, %b %e, %Y, %I:%M%P", new Date(Date.parse(response.article.headers.DATE)))}
<font size=-1> </font>
<tr> <tr>
<td valign=top> <td valign=top>
From: From:
@@ -594,19 +601,26 @@ From:
data += `<tr> data += `<tr>
<td nowrap valign=top> <td nowrap valign=top>
<td> <td>
<tr>
<td valign=top>Subject:
<td>${(response.article.headers.SUBJECT) ? wtvshared.htmlEntitize(response.article.headers.SUBJECT) : '(No subject)'}
</table> </table>
<br><br>
<table cellspacing=0 cellpadding=0> <table cellspacing=0 cellpadding=0>
<tr> <tr>
<td abswidth=10 rowspan=99> <td abswidth=10 rowspan=99>
<td><br><br><br><font color=E7CE4A>
${(response.article.headers.SUBJECT) ? wtvshared.htmlEntitize(response.article.headers.SUBJECT) : '(No subject)'}<br><br>
</font>
<td abswidth=20 rowspan=99>
<tr> <tr>
<td> <td>
` `;
var allow_html = false;
if (message_body) {
if (message_body.indexOf("<html>") >= 0) {
allow_html = true;
}
}
data += (allow_html) ? wtvshared.sanitizeSignature(message_body) : wtvshared.htmlEntitize(message_body, true)
data += ` data += `
${wtvshared.htmlEntitize(message_body, true)}
<br> <br>
<br>`; <br>`;
if (signature) data += wtvshared.sanitizeSignature(signature); if (signature) data += wtvshared.sanitizeSignature(signature);

View File

@@ -250,6 +250,7 @@ class WTVShared {
allowedProtocols.push(k); allowedProtocols.push(k);
} }
}); });
console.log(allowedProtocols);
const clean = this.sanitizeHtml(string, { const clean = this.sanitizeHtml(string, {
allowedTags: ['a', 'audioscope', 'b', 'bgsound', 'big', 'blackface', 'blockquote', 'bq', 'br', 'caption', 'center', 'cite', 'c', 'dd', 'dfn', 'div', 'dl', 'dt', 'fn', 'font', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'html', 'i', 'img', 'label', 'li', 'link', 'listing', 'em', 'marquee', 'nobr', 'note', 'ol', 'p', 'plaintext', 'pre', 's', 'samp', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'tbody', 'table', 'td', 'th', 'tr', 'tt', 'u', 'ul'], allowedTags: ['a', 'audioscope', 'b', 'bgsound', 'big', 'blackface', 'blockquote', 'bq', 'br', 'caption', 'center', 'cite', 'c', 'dd', 'dfn', 'div', 'dl', 'dt', 'fn', 'font', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'html', 'i', 'img', 'label', 'li', 'link', 'listing', 'em', 'marquee', 'nobr', 'note', 'ol', 'p', 'plaintext', 'pre', 's', 'samp', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'tbody', 'table', 'td', 'th', 'tr', 'tt', 'u', 'ul'],
@@ -265,13 +266,15 @@ class WTVShared {
allowedSchemesByTag: {}, allowedSchemesByTag: {},
allowedSchemesAppliedToAttributes: ['href', 'src', 'cite'], allowedSchemesAppliedToAttributes: ['href', 'src', 'cite'],
exclusiveFilter: function (frame) { exclusiveFilter: function (frame) {
var allowed = false; var allowed = true;
Object.keys(frame.attribs).forEach((k) => { Object.keys(frame.attribs).forEach((k) => {
if (k == "href" || k == "background" || k == "src") { if (k == "href" || k == "background" || k == "src") {
var allowed = false;
var value = frame.attribs[k]; var value = frame.attribs[k];
Object.keys(allowedProtocols).forEach((j) => { Object.keys(allowedProtocols).forEach((j) => {
if (value.startsWith(allowedProtocols[j])) { if (value.startsWith(allowedProtocols[j])) {
allowed = true; allowed = true;
return false;
} }
}) })
} }