fix: strip display names from EmailSubmission envelope addresses

This commit is contained in:
Linus Rath
2026-06-24 17:01:51 +02:00
parent 32f0a67dbc
commit 1119d8ed73
+6 -6
View File
@@ -459,8 +459,11 @@ function sanitizeIdentityDisplayName(name: string | undefined | null): string {
}
function normalizeEnvelopeRecipients(recipients?: Array<string | EmailAddress>): Array<{ email: string }> {
// The JMAP envelope rcptTo/mailFrom take a bare addr-spec, not an RFC 5322
// mailbox. `to`/`cc`/`bcc` may arrive as "Name <addr>"; strip the display
// name or the submission validator rejects the whole envelope (#…).
return (recipients || [])
.map((recipient) => typeof recipient === 'string' ? recipient : recipient.email)
.map((recipient) => typeof recipient === 'string' ? parseRecipientString(recipient).email : recipient.email)
.map((email) => email.trim())
.filter(Boolean)
.map((email) => ({ email }));
@@ -2388,13 +2391,10 @@ export class JMAPClient implements IJMAPClient {
const buildSubmissionCreate = (submissionId: string): Record<string, unknown> => {
const create: Record<string, unknown> = { emailId: `#${emailId}`, identityId: finalIdentityId };
if (holdForSeconds || envelopeMailFrom) {
const envelopeRecipients = [...to, ...(cc || []), ...(bcc || [])]
.map((email) => email.trim())
.filter(Boolean)
.map((email) => ({ email }));
const envelopeRecipients = normalizeEnvelopeRecipients([...to, ...(cc || []), ...(bcc || [])]);
create.envelope = {
mailFrom: {
email: envelopeMailFrom || fromEmail || this.username,
email: parseRecipientString(envelopeMailFrom || fromEmail || this.username).email,
...(holdForSeconds ? { parameters: { HOLDFOR: String(holdForSeconds) } } : {}),
},
rcptTo: envelopeRecipients,