Merge pull request #1840 from omnivore-app/fix/unsubscribe

Fix confusing unsubscribing url with email address
This commit is contained in:
Hongbo Wu
2023-02-27 13:42:25 +08:00
committed by GitHub
2 changed files with 33 additions and 2 deletions

View File

@ -150,8 +150,8 @@ export abstract class ContentHandler {
// e.g. List-Unsubscribe: <https://omnivore.com/unsub>, <mailto:unsub@omnivore.com>
const decoded = rfc2047.decode(unSubHeader)
return {
mailTo: decoded.match(/<(https?:\/\/[^>]*)>/)?.[1],
httpUrl: decoded.match(/<mailto:([^>]*)>/)?.[1],
httpUrl: decoded.match(/<(https?:\/\/[^>]*)>/)?.[1],
mailTo: decoded.match(/<mailto:([^>]*)>/)?.[1],
}
}

View File

@ -516,4 +516,35 @@ describe('Newsletter email test', () => {
expect(url1).to.not.eql(url2)
})
})
describe('get unsubscribe from header', () => {
const mailTo = 'unsub@omnivore.com'
const httpUrl = 'https://omnivore.com/unsubscribe'
it('returns mail to address if exists', () => {
const header = `<https://omnivore.com/unsub>, <mailto:${mailTo}>`
expect(new GenericHandler().parseUnsubscribe(header).mailTo).to.equal(
mailTo
)
})
it('returns http url if exists', () => {
const header = `<${httpUrl}>`
expect(new GenericHandler().parseUnsubscribe(header).httpUrl).to.equal(
httpUrl
)
})
context('when unsubscribe header rfc2047 encoded', () => {
it('returns mail to address if exists', () => {
const header = `=?us-ascii?Q?=3Cmailto=3A654e9594-184c-4884-8e02-e6e58a3a6871+87e39b3d-c3ca-4be?= =?us-ascii?Q?b-ba4d-977cc2ba61e7+067a353f-f775-4f2c-?= =?us-ascii?Q?a5cc-978df38deeca=40unsub=2Ebeehiiv=2Ecom=3E=2C?= =?us-ascii?Q?_=3Chttps=3A=2F=2Fwww=2Emilkroad=2Ecom=2Fsubscribe=2F87e39b3d-c3ca-4beb-ba4d-97?= =?us-ascii?Q?7cc2ba61e7=2Fmanage=3Fpost=5Fid=3D067a353f-f775?= =?us-ascii?Q?-4f2c-a5cc-978df38deeca=3E?=',`
expect(new GenericHandler().parseUnsubscribe(header).mailTo).to.equal(
'654e9594-184c-4884-8e02-e6e58a3a6871+87e39b3d-c3ca-4beb-ba4d-977cc2ba61e7+067a353f-f775-4f2c-a5cc-978df38deeca@unsub.beehiiv.com'
)
})
})
})
})