Add null check on email body to prevent cheerio exception (#2298)

This commit is contained in:
Janosch Maier 2021-03-26 16:02:08 +01:00 committed by GitHub
parent 187ba07206
commit f8b8bff5db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -66,11 +66,15 @@ interface UnsubscribeAction {
}
function bestUnsubscribeLink(message): string {
const dom = cheerio.load(message.body);
const links = _getLinks(dom);
let result = null;
// Only check the body if it has been downloaded already
if (message.body) {
const dom = cheerio.load(message.body);
const links = _getLinks(dom);
for (const link of links) {
for (const re of regexps) {
if (re.test(link.href)) {
@ -86,6 +90,8 @@ function bestUnsubscribeLink(message): string {
}
}
}
return result;
}