From 85d3a95dec9f1ab0efd2908c53bd5645c26539bc Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Wed, 8 Feb 2023 11:39:07 +0100 Subject: [PATCH] Message whitelist #201: * sort options based on domain count (highest top) * hide when whitelist not active --- dev/Model/Message.js | 22 ++++++++++++++----- dev/View/User/MailBox/MessageView.js | 2 ++ .../templates/Views/User/MailMessageView.html | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/dev/Model/Message.js b/dev/Model/Message.js index bd6388051f..d7d4e54bf2 100644 --- a/dev/Model/Message.js +++ b/dev/Model/Message.js @@ -156,12 +156,24 @@ export class MessageModel extends AbstractModel { let options = []; if ('match' === SettingsUserStore.viewImages()) { let from = this.from[0], - list = SettingsUserStore.viewImagesWhitelist(); - from && options.push(from.email); - this.html().match(/src=["'][^"']+/g)?.forEach(m => options.push(m.replace(/^.+(:\/\/[^/]+).+$/, '$1'))); - options = options.filter(txt => !list.includes(txt)); + list = SettingsUserStore.viewImagesWhitelist(), + counts = {}; + this.html().match(/src=["'][^"']+/g)?.forEach(m => { + m = m.replace(/^.+(:\/\/[^/]+).+$/, '$1'); + if (counts[m]) { + ++counts[m]; + } else { + counts[m] = 1; + options.push(m); + } + }); + options = options.filter(txt => !list.includes(txt)).sort((a,b) => (counts[a] < counts[b]) + ? 1 + : (counts[a] > counts[b] ? -1 : a.localeCompare(b)) + ); + from && options.unshift(from.email); } - return options.unique(); + return options; } }); } diff --git a/dev/View/User/MailBox/MessageView.js b/dev/View/User/MailBox/MessageView.js index b3e6002ebd..98d7161e50 100644 --- a/dev/View/User/MailBox/MessageView.js +++ b/dev/View/User/MailBox/MessageView.js @@ -193,6 +193,8 @@ export class MailMessageView extends AbstractViewRight { return ''; }, + showWhitelistOptions: () => 'match' === SettingsUserStore.viewImages(), + firstUnsubsribeLink: () => currentMessage()?.unsubsribeLinks()[0] || '', pgpSupported: () => currentMessage() && PgpUserStore.isSupported(), diff --git a/snappymail/v/0.0.0/app/templates/Views/User/MailMessageView.html b/snappymail/v/0.0.0/app/templates/Views/User/MailMessageView.html index 68a3d1b1dc..07d236c4e6 100644 --- a/snappymail/v/0.0.0/app/templates/Views/User/MailMessageView.html +++ b/snappymail/v/0.0.0/app/templates/Views/User/MailMessageView.html @@ -281,7 +281,7 @@