diff --git a/internal_packages/remove-tracking-pixels/lib/main.es6 b/internal_packages/remove-tracking-pixels/lib/main.es6 index 59276abb6..186859e99 100644 --- a/internal_packages/remove-tracking-pixels/lib/main.es6 +++ b/internal_packages/remove-tracking-pixels/lib/main.es6 @@ -103,24 +103,17 @@ const TrackingBlacklist = [{ name: 'Salesloft', pattern: 'sdr.salesloft.com/email_trackers', homepage: 'http://salesloft.com', -}, { - name: 'Nylas', - pattern: 'nylas.com/open', - homepage: 'http://nylas.com/N1', }] -export function removeTrackingImagesFromBody(body) { +export function rejectImagesInBody(body, callback) { const spliceRegions = []; const regex = RegExpUtils.imageTagRegex(); // Identify img tags that should be cut let result = null; while ((result = regex.exec(body)) !== null) { - for (const item of TrackingBlacklist) { - if (result[1].indexOf(item.pattern) > 0) { - spliceRegions.push({start: result.index, end: result.index + result[0].length}) - continue; - } + if (callback(result[1])) { + spliceRegions.push({start: result.index, end: result.index + result[0].length}) } } // Remove them all, from the end of the string to the start @@ -132,17 +125,39 @@ export function removeTrackingImagesFromBody(body) { return updated; } +export function removeTrackingPixels(message) { + const isFromMe = message.isFromMe(); + + message.body = rejectImagesInBody(message.body, (imageURL) => { + if (isFromMe) { + // If the image is sent by the user, remove all forms of tracking pixels. + // They could be viewing an email they sent with Salesloft, etc. + for (const item of TrackingBlacklist) { + if (imageURL.indexOf(item.pattern) >= 0) { + return true; + } + } + } + + // Remove Nylas 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(`nylas.com/open/${message.accountId}`) >= 0) { + return true; + } + return false; + }); +} + class TrackingPixelsMessageExtension extends MessageViewExtension { static formatMessageBody = ({message}) => { - if (message.isFromMe()) { - message.body = removeTrackingImagesFromBody(message.body); - } + removeTrackingPixels(message); } } class TrackingPixelsComposerExtension extends ComposerExtension { static prepareNewDraft = ({draft}) => { - draft.body = removeTrackingImagesFromBody(draft.body); + removeTrackingPixels(draft); } } diff --git a/internal_packages/remove-tracking-pixels/spec/fixtures/a-after.txt b/internal_packages/remove-tracking-pixels/spec/fixtures/a-after.txt new file mode 100644 index 000000000..cdfc350e8 --- /dev/null +++ b/internal_packages/remove-tracking-pixels/spec/fixtures/a-after.txt @@ -0,0 +1,28 @@ +

Hey Ben,

+I've noticed that we don't yet have an SLA in place with Nylas. Are you the right +person to be speaking with to make sure everything is set up on that end? If not, +could you please put me in touch with them, so that we can get you guys set up +correctly as soon as possible?

Thanks!

Gleb Polyakov

Head of +Business Development and Growth

After Pixel + +

Sent from Nylas N1, the extensible, open source mail client.
+ On Apr 28 2016, at 2:14 pm, Ben Gotow (Careless) <careless@foundry376.com> wrote: +
+
+ nother mailA

Sent from Nylas N1, the extensible, open source mail client.
+ On Apr 28 2016, at 1:46 pm, Ben Gotow (Careless) <careless@foundry376.com> wrote: +
+
+ Hi Ben this is just a test.

Sent from Nylas N1, the extensible, open source mail client.
+ On Apr 26 2016, at 6:03 pm, Ben Gotow <bengotow@gmail.com> wrote: +
+
+

To test this, send https://www.google.com/search?q=test@example.com to yourself from a client that allows plaintext or html editing.

+


Ben Gotow
-----------------------------------
http://www.foundry376.com/
bengotow@gmail.com
540-250-2334

+
+
+
+
+
+
\ No newline at end of file diff --git a/internal_packages/remove-tracking-pixels/spec/fixtures/a-before.txt b/internal_packages/remove-tracking-pixels/spec/fixtures/a-before.txt new file mode 100644 index 000000000..fe1cb1371 --- /dev/null +++ b/internal_packages/remove-tracking-pixels/spec/fixtures/a-before.txt @@ -0,0 +1,28 @@ +

Hey Ben,

+I've noticed that we don't yet have an SLA in place with Nylas. Are you the right +person to be speaking with to make sure everything is set up on that end? If not, +could you please put me in touch with them, so that we can get you guys set up +correctly as soon as possible?

Thanks!

Gleb Polyakov

Head of +Business Development and Growth

After Pixel + +

Sent from Nylas N1, the extensible, open source mail client.
+ On Apr 28 2016, at 2:14 pm, Ben Gotow (Careless) <careless@foundry376.com> wrote: +
+
+ nother mailA

Sent from Nylas N1, the extensible, open source mail client.
+ On Apr 28 2016, at 1:46 pm, Ben Gotow (Careless) <careless@foundry376.com> wrote: +
+
+ Hi Ben this is just a test.

Sent from Nylas N1, the extensible, open source mail client.
+ On Apr 26 2016, at 6:03 pm, Ben Gotow <bengotow@gmail.com> wrote: +
+
+

To test this, send https://www.google.com/search?q=test@example.com to yourself from a client that allows plaintext or html editing.

+


Ben Gotow
-----------------------------------
http://www.foundry376.com/
bengotow@gmail.com
540-250-2334

+
+
+
+
+
+
diff --git a/internal_packages/remove-tracking-pixels/spec/fixtures/b-after.txt b/internal_packages/remove-tracking-pixels/spec/fixtures/b-after.txt new file mode 100644 index 000000000..9170d928a --- /dev/null +++ b/internal_packages/remove-tracking-pixels/spec/fixtures/b-after.txt @@ -0,0 +1,8 @@ +

Hey Ben,

+This is the reply! This tracking pixel should not be removed. + +

+This is the email I sent! + +
+ \ No newline at end of file diff --git a/internal_packages/remove-tracking-pixels/spec/fixtures/b-before.txt b/internal_packages/remove-tracking-pixels/spec/fixtures/b-before.txt new file mode 100644 index 000000000..21254075b --- /dev/null +++ b/internal_packages/remove-tracking-pixels/spec/fixtures/b-before.txt @@ -0,0 +1,8 @@ +

Hey Ben,

+This is the reply! This tracking pixel should not be removed. + +

+This is the email I sent! + +
+ diff --git a/internal_packages/remove-tracking-pixels/spec/tracking-pixels-extension-spec.es6 b/internal_packages/remove-tracking-pixels/spec/tracking-pixels-extension-spec.es6 index 313c8f296..8b60cfb1b 100644 --- a/internal_packages/remove-tracking-pixels/spec/tracking-pixels-extension-spec.es6 +++ b/internal_packages/remove-tracking-pixels/spec/tracking-pixels-extension-spec.es6 @@ -1,69 +1,35 @@ /* eslint no-irregular-whitespace: 0 */ -import {removeTrackingImagesFromBody} from '../lib/main'; +import {removeTrackingPixels} from '../lib/main'; +import fs from 'fs'; -const testBody = ` -

Hey Ben,

-I've noticed that we don't yet have an SLA in place with Nylas. Are you the right -person to be speaking with to make sure everything is set up on that end? If not, -could you please put me in touch with them, so that we can get you guys set up -correctly as soon as possible?

Thanks!

Gleb Polyakov

Head of -Business Development and Growth

After Pixel - -

Sent from Nylas N1, the extensible, open source mail client.
- On Apr 28 2016, at 2:14 pm, Ben Gotow (Careless) <careless@foundry376.com> wrote: -
-
- nother mailA

Sent from Nylas N1, the extensible, open source mail client.
- On Apr 28 2016, at 1:46 pm, Ben Gotow (Careless) <careless@foundry376.com> wrote: -
-
- Hi Ben this is just a test.

Sent from Nylas N1, the extensible, open source mail client.
- On Apr 26 2016, at 6:03 pm, Ben Gotow <bengotow@gmail.com> wrote: -
-
-

To test this, send https://www.google.com/search?q=test@example.com to yourself from a client that allows plaintext or html editing.

-


Ben Gotow
-----------------------------------
http://www.foundry376.com/
bengotow@gmail.com
540-250-2334

-
-
-
-
-
-
-` -const testBodyProcessed = ` -

Hey Ben,

-I've noticed that we don't yet have an SLA in place with Nylas. Are you the right -person to be speaking with to make sure everything is set up on that end? If not, -could you please put me in touch with them, so that we can get you guys set up -correctly as soon as possible?

Thanks!

Gleb Polyakov

Head of -Business Development and Growth

After Pixel - -

Sent from Nylas N1, the extensible, open source mail client.
- On Apr 28 2016, at 2:14 pm, Ben Gotow (Careless) <careless@foundry376.com> wrote: -
-
- nother mailA

Sent from Nylas N1, the extensible, open source mail client.
- On Apr 28 2016, at 1:46 pm, Ben Gotow (Careless) <careless@foundry376.com> wrote: -
-
- Hi Ben this is just a test.

Sent from Nylas N1, the extensible, open source mail client.
- On Apr 26 2016, at 6:03 pm, Ben Gotow <bengotow@gmail.com> wrote: -
-
-

To test this, send https://www.google.com/search?q=test@example.com to yourself from a client that allows plaintext or html editing.

-


Ben Gotow
-----------------------------------
http://www.foundry376.com/
bengotow@gmail.com
540-250-2334

-
-
-
-
-
-
-` +const readFixture = (name) => { + return fs.readFileSync(`${__dirname}/fixtures/${name}`).toString().trim() +} describe("TrackingPixelsExtension", () => { - it("should splice tracking pixels", () => { - expect(removeTrackingImagesFromBody(testBody)).toEqual(testBodyProcessed); + it("should splice all tracking pixels from emails I've sent", () => { + const before = readFixture('a-before.txt'); + const expected = readFixture('a-after.txt'); + + const message = { + body: before, + accountId: '1234', + isFromMe: () => true, + } + removeTrackingPixels(message); + expect(message.body).toEqual(expected); + }); + + it("should always splice Nylas read receipts for the current account id ", () => { + const before = readFixture('b-before.txt'); + const expected = readFixture('b-after.txt'); + + const message = { + body: before, + accountId: '1234', + isFromMe: () => false, + } + removeTrackingPixels(message); + expect(message.body).toEqual(expected); }); });