mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-07 00:17:03 +03:00
Image whitelist shortcuts as discussed in #201
This commit is contained in:
parent
7aa5142047
commit
69064e2ad0
3 changed files with 40 additions and 15 deletions
|
|
@ -150,8 +150,19 @@ export class MessageModel extends AbstractModel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return tagOptions
|
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();
|
this.showExternalImages();
|
||||||
}
|
}
|
||||||
if ('match' === SettingsUserStore.viewImages()) {
|
if ('match' === SettingsUserStore.viewImages()) {
|
||||||
let regex = SettingsUserStore.viewImagesWhitelist()
|
this.showExternalImages(1);
|
||||||
.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
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -386,6 +386,20 @@ export class MessageModel extends AbstractModel {
|
||||||
showExternalImages(regex) {
|
showExternalImages(regex) {
|
||||||
const body = this.body;
|
const body = this.body;
|
||||||
if (body && this.hasImages()) {
|
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,
|
let hasImages = false,
|
||||||
isValid = src => {
|
isValid = src => {
|
||||||
if (!regex || src.match(regex)) {
|
if (!regex || src.match(regex)) {
|
||||||
|
|
|
||||||
|
|
@ -499,6 +499,13 @@ export class MailMessageView extends AbstractViewRight {
|
||||||
currentMessage().showExternalImages();
|
currentMessage().showExternalImages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
whitelistText(txt) {
|
||||||
|
let value = (SettingsUserStore.viewImagesWhitelist().trim() + '\n' + txt).trim();
|
||||||
|
SettingsUserStore.viewImagesWhitelist(value);
|
||||||
|
Remote.saveSetting('ViewImagesWhitelist', value);
|
||||||
|
currentMessage().showExternalImages(1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -279,8 +279,12 @@
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="showImages" data-bind="visible: message().hasImages(), click: showImages"
|
<div class="showImages" data-bind="visible: message().hasImages()">
|
||||||
data-icon="🖼" data-i18n="MESSAGE/BUTTON_SHOW_IMAGES"></div>
|
<div class="btn" data-bind="click: showImages" data-icon="🖼" data-i18n="MESSAGE/BUTTON_SHOW_IMAGES"></div>
|
||||||
|
<div data-bind="foreach: message().whitelistOptions()">
|
||||||
|
<div class="btn" data-bind="click: $root.whitelistText, text: $data" data-icon="🖼"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="openpgp-control encrypted" data-bind="visible: message().pgpEncrypted(), css: {'success': message().pgpDecrypted()}">
|
<div class="openpgp-control encrypted" data-bind="visible: message().pgpEncrypted(), css: {'success': message().pgpDecrypted()}">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue