Skip to content

Commit 67522cf

Browse files
committed
remove code duplicates
1 parent f707f6f commit 67522cf

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

extension/js/common/browser/browser-msg.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ export namespace Bm {
9999
export type PgpBlockRetry = { frameId: string; messageSender: Dest };
100100
export type PgpBlockReady = { frameId: string; messageSender: Dest };
101101
export type ThunderbirdOpenPassphraseDialog = { acctEmail: string; longids: string };
102-
export type ThunderbirdGetDownloadableAttachment = { attachments: messenger.messages.MessageAttachment[] };
103102
export type ThunderbirdInitiateAttachmentDownload = { decryptedFileName: string; decryptedContent: Buf };
104103

105104
export namespace Res {
@@ -181,7 +180,6 @@ export namespace Bm {
181180
| PgpBlockReady
182181
| PgpBlockRetry
183182
| ConfirmationResult
184-
| ThunderbirdGetDownloadableAttachment
185183
| ThunderbirdOpenPassphraseDialog
186184
| ThunderbirdInitiateAttachmentDownload
187185
| Ajax;
@@ -247,8 +245,8 @@ export class BrowserMsg {
247245
BrowserMsg.sendAwait(undefined, 'expirationCacheSet', bm, true) as Promise<Bm.Res.ExpirationCacheSet>,
248246
expirationCacheDeleteExpired: (bm: Bm.ExpirationCacheDeleteExpired) =>
249247
BrowserMsg.sendAwait(undefined, 'expirationCacheDeleteExpired', bm, true) as Promise<Bm.Res.ExpirationCacheDeleteExpired>,
250-
thunderbirdGetDownloadableAttachment: (bm: Bm.ThunderbirdGetDownloadableAttachment) =>
251-
BrowserMsg.sendAwait(undefined, 'thunderbirdGetDownloadableAttachment', bm, true) as Promise<Bm.Res.ThunderbirdGetDownloadableAttachment>,
248+
thunderbirdGetDownloadableAttachment: () =>
249+
BrowserMsg.sendAwait(undefined, 'thunderbirdGetDownloadableAttachment', undefined, true) as Promise<Bm.Res.ThunderbirdGetDownloadableAttachment>,
252250
thunderbirdInitiateAttachmentDownload: (bm: Bm.ThunderbirdInitiateAttachmentDownload) =>
253251
BrowserMsg.sendAwait(undefined, 'thunderbirdInitiateAttachmentDownload', bm, true) as Promise<Bm.Res.ThunderbirdInitiateAttachmentDownload>,
254252
thunderbirdGetCurrentUser: () =>

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
3131
public replaceThunderbirdMsgPane = async () => {
3232
const emailBodyToParse = $('div.moz-text-plain').text().trim() || $('div.moz-text-html').text().trim();
3333
if (Catch.isThunderbirdMail()) {
34-
const { attachments } = await BrowserMsg.send.bg.await.thunderbirdMsgGet();
3534
const pgpRegex = /-----BEGIN PGP MESSAGE-----(.*?)-----END PGP MESSAGE-----/s;
3635
const pgpRegexMatch = new RegExp(pgpRegex).exec(emailBodyToParse);
3736
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -43,11 +42,9 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
4342
} else if (this.resemblesSignedMsg(emailBodyToParse)) {
4443
await this.messageVerify(signerKeys);
4544
}
46-
if (attachments.length) {
47-
const fcAttachments = await BrowserMsg.send.bg.await.thunderbirdGetDownloadableAttachment({ attachments });
48-
for (const fcAttachment of fcAttachments) {
49-
await this.attachmentUiRenderer(fcAttachment, signerKeys, emailBodyToParse);
50-
}
45+
const fcAttachments = await BrowserMsg.send.bg.await.thunderbirdGetDownloadableAttachment();
46+
for (const fcAttachment of fcAttachments) {
47+
await this.attachmentUiRenderer(fcAttachment, signerKeys, emailBodyToParse);
5148
}
5249
}
5350
};

extension/js/service_worker/bg-handlers.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,22 @@ export class BgHandlers {
163163
});
164164
};
165165

166-
public static thunderbirdGetDownloadableAttachment = async (
167-
r: Bm.ThunderbirdGetDownloadableAttachment
168-
): Promise<Bm.Res.ThunderbirdGetDownloadableAttachment> => {
166+
public static thunderbirdGetDownloadableAttachment = async (): Promise<Bm.Res.ThunderbirdGetDownloadableAttachment> => {
169167
const processableAttachments: Bm.Res.ThunderbirdGetDownloadableAttachment = [];
170168
const [tab] = await messenger.mailTabs.query({ active: true, currentWindow: true });
171169
const message = await messenger.messageDisplay.getDisplayedMessage(tab.id);
172170
if (tab.id && message?.id) {
171+
const attachments = await messenger.messages.listAttachments(message.id);
173172
const fcAttachments: Attachment[] = [];
174173
// convert Thunderbird Attachments to FlowCrypt recognizable Attachments
175-
for (const tbAttachment of r.attachments) {
176-
const rawAttachment = await messenger.messages.getAttachmentFile(message.id, tbAttachment.partName);
174+
for (const attachment of attachments) {
175+
const file = await messenger.messages.getAttachmentFile(message.id, attachment.partName);
177176
fcAttachments.push(
178177
new Attachment({
179-
data: new Uint8Array(await rawAttachment.arrayBuffer()),
180-
type: tbAttachment.contentType,
181-
name: tbAttachment.name,
182-
length: tbAttachment.size,
178+
data: new Uint8Array(await file.arrayBuffer()),
179+
type: attachment.contentType,
180+
name: attachment.name,
181+
length: attachment.size,
183182
})
184183
);
185184
}

0 commit comments

Comments
 (0)