Merge pull request #7 from LINUXexpert-org/message-theme-option

Let messages follow the app theme, at the user's choice
This commit is contained in:
LINUXexpert.org
2026-08-23 13:36:38 -07:00
committed by GitHub
6 changed files with 68 additions and 6 deletions
+19 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { sanitizeEmailHtml, sanitizeEditorHtml } from "../html";
import { htmlDeclaresColors, sanitizeEditorHtml, sanitizeEmailHtml } from "../html";
describe("sanitizeEmailHtml", () => {
it("removes scripts and event handlers", () => {
@@ -32,3 +32,21 @@ describe("sanitizeEmailHtml", () => {
expect(sanitizeEditorHtml("<b>x</b><script>1</script>")).toBe("<b>x</b>");
});
});
describe("htmlDeclaresColors", () => {
it("is false for mail that brings no colours", () => {
expect(htmlDeclaresColors("<p>Hi there</p>")).toBe(false);
expect(htmlDeclaresColors("<div><b>bold</b> and <i>italic</i></div>", "font-family:Arial")).toBe(false);
expect(htmlDeclaresColors('<a href="https://x.io/?color=red">link</a>')).toBe(false);
expect(htmlDeclaresColors('<div style="border-color: red">x</div>')).toBe(false);
});
it("is true when the message paints itself", () => {
expect(htmlDeclaresColors('<td bgcolor="#ffffff">x</td>')).toBe(true);
expect(htmlDeclaresColors('<font color="red">x</font>')).toBe(true);
expect(htmlDeclaresColors('<div style="color:#333">x</div>')).toBe(true);
expect(htmlDeclaresColors('<div style="background-color:#fff">x</div>')).toBe(true);
expect(htmlDeclaresColors("<style>p { color: red }</style><p>x</p>")).toBe(true);
expect(htmlDeclaresColors("<p>plain</p>", "background:#eee")).toBe(true);
});
});