A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
feat(email): add mjml layouts and an html email renderer
Hampus60f523d2692e
diff --git a/fluxer_api/pkgs/email/package.json b/fluxer_api/pkgs/email/package.jsonindex 85bed12f3..9e3d1f528 100644--- a/fluxer_api/pkgs/email/package.json+++ b/fluxer_api/pkgs/email/package.json@@ -7,6 +7,8 @@"./*": "./*"},"scripts": {+ "html:compile": "tsx scripts/CompileEmailHtml.ts",+ "preview": "tsx scripts/RenderEmailPreviews.ts","test": "vitest run","test:watch": "vitest","typecheck": "tsc --noEmit"@@ -15,11 +17,17 @@"@fluxer/constants": "workspace:*","@fluxer/i18n": "workspace:*","@fluxer/logger": "workspace:*",+ "@fluxer/number_utils": "workspace:*","itty-time": "catalog:",- "nodemailer": "catalog:"+ "nodemailer": "catalog:",+ "pdf-lib": "catalog:"},"devDependencies": {"@types/node": "catalog:",+ "mjml-core": "catalog:",+ "mjml-preset-core": "catalog:",+ "mjml-validator": "catalog:",+ "tsx": "catalog:","typescript": "catalog:ts7","vitest": "catalog:"}diff --git a/fluxer_api/pkgs/email/scripts/CompileEmailHtml.ts b/fluxer_api/pkgs/email/scripts/CompileEmailHtml.tsnew file mode 100644index 000000000..48af185f7--- /dev/null+++ b/fluxer_api/pkgs/email/scripts/CompileEmailHtml.ts@@ -0,0 +1,178 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import * as fs from 'node:fs';+import {createRequire} from 'node:module';+import * as path from 'node:path';+import {fileURLToPath} from 'node:url';++interface MjmlError {+ formattedMessage: string;+}++interface MjmlResult {+ html: string;+ errors: Array<MjmlError>;+}++type Mjml2Html = (input: string, options: Record<string, unknown>) => Promise<MjmlResult>;++interface MjmlCoreModule {+ default: Mjml2Html;+ components: Record<string, unknown>;+ assignComponents(target: Record<string, unknown>, source: Array<unknown>): void;+}++interface MjmlValidatorModule {+ dependencies: Record<string, unknown>;+ assignDependencies(target: Record<string, unknown>, source: Record<string, unknown>): void;+}++interface MjmlPreset {+ components: Array<unknown>;+ dependencies: Record<string, unknown>;+}++const require = createRequire(import.meta.url);+const mjmlCore = require('mjml-core') as MjmlCoreModule;+const mjmlValidator = require('mjml-validator') as MjmlValidatorModule;+const presetCore = require('mjml-preset-core') as MjmlPreset;+mjmlCore.assignComponents(mjmlCore.components, presetCore.components);+mjmlValidator.assignDependencies(mjmlValidator.dependencies, presetCore.dependencies);++const __dirname = path.dirname(fileURLToPath(import.meta.url));+const PACKAGE_ROOT = path.resolve(__dirname, '..');+const LAYOUTS_DIR = path.join(PACKAGE_ROOT, 'src/email_html/layouts');+const OUTPUT_FILE = path.join(PACKAGE_ROOT, 'src/email_html/EmailHtmlLayouts.generated.ts');+const GENERATED_HEADER = '// SPDX-License-Identifier: AGPL-3.0-or-later\n\n';+const INCLUDE_PATTERN = /<mj-include path="\.\/partials\/([a-z-]+)\.mjml"((?:\s+[a-z_]+="[a-z0-9_#-]*")*)\s*\/>/g;+const INCLUDE_PARAM_PATTERN = /([a-z_]+)="([a-z0-9_#-]*)"/g;+const SLOT_PATTERN = /%%([a-z0-9_]+)%%/g;+const BLOCK_MARKER_PATTERN = /%%([?/])([a-z0-9_]+)%%/g;+const MAX_STYLE_BYTES = 16_000;++type Direction = 'ltr' | 'rtl';++const FONT_TOKENS: Record<string, string> = {+ font: "-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif",+ mono: "ui-monospace,SFMono-Regular,Menlo,Consolas,'Liberation Mono',monospace",+};++const DIRECTION_TOKENS: Record<Direction, Record<string, string>> = {+ ltr: {dir: 'ltr', start: 'left'},+ rtl: {dir: 'rtl', start: 'right'},+};++function resolveIncludes(source: string, depth = 0): string {+ if (depth > 4) {+ throw new Error('email layout includes nest too deeply');+ }+ return source.replace(INCLUDE_PATTERN, (_match, name: string, params: string) => {+ let partial = fs.readFileSync(path.join(LAYOUTS_DIR, 'partials', `${name}.mjml`), 'utf8');+ for (const [, key, value] of params.matchAll(INCLUDE_PARAM_PATTERN)) {+ partial = partial.replaceAll(`[[${key}]]`, value);+ }+ return resolveIncludes(partial, depth + 1);+ });+}++function applyDirection(source: string, direction: Direction): string {+ const tokens = {...FONT_TOKENS, ...DIRECTION_TOKENS[direction]};+ return source.replace(/\[\[([a-z_]+)\]\]/g, (match, name: string) => {+ const value = tokens[name];+ if (value === undefined) {+ throw new Error(`unknown layout token ${match}`);+ }+ return value;+ });+}++function assertStyleBudget(name: string, html: string): void {+ for (const match of html.matchAll(/<style[^>]*>([\s\S]*?)<\/style>/g)) {+ const bytes = Buffer.byteLength(match[1], 'utf8');+ if (bytes > MAX_STYLE_BYTES) {+ throw new Error(`${name} has a <style> block of ${bytes} bytes, over the Gmail budget`);+ }+ if (match[1].includes('/*')) {+ throw new Error(`${name} has a CSS comment, which Gmail treats as a parse error`);+ }+ }+}++async function compileLayout(name: string, direction: Direction): Promise<string> {+ const source = applyDirection(+ resolveIncludes(fs.readFileSync(path.join(LAYOUTS_DIR, `${name}.mjml`), 'utf8')),+ direction,+ );+ const result = await mjmlCore.default(source, {+ validationLevel: 'strict',+ minify: true,+ keepComments: false,+ fonts: {},+ filePath: LAYOUTS_DIR,+ ignoreIncludes: true,+ });+ if (result.errors.length > 0) {+ throw new Error(+ `${name} (${direction}) failed MJML validation:\n${result.errors.map((error) => error.formattedMessage).join('\n')}`,+ );+ }+ const html = result.html.trim();+ if (html.includes('[[')) {+ throw new Error(`${name} (${direction}) has an unresolved layout token`);+ }+ if (!html.includes('mso-padding-alt:12px 22px')) {+ throw new Error(`${name} (${direction}) lost its Outlook button padding`);+ }+ assertStyleBudget(`${name} (${direction})`, html);+ assertBlocks(`${name} (${direction})`, html);+ return html;+}++function assertBlocks(name: string, html: string): void {+ const open: Array<string> = [];+ for (const [, kind, slot] of html.matchAll(BLOCK_MARKER_PATTERN)) {+ if (kind === '?') {+ if (open.includes(slot)) {+ throw new Error(`${name} opens the block ${slot} twice`);+ }+ open.push(slot);+ } else if (open.pop() !== slot) {+ throw new Error(`${name} closes the block ${slot} out of order`);+ }+ }+ if (open.length > 0) {+ throw new Error(`${name} leaves the block ${open.join(', ')} open`);+ }+ if (/="[^"]*%%[?/][a-z0-9_]+%%/.test(html)) {+ throw new Error(`${name} has a block marker inside an attribute`);+ }+}++function collectSlots(html: string): Array<string> {+ return [...new Set([...html.matchAll(SLOT_PATTERN)].map((match) => match[1]))].sort();+}++async function main(): Promise<void> {+ const names = fs+ .readdirSync(LAYOUTS_DIR)+ .filter((file) => file.endsWith('.mjml'))+ .map((file) => file.slice(0, -'.mjml'.length))+ .sort();+ const entries: Array<string> = [];+ for (const name of names) {+ const ltr = await compileLayout(name, 'ltr');+ const rtl = await compileLayout(name, 'rtl');+ const slots = collectSlots(ltr);+ if (JSON.stringify(slots) !== JSON.stringify(collectSlots(rtl))) {+ throw new Error(`${name} has different slots in its ltr and rtl variants`);+ }+ entries.push(+ `\t${name}: {\n\t\tslots: ${JSON.stringify(slots)},\n\t\tltr: ${JSON.stringify(ltr)},\n\t\trtl: ${JSON.stringify(rtl)},\n\t},`,+ );+ }+ const content = `${GENERATED_HEADER}export const EMAIL_HTML_LAYOUTS = {\n${entries.join('\n')}\n} as const;\n`;+ fs.writeFileSync(OUTPUT_FILE, content, 'utf8');+ console.log(`compiled ${names.length} email layouts -> ${path.relative(PACKAGE_ROOT, OUTPUT_FILE)}`);+}++await main();diff --git a/fluxer_api/pkgs/email/src/email_html/EmailHtmlLayouts.generated.ts b/fluxer_api/pkgs/email/src/email_html/EmailHtmlLayouts.generated.tsnew file mode 100644index 000000000..f67307ca8--- /dev/null+++ b/fluxer_api/pkgs/email/src/email_html/EmailHtmlLayouts.generated.ts@@ -0,0 +1,9 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++export const EMAIL_HTML_LAYOUTS = {+ message: {+ slots: ["code","cta","cta_url","end_link","end_link_url","expiry","fact_1_label","fact_1_link","fact_1_link_url","fact_1_value","fact_2_label","fact_2_link","fact_2_link_url","fact_2_value","fact_3_label","fact_3_link","fact_3_link_url","fact_3_value","fact_4_label","fact_4_link","fact_4_link_url","fact_4_value","fact_5_label","fact_5_link","fact_5_link_url","fact_5_value","fact_6_label","fact_6_link","fact_6_link_url","fact_6_value","fact_7_label","fact_7_link","fact_7_link_url","fact_7_value","footer_reason","home_url","intro","lang","lead","legal_address","logo_dark_url","logo_url","note","points_list","preheader","product_name","section_1_body","section_1_link","section_1_link_url","section_1_list","section_1_note","section_1_title","section_2_body","section_2_link","section_2_link_url","section_2_list","section_2_note","section_2_title","section_3_body","section_3_link","section_3_link_url","section_3_list","section_3_note","section_3_title","section_4_body","section_4_link","section_4_link_url","section_4_list","section_4_note","section_4_title","signoff","subject","text_1","text_2","unsubscribe","unsubscribe_url","wordmark"],+ ltr: "<!doctype html><html lang=\"%%lang%%\" dir=\"ltr\" xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\"><head><title>%%subject%%</title><!--[if !mso]><!--><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"><!--<![endif]--><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><style type=\"text/css\">#outlook a{padding:0}body{margin:0;padding:0;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}table, td{border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt}img{border:0;height:auto;line-height:100%;outline:none;text-decoration:none;-ms-interpolation-mode:bicubic}p{display:block;margin:13px 0}</style><!--[if mso]>\n <noscript>\n <xml>\n <o:OfficeDocumentSettings>\n <o:AllowPNG/>\n <o:PixelsPerInch>96</o:PixelsPerInch>\n </o:OfficeDocumentSettings>\n </xml>\n </noscript>\n <![endif]--><!--[if lte mso 11]>\n <style type=\"text/css\">\n .mj-outlook-group-fix { width:100% !important; }\n </style>\n <![endif]--><style type=\"text/css\">@media only screen and (min-width:480px){.mj-column-per-100{width:100%!important;max-width:100%}}</style><style media=\"screen and (min-width:480px)\">.moz-text-html .mj-column-per-100{width:100%!important;max-width:100%}</style><style type=\"text/css\">:root{color-scheme:light dark;supported-color-schemes:light dark}body{margin:0;padding:0;word-spacing:normal;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}a{text-decoration:underline}.x-btn{text-decoration:none!important}@media only screen and (max-width: 480px){.x-pad > table > tbody > tr > td{padding-left:16px!important;padding-right:16px!important}}@media (prefers-color-scheme: dark){.x-page, .x-page > [role=\"article\"]{background-color:#121218!important}.x-ink{color:#ececf3!important}.x-muted{color:#a9a8bd!important}.x-link{color:#b8b5ff!important}.x-rule{border-color:#34334a!important}.x-light{display:none!important}.x-dark{display:block!important;max-height:none!important;overflow:visible!important}}[data-ogsb] .x-page, [data-ogsb] .x-page > [role=\"article\"]{background-color:#121218!important}[data-ogsc] .x-ink{color:#ececf3!important}[data-ogsc] .x-muted{color:#a9a8bd!important}[data-ogsc] .x-link{color:#b8b5ff!important}[data-ogsc] .x-light{display:none!important}[data-ogsc] .x-dark{display:block!important;max-height:none!important;overflow:visible!important}</style><meta name=\"color-scheme\" content=\"light dark\"><meta name=\"supported-color-schemes\" content=\"light dark\"><meta name=\"format-detection\" content=\"telephone=no, date=no, address=no, email=no, url=no\"><meta name=\"x-apple-disable-message-reformatting\"></head><body class=\"x-page\" style=\"word-spacing:normal;background-color:#ffffff\"> <div style=\"display:none;font-size:1px;color:#ffffff;line-height:1px;max-height:0px;max-width:0px;opacity:0;overflow:hidden\">%%preheader%%͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ </div> <div aria-label=\"%%subject%%\" aria-roledescription=\"email\" role=\"article\" lang=\"%%lang%%\" dir=\"ltr\" style=\"word-spacing:normal;background-color:#ffffff\"> <!--[if mso | IE]><table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"x-pad-outlook\" role=\"presentation\" style=\"width:600px;\" width=\"600\" ><tr><td style=\"line-height:0px;font-size:0px;mso-line-height-rule:exactly;\"><![endif]--> <div class=\"x-pad\" style=\"margin:0px auto;max-width:600px\"> <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"width:100%\"> <tbody> <tr> <td style=\"direction:ltr;font-size:0px;padding:32px 24px 0;text-align:left\"> <!--[if mso | IE]><table role=\"presentation\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"\" style=\"vertical-align:top;width:552px;\" ><![endif]--> <div class=\"mj-column-per-100 mj-outlook-group-fix\" style=\"font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%\"> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\"> <tbody> <tr> <td style=\"vertical-align:top;padding:0\"> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\"> <tbody> <tr> <td dir=\"ltr\" style=\"padding:0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;text-align:left;direction:ltr\"> %%?logo_url%%<a href=\"%%home_url%%\" target=\"_blank\" class=\"x-light\" style=\"display:inline-block;text-decoration:none\"><img src=\"%%logo_url%%\" width=\"92\" height=\"24\" alt=\"%%product_name%%\" style=\"display:block;width:92px;height:24px;border:0;font-size:18px;line-height:24px;font-weight:700;color:#4641d9\"></a><!--[if !mso]><!--><div class=\"x-dark\" style=\"display:none;max-height:0;overflow:hidden;mso-hide:all\"><a href=\"%%home_url%%\" target=\"_blank\" style=\"display:inline-block;text-decoration:none\"><img src=\"%%logo_dark_url%%\" width=\"92\" height=\"24\" alt=\"%%product_name%%\" style=\"display:block;width:92px;height:24px;border:0;font-size:18px;line-height:24px;font-weight:700;color:#ffffff\"></a></div><!--<![endif]-->%%/logo_url%% %%?wordmark%%<a href=\"%%home_url%%\" target=\"_blank\" class=\"x-ink\" style=\"font-size:18px;line-height:24px;font-weight:700;color:#1b1a2e;text-decoration:none\">%%wordmark%%</a>%%/wordmark%% </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </div> <!--[if mso | IE]></td></tr></table><![endif]--> </td> </tr> </tbody> </table> </div> <!--[if mso | IE]></td></tr></table><table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"x-pad-outlook\" role=\"presentation\" style=\"width:600px;\" width=\"600\" ><tr><td style=\"line-height:0px;font-size:0px;mso-line-height-rule:exactly;\"><![endif]--> <div class=\"x-pad\" style=\"margin:0px auto;max-width:600px\"> <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"width:100%\"> <tbody> <tr> <td style=\"direction:ltr;font-size:0px;padding:20px 24px 0;text-align:left\"> <!--[if mso | IE]><table role=\"presentation\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"\" style=\"vertical-align:top;width:552px;\" ><![endif]--> <div class=\"mj-column-per-100 mj-outlook-group-fix\" style=\"font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%\"> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\"> <tbody> <tr> <td style=\"vertical-align:top;padding:0\"> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\"> <tbody> <tr> <td style=\"padding:0\"> <table role=\"presentation\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" dir=\"ltr\" style=\"width:100%;border-collapse:collapse;direction:ltr;text-align:left\"> <tr> <td dir=\"ltr\" class=\"x-ink\" style=\"padding:0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:left;direction:ltr;overflow-wrap:anywhere;word-break:break-word\">%%intro%%</td> </tr> %%?code%%<tr> <td dir=\"ltr\" class=\"x-ink\" style=\"padding:16px 0 0;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,'Liberation Mono',monospace;font-size:28px;line-height:36px;font-weight:700;letter-spacing:3px;color:#1b1a2e;text-align:left;white-space:nowrap\">%%code%%</td> </tr>%%/code%% %%?fact_1_label%%<tr> <td dir=\"ltr\" class=\"x-fact x-ink\" style=\"padding:16px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:left;direction:ltr;overflow-wrap:anywhere;word-break:break-word\"><span class=\"x-muted\" style=\"color:#5b5a70\">%%fact_1_label%%:</span> %%?fact_1_value%%<span dir=\"auto\">%%fact_1_value%%</span>%%/fact_1_value%%%%?fact_1_link%%<a href=\"%%fact_1_link_url%%\" class=\"x-link\" dir=\"auto\" style=\"color:#4641d9\">%%fact_1_link%%</a>%%/fact_1_link%%</td> </tr>%%/fact_1_label%% %%?fact_2_label%%<tr> <td dir=\"ltr\" class=\"x-fact x-ink\" style=\"padding:4px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:left;direction:ltr;overflow-wrap:anywhere;word-break:break-word\"><span class=\"x-muted\" style=\"color:#5b5a70\">%%fact_2_label%%:</span> %%?fact_2_value%%<span dir=\"auto\">%%fact_2_value%%</span>%%/fact_2_value%%%%?fact_2_link%%<a href=\"%%fact_2_link_url%%\" class=\"x-link\" dir=\"auto\" style=\"color:#4641d9\">%%fact_2_link%%</a>%%/fact_2_link%%</td> </tr>%%/fact_2_label%% %%?fact_3_label%%<tr> <td dir=\"ltr\" class=\"x-fact x-ink\" style=\"padding:4px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:left;direction:ltr;overflow-wrap:anywhere;word-break:break-word\"><span class=\"x-muted\" style=\"color:#5b5a70\">%%fact_3_label%%:</span> %%?fact_3_value%%<span dir=\"auto\">%%fact_3_value%%</span>%%/fact_3_value%%%%?fact_3_link%%<a href=\"%%fact_3_link_url%%\" class=\"x-link\" dir=\"auto\" style=\"color:#4641d9\">%%fact_3_link%%</a>%%/fact_3_link%%</td> </tr>%%/fact_3_label%% %%?fact_4_label%%<tr> <td dir=\"ltr\" class=\"x-fact x-ink\" style=\"padding:4px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:left;direction:ltr;overflow-wrap:anywhere;word-break:break-word\"><span class=\"x-muted\" style=\"color:#5b5a70\">%%fact_4_label%%:</span> %%?fact_4_value%%<span dir=\"auto\">%%fact_4_value%%</span>%%/fact_4_value%%%%?fact_4_link%%<a href=\"%%fact_4_link_url%%\" class=\"x-link\" dir=\"auto\" style=\"color:#4641d9\">%%fact_4_link%%</a>%%/fact_4_link%%</td> </tr>%%/fact_4_label%% %%?fact_5_label%%<tr> <td dir=\"ltr\" class=\"x-fact x-ink\" style=\"padding:4px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:left;direction:ltr;overflow-wrap:anywhere;word-break:break-word\"><span class=\"x-muted\" style=\"color:#5b5a70\">%%fact_5_label%%:</span> %%?fact_5_value%%<span dir=\"auto\">%%fact_5_value%%</span>%%/fact_5_value%%%%?fact_5_link%%<a href=\"%%fact_5_link_url%%\" class=\"x-link\" dir=\"auto\" style=\"color:#4641d9\">%%fact_5_link%%</a>%%/fact_5_link%%</td> </tr>%%/fact_5_label%% %%?fact_6_label%%<tr> <td dir=\"ltr\" class=\"x-fact x-ink\" style=\"padding:4px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:left;direction:ltr;overflow-wrap:anywhere;word-break:break-word\"><span class=\"x-muted\" style=\"color:#5b5a70\">%%fact_6_label%%:</span> %%?fact_6_value%%<span dir=\"auto\">%%fact_6_value%%</span>%%/fact_6_value%%%%?fact_6_link%%<a href=\"%%fact_6_link_url%%\" class=\"x-link\" dir=\"auto\" style=\"color:#4641d9\">%%fact_6_link%%</a>%%/fact_6_link%%</td> </tr>%%/fact_6_label%% %%?fact_7_label%%<tr> <td dir=\"ltr\" class=\"x-fact x-ink\" style=\"padding:4px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:left;direction:ltr;overflow-wrap:anywhere;word-break:break-word\"><span class=\"x-muted\" style=\"color:#5b5a70\">%%fact_7_label%%:</span> %%?fact_7_value%%<span dir=\"auto\">%%fact_7_value%%</span>%%/fact_7_value%%%%?fact_7_link%%<a href=\"%%fact_7_link_url%%\" class=\"x-link\" dir=\"auto\" style=\"color:#4641d9\">%%fact_7_link%%</a>%%/fact_7_link%%</td> </tr>%%/fact_7_label%% %%?points_list%%<tr> <td dir=\"ltr\" class=\"x-ink\" style=\"padding:16px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:left;direction:ltr;overflow-wrap:anywhere;word-break:break-word\"> <ul dir=\"auto\" style=\"margin:0;padding-left:20px;text-align:start\">%%points_list%%</ul> </td> </tr>%%/points_list%% %%?lead%%<tr> <td dir=\"ltr\" class=\"x-ink\" style=\"padding:16px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:left;direction:ltr;overflow-wrap:anywhere;word-break:break-word\">%%lead%%</td> </tr>%%/lead%% %%?cta%%<tr> <td align=\"left\" style=\"padding:24px 0 0\"> <table role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"left\" style=\"border-collapse:separate\"> <tr> <td align=\"center\" bgcolor=\"#4641d9\" style=\"border-radius:6px;background-color:#4641d9;mso-padding-alt:12px 22px\"> <a href=\"%%cta_url%%\" target=\"_blank\" class=\"x-btn\" style=\"display:inline-block;padding:12px 22px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:22px;font-weight:600;color:#ffffff;text-decoration:none;border-radius:6px\">%%cta%%</a> </td> </tr> </table> </td> </tr>%%/cta%% %%?expiry%%<tr> <td dir=\"ltr\" class=\"x-muted\" style=\"padding:12px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:14px;line-height:21px;color:#5b5a70;text-align:left;direction:ltr;overflow-wrap:anywhere;word-break:break-word\">%%expiry%%</td> </tr>%%/expiry%% %%?text_1%%<tr> <td dir=\"ltr\" class=\"x-ink\" style=\"padding:16px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:left;direction:ltr;overflow-wrap:anywhere;word-break:break-word\">%%text_1%%</td> </tr>%%/text_1%% %%?text_2%%<tr> <td dir=\"ltr\" class=\"x-ink\" style=\"padding:16px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:left;direction:ltr;overflow-wrap:anywhere;word-break:break-word\">%%text_2%%</td> </tr>%%/text_2%% %%?section_1_title%%<tr> <td dir=\"ltr\" class=\"x-ink\" style=\"padding:24px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:left;direction:ltr;overflow-wrap:anywhere;word-break:break-word\"> <h2 class=\"x-ink\" style=\"margin:0 0 4px;font-size:16px;line-height:24px;font-weight:700;color:#1b1a2e\">%%section_1_title%%</h2> %%?section_1_body%%<div dir=\"auto\" style=\"margin:0;text-align:start\">%%section_1_body%%</div>%%/section_1_body%% %%?section_1_list%%<ul dir=\"auto\" style=\"margin:0;padding-left:20px;text-align:start\">%%section_1_list%%</ul>%%/section_1_list%% %%?section_1_note%%<div dir=\"auto\" style=\"margin:8px 0 0;text-align:start\">%%section_1_note%%</div>%%/section_1_note%% %%?section_1_link%%<p dir=\"auto\" style=\"margin:8px 0 0;text-align:start\"><a href=\"%%section_1_link_url%%\" class=\"x-link\" style=\"color:#4641d9\">%%section_1_link%%</a></p>%%/section_1_link%% </td> </tr>%%/section_1_title%% %%?section_2_title%%<tr> <td dir=\"ltr\" class=\"x-ink\" style=\"padding:24px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:left;direction:ltr;overflow-wrap:anywhere;word-break:break-word\"> <h2 class=\"x-ink\" style=\"margin:0 0 4px;font-size:16px;line-height:24px;font-weight:700;color:#1b1a2e\">%%section_2_title%%</h2> %%?section_2_body%%<div dir=\"auto\" style=\"margin:0;text-align:start\">%%section_2_body%%</div>%%/section_2_body%% %%?section_2_list%%<ul dir=\"auto\" style=\"margin:0;padding-left:20px;text-align:start\">%%section_2_list%%</ul>%%/section_2_list%% %%?section_2_note%%<div dir=\"auto\" style=\"margin:8px 0 0;text-align:start\">%%section_2_note%%</div>%%/section_2_note%% %%?section_2_link%%<p dir=\"auto\" style=\"margin:8px 0 0;text-align:start\"><a href=\"%%section_2_link_url%%\" class=\"x-link\" style=\"color:#4641d9\">%%section_2_link%%</a></p>%%/section_2_link%% </td> </tr>%%/section_2_title%% %%?section_3_title%%<tr> <td dir=\"ltr\" class=\"x-ink\" style=\"padding:24px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:left;direction:ltr;overflow-wrap:anywhere;word-break:break-word\"> <h2 class=\"x-ink\" style=\"margin:0 0 4px;font-size:16px;line-height:24px;font-weight:700;color:#1b1a2e\">%%section_3_title%%</h2> %%?section_3_body%%<div dir=\"auto\" style=\"margin:0;text-align:start\">%%section_3_body%%</div>%%/section_3_body%% %%?section_3_list%%<ul dir=\"auto\" style=\"margin:0;padding-left:20px;text-align:start\">%%section_3_list%%</ul>%%/section_3_list%% %%?section_3_note%%<div dir=\"auto\" style=\"margin:8px 0 0;text-align:start\">%%section_3_note%%</div>%%/section_3_note%% %%?section_3_link%%<p dir=\"auto\" style=\"margin:8px 0 0;text-align:start\"><a href=\"%%section_3_link_url%%\" class=\"x-link\" style=\"color:#4641d9\">%%section_3_link%%</a></p>%%/section_3_link%% </td> </tr>%%/section_3_title%% %%?section_4_title%%<tr> <td dir=\"ltr\" class=\"x-ink\" style=\"padding:24px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:left;direction:ltr;overflow-wrap:anywhere;word-break:break-word\"> <h2 class=\"x-ink\" style=\"margin:0 0 4px;font-size:16px;line-height:24px;font-weight:700;color:#1b1a2e\">%%section_4_title%%</h2> %%?section_4_body%%<div dir=\"auto\" style=\"margin:0;text-align:start\">%%section_4_body%%</div>%%/section_4_body%% %%?section_4_list%%<ul dir=\"auto\" style=\"margin:0;padding-left:20px;text-align:start\">%%section_4_list%%</ul>%%/section_4_list%% %%?section_4_note%%<div dir=\"auto\" style=\"margin:8px 0 0;text-align:start\">%%section_4_note%%</div>%%/section_4_note%% %%?section_4_link%%<p dir=\"auto\" style=\"margin:8px 0 0;text-align:start\"><a href=\"%%section_4_link_url%%\" class=\"x-link\" style=\"color:#4641d9\">%%section_4_link%%</a></p>%%/section_4_link%% </td> </tr>%%/section_4_title%% %%?note%%<tr> <td dir=\"ltr\" class=\"x-muted\" style=\"padding:16px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:14px;line-height:21px;color:#5b5a70;text-align:left;direction:ltr;overflow-wrap:anywhere;word-break:break-word\">%%note%%</td> </tr>%%/note%% %%?end_link%%<tr> <td dir=\"ltr\" style=\"padding:16px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;text-align:left;direction:ltr\"><a href=\"%%end_link_url%%\" class=\"x-link\" style=\"color:#4641d9\">%%end_link%%</a></td> </tr>%%/end_link%% <tr> <td dir=\"ltr\" class=\"x-ink\" style=\"padding:24px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:left;direction:ltr\">%%signoff%%</td> </tr> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </div> <!--[if mso | IE]></td></tr></table><![endif]--> </td> </tr> </tbody> </table> </div> <!--[if mso | IE]></td></tr></table><table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"x-pad-outlook\" role=\"presentation\" style=\"width:600px;\" width=\"600\" ><tr><td style=\"line-height:0px;font-size:0px;mso-line-height-rule:exactly;\"><![endif]--> <div class=\"x-pad\" style=\"margin:0px auto;max-width:600px\"> <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"width:100%\"> <tbody> <tr> <td style=\"direction:ltr;font-size:0px;padding:32px 24px 40px;text-align:left\"> <!--[if mso | IE]><table role=\"presentation\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"\" style=\"vertical-align:top;width:552px;\" ><![endif]--> <div class=\"mj-column-per-100 mj-outlook-group-fix\" style=\"font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%\"> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\"> <tbody> <tr> <td style=\"vertical-align:top;padding:0\"> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\"> <tbody> <tr> <td dir=\"ltr\" class=\"x-muted x-rule\" style=\"padding:16px 0 0;border-top:1px solid #e4e3ec;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:13px;line-height:20px;color:#5b5a70;text-align:left;direction:ltr\"> <div style=\"margin:0\">%%footer_reason%%</div> %%?unsubscribe%%<p style=\"margin:8px 0 0\"><a href=\"%%unsubscribe_url%%\" style=\"color:inherit;text-decoration:underline\">%%unsubscribe%%</a></p>%%/unsubscribe%% %%?legal_address%%<p dir=\"ltr\" style=\"margin:8px 0 0;text-align:left\">%%legal_address%%</p>%%/legal_address%% </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </div> <!--[if mso | IE]></td></tr></table><![endif]--> </td> </tr> </tbody> </table> </div> <!--[if mso | IE]></td></tr></table><![endif]--> </div> </body></html>",+ rtl: "<!doctype html><html lang=\"%%lang%%\" dir=\"rtl\" xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\"><head><title>%%subject%%</title><!--[if !mso]><!--><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"><!--<![endif]--><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><style type=\"text/css\">#outlook a{padding:0}body{margin:0;padding:0;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}table, td{border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt}img{border:0;height:auto;line-height:100%;outline:none;text-decoration:none;-ms-interpolation-mode:bicubic}p{display:block;margin:13px 0}</style><!--[if mso]>\n <noscript>\n <xml>\n <o:OfficeDocumentSettings>\n <o:AllowPNG/>\n <o:PixelsPerInch>96</o:PixelsPerInch>\n </o:OfficeDocumentSettings>\n </xml>\n </noscript>\n <![endif]--><!--[if lte mso 11]>\n <style type=\"text/css\">\n .mj-outlook-group-fix { width:100% !important; }\n </style>\n <![endif]--><style type=\"text/css\">@media only screen and (min-width:480px){.mj-column-per-100{width:100%!important;max-width:100%}}</style><style media=\"screen and (min-width:480px)\">.moz-text-html .mj-column-per-100{width:100%!important;max-width:100%}</style><style type=\"text/css\">:root{color-scheme:light dark;supported-color-schemes:light dark}body{margin:0;padding:0;word-spacing:normal;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}a{text-decoration:underline}.x-btn{text-decoration:none!important}@media only screen and (max-width: 480px){.x-pad > table > tbody > tr > td{padding-left:16px!important;padding-right:16px!important}}@media (prefers-color-scheme: dark){.x-page, .x-page > [role=\"article\"]{background-color:#121218!important}.x-ink{color:#ececf3!important}.x-muted{color:#a9a8bd!important}.x-link{color:#b8b5ff!important}.x-rule{border-color:#34334a!important}.x-light{display:none!important}.x-dark{display:block!important;max-height:none!important;overflow:visible!important}}[data-ogsb] .x-page, [data-ogsb] .x-page > [role=\"article\"]{background-color:#121218!important}[data-ogsc] .x-ink{color:#ececf3!important}[data-ogsc] .x-muted{color:#a9a8bd!important}[data-ogsc] .x-link{color:#b8b5ff!important}[data-ogsc] .x-light{display:none!important}[data-ogsc] .x-dark{display:block!important;max-height:none!important;overflow:visible!important}</style><meta name=\"color-scheme\" content=\"light dark\"><meta name=\"supported-color-schemes\" content=\"light dark\"><meta name=\"format-detection\" content=\"telephone=no, date=no, address=no, email=no, url=no\"><meta name=\"x-apple-disable-message-reformatting\"></head><body class=\"x-page\" style=\"word-spacing:normal;background-color:#ffffff\"> <div style=\"display:none;font-size:1px;color:#ffffff;line-height:1px;max-height:0px;max-width:0px;opacity:0;overflow:hidden\">%%preheader%%͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ </div> <div aria-label=\"%%subject%%\" aria-roledescription=\"email\" role=\"article\" lang=\"%%lang%%\" dir=\"rtl\" style=\"word-spacing:normal;background-color:#ffffff\"> <!--[if mso | IE]><table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"x-pad-outlook\" role=\"presentation\" style=\"width:600px;\" width=\"600\" ><tr><td style=\"line-height:0px;font-size:0px;mso-line-height-rule:exactly;\"><![endif]--> <div class=\"x-pad\" style=\"margin:0px auto;max-width:600px\"> <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"width:100%\"> <tbody> <tr> <td style=\"direction:ltr;font-size:0px;padding:32px 24px 0;text-align:right\"> <!--[if mso | IE]><table role=\"presentation\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"\" style=\"vertical-align:top;width:552px;\" ><![endif]--> <div class=\"mj-column-per-100 mj-outlook-group-fix\" style=\"font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%\"> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\"> <tbody> <tr> <td style=\"vertical-align:top;padding:0\"> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\"> <tbody> <tr> <td dir=\"rtl\" style=\"padding:0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;text-align:right;direction:rtl\"> %%?logo_url%%<a href=\"%%home_url%%\" target=\"_blank\" class=\"x-light\" style=\"display:inline-block;text-decoration:none\"><img src=\"%%logo_url%%\" width=\"92\" height=\"24\" alt=\"%%product_name%%\" style=\"display:block;width:92px;height:24px;border:0;font-size:18px;line-height:24px;font-weight:700;color:#4641d9\"></a><!--[if !mso]><!--><div class=\"x-dark\" style=\"display:none;max-height:0;overflow:hidden;mso-hide:all\"><a href=\"%%home_url%%\" target=\"_blank\" style=\"display:inline-block;text-decoration:none\"><img src=\"%%logo_dark_url%%\" width=\"92\" height=\"24\" alt=\"%%product_name%%\" style=\"display:block;width:92px;height:24px;border:0;font-size:18px;line-height:24px;font-weight:700;color:#ffffff\"></a></div><!--<![endif]-->%%/logo_url%% %%?wordmark%%<a href=\"%%home_url%%\" target=\"_blank\" class=\"x-ink\" style=\"font-size:18px;line-height:24px;font-weight:700;color:#1b1a2e;text-decoration:none\">%%wordmark%%</a>%%/wordmark%% </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </div> <!--[if mso | IE]></td></tr></table><![endif]--> </td> </tr> </tbody> </table> </div> <!--[if mso | IE]></td></tr></table><table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"x-pad-outlook\" role=\"presentation\" style=\"width:600px;\" width=\"600\" ><tr><td style=\"line-height:0px;font-size:0px;mso-line-height-rule:exactly;\"><![endif]--> <div class=\"x-pad\" style=\"margin:0px auto;max-width:600px\"> <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"width:100%\"> <tbody> <tr> <td style=\"direction:ltr;font-size:0px;padding:20px 24px 0;text-align:right\"> <!--[if mso | IE]><table role=\"presentation\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"\" style=\"vertical-align:top;width:552px;\" ><![endif]--> <div class=\"mj-column-per-100 mj-outlook-group-fix\" style=\"font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%\"> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\"> <tbody> <tr> <td style=\"vertical-align:top;padding:0\"> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\"> <tbody> <tr> <td style=\"padding:0\"> <table role=\"presentation\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" dir=\"rtl\" style=\"width:100%;border-collapse:collapse;direction:rtl;text-align:right\"> <tr> <td dir=\"rtl\" class=\"x-ink\" style=\"padding:0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:right;direction:rtl;overflow-wrap:anywhere;word-break:break-word\">%%intro%%</td> </tr> %%?code%%<tr> <td dir=\"ltr\" class=\"x-ink\" style=\"padding:16px 0 0;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,'Liberation Mono',monospace;font-size:28px;line-height:36px;font-weight:700;letter-spacing:3px;color:#1b1a2e;text-align:right;white-space:nowrap\">%%code%%</td> </tr>%%/code%% %%?fact_1_label%%<tr> <td dir=\"rtl\" class=\"x-fact x-ink\" style=\"padding:16px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:right;direction:rtl;overflow-wrap:anywhere;word-break:break-word\"><span class=\"x-muted\" style=\"color:#5b5a70\">%%fact_1_label%%:</span> %%?fact_1_value%%<span dir=\"auto\">%%fact_1_value%%</span>%%/fact_1_value%%%%?fact_1_link%%<a href=\"%%fact_1_link_url%%\" class=\"x-link\" dir=\"auto\" style=\"color:#4641d9\">%%fact_1_link%%</a>%%/fact_1_link%%</td> </tr>%%/fact_1_label%% %%?fact_2_label%%<tr> <td dir=\"rtl\" class=\"x-fact x-ink\" style=\"padding:4px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:right;direction:rtl;overflow-wrap:anywhere;word-break:break-word\"><span class=\"x-muted\" style=\"color:#5b5a70\">%%fact_2_label%%:</span> %%?fact_2_value%%<span dir=\"auto\">%%fact_2_value%%</span>%%/fact_2_value%%%%?fact_2_link%%<a href=\"%%fact_2_link_url%%\" class=\"x-link\" dir=\"auto\" style=\"color:#4641d9\">%%fact_2_link%%</a>%%/fact_2_link%%</td> </tr>%%/fact_2_label%% %%?fact_3_label%%<tr> <td dir=\"rtl\" class=\"x-fact x-ink\" style=\"padding:4px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:right;direction:rtl;overflow-wrap:anywhere;word-break:break-word\"><span class=\"x-muted\" style=\"color:#5b5a70\">%%fact_3_label%%:</span> %%?fact_3_value%%<span dir=\"auto\">%%fact_3_value%%</span>%%/fact_3_value%%%%?fact_3_link%%<a href=\"%%fact_3_link_url%%\" class=\"x-link\" dir=\"auto\" style=\"color:#4641d9\">%%fact_3_link%%</a>%%/fact_3_link%%</td> </tr>%%/fact_3_label%% %%?fact_4_label%%<tr> <td dir=\"rtl\" class=\"x-fact x-ink\" style=\"padding:4px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:right;direction:rtl;overflow-wrap:anywhere;word-break:break-word\"><span class=\"x-muted\" style=\"color:#5b5a70\">%%fact_4_label%%:</span> %%?fact_4_value%%<span dir=\"auto\">%%fact_4_value%%</span>%%/fact_4_value%%%%?fact_4_link%%<a href=\"%%fact_4_link_url%%\" class=\"x-link\" dir=\"auto\" style=\"color:#4641d9\">%%fact_4_link%%</a>%%/fact_4_link%%</td> </tr>%%/fact_4_label%% %%?fact_5_label%%<tr> <td dir=\"rtl\" class=\"x-fact x-ink\" style=\"padding:4px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:right;direction:rtl;overflow-wrap:anywhere;word-break:break-word\"><span class=\"x-muted\" style=\"color:#5b5a70\">%%fact_5_label%%:</span> %%?fact_5_value%%<span dir=\"auto\">%%fact_5_value%%</span>%%/fact_5_value%%%%?fact_5_link%%<a href=\"%%fact_5_link_url%%\" class=\"x-link\" dir=\"auto\" style=\"color:#4641d9\">%%fact_5_link%%</a>%%/fact_5_link%%</td> </tr>%%/fact_5_label%% %%?fact_6_label%%<tr> <td dir=\"rtl\" class=\"x-fact x-ink\" style=\"padding:4px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:right;direction:rtl;overflow-wrap:anywhere;word-break:break-word\"><span class=\"x-muted\" style=\"color:#5b5a70\">%%fact_6_label%%:</span> %%?fact_6_value%%<span dir=\"auto\">%%fact_6_value%%</span>%%/fact_6_value%%%%?fact_6_link%%<a href=\"%%fact_6_link_url%%\" class=\"x-link\" dir=\"auto\" style=\"color:#4641d9\">%%fact_6_link%%</a>%%/fact_6_link%%</td> </tr>%%/fact_6_label%% %%?fact_7_label%%<tr> <td dir=\"rtl\" class=\"x-fact x-ink\" style=\"padding:4px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:right;direction:rtl;overflow-wrap:anywhere;word-break:break-word\"><span class=\"x-muted\" style=\"color:#5b5a70\">%%fact_7_label%%:</span> %%?fact_7_value%%<span dir=\"auto\">%%fact_7_value%%</span>%%/fact_7_value%%%%?fact_7_link%%<a href=\"%%fact_7_link_url%%\" class=\"x-link\" dir=\"auto\" style=\"color:#4641d9\">%%fact_7_link%%</a>%%/fact_7_link%%</td> </tr>%%/fact_7_label%% %%?points_list%%<tr> <td dir=\"rtl\" class=\"x-ink\" style=\"padding:16px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:right;direction:rtl;overflow-wrap:anywhere;word-break:break-word\"> <ul dir=\"auto\" style=\"margin:0;padding-right:20px;text-align:start\">%%points_list%%</ul> </td> </tr>%%/points_list%% %%?lead%%<tr> <td dir=\"rtl\" class=\"x-ink\" style=\"padding:16px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:right;direction:rtl;overflow-wrap:anywhere;word-break:break-word\">%%lead%%</td> </tr>%%/lead%% %%?cta%%<tr> <td align=\"right\" style=\"padding:24px 0 0\"> <table role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"right\" style=\"border-collapse:separate\"> <tr> <td align=\"center\" bgcolor=\"#4641d9\" style=\"border-radius:6px;background-color:#4641d9;mso-padding-alt:12px 22px\"> <a href=\"%%cta_url%%\" target=\"_blank\" class=\"x-btn\" style=\"display:inline-block;padding:12px 22px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:22px;font-weight:600;color:#ffffff;text-decoration:none;border-radius:6px\">%%cta%%</a> </td> </tr> </table> </td> </tr>%%/cta%% %%?expiry%%<tr> <td dir=\"rtl\" class=\"x-muted\" style=\"padding:12px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:14px;line-height:21px;color:#5b5a70;text-align:right;direction:rtl;overflow-wrap:anywhere;word-break:break-word\">%%expiry%%</td> </tr>%%/expiry%% %%?text_1%%<tr> <td dir=\"rtl\" class=\"x-ink\" style=\"padding:16px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:right;direction:rtl;overflow-wrap:anywhere;word-break:break-word\">%%text_1%%</td> </tr>%%/text_1%% %%?text_2%%<tr> <td dir=\"rtl\" class=\"x-ink\" style=\"padding:16px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:right;direction:rtl;overflow-wrap:anywhere;word-break:break-word\">%%text_2%%</td> </tr>%%/text_2%% %%?section_1_title%%<tr> <td dir=\"rtl\" class=\"x-ink\" style=\"padding:24px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:right;direction:rtl;overflow-wrap:anywhere;word-break:break-word\"> <h2 class=\"x-ink\" style=\"margin:0 0 4px;font-size:16px;line-height:24px;font-weight:700;color:#1b1a2e\">%%section_1_title%%</h2> %%?section_1_body%%<div dir=\"auto\" style=\"margin:0;text-align:start\">%%section_1_body%%</div>%%/section_1_body%% %%?section_1_list%%<ul dir=\"auto\" style=\"margin:0;padding-right:20px;text-align:start\">%%section_1_list%%</ul>%%/section_1_list%% %%?section_1_note%%<div dir=\"auto\" style=\"margin:8px 0 0;text-align:start\">%%section_1_note%%</div>%%/section_1_note%% %%?section_1_link%%<p dir=\"auto\" style=\"margin:8px 0 0;text-align:start\"><a href=\"%%section_1_link_url%%\" class=\"x-link\" style=\"color:#4641d9\">%%section_1_link%%</a></p>%%/section_1_link%% </td> </tr>%%/section_1_title%% %%?section_2_title%%<tr> <td dir=\"rtl\" class=\"x-ink\" style=\"padding:24px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:right;direction:rtl;overflow-wrap:anywhere;word-break:break-word\"> <h2 class=\"x-ink\" style=\"margin:0 0 4px;font-size:16px;line-height:24px;font-weight:700;color:#1b1a2e\">%%section_2_title%%</h2> %%?section_2_body%%<div dir=\"auto\" style=\"margin:0;text-align:start\">%%section_2_body%%</div>%%/section_2_body%% %%?section_2_list%%<ul dir=\"auto\" style=\"margin:0;padding-right:20px;text-align:start\">%%section_2_list%%</ul>%%/section_2_list%% %%?section_2_note%%<div dir=\"auto\" style=\"margin:8px 0 0;text-align:start\">%%section_2_note%%</div>%%/section_2_note%% %%?section_2_link%%<p dir=\"auto\" style=\"margin:8px 0 0;text-align:start\"><a href=\"%%section_2_link_url%%\" class=\"x-link\" style=\"color:#4641d9\">%%section_2_link%%</a></p>%%/section_2_link%% </td> </tr>%%/section_2_title%% %%?section_3_title%%<tr> <td dir=\"rtl\" class=\"x-ink\" style=\"padding:24px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:right;direction:rtl;overflow-wrap:anywhere;word-break:break-word\"> <h2 class=\"x-ink\" style=\"margin:0 0 4px;font-size:16px;line-height:24px;font-weight:700;color:#1b1a2e\">%%section_3_title%%</h2> %%?section_3_body%%<div dir=\"auto\" style=\"margin:0;text-align:start\">%%section_3_body%%</div>%%/section_3_body%% %%?section_3_list%%<ul dir=\"auto\" style=\"margin:0;padding-right:20px;text-align:start\">%%section_3_list%%</ul>%%/section_3_list%% %%?section_3_note%%<div dir=\"auto\" style=\"margin:8px 0 0;text-align:start\">%%section_3_note%%</div>%%/section_3_note%% %%?section_3_link%%<p dir=\"auto\" style=\"margin:8px 0 0;text-align:start\"><a href=\"%%section_3_link_url%%\" class=\"x-link\" style=\"color:#4641d9\">%%section_3_link%%</a></p>%%/section_3_link%% </td> </tr>%%/section_3_title%% %%?section_4_title%%<tr> <td dir=\"rtl\" class=\"x-ink\" style=\"padding:24px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:right;direction:rtl;overflow-wrap:anywhere;word-break:break-word\"> <h2 class=\"x-ink\" style=\"margin:0 0 4px;font-size:16px;line-height:24px;font-weight:700;color:#1b1a2e\">%%section_4_title%%</h2> %%?section_4_body%%<div dir=\"auto\" style=\"margin:0;text-align:start\">%%section_4_body%%</div>%%/section_4_body%% %%?section_4_list%%<ul dir=\"auto\" style=\"margin:0;padding-right:20px;text-align:start\">%%section_4_list%%</ul>%%/section_4_list%% %%?section_4_note%%<div dir=\"auto\" style=\"margin:8px 0 0;text-align:start\">%%section_4_note%%</div>%%/section_4_note%% %%?section_4_link%%<p dir=\"auto\" style=\"margin:8px 0 0;text-align:start\"><a href=\"%%section_4_link_url%%\" class=\"x-link\" style=\"color:#4641d9\">%%section_4_link%%</a></p>%%/section_4_link%% </td> </tr>%%/section_4_title%% %%?note%%<tr> <td dir=\"rtl\" class=\"x-muted\" style=\"padding:16px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:14px;line-height:21px;color:#5b5a70;text-align:right;direction:rtl;overflow-wrap:anywhere;word-break:break-word\">%%note%%</td> </tr>%%/note%% %%?end_link%%<tr> <td dir=\"rtl\" style=\"padding:16px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;text-align:right;direction:rtl\"><a href=\"%%end_link_url%%\" class=\"x-link\" style=\"color:#4641d9\">%%end_link%%</a></td> </tr>%%/end_link%% <tr> <td dir=\"rtl\" class=\"x-ink\" style=\"padding:24px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:16px;line-height:24px;color:#1b1a2e;text-align:right;direction:rtl\">%%signoff%%</td> </tr> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </div> <!--[if mso | IE]></td></tr></table><![endif]--> </td> </tr> </tbody> </table> </div> <!--[if mso | IE]></td></tr></table><table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"x-pad-outlook\" role=\"presentation\" style=\"width:600px;\" width=\"600\" ><tr><td style=\"line-height:0px;font-size:0px;mso-line-height-rule:exactly;\"><![endif]--> <div class=\"x-pad\" style=\"margin:0px auto;max-width:600px\"> <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"width:100%\"> <tbody> <tr> <td style=\"direction:ltr;font-size:0px;padding:32px 24px 40px;text-align:right\"> <!--[if mso | IE]><table role=\"presentation\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"\" style=\"vertical-align:top;width:552px;\" ><![endif]--> <div class=\"mj-column-per-100 mj-outlook-group-fix\" style=\"font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%\"> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\"> <tbody> <tr> <td style=\"vertical-align:top;padding:0\"> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\"> <tbody> <tr> <td dir=\"rtl\" class=\"x-muted x-rule\" style=\"padding:16px 0 0;border-top:1px solid #e4e3ec;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,'Noto Sans',sans-serif;font-size:13px;line-height:20px;color:#5b5a70;text-align:right;direction:rtl\"> <div style=\"margin:0\">%%footer_reason%%</div> %%?unsubscribe%%<p style=\"margin:8px 0 0\"><a href=\"%%unsubscribe_url%%\" style=\"color:inherit;text-decoration:underline\">%%unsubscribe%%</a></p>%%/unsubscribe%% %%?legal_address%%<p dir=\"ltr\" style=\"margin:8px 0 0;text-align:right\">%%legal_address%%</p>%%/legal_address%% </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </div> <!--[if mso | IE]></td></tr></table><![endif]--> </td> </tr> </tbody> </table> </div> <!--[if mso | IE]></td></tr></table><![endif]--> </div> </body></html>",+ },+} as const;diff --git a/fluxer_api/pkgs/email/src/email_html/EmailHtmlRenderer.ts b/fluxer_api/pkgs/email/src/email_html/EmailHtmlRenderer.tsnew file mode 100644index 000000000..13b138e79--- /dev/null+++ b/fluxer_api/pkgs/email/src/email_html/EmailHtmlRenderer.ts@@ -0,0 +1,396 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import {EMAIL_HTML_LAYOUTS} from '@pkgs/email/src/email_html/EmailHtmlLayouts.generated';++export type EmailTextDirection = 'ltr' | 'rtl';++const RTL_LANGUAGES = new Set(['ar', 'he']);+const LOCAL_HOSTNAMES = new Set(['localhost', '127.0.0.1', '[::1]']);+const SLOT_PATTERN = /%%([a-z0-9_]+)%%/g;+const BLOCK_PATTERN = /%%\?([a-z0-9_]+)%%([\s\S]*?)%%\/\1%%/g;+const LANG_PATTERN = /^[a-zA-Z]{2,3}(?:-[a-zA-Z0-9]{2,8})*$/;+const CHANNEL_MENTION_PATTERN = /(?<![\w/&#])#[a-z][a-z0-9-]*/g;+const LEFT_TO_RIGHT_ISOLATE = '\u2066';+const FIRST_STRONG_ISOLATE = '\u2068';+const POP_DIRECTIONAL_ISOLATE = '\u2069';+const INERT_LITERALS: ReadonlyArray<readonly [string, string]> = [+ ['<', '\uE000'],+ ['>', '\uE001'],+ ['[', '\uE002'],+ [']', '\uE003'],+];+const INERT_PATTERN = /[<>[\]]/g;+const LITERAL_PATTERN = /[\uE000-\uE003]/g;+const TO_INERT = new Map(INERT_LITERALS);+const TO_LITERAL = new Map(INERT_LITERALS.map(([literal, inert]) => [inert, literal]));+const HTML_ESCAPES: Record<string, string> = {+ '&': '&',+ '<': '<',+ '>': '>',+ '"': '"',+ "'": ''',+};++export function getEmailTextDirection(locale: string): EmailTextDirection {+ return RTL_LANGUAGES.has(locale.split('-')[0].toLowerCase()) ? 'rtl' : 'ltr';+}++export function escapeHtml(value: string): string {+ return value.replace(/[&<>"']/g, (character) => HTML_ESCAPES[character]);+}++export function inertEmailValue(value: string): string {+ return value.replace(INERT_PATTERN, (character) => TO_INERT.get(character) ?? character);+}++export function restoreEmailLiterals(value: string): string {+ return value.replace(LITERAL_PATTERN, (character) => TO_LITERAL.get(character) ?? character);+}++export function isolateEmailValue(value: string): string {+ return `${FIRST_STRONG_ISOLATE}${value}${POP_DIRECTIONAL_ISOLATE}`;+}++function bidiIsolatesToHtml(value: string): string {+ const open: Array<boolean> = [];+ let out = '';+ for (const character of value) {+ if (character === FIRST_STRONG_ISOLATE) {+ open.push(true);+ out += '<bdi>';+ } else if (character === LEFT_TO_RIGHT_ISOLATE) {+ open.push(false);+ out += '<span dir="ltr">';+ } else if (character === POP_DIRECTIONAL_ISOLATE) {+ const isBdi = open.pop();+ if (isBdi === true) out += '</bdi>';+ else if (isBdi === false) out += '</span>';+ } else {+ out += character;+ }+ }+ return open.reduceRight((closing, isBdi) => closing + (isBdi ? '</bdi>' : '</span>'), out);+}++function escapeText(value: string): string {+ return bidiIsolatesToHtml(escapeHtml(restoreEmailLiterals(value)));+}++function hasUnsafeUrlCharacters(value: string): boolean {+ for (const character of value) {+ const code = character.codePointAt(0) ?? 0;+ if (code <= 0x20 || code === 0x7f || /\s/u.test(character)) {+ return true;+ }+ }+ return false;+}++export function validateEmailUrl(value: string, ownHttpOrigins: ReadonlySet<string> = new Set()): string {+ if (hasUnsafeUrlCharacters(value)) {+ throw new Error('Email link contains whitespace or control characters');+ }+ let url: URL;+ try {+ url = new URL(value);+ } catch {+ throw new Error('Email link is not an absolute URL');+ }+ if (url.username || url.password) {+ throw new Error('Email link must not contain credentials');+ }+ const isAllowedHttp =+ url.protocol === 'http:' && (LOCAL_HOSTNAMES.has(url.hostname) || ownHttpOrigins.has(url.origin));+ if (url.protocol !== 'https:' && !isAllowedHttp) {+ throw new Error(`Email link must use https: ${url.protocol}`);+ }+ return value;+}++function isolateChannelMentions(value: string): string {+ return value.replace(+ CHANNEL_MENTION_PATTERN,+ (mention) => `${LEFT_TO_RIGHT_ISOLATE}${mention}${POP_DIRECTIONAL_ISOLATE}`,+ );+}++type Slots = Readonly<Record<string, string | null | undefined>>;++interface InlineLink {+ anchor: string;+ url: string | null;+}++type InlinePart = string | InlineLink;++const INLINE_PATTERN = /<(mail|settings|dsa|arn)>([^<]*)<\/\1>|\[([^\]\n]+)\]\(([^)\s]+)\)/g;+const CITED_LINK_HOSTS = ['digital-strategy.ec.europa.eu', 'www.arn.se'];++export function emailLinkHosts(baseUrls: ReadonlyArray<string>): ReadonlySet<string> {+ const hosts = new Set(CITED_LINK_HOSTS);+ for (const base of baseUrls) {+ if (URL.canParse(base)) {+ hosts.add(new URL(base).host);+ }+ }+ return hosts;+}+const EMAIL_PATTERN = /^[^\s@<>()]+@[^\s@<>()]+\.[^\s@<>()]+$/;++function inlineParts(+ text: string,+ slots: Slots,+ checkUrl: ((url: string) => string) | null,+ linkHosts: ReadonlySet<string> | null = null,+): Array<InlinePart> {+ const parts: Array<InlinePart> = [];+ let last = 0;+ for (const match of text.matchAll(INLINE_PATTERN)) {+ const index = match.index ?? 0;+ parts.push(text.slice(last, index));+ last = index + match[0].length;+ if (match[1]) {+ const [, tag, anchor] = match;+ if (tag === 'mail') {+ if (!EMAIL_PATTERN.test(anchor) && checkUrl) {+ throw new Error(`Email link tag holds no address: ${anchor}`);+ }+ parts.push({anchor, url: `mailto:${anchor}`});+ continue;+ }+ const url = slots[`${tag}_url`];+ if (!url && checkUrl) {+ throw new Error(`Email link tag <${tag}> has no ${tag}_url slot`);+ }+ parts.push({anchor, url: url && checkUrl ? checkUrl(url) : (url ?? null)});+ continue;+ }+ const [whole, , , anchor, url] = match;+ if (linkHosts && !(URL.canParse(url) && linkHosts.has(new URL(url).host))) {+ parts.push(whole);+ continue;+ }+ try {+ parts.push({anchor, url: checkUrl ? checkUrl(url) : url});+ } catch {+ parts.push(whole);+ }+ }+ parts.push(text.slice(last));+ return parts.filter((part) => part !== '');+}++function inlineHtml(+ text: string,+ slots: Slots,+ direction: EmailTextDirection,+ ownHttpOrigins: ReadonlySet<string>,+ linkHosts: ReadonlySet<string>,+) {+ return inlineParts(text, slots, (url) => validateEmailUrl(url, ownHttpOrigins), linkHosts)+ .map((part) => {+ if (typeof part === 'string') {+ return escapeText(direction === 'rtl' ? isolateChannelMentions(part) : part);+ }+ const href = part.url ?? '';+ const dir = href.startsWith('mailto:') ? ' dir="ltr"' : '';+ return `<a href="${escapeHtml(href)}" class="x-link"${dir} style="color:#4641d9">${escapeText(part.anchor)}</a>`;+ })+ .join('');+}++function paragraphs(value: string): Array<string> {+ return value+ .split(/\r?\n/)+ .map((line) => line.trim())+ .filter(Boolean);+}++function encodeSlot(+ name: string,+ value: string,+ slots: Slots,+ direction: EmailTextDirection,+ ownHttpOrigins: ReadonlySet<string>,+ linkHosts: ReadonlySet<string>,+): string {+ if (name === 'lang') {+ if (!LANG_PATTERN.test(value)) {+ throw new Error(`Invalid email language tag: ${value}`);+ }+ return value;+ }+ if (name.endsWith('_url')) {+ return escapeHtml(validateEmailUrl(value, ownHttpOrigins));+ }+ if (name === 'subject' || name === 'preheader' || name === 'code' || name.endsWith('_label')) {+ const literal = restoreEmailLiterals(value);+ return escapeHtml(direction === 'rtl' ? isolateChannelMentions(literal) : literal);+ }+ if (name.endsWith('_list')) {+ return paragraphs(value)+ .map((item) => `<li style="margin:0 0 6px">${inlineHtml(item, slots, direction, ownHttpOrigins, linkHosts)}</li>`)+ .join('');+ }+ if (/^fact_\d+_value$/.test(name)) {+ return paragraphs(value)+ .map((line) =>+ inlineHtml(direction === 'rtl' ? isolateEmailValue(line) : line, slots, direction, ownHttpOrigins, linkHosts),+ )+ .join('<br>');+ }+ const blocks = paragraphs(value);+ if (blocks.length <= 1) {+ return inlineHtml(blocks[0] ?? '', slots, direction, ownHttpOrigins, linkHosts);+ }+ return blocks+ .map(+ (block, index) =>+ `<p style="margin:${index === 0 ? 0 : '12px 0 0'}">${inlineHtml(block, slots, direction, ownHttpOrigins, linkHosts)}</p>`,+ )+ .join('');+}++export function renderEmailHtml(+ direction: EmailTextDirection,+ slots: Slots,+ ownHttpOrigins: ReadonlySet<string> = new Set(),+ linkHosts: ReadonlySet<string> = new Set(CITED_LINK_HOSTS),+): string {+ let html: string = EMAIL_HTML_LAYOUTS.message[direction];+ for (let previous = ''; previous !== html; ) {+ previous = html;+ html = html.replace(BLOCK_PATTERN, (_match, name: string, inner: string) => (slots[name] ? inner : ''));+ }+ return html.replace(SLOT_PATTERN, (_match, name: string) => {+ const value = slots[name];+ if (typeof value !== 'string') {+ throw new Error(`Missing email layout slot ${name}`);+ }+ return encodeSlot(name, value, slots, direction, ownHttpOrigins, linkHosts);+ });+}++export type EmailTextLinks = 'plain' | 'markdown';++export function stripInlineMarkup(text: string): string {+ return inlineParts(text, {}, null)+ .map((part) => (typeof part === 'string' ? part : part.anchor))+ .join('');+}++const FACT_COUNT = 7;+const SECTION_COUNT = 4;++function textInline(text: string, slots: Slots, links: EmailTextLinks): {line: string; urls: Array<string>} {+ const urls: Array<string> = [];+ const line = inlineParts(text, slots, null)+ .map((part) => {+ if (typeof part === 'string') {+ return part;+ }+ if (!part.url || part.url.startsWith('mailto:')) {+ return part.anchor;+ }+ if (links === 'markdown') {+ return `[${part.anchor}](${part.url})`;+ }+ urls.push(part.url);+ return part.anchor;+ })+ .join('');+ return {line, urls};+}++function textParagraphs(value: string | null | undefined, slots: Slots, links: EmailTextLinks): string | null {+ if (!value) {+ return null;+ }+ return paragraphs(value)+ .map((block) => {+ const {line, urls} = textInline(block, slots, links);+ return [line, ...urls].join('\n');+ })+ .join('\n\n');+}++function textList(value: string | null | undefined, slots: Slots, links: EmailTextLinks): string | null {+ if (!value) {+ return null;+ }+ return paragraphs(value)+ .map((item) => {+ const {line, urls} = textInline(item, slots, links);+ return [`- ${line}`, ...urls.map((url) => ` ${url}`)].join('\n');+ })+ .join('\n');+}++function textLink(label: string | null | undefined, url: string | null | undefined, links: EmailTextLinks) {+ if (!label || !url) {+ return null;+ }+ return links === 'markdown' ? `[${label}](${url})` : `${label}\n${url}`;+}++function textBlock(...lines: Array<string | null | undefined>): string {+ return lines.filter((line): line is string => Boolean(line)).join('\n');+}++export function renderEmailText(slots: Slots, links: EmailTextLinks = 'plain'): string {+ const facts: Array<string> = [];+ for (let n = 1; n <= FACT_COUNT; n++) {+ const label = slots[`fact_${n}_label`];+ const value = slots[`fact_${n}_value`] ?? slots[`fact_${n}_link`];+ if (!label || !value) {+ continue;+ }+ const url = slots[`fact_${n}_link_url`];+ if (slots[`fact_${n}_link`] && url) {+ facts.push(links === 'markdown' ? `${label}: [${value}](${url})` : `${label}: ${value}\n${url}`);+ continue;+ }+ const {line, urls} = textInline(paragraphs(value).join('\n'), slots, links);+ facts.push([`${label}: ${line}`, ...urls].join('\n'));+ }+ const sections: Array<string> = [];+ for (let n = 1; n <= SECTION_COUNT; n++) {+ const title = slots[`section_${n}_title`];+ if (!title) {+ continue;+ }+ const blocks = [+ textParagraphs(slots[`section_${n}_body`], slots, links),+ textList(slots[`section_${n}_list`], slots, links),+ textParagraphs(slots[`section_${n}_note`], slots, links),+ textLink(slots[`section_${n}_link`], slots[`section_${n}_link_url`], links),+ ].filter(Boolean);+ sections.push(`${title}\n${blocks.join('\n\n')}`);+ }+ const footer = slots.unsubscribe+ ? textBlock(+ textParagraphs(slots.footer_reason, slots, links),+ textLink(slots.unsubscribe, slots.unsubscribe_url, links),+ slots.legal_address,+ )+ : null;+ const text = [+ textParagraphs(slots.intro, slots, links),+ slots.code,+ facts.join('\n'),+ textList(slots.points_list, slots, links),+ textParagraphs(slots.lead, slots, links),+ textLink(slots.cta, slots.cta_url, links),+ textParagraphs(slots.expiry, slots, links),+ textParagraphs(slots.text_1, slots, links),+ textParagraphs(slots.text_2, slots, links),+ ...sections,+ textParagraphs(slots.note, slots, links),+ textLink(slots.end_link, slots.end_link_url, links),+ slots.signoff,+ footer,+ ]+ .filter((block): block is string => Boolean(block))+ .join('\n\n');+ return restoreEmailLiterals(text);+}diff --git a/fluxer_api/pkgs/email/src/email_html/layouts/message.mjml b/fluxer_api/pkgs/email/src/email_html/layouts/message.mjmlnew file mode 100644index 000000000..3ef33a76c--- /dev/null+++ b/fluxer_api/pkgs/email/src/email_html/layouts/message.mjml@@ -0,0 +1,86 @@+<mjml lang="%%lang%%" dir="[[dir]]">+ <mj-include path="./partials/head.mjml" />+ <mj-body width="600px" background-color="#ffffff" css-class="x-page">+ <mj-section padding="32px 24px 0" css-class="x-pad">+ <mj-column>+ <mj-raw>+ <tr>+ <td dir="[[dir]]" style="padding:0;font-family:[[font]];text-align:[[start]];direction:[[dir]]">+ %%?logo_url%%<a href="%%home_url%%" target="_blank" class="x-light" style="display:inline-block;text-decoration:none"><img src="%%logo_url%%" width="92" height="24" alt="%%product_name%%" style="display:block;width:92px;height:24px;border:0;font-size:18px;line-height:24px;font-weight:700;color:#4641d9"></a><!--[if !mso]><!--><div class="x-dark" style="display:none;max-height:0;overflow:hidden;mso-hide:all"><a href="%%home_url%%" target="_blank" style="display:inline-block;text-decoration:none"><img src="%%logo_dark_url%%" width="92" height="24" alt="%%product_name%%" style="display:block;width:92px;height:24px;border:0;font-size:18px;line-height:24px;font-weight:700;color:#ffffff"></a></div><!--<![endif]-->%%/logo_url%%+ %%?wordmark%%<a href="%%home_url%%" target="_blank" class="x-ink" style="font-size:18px;line-height:24px;font-weight:700;color:#1b1a2e;text-decoration:none">%%wordmark%%</a>%%/wordmark%%+ </td>+ </tr>+ </mj-raw>+ </mj-column>+ </mj-section>+ <mj-section padding="20px 24px 0" css-class="x-pad">+ <mj-column>+ <mj-raw>+ <tr>+ <td style="padding:0">+ <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" dir="[[dir]]" style="width:100%;border-collapse:collapse;direction:[[dir]];text-align:[[start]]">+ <tr>+ <td dir="[[dir]]" class="x-ink" style="padding:0;font-family:[[font]];font-size:16px;line-height:24px;color:#1b1a2e;text-align:[[start]];direction:[[dir]];overflow-wrap:anywhere;word-break:break-word">%%intro%%</td>+ </tr>+ %%?code%%<tr>+ <td dir="ltr" class="x-ink" style="padding:16px 0 0;font-family:[[mono]];font-size:28px;line-height:36px;font-weight:700;letter-spacing:3px;color:#1b1a2e;text-align:[[start]];white-space:nowrap">%%code%%</td>+ </tr>%%/code%%+ <mj-include path="./partials/fact-row.mjml" n="1" top="16px" />+ <mj-include path="./partials/fact-row.mjml" n="2" top="4px" />+ <mj-include path="./partials/fact-row.mjml" n="3" top="4px" />+ <mj-include path="./partials/fact-row.mjml" n="4" top="4px" />+ <mj-include path="./partials/fact-row.mjml" n="5" top="4px" />+ <mj-include path="./partials/fact-row.mjml" n="6" top="4px" />+ <mj-include path="./partials/fact-row.mjml" n="7" top="4px" />+ %%?points_list%%<tr>+ <td dir="[[dir]]" class="x-ink" style="padding:16px 0 0;font-family:[[font]];font-size:16px;line-height:24px;color:#1b1a2e;text-align:[[start]];direction:[[dir]];overflow-wrap:anywhere;word-break:break-word">+ <ul dir="auto" style="margin:0;padding-[[start]]:20px;text-align:start">%%points_list%%</ul>+ </td>+ </tr>%%/points_list%%+ <mj-include path="./partials/text-row.mjml" slot="lead" />+ %%?cta%%<tr>+ <td align="[[start]]" style="padding:24px 0 0">+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" align="[[start]]" style="border-collapse:separate">+ <tr>+ <td align="center" bgcolor="#4641d9" style="border-radius:6px;background-color:#4641d9;mso-padding-alt:12px 22px">+ <a href="%%cta_url%%" target="_blank" class="x-btn" style="display:inline-block;padding:12px 22px;font-family:[[font]];font-size:16px;line-height:22px;font-weight:600;color:#ffffff;text-decoration:none;border-radius:6px">%%cta%%</a>+ </td>+ </tr>+ </table>+ </td>+ </tr>%%/cta%%+ <mj-include path="./partials/muted-row.mjml" slot="expiry" gap="12px" />+ <mj-include path="./partials/text-row.mjml" slot="text_1" />+ <mj-include path="./partials/text-row.mjml" slot="text_2" />+ <mj-include path="./partials/section.mjml" n="1" />+ <mj-include path="./partials/section.mjml" n="2" />+ <mj-include path="./partials/section.mjml" n="3" />+ <mj-include path="./partials/section.mjml" n="4" />+ <mj-include path="./partials/muted-row.mjml" slot="note" gap="16px" />+ %%?end_link%%<tr>+ <td dir="[[dir]]" style="padding:16px 0 0;font-family:[[font]];font-size:16px;line-height:24px;text-align:[[start]];direction:[[dir]]"><a href="%%end_link_url%%" class="x-link" style="color:#4641d9">%%end_link%%</a></td>+ </tr>%%/end_link%%+ <tr>+ <td dir="[[dir]]" class="x-ink" style="padding:24px 0 0;font-family:[[font]];font-size:16px;line-height:24px;color:#1b1a2e;text-align:[[start]];direction:[[dir]]">%%signoff%%</td>+ </tr>+ </table>+ </td>+ </tr>+ </mj-raw>+ </mj-column>+ </mj-section>+ <mj-section padding="32px 24px 40px" css-class="x-pad">+ <mj-column>+ <mj-raw>+ <tr>+ <td dir="[[dir]]" class="x-muted x-rule" style="padding:16px 0 0;border-top:1px solid #e4e3ec;font-family:[[font]];font-size:13px;line-height:20px;color:#5b5a70;text-align:[[start]];direction:[[dir]]">+ <div style="margin:0">%%footer_reason%%</div>+ %%?unsubscribe%%<p style="margin:8px 0 0"><a href="%%unsubscribe_url%%" style="color:inherit;text-decoration:underline">%%unsubscribe%%</a></p>%%/unsubscribe%%+ %%?legal_address%%<p dir="ltr" style="margin:8px 0 0;text-align:[[start]]">%%legal_address%%</p>%%/legal_address%%+ </td>+ </tr>+ </mj-raw>+ </mj-column>+ </mj-section>+ </mj-body>+</mjml>diff --git a/fluxer_api/pkgs/email/src/email_html/layouts/partials/fact-row.mjml b/fluxer_api/pkgs/email/src/email_html/layouts/partials/fact-row.mjmlnew file mode 100644index 000000000..3c1f256cb--- /dev/null+++ b/fluxer_api/pkgs/email/src/email_html/layouts/partials/fact-row.mjml@@ -0,0 +1,3 @@+%%?fact_[[n]]_label%%<tr>+ <td dir="[[dir]]" class="x-ink x-fact" style="padding:[[top]] 0 0;font-family:[[font]];font-size:16px;line-height:24px;color:#1b1a2e;text-align:[[start]];direction:[[dir]];overflow-wrap:anywhere;word-break:break-word"><span class="x-muted" style="color:#5b5a70">%%fact_[[n]]_label%%:</span> %%?fact_[[n]]_value%%<span dir="auto">%%fact_[[n]]_value%%</span>%%/fact_[[n]]_value%%%%?fact_[[n]]_link%%<a href="%%fact_[[n]]_link_url%%" class="x-link" dir="auto" style="color:#4641d9">%%fact_[[n]]_link%%</a>%%/fact_[[n]]_link%%</td>+</tr>%%/fact_[[n]]_label%%diff --git a/fluxer_api/pkgs/email/src/email_html/layouts/partials/head.mjml b/fluxer_api/pkgs/email/src/email_html/layouts/partials/head.mjmlnew file mode 100644index 000000000..23f409c12--- /dev/null+++ b/fluxer_api/pkgs/email/src/email_html/layouts/partials/head.mjml@@ -0,0 +1,40 @@+<mj-head>+ <mj-title>%%subject%%</mj-title>+ <mj-preview>%%preheader%%͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ ͏‌ </mj-preview>+ <mj-breakpoint width="480px" />+ <mj-attributes>+ <mj-all font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif" />+ <mj-section padding="0" text-align="[[start]]" />+ <mj-column padding="0" />+ </mj-attributes>+ <mj-raw>+ <meta name="color-scheme" content="light dark" />+ <meta name="supported-color-schemes" content="light dark" />+ <meta name="format-detection" content="telephone=no, date=no, address=no, email=no, url=no" />+ <meta name="x-apple-disable-message-reformatting" />+ </mj-raw>+ <mj-style>+ :root { color-scheme: light dark; supported-color-schemes: light dark; }+ body { margin: 0; padding: 0; word-spacing: normal; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }+ a { text-decoration: underline; }+ .x-btn { text-decoration: none !important; }+ @media only screen and (max-width: 480px) {+ .x-pad > table > tbody > tr > td { padding-left: 16px !important; padding-right: 16px !important; }+ }+ @media (prefers-color-scheme: dark) {+ .x-page, .x-page > [role="article"] { background-color: #121218 !important; }+ .x-ink { color: #ececf3 !important; }+ .x-muted { color: #a9a8bd !important; }+ .x-link { color: #b8b5ff !important; }+ .x-rule { border-color: #34334a !important; }+ .x-light { display: none !important; }+ .x-dark { display: block !important; max-height: none !important; overflow: visible !important; }+ }+ [data-ogsb] .x-page, [data-ogsb] .x-page > [role="article"] { background-color: #121218 !important; }+ [data-ogsc] .x-ink { color: #ececf3 !important; }+ [data-ogsc] .x-muted { color: #a9a8bd !important; }+ [data-ogsc] .x-link { color: #b8b5ff !important; }+ [data-ogsc] .x-light { display: none !important; }+ [data-ogsc] .x-dark { display: block !important; max-height: none !important; overflow: visible !important; }+ </mj-style>+</mj-head>diff --git a/fluxer_api/pkgs/email/src/email_html/layouts/partials/muted-row.mjml b/fluxer_api/pkgs/email/src/email_html/layouts/partials/muted-row.mjmlnew file mode 100644index 000000000..deb995832--- /dev/null+++ b/fluxer_api/pkgs/email/src/email_html/layouts/partials/muted-row.mjml@@ -0,0 +1,3 @@+%%?[[slot]]%%<tr>+ <td dir="[[dir]]" class="x-muted" style="padding:[[gap]] 0 0;font-family:[[font]];font-size:14px;line-height:21px;color:#5b5a70;text-align:[[start]];direction:[[dir]];overflow-wrap:anywhere;word-break:break-word">%%[[slot]]%%</td>+</tr>%%/[[slot]]%%diff --git a/fluxer_api/pkgs/email/src/email_html/layouts/partials/section.mjml b/fluxer_api/pkgs/email/src/email_html/layouts/partials/section.mjmlnew file mode 100644index 000000000..db34c59c0--- /dev/null+++ b/fluxer_api/pkgs/email/src/email_html/layouts/partials/section.mjml@@ -0,0 +1,9 @@+%%?section_[[n]]_title%%<tr>+ <td dir="[[dir]]" class="x-ink" style="padding:24px 0 0;font-family:[[font]];font-size:16px;line-height:24px;color:#1b1a2e;text-align:[[start]];direction:[[dir]];overflow-wrap:anywhere;word-break:break-word">+ <h2 class="x-ink" style="margin:0 0 4px;font-size:16px;line-height:24px;font-weight:700;color:#1b1a2e">%%section_[[n]]_title%%</h2>+ %%?section_[[n]]_body%%<div dir="auto" style="margin:0;text-align:start">%%section_[[n]]_body%%</div>%%/section_[[n]]_body%%+ %%?section_[[n]]_list%%<ul dir="auto" style="margin:0;padding-[[start]]:20px;text-align:start">%%section_[[n]]_list%%</ul>%%/section_[[n]]_list%%+ %%?section_[[n]]_note%%<div dir="auto" style="margin:8px 0 0;text-align:start">%%section_[[n]]_note%%</div>%%/section_[[n]]_note%%+ %%?section_[[n]]_link%%<p dir="auto" style="margin:8px 0 0;text-align:start"><a href="%%section_[[n]]_link_url%%" class="x-link" style="color:#4641d9">%%section_[[n]]_link%%</a></p>%%/section_[[n]]_link%%+ </td>+</tr>%%/section_[[n]]_title%%diff --git a/fluxer_api/pkgs/email/src/email_html/layouts/partials/text-row.mjml b/fluxer_api/pkgs/email/src/email_html/layouts/partials/text-row.mjmlnew file mode 100644index 000000000..3ef1f45b5--- /dev/null+++ b/fluxer_api/pkgs/email/src/email_html/layouts/partials/text-row.mjml@@ -0,0 +1,3 @@+%%?[[slot]]%%<tr>+ <td dir="[[dir]]" class="x-ink" style="padding:16px 0 0;font-family:[[font]];font-size:16px;line-height:24px;color:#1b1a2e;text-align:[[start]];direction:[[dir]];overflow-wrap:anywhere;word-break:break-word">%%[[slot]]%%</td>+</tr>%%/[[slot]]%%diff --git a/fluxer_api/pkgs/email/tsconfig.json b/fluxer_api/pkgs/email/tsconfig.jsonindex 97f2c7f13..7264291e6 100644--- a/fluxer_api/pkgs/email/tsconfig.json+++ b/fluxer_api/pkgs/email/tsconfig.json@@ -6,5 +6,5 @@"@pkgs/*": ["../*"]}},- "include": ["src/**/*"]+ "include": ["src/**/*", "scripts/**/*"]}