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:
2025-09-13 16:26:53 +02:00
parent 719b60b9ef
commit fa54c5622c

View File

@@ -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 {