From a9a0aec375df8ef024af45250397e2ddd1b7bb4e Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Fri, 1 Jul 2022 09:00:27 +0200 Subject: [PATCH] =?UTF-8?q?fix(email):=20=F0=9F=90=9B=20Reply=20to=20name?= =?UTF-8?q?=20parsing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../typebots/[typebotId]/integrations/email.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/viewer/pages/api/typebots/[typebotId]/integrations/email.ts b/apps/viewer/pages/api/typebots/[typebotId]/integrations/email.ts index 2bdff9bda..ab29c3792 100644 --- a/apps/viewer/pages/api/typebots/[typebotId]/integrations/email.ts +++ b/apps/viewer/pages/api/typebots/[typebotId]/integrations/email.ts @@ -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)