mirror of
https://github.com/xtr-dev/payload-mailing.git
synced 2025-12-10 00:03:23 +00:00
Improve email display name handling with proper escaping
- 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" <email> 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -51,7 +51,15 @@ export class MailingService implements IMailingService {
|
|||||||
private getDefaultFrom(): string {
|
private getDefaultFrom(): string {
|
||||||
const fromEmail = this.config.defaultFrom
|
const fromEmail = this.config.defaultFrom
|
||||||
const fromName = this.config.defaultFromName
|
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 {
|
private registerHandlebarsHelpers(): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user