From 50f9b473e04756a6cb176bdc74ccc4a9680840d8 Mon Sep 17 00:00:00 2001 From: Leandro Facchinetti Date: Mon, 23 Mar 2020 17:43:48 -0400 Subject: [PATCH] Use textAsHtml --- src/index.tsx | 14 ++++---------- src/test.ts | 13 +++++++++++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index fce115d..727a3be 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -72,9 +72,8 @@ export const emailServer = new SMTPServer({ const { entry } = Entry({ title: email.subject ?? "", author: email.from?.text ?? "", - ...(typeof email.html === "string" - ? { content: email.html } - : { html: false, content: email.text ?? "" }) + content: + typeof email.html === "string" ? email.html : email.textAsHtml ?? "" }); for (const { address } of session.envelope.rcptTo) { const match = address.match(/^(\w+)@kill-the-newsletter.com$/); @@ -246,13 +245,11 @@ function Feed({ name, identifier }: { name: string; identifier: string }) { function Entry({ title, author, - content, - html + content }: { title: string; author: string; content: string; - html?: boolean; }) { return { entry: { @@ -267,10 +264,7 @@ function Entry({ href: "https://www.kill-the-newsletter.com/entry" } }, - content: { - ...(html === false ? {} : { $: { type: "html" } }), - _: content - } + content: { $: { type: "html" }, _: content } } }; } diff --git a/src/test.ts b/src/test.ts index 60aa7af..4e0327b 100644 --- a/src/test.ts +++ b/src/test.ts @@ -36,6 +36,19 @@ describe("receive email", () => { expect(feed).toMatch("TEXT content"); }); + test("rich text content", async () => { + const identifier = await createFeed(); + await emailClient.sendMail({ + from: "publisher@example.com", + to: `${identifier}@kill-the-newsletter.com`, + subject: "New Message", + text: "TEXT content\n\nhttps://www.kill-the-newsletter.com\n\nMore text" + }); + const feed = await getFeed(identifier); + expect(feed).toMatch("TEXT content"); + expect(feed).toMatch(`href="https://www.kill-the-newsletter.com"`); + }); + test("missing content", async () => { const identifier = await createFeed(); await emailClient.sendMail({