Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
martgil committed Jul 28, 2024
1 parent cd8dbb9 commit c4467b6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion extension/js/common/browser/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class Env {

// eslint-disable-next-line @typescript-eslint/require-await
public static async webmails(): Promise<WebMailName[]> {
return ['gmail']; // async because storage may be involved in the future
return ['gmail', 'thunderbird']; // async because storage may be involved in the future
}

public static getBaseUrl() {
Expand Down
8 changes: 5 additions & 3 deletions extension/js/common/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ export class Injector {
}

public meta = () => {
this.S.cached('body')
.addClass(`cryptup_${this.webmailName} cryptup_${this.webmailName}_${this.webmailVariant} ${Catch.browser().name}`)
.append(this.factory.metaStylesheet('webmail') + this.factory.metaNotificationContainer()); // xss-safe-factory
if (!Catch.isThunderbirdMail()) {
this.S.cached('body')
.addClass(`cryptup_${this.webmailName} cryptup_${this.webmailName}_${this.webmailVariant} ${Catch.browser().name}`)
.append(this.factory.metaStylesheet('webmail') + this.factory.metaNotificationContainer()); // xss-safe-factory
}
};

public openComposeWin = (draftId?: string, openInFullScreen?: boolean, thunderbirdMsgId?: number, replyOption?: string, replyMsgId?: string): boolean => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ export const contentScriptSetupIfVacant = async (webmailSpecific: WebmailSpecifi
const webmails = await Env.webmails();
while (true) {
// todo - find a way to obtain current user account from Thundermail
const acctEmail = webmailSpecific.getUserAccountEmail();
let acctEmail: string | undefined;
if (Catch.isThunderbirdMail()) {
acctEmail = (await messenger.runtime.sendMessage('thunderbird_get_current_user')) as string; // todo - add to BrowserMsg
} else {
acctEmail = webmailSpecific.getUserAccountEmail();
}
if (typeof acctEmail !== 'undefined') {
win.account_email_global = acctEmail;
if (webmails.includes(webmailSpecific.name)) {
Expand Down Expand Up @@ -434,12 +439,16 @@ export const contentScriptSetupIfVacant = async (webmailSpecific: WebmailSpecifi
}
const acctEmail = await waitForAcctEmail();
const { tabId, notifications, factory, inject } = await initInternalVars(acctEmail);
await showNotificationsAndWaitTilAcctSetUp(acctEmail, notifications);

Catch.setHandledTimeout(() => updateClientConfiguration(acctEmail), 0);
const ppEvent: { entered?: boolean } = {};
const relayManager = new RelayManager();
browserMsgListen(acctEmail, tabId, inject, factory, notifications, relayManager, ppEvent);
if (webmailSpecific.name === 'gmail') {
await showNotificationsAndWaitTilAcctSetUp(acctEmail, notifications);
browserMsgListen(acctEmail, tabId, inject, factory, notifications, relayManager, ppEvent);
}
const clientConfiguration = await ClientConfiguration.newInstance(acctEmail);
// todo - investigate startPullingKeysFromEkm in Thunderbird
await startPullingKeysFromEkm(
acctEmail,
clientConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
return [{ interval: 1000, handler: () => this.replaceThunderbirdMsgPane() }];
};

public replaceThunderbirdMsgPane = () => {
private replaceThunderbirdMsgPane = () => {
if (Catch.isThunderbirdMail()) {
console.log('todo');
// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class ThunderbirdWebmailStartup {
) => {
// injector.btns(); // todo in another issue - add compose button
this.replacer = new ThunderbirdElementReplacer();
this.replacer.getIntervalFunctions();
this.replacer.runIntervalFunctionsPeriodically();
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.'
Expand Down
13 changes: 13 additions & 0 deletions extension/js/service_worker/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,18 @@ console.info('background.js service worker starting');
BgHandlers.thunderbirdSecureComposeHandler();
await BgHandlers.thunderbirdContentScriptRegistration();
// todo - add background listener here with name "thunderbird_msg_decrypt"
// todo - move this to BrowserMsg
messenger.runtime.onMessage.addListener(async (message, sender) => {
if (message === 'thunderbird_get_current_user') {
if (sender.tab?.id) {
const messageDetails = await messenger.messageDisplay.getDisplayedMessage(sender.tab?.id);
if (messageDetails) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return (await messenger.accounts.get(messageDetails.folder!.accountId)).name;
}
}
}
return;
});
}
})().catch(Catch.reportErr);

0 comments on commit c4467b6

Please sign in to comment.