Skip to content

Commit

Permalink
Merge branch 'master' into issue-5726-improve-encrypted-msg-detection…
Browse files Browse the repository at this point in the history
…-for-multipart-email
  • Loading branch information
martgil authored May 24, 2024
2 parents 815e9a8 + 034b77a commit 7bb3635
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export class ComposeInputModule extends ViewModule<ComposeView> {
};

public removeRichTextFormatting = () => {
this.initSquire(false, true);
if (this.view.inputModule.isRichText()) {
this.initSquire(false, true);
}
};

public inputTextHtmlSetSafely = (html: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Catch } from '../../../../js/common/platform/catch.js';
import { GmailParser } from '../../../../js/common/api/email-provider/gmail/gmail-parser.js';
import { InboxView } from '../inbox.js';
import { Lang } from '../../../../js/common/lang.js';
import { Str } from '../../../../js/common/core/common.js';
import { Str, promiseAllWithLimit } from '../../../../js/common/core/common.js';
import { Ui } from '../../../../js/common/browser/ui.js';
import { ViewModule } from '../../../../js/common/view-module.js';
import { Xss } from '../../../../js/common/platform/xss.js';
Expand All @@ -18,7 +18,10 @@ export class InboxListThreadsModule extends ViewModule<InboxView> {
try {
const { threads } = await this.view.gmail.threadList(labelId);
if (threads?.length) {
await Promise.all(threads.map(t => this.renderInboxItem(t.id)));
await promiseAllWithLimit(
30,
threads.map(t => () => this.renderInboxItem(t.id))
);
} else {
Xss.sanitizeRender('.threads', `<p>No encrypted messages in ${Xss.escape(labelId)} yet. ${Ui.retryLink()}</p>`);
}
Expand All @@ -39,7 +42,7 @@ export class InboxListThreadsModule extends ViewModule<InboxView> {
}
};

private renderInboxItem = async (threadId: string) => {
private renderInboxItem = async (threadId: string): Promise<void> => {
this.inboxThreadItemAdd(threadId);
const threadItem = $('.threads #' + this.threadListItemId(threadId));
try {
Expand Down
7 changes: 5 additions & 2 deletions extension/js/common/api/email-provider/gmail/gmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { AddrParserResult, BrowserWindow } from '../../../browser/browser-window.js';
import { ChunkedCb, ProgressCb, EmailProviderContact } from '../../shared/api.js';
import { Dict, Str, Value } from '../../../core/common.js';
import { Dict, Str, Value, promiseAllWithLimit } from '../../../core/common.js';
import { EmailProviderApi, EmailProviderInterface, Backups } from '../email-provider-api.js';
import { GMAIL_GOOGLE_API_HOST, gmailBackupSearchQuery } from '../../../core/const.js';
import { GmailParser, GmailRes } from './gmail-parser.js';
Expand Down Expand Up @@ -136,7 +136,10 @@ export class Gmail extends EmailProviderApi implements EmailProviderInterface {
};

public msgsGet = async (msgIds: string[], format: GmailResponseFormat): Promise<GmailRes.GmailMsg[]> => {
return await Promise.all(msgIds.map(id => this.msgGet(id, format)));
return await promiseAllWithLimit(
30,
msgIds.map(id => () => this.msgGet(id, format))
);
};

public labelsGet = async (): Promise<GmailRes.GmailLabels> => {
Expand Down
17 changes: 17 additions & 0 deletions extension/js/common/core/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,20 @@ export const checkValidURL = (url: string): boolean => {
const pattern = /(http|https):\/\/([a-z0-9-]+((\.[a-z0-9-]+)+)?)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@\-\/]))?/;
return pattern.test(url);
};

/**
* Executes multiple promises concurrently with a limit to the number of promises running simultaneously.
* Resolves when all promises are resolved or rejects when any promise is rejected.
*
* @param concurrency - The maximum number of promises to run at the same time.
* @param tasks - An array of functions that return promises.
* @returns A Promise that resolves to an array of the resolved values of the input promises.
*/
export const promiseAllWithLimit = async <V>(concurrency: number, tasks: (() => Promise<V>)[]): Promise<V[]> => {
let results: V[] = [];
while (tasks.length) {
const currentTasks = tasks.splice(0, concurrency).map(task => task());
results = results.concat(await Promise.all(currentTasks));
}
return results;
};
1 change: 1 addition & 0 deletions extension/js/common/core/crypto/pgp/openpgp-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ export class OpenPGPKey {
const message = await opgp.createMessage({ text });
return await opgp.sign({ message, format: 'armored', signingKeys: [signingPrv], detached });
}
text = text ? text : '\n';
const message = await opgp.createCleartextMessage({ text });
return await opgp.sign({ message, signingKeys: [signingPrv] });
}
Expand Down

0 comments on commit 7bb3635

Please sign in to comment.