Skip to content

Commit 3084d14

Browse files
committed
add secure forward functionality
1 parent f02b6f0 commit 3084d14

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

extension/js/content_scripts/webmail/generic/webmail-element-replacer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* ©️ 2016 - present FlowCrypt a.s. Limitations apply. Contact [email protected] */
22

3+
import { ReplyOption } from '../../../../chrome/elements/compose-modules/compose-reply-btn-popover-module';
34
import { ContentScriptWindow } from '../../../common/browser/browser-window';
45
import { notifyMurdered } from './setup-webmail-content-script';
56

@@ -9,7 +10,7 @@ export abstract class WebmailElementReplacer {
910
private replacePgpElsInterval: number;
1011

1112
public abstract getIntervalFunctions: () => IntervalFunction[];
12-
public abstract setReplyBoxEditable: () => Promise<void>;
13+
public abstract setReplyBoxEditable: (replyOption?: ReplyOption) => Promise<void>;
1314
public abstract reinsertReplyBox: (replyMsgId: string) => void;
1415
public abstract scrollToReplyBox: (replyMsgId: string) => void;
1516
public abstract scrollToCursorInReplyBox: (replyMsgId: string, cursorOffsetTop: number) => void;

extension/js/content_scripts/webmail/gmail/gmail-element-replacer.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ export class GmailElementReplacer extends WebmailElementReplacer {
8787
];
8888
};
8989

90-
public setReplyBoxEditable = async () => {
90+
public setReplyBoxEditable = async (replyOption?: ReplyOption) => {
9191
const replyContainerIframe = $('.reply_message_iframe_container > iframe').last();
9292
if (replyContainerIframe.length) {
93-
$(replyContainerIframe).replaceWith(this.factory.embeddedReply(this.getLastMsgReplyParams(this.getConvoRootEl(replyContainerIframe[0])), true)); // xss-safe-value
93+
$(replyContainerIframe).replaceWith(
94+
this.factory.embeddedReply(this.getLastMsgReplyParams(this.getConvoRootEl(replyContainerIframe[0]), replyOption), true)
95+
); // xss-safe-value
9496
} else {
9597
await this.replaceStandardReplyBox(undefined, true);
9698
}
@@ -365,7 +367,8 @@ export class GmailElementReplacer extends WebmailElementReplacer {
365367

366368
private actionActivateSecureReplyHandler = async (btn: HTMLElement, event: JQuery.Event) => {
367369
event.stopImmediatePropagation();
368-
const secureReplyInvokedFromMenu = btn.className.includes('action_reply_message_button');
370+
const secureReplyInvokedFromMenu = btn.className.includes('action_menu_message_button');
371+
const replyOption: ReplyOption = btn.className.includes('reply') ? 'a_reply' : 'a_forward';
369372
if ($('#switch_to_encrypted_reply').length) {
370373
$('#switch_to_encrypted_reply').trigger('click');
371374
return;
@@ -374,12 +377,12 @@ export class GmailElementReplacer extends WebmailElementReplacer {
374377
const messageContainer = secureReplyInvokedFromMenu ? $('.T-I-JO.T-I-Kq').closest('.h7') : $(btn.closest('.h7')!);
375378
if (messageContainer.is(':last-child')) {
376379
if (this.isEncrypted()) {
377-
await this.setReplyBoxEditable();
380+
await this.setReplyBoxEditable(replyOption);
378381
} else {
379382
await this.replaceStandardReplyBox(undefined, true);
380383
}
381384
} else {
382-
this.insertEncryptedReplyBox(messageContainer);
385+
this.insertEncryptedReplyBox(messageContainer, replyOption);
383386
}
384387
if (secureReplyInvokedFromMenu) {
385388
$(this.sel.msgActionsBtn).removeClass('T-I-JO T-I-Kq');
@@ -613,18 +616,18 @@ export class GmailElementReplacer extends WebmailElementReplacer {
613616
return from ? Str.parseEmail(from) : undefined;
614617
};
615618

616-
private getLastMsgReplyParams = (convoRootEl: JQuery): FactoryReplyParams => {
617-
return { replyMsgId: this.determineMsgId($(convoRootEl).find(this.sel.msgInner).last()) };
619+
private getLastMsgReplyParams = (convoRootEl: JQuery, replyOption?: ReplyOption): FactoryReplyParams => {
620+
return { replyMsgId: this.determineMsgId($(convoRootEl).find(this.sel.msgInner).last()), replyOption };
618621
};
619622

620623
private getConvoRootEl = (anyInnerElement: HTMLElement) => {
621624
return $(anyInnerElement).closest('div.if, div.aHU, td.Bu').first();
622625
};
623626

624-
private insertEncryptedReplyBox = (messageContainer: JQuery<Element>) => {
627+
private insertEncryptedReplyBox = (messageContainer: JQuery<Element>, replyOption: ReplyOption) => {
625628
const msgIdElement = messageContainer.find('[data-legacy-message-id], [data-message-id]');
626629
const msgId = msgIdElement.attr('data-legacy-message-id') || msgIdElement.attr('data-message-id');
627-
const replyParams: FactoryReplyParams = { replyMsgId: msgId, removeAfterClose: true };
630+
const replyParams: FactoryReplyParams = { replyMsgId: msgId, removeAfterClose: true, replyOption };
628631
const secureReplyBoxXssSafe = /* xss-safe-factory */ `<div class="remove_borders reply_message_iframe_container inserted">${this.factory.embeddedReply(
629632
replyParams,
630633
true,

0 commit comments

Comments
 (0)