diff --git a/.gitignore b/.gitignore index 14e4361..f80343d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /node_modules /static/feeds/* !/static/feeds/.gitkeep +/static/alternate/* +!/static/alternate/.gitkeep diff --git a/index.ts b/index.ts index e47a370..83a9755 100644 --- a/index.ts +++ b/index.ts @@ -34,6 +34,7 @@ export const webServer = express() try { const { name } = req.body; const identifier = createIdentifier(); + await writeFileAtomic(alternatePath(identifier), created(identifier)); await writeFileAtomic(feedPath(identifier), feed(X(name), identifier)); res.send( layout(` @@ -61,10 +62,15 @@ export const emailServer = new SMTPServer({ async onData(stream, session, callback) { try { const email = await mailparser.simpleParser(stream); + const identifier = createIdentifier(); + const content = + typeof email.html === "string" ? email.html : email.textAsHtml ?? ""; + await writeFileAtomic(alternatePath(identifier), content); const newEntry = entry( X(email.subject ?? ""), X(email.from?.text ?? ""), - X(typeof email.html === "string" ? email.html : email.textAsHtml ?? "") + X(content), + identifier ); for (const { address } of session.envelope.rcptTo) { const match = address.match( @@ -154,7 +160,9 @@ function feed(name: string, identifier: string): string { - + ${urn(identifier)} ${name} Kill the Newsletter! Inbox: ${feedEmail( @@ -165,20 +173,28 @@ function feed(name: string, identifier: string): string { ${entry( `“${name}” Inbox Created`, "Kill the Newsletter!", - X(created(identifier)) + X(created(identifier)), + identifier )} `; } -function entry(title: string, author: string, content: string): string { +function entry( + title: string, + author: string, + content: string, + identifier: string +): string { return ` - ${urn(createIdentifier())} + ${urn(identifier)} ${title} ${author} ${now()} - + ${content} `.trim(); @@ -207,6 +223,14 @@ function feedEmail(identifier: string): string { return `${identifier}@${EMAIL_DOMAIN}`; } +function alternatePath(identifier: string): string { + return `static/alternate/${identifier}.html`; +} + +function alternateURL(identifier: string): string { + return `${BASE_URL}/alternate/${identifier}.html`; +} + function urn(identifier: string): string { return `urn:kill-the-newsletter:${identifier}`; } diff --git a/static/alternate/.gitkeep b/static/alternate/.gitkeep new file mode 100644 index 0000000..e69de29