@rapidmx/web-client 0.9.0 → 0.11.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 (443) hide show
  1. package/README.md +373 -88
  2. package/apps/admin/_layout.tsx +8 -2
  3. package/apps/admin/index.tsx +7 -1
  4. package/apps/admin/ingest-queue/index.tsx +2 -1
  5. package/apps/admin/mailboxes/[uid].tsx +23 -10
  6. package/apps/admin/quarantine/index.tsx +2 -1
  7. package/apps/admin/signing-certificates/index.tsx +343 -0
  8. package/apps/escrow/_layout.tsx +8 -2
  9. package/apps/shared/appearance/AppearanceForm.tsx +392 -0
  10. package/apps/shared/appearance/AppearanceHead.tsx +49 -0
  11. package/apps/shared/appearance/AppearanceProvider.tsx +470 -0
  12. package/apps/shared/appearance/ColorField.tsx +107 -0
  13. package/apps/shared/appearance/appearanceCache.ts +106 -0
  14. package/apps/shared/appearance/appearanceContext.ts +77 -0
  15. package/apps/shared/appearance/bootScript.ts +35 -0
  16. package/apps/shared/appearance/color.ts +169 -0
  17. package/apps/shared/appearance/photo.ts +88 -0
  18. package/apps/shared/appearance/resolvedTheme.ts +67 -0
  19. package/apps/shared/appearance/theme.ts +355 -0
  20. package/apps/shared/auth/accountUrl.ts +9 -0
  21. package/apps/shared/auth/adminAccess.ts +99 -0
  22. package/apps/shared/components/admin/layout/AdminShell.tsx +22 -10
  23. package/apps/shared/components/admin/mailboxes/ShareAccessCard.tsx +107 -60
  24. package/apps/shared/components/admin/settings/BrandingForm.tsx +24 -0
  25. package/apps/shared/components/admin/settings/DomainDnsSetup.tsx +2 -1
  26. package/apps/shared/components/admin/settings/PluginsManager.tsx +228 -25
  27. package/apps/shared/components/admin/setup/SetupWizard.tsx +2 -1
  28. package/apps/shared/components/calendar/CalendarListSidebar.tsx +4 -5
  29. package/apps/shared/components/calendar/layout/CalendarShell.tsx +8 -2
  30. package/apps/shared/components/contacts/ContactForm.tsx +11 -5
  31. package/apps/shared/components/contacts/ContactsSidebar.tsx +5 -3
  32. package/apps/shared/components/contacts/ContactsToolbar.tsx +98 -115
  33. package/apps/shared/components/contacts/layout/ContactsShell.tsx +25 -8
  34. package/apps/shared/components/escrow/layout/EscrowShell.tsx +13 -6
  35. package/apps/shared/components/layout/AppShell.tsx +477 -288
  36. package/apps/shared/components/layout/BrandingChrome.tsx +200 -13
  37. package/apps/shared/components/layout/KeyEnrollmentGate.tsx +398 -389
  38. package/apps/shared/components/layout/MailboxProvisioning.tsx +168 -164
  39. package/apps/shared/components/layout/RailIcon.tsx +100 -0
  40. package/apps/shared/components/layout/ResponsiveToolbar.tsx +315 -0
  41. package/apps/shared/components/layout/ThemeSwitch.tsx +84 -0
  42. package/apps/shared/components/layout/UserMenu.tsx +372 -185
  43. package/apps/shared/components/mail/ConversationList.tsx +271 -262
  44. package/apps/shared/components/mail/ConversationThreadPane.tsx +147 -94
  45. package/apps/shared/components/mail/LazyReadingPane.tsx +113 -0
  46. package/apps/shared/components/mail/MailSelectionBar.tsx +227 -222
  47. package/apps/shared/components/mail/MessageDetailPane.tsx +1537 -1387
  48. package/apps/shared/components/mail/OutboxBadge.tsx +44 -0
  49. package/apps/shared/components/mail/OutboxRowStatus.tsx +31 -0
  50. package/apps/shared/components/mail/compose/ComposeContext.tsx +312 -160
  51. package/apps/shared/components/mail/compose/ComposeToolbar.tsx +422 -418
  52. package/apps/shared/components/mail/compose/ComposeWindow.tsx +1644 -1736
  53. package/apps/shared/components/mail/compose/ComposeWindowPlaceholder.tsx +111 -0
  54. package/apps/shared/components/mail/compose/RichTextEditor.tsx +147 -118
  55. package/apps/shared/components/mail/compose/composePerf.ts +46 -0
  56. package/apps/shared/components/mail/compose/encryptionRequirement.ts +86 -0
  57. package/apps/shared/components/mail/compose/quotedBody.ts +161 -100
  58. package/apps/shared/components/mail/layout/MailShell.tsx +490 -472
  59. package/apps/shared/components/mail/reading/EncryptedBody.tsx +65 -0
  60. package/apps/shared/components/mail/reading/EncryptedPreview.tsx +35 -0
  61. package/apps/shared/components/mail/reading/MessageBody.tsx +240 -0
  62. package/apps/shared/components/mail/reading/MessageCard.tsx +174 -0
  63. package/apps/shared/components/mail/reading/bodyContent.ts +100 -0
  64. package/apps/shared/components/mail/reading/bodyHtml.ts +298 -0
  65. package/apps/shared/components/mail/reading/color.ts +245 -0
  66. package/apps/shared/components/mail/reading/frameControl.ts +142 -0
  67. package/apps/shared/components/mail/reading/frameDocument.ts +123 -0
  68. package/apps/shared/components/mail/reading/safeDocument.ts +24 -0
  69. package/apps/shared/components/mail/reading/themeAdaptation.ts +221 -0
  70. package/apps/shared/components/mail/reading/themeSurface.ts +90 -0
  71. package/apps/shared/components/mail/reading/viewOriginal.ts +38 -0
  72. package/apps/shared/components/mail/unreadStyle.tsx +75 -0
  73. package/apps/shared/components/settings/SigningCertificateCard.tsx +344 -0
  74. package/apps/shared/components/settings/layout/SettingsShell.tsx +253 -240
  75. package/apps/shared/components/sharing/PrincipalPicker.tsx +145 -0
  76. package/apps/shared/components/tasks/TasksSidebar.tsx +5 -3
  77. package/apps/shared/components/tasks/layout/TasksShell.tsx +24 -8
  78. package/apps/shared/keyboard/GlobalShortcuts.tsx +51 -0
  79. package/apps/shared/keyboard/ShortcutProvider.tsx +62 -0
  80. package/apps/shared/keyboard/ShortcutsDialog.tsx +84 -0
  81. package/apps/shared/keyboard/dispatch.ts +124 -0
  82. package/apps/shared/keyboard/format.ts +89 -0
  83. package/apps/shared/keyboard/keymap.ts +114 -0
  84. package/apps/shared/keyboard/match.ts +44 -0
  85. package/apps/shared/keyboard/parse.ts +136 -0
  86. package/apps/shared/keyboard/platform.ts +34 -0
  87. package/apps/shared/keyboard/registry.ts +65 -0
  88. package/apps/shared/keyboard/targets.ts +79 -0
  89. package/apps/shared/keyboard/useShortcut.ts +50 -0
  90. package/apps/shared/keyboard/useShortcutProps.ts +17 -0
  91. package/apps/shared/mail/folderCounts.ts +308 -0
  92. package/apps/shared/mail/folderTree.ts +143 -0
  93. package/apps/shared/mail/listSnapshots.ts +87 -0
  94. package/apps/shared/mail/messageReadState.ts +85 -0
  95. package/apps/shared/mail/newMailNotifications.ts +183 -0
  96. package/apps/shared/mail/outbox/UnlockBridge.tsx +23 -0
  97. package/apps/shared/mail/outbox/composeBridge.ts +69 -0
  98. package/apps/shared/mail/outbox/outboxState.ts +88 -0
  99. package/apps/shared/mail/outbox/pendingSends.ts +146 -0
  100. package/apps/shared/mail/outbox/sendDecision.ts +157 -0
  101. package/apps/shared/mail/outbox/sendJob.ts +427 -0
  102. package/apps/shared/mail/outbox/sendOutcomes.ts +146 -0
  103. package/apps/shared/mail/outbox/sendState.ts +35 -0
  104. package/apps/shared/mail/outbox/useOutboxStatus.ts +61 -0
  105. package/apps/shared/mail/useMailConnection.ts +203 -0
  106. package/apps/shared/mail/useMailLiveUpdates.ts +277 -224
  107. package/apps/shared/mail/useMarkMessageRead.ts +47 -0
  108. package/apps/shared/mail/useNewMailNotifications.ts +178 -0
  109. package/apps/shared/mail/useUnreadTitle.ts +42 -0
  110. package/apps/shared/navigation/AppRouter.tsx +300 -0
  111. package/apps/shared/navigation/appHrefs.ts +23 -0
  112. package/apps/shared/navigation/frameContext.tsx +35 -0
  113. package/apps/shared/navigation/idle.ts +45 -0
  114. package/apps/shared/navigation/routerContext.tsx +83 -0
  115. package/apps/shared/navigation/routes.ts +72 -0
  116. package/apps/shared/notifications/NotificationCenter.tsx +215 -0
  117. package/apps/shared/notifications/NotificationHistoryDialog.tsx +90 -0
  118. package/apps/shared/notifications/apiErrors.ts +98 -0
  119. package/apps/shared/notifications/headerOffset.ts +35 -0
  120. package/apps/shared/notifications/pushStatus.ts +56 -0
  121. package/apps/shared/notifications/store.ts +549 -0
  122. package/apps/shared/notifications/systemErrors.ts +63 -0
  123. package/apps/shared/notifications/useNotifications.ts +41 -0
  124. package/apps/shared/search/LocalIndexLifecycle.tsx +114 -98
  125. package/apps/shared/signing/enrollmentStorage.ts +33 -0
  126. package/apps/shared/signing/enrollmentTracker.ts +385 -0
  127. package/apps/shared/signing/enrollmentView.ts +251 -0
  128. package/apps/shared/signing/signingInfo.ts +58 -0
  129. package/apps/shared/signing/useNow.ts +19 -0
  130. package/apps/shared/signing/useSigningEnrollmentWatcher.ts +90 -0
  131. package/apps/shared/styles/app.css +108 -10
  132. package/apps/www/_layout.tsx +8 -2
  133. package/apps/www/_routedPage.tsx +24 -0
  134. package/apps/www/_routes.ts +36 -0
  135. package/apps/www/calendar/index.tsx +64 -33
  136. package/apps/www/contacts/[uid].tsx +109 -107
  137. package/apps/www/contacts/index.tsx +62 -42
  138. package/apps/www/index.tsx +2291 -1917
  139. package/apps/www/messages/[uid].tsx +108 -101
  140. package/apps/www/settings/appearance/index.tsx +21 -0
  141. package/apps/www/settings/auto-reply/index.tsx +7 -8
  142. package/apps/www/settings/encryption/index.tsx +1287 -1249
  143. package/apps/www/settings/filters/[uid].tsx +7 -2
  144. package/apps/www/settings/filters/index.tsx +102 -99
  145. package/apps/www/settings/filters/new/index.tsx +140 -133
  146. package/apps/www/settings/labels/index.tsx +204 -201
  147. package/apps/www/settings/privacy/index.tsx +7 -9
  148. package/apps/www/settings/read-receipts/index.tsx +7 -8
  149. package/apps/www/settings/sharing/index.tsx +256 -274
  150. package/apps/www/settings/signatures/[uid].tsx +172 -167
  151. package/apps/www/settings/signatures/index.tsx +88 -85
  152. package/apps/www/settings/signatures/new/index.tsx +135 -129
  153. package/apps/www/tasks/index.tsx +29 -18
  154. package/dist/apps/admin/_layout.d.ts +5 -1
  155. package/dist/apps/admin/_layout.js +3 -2
  156. package/dist/apps/admin/index.js +3 -2
  157. package/dist/apps/admin/ingest-queue/index.js +2 -1
  158. package/dist/apps/admin/mailboxes/[uid].js +9 -6
  159. package/dist/apps/admin/quarantine/index.js +2 -1
  160. package/dist/apps/admin/signing-certificates/index.d.ts +3 -0
  161. package/dist/apps/admin/signing-certificates/index.js +161 -0
  162. package/dist/apps/escrow/_layout.d.ts +5 -1
  163. package/dist/apps/escrow/_layout.js +3 -2
  164. package/dist/apps/shared/appearance/AppearanceForm.d.ts +7 -0
  165. package/dist/apps/shared/appearance/AppearanceForm.js +131 -0
  166. package/dist/apps/shared/appearance/AppearanceHead.d.ts +15 -0
  167. package/dist/apps/shared/appearance/AppearanceHead.js +31 -0
  168. package/dist/apps/shared/appearance/AppearanceProvider.d.ts +32 -0
  169. package/dist/apps/shared/appearance/AppearanceProvider.js +390 -0
  170. package/dist/apps/shared/appearance/ColorField.d.ts +22 -0
  171. package/dist/apps/shared/appearance/ColorField.js +40 -0
  172. package/dist/apps/shared/appearance/appearanceCache.d.ts +45 -0
  173. package/dist/apps/shared/appearance/appearanceCache.js +80 -0
  174. package/dist/apps/shared/appearance/appearanceContext.d.ts +45 -0
  175. package/dist/apps/shared/appearance/appearanceContext.js +29 -0
  176. package/dist/apps/shared/appearance/bootScript.d.ts +16 -0
  177. package/dist/apps/shared/appearance/bootScript.js +33 -0
  178. package/dist/apps/shared/appearance/color.d.ts +65 -0
  179. package/dist/apps/shared/appearance/color.js +132 -0
  180. package/dist/apps/shared/appearance/photo.d.ts +17 -0
  181. package/dist/apps/shared/appearance/photo.js +79 -0
  182. package/dist/apps/shared/appearance/resolvedTheme.d.ts +21 -0
  183. package/dist/apps/shared/appearance/resolvedTheme.js +55 -0
  184. package/dist/apps/shared/appearance/theme.d.ts +111 -0
  185. package/dist/apps/shared/appearance/theme.js +251 -0
  186. package/dist/apps/shared/auth/accountUrl.d.ts +2 -0
  187. package/dist/apps/shared/auth/accountUrl.js +8 -0
  188. package/dist/apps/shared/auth/adminAccess.d.ts +30 -0
  189. package/dist/apps/shared/auth/adminAccess.js +89 -0
  190. package/dist/apps/shared/components/admin/layout/AdminShell.d.ts +1 -1
  191. package/dist/apps/shared/components/admin/layout/AdminShell.js +16 -6
  192. package/dist/apps/shared/components/admin/mailboxes/ShareAccessCard.d.ts +10 -5
  193. package/dist/apps/shared/components/admin/mailboxes/ShareAccessCard.js +49 -34
  194. package/dist/apps/shared/components/admin/settings/BrandingForm.d.ts +2 -0
  195. package/dist/apps/shared/components/admin/settings/BrandingForm.js +7 -1
  196. package/dist/apps/shared/components/admin/settings/DomainDnsSetup.js +1 -1
  197. package/dist/apps/shared/components/admin/settings/PluginsManager.js +106 -20
  198. package/dist/apps/shared/components/admin/setup/SetupWizard.js +2 -1
  199. package/dist/apps/shared/components/calendar/CalendarListSidebar.js +8 -8
  200. package/dist/apps/shared/components/calendar/layout/CalendarShell.d.ts +1 -1
  201. package/dist/apps/shared/components/calendar/layout/CalendarShell.js +8 -4
  202. package/dist/apps/shared/components/contacts/ContactForm.js +1 -1
  203. package/dist/apps/shared/components/contacts/ContactsSidebar.js +4 -2
  204. package/dist/apps/shared/components/contacts/ContactsToolbar.d.ts +6 -2
  205. package/dist/apps/shared/components/contacts/ContactsToolbar.js +28 -10
  206. package/dist/apps/shared/components/contacts/layout/ContactsShell.d.ts +1 -1
  207. package/dist/apps/shared/components/contacts/layout/ContactsShell.js +19 -6
  208. package/dist/apps/shared/components/escrow/layout/EscrowShell.js +7 -4
  209. package/dist/apps/shared/components/layout/AppShell.d.ts +34 -4
  210. package/dist/apps/shared/components/layout/AppShell.js +122 -17
  211. package/dist/apps/shared/components/layout/BrandingChrome.d.ts +69 -10
  212. package/dist/apps/shared/components/layout/BrandingChrome.js +140 -12
  213. package/dist/apps/shared/components/layout/KeyEnrollmentGate.js +10 -9
  214. package/dist/apps/shared/components/layout/MailboxProvisioning.js +3 -1
  215. package/dist/apps/shared/components/layout/RailIcon.d.ts +21 -0
  216. package/dist/apps/shared/components/layout/RailIcon.js +85 -0
  217. package/dist/apps/shared/components/layout/ResponsiveToolbar.d.ts +55 -0
  218. package/dist/apps/shared/components/layout/ResponsiveToolbar.js +199 -0
  219. package/dist/apps/shared/components/layout/ThemeSwitch.d.ts +9 -0
  220. package/dist/apps/shared/components/layout/ThemeSwitch.js +54 -0
  221. package/dist/apps/shared/components/layout/UserMenu.d.ts +25 -3
  222. package/dist/apps/shared/components/layout/UserMenu.js +88 -7
  223. package/dist/apps/shared/components/mail/ConversationList.js +5 -11
  224. package/dist/apps/shared/components/mail/ConversationThreadPane.d.ts +6 -2
  225. package/dist/apps/shared/components/mail/ConversationThreadPane.js +87 -40
  226. package/dist/apps/shared/components/mail/LazyReadingPane.d.ts +9 -0
  227. package/dist/apps/shared/components/mail/LazyReadingPane.js +83 -0
  228. package/dist/apps/shared/components/mail/MailSelectionBar.d.ts +6 -4
  229. package/dist/apps/shared/components/mail/MailSelectionBar.js +11 -4
  230. package/dist/apps/shared/components/mail/MessageDetailPane.d.ts +25 -8
  231. package/dist/apps/shared/components/mail/MessageDetailPane.js +167 -73
  232. package/dist/apps/shared/components/mail/OutboxBadge.d.ts +17 -0
  233. package/dist/apps/shared/components/mail/OutboxBadge.js +18 -0
  234. package/dist/apps/shared/components/mail/OutboxRowStatus.d.ts +10 -0
  235. package/dist/apps/shared/components/mail/OutboxRowStatus.js +19 -0
  236. package/dist/apps/shared/components/mail/compose/ComposeContext.d.ts +38 -0
  237. package/dist/apps/shared/components/mail/compose/ComposeContext.js +97 -6
  238. package/dist/apps/shared/components/mail/compose/ComposeToolbar.js +4 -3
  239. package/dist/apps/shared/components/mail/compose/ComposeWindow.d.ts +3 -2
  240. package/dist/apps/shared/components/mail/compose/ComposeWindow.js +316 -339
  241. package/dist/apps/shared/components/mail/compose/ComposeWindowPlaceholder.d.ts +19 -0
  242. package/dist/apps/shared/components/mail/compose/ComposeWindowPlaceholder.js +33 -0
  243. package/dist/apps/shared/components/mail/compose/RichTextEditor.d.ts +9 -1
  244. package/dist/apps/shared/components/mail/compose/RichTextEditor.js +20 -2
  245. package/dist/apps/shared/components/mail/compose/composePerf.d.ts +16 -0
  246. package/dist/apps/shared/components/mail/compose/composePerf.js +41 -0
  247. package/dist/apps/shared/components/mail/compose/encryptionRequirement.d.ts +49 -0
  248. package/dist/apps/shared/components/mail/compose/encryptionRequirement.js +35 -0
  249. package/dist/apps/shared/components/mail/compose/quotedBody.d.ts +13 -0
  250. package/dist/apps/shared/components/mail/compose/quotedBody.js +67 -11
  251. package/dist/apps/shared/components/mail/layout/MailShell.d.ts +14 -4
  252. package/dist/apps/shared/components/mail/layout/MailShell.js +90 -104
  253. package/dist/apps/shared/components/mail/reading/EncryptedBody.d.ts +21 -0
  254. package/dist/apps/shared/components/mail/reading/EncryptedBody.js +22 -0
  255. package/dist/apps/shared/components/mail/reading/EncryptedPreview.d.ts +18 -0
  256. package/dist/apps/shared/components/mail/reading/EncryptedPreview.js +22 -0
  257. package/dist/apps/shared/components/mail/reading/MessageBody.d.ts +32 -0
  258. package/dist/apps/shared/components/mail/reading/MessageBody.js +136 -0
  259. package/dist/apps/shared/components/mail/reading/MessageCard.d.ts +62 -0
  260. package/dist/apps/shared/components/mail/reading/MessageCard.js +58 -0
  261. package/dist/apps/shared/components/mail/reading/bodyContent.d.ts +38 -0
  262. package/dist/apps/shared/components/mail/reading/bodyContent.js +84 -0
  263. package/dist/apps/shared/components/mail/reading/bodyHtml.d.ts +47 -0
  264. package/dist/apps/shared/components/mail/reading/bodyHtml.js +267 -0
  265. package/dist/apps/shared/components/mail/reading/color.d.ts +63 -0
  266. package/dist/apps/shared/components/mail/reading/color.js +201 -0
  267. package/dist/apps/shared/components/mail/reading/frameControl.d.ts +33 -0
  268. package/dist/apps/shared/components/mail/reading/frameControl.js +120 -0
  269. package/dist/apps/shared/components/mail/reading/frameDocument.d.ts +52 -0
  270. package/dist/apps/shared/components/mail/reading/frameDocument.js +98 -0
  271. package/dist/apps/shared/components/mail/reading/safeDocument.d.ts +3 -0
  272. package/dist/apps/shared/components/mail/reading/safeDocument.js +12 -0
  273. package/dist/apps/shared/components/mail/reading/themeAdaptation.d.ts +56 -0
  274. package/dist/apps/shared/components/mail/reading/themeAdaptation.js +144 -0
  275. package/dist/apps/shared/components/mail/reading/themeSurface.d.ts +17 -0
  276. package/dist/apps/shared/components/mail/reading/themeSurface.js +83 -0
  277. package/dist/apps/shared/components/mail/reading/viewOriginal.d.ts +9 -0
  278. package/dist/apps/shared/components/mail/reading/viewOriginal.js +32 -0
  279. package/dist/apps/shared/components/mail/unreadStyle.d.ts +45 -0
  280. package/dist/apps/shared/components/mail/unreadStyle.js +61 -0
  281. package/dist/apps/shared/components/settings/SigningCertificateCard.d.ts +32 -0
  282. package/dist/apps/shared/components/settings/SigningCertificateCard.js +98 -0
  283. package/dist/apps/shared/components/settings/layout/SettingsShell.d.ts +1 -1
  284. package/dist/apps/shared/components/settings/layout/SettingsShell.js +16 -5
  285. package/dist/apps/shared/components/sharing/PrincipalPicker.d.ts +26 -0
  286. package/dist/apps/shared/components/sharing/PrincipalPicker.js +77 -0
  287. package/dist/apps/shared/components/tasks/TasksSidebar.js +4 -2
  288. package/dist/apps/shared/components/tasks/layout/TasksShell.d.ts +1 -1
  289. package/dist/apps/shared/components/tasks/layout/TasksShell.js +18 -6
  290. package/dist/apps/shared/keyboard/GlobalShortcuts.d.ts +14 -0
  291. package/dist/apps/shared/keyboard/GlobalShortcuts.js +37 -0
  292. package/dist/apps/shared/keyboard/ShortcutProvider.d.ts +20 -0
  293. package/dist/apps/shared/keyboard/ShortcutProvider.js +52 -0
  294. package/dist/apps/shared/keyboard/ShortcutsDialog.d.ts +14 -0
  295. package/dist/apps/shared/keyboard/ShortcutsDialog.js +42 -0
  296. package/dist/apps/shared/keyboard/dispatch.d.ts +16 -0
  297. package/dist/apps/shared/keyboard/dispatch.js +109 -0
  298. package/dist/apps/shared/keyboard/format.d.ts +12 -0
  299. package/dist/apps/shared/keyboard/format.js +74 -0
  300. package/dist/apps/shared/keyboard/keymap.d.ts +294 -0
  301. package/dist/apps/shared/keyboard/keymap.js +84 -0
  302. package/dist/apps/shared/keyboard/match.d.ts +20 -0
  303. package/dist/apps/shared/keyboard/match.js +31 -0
  304. package/dist/apps/shared/keyboard/parse.d.ts +31 -0
  305. package/dist/apps/shared/keyboard/parse.js +107 -0
  306. package/dist/apps/shared/keyboard/platform.d.ts +15 -0
  307. package/dist/apps/shared/keyboard/platform.js +22 -0
  308. package/dist/apps/shared/keyboard/registry.d.ts +39 -0
  309. package/dist/apps/shared/keyboard/registry.js +33 -0
  310. package/dist/apps/shared/keyboard/targets.d.ts +14 -0
  311. package/dist/apps/shared/keyboard/targets.js +67 -0
  312. package/dist/apps/shared/keyboard/useShortcut.d.ts +19 -0
  313. package/dist/apps/shared/keyboard/useShortcut.js +35 -0
  314. package/dist/apps/shared/keyboard/useShortcutProps.d.ts +10 -0
  315. package/dist/apps/shared/keyboard/useShortcutProps.js +15 -0
  316. package/dist/apps/shared/mail/folderCounts.d.ts +78 -0
  317. package/dist/apps/shared/mail/folderCounts.js +218 -0
  318. package/dist/apps/shared/mail/folderTree.d.ts +55 -0
  319. package/dist/apps/shared/mail/folderTree.js +116 -0
  320. package/dist/apps/shared/mail/listSnapshots.d.ts +46 -0
  321. package/dist/apps/shared/mail/listSnapshots.js +43 -0
  322. package/dist/apps/shared/mail/messageReadState.d.ts +32 -0
  323. package/dist/apps/shared/mail/messageReadState.js +63 -0
  324. package/dist/apps/shared/mail/newMailNotifications.d.ts +62 -0
  325. package/dist/apps/shared/mail/newMailNotifications.js +138 -0
  326. package/dist/apps/shared/mail/outbox/UnlockBridge.d.ts +5 -0
  327. package/dist/apps/shared/mail/outbox/UnlockBridge.js +18 -0
  328. package/dist/apps/shared/mail/outbox/composeBridge.d.ts +34 -0
  329. package/dist/apps/shared/mail/outbox/composeBridge.js +32 -0
  330. package/dist/apps/shared/mail/outbox/outboxState.d.ts +41 -0
  331. package/dist/apps/shared/mail/outbox/outboxState.js +42 -0
  332. package/dist/apps/shared/mail/outbox/pendingSends.d.ts +39 -0
  333. package/dist/apps/shared/mail/outbox/pendingSends.js +109 -0
  334. package/dist/apps/shared/mail/outbox/sendDecision.d.ts +80 -0
  335. package/dist/apps/shared/mail/outbox/sendDecision.js +94 -0
  336. package/dist/apps/shared/mail/outbox/sendJob.d.ts +68 -0
  337. package/dist/apps/shared/mail/outbox/sendJob.js +319 -0
  338. package/dist/apps/shared/mail/outbox/sendOutcomes.d.ts +3 -0
  339. package/dist/apps/shared/mail/outbox/sendOutcomes.js +141 -0
  340. package/dist/apps/shared/mail/outbox/sendState.d.ts +25 -0
  341. package/dist/apps/shared/mail/outbox/sendState.js +8 -0
  342. package/dist/apps/shared/mail/outbox/useOutboxStatus.d.ts +11 -0
  343. package/dist/apps/shared/mail/outbox/useOutboxStatus.js +49 -0
  344. package/dist/apps/shared/mail/useMailConnection.d.ts +56 -0
  345. package/dist/apps/shared/mail/useMailConnection.js +138 -0
  346. package/dist/apps/shared/mail/useMailLiveUpdates.d.ts +29 -9
  347. package/dist/apps/shared/mail/useMailLiveUpdates.js +60 -32
  348. package/dist/apps/shared/mail/useMarkMessageRead.d.ts +12 -0
  349. package/dist/apps/shared/mail/useMarkMessageRead.js +44 -0
  350. package/dist/apps/shared/mail/useNewMailNotifications.d.ts +35 -0
  351. package/dist/apps/shared/mail/useNewMailNotifications.js +130 -0
  352. package/dist/apps/shared/mail/useUnreadTitle.d.ts +18 -0
  353. package/dist/apps/shared/mail/useUnreadTitle.js +31 -0
  354. package/dist/apps/shared/navigation/AppRouter.d.ts +52 -0
  355. package/dist/apps/shared/navigation/AppRouter.js +242 -0
  356. package/dist/apps/shared/navigation/appHrefs.d.ts +14 -0
  357. package/dist/apps/shared/navigation/appHrefs.js +20 -0
  358. package/dist/apps/shared/navigation/frameContext.d.ts +19 -0
  359. package/dist/apps/shared/navigation/frameContext.js +24 -0
  360. package/dist/apps/shared/navigation/idle.d.ts +14 -0
  361. package/dist/apps/shared/navigation/idle.js +43 -0
  362. package/dist/apps/shared/navigation/routerContext.d.ts +37 -0
  363. package/dist/apps/shared/navigation/routerContext.js +56 -0
  364. package/dist/apps/shared/navigation/routes.d.ts +32 -0
  365. package/dist/apps/shared/navigation/routes.js +37 -0
  366. package/dist/apps/shared/notifications/NotificationCenter.d.ts +19 -0
  367. package/dist/apps/shared/notifications/NotificationCenter.js +90 -0
  368. package/dist/apps/shared/notifications/NotificationHistoryDialog.d.ts +10 -0
  369. package/dist/apps/shared/notifications/NotificationHistoryDialog.js +36 -0
  370. package/dist/apps/shared/notifications/apiErrors.d.ts +19 -0
  371. package/dist/apps/shared/notifications/apiErrors.js +86 -0
  372. package/dist/apps/shared/notifications/headerOffset.d.ts +8 -0
  373. package/dist/apps/shared/notifications/headerOffset.js +33 -0
  374. package/dist/apps/shared/notifications/pushStatus.d.ts +9 -0
  375. package/dist/apps/shared/notifications/pushStatus.js +54 -0
  376. package/dist/apps/shared/notifications/store.d.ts +136 -0
  377. package/dist/apps/shared/notifications/store.js +416 -0
  378. package/dist/apps/shared/notifications/systemErrors.d.ts +9 -0
  379. package/dist/apps/shared/notifications/systemErrors.js +58 -0
  380. package/dist/apps/shared/notifications/useNotifications.d.ts +17 -0
  381. package/dist/apps/shared/notifications/useNotifications.js +18 -0
  382. package/dist/apps/shared/search/LocalIndexLifecycle.js +17 -3
  383. package/dist/apps/shared/signing/enrollmentStorage.d.ts +10 -0
  384. package/dist/apps/shared/signing/enrollmentStorage.js +33 -0
  385. package/dist/apps/shared/signing/enrollmentTracker.d.ts +73 -0
  386. package/dist/apps/shared/signing/enrollmentTracker.js +307 -0
  387. package/dist/apps/shared/signing/enrollmentView.d.ts +57 -0
  388. package/dist/apps/shared/signing/enrollmentView.js +214 -0
  389. package/dist/apps/shared/signing/signingInfo.d.ts +11 -0
  390. package/dist/apps/shared/signing/signingInfo.js +48 -0
  391. package/dist/apps/shared/signing/useNow.d.ts +2 -0
  392. package/dist/apps/shared/signing/useNow.js +18 -0
  393. package/dist/apps/shared/signing/useSigningEnrollmentWatcher.d.ts +16 -0
  394. package/dist/apps/shared/signing/useSigningEnrollmentWatcher.js +87 -0
  395. package/dist/apps/shared/styles/app.css +108 -10
  396. package/dist/apps/www/_layout.d.ts +5 -1
  397. package/dist/apps/www/_layout.js +3 -2
  398. package/dist/apps/www/_routedPage.d.ts +12 -0
  399. package/dist/apps/www/_routedPage.js +19 -0
  400. package/dist/apps/www/_routes.d.ts +11 -0
  401. package/dist/apps/www/_routes.js +30 -0
  402. package/dist/apps/www/calendar/index.d.ts +2 -2
  403. package/dist/apps/www/calendar/index.js +41 -11
  404. package/dist/apps/www/contacts/[uid].d.ts +3 -9
  405. package/dist/apps/www/contacts/[uid].js +11 -9
  406. package/dist/apps/www/contacts/index.d.ts +2 -2
  407. package/dist/apps/www/contacts/index.js +30 -24
  408. package/dist/apps/www/index.d.ts +2 -2
  409. package/dist/apps/www/index.js +332 -48
  410. package/dist/apps/www/messages/[uid].d.ts +3 -7
  411. package/dist/apps/www/messages/[uid].js +10 -5
  412. package/dist/apps/www/settings/appearance/index.d.ts +4 -0
  413. package/dist/apps/www/settings/appearance/index.js +13 -0
  414. package/dist/apps/www/settings/auto-reply/index.d.ts +2 -2
  415. package/dist/apps/www/settings/auto-reply/index.js +6 -7
  416. package/dist/apps/www/settings/encryption/index.d.ts +2 -2
  417. package/dist/apps/www/settings/encryption/index.js +106 -96
  418. package/dist/apps/www/settings/filters/[uid].d.ts +2 -2
  419. package/dist/apps/www/settings/filters/[uid].js +6 -2
  420. package/dist/apps/www/settings/filters/index.d.ts +2 -2
  421. package/dist/apps/www/settings/filters/index.js +3 -1
  422. package/dist/apps/www/settings/filters/new/index.d.ts +2 -2
  423. package/dist/apps/www/settings/filters/new/index.js +9 -3
  424. package/dist/apps/www/settings/labels/index.d.ts +2 -2
  425. package/dist/apps/www/settings/labels/index.js +3 -1
  426. package/dist/apps/www/settings/privacy/index.d.ts +2 -2
  427. package/dist/apps/www/settings/privacy/index.js +8 -9
  428. package/dist/apps/www/settings/read-receipts/index.d.ts +2 -2
  429. package/dist/apps/www/settings/read-receipts/index.js +6 -7
  430. package/dist/apps/www/settings/sharing/index.d.ts +2 -2
  431. package/dist/apps/www/settings/sharing/index.js +22 -34
  432. package/dist/apps/www/settings/signatures/[uid].d.ts +2 -2
  433. package/dist/apps/www/settings/signatures/[uid].js +6 -2
  434. package/dist/apps/www/settings/signatures/index.d.ts +2 -2
  435. package/dist/apps/www/settings/signatures/index.js +3 -1
  436. package/dist/apps/www/settings/signatures/new/index.d.ts +2 -2
  437. package/dist/apps/www/settings/signatures/new/index.js +9 -4
  438. package/dist/apps/www/tasks/index.d.ts +2 -2
  439. package/dist/apps/www/tasks/index.js +22 -16
  440. package/package.json +2 -2
  441. package/apps/shared/components/mail/compose/SendFailureAlert.tsx +0 -48
  442. package/dist/apps/shared/components/mail/compose/SendFailureAlert.d.ts +0 -14
  443. package/dist/apps/shared/components/mail/compose/SendFailureAlert.js +0 -11
@@ -1,472 +1,490 @@
1
- ///////////////////////////////////////////////////////////////////////////////
2
- // Copyright (C) 2026 Jean-Philippe Steinmetz
3
- // SPDX-License-Identifier: MPL-2.0
4
- ///////////////////////////////////////////////////////////////////////////////
5
- import React, { createContext, PropsWithChildren, ReactNode, useCallback, useContext, useEffect, useMemo, useState } from "react";
6
- import { HiOutlineBars3 } from "react-icons/hi2";
7
- import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
8
- import Drawer from "@rapidmx/react-shared/components/overlays/Drawer.js";
9
- import { Folder, Mailbox, listFolders, listMailboxes } from "@rapidmx/react-shared/mail/mailApi.js";
10
- import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
11
- import Skeleton, { SkeletonList } from "@rapidmx/react-shared/components/feedback/Skeleton.js";
12
- import AppShell, { AppShellProps } from "../../layout/AppShell.js";
13
- import KeyEnrollmentGate from "../../layout/KeyEnrollmentGate.js";
14
- import MailboxProvisioning from "../../layout/MailboxProvisioning.js";
15
- import { useCompose } from "../compose/ComposeContext.js";
16
- import LocalIndexLifecycle from "../../../search/LocalIndexLifecycle.js";
17
- import { LiveUpdates, NO_LIVE_UPDATES, useMailLiveUpdates } from "../../../mail/useMailLiveUpdates.js";
18
-
19
- export type MailShellProps = Omit<AppShellProps, "active">;
20
-
21
- /** One mailbox's own mail folders (already filtered to `MAIL_FOLDER_TYPES` and unsorted) - one entry per
22
- * mailbox in `mailboxes`, fetched in parallel so every accessible mailbox's folder tree can render
23
- * simultaneously (see `MailShell`'s own doc comment on why this replaced the old single-mailbox `folders`
24
- * field). `error` is set (and `folders` left empty) for a mailbox whose own `listFolders()` call failed -
25
- * one mailbox's fetch failure must never blank out every other mailbox's section. */
26
- export interface MailboxFolders {
27
- mailbox: Mailbox;
28
- folders: Folder[];
29
- error?: string;
30
- }
31
-
32
- /** The well-known mail folder types an "aggregate" pseudo-folder can merge across every accessible
33
- * mailbox - a fixed, small set: `outbox` is deliberately excluded (transient per-mailbox send-queue
34
- * state, not a "merge across mailboxes" concept), and there's no aggregate concept for `calendar`/
35
- * `contacts`/`tasks`/`notes`/`user` folders (Mail's own sidebar already excludes those - see
36
- * `MAIL_FOLDER_TYPES`). */
37
- export const AGGREGATE_FOLDER_TYPES = ["inbox", "sent_items", "drafts", "deleted_items", "junk"] as const;
38
- export type AggregateFolderType = (typeof AGGREGATE_FOLDER_TYPES)[number];
39
-
40
- function isAggregateFolderType(value: string | null): value is AggregateFolderType {
41
- return !!value && (AGGREGATE_FOLDER_TYPES as readonly string[]).includes(value);
42
- }
43
-
44
- export interface MailShellContextValue {
45
- /** The mailbox currently selected (`?mailboxUid=`) - `undefined` while an aggregate pseudo-folder is
46
- * active instead (`aggregateFolderType` set), since there's no single mailbox to speak of then. */
47
- mailboxUid?: string;
48
- /** The folder currently selected (`?folderUid=`, or the selected mailbox's Inbox) - `undefined` in
49
- * aggregate mode, for the same reason. */
50
- folderUid?: string;
51
- /** Set only when an aggregate pseudo-folder (`?aggregate=inbox` etc.) is selected instead of a real,
52
- * single mailbox+folder - mutually exclusive with `mailboxUid`/`folderUid` above. */
53
- aggregateFolderType?: AggregateFolderType;
54
- mailboxes: Mailbox[];
55
- /** Every accessible mailbox's own mail folders - replaces the old single-mailbox `folders: Folder[]`
56
- * now that every mailbox's tree renders at once (see `MailboxFolders`'s own doc comment). */
57
- mailboxFolders: MailboxFolders[];
58
- /**
59
- * Adds a folder a page has just created (the Move to prompt's "New folder") to the tree this shell
60
- * already fetched, so it appears in the sidebar and in every folder picker without a reload - this
61
- * framework has no client-side router, so a reload is a whole page load.
62
- *
63
- * A no-op on the default context value, which is only ever read outside a real shell.
64
- */
65
- onFolderCreated: (folder: Folder) => void;
66
- /**
67
- * Bumped whenever new mail (or another change to a message) may have arrived - a push event, a reconnect or the safety-net
68
- * poll - so the list on screen can quietly refetch its first page. See `useMailLiveUpdates()`. Never changes on the default
69
- * context value, which is only ever read outside a real shell.
70
- */
71
- live: LiveUpdates;
72
- }
73
-
74
- const MailShellContext = createContext<MailShellContextValue>({
75
- mailboxes: [],
76
- mailboxFolders: [],
77
- onFolderCreated: () => undefined,
78
- live: NO_LIVE_UPDATES,
79
- });
80
-
81
- /** Reads the mailbox/folder a page is currently showing, as resolved by the enclosing `MailShell`. */
82
- export function useMailShell(): MailShellContextValue {
83
- return useContext(MailShellContext);
84
- }
85
-
86
- const FOLDER_LABELS: Record<string, string> = {
87
- inbox: "Inbox",
88
- sent_items: "Sent Items",
89
- drafts: "Drafts",
90
- outbox: "Outbox",
91
- junk: "Junk Email",
92
- archive: "Archive",
93
- deleted_items: "Deleted Items",
94
- };
95
-
96
- /** Well-known folders sort first, in Gmail/Outlook's conventional order; anything else (incl. `user`) sorts after, alphabetically. */
97
- const FOLDER_ORDER = ["inbox", "drafts", "outbox", "sent_items", "junk", "archive", "deleted_items"];
98
-
99
- /**
100
- * A mailbox's `calendar`/`contacts`/`tasks`/`notes` folders back their own dedicated apps (see
101
- * `CalendarShell`/`ContactsShell`/`TasksShell`), not Mail — `listFolders()` returns every well-known
102
- * folder for the mailbox regardless of which app owns it, so Mail's own folder tree must filter down
103
- * to just the mail ones itself, or those other apps' folders leak into this sidebar.
104
- */
105
- const MAIL_FOLDER_TYPES = new Set([...FOLDER_ORDER, "user"]);
106
-
107
- function folderSortKey(folder: Folder): number {
108
- const idx = FOLDER_ORDER.indexOf(folder.type);
109
- return idx === -1 ? FOLDER_ORDER.length : idx;
110
- }
111
-
112
- function sortedFoldersOf(folders: Folder[]): Folder[] {
113
- return [...folders].sort((a, b) => folderSortKey(a) - folderSortKey(b) || a.name.localeCompare(b.name));
114
- }
115
-
116
- /** A folder's unread count: the refreshed one when live updates have read it since load, else the one it was listed with. */
117
- function unreadOf(folder: Folder, unreadCounts: Record<string, number>): number {
118
- return unreadCounts[folder.uid] ?? folder.unreadCount;
119
- }
120
-
121
- function aggregateUnreadCount(mailboxFolders: MailboxFolders[], type: AggregateFolderType, unreadCounts: Record<string, number>): number {
122
- return mailboxFolders.reduce((total, mf) => {
123
- const folder = mf.folders.find((f) => f.type === type);
124
- return total + (folder ? unreadOf(folder, unreadCounts) : 0);
125
- }, 0);
126
- }
127
-
128
- type Status = "checking" | "error" | "ready";
129
-
130
- /** Page size of the one `listMailboxes()` call this shell makes. */
131
- export const MAILBOX_LIST_LIMIT = 100;
132
-
133
- /**
134
- * A separate component (not inlined into `MailShell`'s own render) so `useCompose()` resolves against
135
- * `ComposeProvider` correctly: that provider is rendered *inside* the `AppShell` that `MailShell` itself
136
- * returns, i.e. a descendant of `MailShell`, not an ancestor — a hook call made directly in `MailShell`'s
137
- * own function body would see only whatever context exists *above* `MailShell`, never a provider one of
138
- * its own descendants creates. This button, rendered as part of `AppShell`'s `children`, sits correctly
139
- * inside that subtree.
140
- *
141
- * Opens with no mailbox: a fresh message defaults to the caller's own mailbox, and the compose window's
142
- * own From field is where the sender is chosen.
143
- */
144
- function ComposeButton() {
145
- const { openCompose } = useCompose();
146
- return (
147
- <button
148
- type="button"
149
- onClick={() => openCompose({})}
150
- className="block text-center w-full py-2.5 px-4 rounded-sm font-semibold text-sm bg-primary text-white hover:bg-primary-dark"
151
- >
152
- Compose
153
- </button>
154
- );
155
- }
156
-
157
- /**
158
- * Mail's own contextual sidebar (every accessible mailbox's own folder tree, plus a merged "All Mailboxes"
159
- * aggregate section) + content area, rendered inside the shared `AppShell` chrome (icon rail, header,
160
- * impersonation banner — see that component). There is no client-side router in this framework (see
161
- * `ReactRoute`'s file-convention resolver) — the selected mailbox/folder (or aggregate pseudo-folder) live
162
- * in the URL's `?mailboxUid=`/`?folderUid=`/`?aggregate=` query params, read once on mount (never during
163
- * the initial render itself, matching every other query-param reader in this codebase — e.g.
164
- * `apps/admin/quarantine`'s `readMailboxUid()` — so the server-rendered and just-hydrated client markup
165
- * match).
166
- *
167
- * Every accessible mailbox's folder tree renders at once - there is no "switch mailbox" affordance
168
- * anymore (the mailbox `<select>` this shell used to have is gone) - so a single-mailbox user sees zero
169
- * behavior change from before this, and a multi-mailbox user sees every mailbox's folders (and the new
170
- * aggregate section) simultaneously, matching the shared-mailbox feature's own "display as a separate set
171
- * of folders" requirement.
172
- */
173
- export default function MailShell({
174
- userUid,
175
- authServerUrl,
176
- impersonating,
177
- impersonationBaseUrl,
178
- trusted,
179
- pluginNav,
180
- children,
181
- }: PropsWithChildren<MailShellProps>) {
182
- const [status, setStatus] = useState<Status>("checking");
183
- const [error, setError] = useState<string | null>(null);
184
- const [mailboxes, setMailboxes] = useState<Mailbox[]>([]);
185
- const [mailboxFolders, setMailboxFolders] = useState<MailboxFolders[]>([]);
186
- const [foldersLoading, setFoldersLoading] = useState(true);
187
- const [requestedMailboxUid, setRequestedMailboxUid] = useState<string | null>(null);
188
- const [requestedFolderUid, setRequestedFolderUid] = useState<string | null>(null);
189
- const [requestedAggregateType, setRequestedAggregateType] = useState<string | null>(null);
190
- const [drawerOpen, setDrawerOpen] = useState(false);
191
-
192
- useEffect(() => {
193
- const params = new URLSearchParams(window.location.search);
194
- setRequestedMailboxUid(params.get("mailboxUid"));
195
- setRequestedFolderUid(params.get("folderUid"));
196
- setRequestedAggregateType(params.get("aggregate"));
197
- }, []);
198
-
199
- useEffect(() => {
200
- if (!userUid) {
201
- return;
202
- }
203
- listMailboxes({ limit: MAILBOX_LIST_LIMIT })
204
- .then((result) => {
205
- setMailboxes(result);
206
- setStatus("ready");
207
- })
208
- .catch((err) => {
209
- setError(err instanceof ApiRequestError ? err.message : "Could not load your mailboxes.");
210
- setStatus("error");
211
- });
212
- }, [userUid]);
213
-
214
- const aggregateFolderType: AggregateFolderType | undefined = isAggregateFolderType(requestedAggregateType)
215
- ? requestedAggregateType
216
- : undefined;
217
-
218
- const mailboxUid: string | undefined = aggregateFolderType
219
- ? undefined
220
- : (requestedMailboxUid && mailboxes.some((mb) => mb.uid === requestedMailboxUid) ? requestedMailboxUid : undefined) ??
221
- mailboxes[0]?.uid;
222
-
223
- // Fans out one listFolders() call per accessible mailbox in parallel - each call catches its own
224
- // failure into an MailboxFolders.error rather than letting Promise.all reject, so one mailbox's fetch
225
- // failure renders that section's own inline Alert instead of blanking out every other mailbox's
226
- // folder tree.
227
- useEffect(() => {
228
- if (mailboxes.length === 0) {
229
- // Deliberately leaves foldersLoading as-is: this also runs once before listMailboxes() has
230
- // resolved, and clearing it here would briefly render an empty sidebar the moment mailboxes
231
- // arrive, before their folders do. A genuinely mailbox-less caller gets MailboxProvisioning.
232
- setMailboxFolders([]);
233
- return;
234
- }
235
- setFoldersLoading(true);
236
- void Promise.all(
237
- mailboxes.map((mailbox) =>
238
- listFolders(mailbox.uid)
239
- .then((result): MailboxFolders => ({ mailbox, folders: result.filter((f) => MAIL_FOLDER_TYPES.has(f.type)) }))
240
- .catch(
241
- (err): MailboxFolders => ({
242
- mailbox,
243
- folders: [],
244
- error: err instanceof ApiRequestError ? err.message : "Could not load folders.",
245
- }),
246
- ),
247
- ),
248
- )
249
- .then(setMailboxFolders)
250
- .finally(() => setFoldersLoading(false));
251
- }, [mailboxes]);
252
-
253
- const selectedMailboxFolders = mailboxFolders.find((mf) => mf.mailbox.uid === mailboxUid)?.folders ?? [];
254
- const folderUid: string | undefined = aggregateFolderType
255
- ? undefined
256
- : (requestedFolderUid && selectedMailboxFolders.some((f) => f.uid === requestedFolderUid) ? requestedFolderUid : undefined) ??
257
- selectedMailboxFolders.find((f) => f.type === "inbox")?.uid;
258
-
259
- // The mailbox `KeyEnrollmentGate`/`LocalIndexLifecycle`/`ComposeButton` treat as "the" mailbox when
260
- // there's no single selected one to use (aggregate mode) - the caller's own owned mailbox if they
261
- // have one, else whichever accessible mailbox happens to be first. See MailShell's own doc comment on
262
- // this being an accepted limitation: an aggregate-view message from a *different*, not-yet-visited
263
- // mailbox may still need that mailbox's own folder view opened directly to unlock/decrypt it.
264
- const defaultMailboxUid = mailboxes.find((mb) => mb.ownerUserUid === userUid)?.uid ?? mailboxes[0]?.uid;
265
- const activeMailboxUid = mailboxUid ?? defaultMailboxUid;
266
-
267
- /** Files a newly created folder under its own mailbox, leaving every other mailbox's list untouched -
268
- * and ignoring a type this sidebar doesn't list at all, the same filter the fetch above applies. */
269
- const onFolderCreated = useCallback((folder: Folder) => {
270
- if (!MAIL_FOLDER_TYPES.has(folder.type)) {
271
- return;
272
- }
273
- setMailboxFolders((prev) =>
274
- prev.map((entry) =>
275
- // Not one already there: another client's create event can arrive after (or twice, or alongside) our own.
276
- entry.mailbox.uid === folder.mailboxUid && !entry.folders.some((existing) => existing.uid === folder.uid)
277
- ? { ...entry, folders: [...entry.folders, folder] }
278
- : entry,
279
- ),
280
- );
281
- }, []);
282
-
283
- // New mail without a reload: push events for every folder, plus a safety-net poll. Held in state beside `mailboxFolders`
284
- // rather than written into it, so a refreshed unread count never looks like a change of folders to the list on screen
285
- // (which reloads, and forgets its selection, whenever the folders do).
286
- const { live, unreadCounts } = useMailLiveUpdates({ userUid, mailboxes, mailboxFolders, onFolderCreated });
287
-
288
- const contextValue = useMemo<MailShellContextValue>(
289
- () => ({ mailboxUid, folderUid, aggregateFolderType, mailboxes, mailboxFolders, onFolderCreated, live }),
290
- [mailboxUid, folderUid, aggregateFolderType, mailboxes, mailboxFolders, onFolderCreated, live],
291
- );
292
-
293
- // A full-screen takeover, not nested inside the rest of the app's chrome — there's nothing else for a
294
- // mailbox-less caller to do here yet, so the icon rail/header/folder tree don't render at all. Checks
295
- // `mailboxes.length` directly (not `!mailboxUid`) since `mailboxUid` is legitimately undefined in
296
- // aggregate mode even with mailboxes present.
297
- if (userUid && status === "ready" && mailboxes.length === 0) {
298
- return <MailboxProvisioning />;
299
- }
300
-
301
- let inner: ReactNode = null;
302
- if (userUid && status === "checking") {
303
- // Renders immediately (no network round trip needed) so switching into Mail never shows a blank
304
- // pane while `listMailboxes()` is in flight — the outline below mirrors the real sidebar's shape.
305
- inner = (
306
- <aside className="w-64 shrink-0 bg-surface border-r border-border flex flex-col p-3 gap-4">
307
- <Skeleton height="h-9" className="rounded-sm" />
308
- <SkeletonList count={6} />
309
- </aside>
310
- );
311
- } else if (userUid && status === "error") {
312
- inner = (
313
- <div className="flex-1 flex items-center justify-center p-8">
314
- <div className="w-full max-w-md">
315
- <Alert>{error}</Alert>
316
- </div>
317
- </div>
318
- );
319
- } else if (userUid && status === "ready") {
320
- // A function, not a plain JSX constant — it's rendered twice (desktop `<aside>` + mobile
321
- // `Drawer`), possibly *simultaneously* mounted (the aside is only CSS-hidden below `md`, not
322
- // unmounted).
323
- const sidebarContent = () => (
324
- <>
325
- <div className="p-3">
326
- <ComposeButton />
327
- </div>
328
- {foldersLoading ? (
329
- <div className="flex-1 overflow-y-auto px-3 pb-3">
330
- <SkeletonList count={6} className="pt-1" />
331
- </div>
332
- ) : (
333
- <nav className="flex-1 overflow-y-auto px-3 pb-3 flex flex-col gap-3">
334
- {mailboxes.length > 1 && (
335
- <div>
336
- <div className="text-xs font-bold uppercase tracking-wide text-text-muted mb-1 px-2.5">
337
- All Mailboxes
338
- </div>
339
- <div className="flex flex-col gap-0.5">
340
- {AGGREGATE_FOLDER_TYPES.map((type) => {
341
- const unread = aggregateUnreadCount(mailboxFolders, type, unreadCounts);
342
- return (
343
- <a
344
- key={type}
345
- href={`/?aggregate=${encodeURIComponent(type)}`}
346
- className={[
347
- "flex items-center justify-between text-sm rounded-sm py-1.5 px-2.5",
348
- aggregateFolderType === type
349
- ? "bg-primary/10 text-primary-dark font-semibold"
350
- : "text-text hover:bg-surface-alt",
351
- ].join(" ")}
352
- >
353
- <span>{FOLDER_LABELS[type]}</span>
354
- {unread > 0 && (
355
- <span className="text-xs font-bold rounded-pill py-0.5 px-1.5 bg-surface-alt text-text-muted">
356
- {unread}
357
- </span>
358
- )}
359
- </a>
360
- );
361
- })}
362
- </div>
363
- </div>
364
- )}
365
- {mailboxFolders.map(({ mailbox, folders, error: mailboxError }) => (
366
- <div key={mailbox.uid}>
367
- <div className="text-xs font-bold uppercase tracking-wide text-text-muted mb-1 px-2.5 truncate">
368
- {mailbox.displayName}
369
- {mailbox.ownerUserUid ? "" : " (shared)"}
370
- </div>
371
- {mailboxError && (
372
- <div className="px-2.5 pb-1">
373
- <Alert>{mailboxError}</Alert>
374
- </div>
375
- )}
376
- <div className="flex flex-col gap-0.5">
377
- {sortedFoldersOf(folders).map((folder) => {
378
- const unread = unreadOf(folder, unreadCounts);
379
- return (
380
- <a
381
- key={folder.uid}
382
- href={`/?mailboxUid=${encodeURIComponent(mailbox.uid)}&folderUid=${encodeURIComponent(folder.uid)}`}
383
- className={[
384
- "flex items-center justify-between text-sm rounded-sm py-1.5 px-2.5",
385
- folder.uid === folderUid
386
- ? "bg-primary/10 text-primary-dark font-semibold"
387
- : "text-text hover:bg-surface-alt",
388
- ].join(" ")}
389
- >
390
- <span>{FOLDER_LABELS[folder.type] ?? folder.name}</span>
391
- {unread > 0 && (
392
- <span className="text-xs font-bold rounded-pill py-0.5 px-1.5 bg-surface-alt text-text-muted">
393
- {unread}
394
- </span>
395
- )}
396
- </a>
397
- );
398
- })}
399
- </div>
400
- </div>
401
- ))}
402
- </nav>
403
- )}
404
- </>
405
- );
406
-
407
- inner = (
408
- <>
409
- <aside className="hidden md:flex w-64 shrink-0 bg-surface border-r border-border flex-col">{sidebarContent()}</aside>
410
- <Drawer open={drawerOpen} onClose={() => setDrawerOpen(false)} title="Folders">
411
- <div className="flex flex-col">{sidebarContent()}</div>
412
- </Drawer>
413
- <main className="flex-1 min-w-0 overflow-y-auto">
414
- <button
415
- type="button"
416
- className="md:hidden m-3 w-9 h-9 flex items-center justify-center rounded-sm text-text-muted hover:bg-surface-alt hover:text-text"
417
- aria-label="Open folders"
418
- onClick={() => setDrawerOpen(true)}
419
- >
420
- <HiOutlineBars3 size={20} aria-hidden="true" />
421
- </button>
422
- <MailShellContext.Provider value={contextValue}>{children}</MailShellContext.Provider>
423
- </main>
424
- </>
425
- );
426
- }
427
-
428
- // Wraps AppShell unconditionally, at a stable tree position regardless of whether mailboxUid has
429
- // resolved yet - KeyEnrollmentGate itself passes `children` through untouched until a real
430
- // mailboxUid is supplied (see its own doc comment). Wrapping only once ready (a conditional tree
431
- // position) would make AppShell itself remount the moment mailboxUid resolves, tearing down
432
- // whatever state/effects it had already started (confirmed by direct reproduction: the
433
- // impersonation banner's own internal state was lost exactly at that transition).
434
- const activeMailbox = mailboxes.find((mb) => mb.uid === activeMailboxUid);
435
- return (
436
- <KeyEnrollmentGate
437
- mailboxUid={activeMailboxUid}
438
- mailboxAddress={activeMailbox?.primarySmtpAddress}
439
- mailboxKeys={activeMailbox?.keys}
440
- // Unlocking is only actually required to sign/encrypt a compose, read an already-encrypted
441
- // message, or change encryption settings - not merely to open Mail. Those specific call sites
442
- // (ComposeWindow, MessageDetailPane) request an unlock on demand via useUnlockPrompt() instead.
443
- // First-time provisioning (a mailbox with no vault at all yet) still always blocks - see this
444
- // prop's own doc comment on KeyEnrollmentGateProps.
445
- blocking={false}
446
- // A shared/delegated mailbox the caller doesn't own is never provisioned from here - its keys
447
- // belong to its owner (or its admins), not to whoever happens to open it first - and neither is
448
- // the impersonated user's own mailbox: an administrator must never choose its password/recovery codes.
449
- canProvision={!impersonating && activeMailbox?.ownerUserUid === userUid}
450
- >
451
- <LocalIndexLifecycle
452
- mailboxUid={activeMailboxUid}
453
- mailboxKeys={activeMailbox?.keys}
454
- folders={mailboxFolders.find((mf) => mf.mailbox.uid === activeMailboxUid)?.folders ?? []}
455
- // A full page may be truncated - pruning against it would delete indexes of accessible mailboxes
456
- // beyond the limit, so it's only trusted as the complete list when it came back short.
457
- accessibleMailboxUids={status === "ready" && mailboxes.length < MAILBOX_LIST_LIMIT ? mailboxes.map((mb) => mb.uid) : undefined}
458
- />
459
- <AppShell
460
- active="mail"
461
- userUid={userUid}
462
- authServerUrl={authServerUrl}
463
- impersonating={impersonating}
464
- impersonationBaseUrl={impersonationBaseUrl}
465
- trusted={trusted}
466
- pluginNav={pluginNav}
467
- >
468
- {inner}
469
- </AppShell>
470
- </KeyEnrollmentGate>
471
- );
472
- }
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import React, { createContext, PropsWithChildren, ReactNode, useContext, useEffect, useMemo, useState } from "react";
6
+ import { HiOutlineBars3 } from "react-icons/hi2";
7
+ import Drawer from "@rapidmx/react-shared/components/overlays/Drawer.js";
8
+ import { Folder, Mailbox, Message } from "@rapidmx/react-shared/mail/mailApi.js";
9
+ import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
10
+ import Skeleton, { SkeletonList } from "@rapidmx/react-shared/components/feedback/Skeleton.js";
11
+ import AppShell, { AppShellProps } from "../../layout/AppShell.js";
12
+ import { useLocationSearch, useNavigate } from "../../../navigation/AppRouter.js";
13
+ import KeyEnrollmentGate from "../../layout/KeyEnrollmentGate.js";
14
+ import MailboxProvisioning from "../../layout/MailboxProvisioning.js";
15
+ import { prefetchComposeWindow, useCompose } from "../compose/ComposeContext.js";
16
+ import LocalIndexLifecycle from "../../../search/LocalIndexLifecycle.js";
17
+ import { LiveUpdates, NO_LIVE_UPDATES } from "../../../mail/useMailLiveUpdates.js";
18
+ import { MAILBOX_LIST_LIMIT, MailConnectionContext, useMailConnection } from "../../../mail/useMailConnection.js";
19
+ import { folderRows } from "../../../mail/folderTree.js";
20
+ import {
21
+ CountTracker,
22
+ FolderBadge,
23
+ FolderCount,
24
+ badgeFor,
25
+ badgeLabel,
26
+ countOfFolder,
27
+ inboxUnreadTotal,
28
+ } from "../../../mail/folderCounts.js";
29
+ import { useUnreadTitle } from "../../../mail/useUnreadTitle.js";
30
+ import { pendingCountFor, usePendingSends } from "../../../mail/outbox/pendingSends.js";
31
+ import OutboxBadge from "../OutboxBadge.js";
32
+ import { ariaKeyShortcuts, withHint } from "../../../keyboard/format.js";
33
+ import { SHORTCUTS } from "../../../keyboard/keymap.js";
34
+ import { useKeyEnvironment } from "../../../keyboard/ShortcutProvider.js";
35
+ import { useShortcut } from "../../../keyboard/useShortcut.js";
36
+
37
+ export type MailShellProps = Omit<AppShellProps, "active">;
38
+
39
+ /** One mailbox's own mail folders (already filtered to `MAIL_FOLDER_TYPES` and unsorted) - one entry per
40
+ * mailbox in `mailboxes`, fetched in parallel so every accessible mailbox's folder tree can render
41
+ * simultaneously (see `MailShell`'s own doc comment on why this replaced the old single-mailbox `folders`
42
+ * field). `error` is set (and `folders` left empty) for a mailbox whose own `listFolders()` call failed -
43
+ * one mailbox's fetch failure must never blank out every other mailbox's section. */
44
+ export interface MailboxFolders {
45
+ mailbox: Mailbox;
46
+ folders: Folder[];
47
+ error?: string;
48
+ }
49
+
50
+ /** The well-known mail folder types an "aggregate" pseudo-folder can merge across every accessible
51
+ * mailbox - a fixed, small set: `outbox` is deliberately excluded (transient per-mailbox send-queue
52
+ * state, not a "merge across mailboxes" concept), and there's no aggregate concept for `calendar`/
53
+ * `contacts`/`tasks`/`notes`/`user` folders (Mail's own sidebar already excludes those - see
54
+ * `MAIL_FOLDER_TYPES`). */
55
+ export const AGGREGATE_FOLDER_TYPES = ["inbox", "sent_items", "drafts", "deleted_items", "junk"] as const;
56
+ export type AggregateFolderType = (typeof AGGREGATE_FOLDER_TYPES)[number];
57
+
58
+ function isAggregateFolderType(value: string | null): value is AggregateFolderType {
59
+ return !!value && (AGGREGATE_FOLDER_TYPES as readonly string[]).includes(value);
60
+ }
61
+
62
+ export interface MailShellContextValue {
63
+ /** The mailbox currently selected (`?mailboxUid=`) - `undefined` while an aggregate pseudo-folder is
64
+ * active instead (`aggregateFolderType` set), since there's no single mailbox to speak of then. */
65
+ mailboxUid?: string;
66
+ /** The folder currently selected (`?folderUid=`, or the selected mailbox's Inbox) - `undefined` in
67
+ * aggregate mode, for the same reason. */
68
+ folderUid?: string;
69
+ /** Set only when an aggregate pseudo-folder (`?aggregate=inbox` etc.) is selected instead of a real,
70
+ * single mailbox+folder - mutually exclusive with `mailboxUid`/`folderUid` above. */
71
+ aggregateFolderType?: AggregateFolderType;
72
+ mailboxes: Mailbox[];
73
+ /** Every accessible mailbox's own mail folders - replaces the old single-mailbox `folders: Folder[]`
74
+ * now that every mailbox's tree renders at once (see `MailboxFolders`'s own doc comment). */
75
+ mailboxFolders: MailboxFolders[];
76
+ /**
77
+ * Adds a folder a page has just created (the Move to prompt's "New folder") to the tree this shell
78
+ * already fetched, so it appears in the sidebar and in every folder picker without a reload - this
79
+ * framework has no client-side router, so a reload is a whole page load.
80
+ *
81
+ * A no-op on the default context value, which is only ever read outside a real shell.
82
+ */
83
+ onFolderCreated: (folder: Folder) => void;
84
+ /** Says which folders the messages on screen live in: one the sidebar does not know is looked for (see `MailConnection.noteFolderUids`). A no-op on the default context value. */
85
+ noteFolderUids: (folderUids: Iterable<string>) => void;
86
+ /**
87
+ * Bumped whenever new mail (or another change to a message) may have arrived - a push event, a reconnect or the safety-net
88
+ * poll - so the list on screen can quietly refetch its first page. See `useMailLiveUpdates()`. Never changes on the default
89
+ * context value, which is only ever read outside a real shell.
90
+ */
91
+ live: LiveUpdates;
92
+ /**
93
+ * Applies a change to a message (`previous` to `next`; `next` absent when it was deleted) to the folder badges at once, and
94
+ * hands back what to call when the server has answered: `settle()` keeps it, `revert()` takes it back. Every place that
95
+ * reads, moves or deletes a message goes through this (see `setReadState()`), so the badges follow. A no-op on the default
96
+ * context value, which is only ever read outside a real shell.
97
+ */
98
+ trackMessageChange: (previous: Message, next: Message | null) => CountTracker;
99
+ }
100
+
101
+ const NO_TRACKER: CountTracker = { settle: () => undefined, revert: () => undefined };
102
+
103
+ const MailShellContext = createContext<MailShellContextValue>({
104
+ mailboxes: [],
105
+ mailboxFolders: [],
106
+ onFolderCreated: () => undefined,
107
+ noteFolderUids: () => undefined,
108
+ live: NO_LIVE_UPDATES,
109
+ trackMessageChange: () => NO_TRACKER,
110
+ });
111
+
112
+ /** Reads the mailbox/folder a page is currently showing, as resolved by the enclosing `MailShell`. */
113
+ export function useMailShell(): MailShellContextValue {
114
+ return useContext(MailShellContext);
115
+ }
116
+
117
+ const FOLDER_LABELS: Record<string, string> = {
118
+ inbox: "Inbox",
119
+ sent_items: "Sent Items",
120
+ drafts: "Drafts",
121
+ outbox: "Outbox",
122
+ junk: "Junk Email",
123
+ archive: "Archive",
124
+ deleted_items: "Deleted Items",
125
+ };
126
+
127
+ /** The badge an "All Mailboxes" entry shows: the folders of that type, summed across every mailbox, under the same rules as a single folder's. */
128
+ function aggregateBadge(mailboxFolders: MailboxFolders[], type: AggregateFolderType, counts: Record<string, FolderCount>): FolderBadge | undefined {
129
+ const sum = mailboxFolders.reduce(
130
+ (total, mf) => {
131
+ const folder = mf.folders.find((f) => f.type === type);
132
+ const count = folder ? countOfFolder(folder, counts) : { unread: 0, total: 0 };
133
+ return { unread: total.unread + count.unread, total: total.total + count.total };
134
+ },
135
+ { unread: 0, total: 0 },
136
+ );
137
+ return badgeFor(type, sum);
138
+ }
139
+
140
+ /** A folder's badge: an accent pill with the unread count, or - for the folders that show how many they hold - plain muted text. */
141
+ function FolderBadgeChip({ badge }: { badge: FolderBadge }) {
142
+ return (
143
+ <span
144
+ className={[
145
+ "text-xs rounded-pill py-0.5 px-1.5",
146
+ badge.kind === "unread" ? "font-bold bg-primary/15 text-primary-dark" : "font-medium text-text-muted",
147
+ ].join(" ")}
148
+ >
149
+ <span aria-hidden="true">{badge.value}</span>
150
+ <span className="sr-only"> {badgeLabel(badge)}</span>
151
+ </span>
152
+ );
153
+ }
154
+
155
+ type Status = "checking" | "error" | "ready";
156
+
157
+ export { MAILBOX_LIST_LIMIT };
158
+
159
+ /**
160
+ * A separate component (not inlined into `MailShell`'s own render) so `useCompose()` resolves against
161
+ * `ComposeProvider` correctly: that provider is rendered *inside* the `AppShell` that `MailShell` itself
162
+ * returns, i.e. a descendant of `MailShell`, not an ancestor — a hook call made directly in `MailShell`'s
163
+ * own function body would see only whatever context exists *above* `MailShell`, never a provider one of
164
+ * its own descendants creates. This button, rendered as part of `AppShell`'s `children`, sits correctly
165
+ * inside that subtree.
166
+ *
167
+ * Opens with the caller's own mailbox (the shell has already listed them), so the window can start on its
168
+ * signature, draft and encryption lookups straight away instead of first asking which mailbox that is; the
169
+ * compose window's own From field is where the sender is chosen. Fetches the window's code as the pointer or
170
+ * keyboard reaches the button, so the click finds it already here.
171
+ */
172
+ function ComposeButton({ mailboxUid }: { mailboxUid?: string }) {
173
+ const { openCompose } = useCompose();
174
+ const env = useKeyEnvironment();
175
+ return (
176
+ <button
177
+ type="button"
178
+ title={withHint("Compose", SHORTCUTS.mail.create, env)}
179
+ aria-keyshortcuts={ariaKeyShortcuts(SHORTCUTS.mail.create, env)}
180
+ onClick={() => openCompose({ mailboxUid })}
181
+ onPointerEnter={prefetchComposeWindow}
182
+ onFocus={prefetchComposeWindow}
183
+ className="block text-center w-full py-2.5 px-4 rounded-sm font-semibold text-sm bg-primary text-white hover:bg-primary-dark"
184
+ >
185
+ Compose
186
+ </button>
187
+ );
188
+ }
189
+
190
+ /**
191
+ * Mail's keyboard shortcuts that don't belong to a list or a message: "New message". A component of its own for the reason `ComposeButton`
192
+ * is - `useCompose()` only resolves below `ComposeProvider`, i.e. inside the `AppShell` this shell renders - and mounted once, whatever number
193
+ * of Compose buttons (the sidebar, the folders drawer) are on screen. Opens the same window, for the same mailbox, as the button.
194
+ */
195
+ function MailShortcuts({ mailboxUid }: { mailboxUid?: string }) {
196
+ const { openCompose } = useCompose();
197
+ useShortcut(SHORTCUTS.mail.create, () => openCompose({ mailboxUid }));
198
+ return null;
199
+ }
200
+
201
+ /**
202
+ * Mail's own contextual sidebar (every accessible mailbox's own folder tree, plus a merged "All Mailboxes"
203
+ * aggregate section) + content area, rendered inside the shared `AppShell` chrome (icon rail, header,
204
+ * impersonation banner — see that component). There is no client-side router in this framework (see
205
+ * `ReactRoute`'s file-convention resolver) — the selected mailbox/folder (or aggregate pseudo-folder) live
206
+ * in the URL's `?mailboxUid=`/`?folderUid=`/`?aggregate=` query params, read once on mount (never during
207
+ * the initial render itself, matching every other query-param reader in this codebase — e.g.
208
+ * `apps/admin/quarantine`'s `readMailboxUid()` — so the server-rendered and just-hydrated client markup
209
+ * match).
210
+ *
211
+ * Every accessible mailbox's folder tree renders at once - there is no "switch mailbox" affordance
212
+ * anymore (the mailbox `<select>` this shell used to have is gone) - so a single-mailbox user sees zero
213
+ * behavior change from before this, and a multi-mailbox user sees every mailbox's folders (and the new
214
+ * aggregate section) simultaneously, matching the shared-mailbox feature's own "display as a separate set
215
+ * of folders" requirement.
216
+ */
217
+ export default function MailShell({
218
+ userUid,
219
+ authServerUrl,
220
+ impersonating,
221
+ impersonationBaseUrl,
222
+ trusted,
223
+ trustedRoles,
224
+ pluginNav,
225
+ children,
226
+ }: PropsWithChildren<MailShellProps>) {
227
+ // The mailboxes, their folders and the live connection come from the persistent app frame when there is one (`AppChrome` owns them, so
228
+ // they survive Mail -> Calendar -> Mail and the push socket, pop-ups, counters and tab title work in every app). A page rendered
229
+ // outside the frame - a test, a plugin page - has no frame to ask, so this shell runs the same hook for itself, and renders the pop-ups.
230
+ const navigate = useNavigate();
231
+ const hosted = useContext(MailConnectionContext);
232
+ const own = useMailConnection({ userUid, enabled: !hosted, open: navigate });
233
+ const { status, error, mailboxes, mailboxFolders, foldersLoading, onFolderCreated, noteFolderUids, live, folderCounts, outbox: outboxStatuses } = hosted ?? own;
234
+ // The messages this tab is still handing to the server: the Outbox pill counts them at once.
235
+ const pendingSends = usePendingSends();
236
+ const [requestedMailboxUid, setRequestedMailboxUid] = useState<string | null>(null);
237
+ const [requestedFolderUid, setRequestedFolderUid] = useState<string | null>(null);
238
+ const [requestedAggregateType, setRequestedAggregateType] = useState<string | null>(null);
239
+ const [drawerOpen, setDrawerOpen] = useState(false);
240
+
241
+ // The selection lives in the URL, and the router (`AppRouter`) changes the URL without a page load when a folder link is
242
+ // clicked - so it is read from the router's location, which updates, rather than once from `window.location`. Still read
243
+ // in an effect, never during the first render, so the server render and the hydrating render agree.
244
+ const search = useLocationSearch();
245
+ useEffect(() => {
246
+ const params = new URLSearchParams(search);
247
+ setRequestedMailboxUid(params.get("mailboxUid"));
248
+ setRequestedFolderUid(params.get("folderUid"));
249
+ setRequestedAggregateType(params.get("aggregate"));
250
+ }, [search]);
251
+ // Choosing a folder (or mailbox) changes the URL without a page load now, so the drawer that held the choice - which used to go
252
+ // with the page - is closed here.
253
+ useEffect(() => {
254
+ setDrawerOpen(false);
255
+ }, [search]);
256
+
257
+ const aggregateFolderType: AggregateFolderType | undefined = isAggregateFolderType(requestedAggregateType)
258
+ ? requestedAggregateType
259
+ : undefined;
260
+
261
+ const mailboxUid: string | undefined = aggregateFolderType
262
+ ? undefined
263
+ : (requestedMailboxUid && mailboxes.some((mb) => mb.uid === requestedMailboxUid) ? requestedMailboxUid : undefined) ??
264
+ mailboxes[0]?.uid;
265
+
266
+ const selectedMailboxFolders = mailboxFolders.find((mf) => mf.mailbox.uid === mailboxUid)?.folders ?? [];
267
+ const folderUid: string | undefined = aggregateFolderType
268
+ ? undefined
269
+ : (requestedFolderUid && selectedMailboxFolders.some((f) => f.uid === requestedFolderUid) ? requestedFolderUid : undefined) ??
270
+ selectedMailboxFolders.find((f) => f.type === "inbox")?.uid;
271
+
272
+ // The mailbox `KeyEnrollmentGate`/`LocalIndexLifecycle`/`ComposeButton` treat as "the" mailbox when
273
+ // there's no single selected one to use (aggregate mode) - the caller's own owned mailbox if they
274
+ // have one, else whichever accessible mailbox happens to be first. See MailShell's own doc comment on
275
+ // this being an accepted limitation: an aggregate-view message from a *different*, not-yet-visited
276
+ // mailbox may still need that mailbox's own folder view opened directly to unlock/decrypt it.
277
+ const defaultMailboxUid = mailboxes.find((mb) => mb.ownerUserUid === userUid)?.uid ?? mailboxes[0]?.uid;
278
+ const activeMailboxUid = mailboxUid ?? defaultMailboxUid;
279
+
280
+ const counts = folderCounts.counts;
281
+ const trackMessageChange = folderCounts.track;
282
+ // `(3) Acme: Mail` in the tab strip while there is unread mail in an Inbox - kept by the frame when there is one.
283
+ useUnreadTitle(inboxUnreadTotal(mailboxFolders, counts), { enabled: !hosted });
284
+
285
+ const contextValue = useMemo<MailShellContextValue>(
286
+ () => ({ mailboxUid, folderUid, aggregateFolderType, mailboxes, mailboxFolders, onFolderCreated, noteFolderUids, live, trackMessageChange }),
287
+ [mailboxUid, folderUid, aggregateFolderType, mailboxes, mailboxFolders, onFolderCreated, noteFolderUids, live, trackMessageChange],
288
+ );
289
+
290
+ // A full-screen takeover, not nested inside the rest of the app's chrome — there's nothing else for a
291
+ // mailbox-less caller to do here yet, so the icon rail/header/folder tree don't render at all. Checks
292
+ // `mailboxes.length` directly (not `!mailboxUid`) since `mailboxUid` is legitimately undefined in
293
+ // aggregate mode even with mailboxes present.
294
+ if (userUid && status === "ready" && mailboxes.length === 0) {
295
+ return <MailboxProvisioning />;
296
+ }
297
+
298
+ let inner: ReactNode = null;
299
+ if (userUid && status === "checking") {
300
+ // Renders immediately (no network round trip needed) so switching into Mail never shows a blank
301
+ // pane while `listMailboxes()` is in flight — the outline below mirrors the real sidebar's shape.
302
+ inner = (
303
+ <aside className="w-64 shrink-0 bg-surface border-r border-border flex flex-col p-3 gap-4">
304
+ <Skeleton height="h-9" className="rounded-sm" />
305
+ <SkeletonList count={6} />
306
+ </aside>
307
+ );
308
+ } else if (userUid && status === "error") {
309
+ inner = (
310
+ <div className="flex-1 flex items-center justify-center p-8">
311
+ <div className="w-full max-w-md">
312
+ <Alert>{error}</Alert>
313
+ </div>
314
+ </div>
315
+ );
316
+ } else if (userUid && status === "ready") {
317
+ // A function, not a plain JSX constant — it's rendered twice (desktop `<aside>` + mobile
318
+ // `Drawer`), possibly *simultaneously* mounted (the aside is only CSS-hidden below `md`, not
319
+ // unmounted).
320
+ const sidebarContent = () => (
321
+ <>
322
+ <div className="p-3">
323
+ <ComposeButton mailboxUid={defaultMailboxUid} />
324
+ </div>
325
+ {foldersLoading ? (
326
+ <div className="flex-1 overflow-y-auto px-3 pb-3">
327
+ <SkeletonList count={6} className="pt-1" />
328
+ </div>
329
+ ) : (
330
+ <nav className="flex-1 overflow-y-auto px-3 pb-3 flex flex-col gap-3">
331
+ {mailboxes.length > 1 && (
332
+ <div>
333
+ <div className="text-xs font-bold uppercase tracking-wide text-text-muted mb-1 px-2.5">
334
+ All Mailboxes
335
+ </div>
336
+ <div className="flex flex-col gap-0.5">
337
+ {AGGREGATE_FOLDER_TYPES.map((type) => {
338
+ const badge = aggregateBadge(mailboxFolders, type, counts);
339
+ return (
340
+ <a
341
+ key={type}
342
+ href={`/?aggregate=${encodeURIComponent(type)}`}
343
+ className={[
344
+ "flex items-center justify-between text-sm rounded-sm py-1.5 px-2.5",
345
+ aggregateFolderType === type
346
+ ? "bg-primary/10 text-primary-dark font-semibold"
347
+ : "text-text hover:bg-surface-alt",
348
+ ].join(" ")}
349
+ >
350
+ <span className={badge?.kind === "unread" ? "font-semibold" : undefined}>{FOLDER_LABELS[type]}</span>
351
+ {badge && <FolderBadgeChip badge={badge} />}
352
+ </a>
353
+ );
354
+ })}
355
+ </div>
356
+ </div>
357
+ )}
358
+ {mailboxFolders.map(({ mailbox, folders, error: mailboxError }) => (
359
+ <div key={mailbox.uid}>
360
+ <div className="text-xs font-bold uppercase tracking-wide text-text-muted mb-1 px-2.5 truncate">
361
+ {mailbox.displayName}
362
+ {mailbox.ownerUserUid ? "" : " (shared)"}
363
+ </div>
364
+ {mailboxError && (
365
+ <div className="px-2.5 pb-1">
366
+ <Alert>{mailboxError}</Alert>
367
+ </div>
368
+ )}
369
+ <div className="flex flex-col gap-0.5">
370
+ {folderRows(folders, pendingCountFor(mailbox.uid, pendingSends)).map((row) => {
371
+ if (row.kind === "placeholder") {
372
+ // A folder the server has not made (or told us about) yet - the Outbox and Sent Items are made with the first message
373
+ // sent - shown the moment a message is on its way. Nothing to open; the real folder replaces it when it arrives.
374
+ const sending = pendingCountFor(mailbox.uid, pendingSends);
375
+ return (
376
+ <div
377
+ key={`placeholder-${row.type}`}
378
+ data-folder-placeholder={row.type}
379
+ className="flex items-center justify-between text-sm rounded-sm py-1.5 px-2.5 text-text-muted"
380
+ >
381
+ <span>{FOLDER_LABELS[row.type]}</span>
382
+ {row.type === "outbox" && <OutboxBadge total={sending} pendingHere={sending} />}
383
+ </div>
384
+ );
385
+ }
386
+ const folder = row.folder;
387
+ const badge = badgeFor(folder.type, countOfFolder(folder, counts));
388
+ return (
389
+ <a
390
+ key={folder.uid}
391
+ href={`/?mailboxUid=${encodeURIComponent(mailbox.uid)}&folderUid=${encodeURIComponent(folder.uid)}`}
392
+ className={[
393
+ "flex items-center justify-between text-sm rounded-sm py-1.5 px-2.5",
394
+ folder.uid === folderUid
395
+ ? "bg-primary/10 text-primary-dark font-semibold"
396
+ : "text-text hover:bg-surface-alt",
397
+ ].join(" ")}
398
+ >
399
+ <span className={badge?.kind === "unread" ? "font-semibold" : undefined}>
400
+ {FOLDER_LABELS[folder.type] ?? folder.name}
401
+ </span>
402
+ {badge &&
403
+ (folder.type === "outbox" ? (
404
+ <OutboxBadge
405
+ total={badge.value}
406
+ status={outboxStatuses[folder.uid]}
407
+ pendingHere={pendingCountFor(mailbox.uid, pendingSends)}
408
+ />
409
+ ) : (
410
+ <FolderBadgeChip badge={badge} />
411
+ ))}
412
+ </a>
413
+ );
414
+ })}
415
+ </div>
416
+ </div>
417
+ ))}
418
+ </nav>
419
+ )}
420
+ </>
421
+ );
422
+
423
+ inner = (
424
+ <>
425
+ <MailShortcuts mailboxUid={defaultMailboxUid} />
426
+ <aside className="hidden md:flex w-64 shrink-0 bg-surface border-r border-border flex-col">{sidebarContent()}</aside>
427
+ <Drawer open={drawerOpen} onClose={() => setDrawerOpen(false)} title="Folders">
428
+ <div className="flex flex-col">{sidebarContent()}</div>
429
+ </Drawer>
430
+ <main className="flex-1 min-w-0 overflow-y-auto">
431
+ <button
432
+ type="button"
433
+ className="md:hidden m-3 w-9 h-9 flex items-center justify-center rounded-sm text-text-muted hover:bg-surface-alt hover:text-text"
434
+ aria-label="Open folders"
435
+ onClick={() => setDrawerOpen(true)}
436
+ >
437
+ <HiOutlineBars3 size={20} aria-hidden="true" />
438
+ </button>
439
+ <MailShellContext.Provider value={contextValue}>{children}</MailShellContext.Provider>
440
+ </main>
441
+ </>
442
+ );
443
+ }
444
+
445
+ // Wraps AppShell unconditionally, at a stable tree position regardless of whether mailboxUid has
446
+ // resolved yet - KeyEnrollmentGate itself passes `children` through untouched until a real
447
+ // mailboxUid is supplied (see its own doc comment). Wrapping only once ready (a conditional tree
448
+ // position) would make AppShell itself remount the moment mailboxUid resolves, tearing down
449
+ // whatever state/effects it had already started (confirmed by direct reproduction: the
450
+ // impersonation banner's own internal state was lost exactly at that transition).
451
+ const activeMailbox = mailboxes.find((mb) => mb.uid === activeMailboxUid);
452
+ return (
453
+ <KeyEnrollmentGate
454
+ mailboxUid={activeMailboxUid}
455
+ mailboxAddress={activeMailbox?.primarySmtpAddress}
456
+ mailboxKeys={activeMailbox?.keys}
457
+ // Unlocking is only actually required to sign/encrypt a compose, read an already-encrypted
458
+ // message, or change encryption settings - not merely to open Mail. Those specific call sites
459
+ // (ComposeWindow, MessageDetailPane) request an unlock on demand via useUnlockPrompt() instead.
460
+ // First-time provisioning (a mailbox with no vault at all yet) still always blocks - see this
461
+ // prop's own doc comment on KeyEnrollmentGateProps.
462
+ blocking={false}
463
+ // A shared/delegated mailbox the caller doesn't own is never provisioned from here - its keys
464
+ // belong to its owner (or its admins), not to whoever happens to open it first - and neither is
465
+ // the impersonated user's own mailbox: an administrator must never choose its password/recovery codes.
466
+ canProvision={!impersonating && activeMailbox?.ownerUserUid === userUid}
467
+ >
468
+ <LocalIndexLifecycle
469
+ mailboxUid={activeMailboxUid}
470
+ mailboxKeys={activeMailbox?.keys}
471
+ folders={mailboxFolders.find((mf) => mf.mailbox.uid === activeMailboxUid)?.folders ?? []}
472
+ // A full page may be truncated - pruning against it would delete indexes of accessible mailboxes
473
+ // beyond the limit, so it's only trusted as the complete list when it came back short.
474
+ accessibleMailboxUids={status === "ready" && mailboxes.length < MAILBOX_LIST_LIMIT ? mailboxes.map((mb) => mb.uid) : undefined}
475
+ />
476
+ <AppShell
477
+ active="mail"
478
+ userUid={userUid}
479
+ authServerUrl={authServerUrl}
480
+ impersonating={impersonating}
481
+ impersonationBaseUrl={impersonationBaseUrl}
482
+ trusted={trusted}
483
+ trustedRoles={trustedRoles}
484
+ pluginNav={pluginNav}
485
+ >
486
+ {inner}
487
+ </AppShell>
488
+ </KeyEnrollmentGate>
489
+ );
490
+ }