mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 09:38:54 +00:00
fix(notifications): show the header logo in Gmail and Outlook (#2507)
The logo at the top of every TREK mail was an SVG inlined into the HTML as a data: URI. Gmail strips data: URIs, Outlook blocks them and neither renders SVG, so notification and password-reset mails showed a broken image with "TREK" as its alt text. The image data itself was fine; it only rendered in clients that accept both data: URIs and SVG, such as Apple Mail. The logo is now a 96x96 PNG, rasterized from client/public/icons/icon.svg with the corner radius baked in, and MailerService attaches it to both HTML sends as an inline part. The header img points at it by cid:, so nodemailer puts the HTML and the image into multipart/related. That is the form Gmail, Outlook and Apple Mail all display, and it does not depend on the instance being reachable from the recipient's mail provider. The plain-text admin test mail carries no HTML and stays without an attachment.
This commit is contained in:
@@ -267,3 +267,61 @@ describe('MailerService test send', () => {
|
||||
expect(lines.some(line => line.includes('SMTP test email sent to=admin@example.com smtp=mail.internal.example:587'))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('MailerService header logo (#2507)', () => {
|
||||
interface SentAttachment {
|
||||
cid?: string;
|
||||
contentType?: string;
|
||||
contentDisposition?: string;
|
||||
content?: Buffer;
|
||||
}
|
||||
|
||||
/** The options object of the most recent sendMail() call. */
|
||||
function lastMail(): { html?: string; attachments?: SentAttachment[] } {
|
||||
const calls = sendMail.mock.calls;
|
||||
return calls[calls.length - 1][0] as { html?: string; attachments?: SentAttachment[] };
|
||||
}
|
||||
|
||||
/**
|
||||
* The attachment the HTML's header image resolves to. Before #2507 the logo was
|
||||
* an SVG data: URI, which Gmail strips and Outlook blocks; it has to be a PNG
|
||||
* part inside the message, marked inline and addressed by Content-ID.
|
||||
*/
|
||||
function expectLogoResolves(mail: { html?: string; attachments?: SentAttachment[] }): void {
|
||||
const cid = /<img src="cid:([^"]+)"/.exec(mail.html ?? '')?.[1];
|
||||
expect(cid).toBeTruthy();
|
||||
const logo = mail.attachments?.find(a => a.cid === cid);
|
||||
expect(logo).toBeDefined();
|
||||
expect(logo!.contentType).toBe('image/png');
|
||||
expect(logo!.contentDisposition).toBe('inline');
|
||||
const png = logo!.content!;
|
||||
expect(png.subarray(0, 8).toString('hex')).toBe('89504e470d0a1a0a');
|
||||
// IHDR width and height: twice the 48px the header shows it at.
|
||||
expect([png.readUInt32BE(16), png.readUInt32BE(20)]).toEqual([96, 96]);
|
||||
}
|
||||
|
||||
it('MAILER-015: a notification mail carries the logo its HTML points to', async () => {
|
||||
configureSmtp();
|
||||
|
||||
expect(await newMailer().sendEmail('someone@example.com', 'Subject', 'Body')).toBe(true);
|
||||
|
||||
expectLogoResolves(lastMail());
|
||||
});
|
||||
|
||||
it('MAILER-016: the password-reset mail carries it too', async () => {
|
||||
configureSmtp();
|
||||
|
||||
expect((await newMailer().sendPasswordResetEmail('someone@example.com', 'https://trek.example/reset', null)).delivered).toBe('email');
|
||||
|
||||
expectLogoResolves(lastMail());
|
||||
});
|
||||
|
||||
it('MAILER-017: the plain-text test mail has no HTML, so it carries no logo either', async () => {
|
||||
configureSmtp();
|
||||
|
||||
await newMailer().testSmtp('admin@example.com');
|
||||
|
||||
expect(lastMail().html).toBeUndefined();
|
||||
expect(lastMail().attachments).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -232,6 +232,14 @@ describe('buildEmailHtml', () => {
|
||||
// Both should have the same footer text
|
||||
expect(unknown).toContain('notifications enabled in TREK');
|
||||
});
|
||||
|
||||
it('points the header logo at an inline part by Content-ID, not at a data: URI (#2507)', () => {
|
||||
const html = buildEmailHtml('Subject', 'Body', 'en');
|
||||
// Gmail strips data: URIs and Outlook blocks them, which left a broken image
|
||||
// in the header of every mail.
|
||||
expect(html).not.toContain('data:');
|
||||
expect(html).toMatch(/<img src="cid:[^"]+" alt="TREK" width="48" height="48"/);
|
||||
});
|
||||
});
|
||||
|
||||
// ── SEC: XSS escaping in buildEmailHtml ──────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user