mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-28 03:29:20 +03:00
Resolve #1225 by using optional link tracking
This commit is contained in:
parent
d2c59d2e1c
commit
d55ce60cc5
42 changed files with 153 additions and 46 deletions
|
|
@ -208,6 +208,7 @@ export const
|
|||
|
||||
result = {
|
||||
hasExternals: false,
|
||||
tracking: false,
|
||||
linkedData: []
|
||||
},
|
||||
|
||||
|
|
@ -398,10 +399,14 @@ export const
|
|||
if ('A' === name) {
|
||||
value = oElement.href;
|
||||
if (!/^([a-z]+):/i.test(value)) {
|
||||
setAttribute('data-x-broken-href', value);
|
||||
setAttribute('data-x-href-broken', value);
|
||||
delAttribute('href');
|
||||
} else {
|
||||
oElement.href = stripTracking(value);
|
||||
if (oElement.href != value) {
|
||||
result.tracking = true;
|
||||
setAttribute('data-x-href-tracking', value);
|
||||
}
|
||||
setAttribute('target', '_blank');
|
||||
// setAttribute('rel', 'external nofollow noopener noreferrer');
|
||||
}
|
||||
|
|
@ -423,9 +428,8 @@ export const
|
|||
*/
|
||||
|
||||
let skipStyle = false;
|
||||
if (hasAttribute('src')) {
|
||||
value = stripTracking(delAttribute('src'));
|
||||
|
||||
value = delAttribute('src');
|
||||
if (value) {
|
||||
if ('IMG' === name) {
|
||||
oElement.loading = 'lazy';
|
||||
let attachment;
|
||||
|
|
@ -462,12 +466,18 @@ export const
|
|||
oStyle.display = 'none';
|
||||
// setAttribute('style', 'display:none');
|
||||
setAttribute('data-x-src-hidden', value);
|
||||
// result.tracking = true;
|
||||
}
|
||||
else if (httpre.test(value))
|
||||
{
|
||||
setAttribute('data-x-src', value);
|
||||
let src = stripTracking(value);
|
||||
if (src != value) {
|
||||
result.tracking = true;
|
||||
setAttribute('data-x-src-tracking', value);
|
||||
}
|
||||
setAttribute('data-x-src', src);
|
||||
result.hasExternals = true;
|
||||
oElement.alt || (oElement.alt = value.replace(/^.+\/([^/?]+).*$/, '$1').slice(-20));
|
||||
oElement.alt || (oElement.alt = src.replace(/^.+\/([^/?]+).*$/, '$1').slice(-20));
|
||||
}
|
||||
else if (value.startsWith('data:image/'))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@ export class MessageModel extends AbstractModel {
|
|||
isHtml: false,
|
||||
hasImages: false,
|
||||
hasExternals: false,
|
||||
hasTracking: false,
|
||||
|
||||
pgpSigned: null,
|
||||
pgpVerified: null,
|
||||
|
|
@ -373,6 +374,7 @@ export class MessageModel extends AbstractModel {
|
|||
let result = msgHtml(this);
|
||||
this.hasExternals(result.hasExternals);
|
||||
this.hasImages(!!result.hasExternals);
|
||||
this.hasTracking(!!result.tracking);
|
||||
this.linkedData = result.linkedData;
|
||||
body.innerHTML = result.html;
|
||||
if (!this.isSpam && FolderUserStore.spamFolder() != this.folder) {
|
||||
|
|
|
|||
|
|
@ -109,7 +109,8 @@ export class MailMessageView extends AbstractViewRight {
|
|||
actionsMenu: null,
|
||||
// viewer
|
||||
viewFromShort: '',
|
||||
dkimData: ['none', '', '']
|
||||
dkimData: ['none', '', ''],
|
||||
nowTracking: false
|
||||
});
|
||||
|
||||
this.moveAction = moveAction;
|
||||
|
|
@ -208,6 +209,7 @@ export class MailMessageView extends AbstractViewRight {
|
|||
// TODO: make first param a user setting #683
|
||||
this.viewFromShort(message.from.toString(false, true));
|
||||
this.dkimData(message.dkim[0] || ['none', '', '']);
|
||||
this.nowTracking(false);
|
||||
} else {
|
||||
MessagelistUserStore.selectedMessage(null);
|
||||
|
||||
|
|
@ -500,6 +502,17 @@ export class MailMessageView extends AbstractViewRight {
|
|||
currentMessage().showExternalImages();
|
||||
}
|
||||
|
||||
showTracking() {
|
||||
const msg = currentMessage(), body = msg?.body;
|
||||
if (body && msg.hasTracking()) {
|
||||
let attr = 'data-x-href-tracking';
|
||||
body.querySelectorAll('a['+attr+']').forEach(node => node.href = node.getAttribute(attr));
|
||||
// attr = 'data-x-src-tracking';
|
||||
// body.querySelectorAll('img['+attr+']').forEach(node => node.src = node.getAttribute(attr));
|
||||
this.nowTracking(true);
|
||||
}
|
||||
}
|
||||
|
||||
whitelistText(txt) {
|
||||
let value = (SettingsUserStore.viewImagesWhitelist().trim() + '\n' + txt).trim();
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue