From a38445c72336ce23cfed679d8034c482863886b2 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Sun, 26 May 2019 15:22:18 -0500 Subject: [PATCH] Prefix draft header message IDs with the account ID to fix filtering of open tracking #1494 --- .../remove-tracking-pixels/lib/main.ts | 12 +++++++----- app/src/flux/stores/draft-factory.ts | 10 +++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/internal_packages/remove-tracking-pixels/lib/main.ts b/app/internal_packages/remove-tracking-pixels/lib/main.ts index b1eecb627..75d290d32 100644 --- a/app/internal_packages/remove-tracking-pixels/lib/main.ts +++ b/app/internal_packages/remove-tracking-pixels/lib/main.ts @@ -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; diff --git a/app/src/flux/stores/draft-factory.ts b/app/src/flux/stores/draft-factory.ts index 026d9713f..4dae2f4d0 100644 --- a/app/src/flux/stores/draft-factory.ts +++ b/app/src/flux/stores/draft-factory.ts @@ -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: '
', 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,