Prefix draft header message IDs with the account ID to fix filtering of open tracking #1494

This commit is contained in:
Ben Gotow 2019-05-26 15:22:18 -05:00
parent 4dfe0a3f13
commit a38445c723
2 changed files with 16 additions and 6 deletions

View file

@ -3,6 +3,7 @@ import {
MessageViewExtension,
ComposerExtension,
RegExpUtils,
Message,
} from 'mailspring-exports';
const TrackingBlacklist = [
@ -128,7 +129,7 @@ const TrackingBlacklist = [
},
];
export function rejectImagesInBody(body, callback) {
export function rejectImagesInBody(body: string, callback: (url: string) => boolean) {
const spliceRegions = [];
const regex = RegExpUtils.imageTagRegex();
@ -148,7 +149,7 @@ export function rejectImagesInBody(body, callback) {
return updated;
}
export function removeTrackingPixels(message) {
export function removeTrackingPixels(message: Message) {
const isFromMe = message.isFromMe();
message.body = rejectImagesInBody(message.body, imageURL => {
@ -163,9 +164,10 @@ export function removeTrackingPixels(message) {
}
// Remove Mailspring read receipt pixels for the current account. If this is a
// reply, our read receipt could still be in the body and could trigger
// additional opens. (isFromMe is not sufficient!)
if (imageURL.indexOf(`getmailspring.com/open/${message.accountId}`) >= 0) {
// reply or a bounce, our read receipt could still be in the body and could
// trigger additional opens. (isFromMe is not sufficient!) [BG NOTE "HMID"]
const ownOpenURL = `getmailspring.com/open/${message.accountId}`.toLowerCase();
if (imageURL.toLowerCase().includes(ownOpenURL)) {
return true;
}
return false;

View file

@ -35,13 +35,21 @@ async function prepareBodyForQuoting(body) {
class DraftFactory {
async createDraft(fields = {}) {
const account = this._accountForNewDraft();
// create a UUID where the first segment is always the 8-digit account ID.
// Having a consistent accountID prefix is what allows us to ensure that you
// don't trigger your own open-tracked emails, for example. [BG NOTE "HMID"]
//
const auuid = uuidv4().toUpperCase().split('-')
auuid.splice(0, 1, account.id.toUpperCase())
const defaults = {
body: '<br/>',
subject: '',
version: 0,
unread: false,
starred: false,
headerMessageId: `${uuidv4().toUpperCase()}@getmailspring.com`,
headerMessageId: `${auuid.join('-')}@getmailspring.com`,
from: [account.defaultMe()],
date: new Date(),
draft: true,