Use textAsHtml
This commit is contained in:
parent
169637d408
commit
50f9b473e0
|
@ -72,9 +72,8 @@ export const emailServer = new SMTPServer({
|
||||||
const { entry } = Entry({
|
const { entry } = Entry({
|
||||||
title: email.subject ?? "",
|
title: email.subject ?? "",
|
||||||
author: email.from?.text ?? "",
|
author: email.from?.text ?? "",
|
||||||
...(typeof email.html === "string"
|
content:
|
||||||
? { content: email.html }
|
typeof email.html === "string" ? email.html : email.textAsHtml ?? ""
|
||||||
: { html: false, content: email.text ?? "" })
|
|
||||||
});
|
});
|
||||||
for (const { address } of session.envelope.rcptTo) {
|
for (const { address } of session.envelope.rcptTo) {
|
||||||
const match = address.match(/^(\w+)@kill-the-newsletter.com$/);
|
const match = address.match(/^(\w+)@kill-the-newsletter.com$/);
|
||||||
|
@ -246,13 +245,11 @@ function Feed({ name, identifier }: { name: string; identifier: string }) {
|
||||||
function Entry({
|
function Entry({
|
||||||
title,
|
title,
|
||||||
author,
|
author,
|
||||||
content,
|
content
|
||||||
html
|
|
||||||
}: {
|
}: {
|
||||||
title: string;
|
title: string;
|
||||||
author: string;
|
author: string;
|
||||||
content: string;
|
content: string;
|
||||||
html?: boolean;
|
|
||||||
}) {
|
}) {
|
||||||
return {
|
return {
|
||||||
entry: {
|
entry: {
|
||||||
|
@ -267,10 +264,7 @@ function Entry({
|
||||||
href: "https://www.kill-the-newsletter.com/entry"
|
href: "https://www.kill-the-newsletter.com/entry"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
content: {
|
content: { $: { type: "html" }, _: content }
|
||||||
...(html === false ? {} : { $: { type: "html" } }),
|
|
||||||
_: content
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
13
src/test.ts
13
src/test.ts
|
@ -36,6 +36,19 @@ describe("receive email", () => {
|
||||||
expect(feed).toMatch("TEXT content");
|
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 () => {
|
test("missing content", async () => {
|
||||||
const identifier = await createFeed();
|
const identifier = await createFeed();
|
||||||
await emailClient.sendMail({
|
await emailClient.sendMail({
|
||||||
|
|
Loading…
Reference in New Issue