2
0

fix(email): 🐛 Reply to name parsing

This commit is contained in:
Baptiste Arnaud
2022-07-01 09:00:27 +02:00
parent db9a314b9f
commit a9a0aec375

View File

@ -67,7 +67,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
resultValues: ResultValues
fileUrls?: string
}
const replyToName = replyTo?.split(' <')[0].replace(/"/g, '')
const { name: replyToName } = parseEmailRecipient(replyTo)
const { host, port, isTlsEnabled, username, password, from } =
(await getEmailInfo(credentialsId)) ?? {}
@ -191,4 +191,20 @@ const getEmailBody = async ({
}
}
const parseEmailRecipient = (
recipient?: string
): { email?: string; name?: string } => {
if (!recipient) return {}
if (recipient.includes('<')) {
const [name, email] = recipient.split('<')
return {
name: name.replace(/>/g, '').trim().replace(/"/g, ''),
email: email.replace('>', '').trim(),
}
}
return {
email: recipient,
}
}
export default withSentry(handler)