mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-01 21:22:14 +08:00
Fix “disable images” occasionally showing images due to reuse/statefulness of Regexp.test
This commit is contained in:
parent
0086b2cf13
commit
250f880040
1 changed files with 17 additions and 5 deletions
|
@ -4,11 +4,7 @@ import path from 'path';
|
||||||
import { Utils, MessageBodyProcessor, CategoryStore } from 'mailspring-exports';
|
import { Utils, MessageBodyProcessor, CategoryStore } from 'mailspring-exports';
|
||||||
import * as AutoloadImagesActions from './autoload-images-actions';
|
import * as AutoloadImagesActions from './autoload-images-actions';
|
||||||
|
|
||||||
const ImagesRegexp = /((?:src|background|placeholder|icon|background|poster|srcset)\s*=\s*['"]?(?=\w*:\/\/)|:\s*url\()+([^"')]*)/gi;
|
|
||||||
|
|
||||||
class AutoloadImagesStore extends MailspringStore {
|
class AutoloadImagesStore extends MailspringStore {
|
||||||
ImagesRegexp = ImagesRegexp;
|
|
||||||
|
|
||||||
_whitelistEmails = {};
|
_whitelistEmails = {};
|
||||||
_whitelistMessageIds = {};
|
_whitelistMessageIds = {};
|
||||||
_whitelistEmailsPath = path.join(AppEnv.getConfigDirPath(), 'autoload-images-whitelist.txt');
|
_whitelistEmailsPath = path.join(AppEnv.getConfigDirPath(), 'autoload-images-whitelist.txt');
|
||||||
|
@ -26,6 +22,20 @@ class AutoloadImagesStore extends MailspringStore {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getImagesRegexp = () => {
|
||||||
|
// Matches:
|
||||||
|
// - src='....'
|
||||||
|
// - background="...."
|
||||||
|
// - background: url(....)
|
||||||
|
// - background: url(""...."")
|
||||||
|
// - @import url(....)
|
||||||
|
return /((?:src|background|placeholder|icon|poster|srcset)\s*=\s*['"]?(?=[cid:|\w*:\/\/])|(?::|@import)\s*url\(['"]?)+([^"')]*)/gi;
|
||||||
|
};
|
||||||
|
|
||||||
|
getLinkTagRegexp = () => {
|
||||||
|
return /<link [^>]+>/gi;
|
||||||
|
};
|
||||||
|
|
||||||
shouldBlockImagesIn = message => {
|
shouldBlockImagesIn = message => {
|
||||||
const spam = CategoryStore.getSpamCategory(message.accountId);
|
const spam = CategoryStore.getSpamCategory(message.accountId);
|
||||||
const spamFolderId = spam ? spam.id : undefined;
|
const spamFolderId = spam ? spam.id : undefined;
|
||||||
|
@ -40,7 +50,9 @@ class AutoloadImagesStore extends MailspringStore {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ImagesRegexp.test(message.body);
|
const containsImages = this.getImagesRegexp().test(message.body);
|
||||||
|
const containsLinkTags = this.getLinkTagRegexp().test(message.body);
|
||||||
|
return containsImages || containsLinkTags;
|
||||||
};
|
};
|
||||||
|
|
||||||
_loadWhitelist = () => {
|
_loadWhitelist = () => {
|
||||||
|
|
Loading…
Reference in a new issue