mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-07 00:17:03 +03:00
Moved handling of images using proxy in preperation of #491
This commit is contained in:
parent
f41559ae2f
commit
aff2d4dd76
2 changed files with 56 additions and 51 deletions
|
|
@ -39,7 +39,6 @@ export const
|
||||||
cleanHtml = (html, oAttachments, removeColors) => {
|
cleanHtml = (html, oAttachments, removeColors) => {
|
||||||
const
|
const
|
||||||
debug = false, // Config()->Get('debug', 'enable', false);
|
debug = false, // Config()->Get('debug', 'enable', false);
|
||||||
useProxy = !!SettingsGet('UseLocalProxyForExternalImages'),
|
|
||||||
detectHiddenImages = true, // !!SettingsGet('try_to_detect_hidden_images'),
|
detectHiddenImages = true, // !!SettingsGet('try_to_detect_hidden_images'),
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
|
|
@ -229,48 +228,52 @@ export const
|
||||||
value = getAttribute('src');
|
value = getAttribute('src');
|
||||||
delAttribute('src');
|
delAttribute('src');
|
||||||
|
|
||||||
let attachment;
|
if ('IMG' === name) {
|
||||||
|
let attachment;
|
||||||
if (detectHiddenImages
|
if (detectHiddenImages
|
||||||
&& 'IMG' === name
|
&& (('' != getAttribute('height') && 3 > pInt(getAttribute('height')))
|
||||||
&& (('' != getAttribute('height') && 3 > pInt(getAttribute('height')))
|
|| ('' != getAttribute('width') && 3 > pInt(getAttribute('width')))
|
||||||
|| ('' != getAttribute('width') && 3 > pInt(getAttribute('width')))
|
|| [
|
||||||
|| [
|
'email.microsoftemail.com/open',
|
||||||
'email.microsoftemail.com/open',
|
'github.com/notifications/beacon/',
|
||||||
'github.com/notifications/beacon/',
|
'mandrillapp.com/track/open',
|
||||||
'mandrillapp.com/track/open',
|
'list-manage.com/track/open'
|
||||||
'list-manage.com/track/open'
|
].filter(uri => value.toLowerCase().includes(uri)).length
|
||||||
].filter(uri => value.toLowerCase().includes(uri)).length
|
)) {
|
||||||
)) {
|
skipStyle = true;
|
||||||
skipStyle = true;
|
setAttribute('style', 'display:none');
|
||||||
setAttribute('style', 'display:none');
|
setAttribute('data-x-hidden-src', value);
|
||||||
setAttribute('data-x-hidden-src', value);
|
|
||||||
}
|
|
||||||
else if ((attachment = findLocationByCid(value)))
|
|
||||||
{
|
|
||||||
if (attachment.download) {
|
|
||||||
oElement.loading = 'lazy';
|
|
||||||
oElement.src = attachment.linkPreview();
|
|
||||||
attachment.isLinked(true);
|
|
||||||
}
|
}
|
||||||
}
|
else if ((attachment = findLocationByCid(value)))
|
||||||
else if ('cid:' === value.slice(0, 4))
|
{
|
||||||
{
|
if (attachment.download) {
|
||||||
attachment = findAttachmentByCid(value.slice(4));
|
oElement.loading = 'lazy';
|
||||||
if (attachment && attachment.download) {
|
oElement.src = attachment.linkPreview();
|
||||||
oElement.src = attachment.linkPreview();
|
attachment.isLinked(true);
|
||||||
attachment.isInline(true);
|
}
|
||||||
attachment.isLinked(true);
|
}
|
||||||
|
else if ('cid:' === value.slice(0, 4))
|
||||||
|
{
|
||||||
|
attachment = findAttachmentByCid(value.slice(4));
|
||||||
|
if (attachment && attachment.download) {
|
||||||
|
oElement.src = attachment.linkPreview();
|
||||||
|
attachment.isInline(true);
|
||||||
|
attachment.isLinked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (/^(https?:)?\/\//i.test(value))
|
||||||
|
{
|
||||||
|
setAttribute('data-x-src', value);
|
||||||
|
result.hasExternals = true;
|
||||||
|
}
|
||||||
|
else if ('data:image/' === value.slice(0, 11))
|
||||||
|
{
|
||||||
|
setAttribute('src', value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setAttribute('data-x-broken-src', value);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (/^(https?:)?\/\//i.test(value))
|
|
||||||
{
|
|
||||||
setAttribute('data-x-src', useProxy ? proxy(value) : value);
|
|
||||||
result.hasExternals = true;
|
|
||||||
}
|
|
||||||
else if ('data:image/' === value.slice(0, 11))
|
|
||||||
{
|
|
||||||
setAttribute('src', value);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -323,7 +326,7 @@ export const
|
||||||
}
|
}
|
||||||
} else if (/^(https?:)?\/\//.test(lowerUrl)) {
|
} else if (/^(https?:)?\/\//.test(lowerUrl)) {
|
||||||
result.hasExternals = true;
|
result.hasExternals = true;
|
||||||
urls_remote.push([property, useProxy ? proxy(found) : value]);
|
urls_remote.push([property, found]);
|
||||||
} else if ('data:image/' === lowerUrl.slice(0, 11)) {
|
} else if ('data:image/' === lowerUrl.slice(0, 11)) {
|
||||||
oStyle[property] = value;
|
oStyle[property] = value;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@ import ko from 'ko';
|
||||||
import { MessagePriority } from 'Common/EnumsUser';
|
import { MessagePriority } from 'Common/EnumsUser';
|
||||||
import { i18n } from 'Common/Translator';
|
import { i18n } from 'Common/Translator';
|
||||||
|
|
||||||
import { doc } from 'Common/Globals';
|
import { doc, SettingsGet } from 'Common/Globals';
|
||||||
import { encodeHtml, plainToHtml, cleanHtml } from 'Common/Html';
|
import { encodeHtml, plainToHtml, cleanHtml } from 'Common/Html';
|
||||||
import { isArray, arrayLength, forEachObjectEntry } from 'Common/Utils';
|
import { isArray, arrayLength, forEachObjectEntry } from 'Common/Utils';
|
||||||
import { serverRequestRaw } from 'Common/Links';
|
import { serverRequestRaw, proxy } from 'Common/Links';
|
||||||
|
|
||||||
import { FolderUserStore } from 'Stores/User/Folder';
|
import { FolderUserStore } from 'Stores/User/Folder';
|
||||||
import { SettingsUserStore } from 'Stores/User/Settings';
|
import { SettingsUserStore } from 'Stores/User/Settings';
|
||||||
|
|
@ -606,16 +606,18 @@ export class MessageModel extends AbstractModel {
|
||||||
this.hasImages(false);
|
this.hasImages(false);
|
||||||
body.rlHasImages = false;
|
body.rlHasImages = false;
|
||||||
|
|
||||||
let attr = 'data-x-src';
|
let attr = 'data-x-src',
|
||||||
body.querySelectorAll('[' + attr + ']').forEach(node => {
|
src, useProxy = !!SettingsGet('UseLocalProxyForExternalImages');
|
||||||
if (node.matches('img')) {
|
body.querySelectorAll('img[' + attr + ']').forEach(node => {
|
||||||
node.loading = 'lazy';
|
node.loading = 'lazy';
|
||||||
}
|
src = node.getAttribute(attr);
|
||||||
node.src = node.getAttribute(attr);
|
node.src = useProxy ? proxy(src) : src;
|
||||||
});
|
});
|
||||||
|
|
||||||
body.querySelectorAll('[data-x-style-url]').forEach(node => {
|
body.querySelectorAll('[data-x-style-url]').forEach(node => {
|
||||||
JSON.parse(node.dataset.xStyleUrl).forEach(data => node.style[data[0]] = "url('" + data[1] + "')");
|
JSON.parse(node.dataset.xStyleUrl).forEach(data =>
|
||||||
|
node.style[data[0]] = "url('" + (useProxy ? proxy(data[1]) : data[1]) + "')"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue