This commit is contained in:
parent
b6dabd2386
commit
d984e361f5
|
@ -39,35 +39,37 @@ export const webServer = express()
|
||||||
|
|
||||||
export const emailServer = new SMTPServer({
|
export const emailServer = new SMTPServer({
|
||||||
disabledCommands: ["AUTH", "STARTTLS"],
|
disabledCommands: ["AUTH", "STARTTLS"],
|
||||||
async onData(stream, session, callback) {
|
onData(stream, session, callback) {
|
||||||
const paths = session.envelope.rcptTo.flatMap(({ address }) => {
|
(async () => {
|
||||||
const match = address.match(/^(\w+)@kill-the-newsletter.com$/);
|
const paths = session.envelope.rcptTo.flatMap(({ address }) => {
|
||||||
if (match === null) return [];
|
const match = address.match(/^(\w+)@kill-the-newsletter.com$/);
|
||||||
const identifier = match[1];
|
if (match === null) return [];
|
||||||
const path = feedPath(identifier);
|
const identifier = match[1];
|
||||||
if (!fs.existsSync(path)) return [];
|
const path = feedPath(identifier);
|
||||||
return [path];
|
if (!fs.existsSync(path)) return [];
|
||||||
});
|
return [path];
|
||||||
if (paths.length === 0) return callback();
|
});
|
||||||
const email = await mailparser.simpleParser(stream);
|
if (paths.length === 0) return callback();
|
||||||
const { entry } = Entry({
|
const email = await mailparser.simpleParser(stream);
|
||||||
title: email.subject,
|
const { entry } = Entry({
|
||||||
author: email.from.text,
|
title: email.subject,
|
||||||
// FIXME: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/43234 / typeof email.html !== "boolean" => email.html !== false
|
author: email.from.text,
|
||||||
content: typeof email.html !== "boolean" ? email.html : email.textAsHtml
|
// FIXME: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/43234 / typeof email.html !== "boolean" => email.html !== false
|
||||||
});
|
content: typeof email.html !== "boolean" ? email.html : email.textAsHtml
|
||||||
for (const path of paths) {
|
});
|
||||||
const xml = await new xml2js.Parser().parseStringPromise(
|
for (const path of paths) {
|
||||||
fs.readFileSync(path, "utf8")
|
const xml = await new xml2js.Parser().parseStringPromise(
|
||||||
);
|
fs.readFileSync(path, "utf8")
|
||||||
xml.feed.updated = now();
|
);
|
||||||
if (xml.feed.entry === undefined) xml.feed.entry = [];
|
xml.feed.updated = now();
|
||||||
xml.feed.entry.unshift(entry);
|
if (xml.feed.entry === undefined) xml.feed.entry = [];
|
||||||
while (xml.feed.entry.length > 0 && renderXML(xml).length > 500_000)
|
xml.feed.entry.unshift(entry);
|
||||||
xml.feed.entry.pop();
|
while (xml.feed.entry.length > 0 && renderXML(xml).length > 500_000)
|
||||||
fs.writeFileSync(path, renderXML(xml));
|
xml.feed.entry.pop();
|
||||||
}
|
fs.writeFileSync(path, renderXML(xml));
|
||||||
callback();
|
}
|
||||||
|
callback();
|
||||||
|
})().catch(callback);
|
||||||
}
|
}
|
||||||
}).listen(process.env.NODE_ENV === "production" ? 25 : 2525);
|
}).listen(process.env.NODE_ENV === "production" ? 25 : 2525);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue