mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Merge pull request #1377 from omnivore-app/fix/gmail-confirmation
Fix not correctly set confirmation code from Gmail in Spanish
This commit is contained in:
commit
142c022ccb
3 changed files with 27 additions and 12 deletions
|
|
@ -23,7 +23,7 @@ interface ForwardEmailMessage {
|
|||
html: string
|
||||
unsubMailTo?: string
|
||||
unsubHttpUrl?: string
|
||||
text?: string
|
||||
text: string
|
||||
forwardedFrom?: string
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ export function emailsServiceRouter() {
|
|||
logger.info('email forward router')
|
||||
|
||||
const { message, expired } = readPushSubscription(req)
|
||||
logger.info('pubsub message:', message, 'expired:', expired)
|
||||
logger.info('pubsub message:', { message, expired })
|
||||
|
||||
if (!message) {
|
||||
res.status(400).send('Bad Request')
|
||||
|
|
@ -45,7 +45,7 @@ export function emailsServiceRouter() {
|
|||
}
|
||||
|
||||
if (expired) {
|
||||
logger.log('discards expired message:', message)
|
||||
logger.info('discards expired message.')
|
||||
res.status(200).send('Expired')
|
||||
return
|
||||
}
|
||||
|
|
@ -58,9 +58,9 @@ export function emailsServiceRouter() {
|
|||
!('from' in data) ||
|
||||
!('to' in data) ||
|
||||
!('subject' in data) ||
|
||||
!('html' in data)
|
||||
(!('html' in data) && !('text' in data))
|
||||
) {
|
||||
logger.info('Invalid message')
|
||||
logger.error('Invalid message')
|
||||
res.status(400).send('Bad Request')
|
||||
return
|
||||
}
|
||||
|
|
@ -69,7 +69,7 @@ export function emailsServiceRouter() {
|
|||
const newsletterEmail = await getNewsletterEmail(data.to)
|
||||
|
||||
if (!newsletterEmail) {
|
||||
logger.info('newsletter email not found', data.to)
|
||||
logger.info('newsletter email not found', { email: data.to })
|
||||
res.status(200).send('Not Found')
|
||||
return
|
||||
}
|
||||
|
|
@ -83,12 +83,12 @@ export function emailsServiceRouter() {
|
|||
data.subject
|
||||
)
|
||||
) {
|
||||
logger.info('handling as article', data)
|
||||
logger.info('handling as article')
|
||||
await saveEmail(ctx, {
|
||||
title: getTitleFromEmailSubject(data.subject),
|
||||
author: parsedFrom.name,
|
||||
url: generateUniqueUrl(),
|
||||
originalContent: data.html,
|
||||
originalContent: data.html || data.text,
|
||||
})
|
||||
res.status(200).send('Article')
|
||||
return
|
||||
|
|
@ -113,8 +113,8 @@ export function emailsServiceRouter() {
|
|||
})
|
||||
|
||||
if (!result) {
|
||||
logger.info('Email not forwarded', data)
|
||||
res.status(200).send('Failed to send email')
|
||||
logger.error('Email not forwarded')
|
||||
res.status(500).send('Failed to send email')
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 = /<mailto:([^>]*)>/
|
||||
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <forwarding-noreply@google.com>'
|
||||
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)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue