mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-03-02 02:53:01 +08:00
Add null check on email body to prevent cheerio exception (#2298)
This commit is contained in:
parent
187ba07206
commit
f8b8bff5db
1 changed files with 19 additions and 13 deletions
|
@ -66,24 +66,30 @@ interface UnsubscribeAction {
|
|||
}
|
||||
|
||||
function bestUnsubscribeLink(message): string {
|
||||
const dom = cheerio.load(message.body);
|
||||
const links = _getLinks(dom);
|
||||
|
||||
let result = null;
|
||||
|
||||
for (const link of links) {
|
||||
for (const re of regexps) {
|
||||
if (re.test(link.href)) {
|
||||
// If the URL contains e.g. "unsubscribe" we assume that we have correctly
|
||||
// detected the unsubscribe link.
|
||||
return link.href;
|
||||
}
|
||||
if (re.test(link.innerText)) {
|
||||
// If the URL does not contain "unsubscribe", but the text around the link contains
|
||||
// it, it is a possible candidate, we we still check all other links for a better match
|
||||
result = link.href;
|
||||
// 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)) {
|
||||
// If the URL contains e.g. "unsubscribe" we assume that we have correctly
|
||||
// detected the unsubscribe link.
|
||||
return link.href;
|
||||
}
|
||||
if (re.test(link.innerText)) {
|
||||
// If the URL does not contain "unsubscribe", but the text around the link contains
|
||||
// it, it is a possible candidate, we we still check all other links for a better match
|
||||
result = link.href;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
Loading…
Reference in a new issue