diff --git a/extension/js/content_scripts/webmail/generic/setup-webmail-content-script.ts b/extension/js/content_scripts/webmail/generic/setup-webmail-content-script.ts index 6fbe109a63b..80d93f2de39 100644 --- a/extension/js/content_scripts/webmail/generic/setup-webmail-content-script.ts +++ b/extension/js/content_scripts/webmail/generic/setup-webmail-content-script.ts @@ -74,6 +74,7 @@ export const contentScriptSetupIfVacant = async (webmailSpecific: WebmailSpecifi let acctEmailInterval = 1000; const webmails = await Env.webmails(); while (true) { + // todo - find a way to obtain current user account from Thundermail const acctEmail = webmailSpecific.getUserAccountEmail(); if (typeof acctEmail !== 'undefined') { win.account_email_global = acctEmail; @@ -515,6 +516,9 @@ export const contentScriptSetupIfVacant = async (webmailSpecific: WebmailSpecifi document.dispatchEvent(new CustomEvent(win.destruction_event)); document.addEventListener(win.destruction_event, win.destroy); + if (Catch.isThunderbirdMail()) { + await entrypoint(); + } if (win.vacant()) { await entrypoint(); } else if (Catch.isFirefox()) { diff --git a/extension/js/content_scripts/webmail/thunderbird/message-display-scripts/injector.ts b/extension/js/content_scripts/webmail/thunderbird/message-display-scripts/injector.ts deleted file mode 100644 index 8abf2381bb4..00000000000 --- a/extension/js/content_scripts/webmail/thunderbird/message-display-scripts/injector.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* ©️ 2016 - present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com */ - -'use strict'; - -import { Catch } from '../../../../common/platform/catch.js'; - -// send message to background script about decryption - -(async () => { - const fullMsg = (await messenger.runtime.sendMessage('decrypt')) as messenger.messages.MessagePart; - if (fullMsg?.headers && 'openpgp' in fullMsg.headers) { - // note : embeddedMsg for pgp_block injection -> replaceArmoredBlocks - // do secure compose badge injection eg. signed or encrypted, (secure email status rendering) etc - // render decrypted message right into the messageDisplay - } -})().catch(Catch.reportErr); diff --git a/extension/js/content_scripts/webmail/thunderbird/thunderbird-element-replacer.ts b/extension/js/content_scripts/webmail/thunderbird/thunderbird-element-replacer.ts index fc286d6e341..a182dd6fdf9 100644 --- a/extension/js/content_scripts/webmail/thunderbird/thunderbird-element-replacer.ts +++ b/extension/js/content_scripts/webmail/thunderbird/thunderbird-element-replacer.ts @@ -2,12 +2,27 @@ 'use strict'; +import { Catch } from '../../../common/platform/catch'; import { IntervalFunction, WebmailElementReplacer } from '../generic/webmail-element-replacer'; export class ThunderbirdElementReplacer extends WebmailElementReplacer { - public getIntervalFunctions: () => IntervalFunction[]; + // public getIntervalFunctions: () => IntervalFunction[]; public setReplyBoxEditable: () => Promise; public reinsertReplyBox: (replyMsgId: string) => void; public scrollToReplyBox: (replyMsgId: string) => void; public scrollToCursorInReplyBox: (replyMsgId: string, cursorOffsetTop: number) => void; + + public getIntervalFunctions = (): IntervalFunction[] => { + return [{ interval: 1000, handler: () => this.replaceThunderbirdMsgPane() }]; + }; + + public replaceThunderbirdMsgPane = () => { + if (Catch.isThunderbirdMail()) { + // const fullMsg = (await messenger.runtime.sendMessage('decrypt')) as messenger.messages.MessagePart; + // if (fullMsg?.headers && 'openpgp' in fullMsg.headers) { + // // note : embeddedMsg for pgp_block injection -> replaceArmoredBlocks + // // do secure compose badge injection eg. signed or encrypted, (secure email status rendering) etc + // // render decrypted message right into the messageDisplay + } + }; } diff --git a/extension/js/content_scripts/webmail/thunderbird/thunderbird-webmail-startup.ts b/extension/js/content_scripts/webmail/thunderbird/thunderbird-webmail-startup.ts index 2f1fd1d3363..d7349bf43c4 100644 --- a/extension/js/content_scripts/webmail/thunderbird/thunderbird-webmail-startup.ts +++ b/extension/js/content_scripts/webmail/thunderbird/thunderbird-webmail-startup.ts @@ -28,7 +28,8 @@ export class ThunderbirdWebmailStartup { // relayManager: RelayManager // todo in another issue ) => { // injector.btns(); // todo in another issue - add compose button - this.replacer.runIntervalFunctionsPeriodically(); + this.replacer = new ThunderbirdElementReplacer(); + this.replacer.getIntervalFunctions(); await notifications.showInitial(acctEmail); notifications.show( 'FlowCrypt Thunderbird support is still in early development, and not expected to function properly yet. Support will be gradually added in upcoming versions.' diff --git a/extension/js/service_worker/background.ts b/extension/js/service_worker/background.ts index 9caf9692b66..421785d4bb5 100644 --- a/extension/js/service_worker/background.ts +++ b/extension/js/service_worker/background.ts @@ -71,16 +71,6 @@ console.info('background.js service worker starting'); if (Catch.isThunderbirdMail()) { BgHandlers.thunderbirdSecureComposeHandler(); await BgHandlers.thunderbirdContentScriptRegistration(); - chrome.runtime.onMessage.addListener(async (message, sender) => { - if (message === 'decrypt') { - const tabId = sender.tab?.id; - if (tabId) { - const res = await messenger.messageDisplay.getDisplayedMessage(tabId); - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - return await messenger.messages.getFull(res!.id); - } - } - return; - }); + // todo - add background listener here with name "thunderbird_msg_decrypt" } })().catch(Catch.reportErr); diff --git a/tooling/bundle-content-scripts.ts b/tooling/bundle-content-scripts.ts index 1b411087f59..68533db3f02 100644 --- a/tooling/bundle-content-scripts.ts +++ b/tooling/bundle-content-scripts.ts @@ -59,6 +59,24 @@ buildContentScript( // thunderbird buildContentScript( - ([] as string[]).concat(getFilesInDir(`${sourceDir}/js/content_scripts/webmail/thunderbird/message-display-scripts`, /\.js$/)), + ([] as string[]).concat( + getFilesInDir(`${sourceDir}/js/common/platform`, /\.js$/, false), + getFilesInDir(`${sourceDir}/js/common/platform/store`, /\.js$/, false), + getFilesInDir(`${sourceDir}/js/common/core`, /\.js$/, false), + getFilesInDir(`${sourceDir}/js/common/core/crypto/`, /\.js$/, false), + getFilesInDir(`${sourceDir}/js/common/core/crypto/smime`, /\.js$/, false), + getFilesInDir(`${sourceDir}/js/common/api/shared`, /\.js$/, false), + getFilesInDir(`${sourceDir}/js/common/api/key-server`, /\.js$/, false), + getFilesInDir(`${sourceDir}/js/common/api/account-servers`, /\.js$/, false), + getFilesInDir(`${sourceDir}/js/common/api/authentication/generic`, /\.js$/, false), + getFilesInDir(`${sourceDir}/js/common/api/authentication/google`, /\.js$/, false), + getFilesInDir(`${sourceDir}/js/common/api/authentication`, /\.js$/, false), + getFilesInDir(`${sourceDir}/js/common/api/email-provider`, /\.js$/, false), + getFilesInDir(`${sourceDir}/js/common/api/email-provider/gmail`, /\.js$/, false), + getFilesInDir(`${sourceDir}/js/common/api`, /\.js$/, false), + getFilesInDir(`${sourceDir}/js/common/browser`, /\.js$/, false), + getFilesInDir(`${sourceDir}/js/common`, /\.js$/, false), + getFilesInDir(`${sourceDir}/js/content_scripts/webmail`, /\.js$/) + ), 'thunderbird-content-script.js' );