@rapidmx/web-client 0.35.0 → 0.36.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/apps/escrow/matters/[uid].tsx +4 -3
- package/apps/shared/calendar/sealedEvents.ts +80 -0
- package/apps/shared/components/admin/settings/EncryptionPolicyForm.tsx +61 -3
- package/apps/shared/components/contacts/contactCardData.ts +2 -1
- package/apps/shared/components/layout/KeyEnrollmentGate.tsx +23 -1
- package/apps/shared/components/layout/SharedMailboxKeyManager.tsx +91 -0
- package/apps/shared/components/layout/UnlockPromptProvider.tsx +34 -0
- package/apps/shared/components/mail/ConversationList.tsx +1 -1
- package/apps/shared/components/mail/MessageDetailPane.tsx +35 -13
- package/apps/shared/components/mail/compose/draftResume.ts +28 -3
- package/apps/shared/components/mail/compose/quotedBody.ts +4 -3
- package/apps/shared/components/mail/invite/inviteStore.ts +7 -1
- package/apps/shared/components/mail/layout/MailShell.tsx +2 -0
- package/apps/shared/components/mail/reading/useMessageActions.ts +4 -1
- package/apps/shared/components/settings/KeyExportSetting.tsx +170 -0
- package/apps/shared/components/settings/PolicyLockedNotice.tsx +23 -0
- package/apps/shared/components/settings/ZeroAccessSetting.tsx +117 -0
- package/apps/shared/mail/decryptedMessages.ts +11 -3
- package/apps/shared/mail/outbox/sendJob.ts +2 -2
- package/apps/shared/mail/reportNotices.ts +3 -1
- package/apps/shared/mail/zeroAccessSource.ts +27 -0
- package/apps/shared/search/LocalIndexLifecycle.tsx +31 -0
- package/apps/shared/search/localIndexBuilder.ts +27 -1
- package/apps/shared/search/localIndexRpcClient.ts +8 -4
- package/apps/shared/search/localIndexSchema.ts +2 -2
- package/apps/shared/search/localIndexTransport.ts +2 -1
- package/apps/shared/search/localIndexWorker.ts +6 -4
- package/apps/shared/search/zeroAccessIndexSync.ts +487 -0
- package/apps/www/calendar/index.tsx +176 -56
- package/apps/www/index.tsx +10 -3
- package/apps/www/settings/encryption/index.tsx +5 -0
- package/apps/www/settings/privacy/index.tsx +2 -1
- package/dist/apps/escrow/matters/[uid].js +2 -2
- package/dist/apps/shared/calendar/sealedEvents.d.ts +13 -0
- package/dist/apps/shared/calendar/sealedEvents.js +54 -0
- package/dist/apps/shared/components/admin/settings/EncryptionPolicyForm.js +18 -2
- package/dist/apps/shared/components/contacts/contactCardData.js +2 -1
- package/dist/apps/shared/components/layout/KeyEnrollmentGate.js +21 -2
- package/dist/apps/shared/components/layout/SharedMailboxKeyManager.d.ts +15 -0
- package/dist/apps/shared/components/layout/SharedMailboxKeyManager.js +72 -0
- package/dist/apps/shared/components/layout/UnlockPromptProvider.d.ts +3 -0
- package/dist/apps/shared/components/layout/UnlockPromptProvider.js +32 -0
- package/dist/apps/shared/components/mail/ConversationList.js +1 -1
- package/dist/apps/shared/components/mail/MessageDetailPane.js +34 -13
- package/dist/apps/shared/components/mail/compose/draftResume.d.ts +2 -0
- package/dist/apps/shared/components/mail/compose/draftResume.js +28 -3
- package/dist/apps/shared/components/mail/compose/quotedBody.d.ts +1 -1
- package/dist/apps/shared/components/mail/compose/quotedBody.js +4 -3
- package/dist/apps/shared/components/mail/invite/inviteStore.js +6 -1
- package/dist/apps/shared/components/mail/layout/MailShell.js +2 -1
- package/dist/apps/shared/components/mail/reading/useMessageActions.js +4 -1
- package/dist/apps/shared/components/settings/KeyExportSetting.d.ts +13 -0
- package/dist/apps/shared/components/settings/KeyExportSetting.js +88 -0
- package/dist/apps/shared/components/settings/PolicyLockedNotice.d.ts +11 -0
- package/dist/apps/shared/components/settings/PolicyLockedNotice.js +9 -0
- package/dist/apps/shared/components/settings/ZeroAccessSetting.d.ts +14 -0
- package/dist/apps/shared/components/settings/ZeroAccessSetting.js +71 -0
- package/dist/apps/shared/mail/decryptedMessages.d.ts +1 -1
- package/dist/apps/shared/mail/decryptedMessages.js +11 -3
- package/dist/apps/shared/mail/outbox/sendJob.js +2 -2
- package/dist/apps/shared/mail/reportNotices.js +3 -1
- package/dist/apps/shared/mail/zeroAccessSource.d.ts +8 -0
- package/dist/apps/shared/mail/zeroAccessSource.js +26 -0
- package/dist/apps/shared/search/LocalIndexLifecycle.d.ts +2 -0
- package/dist/apps/shared/search/LocalIndexLifecycle.js +28 -0
- package/dist/apps/shared/search/localIndexBuilder.d.ts +5 -0
- package/dist/apps/shared/search/localIndexBuilder.js +24 -2
- package/dist/apps/shared/search/localIndexRpcClient.d.ts +1 -1
- package/dist/apps/shared/search/localIndexRpcClient.js +6 -4
- package/dist/apps/shared/search/localIndexSchema.d.ts +1 -1
- package/dist/apps/shared/search/localIndexSchema.js +2 -2
- package/dist/apps/shared/search/localIndexTransport.d.ts +2 -1
- package/dist/apps/shared/search/localIndexWorker.d.ts +2 -0
- package/dist/apps/shared/search/localIndexWorker.js +4 -4
- package/dist/apps/shared/search/zeroAccessIndexSync.d.ts +71 -0
- package/dist/apps/shared/search/zeroAccessIndexSync.js +382 -0
- package/dist/apps/www/calendar/index.js +41 -15
- package/dist/apps/www/index.js +10 -3
- package/dist/apps/www/settings/encryption/index.js +3 -1
- package/dist/apps/www/settings/privacy/index.js +1 -1
- package/dist/lib/admin/escrowAccessRequestsApi.d.ts +6 -0
- package/dist/lib/calendar/calendarApi.d.ts +6 -0
- package/dist/lib/calendar/inviteApi.js +27 -5
- package/dist/lib/calendar/sealedInvites.d.ts +11 -0
- package/dist/lib/calendar/sealedInvites.js +28 -0
- package/dist/lib/crypto/keyExport.d.ts +54 -0
- package/dist/lib/crypto/keyExport.js +161 -0
- package/dist/lib/crypto/keySession.d.ts +45 -1
- package/dist/lib/crypto/keySession.js +93 -2
- package/dist/lib/crypto/keyvaultApi.d.ts +88 -3
- package/dist/lib/crypto/keyvaultApi.js +32 -0
- package/dist/lib/crypto/messageSecurity.d.ts +30 -1
- package/dist/lib/crypto/messageSecurity.js +80 -4
- package/dist/lib/crypto/mime.d.ts +5 -0
- package/dist/lib/crypto/mime.js +25 -0
- package/dist/lib/crypto/sharedMailboxKeys.d.ts +50 -0
- package/dist/lib/crypto/sharedMailboxKeys.js +264 -0
- package/dist/lib/crypto/zeroAccessKey.d.ts +32 -0
- package/dist/lib/crypto/zeroAccessKey.js +66 -0
- package/dist/lib/mail/conversationsApi.d.ts +6 -0
- package/dist/lib/mail/mailApi.d.ts +30 -2
- package/dist/lib/mail/mailApi.js +5 -1
- package/dist/lib/search/zeroAccessIndexApi.d.ts +81 -0
- package/dist/lib/search/zeroAccessIndexApi.js +35 -0
- package/lib/admin/escrowAccessRequestsApi.ts +6 -0
- package/lib/calendar/calendarApi.ts +3 -0
- package/lib/calendar/inviteApi.ts +28 -5
- package/lib/calendar/sealedInvites.ts +33 -0
- package/lib/crypto/keyExport.ts +229 -0
- package/lib/crypto/keySession.ts +117 -3
- package/lib/crypto/keyvaultApi.ts +125 -3
- package/lib/crypto/messageSecurity.ts +110 -3
- package/lib/crypto/mime.ts +26 -0
- package/lib/crypto/sharedMailboxKeys.ts +324 -0
- package/lib/crypto/zeroAccessKey.ts +97 -0
- package/lib/mail/conversationsApi.ts +3 -0
- package/lib/mail/mailApi.ts +33 -3
- package/lib/search/zeroAccessIndexApi.ts +119 -0
- package/package.json +3 -3
|
@@ -15,6 +15,7 @@ import KeyEnrollmentGate from "../../layout/KeyEnrollmentGate.js";
|
|
|
15
15
|
import MailboxProvisioning from "../../layout/MailboxProvisioning.js";
|
|
16
16
|
import { prefetchComposeWindow, useCompose } from "../compose/ComposeContext.js";
|
|
17
17
|
import LocalIndexLifecycle from "../../../search/LocalIndexLifecycle.js";
|
|
18
|
+
import SharedMailboxKeyManager from "../../layout/SharedMailboxKeyManager.js";
|
|
18
19
|
import { NO_LIVE_UPDATES } from "../../../mail/useMailLiveUpdates.js";
|
|
19
20
|
import { MAILBOX_LIST_LIMIT, MailConnectionContext, useMailConnection } from "../../../mail/useMailConnection.js";
|
|
20
21
|
import { folderRows } from "../../../mail/folderTree.js";
|
|
@@ -264,7 +265,7 @@ export default function MailShell({ userUid, authServerUrl, impersonating, imper
|
|
|
264
265
|
// A shared/delegated mailbox the caller doesn't own is never provisioned from here - its keys
|
|
265
266
|
// belong to its owner (or its admins), not to whoever happens to open it first - and neither is
|
|
266
267
|
// the impersonated user's own mailbox: an administrator must never choose its password/recovery codes.
|
|
267
|
-
canProvision: !impersonating && activeMailbox?.ownerUserUid === userUid, children: [_jsx(LocalIndexLifecycle, { mailboxUid: activeMailboxUid, mailboxKeys: activeMailbox?.keys, folders: mailboxFolders.find((mf) => mf.mailbox.uid === activeMailboxUid)?.folders ?? [],
|
|
268
|
+
canProvision: !impersonating && activeMailbox?.ownerUserUid === userUid, children: [_jsx(SharedMailboxKeyManager, { mailboxes: mailboxes, userUid: userUid }), _jsx(LocalIndexLifecycle, { mailboxUid: activeMailboxUid, mailboxKeys: activeMailbox?.keys, folders: mailboxFolders.find((mf) => mf.mailbox.uid === activeMailboxUid)?.folders ?? [],
|
|
268
269
|
// A full page may be truncated - pruning against it would delete indexes of accessible mailboxes
|
|
269
270
|
// beyond the limit, so it's only trusted as the complete list when it came back short.
|
|
270
271
|
accessibleMailboxUids: status === "ready" && mailboxes.length < MAILBOX_LIST_LIMIT ? mailboxes.map((mb) => mb.uid) : undefined }), _jsx(AppShell, { active: "mail", userUid: userUid, authServerUrl: authServerUrl, impersonating: impersonating, impersonationBaseUrl: impersonationBaseUrl, trusted: trusted, trustedRoles: trustedRoles, pluginNav: pluginNav, children: inner })] }));
|
|
@@ -11,6 +11,7 @@ import { resolveFolderOfType } from "../../../mail/folderOfType.js";
|
|
|
11
11
|
import { setReadStateMany } from "../../../mail/messageReadState.js";
|
|
12
12
|
import { usePermanentDelete } from "../../../mail/usePermanentDelete.js";
|
|
13
13
|
import { reportFolderName, reportNotice, reportNoun, reportTitle, senderListsHref } from "../../../mail/reportNotices.js";
|
|
14
|
+
import { zeroAccessSourceBase64 } from "../../../mail/zeroAccessSource.js";
|
|
14
15
|
import { blockSender, neverBlockSender, normalizeAddresses, removeSenderRule } from "../../../mail/senderBlocking.js";
|
|
15
16
|
import { notifyApiError } from "../../../notifications/apiErrors.js";
|
|
16
17
|
import { notify } from "../../../notifications/store.js";
|
|
@@ -122,7 +123,9 @@ export function useMessageActions(params) {
|
|
|
122
123
|
await exclusive(async () => {
|
|
123
124
|
let result;
|
|
124
125
|
try {
|
|
125
|
-
|
|
126
|
+
// The server holds only the sealed copy of a zero-access message: its spam filter learns from the source decrypted here.
|
|
127
|
+
const rawMessage = await zeroAccessSourceBase64(message, client);
|
|
128
|
+
result = await reportMessage(message.uid, kind, { alwaysTrustSender, ...(rawMessage ? { rawMessage } : {}) }, client);
|
|
126
129
|
}
|
|
127
130
|
catch (err) {
|
|
128
131
|
if (isNotFound(err)) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { Mailbox } from "../../../../lib/mail/mailApi.js";
|
|
3
|
+
export interface KeyExportSettingProps {
|
|
4
|
+
mailbox: Mailbox;
|
|
5
|
+
/** The caller owns the mailbox and isn't impersonating: restapi records an export only for the owner. */
|
|
6
|
+
canManage: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* "Export keys for Outlook/phone" (`lib/crypto/keyExport.ts`): a passphrase-protected `.p12` with the mailbox's zero-access
|
|
10
|
+
* and end-to-end encryption keys - and its signing key, if the user ticks the box - so a mail app that isn't RapidMX can read
|
|
11
|
+
* mail stored encrypted. Asks for the master password again however long the mailbox has been unlocked.
|
|
12
|
+
*/
|
|
13
|
+
export default function KeyExportSetting({ mailbox, canManage }: KeyExportSettingProps): React.JSX.Element;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
3
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
4
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
5
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { exportKeysAsPkcs12, MIN_EXPORT_PASSPHRASE_LENGTH, NothingToExportError } from "../../../../lib/crypto/keyExport.js";
|
|
8
|
+
import { ApiRequestError } from "../../../../lib/util/api.js";
|
|
9
|
+
import { useApiClient } from "../../../../lib/util/apiClientContext.js";
|
|
10
|
+
import Alert from "../../../../lib/components/feedback/Alert.js";
|
|
11
|
+
import Button from "../../../../lib/components/buttons/Button.js";
|
|
12
|
+
import { notifyApiError } from "../../notifications/apiErrors.js";
|
|
13
|
+
import PolicyLockedNotice from "./PolicyLockedNotice.js";
|
|
14
|
+
const INPUT_CLASS = "w-full text-sm border border-border rounded-sm py-1.5 px-2 bg-surface";
|
|
15
|
+
/** Hands `bytes` to the browser as a file download. */
|
|
16
|
+
function saveFile(bytes, filename) {
|
|
17
|
+
const url = URL.createObjectURL(new Blob([bytes], { type: "application/x-pkcs12" }));
|
|
18
|
+
const link = document.createElement("a");
|
|
19
|
+
link.href = url;
|
|
20
|
+
link.download = filename;
|
|
21
|
+
document.body.appendChild(link);
|
|
22
|
+
link.click();
|
|
23
|
+
link.remove();
|
|
24
|
+
URL.revokeObjectURL(url);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* "Export keys for Outlook/phone" (`lib/crypto/keyExport.ts`): a passphrase-protected `.p12` with the mailbox's zero-access
|
|
28
|
+
* and end-to-end encryption keys - and its signing key, if the user ticks the box - so a mail app that isn't RapidMX can read
|
|
29
|
+
* mail stored encrypted. Asks for the master password again however long the mailbox has been unlocked.
|
|
30
|
+
*/
|
|
31
|
+
export default function KeyExportSetting({ mailbox, canManage }) {
|
|
32
|
+
const client = useApiClient();
|
|
33
|
+
const [open, setOpen] = useState(false);
|
|
34
|
+
const [password, setPassword] = useState("");
|
|
35
|
+
const [passphrase, setPassphrase] = useState("");
|
|
36
|
+
const [confirmPassphrase, setConfirmPassphrase] = useState("");
|
|
37
|
+
const [includeSigningKey, setIncludeSigningKey] = useState(false);
|
|
38
|
+
const [exporting, setExporting] = useState(false);
|
|
39
|
+
const [error, setError] = useState(null);
|
|
40
|
+
function reset() {
|
|
41
|
+
setOpen(false);
|
|
42
|
+
setPassword("");
|
|
43
|
+
setPassphrase("");
|
|
44
|
+
setConfirmPassphrase("");
|
|
45
|
+
setIncludeSigningKey(false);
|
|
46
|
+
setError(null);
|
|
47
|
+
}
|
|
48
|
+
async function handleExport(e) {
|
|
49
|
+
e.preventDefault();
|
|
50
|
+
if (passphrase.length < MIN_EXPORT_PASSPHRASE_LENGTH) {
|
|
51
|
+
setError(`The file's passphrase must be at least ${MIN_EXPORT_PASSPHRASE_LENGTH} characters.`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (passphrase !== confirmPassphrase) {
|
|
55
|
+
setError("The passphrases don't match.");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
setExporting(true);
|
|
59
|
+
setError(null);
|
|
60
|
+
try {
|
|
61
|
+
const result = await exportKeysAsPkcs12({
|
|
62
|
+
mailboxUid: mailbox.uid,
|
|
63
|
+
mailboxAddress: mailbox.primarySmtpAddress,
|
|
64
|
+
mailboxKeys: mailbox.keys ?? [],
|
|
65
|
+
masterPassword: password,
|
|
66
|
+
exportPassphrase: passphrase,
|
|
67
|
+
includeSigningKey,
|
|
68
|
+
}, client);
|
|
69
|
+
saveFile(result.pkcs12, `${mailbox.primarySmtpAddress}-keys.p12`);
|
|
70
|
+
reset();
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
if (err instanceof ApiRequestError) {
|
|
74
|
+
notifyApiError(err, "Couldn't export your keys");
|
|
75
|
+
}
|
|
76
|
+
else if (err instanceof NothingToExportError || (err instanceof Error && err.message.startsWith("This mailbox has no password"))) {
|
|
77
|
+
setError(err.message);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
setError("Incorrect password.");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
setExporting(false);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return (_jsxs("div", { children: [_jsx("h2", { className: "text-sm font-semibold mb-2", children: "Export keys for Outlook or a phone" }), _jsx("p", { className: "text-sm text-text-muted mb-2", children: "Mail apps other than RapidMX need your keys to read encrypted mail. The exported file holds your zero-access and end-to-end encryption keys, protected by a passphrase you choose. Anyone with the file and its passphrase can read all of this mailbox\u2019s mail, so keep it safe and delete it once it\u2019s installed." }), !canManage ? (_jsx(PolicyLockedNotice, { children: "Only this mailbox\u2019s owner, signed in as themselves, can export its keys." })) : !open ? (_jsx(Button, { type: "button", variant: "secondary", className: "!w-auto", onClick: () => setOpen(true), children: "Export keys\u2026" })) : (_jsxs("form", { onSubmit: (e) => void handleExport(e), className: "flex flex-col gap-2", children: [_jsx("input", { type: "password", "aria-label": "Encryption password", placeholder: "Encryption password", className: INPUT_CLASS, value: password, onChange: (e) => setPassword(e.target.value), disabled: exporting, autoComplete: "current-password" }), _jsx("input", { type: "password", "aria-label": "File passphrase", placeholder: `File passphrase (at least ${MIN_EXPORT_PASSPHRASE_LENGTH} characters)`, className: INPUT_CLASS, value: passphrase, onChange: (e) => setPassphrase(e.target.value), disabled: exporting, autoComplete: "new-password" }), _jsx("input", { type: "password", "aria-label": "Confirm file passphrase", placeholder: "Confirm file passphrase", className: INPUT_CLASS, value: confirmPassphrase, onChange: (e) => setConfirmPassphrase(e.target.value), disabled: exporting, autoComplete: "new-password" }), _jsxs("label", { className: "flex items-start gap-2 text-sm", children: [_jsx("input", { type: "checkbox", className: "mt-1", checked: includeSigningKey, onChange: (e) => setIncludeSigningKey(e.target.checked), disabled: exporting }), _jsxs("span", { children: [_jsx("span", { className: "font-semibold block", children: "Include my signing key" }), _jsx("span", { className: "text-xs text-text-muted", children: "Only if that app will sign mail you send. Anyone with the file could sign as you." })] })] }), error && _jsx(Alert, { children: error }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { type: "submit", className: "!w-auto", disabled: exporting || !password || !passphrase, children: exporting ? "Exporting…" : "Export" }), _jsx(Button, { type: "button", variant: "secondary", className: "!w-auto", onClick: reset, disabled: exporting, children: "Cancel" })] })] }))] }));
|
|
88
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface PolicyLockedNoticeProps {
|
|
3
|
+
/** Why the setting next to this notice can't be changed - e.g. that an administrator turned it off for the server. */
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Explains why a settings control is disabled by a policy the user can't change themselves (an administrator's server-wide
|
|
8
|
+
* setting, say), shown right under that control. A disabled control with no reason reads as a defect; this says who decided
|
|
9
|
+
* and that the user isn't the one who can undo it.
|
|
10
|
+
*/
|
|
11
|
+
export default function PolicyLockedNotice({ children }: PolicyLockedNoticeProps): React.JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Explains why a settings control is disabled by a policy the user can't change themselves (an administrator's server-wide
|
|
4
|
+
* setting, say), shown right under that control. A disabled control with no reason reads as a defect; this says who decided
|
|
5
|
+
* and that the user isn't the one who can undo it.
|
|
6
|
+
*/
|
|
7
|
+
export default function PolicyLockedNotice({ children }) {
|
|
8
|
+
return (_jsx("p", { role: "note", className: "mt-1.5 text-xs text-text-muted border-l-2 border-border pl-2", children: children }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type Mailbox } from "../../../../lib/mail/mailApi.js";
|
|
3
|
+
export interface ZeroAccessSettingProps {
|
|
4
|
+
mailbox: Mailbox;
|
|
5
|
+
/** The caller owns the mailbox and isn't impersonating: only then can the setting be changed (restapi drops anybody else's value). */
|
|
6
|
+
canManage: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* "Enable zero-access encryption" for one mailbox (restapi `specs/search.md` §3): unencrypted mail is encrypted to the
|
|
10
|
+
* mailbox's zero-access key as it arrives and the server keeps no readable copy. On by default. Shown disabled, with the
|
|
11
|
+
* reason, when the administrator has turned "Allow zero-access encryption" off for the server, or when the server doesn't
|
|
12
|
+
* support it. A shared mailbox is covered too: its members read it through member key wraps (`sharedMailboxKeys.ts`).
|
|
13
|
+
*/
|
|
14
|
+
export default function ZeroAccessSetting({ mailbox, canManage }: ZeroAccessSettingProps): React.JSX.Element;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
3
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
4
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
5
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
6
|
+
import { useEffect, useState } from "react";
|
|
7
|
+
import { getEncryptionPolicy } from "../../../../lib/crypto/keyvaultApi.js";
|
|
8
|
+
import { getMailbox, updateMailbox } from "../../../../lib/mail/mailApi.js";
|
|
9
|
+
import { ApiRequestError } from "../../../../lib/util/api.js";
|
|
10
|
+
import { useApiClient } from "../../../../lib/util/apiClientContext.js";
|
|
11
|
+
import { notifyApiError } from "../../notifications/apiErrors.js";
|
|
12
|
+
import PolicyLockedNotice from "./PolicyLockedNotice.js";
|
|
13
|
+
/**
|
|
14
|
+
* "Enable zero-access encryption" for one mailbox (restapi `specs/search.md` §3): unencrypted mail is encrypted to the
|
|
15
|
+
* mailbox's zero-access key as it arrives and the server keeps no readable copy. On by default. Shown disabled, with the
|
|
16
|
+
* reason, when the administrator has turned "Allow zero-access encryption" off for the server, or when the server doesn't
|
|
17
|
+
* support it. A shared mailbox is covered too: its members read it through member key wraps (`sharedMailboxKeys.ts`).
|
|
18
|
+
*/
|
|
19
|
+
export default function ZeroAccessSetting({ mailbox, canManage }) {
|
|
20
|
+
const client = useApiClient();
|
|
21
|
+
const [enabled, setEnabled] = useState(mailbox.zeroAccessEnabled !== false);
|
|
22
|
+
const [blocker, setBlocker] = useState(undefined);
|
|
23
|
+
const [saving, setSaving] = useState(false);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
let cancelled = false;
|
|
26
|
+
void (async () => {
|
|
27
|
+
const policy = await getEncryptionPolicy(client).catch(() => undefined);
|
|
28
|
+
let next = null;
|
|
29
|
+
if (policy?.allowZeroAccess === undefined) {
|
|
30
|
+
next = "unsupported";
|
|
31
|
+
}
|
|
32
|
+
else if (!policy.allowZeroAccess) {
|
|
33
|
+
next = "disabled_by_admin";
|
|
34
|
+
}
|
|
35
|
+
if (!cancelled) {
|
|
36
|
+
setBlocker(next);
|
|
37
|
+
}
|
|
38
|
+
})();
|
|
39
|
+
return () => {
|
|
40
|
+
cancelled = true;
|
|
41
|
+
};
|
|
42
|
+
}, [mailbox.uid, client]);
|
|
43
|
+
async function save(next) {
|
|
44
|
+
setSaving(true);
|
|
45
|
+
const previous = enabled;
|
|
46
|
+
setEnabled(next);
|
|
47
|
+
try {
|
|
48
|
+
const write = (version) => updateMailbox({ uid: mailbox.uid, version, zeroAccessEnabled: next }, client);
|
|
49
|
+
try {
|
|
50
|
+
await write(mailbox.version);
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
// Enrolling a key (which happens on unlock) moves the mailbox's version on, so the copy this page was given may be
|
|
54
|
+
// behind: read it again and retry once.
|
|
55
|
+
if (!(err instanceof ApiRequestError && err.status === 409)) {
|
|
56
|
+
throw err;
|
|
57
|
+
}
|
|
58
|
+
await write((await getMailbox(mailbox.uid, {}, client)).version);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
setEnabled(previous);
|
|
63
|
+
notifyApiError(err, "Couldn't save the zero-access encryption setting");
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
setSaving(false);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const locked = blocker !== null;
|
|
70
|
+
return (_jsxs("div", { children: [_jsx("h2", { className: "text-sm font-semibold mb-2", children: "Zero-access encryption" }), _jsxs("label", { className: "flex items-start gap-2 text-sm", children: [_jsx("input", { type: "checkbox", className: "mt-1", checked: !locked && enabled, disabled: !canManage || locked || saving, onChange: (e) => void save(e.target.checked) }), _jsxs("span", { children: [_jsx("span", { className: "font-semibold block", children: "Enable zero-access encryption" }), _jsx("span", { className: "text-xs text-text-muted", children: "Mail that arrives unencrypted is encrypted the moment it is received, and the server keeps no copy it can read - nobody else, administrators included, can read it. You unlock it with your encryption password, and search of message contents happens on your device. Outlook and phone mail apps need your exported keys to read it. Turning this off only affects mail that arrives afterwards." })] })] }), blocker === "disabled_by_admin" && (_jsx(PolicyLockedNotice, { children: "Your administrator has turned off zero-access encryption for this server, so new mail is stored without it. Mail already encrypted stays encrypted." })), blocker === "unsupported" && _jsx(PolicyLockedNotice, { children: "This server doesn\u2019t offer zero-access encryption." }), !mailbox.ownerUserUid && !locked && (_jsx(PolicyLockedNotice, { children: "This shared mailbox has no owner: it is protected for its members, whose apps share its key with each other." })), !canManage && !locked && mailbox.ownerUserUid && (_jsx(PolicyLockedNotice, { children: "Only this mailbox\u2019s owner, signed in as themselves, can change this." }))] }));
|
|
71
|
+
}
|
|
@@ -32,4 +32,4 @@ export declare function useUnlockEpoch(): number;
|
|
|
32
32
|
* Decrypts one message to recover its subject and preview, when its mailbox's keys are unlocked and it isn't already known. Best effort: a
|
|
33
33
|
* message that can't be fetched or opened is simply left as it was. Never prompts.
|
|
34
34
|
*/
|
|
35
|
-
export declare function decryptForDisplay(uid: string, mailboxUid: string): Promise<void>;
|
|
35
|
+
export declare function decryptForDisplay(uid: string, mailboxUid: string, sealedSummary?: string): Promise<void>;
|
|
@@ -113,16 +113,24 @@ export function useUnlockEpoch() {
|
|
|
113
113
|
* Decrypts one message to recover its subject and preview, when its mailbox's keys are unlocked and it isn't already known. Best effort: a
|
|
114
114
|
* message that can't be fetched or opened is simply left as it was. Never prompts.
|
|
115
115
|
*/
|
|
116
|
-
export async function decryptForDisplay(uid, mailboxUid) {
|
|
116
|
+
export async function decryptForDisplay(uid, mailboxUid, sealedSummary) {
|
|
117
117
|
const unlocked = getUnlockedKeys(mailboxUid);
|
|
118
118
|
if (!unlocked || entries[uid] || inFlight.has(uid) || decryptFailedBefore(uid)) {
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
121
121
|
inFlight.add(uid);
|
|
122
122
|
try {
|
|
123
|
+
const securityApi = await import("../../../lib/crypto/messageSecurity.js");
|
|
124
|
+
// A message sealed at rest has its subject and preview sealed on its row: opening that small summary saves downloading it.
|
|
125
|
+
const summary = sealedSummary ? await securityApi.openZeroAccessSummary(sealedSummary, unlocked.zeroAccessKeys) : undefined;
|
|
126
|
+
if (summary) {
|
|
127
|
+
if (getUnlockedKeys(mailboxUid) === unlocked) {
|
|
128
|
+
rememberDecrypted(uid, mailboxUid, { subject: summary.subject, preview: summary.preview.slice(0, PREVIEW_MAX_LENGTH) });
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
123
132
|
const rawMime = await getMessageRawContent(uid);
|
|
124
|
-
const
|
|
125
|
-
const security = await evaluateMessageSecurity(rawMime, unlocked);
|
|
133
|
+
const security = await securityApi.evaluateMessageSecurity(rawMime, unlocked);
|
|
126
134
|
// A lock while this ran: the result must not go back on screen.
|
|
127
135
|
if (getUnlockedKeys(mailboxUid) === unlocked) {
|
|
128
136
|
rememberDecrypted(uid, mailboxUid, { subject: security.subject, preview: security.html ? previewOf(security.html) : security.text?.slice(0, PREVIEW_MAX_LENGTH) });
|
|
@@ -106,7 +106,7 @@ async function completeContext(request, client) {
|
|
|
106
106
|
async function assemble(request, mailbox, mode, statuses, withSignature, client) {
|
|
107
107
|
const { draft, to, cc, bcc, subject, html } = request;
|
|
108
108
|
if (mode === "plain") {
|
|
109
|
-
return assembleDraft(draft.uid, { to, cc, bcc, subject, html }, client);
|
|
109
|
+
return assembleDraft(draft.uid, { to, cc, bcc, subject, html, intent: "send" }, client);
|
|
110
110
|
}
|
|
111
111
|
const keys = readSendKeys(request.mailboxUid, request.signEnabled, mailbox);
|
|
112
112
|
const own = mailbox;
|
|
@@ -131,7 +131,7 @@ async function assemble(request, mailbox, mode, statuses, withSignature, client)
|
|
|
131
131
|
? await buildEncryptedMessage(bodyContentType, html, protectedHeaders, outerHeaders, [keys.unlocked.encryptionCertDer, ...statuses.map((status) => fromBase64(status.encryptCert.publicKey))], signing)
|
|
132
132
|
: await buildSignedOnlyMessage(bodyContentType, html, protectedHeaders, signing.certDer, signing.privateKey);
|
|
133
133
|
const rawMime = assembleOutboundMime(outerHeaders, mimePart);
|
|
134
|
-
return assembleDraftRaw(draft.uid, { to, cc, bcc, subject: outerHeaders.subject, rawMime }, client);
|
|
134
|
+
return assembleDraftRaw(draft.uid, { to, cc, bcc, subject: outerHeaders.subject, rawMime, intent: "send" }, client);
|
|
135
135
|
}
|
|
136
136
|
function failureOf(err, fallback) {
|
|
137
137
|
const failure = describeSendFailure(err, fallback);
|
|
@@ -42,6 +42,8 @@ export function reportNotice(result, subject, alwaysTrust) {
|
|
|
42
42
|
? "The spam filter could not be trained from this report."
|
|
43
43
|
: result.learnSkipped === "encrypted"
|
|
44
44
|
? "Not used to train the spam filter: the message is encrypted."
|
|
45
|
-
:
|
|
45
|
+
: result.learnSkipped === "zero_access"
|
|
46
|
+
? "Not used to train the spam filter: unlock your mailbox to let it learn from protected mail."
|
|
47
|
+
: undefined;
|
|
46
48
|
return { title: kind.title, message: parts.join(" "), hint };
|
|
47
49
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Message } from "../../../lib/mail/mailApi.js";
|
|
2
|
+
import type { ApiClient } from "../../../lib/util/api.js";
|
|
3
|
+
/**
|
|
4
|
+
* The original source of a zero-access `message`, decrypted with its mailbox's unlocked keys and base64-encoded - what the server, which holds
|
|
5
|
+
* only the sealed copy, needs for an action that reads the message itself (`reportMessage()`'s `rawMessage`). `undefined` for any other
|
|
6
|
+
* message, while the mailbox is locked, or when it can't be fetched or opened: the action then goes ahead without it.
|
|
7
|
+
*/
|
|
8
|
+
export declare function zeroAccessSourceBase64(message: Pick<Message, "uid" | "mailboxUid" | "zeroAccess">, client?: ApiClient): Promise<string | undefined>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import { getUnlockedKeys } from "../../../lib/crypto/keySession.js";
|
|
6
|
+
import { openZeroAccessMessage } from "../../../lib/crypto/messageSecurity.js";
|
|
7
|
+
import { getMessageRawContent } from "../../../lib/mail/mailApi.js";
|
|
8
|
+
/**
|
|
9
|
+
* The original source of a zero-access `message`, decrypted with its mailbox's unlocked keys and base64-encoded - what the server, which holds
|
|
10
|
+
* only the sealed copy, needs for an action that reads the message itself (`reportMessage()`'s `rawMessage`). `undefined` for any other
|
|
11
|
+
* message, while the mailbox is locked, or when it can't be fetched or opened: the action then goes ahead without it.
|
|
12
|
+
*/
|
|
13
|
+
export async function zeroAccessSourceBase64(message, client) {
|
|
14
|
+
const unlocked = message.zeroAccess ? getUnlockedKeys(message.mailboxUid) : undefined;
|
|
15
|
+
if (!unlocked) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const original = await openZeroAccessMessage(await getMessageRawContent(message.uid, client), unlocked);
|
|
20
|
+
// A binary string (one char per byte), which `btoa()` encodes as the bytes themselves.
|
|
21
|
+
return original === undefined ? undefined : btoa(original);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { PublicKey } from "../../../lib/crypto/keyvaultApi.js";
|
|
2
2
|
import type { Folder } from "../../../lib/mail/mailApi.js";
|
|
3
3
|
export declare const POLL_INTERVAL_MS = 5000;
|
|
4
|
+
/** How often an unlocked zero-access mailbox's local index is brought up to date with the server's sealed index. */
|
|
5
|
+
export declare const ZERO_ACCESS_SYNC_INTERVAL_MS = 120000;
|
|
4
6
|
export interface LocalIndexLifecycleProps {
|
|
5
7
|
mailboxUid?: string;
|
|
6
8
|
mailboxKeys?: PublicKey[];
|
|
@@ -34,8 +34,16 @@ const loadBuilder = () => (builder ?? (builder = import("./localIndexBuilder.js"
|
|
|
34
34
|
builder = undefined;
|
|
35
35
|
throw err;
|
|
36
36
|
})));
|
|
37
|
+
/** The zero-access index sync (`zeroAccessIndexSync.ts`), loaded the same way: only once a zero-access mailbox is unlocked. */
|
|
38
|
+
let syncer;
|
|
39
|
+
const loadSyncer = () => (syncer ?? (syncer = import("./zeroAccessIndexSync.js").catch((err) => {
|
|
40
|
+
syncer = undefined;
|
|
41
|
+
throw err;
|
|
42
|
+
})));
|
|
37
43
|
import { destroyLocalIndex, pruneInaccessibleLocalIndexes } from "./localIndexRpcClient.js";
|
|
38
44
|
export const POLL_INTERVAL_MS = 5000;
|
|
45
|
+
/** How often an unlocked zero-access mailbox's local index is brought up to date with the server's sealed index. */
|
|
46
|
+
export const ZERO_ACCESS_SYNC_INTERVAL_MS = 120000;
|
|
39
47
|
/** Renders nothing - pure side-effect component, mounted by `MailShell.tsx`. */
|
|
40
48
|
export default function LocalIndexLifecycle({ mailboxUid, folders, accessibleMailboxUids }) {
|
|
41
49
|
// The explicit ApiClient (from useApiClient()) this component is rendered under - undefined for every existing caller (the SSR web/admin
|
|
@@ -49,6 +57,23 @@ export default function LocalIndexLifecycle({ mailboxUid, folders, accessibleMai
|
|
|
49
57
|
// The latest props (and client), for the long-lived polling interval below.
|
|
50
58
|
const latestRef = useRef({ mailboxUid, folders, client });
|
|
51
59
|
latestRef.current = { mailboxUid, folders, client };
|
|
60
|
+
// mailboxUid -> when its last zero-access sync started. Set only once its first build finished (the sync writes into the index the
|
|
61
|
+
// build opened); a mailbox in `syncingRef` has a pass running, and never gets a second one alongside it.
|
|
62
|
+
const lastSyncRef = useRef(new Map());
|
|
63
|
+
const syncingRef = useRef(new Set());
|
|
64
|
+
function syncIfDue(targetMailboxUid, targetClient, first = false) {
|
|
65
|
+
const unlocked = getUnlockedKeys(targetMailboxUid);
|
|
66
|
+
const last = lastSyncRef.current.get(targetMailboxUid);
|
|
67
|
+
if (!unlocked?.zeroAccessKeys?.length || syncingRef.current.has(targetMailboxUid) || (!first && (last === undefined || Date.now() - last < ZERO_ACCESS_SYNC_INTERVAL_MS))) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
lastSyncRef.current.set(targetMailboxUid, Date.now());
|
|
71
|
+
syncingRef.current.add(targetMailboxUid);
|
|
72
|
+
loadSyncer()
|
|
73
|
+
.then(({ syncZeroAccessIndex }) => syncZeroAccessIndex(targetMailboxUid, unlocked, targetClient))
|
|
74
|
+
.catch(() => undefined)
|
|
75
|
+
.finally(() => syncingRef.current.delete(targetMailboxUid));
|
|
76
|
+
}
|
|
52
77
|
function startBuildIfUnlocked(targetMailboxUid, targetFolders, targetClient) {
|
|
53
78
|
const unlocked = getUnlockedKeys(targetMailboxUid);
|
|
54
79
|
if (!unlocked || targetFolders.length === 0 || trackedRef.current.get(targetMailboxUid)) {
|
|
@@ -59,6 +84,7 @@ export default function LocalIndexLifecycle({ mailboxUid, folders, accessibleMai
|
|
|
59
84
|
// the rest of the app depends on.
|
|
60
85
|
loadBuilder()
|
|
61
86
|
.then(({ buildLocalIndex }) => buildLocalIndex(targetMailboxUid, unlocked, targetFolders, undefined, targetClient))
|
|
87
|
+
.then(() => syncIfDue(targetMailboxUid, targetClient, true))
|
|
62
88
|
.catch(() => undefined);
|
|
63
89
|
}
|
|
64
90
|
useEffect(() => {
|
|
@@ -72,6 +98,7 @@ export default function LocalIndexLifecycle({ mailboxUid, folders, accessibleMai
|
|
|
72
98
|
if (wasUnlocked && !getUnlockedKeys(trackedUid)) {
|
|
73
99
|
// A present-to-absent transition: something just destroyed this mailbox's keys.
|
|
74
100
|
trackedRef.current.set(trackedUid, false);
|
|
101
|
+
lastSyncRef.current.delete(trackedUid);
|
|
75
102
|
// Stop the pass still running with the now-destroyed keys; the destroy itself also makes
|
|
76
103
|
// the Worker reject anything that pass still sends.
|
|
77
104
|
loadBuilder()
|
|
@@ -84,6 +111,7 @@ export default function LocalIndexLifecycle({ mailboxUid, folders, accessibleMai
|
|
|
84
111
|
const { mailboxUid: activeUid, folders: activeFolders, client: activeClient } = latestRef.current;
|
|
85
112
|
if (activeUid) {
|
|
86
113
|
startBuildIfUnlocked(activeUid, activeFolders, activeClient);
|
|
114
|
+
syncIfDue(activeUid, activeClient);
|
|
87
115
|
}
|
|
88
116
|
}, POLL_INTERVAL_MS);
|
|
89
117
|
return () => clearInterval(interval);
|
|
@@ -20,6 +20,11 @@
|
|
|
20
20
|
* fully searchable via Tier 1; indexing it here too would spend this index's bounded byte budget on
|
|
21
21
|
* content that didn't need it.
|
|
22
22
|
*
|
|
23
|
+
* **Shared with the mailbox's other devices (Source C).** In a mailbox with a zero-access key, a pass first imports the end-to-end mail
|
|
24
|
+
* other devices already decrypted (`importClientSegments()`), at each message's version, so it isn't decrypted again here; and what this
|
|
25
|
+
* pass decrypts it uploads for them, sealed to the zero-access key (`uploadClientDocuments()`). Both are best effort - see
|
|
26
|
+
* `zeroAccessIndexSync.ts`.
|
|
27
|
+
*
|
|
23
28
|
* **Verification seals.** A message this pass decrypts that has no seal for the vault's current `masterKeyGeneration` is
|
|
24
29
|
* evaluated with `evaluateMessageSecurityWithSeal()`, against the sender's pinned signing keys from the reader's
|
|
25
30
|
* contacts (`pinnedSigners.ts`, the message pane's own source, looked up once per sender per pass), so a verified
|
|
@@ -24,6 +24,11 @@
|
|
|
24
24
|
* fully searchable via Tier 1; indexing it here too would spend this index's bounded byte budget on
|
|
25
25
|
* content that didn't need it.
|
|
26
26
|
*
|
|
27
|
+
* **Shared with the mailbox's other devices (Source C).** In a mailbox with a zero-access key, a pass first imports the end-to-end mail
|
|
28
|
+
* other devices already decrypted (`importClientSegments()`), at each message's version, so it isn't decrypted again here; and what this
|
|
29
|
+
* pass decrypts it uploads for them, sealed to the zero-access key (`uploadClientDocuments()`). Both are best effort - see
|
|
30
|
+
* `zeroAccessIndexSync.ts`.
|
|
31
|
+
*
|
|
27
32
|
* **Verification seals.** A message this pass decrypts that has no seal for the vault's current `masterKeyGeneration` is
|
|
28
33
|
* evaluated with `evaluateMessageSecurityWithSeal()`, against the sender's pinned signing keys from the reader's
|
|
29
34
|
* contacts (`pinnedSigners.ts`, the message pane's own source, looked up once per sender per pass), so a verified
|
|
@@ -39,9 +44,10 @@ import { getMessageRawContent, listFolders, listMessages } from "../../../lib/ma
|
|
|
39
44
|
import { evaluateMessageSecurity, evaluateMessageSecurityWithSeal } from "../../../lib/crypto/messageSecurity.js";
|
|
40
45
|
import { getPinnedSignerFingerprints } from "../components/mail/pinnedSigners.js";
|
|
41
46
|
import { currentVerificationSeal, readVaultGeneration, sendVerificationSeal, verificationSealPending } from "../components/mail/verificationSeals.js";
|
|
42
|
-
import { getIndexedVersions, indexLocalEntities, initLocalIndex, nextLocalIndexGeneration, pruneLocalEntities, setLocalIndexBuilding, setLocalIndexWindow, } from "./localIndexRpcClient.js";
|
|
47
|
+
import { getIndexedVersions, moveLocalEntity, indexLocalEntities, initLocalIndex, nextLocalIndexGeneration, pruneLocalEntities, setLocalIndexBuilding, setLocalIndexWindow, } from "./localIndexRpcClient.js";
|
|
43
48
|
import { deriveLocalIndexKey } from "./localIndexKey.js";
|
|
44
49
|
import { getLocalIndexByteBudget } from "./localIndexSizePreference.js";
|
|
50
|
+
import { importClientSegments, uploadClientDocuments } from "./zeroAccessIndexSync.js";
|
|
45
51
|
/** The RFC 9788 placeholder subject every encrypted message's outer envelope carries server-side - see
|
|
46
52
|
* `apps/www/index.tsx`'s identical constant and its own doc comment for the full citation. */
|
|
47
53
|
const ENCRYPTED_SUBJECT_PLACEHOLDER = "[...]";
|
|
@@ -287,6 +293,9 @@ async function runBuildPass(mailboxUid, unlocked, folders, windowConfig, signal,
|
|
|
287
293
|
await initLocalIndex({ mailboxUid, indexKey, generation });
|
|
288
294
|
let { evictedBefore } = await setLocalIndexWindow(mailboxUid, windowConfig.timeFloorMonths, windowConfig.byteBudgetBytes, generation);
|
|
289
295
|
await setLocalIndexBuilding(mailboxUid, true, { complete: false, generation });
|
|
296
|
+
// End-to-end mail another device already decrypted: imported at its version, so the walk below skips it.
|
|
297
|
+
await importClientSegments(mailboxUid, unlocked, client, { generation }).catch(() => undefined);
|
|
298
|
+
signal.throwIfAborted();
|
|
290
299
|
// Mail arriving after this moment isn't guaranteed to be picked up by this pass.
|
|
291
300
|
const coveredUntil = new Date(Date.now() - CLOCK_SKEW_MARGIN_MS).toISOString();
|
|
292
301
|
let cutoff;
|
|
@@ -307,6 +316,8 @@ async function runBuildPass(mailboxUid, unlocked, folders, windowConfig, signal,
|
|
|
307
316
|
.filter((f) => MESSAGE_FOLDER_TYPES.has(f.type))
|
|
308
317
|
.sort((a, b) => (FOLDER_PRIORITY[a.type] ?? 99) - (FOLDER_PRIORITY[b.type] ?? 99));
|
|
309
318
|
const seenEncryptedUids = new Set();
|
|
319
|
+
// What this pass decrypted, for the mailbox's other devices.
|
|
320
|
+
const decrypted = [];
|
|
310
321
|
async function walkFolder(folder) {
|
|
311
322
|
for (let page = 0;; page++) {
|
|
312
323
|
signal.throwIfAborted();
|
|
@@ -324,8 +335,17 @@ async function runBuildPass(mailboxUid, unlocked, folders, windowConfig, signal,
|
|
|
324
335
|
for (const m of encrypted) {
|
|
325
336
|
seenEncryptedUids.add(m.uid);
|
|
326
337
|
}
|
|
338
|
+
// A zero-access message's content comes from the server's sealed index (`zeroAccessIndexSync.ts`), never decrypted here:
|
|
339
|
+
// only its folder is recorded on its row - and remembered by version, so an unchanged one costs nothing next time.
|
|
340
|
+
const sealed = encrypted.filter((m) => m.zeroAccess);
|
|
341
|
+
if (sealed.length > 0) {
|
|
342
|
+
const indexed = await getIndexedVersions(mailboxUid, sealed.map((m) => m.uid));
|
|
343
|
+
for (const m of sealed.filter((s) => indexed[s.uid] !== versionOf(s))) {
|
|
344
|
+
await moveLocalEntity(mailboxUid, m.uid, m.folderUid, versionOf(m));
|
|
345
|
+
}
|
|
346
|
+
}
|
|
327
347
|
// Anything older than the eviction watermark would only be inserted and evicted again.
|
|
328
|
-
const candidates = encrypted.filter((m) => !isOlderThan(m.receivedDate, evictedBefore));
|
|
348
|
+
const candidates = encrypted.filter((m) => !m.zeroAccess && !isOlderThan(m.receivedDate, evictedBefore));
|
|
329
349
|
if (candidates.length > 0) {
|
|
330
350
|
// Skip anything already indexed at the same version - a re-unlock used to re-fetch and
|
|
331
351
|
// re-decrypt the entire window every time.
|
|
@@ -339,6 +359,7 @@ async function runBuildPass(mailboxUid, unlocked, folders, windowConfig, signal,
|
|
|
339
359
|
const entities = built.filter((e) => e !== undefined && e !== FETCH_FAILED);
|
|
340
360
|
if (entities.length > 0) {
|
|
341
361
|
({ evictedBefore } = await indexLocalEntities(mailboxUid, entities, generation));
|
|
362
|
+
decrypted.push(...entities);
|
|
342
363
|
}
|
|
343
364
|
}
|
|
344
365
|
const oldestOnPage = messages[messages.length - 1].receivedDate;
|
|
@@ -397,6 +418,7 @@ async function runBuildPass(mailboxUid, unlocked, folders, windowConfig, signal,
|
|
|
397
418
|
const since = evictedBefore && isWithinTimeFloor(evictedBefore, cutoff) ? evictedBefore : cutoff?.toISOString();
|
|
398
419
|
await pruneLocalEntities(mailboxUid, [...seenEncryptedUids], since, { folderUids: reliable, generation });
|
|
399
420
|
}
|
|
421
|
+
await uploadClientDocuments(mailboxUid, unlocked, decrypted, client).catch(() => undefined);
|
|
400
422
|
}
|
|
401
423
|
catch (err) {
|
|
402
424
|
complete = false;
|
|
@@ -66,7 +66,7 @@ export declare function indexLocalEntities(mailboxUid: string, entities: LocalIn
|
|
|
66
66
|
export declare function removeLocalEntity(mailboxUid: string, entityUid: string): Promise<void>;
|
|
67
67
|
/** Re-points one indexed message at its new folder (archive, cancel-scheduled-send) so `folder:`-scoped
|
|
68
68
|
* local searches stay correct. Same no-op/never-rejects rules as `removeLocalEntity()`. */
|
|
69
|
-
export declare function moveLocalEntity(mailboxUid: string, entityUid: string, folderUid: string): Promise<void>;
|
|
69
|
+
export declare function moveLocalEntity(mailboxUid: string, entityUid: string, folderUid: string, entityVersion?: string): Promise<void>;
|
|
70
70
|
export declare function getIndexedVersions(mailboxUid: string, entityUids: string[]): Promise<Record<string, string>>;
|
|
71
71
|
export declare function pruneLocalEntities(mailboxUid: string, keepEntityUids: string[], since: string | undefined, options?: PruneLocalEntitiesOptions): Promise<number>;
|
|
72
72
|
export declare function searchLocal(mailboxUid: string, parsed: ParsedSearchQuery, limit: number, offset?: number): Promise<LocalSearchPage>;
|
|
@@ -174,11 +174,11 @@ async function removeLocalEntityImpl(mailboxUid, entityUid) {
|
|
|
174
174
|
}
|
|
175
175
|
/** Re-points one indexed message at its new folder (archive, cancel-scheduled-send) so `folder:`-scoped
|
|
176
176
|
* local searches stay correct. Same no-op/never-rejects rules as `removeLocalEntityImpl()`. */
|
|
177
|
-
async function moveLocalEntityImpl(mailboxUid, entityUid, folderUid) {
|
|
177
|
+
async function moveLocalEntityImpl(mailboxUid, entityUid, folderUid, entityVersion) {
|
|
178
178
|
if (!initializedMailboxes.has(mailboxUid)) {
|
|
179
179
|
return;
|
|
180
180
|
}
|
|
181
|
-
await call("moveEntity", { mailboxUid, entityUid, folderUid }).catch(() => undefined);
|
|
181
|
+
await call("moveEntity", { mailboxUid, entityUid, folderUid, ...(entityVersion !== undefined ? { entityVersion } : {}) }).catch(() => undefined);
|
|
182
182
|
}
|
|
183
183
|
function getIndexedVersionsImpl(mailboxUid, entityUids) {
|
|
184
184
|
return call("indexedVersions", { mailboxUid, entityUids });
|
|
@@ -318,8 +318,10 @@ export function removeLocalEntity(mailboxUid, entityUid) {
|
|
|
318
318
|
}
|
|
319
319
|
/** Re-points one indexed message at its new folder (archive, cancel-scheduled-send) so `folder:`-scoped
|
|
320
320
|
* local searches stay correct. Same no-op/never-rejects rules as `removeLocalEntity()`. */
|
|
321
|
-
export function moveLocalEntity(mailboxUid, entityUid, folderUid) {
|
|
322
|
-
return
|
|
321
|
+
export function moveLocalEntity(mailboxUid, entityUid, folderUid, entityVersion) {
|
|
322
|
+
return entityVersion !== undefined
|
|
323
|
+
? currentTransport.moveEntity(mailboxUid, entityUid, folderUid, entityVersion)
|
|
324
|
+
: currentTransport.moveEntity(mailboxUid, entityUid, folderUid);
|
|
323
325
|
}
|
|
324
326
|
export function getIndexedVersions(mailboxUid, entityUids) {
|
|
325
327
|
return currentTransport.indexedVersions(mailboxUid, entityUids);
|
|
@@ -62,7 +62,7 @@ export interface LocalIndexEntity {
|
|
|
62
62
|
/** `entity_uid` upsert - `ON CONFLICT` (SQLite's UPSERT syntax) rather than a separate delete-then-insert,
|
|
63
63
|
* so re-indexing an already-present message (a flag changed, a folder move) updates it in place and the
|
|
64
64
|
* `entities_au` trigger keeps `entities_fts` in sync automatically. */
|
|
65
|
-
export declare const UPSERT_ENTITY_SQL = "\nINSERT INTO entities (entity_type, entity_uid, mailbox_uid, folder_uid, date_for_sort, participants, flags, has_attachments, subject, body, attachment_text, byte_size, entity_version)\nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\nON CONFLICT(entity_uid) DO UPDATE SET\n folder_uid = excluded.folder_uid, date_for_sort = excluded.date_for_sort, participants = excluded.participants,\n flags = excluded.flags, has_attachments = excluded.has_attachments, subject = excluded.subject,\n body = excluded.body, attachment_text = excluded.attachment_text, byte_size = excluded.byte_size,\n entity_version = excluded.entity_version\n";
|
|
65
|
+
export declare const UPSERT_ENTITY_SQL = "\nINSERT INTO entities (entity_type, entity_uid, mailbox_uid, folder_uid, date_for_sort, participants, flags, has_attachments, subject, body, attachment_text, byte_size, entity_version)\nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\nON CONFLICT(entity_uid) DO UPDATE SET\n folder_uid = COALESCE(excluded.folder_uid, entities.folder_uid), date_for_sort = excluded.date_for_sort, participants = excluded.participants,\n flags = CASE WHEN excluded.flags = '' THEN entities.flags ELSE excluded.flags END, has_attachments = excluded.has_attachments, subject = excluded.subject,\n body = excluded.body, attachment_text = excluded.attachment_text, byte_size = excluded.byte_size,\n entity_version = excluded.entity_version\n";
|
|
66
66
|
/** Bind values for `UPSERT_ENTITY_SQL`, in column order - kept alongside it so the two can never drift
|
|
67
67
|
* out of sync with each other. */
|
|
68
68
|
export declare function entityBindValues(entity: LocalIndexEntity): (string | number)[];
|
|
@@ -91,8 +91,8 @@ export const UPSERT_ENTITY_SQL = `
|
|
|
91
91
|
INSERT INTO entities (entity_type, entity_uid, mailbox_uid, folder_uid, date_for_sort, participants, flags, has_attachments, subject, body, attachment_text, byte_size, entity_version)
|
|
92
92
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
93
93
|
ON CONFLICT(entity_uid) DO UPDATE SET
|
|
94
|
-
folder_uid = excluded.folder_uid, date_for_sort = excluded.date_for_sort, participants = excluded.participants,
|
|
95
|
-
flags = excluded.flags, has_attachments = excluded.has_attachments, subject = excluded.subject,
|
|
94
|
+
folder_uid = COALESCE(excluded.folder_uid, entities.folder_uid), date_for_sort = excluded.date_for_sort, participants = excluded.participants,
|
|
95
|
+
flags = CASE WHEN excluded.flags = '' THEN entities.flags ELSE excluded.flags END, has_attachments = excluded.has_attachments, subject = excluded.subject,
|
|
96
96
|
body = excluded.body, attachment_text = excluded.attachment_text, byte_size = excluded.byte_size,
|
|
97
97
|
entity_version = excluded.entity_version
|
|
98
98
|
`;
|
|
@@ -52,7 +52,8 @@ export interface LocalIndexTransport {
|
|
|
52
52
|
/** Drops one indexed entity. */
|
|
53
53
|
removeEntity(mailboxUid: string, entityUid: string): Promise<void>;
|
|
54
54
|
/** Re-points one indexed entity at its new folder. */
|
|
55
|
-
|
|
55
|
+
/** `entityVersion`, when given, is recorded with the folder (a transport that can't record it leaves the row's version cleared). */
|
|
56
|
+
moveEntity(mailboxUid: string, entityUid: string, folderUid: string, entityVersion?: string): Promise<void>;
|
|
56
57
|
/** The indexed version marker (`Message.version` + folder) currently stored for each of the given entity uids. */
|
|
57
58
|
indexedVersions(mailboxUid: string, entityUids: string[]): Promise<Record<string, string>>;
|
|
58
59
|
/** Removes indexed rows outside `keepEntityUids` (and `since`/`options.folderUids`'s own scope). Returns how many rows were pruned. */
|
|
@@ -62,6 +62,8 @@ export interface MoveEntityParams {
|
|
|
62
62
|
mailboxUid: string;
|
|
63
63
|
entityUid: string;
|
|
64
64
|
folderUid: string;
|
|
65
|
+
/** Recorded as the row's `entity_version`; cleared (the row then counts as changed) when absent. */
|
|
66
|
+
entityVersion?: string;
|
|
65
67
|
}
|
|
66
68
|
export interface IndexedVersionsParams {
|
|
67
69
|
mailboxUid: string;
|