From 719b60b9ef9a77afaea1fc75fadad8914a543391 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Sat, 13 Sep 2025 16:23:39 +0200 Subject: [PATCH 1/2] Add defaultFromName config option and bump to v0.0.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add defaultFromName to MailingPluginConfig interface - Update MailingService to format from field with name when available - Add getDefaultFrom() helper method for consistent formatting - Format as "Name" when both name and email are provided - Bump version to 0.0.7 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- package.json | 2 +- src/services/MailingService.ts | 12 +++++++++--- src/types/index.ts | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 9a28427..2322fef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xtr-dev/payload-mailing", - "version": "0.0.6", + "version": "0.0.7", "description": "Template-based email system with scheduling and job processing for PayloadCMS", "type": "module", "main": "dist/index.js", diff --git a/src/services/MailingService.ts b/src/services/MailingService.ts index c76b1cd..610fb31 100644 --- a/src/services/MailingService.ts +++ b/src/services/MailingService.ts @@ -48,6 +48,12 @@ export class MailingService implements IMailingService { } } + private getDefaultFrom(): string { + const fromEmail = this.config.defaultFrom + const fromName = this.config.defaultFromName + return fromName && fromEmail ? `"${fromName}" <${fromEmail}>` : fromEmail || '' + } + private registerHandlebarsHelpers(): void { Handlebars.registerHelper('formatDate', (date: Date, format?: string) => { if (!date) return '' @@ -128,7 +134,7 @@ export class MailingService implements IMailingService { to: Array.isArray(options.to) ? options.to : [options.to], cc: options.cc ? (Array.isArray(options.cc) ? options.cc : [options.cc]) : undefined, bcc: options.bcc ? (Array.isArray(options.bcc) ? options.bcc : [options.bcc]) : undefined, - from: options.from || this.config.defaultFrom, + from: options.from || this.getDefaultFrom(), replyTo: options.replyTo, subject: subject || options.subject, html, @@ -245,7 +251,7 @@ export class MailingService implements IMailingService { }) as QueuedEmail let emailObject: EmailObject = { - from: email.from || this.config.defaultFrom, + from: email.from || this.getDefaultFrom(), to: email.to, cc: email.cc || undefined, bcc: email.bcc || undefined, @@ -262,7 +268,7 @@ export class MailingService implements IMailingService { } const mailOptions = { - from: emailObject.from || this.config.defaultFrom, + from: emailObject.from, to: emailObject.to, cc: emailObject.cc || undefined, bcc: emailObject.bcc || undefined, diff --git a/src/types/index.ts b/src/types/index.ts index eb30afb..8a7c3e4 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -22,6 +22,7 @@ export interface MailingPluginConfig { emails?: string | Partial } defaultFrom?: string + defaultFromName?: string transport?: Transporter | MailingTransportConfig queue?: string retryAttempts?: number 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 2/2] 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 {