From 66d3ffe7f3c0b731c9898746ae05a2c26e5fc64f Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Tue, 1 Nov 2022 12:54:45 +0800 Subject: [PATCH] Fix not correctly set confirmation code from Gmail in Spanish --- packages/inbound-email-handler/src/newsletter.ts | 4 ++-- .../inbound-email-handler/test/newsletter.test.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/inbound-email-handler/src/newsletter.ts b/packages/inbound-email-handler/src/newsletter.ts index 1f3294541..b3239f55d 100644 --- a/packages/inbound-email-handler/src/newsletter.ts +++ b/packages/inbound-email-handler/src/newsletter.ts @@ -10,7 +10,7 @@ interface Unsubscribe { const EMAIL_CONFIRMATION_CODE_RECEIVED_TOPIC = 'emailConfirmationCodeReceived' const CONFIRMATION_EMAIL_SENDER_ADDRESS = 'forwarding-noreply@google.com' // check unicode parentheses too -const CONFIRMATION_CODE_PATTERN = /^[((]#\d+[))]/u +const CONFIRMATION_CODE_PATTERN = /\d+/u const UNSUBSCRIBE_HTTP_URL_PATTERN = /<(https?:\/\/[^>]*)>/ const UNSUBSCRIBE_MAIL_TO_PATTERN = /]*)>/ @@ -55,7 +55,7 @@ export const getConfirmationCode = (subject: string): string | undefined => { if (matches) { // get the number code only // e.g. (#123456) => 123456 - return matches[0].slice(2, -1) + return matches[0] } return undefined } diff --git a/packages/inbound-email-handler/test/newsletter.test.ts b/packages/inbound-email-handler/test/newsletter.test.ts index 369cf9ab5..598b0a50d 100644 --- a/packages/inbound-email-handler/test/newsletter.test.ts +++ b/packages/inbound-email-handler/test/newsletter.test.ts @@ -25,6 +25,14 @@ describe('Confirmation email test', () => { expect(isConfirmationEmail(from, subject)).to.be.true }) + + it('returns true when email is in Spanish', () => { + from = 'Equipo de Gmail ' + subject = + 'Confirmación de reenvío de 123456789 (n.º Gmail) - Recibir correo de test@omnivore.app' + + expect(isConfirmationEmail(from, subject)).to.be.true + }) }) describe('#getConfirmationCode()', () => { @@ -44,6 +52,13 @@ describe('Confirmation email test', () => { expect(getConfirmationCode(subject)).to.equal(code) }) + + it('returns the confirmation code from the Spanish email', () => { + code = '123456789' + subject = `Confirmación de reenvío de ${code} (n.º Gmail) - Recibir correo de test@omnivore.app` + + expect(getConfirmationCode(subject)).to.equal(code) + }) }) })