From fa54c5622cd5726ba2772378fc8f2004baa1758f Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Sat, 13 Sep 2025 16:26:53 +0200 Subject: [PATCH] Improve email display name handling with proper escaping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add quote escaping in display names to prevent malformed email headers - Handle empty string defaultFromName by checking trim() - Prevent formatting when fromName is only whitespace - Example: John "The Boss" Doe becomes "John \"The Boss\" Doe" 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/services/MailingService.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/services/MailingService.ts b/src/services/MailingService.ts index 610fb31..fe4f5d5 100644 --- a/src/services/MailingService.ts +++ b/src/services/MailingService.ts @@ -51,7 +51,15 @@ export class MailingService implements IMailingService { private getDefaultFrom(): string { const fromEmail = this.config.defaultFrom const fromName = this.config.defaultFromName - return fromName && fromEmail ? `"${fromName}" <${fromEmail}>` : fromEmail || '' + + // Check if fromName exists, is not empty after trimming, and fromEmail exists + if (fromName && fromName.trim() && fromEmail) { + // Escape quotes in the display name to prevent malformed headers + const escapedName = fromName.replace(/"/g, '\\"') + return `"${escapedName}" <${fromEmail}>` + } + + return fromEmail || '' } private registerHandlebarsHelpers(): void {