proton-mail-bridge-client 2.19.8 → 2.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -3
- package/dist/config-env.d.ts +1 -0
- package/dist/config-env.d.ts.map +1 -1
- package/dist/config-env.js +15 -1
- package/dist/config-env.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/services/account-manager.d.ts +3 -0
- package/dist/services/account-manager.d.ts.map +1 -1
- package/dist/services/account-manager.js +3 -0
- package/dist/services/account-manager.js.map +1 -1
- package/dist/services/local-index-service.d.ts +2 -0
- package/dist/services/local-index-service.d.ts.map +1 -1
- package/dist/services/local-index-service.js +76 -4
- package/dist/services/local-index-service.js.map +1 -1
- package/dist/services/simple-imap-service.d.ts +6 -0
- package/dist/services/simple-imap-service.d.ts.map +1 -1
- package/dist/services/simple-imap-service.js +49 -3
- package/dist/services/simple-imap-service.js.map +1 -1
- package/dist/services/undo-journal-service.d.ts +63 -0
- package/dist/services/undo-journal-service.d.ts.map +1 -0
- package/dist/services/undo-journal-service.js +119 -0
- package/dist/services/undo-journal-service.js.map +1 -0
- package/dist/tools/bulk.d.ts.map +1 -1
- package/dist/tools/bulk.js +6 -1
- package/dist/tools/bulk.js.map +1 -1
- package/dist/tools/definitions.d.ts +12 -9
- package/dist/tools/definitions.d.ts.map +1 -1
- package/dist/tools/definitions.js +18 -34
- package/dist/tools/definitions.js.map +1 -1
- package/dist/tools/message-actions.d.ts.map +1 -1
- package/dist/tools/message-actions.js +10 -6
- package/dist/tools/message-actions.js.map +1 -1
- package/dist/tools/rules-runner.d.ts +3 -1
- package/dist/tools/rules-runner.d.ts.map +1 -1
- package/dist/tools/rules-runner.js +44 -6
- package/dist/tools/rules-runner.js.map +1 -1
- package/dist/tools/triage.d.ts.map +1 -1
- package/dist/tools/triage.js +21 -0
- package/dist/tools/triage.js.map +1 -1
- package/dist/tools/undo.d.ts +36 -0
- package/dist/tools/undo.d.ts.map +1 -0
- package/dist/tools/undo.js +175 -0
- package/dist/tools/undo.js.map +1 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +2 -0
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/helpers.js +5 -1
- package/dist/utils/helpers.js.map +1 -1
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ import { mkdir, rm } from "node:fs/promises";
|
|
|
4
4
|
import { readRegularFile } from "../utils/regular-file.js";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
import { ensureAccountIdentityMatches } from "../utils/account-identity.js";
|
|
7
|
-
import { createEmailId, dedupeEmails, extractDomain, extractMessageIdList, foldSearchText, isOutgoingMessage, lowerCaseAddress, nextDay, normalizeMailboxLabel, isSelfAddress, normalizeMessageId, normalizeSubjectForThread, searchEquals, searchIncludes, searchKey, searchNeedles, newestEmail, sortEmailsByNewest, } from "../utils/helpers.js";
|
|
7
|
+
import { DEFAULT_INDEX_BODY_CHARS, createEmailId, dedupeEmails, extractDomain, extractMessageIdList, foldSearchText, isOutgoingMessage, lowerCaseAddress, nextDay, normalizeMailboxLabel, isSelfAddress, normalizeMessageId, normalizeSubjectForThread, searchEquals, searchIncludes, searchKey, searchNeedles, newestEmail, sortEmailsByNewest, } from "../utils/helpers.js";
|
|
8
8
|
import { logger } from "../utils/logger.js";
|
|
9
9
|
const DB_SCHEMA_VERSION = 3;
|
|
10
10
|
// Version of what the full-text index stores. 2 = every column holds the text's searchKey (folded,
|
|
@@ -74,6 +74,9 @@ const KEY_COLUMN = {
|
|
|
74
74
|
};
|
|
75
75
|
// Version of what message_keys stores; bump when searchKey changes so the table is rebuilt once.
|
|
76
76
|
const MESSAGE_KEY_VERSION = "1";
|
|
77
|
+
// The longer text kept for search (message_bodies, see PROTONMAIL_INDEX_BODY_CHARS), for the messages of one search. Beside
|
|
78
|
+
// the summary and not on it, so that it is matched against the query but never reaches a tool's answer.
|
|
79
|
+
const indexedBodies = new WeakMap();
|
|
77
80
|
// WHERE fragment: any of `columns` contains `needle`, ignoring case, accents and spelling variants
|
|
78
81
|
// (Müller/Mueller, see searchKey).
|
|
79
82
|
function foldedLike(columns, needle) {
|
|
@@ -191,6 +194,7 @@ function matchesIndexedSearch(email, filters) {
|
|
|
191
194
|
const haystacks = [
|
|
192
195
|
email.subject,
|
|
193
196
|
email.preview ?? "",
|
|
197
|
+
indexedBodies.get(email) ?? "",
|
|
194
198
|
email.attachmentText ?? "",
|
|
195
199
|
email.folder,
|
|
196
200
|
email.labels.join(" "),
|
|
@@ -664,6 +668,8 @@ export class LocalIndexService {
|
|
|
664
668
|
const db = await this.ensureDb();
|
|
665
669
|
const thread = this.loadThreadByKey(db, normalizedFilters.threadId);
|
|
666
670
|
if (thread) {
|
|
671
|
+
if (normalizedFilters.query)
|
|
672
|
+
this.attachIndexedBodies(db, thread.messages);
|
|
667
673
|
const threadMessages = sortEmailsByNewest(thread.messages).filter((email) => matchesIndexedSearch(email, { ...normalizedFilters, threadId: undefined })).sort((left, right) => searchRelevanceScore(right, normalizedFilters) - searchRelevanceScore(left, normalizedFilters));
|
|
668
674
|
const totalCount = threadMessages.length;
|
|
669
675
|
return {
|
|
@@ -690,6 +696,8 @@ export class LocalIndexService {
|
|
|
690
696
|
const thread = this.buildThreads(snapshot, true).find((entry) => entry.id === normalizedFilters.threadId);
|
|
691
697
|
if (thread) {
|
|
692
698
|
const freshnessFields = this.indexFreshnessFields(snapshot.updatedAt);
|
|
699
|
+
if (normalizedFilters.query)
|
|
700
|
+
this.attachIndexedBodies(await this.ensureDb(), thread.messages);
|
|
693
701
|
const threadMessages = sortEmailsByNewest(thread.messages).filter((email) => matchesIndexedSearch(email, { ...normalizedFilters, threadId: undefined })).sort((left, right) => searchRelevanceScore(right, normalizedFilters) - searchRelevanceScore(left, normalizedFilters));
|
|
694
702
|
const totalCount = threadMessages.length;
|
|
695
703
|
return {
|
|
@@ -1554,6 +1562,7 @@ export class LocalIndexService {
|
|
|
1554
1562
|
}
|
|
1555
1563
|
this.runMigrations(db);
|
|
1556
1564
|
this.rebuildFtsIfNeeded(db);
|
|
1565
|
+
this.resetIndexIfBodyCharsChanged(db);
|
|
1557
1566
|
this.db = db;
|
|
1558
1567
|
await this.maybeImportLegacyIndex(db);
|
|
1559
1568
|
this.initialized = true;
|
|
@@ -1686,6 +1695,11 @@ export class LocalIndexService {
|
|
|
1686
1695
|
email_id, subject, preview, folder, labels, participants, attachment_names
|
|
1687
1696
|
) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
1688
1697
|
`);
|
|
1698
|
+
const upsertBody = db.prepare(`
|
|
1699
|
+
INSERT INTO message_bodies (email_id, body) VALUES (?, ?)
|
|
1700
|
+
ON CONFLICT(email_id) DO UPDATE SET body = excluded.body
|
|
1701
|
+
`);
|
|
1702
|
+
const readBody = db.prepare(`SELECT body FROM message_bodies WHERE email_id = ?`);
|
|
1689
1703
|
// The UIDVALIDITY-embedding id format is optional per-caller (createEmailId):
|
|
1690
1704
|
// a message indexed before that fix lives here under the old 3-field id
|
|
1691
1705
|
// (<folder>::<uid>::<checksum>, no uidValidity), while a sync running the
|
|
@@ -1933,8 +1947,13 @@ export class LocalIndexService {
|
|
|
1933
1947
|
bcc_json: JSON.stringify(email.bcc),
|
|
1934
1948
|
labels_json: JSON.stringify(email.labels),
|
|
1935
1949
|
});
|
|
1950
|
+
// Like preview, the longer text is kept when a flags-only sync brings none, so the FTS row below is
|
|
1951
|
+
// rebuilt from what is stored.
|
|
1952
|
+
if (email.indexText)
|
|
1953
|
+
upsertBody.run(email.id, email.indexText);
|
|
1954
|
+
const body = readBody.get(email.id)?.body;
|
|
1936
1955
|
deleteFts.run(email.id);
|
|
1937
|
-
insertFts.run(email.id, ...ftsColumns(email, persisted.preview ?? "", persisted.attachment_text ?? undefined));
|
|
1956
|
+
insertFts.run(email.id, ...ftsColumns(email, body ?? persisted.preview ?? "", persisted.attachment_text ?? undefined));
|
|
1938
1957
|
}
|
|
1939
1958
|
// Flags-only sweeps: bring read/starred state of every indexed row of the folder in line with the server and
|
|
1940
1959
|
// drop rows the server no longer has. Applied after this snapshot's own upserts, which were fetched first.
|
|
@@ -2071,6 +2090,7 @@ export class LocalIndexService {
|
|
|
2071
2090
|
INSERT INTO messages_fts (email_id, subject, preview, folder, labels, participants, attachment_names)
|
|
2072
2091
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
2073
2092
|
`);
|
|
2093
|
+
const readBody = db.prepare(`SELECT body FROM message_bodies WHERE email_id = ?`);
|
|
2074
2094
|
const nextBatch = db.prepare(`SELECT rowid AS _rowid, * FROM messages WHERE rowid > ? ORDER BY rowid LIMIT 500`);
|
|
2075
2095
|
db.transaction(() => {
|
|
2076
2096
|
db.exec(`DELETE FROM messages_fts`);
|
|
@@ -2085,7 +2105,8 @@ export class LocalIndexService {
|
|
|
2085
2105
|
// That message just has no full-text entry until it is synced again.
|
|
2086
2106
|
try {
|
|
2087
2107
|
const email = this.rowToEmailSummary(row);
|
|
2088
|
-
|
|
2108
|
+
const body = readBody.get(row.email_id)?.body;
|
|
2109
|
+
insertFts.run(email.id, ...ftsColumns(email, body ?? row.preview ?? "", row.attachment_text ?? undefined));
|
|
2089
2110
|
}
|
|
2090
2111
|
catch (error) {
|
|
2091
2112
|
skipped += 1;
|
|
@@ -2103,6 +2124,32 @@ export class LocalIndexService {
|
|
|
2103
2124
|
}
|
|
2104
2125
|
})();
|
|
2105
2126
|
}
|
|
2127
|
+
// PROTONMAIL_INDEX_BODY_CHARS differs from the value the index was built with: its rows hold text of the old length
|
|
2128
|
+
// (or none), and a flags-only sync never reads a body again, so keeping them would leave search silently uneven. The
|
|
2129
|
+
// index is only a copy of the mailbox, so start over; a search on the empty index starts a sync, which refills it
|
|
2130
|
+
// (older mail comes back with full syncs, as after clear_index). One transaction: either all of it or nothing.
|
|
2131
|
+
resetIndexIfBodyCharsChanged(db) {
|
|
2132
|
+
const configured = this.config.runtime?.indexBodyChars ?? DEFAULT_INDEX_BODY_CHARS;
|
|
2133
|
+
const stored = db.prepare(`SELECT value FROM metadata WHERE key = 'indexBodyChars'`).get();
|
|
2134
|
+
// No value: built before the setting existed, so from the preview alone.
|
|
2135
|
+
if (Number(stored?.value ?? DEFAULT_INDEX_BODY_CHARS) === configured)
|
|
2136
|
+
return;
|
|
2137
|
+
const total = Number(db.prepare(`SELECT COUNT(*) AS count FROM messages`).get().count);
|
|
2138
|
+
if (total > 0) {
|
|
2139
|
+
this.log.warn(`PROTONMAIL_INDEX_BODY_CHARS changed to ${configured}; clearing ${total} indexed messages so they are indexed again with it (the next sync refills the index)`, "LocalIndexService");
|
|
2140
|
+
}
|
|
2141
|
+
db.transaction(() => {
|
|
2142
|
+
db.exec(`
|
|
2143
|
+
DELETE FROM messages_fts;
|
|
2144
|
+
DELETE FROM messages;
|
|
2145
|
+
DELETE FROM sync_state;
|
|
2146
|
+
UPDATE folders SET last_indexed_at = NULL, last_indexed_count = NULL;
|
|
2147
|
+
`);
|
|
2148
|
+
const setMetadata = db.prepare(`INSERT INTO metadata (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value`);
|
|
2149
|
+
setMetadata.run("updatedAt", "");
|
|
2150
|
+
setMetadata.run("indexBodyChars", String(configured));
|
|
2151
|
+
})();
|
|
2152
|
+
}
|
|
2106
2153
|
runMigrations(db) {
|
|
2107
2154
|
db.exec(`
|
|
2108
2155
|
CREATE TABLE IF NOT EXISTS metadata (
|
|
@@ -2196,6 +2243,13 @@ export class LocalIndexService {
|
|
|
2196
2243
|
subject_key TEXT, preview_key TEXT, from_key TEXT, to_key TEXT,
|
|
2197
2244
|
cc_key TEXT, bcc_key TEXT, labels_key TEXT, folder_key TEXT
|
|
2198
2245
|
);
|
|
2246
|
+
|
|
2247
|
+
-- Text beyond the preview, only for messages synced with PROTONMAIL_INDEX_BODY_CHARS above its default. A table of
|
|
2248
|
+
-- its own so the wide text is not read with every messages row; it is what messages_fts is rebuilt from.
|
|
2249
|
+
CREATE TABLE IF NOT EXISTS message_bodies (
|
|
2250
|
+
email_id TEXT PRIMARY KEY REFERENCES messages(email_id) ON DELETE CASCADE,
|
|
2251
|
+
body TEXT NOT NULL
|
|
2252
|
+
);
|
|
2199
2253
|
`);
|
|
2200
2254
|
this.ensureMessagesColumns(db);
|
|
2201
2255
|
this.backfillMessageKeys(db);
|
|
@@ -2358,10 +2412,28 @@ export class LocalIndexService {
|
|
|
2358
2412
|
}
|
|
2359
2413
|
sqlParts.push(`ORDER BY COALESCE(internal_date, date) DESC, uid DESC LIMIT ?`);
|
|
2360
2414
|
params.push(limitHint);
|
|
2361
|
-
|
|
2415
|
+
const candidates = db
|
|
2362
2416
|
.prepare(sqlParts.join(" "))
|
|
2363
2417
|
.all(...params)
|
|
2364
2418
|
.map((row) => this.rowToEmailSummary(row));
|
|
2419
|
+
if (filters.query)
|
|
2420
|
+
this.attachIndexedBodies(db, candidates);
|
|
2421
|
+
return candidates;
|
|
2422
|
+
}
|
|
2423
|
+
// FTS matched these messages on their longer text too, so the query check that follows must see it (see indexedBodies).
|
|
2424
|
+
attachIndexedBodies(db, emails) {
|
|
2425
|
+
for (let start = 0; start < emails.length; start += 400) {
|
|
2426
|
+
const chunk = emails.slice(start, start + 400);
|
|
2427
|
+
const rows = db
|
|
2428
|
+
.prepare(`SELECT email_id, body FROM message_bodies WHERE email_id IN (${chunk.map(() => "?").join(", ")})`)
|
|
2429
|
+
.all(...chunk.map((email) => email.id));
|
|
2430
|
+
const bodies = new Map(rows.map((row) => [row.email_id, row.body]));
|
|
2431
|
+
for (const email of chunk) {
|
|
2432
|
+
const body = bodies.get(email.id);
|
|
2433
|
+
if (body)
|
|
2434
|
+
indexedBodies.set(email, body);
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2365
2437
|
}
|
|
2366
2438
|
searchFtsIds(db, query, limit) {
|
|
2367
2439
|
const parsed = parseSearchQuery(query);
|