@rapidmx/web-client 0.35.0 → 0.37.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.
Files changed (268) hide show
  1. package/apps/escrow/matters/[uid].tsx +4 -3
  2. package/apps/shared/calendar/calendarReminders.ts +35 -0
  3. package/apps/shared/calendar/sealedEvents.ts +113 -0
  4. package/apps/shared/calendar/useCalendarReminders.ts +28 -9
  5. package/apps/shared/components/admin/settings/DomainDnsSetup.tsx +4 -0
  6. package/apps/shared/components/admin/settings/EncryptionPolicyForm.tsx +89 -3
  7. package/apps/shared/components/calendar/EventDetails.tsx +13 -2
  8. package/apps/shared/components/calendar/EventEditor.tsx +124 -17
  9. package/apps/shared/components/calendar/EventFormParts.tsx +1 -0
  10. package/apps/shared/components/calendar/EventModal.tsx +19 -2
  11. package/apps/shared/components/calendar/RequestChangeForm.tsx +4 -1
  12. package/apps/shared/components/calendar/eventForm.ts +2 -0
  13. package/apps/shared/components/contacts/ContactCard.tsx +13 -1
  14. package/apps/shared/components/contacts/ContactDetailPane.tsx +189 -9
  15. package/apps/shared/components/contacts/ContactForm.tsx +56 -7
  16. package/apps/shared/components/contacts/KeyChangeReview.tsx +5 -1
  17. package/apps/shared/components/contacts/contactCardData.ts +8 -4
  18. package/apps/shared/components/contacts/contactKeys.ts +3 -3
  19. package/apps/shared/components/layout/AppShell.tsx +34 -5
  20. package/apps/shared/components/layout/KeyEnrollmentGate.tsx +30 -1
  21. package/apps/shared/components/layout/SharedMailboxKeyManager.tsx +122 -0
  22. package/apps/shared/components/layout/UnlockPromptProvider.tsx +34 -0
  23. package/apps/shared/components/mail/ConversationList.tsx +1 -1
  24. package/apps/shared/components/mail/InviteCard.tsx +11 -1
  25. package/apps/shared/components/mail/MessageDetailPane.tsx +59 -26
  26. package/apps/shared/components/mail/compose/ComposeWindow.tsx +9 -2
  27. package/apps/shared/components/mail/compose/RecipientInput.tsx +2 -1
  28. package/apps/shared/components/mail/compose/draftResume.ts +28 -3
  29. package/apps/shared/components/mail/compose/protectedContactSuggestions.ts +121 -0
  30. package/apps/shared/components/mail/compose/quotedBody.ts +4 -3
  31. package/apps/shared/components/mail/invite/inviteStore.ts +17 -1
  32. package/apps/shared/components/mail/layout/MailShell.tsx +2 -0
  33. package/apps/shared/components/mail/pinnedSigners.ts +14 -0
  34. package/apps/shared/components/mail/reading/conversationPrint.ts +3 -3
  35. package/apps/shared/components/mail/reading/useMessageActions.ts +4 -1
  36. package/apps/shared/components/settings/KeyExportSetting.tsx +173 -0
  37. package/apps/shared/components/settings/OpenPgpKeySetting.tsx +240 -0
  38. package/apps/shared/components/settings/PolicyLockedNotice.tsx +23 -0
  39. package/apps/shared/components/settings/ZeroAccessSetting.tsx +128 -0
  40. package/apps/shared/components/settings/ZeroAccessTypes.tsx +175 -0
  41. package/apps/shared/components/settings/layout/SettingsShell.tsx +9 -2
  42. package/apps/shared/mail/decryptedMessages.ts +11 -3
  43. package/apps/shared/mail/outbox/sendJob.ts +349 -50
  44. package/apps/shared/mail/outbox/sendOutcomes.ts +91 -20
  45. package/apps/shared/mail/reportNotices.ts +3 -1
  46. package/apps/shared/mail/zeroAccessSource.ts +27 -0
  47. package/apps/shared/search/LocalIndexLifecycle.tsx +84 -24
  48. package/apps/shared/search/localIndexBuilder.ts +57 -20
  49. package/apps/shared/search/localIndexRpcClient.ts +96 -12
  50. package/apps/shared/search/localIndexSchema.ts +20 -4
  51. package/apps/shared/search/localIndexTransport.ts +6 -2
  52. package/apps/shared/search/localIndexWorker.ts +37 -18
  53. package/apps/shared/search/searchTier2.ts +5 -0
  54. package/apps/shared/search/zeroAccessIndexSync.ts +679 -0
  55. package/apps/shared/search/zeroAccessSyncState.ts +70 -0
  56. package/apps/shared/zeroAccess/ProtectedMark.tsx +19 -0
  57. package/apps/shared/zeroAccess/useKeysLocked.ts +25 -0
  58. package/apps/shared/zeroAccess/useOpenedRecord.ts +71 -0
  59. package/apps/www/_shell.tsx +2 -0
  60. package/apps/www/calendar/index.tsx +225 -61
  61. package/apps/www/contacts/index.tsx +67 -11
  62. package/apps/www/index.tsx +19 -3
  63. package/apps/www/settings/encryption/index.tsx +21 -1
  64. package/apps/www/settings/privacy/index.tsx +89 -39
  65. package/apps/www/tasks/index.tsx +24 -6
  66. package/dist/apps/escrow/matters/[uid].js +2 -2
  67. package/dist/apps/shared/calendar/calendarReminders.d.ts +14 -0
  68. package/dist/apps/shared/calendar/calendarReminders.js +26 -0
  69. package/dist/apps/shared/calendar/sealedEvents.d.ts +14 -0
  70. package/dist/apps/shared/calendar/sealedEvents.js +85 -0
  71. package/dist/apps/shared/calendar/useCalendarReminders.d.ts +2 -1
  72. package/dist/apps/shared/calendar/useCalendarReminders.js +27 -9
  73. package/dist/apps/shared/components/admin/settings/DomainDnsSetup.js +3 -0
  74. package/dist/apps/shared/components/admin/settings/EncryptionPolicyForm.js +25 -2
  75. package/dist/apps/shared/components/calendar/EventDetails.js +13 -2
  76. package/dist/apps/shared/components/calendar/EventEditor.js +115 -18
  77. package/dist/apps/shared/components/calendar/EventFormParts.js +1 -1
  78. package/dist/apps/shared/components/calendar/EventModal.d.ts +1 -1
  79. package/dist/apps/shared/components/calendar/EventModal.js +15 -2
  80. package/dist/apps/shared/components/calendar/RequestChangeForm.d.ts +3 -0
  81. package/dist/apps/shared/components/calendar/RequestChangeForm.js +1 -1
  82. package/dist/apps/shared/components/calendar/eventForm.d.ts +2 -0
  83. package/dist/apps/shared/components/contacts/ContactCard.js +12 -1
  84. package/dist/apps/shared/components/contacts/ContactDetailPane.d.ts +2 -1
  85. package/dist/apps/shared/components/contacts/ContactDetailPane.js +103 -9
  86. package/dist/apps/shared/components/contacts/ContactForm.d.ts +4 -1
  87. package/dist/apps/shared/components/contacts/ContactForm.js +37 -7
  88. package/dist/apps/shared/components/contacts/KeyChangeReview.d.ts +3 -1
  89. package/dist/apps/shared/components/contacts/KeyChangeReview.js +3 -2
  90. package/dist/apps/shared/components/contacts/contactCardData.js +8 -4
  91. package/dist/apps/shared/components/contacts/contactKeys.d.ts +1 -1
  92. package/dist/apps/shared/components/contacts/contactKeys.js +3 -3
  93. package/dist/apps/shared/components/layout/AppShell.d.ts +18 -1
  94. package/dist/apps/shared/components/layout/AppShell.js +17 -6
  95. package/dist/apps/shared/components/layout/KeyEnrollmentGate.js +27 -2
  96. package/dist/apps/shared/components/layout/SharedMailboxKeyManager.d.ts +17 -0
  97. package/dist/apps/shared/components/layout/SharedMailboxKeyManager.js +98 -0
  98. package/dist/apps/shared/components/layout/UnlockPromptProvider.d.ts +3 -0
  99. package/dist/apps/shared/components/layout/UnlockPromptProvider.js +32 -0
  100. package/dist/apps/shared/components/mail/ConversationList.js +1 -1
  101. package/dist/apps/shared/components/mail/InviteCard.js +11 -1
  102. package/dist/apps/shared/components/mail/MessageDetailPane.js +46 -21
  103. package/dist/apps/shared/components/mail/compose/ComposeWindow.js +2 -2
  104. package/dist/apps/shared/components/mail/compose/RecipientInput.js +3 -2
  105. package/dist/apps/shared/components/mail/compose/draftResume.d.ts +2 -0
  106. package/dist/apps/shared/components/mail/compose/draftResume.js +28 -3
  107. package/dist/apps/shared/components/mail/compose/protectedContactSuggestions.d.ts +14 -0
  108. package/dist/apps/shared/components/mail/compose/protectedContactSuggestions.js +96 -0
  109. package/dist/apps/shared/components/mail/compose/quotedBody.d.ts +1 -1
  110. package/dist/apps/shared/components/mail/compose/quotedBody.js +4 -3
  111. package/dist/apps/shared/components/mail/invite/inviteStore.js +16 -1
  112. package/dist/apps/shared/components/mail/layout/MailShell.js +2 -1
  113. package/dist/apps/shared/components/mail/pinnedSigners.d.ts +6 -0
  114. package/dist/apps/shared/components/mail/pinnedSigners.js +10 -1
  115. package/dist/apps/shared/components/mail/reading/conversationPrint.d.ts +2 -2
  116. package/dist/apps/shared/components/mail/reading/conversationPrint.js +3 -3
  117. package/dist/apps/shared/components/mail/reading/useMessageActions.js +4 -1
  118. package/dist/apps/shared/components/settings/KeyExportSetting.d.ts +13 -0
  119. package/dist/apps/shared/components/settings/KeyExportSetting.js +90 -0
  120. package/dist/apps/shared/components/settings/OpenPgpKeySetting.d.ts +13 -0
  121. package/dist/apps/shared/components/settings/OpenPgpKeySetting.js +143 -0
  122. package/dist/apps/shared/components/settings/PolicyLockedNotice.d.ts +11 -0
  123. package/dist/apps/shared/components/settings/PolicyLockedNotice.js +9 -0
  124. package/dist/apps/shared/components/settings/ZeroAccessSetting.d.ts +16 -0
  125. package/dist/apps/shared/components/settings/ZeroAccessSetting.js +80 -0
  126. package/dist/apps/shared/components/settings/ZeroAccessTypes.d.ts +29 -0
  127. package/dist/apps/shared/components/settings/ZeroAccessTypes.js +107 -0
  128. package/dist/apps/shared/components/settings/layout/SettingsShell.d.ts +3 -0
  129. package/dist/apps/shared/components/settings/layout/SettingsShell.js +3 -2
  130. package/dist/apps/shared/mail/decryptedMessages.d.ts +1 -1
  131. package/dist/apps/shared/mail/decryptedMessages.js +11 -3
  132. package/dist/apps/shared/mail/outbox/sendJob.d.ts +37 -4
  133. package/dist/apps/shared/mail/outbox/sendJob.js +287 -42
  134. package/dist/apps/shared/mail/outbox/sendOutcomes.d.ts +12 -0
  135. package/dist/apps/shared/mail/outbox/sendOutcomes.js +76 -20
  136. package/dist/apps/shared/mail/reportNotices.js +3 -1
  137. package/dist/apps/shared/mail/zeroAccessSource.d.ts +8 -0
  138. package/dist/apps/shared/mail/zeroAccessSource.js +26 -0
  139. package/dist/apps/shared/search/LocalIndexLifecycle.d.ts +2 -0
  140. package/dist/apps/shared/search/LocalIndexLifecycle.js +74 -24
  141. package/dist/apps/shared/search/localIndexBuilder.d.ts +9 -1
  142. package/dist/apps/shared/search/localIndexBuilder.js +50 -17
  143. package/dist/apps/shared/search/localIndexRpcClient.d.ts +5 -39
  144. package/dist/apps/shared/search/localIndexRpcClient.js +129 -11
  145. package/dist/apps/shared/search/localIndexSchema.d.ts +14 -2
  146. package/dist/apps/shared/search/localIndexSchema.js +18 -4
  147. package/dist/apps/shared/search/localIndexTransport.d.ts +6 -2
  148. package/dist/apps/shared/search/localIndexWorker.d.ts +11 -0
  149. package/dist/apps/shared/search/localIndexWorker.js +22 -15
  150. package/dist/apps/shared/search/searchTier2.js +5 -0
  151. package/dist/apps/shared/search/zeroAccessIndexSync.d.ts +102 -0
  152. package/dist/apps/shared/search/zeroAccessIndexSync.js +544 -0
  153. package/dist/apps/shared/search/zeroAccessSyncState.d.ts +20 -0
  154. package/dist/apps/shared/search/zeroAccessSyncState.js +65 -0
  155. package/dist/apps/shared/zeroAccess/ProtectedMark.d.ts +7 -0
  156. package/dist/apps/shared/zeroAccess/ProtectedMark.js +10 -0
  157. package/dist/apps/shared/zeroAccess/useKeysLocked.d.ts +6 -0
  158. package/dist/apps/shared/zeroAccess/useKeysLocked.js +20 -0
  159. package/dist/apps/shared/zeroAccess/useOpenedRecord.d.ts +18 -0
  160. package/dist/apps/shared/zeroAccess/useOpenedRecord.js +66 -0
  161. package/dist/apps/www/_shell.d.ts +1 -1
  162. package/dist/apps/www/_shell.js +2 -2
  163. package/dist/apps/www/calendar/index.js +88 -20
  164. package/dist/apps/www/contacts/index.js +64 -11
  165. package/dist/apps/www/index.js +19 -3
  166. package/dist/apps/www/settings/encryption/index.js +16 -4
  167. package/dist/apps/www/settings/privacy/index.js +47 -6
  168. package/dist/apps/www/tasks/index.js +21 -7
  169. package/dist/lib/admin/domainsApi.d.ts +1 -1
  170. package/dist/lib/admin/escrowAccessRequestsApi.d.ts +6 -0
  171. package/dist/lib/calendar/calendarApi.d.ts +52 -6
  172. package/dist/lib/calendar/calendarApi.js +110 -17
  173. package/dist/lib/calendar/calendarMutations.d.ts +20 -7
  174. package/dist/lib/calendar/calendarMutations.js +73 -14
  175. package/dist/lib/calendar/inviteApi.d.ts +17 -3
  176. package/dist/lib/calendar/inviteApi.js +86 -7
  177. package/dist/lib/calendar/protectedEvents.d.ts +31 -0
  178. package/dist/lib/calendar/protectedEvents.js +113 -0
  179. package/dist/lib/calendar/recurrence.d.ts +2 -0
  180. package/dist/lib/calendar/recurrence.js +16 -0
  181. package/dist/lib/calendar/sealedInvites.d.ts +9 -0
  182. package/dist/lib/calendar/sealedInvites.js +65 -0
  183. package/dist/lib/contacts/contactsApi.d.ts +29 -3
  184. package/dist/lib/contacts/contactsApi.js +23 -7
  185. package/dist/lib/contacts/useContactPhotoSrc.d.ts +5 -2
  186. package/dist/lib/contacts/useContactPhotoSrc.js +91 -11
  187. package/dist/lib/crypto/composeSecurity.d.ts +11 -3
  188. package/dist/lib/crypto/composeSecurity.js +13 -5
  189. package/dist/lib/crypto/keyExport.d.ts +54 -0
  190. package/dist/lib/crypto/keyExport.js +161 -0
  191. package/dist/lib/crypto/keyPairMatch.d.ts +9 -0
  192. package/dist/lib/crypto/keyPairMatch.js +65 -0
  193. package/dist/lib/crypto/keySession.d.ts +64 -3
  194. package/dist/lib/crypto/keySession.js +179 -12
  195. package/dist/lib/crypto/keyvaultApi.d.ts +129 -8
  196. package/dist/lib/crypto/keyvaultApi.js +45 -3
  197. package/dist/lib/crypto/meetingKeys.d.ts +25 -0
  198. package/dist/lib/crypto/meetingKeys.js +87 -0
  199. package/dist/lib/crypto/messageSecurity.d.ts +56 -3
  200. package/dist/lib/crypto/messageSecurity.js +201 -13
  201. package/dist/lib/crypto/mime.d.ts +5 -0
  202. package/dist/lib/crypto/mime.js +25 -0
  203. package/dist/lib/crypto/openPgpKey.d.ts +39 -0
  204. package/dist/lib/crypto/openPgpKey.js +89 -0
  205. package/dist/lib/crypto/openpgp.d.ts +47 -0
  206. package/dist/lib/crypto/openpgp.js +88 -0
  207. package/dist/lib/crypto/pgpMessage.d.ts +51 -0
  208. package/dist/lib/crypto/pgpMessage.js +271 -0
  209. package/dist/lib/crypto/sharedMailboxKeys.d.ts +62 -0
  210. package/dist/lib/crypto/sharedMailboxKeys.js +337 -0
  211. package/dist/lib/crypto/smimeMessage.d.ts +21 -0
  212. package/dist/lib/crypto/smimeMessage.js +11 -7
  213. package/dist/lib/crypto/zeroAccessKey.d.ts +32 -0
  214. package/dist/lib/crypto/zeroAccessKey.js +71 -0
  215. package/dist/lib/mail/conversationsApi.d.ts +6 -0
  216. package/dist/lib/mail/mailApi.d.ts +63 -2
  217. package/dist/lib/mail/mailApi.js +5 -1
  218. package/dist/lib/mail/mailboxImportApi.d.ts +10 -0
  219. package/dist/lib/mail/mailboxImportApi.js +15 -0
  220. package/dist/lib/search/zeroAccessIndexApi.d.ts +85 -0
  221. package/dist/lib/search/zeroAccessIndexApi.js +35 -0
  222. package/dist/lib/tasks/tasksApi.d.ts +11 -1
  223. package/dist/lib/tasks/tasksApi.js +10 -4
  224. package/dist/lib/util/clientPlatform.d.ts +14 -0
  225. package/dist/lib/util/clientPlatform.js +26 -0
  226. package/dist/lib/videoconf/protectedMeetings.d.ts +74 -0
  227. package/dist/lib/videoconf/protectedMeetings.js +181 -0
  228. package/dist/lib/videoconf/videoMeetingsApi.d.ts +25 -4
  229. package/dist/lib/videoconf/videoMeetingsApi.js +1 -1
  230. package/dist/lib/zeroAccess/sealedMoves.d.ts +41 -0
  231. package/dist/lib/zeroAccess/sealedMoves.js +63 -0
  232. package/dist/lib/zeroAccess/sealedRecords.d.ts +29 -0
  233. package/dist/lib/zeroAccess/sealedRecords.js +136 -0
  234. package/lib/admin/domainsApi.ts +1 -1
  235. package/lib/admin/escrowAccessRequestsApi.ts +6 -0
  236. package/lib/calendar/calendarApi.ts +143 -17
  237. package/lib/calendar/calendarMutations.ts +79 -12
  238. package/lib/calendar/inviteApi.ts +101 -8
  239. package/lib/calendar/protectedEvents.ts +143 -0
  240. package/lib/calendar/recurrence.ts +17 -0
  241. package/lib/calendar/sealedInvites.ts +73 -0
  242. package/lib/contacts/contactsApi.ts +43 -17
  243. package/lib/contacts/useContactPhotoSrc.ts +103 -13
  244. package/lib/crypto/composeSecurity.ts +20 -5
  245. package/lib/crypto/keyExport.ts +229 -0
  246. package/lib/crypto/keyPairMatch.ts +69 -0
  247. package/lib/crypto/keySession.ts +216 -12
  248. package/lib/crypto/keyvaultApi.ts +174 -10
  249. package/lib/crypto/meetingKeys.ts +118 -0
  250. package/lib/crypto/messageSecurity.ts +284 -16
  251. package/lib/crypto/mime.ts +26 -0
  252. package/lib/crypto/openPgpKey.ts +118 -0
  253. package/lib/crypto/openpgp.ts +115 -0
  254. package/lib/crypto/pgpMessage.ts +336 -0
  255. package/lib/crypto/sharedMailboxKeys.ts +402 -0
  256. package/lib/crypto/smimeMessage.ts +11 -7
  257. package/lib/crypto/zeroAccessKey.ts +102 -0
  258. package/lib/mail/conversationsApi.ts +3 -0
  259. package/lib/mail/mailApi.ts +60 -3
  260. package/lib/mail/mailboxImportApi.ts +24 -0
  261. package/lib/search/zeroAccessIndexApi.ts +123 -0
  262. package/lib/tasks/tasksApi.ts +19 -5
  263. package/lib/util/clientPlatform.ts +50 -0
  264. package/lib/videoconf/protectedMeetings.ts +221 -0
  265. package/lib/videoconf/videoMeetingsApi.ts +15 -4
  266. package/lib/zeroAccess/sealedMoves.ts +79 -0
  267. package/lib/zeroAccess/sealedRecords.ts +153 -0
  268. package/package.json +14 -5
@@ -2,7 +2,7 @@
2
2
  // Copyright (C) 2026 Jean-Philippe Steinmetz
3
3
  // SPDX-License-Identifier: MPL-2.0
4
4
  ///////////////////////////////////////////////////////////////////////////////
5
- import { Message, cancelScheduledSend, getMessage, listAttachments, listFolders, queueMessageSend } from "../../../../lib/mail/mailApi.js";
5
+ import { Message, cancelScheduledSend, deleteMessage, getMessage, listAttachments, listFolders, queueMessageSend } from "../../../../lib/mail/mailApi.js";
6
6
  import { SendEvent, describeSendEventError } from "../../../../lib/mail/sendEvents.js";
7
7
  import type { ApiClient } from "../../../../lib/util/api.js";
8
8
  import { formatRecipient } from "../../components/mail/compose/recipients.js";
@@ -12,7 +12,18 @@ import { dismiss, notify } from "../../notifications/store.js";
12
12
  import { beginPendingSend, finishPendingSend, setPendingStage } from "./pendingSends.js";
13
13
  import { failOutgoing, forgetOutgoing, markOutgoingSending, markOutgoingSent } from "./outgoingReplies.js";
14
14
  import { openComposeFromOutside } from "./composeBridge.js";
15
- import { describeMessage, forgetRetainedRequest, notifySent, openDraftFromRequest, retainedRequest } from "./sendJob.js";
15
+ import {
16
+ SendRequest,
17
+ copyFailed,
18
+ copyRetried,
19
+ describeMessage,
20
+ forgetCopies,
21
+ forgetRetainedRequest,
22
+ notifySent,
23
+ openDraftFromRequest,
24
+ retainedRequest,
25
+ unsentCopies,
26
+ } from "./sendJob.js";
16
27
 
17
28
  /**
18
29
  * What the user is told when the server reports how a queued message went (`send-succeeded`, `send-failed`, `send-retrying` push events,
@@ -43,14 +54,42 @@ function escapeHtml(text: string): string {
43
54
  return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
44
55
  }
45
56
 
46
- /** "Open draft" for a message the server failed to relay: back into Drafts, and into a compose window with what was written. */
47
- async function openFailedDraft(event: SendEvent, client: ApiClient | undefined): Promise<void> {
57
+ /** The message a failure is about: as the server reports it (a `SendEvent`), or as this tab sent it. */
58
+ export type FailedSend = Pick<SendEvent, "uid" | "mailboxUid" | "subject" | "recipients">;
59
+
60
+ /** "Open draft" for a message the server failed to relay: back into Drafts, and into a compose window with what was written. `request`: the
61
+ * one it was queued from, when this tab holds it. */
62
+ async function openFailedDraft(event: FailedSend, client: ApiClient | undefined, request: SendRequest | undefined): Promise<void> {
63
+ // A message sent as several copies (one per encryption format) is written again only when none of them went: while another copy has
64
+ // gone or may still go, the whole message sent again would reach its recipients a second time - however the action came to be offered.
65
+ const copies = unsentCopies(request);
66
+ if (request?.copyFates && !copies) {
67
+ notify({
68
+ id: `open-draft:${event.uid}`,
69
+ kind: "info",
70
+ title: "Only this copy didn't go",
71
+ message: "The copy for its other recipients is sent on its own. Use Retry to send this one to its own recipients.",
72
+ timeoutMs: 8_000,
73
+ });
74
+ return;
75
+ }
48
76
  try {
49
- const moved = await moveBackToDrafts(event.uid, event.mailboxUid ?? "", client);
77
+ // Of a message sent as several copies, its own draft is the one written again.
78
+ const moved = await moveBackToDrafts(copies ? request!.draft.uid : event.uid, event.mailboxUid ?? "", client);
50
79
  // Back in Drafts it is no longer a message on its way in its conversation.
51
80
  forgetOutgoing(event.uid);
52
- const request = retainedRequest(event.uid);
53
81
  if (request) {
82
+ // The other copies (the OpenPGP one's own draft) go: the message is encrypted afresh when it is sent again, and none of them may
83
+ // be retried meanwhile.
84
+ for (const uid of copies?.filter((uid) => uid !== request.draft.uid) ?? []) {
85
+ const extra = await moveBackToDrafts(uid, event.mailboxUid ?? "", client);
86
+ await deleteMessage(extra.uid, extra.version, client);
87
+ dismiss(failedId(uid));
88
+ forgetOutgoing(uid);
89
+ }
90
+ if (request.copyFates) {
91
+ forgetCopies(request.copyFates);
92
+ }
54
93
  openDraftFromRequest({ ...request, draft: moved });
55
94
  return;
56
95
  }
@@ -88,20 +127,24 @@ async function openFailedDraft(event: SendEvent, client: ApiClient | undefined):
88
127
  }
89
128
  }
90
129
 
91
- /** "Retry" for a message the server failed to relay: the same send call again - a failed message stays in Outbox and the server queues it afresh (with a new retry budget). */
92
- async function retryFailed(event: SendEvent, client: ApiClient | undefined): Promise<void> {
130
+ /** "Retry" for a message the server failed to relay: the same send call again - a failed message stays in Outbox and the server queues it afresh (with a new retry budget).
131
+ * `request`: the one it was queued from, when this tab holds it - a copy of a message sent as several is then awaited again. */
132
+ async function retryFailed(event: FailedSend, client: ApiClient | undefined, request: SendRequest | undefined): Promise<void> {
93
133
  if (!beginPendingSend({ draftUid: event.uid, mailboxUid: event.mailboxUid ?? "", subject: event.subject, recipients: event.recipients, scheduled: false })) {
94
134
  return;
95
135
  }
96
136
  dismiss(failedId(event.uid));
97
137
  markOutgoingSending(event.uid);
138
+ copyRetried(request, event.uid);
98
139
  try {
99
140
  setPendingStage(event.uid, "queuing");
100
141
  const result = await queueMessageSend(event.uid, client);
101
- if (!result.queued) {
142
+ // Relayed before the server answered - and so, when it is one copy of several, maybe the last of them.
143
+ if (!result.queued && forgetRetainedRequest(event.uid)) {
102
144
  notifySent();
103
145
  }
104
146
  } catch (err) {
147
+ copyFailed(request, event.uid);
105
148
  notifyApiError(err, "This message wasn't sent", { dedupeKey: failedId(event.uid) });
106
149
  } finally {
107
150
  finishPendingSend(event.uid);
@@ -114,26 +157,29 @@ async function retryFailed(event: SendEvent, client: ApiClient | undefined): Pro
114
157
  export function handleSendEvent(event: SendEvent, client?: ApiClient): void {
115
158
  if (event.action === "send-succeeded") {
116
159
  dismiss(retryId(event.uid));
117
- dismiss(failedId(event.uid));
160
+ // A partly-sent message's failure (`notifyFailure()`) is shown under its first copy's uid but is of a copy that was never handed over:
161
+ // it stays, with the Retry that hands that copy over.
162
+ if (![...(retainedRequest(event.uid)?.copyFates?.values() ?? [])].includes("unsent")) {
163
+ dismiss(failedId(event.uid));
164
+ }
118
165
  // The conversation on screen swaps the message it drew for the Sent Items copy (a message this tab did not send has nothing drawn).
119
166
  markOutgoingSent(event.uid);
120
167
  // The server reports every message it relays, scheduled ones from long ago included: only a message this tab queued in the background is
121
168
  // worth a confirmation (several are one pop-up counting up). Anything else - a send-later message going out, another tab's send - is quiet.
122
- if (retainedRequest(event.uid)) {
123
- forgetRetainedRequest(event.uid);
169
+ // A message sent as several copies (one per encryption format) is confirmed once, when the last of them has gone.
170
+ if (retainedRequest(event.uid) && forgetRetainedRequest(event.uid)) {
124
171
  notifySent();
125
172
  }
126
173
  return;
127
174
  }
128
175
  const failure = describeSendEventError(event.error, event.action === "send-failed" ? "The server couldn't send this message." : "The server couldn't send this message yet.");
129
- const what = describeMessage(event.subject, summary(event.recipients));
130
176
  if (event.action === "send-retrying") {
131
177
  const next = event.nextAttemptAt ? Date.parse(event.nextAttemptAt) : NaN;
132
178
  notify({
133
179
  id: retryId(event.uid),
134
180
  kind: "info",
135
181
  title: "Retrying to send",
136
- message: `${what} (attempt ${event.attempt + 1}${Number.isNaN(next) ? "" : `, at ${new Date(next).toLocaleTimeString()}`}). ${failure.message}`,
182
+ message: `${describeMessage(event.subject, summary(event.recipients))} (attempt ${event.attempt + 1}${Number.isNaN(next) ? "" : `, at ${new Date(next).toLocaleTimeString()}`}). ${failure.message}`,
137
183
  details: failure.lines,
138
184
  sticky: false,
139
185
  timeoutMs: 8_000,
@@ -141,18 +187,43 @@ export function handleSendEvent(event: SendEvent, client?: ApiClient): void {
141
187
  return;
142
188
  }
143
189
  dismiss(retryId(event.uid));
144
- const actions = [
145
- { label: "Retry", onClick: () => void retryFailed(event, client) },
146
- { label: "Open draft", onClick: () => void openFailedDraft(event, client) },
147
- ];
190
+ const request = retainedRequest(event.uid);
191
+ copyFailed(request, event.uid);
192
+ notifySendFailure(event, failure, request, client);
193
+ }
194
+
195
+ /**
196
+ * The sticky "This message wasn't sent" for a message that failed, `failure` saying why, with what can be done about it - for one the server
197
+ * failed to relay, and for a message sent as several copies (`SendRequest.copyUids`) of which this tab couldn't hand over the rest after the
198
+ * server had failed one (`sendJob.ts`'s `notifyFailure()`). `request`: the one it was queued from, when this tab holds it.
199
+ */
200
+ export function notifySendFailure(event: FailedSend, failure: { message: string; lines: string[] }, request: SendRequest | undefined, client: ApiClient | undefined): void {
201
+ // Every copy of a message sent as several (one per encryption format, `SendRequest.copyUids`) failed or never went: nobody has it, and it
202
+ // is the whole message's failure - one pop-up, whose Retry hands each copy over again and whose "Open draft" writes the message again.
203
+ const copies = unsentCopies(request);
204
+ // One copy of several, while another has gone or may still go: the others' recipients have theirs or will, and "Open draft" would send
205
+ // the whole message to them again - Retry sends just this copy, to just its own recipients.
206
+ const oneCopy = !!request?.copyFates && !copies;
207
+ const retry = () => {
208
+ for (const uid of copies ?? [event.uid]) {
209
+ void retryFailed({ ...event, uid }, client, request);
210
+ }
211
+ };
212
+ const actions = [{ label: "Retry", onClick: retry }, ...(oneCopy ? [] : [{ label: "Open draft", onClick: () => void openFailedDraft(event, client, request) }])];
213
+ const message: string = oneCopy ? `The copy for some of its recipients didn't go - the others' copy is sent on its own. ${failure.message}` : failure.message;
214
+ // What an earlier copy's failure said of the others is no longer so: this pop-up stands for the whole message.
215
+ for (const uid of copies?.filter((uid) => uid !== event.uid) ?? []) {
216
+ dismiss(failedId(uid));
217
+ failOutgoing(uid, message, actions);
218
+ }
148
219
  notify({
149
220
  id: failedId(event.uid),
150
221
  kind: "error",
151
222
  title: "This message wasn't sent",
152
- message: `${what}: ${failure.message}`,
223
+ message: `${describeMessage(event.subject, summary(event.recipients))}: ${message}`,
153
224
  details: failure.lines,
154
225
  actions,
155
226
  });
156
227
  // The conversation on screen shows the same failure under the message, with the same ways out.
157
- failOutgoing(event.uid, failure.message, actions);
228
+ failOutgoing(event.uid, message, actions);
158
229
  }
@@ -61,6 +61,8 @@ export function reportNotice(result: MessageReportResult, subject: string, alway
61
61
  ? "The spam filter could not be trained from this report."
62
62
  : result.learnSkipped === "encrypted"
63
63
  ? "Not used to train the spam filter: the message is encrypted."
64
- : undefined;
64
+ : result.learnSkipped === "zero_access"
65
+ ? "Not used to train the spam filter: unlock your mailbox to let it learn from protected mail."
66
+ : undefined;
65
67
  return { title: kind.title, message: parts.join(" "), hint };
66
68
  }
@@ -0,0 +1,27 @@
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, type Message } from "../../../lib/mail/mailApi.js";
8
+ import type { ApiClient } from "../../../lib/util/api.js";
9
+
10
+ /**
11
+ * The original source of a zero-access `message`, decrypted with its mailbox's unlocked keys and base64-encoded - what the server, which holds
12
+ * only the sealed copy, needs for an action that reads the message itself (`reportMessage()`'s `rawMessage`). `undefined` for any other
13
+ * message, while the mailbox is locked, or when it can't be fetched or opened: the action then goes ahead without it.
14
+ */
15
+ export async function zeroAccessSourceBase64(message: Pick<Message, "uid" | "mailboxUid" | "zeroAccess">, client?: ApiClient): Promise<string | undefined> {
16
+ const unlocked = message.zeroAccess ? getUnlockedKeys(message.mailboxUid) : undefined;
17
+ if (!unlocked) {
18
+ return undefined;
19
+ }
20
+ try {
21
+ const original = await openZeroAccessMessage(await getMessageRawContent(message.uid, client), unlocked);
22
+ // A binary string (one char per byte), which `btoa()` encodes as the bytes themselves.
23
+ return original === undefined ? undefined : btoa(original);
24
+ } catch {
25
+ return undefined;
26
+ }
27
+ }
@@ -8,20 +8,23 @@
8
8
  * "MUST be destroyed on the same events that destroy private keys: explicit logout, session revocation,
9
9
  * and the configurable idle timeout").
10
10
  *
11
- * **Why polling, not hooking the existing destroy call sites directly**: `destroyUnlockedKeys()`
12
- * (`react-shared/src/crypto/keySession.ts`) has no observer/callback hook. Watching `getUnlockedKeys()`
13
- * for a present-to-absent transition catches *every* destroy path uniformly - idle timeout, the manual
14
- * button, or anything else that calls it - without needing to know which one fired.
11
+ * **Locks**: `localIndexRpcClient.ts` itself destroys an index it opened the moment `subscribeKeySession()` reports its mailbox locked,
12
+ * whatever destroyed the keys (idle timeout, the manual button, a sign-out) and whether or not this component is still mounted. This
13
+ * component subscribes to the same `locked` event to reset what it remembers of the mailbox (built, synced) at that moment, so a re-unlock
14
+ * builds again - even one made before the next poll tick, which a poll alone would never see as a lock, leaving the destroyed index
15
+ * unbuilt and every zero-access sync failing against it. Keys only ever go away through `destroyUnlockedKeys()`, which always reports
16
+ * the lock, so the poll doesn't watch for a lock itself. A lock while a build is still deriving its index key, before anything is open
17
+ * for the index client to destroy, is the builder's own to catch (`localIndexBuilder.ts`): it opens nothing with destroyed keys.
15
18
  *
16
19
  * Every mailbox this component has seen unlocked is tracked for the life of the mount - not just whichever
17
20
  * is active right now - so switching mailboxes (or a folders-list refresh re-running the build effect)
18
21
  * can never lose a pending unlocked-to-locked transition for a mailbox whose index was already built.
19
22
  *
20
- * **Explicit logout** navigates away immediately, which may not leave time for a poll tick - `AppShell.tsx`
23
+ * **Explicit logout** navigates away immediately, which may not leave time for the lock's asynchronous destroy - `AppShell.tsx`
21
24
  * handles that case itself via `destroyAllLocalIndexes()`.
22
25
  */
23
26
  import { useEffect, useRef } from "react";
24
- import { getUnlockedKeys } from "../../../lib/crypto/keySession.js";
27
+ import { getUnlockedKeys, subscribeKeySession } from "../../../lib/crypto/keySession.js";
25
28
  import type { PublicKey } from "../../../lib/crypto/keyvaultApi.js";
26
29
  import type { Folder } from "../../../lib/mail/mailApi.js";
27
30
  import type { ApiClient } from "../../../lib/util/api.js";
@@ -39,10 +42,20 @@ const loadBuilder = () =>
39
42
  builder = undefined;
40
43
  throw err;
41
44
  }));
42
- import { destroyLocalIndex, pruneInaccessibleLocalIndexes } from "./localIndexRpcClient.js";
45
+ /** The zero-access index sync (`zeroAccessIndexSync.ts`), loaded the same way: only once a zero-access mailbox is unlocked. */
46
+ let syncer: Promise<typeof import("./zeroAccessIndexSync.js")> | undefined;
47
+ const loadSyncer = () =>
48
+ (syncer ??= import("./zeroAccessIndexSync.js").catch((err) => {
49
+ syncer = undefined;
50
+ throw err;
51
+ }));
52
+ import { pruneInaccessibleLocalIndexes } from "./localIndexRpcClient.js";
43
53
 
44
54
  export const POLL_INTERVAL_MS = 5_000;
45
55
 
56
+ /** How often an unlocked zero-access mailbox's local index is brought up to date with the server's sealed index. */
57
+ export const ZERO_ACCESS_SYNC_INTERVAL_MS = 120_000;
58
+
46
59
  export interface LocalIndexLifecycleProps {
47
60
  mailboxUid?: string;
48
61
  mailboxKeys?: PublicKey[];
@@ -58,13 +71,44 @@ export default function LocalIndexLifecycle({ mailboxUid, folders, accessibleMai
58
71
  // apps, Electron), which keeps building the index against the default global cookie-based session exactly as before. A native,
59
72
  // multi-account host that renders this under an ApiClientContext.Provider gets its own account's client threaded through instead.
60
73
  const client = useApiClient();
61
- // mailboxUid -> whether it was unlocked at the last check. An entry exists for every mailbox whose
62
- // build this component started; only ever changed by a real observed transition, never reset by an
63
- // effect re-run.
74
+ // mailboxUid -> whether it is unlocked as far as this component knows: set when its build starts, cleared by its lock. An entry exists
75
+ // for every mailbox whose build this component started; never reset by an effect re-run.
64
76
  const trackedRef = useRef(new Map<string, boolean>());
65
77
  // The latest props (and client), for the long-lived polling interval below.
66
78
  const latestRef = useRef({ mailboxUid, folders, client });
67
79
  latestRef.current = { mailboxUid, folders, client };
80
+ // mailboxUid -> when its last zero-access sync started. A mailbox syncs only once its build of this unlock settled (`builtRef` - the
81
+ // sync writes into the index the build opened), first at once and then every interval; a mailbox in `syncingRef` has a pass running,
82
+ // and never gets a second one alongside it. A lock forgets all three, so a pass still winding down never holds up the next unlock's.
83
+ const lastSyncRef = useRef(new Map<string, number>());
84
+ const builtRef = useRef(new Set<string>());
85
+ // mailboxUid -> its latest build, so only that one's end starts the sync (not one a lock overtook).
86
+ const buildsRef = useRef(new Map<string, symbol>());
87
+ const syncingRef = useRef(new Map<string, symbol>());
88
+
89
+ function syncIfDue(targetMailboxUid: string, targetClient: ApiClient | undefined) {
90
+ const unlocked = getUnlockedKeys(targetMailboxUid);
91
+ const last = lastSyncRef.current.get(targetMailboxUid);
92
+ if (
93
+ !unlocked?.zeroAccessKeys?.length ||
94
+ !builtRef.current.has(targetMailboxUid) ||
95
+ syncingRef.current.has(targetMailboxUid) ||
96
+ (last !== undefined && Date.now() - last < ZERO_ACCESS_SYNC_INTERVAL_MS)
97
+ ) {
98
+ return;
99
+ }
100
+ lastSyncRef.current.set(targetMailboxUid, Date.now());
101
+ const pass = Symbol(targetMailboxUid);
102
+ syncingRef.current.set(targetMailboxUid, pass);
103
+ loadSyncer()
104
+ .then(({ syncZeroAccessIndex }) => syncZeroAccessIndex(targetMailboxUid, unlocked, targetClient))
105
+ .catch(() => undefined)
106
+ .finally(() => {
107
+ if (syncingRef.current.get(targetMailboxUid) === pass) {
108
+ syncingRef.current.delete(targetMailboxUid);
109
+ }
110
+ });
111
+ }
68
112
 
69
113
  function startBuildIfUnlocked(targetMailboxUid: string, targetFolders: Folder[], targetClient: ApiClient | undefined) {
70
114
  const unlocked = getUnlockedKeys(targetMailboxUid);
@@ -72,11 +116,21 @@ export default function LocalIndexLifecycle({ mailboxUid, folders, accessibleMai
72
116
  return;
73
117
  }
74
118
  trackedRef.current.set(targetMailboxUid, true);
119
+ const build = Symbol(targetMailboxUid);
120
+ buildsRef.current.set(targetMailboxUid, build);
75
121
  // Never an unhandled rejection - a broken local index is best-effort infrastructure, not a build
76
122
  // the rest of the app depends on.
77
- loadBuilder()
123
+ // The sync runs however the build ended: zero-access mail reaches the index only through it, and a build that failed part-way
124
+ // isn't tried again until the next unlock. (Locked meanwhile, there are no keys to sync with.)
125
+ void loadBuilder()
78
126
  .then(({ buildLocalIndex }) => buildLocalIndex(targetMailboxUid, unlocked, targetFolders, undefined, targetClient))
79
- .catch(() => undefined);
127
+ .catch(() => undefined)
128
+ .then(() => {
129
+ if (buildsRef.current.get(targetMailboxUid) === build && trackedRef.current.get(targetMailboxUid)) {
130
+ builtRef.current.add(targetMailboxUid);
131
+ syncIfDue(targetMailboxUid, targetClient);
132
+ }
133
+ });
80
134
  }
81
135
 
82
136
  useEffect(() => {
@@ -85,24 +139,30 @@ export default function LocalIndexLifecycle({ mailboxUid, folders, accessibleMai
85
139
  }
86
140
  }, [mailboxUid, folders, client]);
87
141
 
142
+ // A lock forgets the mailbox at once: no build of this unlock counts as built any more (the cancelled build's end finds `buildsRef`
143
+ // cleared and starts no sync), and the next unlock's tick starts a new build. The cancel and destroy themselves are
144
+ // `localIndexRpcClient.ts`'s, which reacts to the same event.
145
+ useEffect(
146
+ () =>
147
+ subscribeKeySession(({ mailboxUid: lockedUid, state }) => {
148
+ if (state === "locked" && trackedRef.current.get(lockedUid)) {
149
+ trackedRef.current.set(lockedUid, false);
150
+ lastSyncRef.current.delete(lockedUid);
151
+ builtRef.current.delete(lockedUid);
152
+ syncingRef.current.delete(lockedUid);
153
+ buildsRef.current.delete(lockedUid);
154
+ }
155
+ }),
156
+ [],
157
+ );
158
+
88
159
  useEffect(() => {
89
160
  const interval = setInterval(() => {
90
- for (const [trackedUid, wasUnlocked] of trackedRef.current) {
91
- if (wasUnlocked && !getUnlockedKeys(trackedUid)) {
92
- // A present-to-absent transition: something just destroyed this mailbox's keys.
93
- trackedRef.current.set(trackedUid, false);
94
- // Stop the pass still running with the now-destroyed keys; the destroy itself also makes
95
- // the Worker reject anything that pass still sends.
96
- loadBuilder()
97
- .then(({ cancelLocalIndexBuild }) => cancelLocalIndexBuild(trackedUid))
98
- .catch(() => undefined);
99
- void destroyLocalIndex(trackedUid);
100
- }
101
- }
102
161
  // The active mailbox was (re-)unlocked since the last check, e.g. via an on-demand unlock prompt.
103
162
  const { mailboxUid: activeUid, folders: activeFolders, client: activeClient } = latestRef.current;
104
163
  if (activeUid) {
105
164
  startBuildIfUnlocked(activeUid, activeFolders, activeClient);
165
+ syncIfDue(activeUid, activeClient);
106
166
  }
107
167
  }, POLL_INTERVAL_MS);
108
168
  return () => clearInterval(interval);
@@ -19,11 +19,16 @@
19
19
  * cross-folder interleaving imprecision here does not affect *what* ultimately survives the window, only
20
20
  * the exact order entities are inserted (and therefore briefly evicted-and-reinserted) in.
21
21
  *
22
- * Only encrypted messages (`subject === "[...]"`) are indexed - see `ENCRYPTED_SUBJECT_PLACEHOLDER`'s
22
+ * Only encrypted messages (`subject === "[...]"`, or flagged `encrypted` by the server - OpenPGP mail keeps its real outer subject) are indexed - see `ENCRYPTED_SUBJECT_PLACEHOLDER`'s
23
23
  * own precedent in `apps/www/index.tsx`'s inbox-list decrypt work. An unencrypted message is already
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
@@ -36,14 +41,16 @@
36
41
  * above), and fetching it only to seal would cost a download per message; they are sealed when opened.
37
42
  */
38
43
  import { getMessageRawContent, listFolders, listMessages, type Folder, type Message } from "../../../lib/mail/mailApi.js";
39
- import { type MessageSecurityResult, evaluateMessageSecurity, evaluateMessageSecurityWithSeal } from "../../../lib/crypto/messageSecurity.js";
44
+ import { type MessageSecurityResult, type SignerPinsInput, evaluateMessageSecurity, evaluateMessageSecurityWithSeal } from "../../../lib/crypto/messageSecurity.js";
40
45
  import type { UnlockedKeys } from "../../../lib/crypto/keySession.js";
46
+ import { KeysLockedError } from "../../../lib/crypto/masterKey.js";
41
47
  import type { ApiClient } from "../../../lib/util/api.js";
42
- import { getPinnedSignerFingerprints } from "../components/mail/pinnedSigners.js";
48
+ import { getPinnedSigners } from "../components/mail/pinnedSigners.js";
43
49
  import { currentVerificationSeal, readVaultGeneration, sendVerificationSeal, verificationSealPending } from "../components/mail/verificationSeals.js";
44
- import type { LocalIndexEntity } from "./localIndexSchema.js";
50
+ import { type LocalIndexEntity, messageRowFlags, messageRowVersion } from "./localIndexSchema.js";
45
51
  import {
46
52
  getIndexedVersions,
53
+ moveLocalEntity,
47
54
  indexLocalEntities,
48
55
  initLocalIndex,
49
56
  nextLocalIndexGeneration,
@@ -53,6 +60,7 @@ import {
53
60
  } from "./localIndexRpcClient.js";
54
61
  import { deriveLocalIndexKey } from "./localIndexKey.js";
55
62
  import { getLocalIndexByteBudget } from "./localIndexSizePreference.js";
63
+ import { importClientSegments, rememberZeroAccessMetadata, uploadClientDocuments } from "./zeroAccessIndexSync.js";
56
64
 
57
65
  /** The RFC 9788 placeholder subject every encrypted message's outer envelope carries server-side - see
58
66
  * `apps/www/index.tsx`'s identical constant and its own doc comment for the full citation. */
@@ -91,6 +99,9 @@ export const MAX_WALK_ATTEMPTS = 3;
91
99
  export const CLOCK_SKEW_MARGIN_MS = 10 * 60 * 1000;
92
100
 
93
101
  const PAGE_SIZE = 100;
102
+ /** Decrypted end-to-end messages are uploaded for the mailbox's other devices (`uploadClientDocuments()`) whenever this many are waiting,
103
+ * not all at the end of the pass: a pass cut short keeps what it shared, and the plaintext isn't all held in memory at once. */
104
+ export const CLIENT_UPLOAD_BATCH = 500;
94
105
  const MAX_APPROX_BYTES_PER_MESSAGE_PADDING = 512; // subject/participants/flags overhead beyond raw text length
95
106
  const FETCH_FAILED = Symbol("fetch-failed");
96
107
 
@@ -114,7 +125,7 @@ interface PassSealer {
114
125
 
115
126
  function createPassSealer(mailboxUid: string, unlocked: UnlockedKeys, signal: AbortSignal, client: ApiClient | undefined): PassSealer {
116
127
  let generation: Promise<number | undefined> | undefined;
117
- const pins = new Map<string, Promise<string[] | undefined>>();
128
+ const pins = new Map<string, Promise<SignerPinsInput>>();
118
129
  const queue: (() => Promise<unknown>)[] = [];
119
130
  let queued = 0;
120
131
  let active = 0;
@@ -127,8 +138,9 @@ function createPassSealer(mailboxUid: string, unlocked: UnlockedKeys, signal: Ab
127
138
  const key = address.toLowerCase();
128
139
  let entry = pins.get(key);
129
140
  if (!entry) {
130
- entry = getPinnedSignerFingerprints(mailboxUid, address, client).then(
131
- (fingerprints) => (fingerprints.length > 0 ? fingerprints : undefined),
141
+ entry = getPinnedSigners(mailboxUid, address, client).then(
142
+ (signers): SignerPinsInput =>
143
+ signers.openPgpKeys.length > 0 ? signers : signers.fingerprints.length > 0 ? signers.fingerprints : undefined,
132
144
  () => undefined,
133
145
  );
134
146
  pins.set(key, entry);
@@ -203,11 +215,8 @@ function estimateByteSize(entity: Pick<LocalIndexEntity, "subject" | "body" | "a
203
215
  return textBytes + MAX_APPROX_BYTES_PER_MESSAGE_PADDING;
204
216
  }
205
217
 
206
- /** The change marker stored per row: a new server `version` (flags, content) or a folder move both
207
- * invalidate the indexed copy. */
208
- function versionOf(message: Message): string {
209
- return `${message.version}:${message.folderUid}`;
210
- }
218
+ const versionOf = (message: Message): string => messageRowVersion(message);
219
+ const entityFlags = (message: Message): string => messageRowFlags(message);
211
220
 
212
221
  /** `Promise.all(items.map(fn))`, but with at most `limit` calls in flight. Preserves input order. */
213
222
  async function mapWithConcurrency<T, R>(items: T[], limit: number, fn: (item: T) => Promise<R>): Promise<R[]> {
@@ -247,12 +256,7 @@ async function buildEntity(message: Message, sealer: PassSealer): Promise<LocalI
247
256
  const participants = [message.from.address, message.from.displayName, ...message.recipients.map((r) => r.address)]
248
257
  .filter(Boolean)
249
258
  .join(" ");
250
- const setFlags = Object.entries(message.flags)
251
- .filter(([, value]) => value)
252
- .map(([key]) => key);
253
- // Leading/trailing comma so `flags LIKE '%,x,%'` (localIndexSchema.ts's buildSearchPredicates())
254
- // matches correctly even for the first/last flag in the list.
255
- const flags = `,${setFlags.join(",")},`;
259
+ const flags = entityFlags(message);
256
260
  const entity: LocalIndexEntity = {
257
261
  entityType: "message",
258
262
  entityUid: message.uid,
@@ -366,9 +370,17 @@ async function runBuildPass(
366
370
  const generation = nextLocalIndexGeneration();
367
371
  const indexKey = await deriveLocalIndexKey(unlocked.masterKey, mailboxUid);
368
372
  signal.throwIfAborted();
373
+ // A lock during the derive doesn't fail it (WebCrypto copied the master key first), and the index client only counts locks from
374
+ // `initLocalIndex()`'s own call on: open nothing with the destroyed keys.
375
+ if (unlocked.destroyed) {
376
+ throw new KeysLockedError();
377
+ }
369
378
  await initLocalIndex({ mailboxUid, indexKey, generation });
370
379
  let { evictedBefore } = await setLocalIndexWindow(mailboxUid, windowConfig.timeFloorMonths, windowConfig.byteBudgetBytes, generation);
371
380
  await setLocalIndexBuilding(mailboxUid, true, { complete: false, generation });
381
+ // End-to-end mail another device already decrypted: imported at its version, so the walk below skips it.
382
+ await importClientSegments(mailboxUid, unlocked, client, { generation }).catch(() => undefined);
383
+ signal.throwIfAborted();
372
384
  // Mail arriving after this moment isn't guaranteed to be picked up by this pass.
373
385
  const coveredUntil = new Date(Date.now() - CLOCK_SKEW_MARGIN_MS).toISOString();
374
386
  let cutoff: Date | undefined;
@@ -389,6 +401,10 @@ async function runBuildPass(
389
401
  .filter((f) => MESSAGE_FOLDER_TYPES.has(f.type))
390
402
  .sort((a, b) => (FOLDER_PRIORITY[a.type] ?? 99) - (FOLDER_PRIORITY[b.type] ?? 99));
391
403
  const seenEncryptedUids = new Set<string>();
404
+ // What this pass decrypted and hasn't shared yet, for the mailbox's other devices.
405
+ const decrypted: LocalIndexEntity[] = [];
406
+ // Best effort: what fails to upload is decrypted again by the other devices themselves.
407
+ const share = (): Promise<unknown> => uploadClientDocuments(mailboxUid, unlocked, decrypted.splice(0), client).catch(() => undefined);
392
408
 
393
409
  async function walkFolder(folder: Folder): Promise<WalkOutcome> {
394
410
  for (let page = 0; ; page++) {
@@ -402,12 +418,28 @@ async function runBuildPass(
402
418
  if (messages.length === 0) {
403
419
  return "done";
404
420
  }
405
- const encrypted = messages.filter((m) => m.subject === ENCRYPTED_SUBJECT_PLACEHOLDER);
421
+ // The server's `encrypted` flag too: an OpenPGP sender (Proton Mail and others) keeps the real outer subject.
422
+ const encrypted = messages.filter((m) => m.subject === ENCRYPTED_SUBJECT_PLACEHOLDER || m.encrypted);
406
423
  for (const m of encrypted) {
407
424
  seenEncryptedUids.add(m.uid);
408
425
  }
426
+ // A zero-access message's content comes from the server's sealed index (`zeroAccessIndexSync.ts`), never decrypted here:
427
+ // only its folder and flags are recorded on its row - and remembered by version, so an unchanged one costs nothing next
428
+ // time. Its row may not be imported yet (a new device, or after a lock): the sync applies them when it imports it.
429
+ const sealed = encrypted.filter((m) => m.zeroAccess);
430
+ if (sealed.length > 0) {
431
+ const indexed = await getIndexedVersions(
432
+ mailboxUid,
433
+ sealed.map((m) => m.uid),
434
+ );
435
+ for (const m of sealed.filter((s) => indexed[s.uid] !== versionOf(s))) {
436
+ const metadata = { folderUid: m.folderUid, entityVersion: versionOf(m), flags: entityFlags(m) };
437
+ await moveLocalEntity(mailboxUid, m.uid, metadata.folderUid, metadata.entityVersion, metadata.flags);
438
+ rememberZeroAccessMetadata(mailboxUid, m.uid, metadata);
439
+ }
440
+ }
409
441
  // Anything older than the eviction watermark would only be inserted and evicted again.
410
- const candidates = encrypted.filter((m) => !isOlderThan(m.receivedDate, evictedBefore));
442
+ const candidates = encrypted.filter((m) => !m.zeroAccess && !isOlderThan(m.receivedDate, evictedBefore));
411
443
  if (candidates.length > 0) {
412
444
  // Skip anything already indexed at the same version - a re-unlock used to re-fetch and
413
445
  // re-decrypt the entire window every time.
@@ -424,6 +456,10 @@ async function runBuildPass(
424
456
  const entities = built.filter((e): e is LocalIndexEntity => e !== undefined && e !== FETCH_FAILED);
425
457
  if (entities.length > 0) {
426
458
  ({ evictedBefore } = await indexLocalEntities(mailboxUid, entities, generation));
459
+ decrypted.push(...entities);
460
+ if (decrypted.length >= CLIENT_UPLOAD_BATCH) {
461
+ await share();
462
+ }
427
463
  }
428
464
  }
429
465
  const oldestOnPage = messages[messages.length - 1].receivedDate;
@@ -481,6 +517,7 @@ async function runBuildPass(
481
517
  const since = evictedBefore && isWithinTimeFloor(evictedBefore, cutoff) ? evictedBefore : cutoff?.toISOString();
482
518
  await pruneLocalEntities(mailboxUid, [...seenEncryptedUids], since, { folderUids: reliable, generation });
483
519
  }
520
+ await share();
484
521
  } catch (err) {
485
522
  complete = false;
486
523
  throw err;