Image whitelist shortcuts as discussed in #201

This commit is contained in:
the-djmaze 2023-02-07 10:23:10 +01:00
parent 7aa5142047
commit 69064e2ad0
3 changed files with 40 additions and 15 deletions

View file

@ -150,8 +150,19 @@ export class MessageModel extends AbstractModel {
}
});
return tagOptions
}
},
whitelistOptions: () => {
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));
}
return options.unique();
}
});
}
@ -283,18 +294,7 @@ export class MessageModel extends AbstractModel {
this.showExternalImages();
}
if ('match' === SettingsUserStore.viewImages()) {
let regex = SettingsUserStore.viewImagesWhitelist()
.trim()
.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&')
.replace(/[\s\r\n,;:]+/g, '|')
.replace(/\|+/g, '|');
if (regex.length) {
console.log('whitelist images = '+regex);
regex = new RegExp(regex);
this.showExternalImages(
(this.from[0]?.email.match(regex)/* || this.sender[0]?.email.match(regex)*/) ? null : regex
);
}
this.showExternalImages(1);
}
}
@ -386,6 +386,20 @@ export class MessageModel extends AbstractModel {
showExternalImages(regex) {
const body = this.body;
if (body && this.hasImages()) {
if (regex) {
regex = SettingsUserStore.viewImagesWhitelist()
.trim()
.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&')
.replace(/[\s\r\n,;:]+/g, '|')
.replace(/\|+/g, '|');
if (regex) {
console.log('whitelist images = '+regex);
regex = new RegExp(regex);
if (this.from[0]?.email.match(regex)) {
regex = 0;
}
}
}
let hasImages = false,
isValid = src => {
if (!regex || src.match(regex)) {