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({