Use textAsHtml

This commit is contained in:
Leandro Facchinetti 2020-03-23 17:43:48 -04:00
parent 169637d408
commit 50f9b473e0
2 changed files with 17 additions and 10 deletions

View File

@ -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 }
}
};
}

View File

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