mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 12:40:08 +08:00
1bd3fc74e9
Summary: Add specs to test the components of open tracking and link tracking. Notably does not test the overall functionality, which still needs specs. Test Plan: adds specs Reviewers: juan, evan, bengotow Reviewed By: evan, bengotow Differential Revision: https://phab.nylas.com/D2667
36 lines
1.3 KiB
JavaScript
36 lines
1.3 KiB
JavaScript
import {ComposerExtension, QuotedHTMLTransformer} from 'nylas-exports';
|
|
import {PLUGIN_ID, PLUGIN_URL} from './open-tracking-constants';
|
|
|
|
|
|
class DraftBody {
|
|
constructor(draft) {this._body = draft.body}
|
|
get unquoted() {return QuotedHTMLTransformer.removeQuotedHTML(this._body);}
|
|
set unquoted(text) {this._body = QuotedHTMLTransformer.appendQuotedHTML(text, this._body);}
|
|
get body() {return this._body}
|
|
}
|
|
|
|
export default class OpenTrackingComposerExtension extends ComposerExtension {
|
|
static finalizeSessionBeforeSending({session}) {
|
|
const draft = session.draft();
|
|
|
|
// grab message metadata, if any
|
|
const metadata = draft.metadataForPluginId(PLUGIN_ID);
|
|
if (!metadata) {
|
|
return;
|
|
}
|
|
|
|
if (!metadata.uid) {
|
|
NylasEnv.reportError(new Error("Open tracking composer extension could not find 'uid' in metadata!"));
|
|
return;
|
|
}
|
|
|
|
// insert a tracking pixel <img> into the message
|
|
const serverUrl = `${PLUGIN_URL}/open/${draft.accountId}/${metadata.uid}`;
|
|
const img = `<img width="0" height="0" style="border:0; width:0; height:0;" src="${serverUrl}">`;
|
|
const draftBody = new DraftBody(draft);
|
|
draftBody.unquoted = draftBody.unquoted + "<br>" + img;
|
|
|
|
// save the draft
|
|
session.changes.add({body: draftBody.body});
|
|
}
|
|
}
|