From 250f88004069fd02e3a1b7399093364562740506 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Wed, 15 Apr 2020 13:46:48 -0500 Subject: [PATCH] =?UTF-8?q?Fix=20=E2=80=9Cdisable=20images=E2=80=9D=20occa?= =?UTF-8?q?sionally=20showing=20images=20due=20to=20reuse/statefulness=20o?= =?UTF-8?q?f=20Regexp.test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/autoload-images-store.ts | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/app/internal_packages/message-autoload-images/lib/autoload-images-store.ts b/app/internal_packages/message-autoload-images/lib/autoload-images-store.ts index 931a9db0b..e0d5509f2 100644 --- a/app/internal_packages/message-autoload-images/lib/autoload-images-store.ts +++ b/app/internal_packages/message-autoload-images/lib/autoload-images-store.ts @@ -4,11 +4,7 @@ import path from 'path'; import { Utils, MessageBodyProcessor, CategoryStore } from 'mailspring-exports'; 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 { - ImagesRegexp = ImagesRegexp; - _whitelistEmails = {}; _whitelistMessageIds = {}; _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 /]+>/gi; + }; + shouldBlockImagesIn = message => { const spam = CategoryStore.getSpamCategory(message.accountId); const spamFolderId = spam ? spam.id : undefined; @@ -40,7 +50,9 @@ class AutoloadImagesStore extends MailspringStore { 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 = () => {