- numerous bug fixes
 - wtv-news goodies, ready for local testing
   - custom patched nntp-server node module with support for POSTing
   - should be able to post locally
   - 4 groups are made by default
   - can override in user_config.json (look at the config.json changes but dont do them there)
   - can sync down from an upstream server with sync_nntp.js
   - sync does not push new posts to upstream yet
This commit is contained in:
zefie
2022-10-11 21:44:18 -04:00
parent 1165b245ce
commit b89e0e932c
181 changed files with 4333 additions and 688 deletions

View File

@@ -11,7 +11,7 @@ class WTVMime {
constructor(minisrv_config) {
var WTVShared = require("./WTVShared.js")['WTVShared'];
const { WTVShared } = require("./WTVShared.js");
this.minisrv_config = minisrv_config;
this.wtvshared = new WTVShared(minisrv_config);
if (!String.prototype.reverse) {
@@ -199,6 +199,67 @@ class WTVMime {
return new Array(wtv_mime_type, modern_mime_type);
}
// modified from https://github.com/sergi/mime-multipart/blob/master/index.js
generateMultipartMIME(tuples, options) {
// modified for creating usenet compliant headers/content from an attachment
var CRLF = '\n';
if (tuples.length === 0) {
// according to rfc1341 there should be at least one encapsulation
throw new Error('Missing argument. At least one part to generate is required');
}
options = options || {};
var preamble = options.preamble || "This is a multi-part message in MIME format.";
var epilogue = options.epilogue;
var boundary = options.boundary || "------------" + this.wtvshared.generateString(24);
if (boundary.length < 1 || boundary.length > 70) {
throw new Error('Boundary should be between 1 and 70 characters long');
}
var boundary_header = 'multipart/mixed; boundary="' + boundary + '"';
var delimiter = CRLF + '--' + boundary;
var closeDelimiter = delimiter + '--';
var wtvshared = this.wtvshared;
var encapsulations = tuples.map(function (tuple, i) {
var mimetype = tuple.mime || 'text/plain';
var encoding = tuple.encoding || 'utf-8';
var use_base64 = tuple.use_base64 || !wtvshared.isASCII(tuple.content);
var is_base64 = tuple.is_base64 || wtvshared.isBase64(tuple.content);
var filename = (tuple.filename) ? tuple.filename : (use_base64) ? ('file' + i) : null;
var headers = [
`Content-Type: ${mimetype}; ${(use_base64) ? `name="${filename}"` : `charset=${encoding.toUpperCase()}; format=flowed`}`,
];
if (filename) headers.push(`Content-Disposition: attachment; filename="${filename}"`);
headers.push(`Content-Transfer-Encoding: ${(use_base64) ? 'base64' : '7bit'}`);
var bodyPart = headers.join(CRLF) + CRLF + CRLF;
if (use_base64 && !is_base64) bodyPart += wtvshared.lineWrap(Buffer.from(tuple.content).toString('base64'),72) + CRLF;
else bodyPart += wtvshared.lineWrap(tuple.content,72);
return delimiter + CRLF + bodyPart;
});
var multipartBody = [
preamble ? preamble : undefined,
encapsulations.join(''),
closeDelimiter,
epilogue ? CRLF + epilogue : undefined,
].filter(function (element) { return !!element; });
return {
"mime_version": "1.0",
"content_type": boundary_header,
"content": multipartBody.join('')
};
}
}
module.exports = WTVMime;