@rapidmx/web-client 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +183 -2
- package/apps/admin/_layout.tsx +8 -2
- package/apps/admin/index.tsx +7 -1
- package/apps/admin/ingest-queue/index.tsx +2 -1
- package/apps/admin/mailboxes/[uid].tsx +23 -10
- package/apps/admin/mailboxes/new/index.tsx +3 -3
- package/apps/admin/quarantine/index.tsx +2 -1
- package/apps/admin/signing-certificates/index.tsx +343 -0
- package/apps/escrow/_layout.tsx +8 -2
- package/apps/shared/appearance/AppearanceForm.tsx +392 -0
- package/apps/shared/appearance/AppearanceHead.tsx +49 -0
- package/apps/shared/appearance/AppearanceProvider.tsx +470 -0
- package/apps/shared/appearance/ColorField.tsx +107 -0
- package/apps/shared/appearance/appearanceCache.ts +106 -0
- package/apps/shared/appearance/appearanceContext.ts +77 -0
- package/apps/shared/appearance/bootScript.ts +35 -0
- package/apps/shared/appearance/color.ts +169 -0
- package/apps/shared/appearance/photo.ts +88 -0
- package/apps/shared/appearance/resolvedTheme.ts +67 -0
- package/apps/shared/appearance/theme.ts +355 -0
- package/apps/shared/components/admin/escrowScopes/EscrowScopeKeyAndHoldersFields.tsx +4 -4
- package/apps/shared/components/admin/layout/AdminShell.tsx +22 -10
- package/apps/shared/components/admin/mailboxes/ShareAccessCard.tsx +107 -60
- package/apps/shared/components/admin/settings/BrandingForm.tsx +24 -0
- package/apps/shared/components/admin/settings/DomainDnsSetup.tsx +60 -14
- package/apps/shared/components/admin/settings/MailboxCreateForm.tsx +65 -16
- package/apps/shared/components/admin/settings/PluginsManager.tsx +228 -25
- package/apps/shared/components/admin/setup/SetupWizard.tsx +2 -1
- package/apps/shared/components/calendar/CalendarListSidebar.tsx +4 -5
- package/apps/shared/components/contacts/ContactForm.tsx +11 -5
- package/apps/shared/components/contacts/ContactsSidebar.tsx +5 -3
- package/apps/shared/components/contacts/ContactsToolbar.tsx +25 -52
- package/apps/shared/components/contacts/layout/ContactsShell.tsx +10 -5
- package/apps/shared/components/escrow/layout/EscrowShell.tsx +13 -6
- package/apps/shared/components/layout/AppShell.tsx +98 -32
- package/apps/shared/components/layout/BrandingChrome.tsx +200 -13
- package/apps/shared/components/layout/RailIcon.tsx +100 -0
- package/apps/shared/components/layout/ResponsiveToolbar.tsx +315 -0
- package/apps/shared/components/layout/ThemeSwitch.tsx +84 -0
- package/apps/shared/components/layout/UserMenu.tsx +75 -6
- package/apps/shared/components/mail/ConversationList.tsx +4 -2
- package/apps/shared/components/mail/ConversationThreadPane.tsx +487 -475
- package/apps/shared/components/mail/LazyReadingPane.tsx +14 -16
- package/apps/shared/components/mail/MailSelectionBar.tsx +2 -10
- package/apps/shared/components/mail/MessageDetailPane.tsx +366 -287
- package/apps/shared/components/mail/OutboxBadge.tsx +44 -0
- package/apps/shared/components/mail/OutboxRowStatus.tsx +31 -0
- package/apps/shared/components/mail/compose/ComposeContext.tsx +35 -2
- package/apps/shared/components/mail/compose/ComposeWindow.tsx +239 -437
- package/apps/shared/components/mail/compose/encryptionRequirement.ts +86 -0
- package/apps/shared/components/mail/layout/MailShell.tsx +39 -25
- package/apps/shared/components/mail/reading/EncryptedBody.tsx +65 -0
- package/apps/shared/components/mail/reading/EncryptedPreview.tsx +35 -0
- package/apps/shared/components/mail/reading/MessageBody.tsx +240 -0
- package/apps/shared/components/mail/reading/MessageCard.tsx +174 -0
- package/apps/shared/components/mail/reading/bodyContent.ts +100 -0
- package/apps/shared/components/mail/reading/bodyHtml.ts +298 -0
- package/apps/shared/components/mail/reading/color.ts +245 -0
- package/apps/shared/components/mail/reading/frameControl.ts +142 -0
- package/apps/shared/components/mail/reading/frameDocument.ts +123 -0
- package/apps/shared/components/mail/reading/safeDocument.ts +24 -0
- package/apps/shared/components/mail/reading/themeAdaptation.ts +221 -0
- package/apps/shared/components/mail/reading/themeSurface.ts +90 -0
- package/apps/shared/components/mail/reading/viewOriginal.ts +38 -0
- package/apps/shared/components/settings/SigningCertificateCard.tsx +344 -0
- package/apps/shared/components/settings/layout/SettingsShell.tsx +1 -0
- package/apps/shared/components/sharing/PrincipalListField.tsx +82 -0
- package/apps/shared/components/sharing/PrincipalPicker.tsx +76 -0
- package/apps/shared/components/sharing/PrincipalResolver.tsx +164 -0
- package/apps/shared/components/tasks/TasksSidebar.tsx +5 -3
- package/apps/shared/components/tasks/layout/TasksShell.tsx +9 -5
- package/apps/shared/mail/folderCounts.ts +9 -3
- package/apps/shared/mail/folderTree.ts +143 -0
- package/apps/shared/mail/outbox/UnlockBridge.tsx +23 -0
- package/apps/shared/mail/outbox/composeBridge.ts +69 -0
- package/apps/shared/mail/outbox/outboxState.ts +88 -0
- package/apps/shared/mail/outbox/pendingSends.ts +146 -0
- package/apps/shared/mail/outbox/sendDecision.ts +157 -0
- package/apps/shared/mail/outbox/sendJob.ts +427 -0
- package/apps/shared/mail/outbox/sendOutcomes.ts +146 -0
- package/apps/shared/mail/outbox/sendState.ts +35 -0
- package/apps/shared/mail/outbox/useOutboxStatus.ts +61 -0
- package/apps/shared/mail/useMailConnection.ts +81 -28
- package/apps/shared/mail/useMailLiveUpdates.ts +55 -10
- package/apps/shared/mail/useNewMailNotifications.ts +47 -32
- package/apps/shared/navigation/AppRouter.tsx +2 -2
- package/apps/shared/notifications/NotificationCenter.tsx +215 -0
- package/apps/shared/notifications/NotificationHistoryDialog.tsx +90 -0
- package/apps/shared/notifications/apiErrors.ts +98 -0
- package/apps/shared/notifications/headerOffset.ts +35 -0
- package/apps/shared/notifications/pushStatus.ts +56 -0
- package/apps/shared/notifications/store.ts +549 -0
- package/apps/shared/notifications/systemErrors.ts +63 -0
- package/apps/shared/notifications/useNotifications.ts +41 -0
- package/apps/shared/signing/enrollmentStorage.ts +33 -0
- package/apps/shared/signing/enrollmentTracker.ts +385 -0
- package/apps/shared/signing/enrollmentView.ts +251 -0
- package/apps/shared/signing/signingInfo.ts +58 -0
- package/apps/shared/signing/useNow.ts +19 -0
- package/apps/shared/signing/useSigningEnrollmentWatcher.ts +90 -0
- package/apps/shared/styles/app.css +80 -0
- package/apps/www/_layout.tsx +8 -2
- package/apps/www/_routes.ts +1 -0
- package/apps/www/calendar/index.tsx +9 -14
- package/apps/www/contacts/[uid].tsx +5 -8
- package/apps/www/contacts/index.tsx +587 -584
- package/apps/www/index.tsx +38 -27
- package/apps/www/messages/[uid].tsx +3 -1
- package/apps/www/settings/appearance/index.tsx +21 -0
- package/apps/www/settings/auto-reply/index.tsx +3 -7
- package/apps/www/settings/encryption/index.tsx +151 -116
- package/apps/www/settings/filters/[uid].tsx +3 -1
- package/apps/www/settings/filters/new/index.tsx +3 -1
- package/apps/www/settings/privacy/index.tsx +3 -8
- package/apps/www/settings/read-receipts/index.tsx +3 -7
- package/apps/www/settings/sharing/index.tsx +44 -65
- package/apps/www/settings/signatures/[uid].tsx +3 -1
- package/apps/www/settings/signatures/new/index.tsx +3 -2
- package/apps/www/tasks/index.tsx +11 -16
- package/dist/apps/admin/_layout.d.ts +5 -1
- package/dist/apps/admin/_layout.js +3 -2
- package/dist/apps/admin/index.js +3 -2
- package/dist/apps/admin/ingest-queue/index.js +2 -1
- package/dist/apps/admin/mailboxes/[uid].js +9 -6
- package/dist/apps/admin/mailboxes/new/index.js +1 -1
- package/dist/apps/admin/quarantine/index.js +2 -1
- package/dist/apps/admin/signing-certificates/index.d.ts +3 -0
- package/dist/apps/admin/signing-certificates/index.js +161 -0
- package/dist/apps/escrow/_layout.d.ts +5 -1
- package/dist/apps/escrow/_layout.js +3 -2
- package/dist/apps/shared/appearance/AppearanceForm.d.ts +7 -0
- package/dist/apps/shared/appearance/AppearanceForm.js +131 -0
- package/dist/apps/shared/appearance/AppearanceHead.d.ts +15 -0
- package/dist/apps/shared/appearance/AppearanceHead.js +31 -0
- package/dist/apps/shared/appearance/AppearanceProvider.d.ts +32 -0
- package/dist/apps/shared/appearance/AppearanceProvider.js +390 -0
- package/dist/apps/shared/appearance/ColorField.d.ts +22 -0
- package/dist/apps/shared/appearance/ColorField.js +40 -0
- package/dist/apps/shared/appearance/appearanceCache.d.ts +45 -0
- package/dist/apps/shared/appearance/appearanceCache.js +80 -0
- package/dist/apps/shared/appearance/appearanceContext.d.ts +45 -0
- package/dist/apps/shared/appearance/appearanceContext.js +29 -0
- package/dist/apps/shared/appearance/bootScript.d.ts +16 -0
- package/dist/apps/shared/appearance/bootScript.js +33 -0
- package/dist/apps/shared/appearance/color.d.ts +65 -0
- package/dist/apps/shared/appearance/color.js +132 -0
- package/dist/apps/shared/appearance/photo.d.ts +17 -0
- package/dist/apps/shared/appearance/photo.js +79 -0
- package/dist/apps/shared/appearance/resolvedTheme.d.ts +21 -0
- package/dist/apps/shared/appearance/resolvedTheme.js +55 -0
- package/dist/apps/shared/appearance/theme.d.ts +111 -0
- package/dist/apps/shared/appearance/theme.js +251 -0
- package/dist/apps/shared/components/admin/escrowScopes/EscrowScopeKeyAndHoldersFields.js +3 -2
- package/dist/apps/shared/components/admin/layout/AdminShell.d.ts +1 -1
- package/dist/apps/shared/components/admin/layout/AdminShell.js +16 -6
- package/dist/apps/shared/components/admin/mailboxes/ShareAccessCard.d.ts +10 -5
- package/dist/apps/shared/components/admin/mailboxes/ShareAccessCard.js +49 -34
- package/dist/apps/shared/components/admin/settings/BrandingForm.d.ts +2 -0
- package/dist/apps/shared/components/admin/settings/BrandingForm.js +7 -1
- package/dist/apps/shared/components/admin/settings/DomainDnsSetup.js +25 -5
- package/dist/apps/shared/components/admin/settings/MailboxCreateForm.js +18 -7
- package/dist/apps/shared/components/admin/settings/PluginsManager.js +106 -20
- package/dist/apps/shared/components/admin/setup/SetupWizard.js +2 -1
- package/dist/apps/shared/components/calendar/CalendarListSidebar.js +8 -8
- package/dist/apps/shared/components/contacts/ContactForm.js +1 -1
- package/dist/apps/shared/components/contacts/ContactsSidebar.js +4 -2
- package/dist/apps/shared/components/contacts/ContactsToolbar.d.ts +3 -1
- package/dist/apps/shared/components/contacts/ContactsToolbar.js +24 -9
- package/dist/apps/shared/components/contacts/layout/ContactsShell.js +4 -1
- package/dist/apps/shared/components/escrow/layout/EscrowShell.js +7 -4
- package/dist/apps/shared/components/layout/AppShell.d.ts +6 -1
- package/dist/apps/shared/components/layout/AppShell.js +59 -13
- package/dist/apps/shared/components/layout/BrandingChrome.d.ts +69 -10
- package/dist/apps/shared/components/layout/BrandingChrome.js +140 -12
- package/dist/apps/shared/components/layout/RailIcon.d.ts +21 -0
- package/dist/apps/shared/components/layout/RailIcon.js +85 -0
- package/dist/apps/shared/components/layout/ResponsiveToolbar.d.ts +55 -0
- package/dist/apps/shared/components/layout/ResponsiveToolbar.js +199 -0
- package/dist/apps/shared/components/layout/ThemeSwitch.d.ts +9 -0
- package/dist/apps/shared/components/layout/ThemeSwitch.js +54 -0
- package/dist/apps/shared/components/layout/UserMenu.d.ts +7 -1
- package/dist/apps/shared/components/layout/UserMenu.js +41 -7
- package/dist/apps/shared/components/mail/ConversationList.js +3 -2
- package/dist/apps/shared/components/mail/ConversationThreadPane.d.ts +2 -1
- package/dist/apps/shared/components/mail/ConversationThreadPane.js +42 -20
- package/dist/apps/shared/components/mail/LazyReadingPane.js +9 -8
- package/dist/apps/shared/components/mail/MailSelectionBar.d.ts +3 -4
- package/dist/apps/shared/components/mail/MailSelectionBar.js +2 -3
- package/dist/apps/shared/components/mail/MessageDetailPane.d.ts +18 -7
- package/dist/apps/shared/components/mail/MessageDetailPane.js +86 -41
- package/dist/apps/shared/components/mail/OutboxBadge.d.ts +17 -0
- package/dist/apps/shared/components/mail/OutboxBadge.js +18 -0
- package/dist/apps/shared/components/mail/OutboxRowStatus.d.ts +10 -0
- package/dist/apps/shared/components/mail/OutboxRowStatus.js +19 -0
- package/dist/apps/shared/components/mail/compose/ComposeContext.d.ts +8 -0
- package/dist/apps/shared/components/mail/compose/ComposeContext.js +28 -3
- package/dist/apps/shared/components/mail/compose/ComposeWindow.d.ts +2 -1
- package/dist/apps/shared/components/mail/compose/ComposeWindow.js +229 -328
- package/dist/apps/shared/components/mail/compose/encryptionRequirement.d.ts +49 -0
- package/dist/apps/shared/components/mail/compose/encryptionRequirement.js +35 -0
- package/dist/apps/shared/components/mail/layout/MailShell.d.ts +2 -0
- package/dist/apps/shared/components/mail/layout/MailShell.js +20 -14
- package/dist/apps/shared/components/mail/reading/EncryptedBody.d.ts +21 -0
- package/dist/apps/shared/components/mail/reading/EncryptedBody.js +22 -0
- package/dist/apps/shared/components/mail/reading/EncryptedPreview.d.ts +18 -0
- package/dist/apps/shared/components/mail/reading/EncryptedPreview.js +22 -0
- package/dist/apps/shared/components/mail/reading/MessageBody.d.ts +32 -0
- package/dist/apps/shared/components/mail/reading/MessageBody.js +136 -0
- package/dist/apps/shared/components/mail/reading/MessageCard.d.ts +62 -0
- package/dist/apps/shared/components/mail/reading/MessageCard.js +58 -0
- package/dist/apps/shared/components/mail/reading/bodyContent.d.ts +38 -0
- package/dist/apps/shared/components/mail/reading/bodyContent.js +84 -0
- package/dist/apps/shared/components/mail/reading/bodyHtml.d.ts +47 -0
- package/dist/apps/shared/components/mail/reading/bodyHtml.js +267 -0
- package/dist/apps/shared/components/mail/reading/color.d.ts +63 -0
- package/dist/apps/shared/components/mail/reading/color.js +201 -0
- package/dist/apps/shared/components/mail/reading/frameControl.d.ts +33 -0
- package/dist/apps/shared/components/mail/reading/frameControl.js +120 -0
- package/dist/apps/shared/components/mail/reading/frameDocument.d.ts +52 -0
- package/dist/apps/shared/components/mail/reading/frameDocument.js +98 -0
- package/dist/apps/shared/components/mail/reading/safeDocument.d.ts +3 -0
- package/dist/apps/shared/components/mail/reading/safeDocument.js +12 -0
- package/dist/apps/shared/components/mail/reading/themeAdaptation.d.ts +56 -0
- package/dist/apps/shared/components/mail/reading/themeAdaptation.js +144 -0
- package/dist/apps/shared/components/mail/reading/themeSurface.d.ts +17 -0
- package/dist/apps/shared/components/mail/reading/themeSurface.js +83 -0
- package/dist/apps/shared/components/mail/reading/viewOriginal.d.ts +9 -0
- package/dist/apps/shared/components/mail/reading/viewOriginal.js +32 -0
- package/dist/apps/shared/components/settings/SigningCertificateCard.d.ts +32 -0
- package/dist/apps/shared/components/settings/SigningCertificateCard.js +98 -0
- package/dist/apps/shared/components/settings/layout/SettingsShell.js +1 -0
- package/dist/apps/shared/components/sharing/PrincipalListField.d.ts +24 -0
- package/dist/apps/shared/components/sharing/PrincipalListField.js +23 -0
- package/dist/apps/shared/components/sharing/PrincipalPicker.d.ts +28 -0
- package/dist/apps/shared/components/sharing/PrincipalPicker.js +24 -0
- package/dist/apps/shared/components/sharing/PrincipalResolver.d.ts +44 -0
- package/dist/apps/shared/components/sharing/PrincipalResolver.js +92 -0
- package/dist/apps/shared/components/tasks/TasksSidebar.js +4 -2
- package/dist/apps/shared/components/tasks/layout/TasksShell.js +3 -1
- package/dist/apps/shared/mail/folderCounts.d.ts +1 -1
- package/dist/apps/shared/mail/folderCounts.js +9 -3
- package/dist/apps/shared/mail/folderTree.d.ts +55 -0
- package/dist/apps/shared/mail/folderTree.js +116 -0
- package/dist/apps/shared/mail/outbox/UnlockBridge.d.ts +5 -0
- package/dist/apps/shared/mail/outbox/UnlockBridge.js +18 -0
- package/dist/apps/shared/mail/outbox/composeBridge.d.ts +34 -0
- package/dist/apps/shared/mail/outbox/composeBridge.js +32 -0
- package/dist/apps/shared/mail/outbox/outboxState.d.ts +41 -0
- package/dist/apps/shared/mail/outbox/outboxState.js +42 -0
- package/dist/apps/shared/mail/outbox/pendingSends.d.ts +39 -0
- package/dist/apps/shared/mail/outbox/pendingSends.js +109 -0
- package/dist/apps/shared/mail/outbox/sendDecision.d.ts +80 -0
- package/dist/apps/shared/mail/outbox/sendDecision.js +94 -0
- package/dist/apps/shared/mail/outbox/sendJob.d.ts +68 -0
- package/dist/apps/shared/mail/outbox/sendJob.js +319 -0
- package/dist/apps/shared/mail/outbox/sendOutcomes.d.ts +3 -0
- package/dist/apps/shared/mail/outbox/sendOutcomes.js +141 -0
- package/dist/apps/shared/mail/outbox/sendState.d.ts +25 -0
- package/dist/apps/shared/mail/outbox/sendState.js +8 -0
- package/dist/apps/shared/mail/outbox/useOutboxStatus.d.ts +11 -0
- package/dist/apps/shared/mail/outbox/useOutboxStatus.js +49 -0
- package/dist/apps/shared/mail/useMailConnection.d.ts +9 -8
- package/dist/apps/shared/mail/useMailConnection.js +64 -22
- package/dist/apps/shared/mail/useMailLiveUpdates.d.ts +17 -4
- package/dist/apps/shared/mail/useMailLiveUpdates.js +36 -10
- package/dist/apps/shared/mail/useNewMailNotifications.d.ts +4 -10
- package/dist/apps/shared/mail/useNewMailNotifications.js +43 -23
- package/dist/apps/shared/navigation/AppRouter.js +2 -2
- package/dist/apps/shared/notifications/NotificationCenter.d.ts +19 -0
- package/dist/apps/shared/notifications/NotificationCenter.js +90 -0
- package/dist/apps/shared/notifications/NotificationHistoryDialog.d.ts +10 -0
- package/dist/apps/shared/notifications/NotificationHistoryDialog.js +36 -0
- package/dist/apps/shared/notifications/apiErrors.d.ts +19 -0
- package/dist/apps/shared/notifications/apiErrors.js +86 -0
- package/dist/apps/shared/notifications/headerOffset.d.ts +8 -0
- package/dist/apps/shared/notifications/headerOffset.js +33 -0
- package/dist/apps/shared/notifications/pushStatus.d.ts +9 -0
- package/dist/apps/shared/notifications/pushStatus.js +54 -0
- package/dist/apps/shared/notifications/store.d.ts +136 -0
- package/dist/apps/shared/notifications/store.js +416 -0
- package/dist/apps/shared/notifications/systemErrors.d.ts +9 -0
- package/dist/apps/shared/notifications/systemErrors.js +58 -0
- package/dist/apps/shared/notifications/useNotifications.d.ts +17 -0
- package/dist/apps/shared/notifications/useNotifications.js +18 -0
- package/dist/apps/shared/signing/enrollmentStorage.d.ts +10 -0
- package/dist/apps/shared/signing/enrollmentStorage.js +33 -0
- package/dist/apps/shared/signing/enrollmentTracker.d.ts +73 -0
- package/dist/apps/shared/signing/enrollmentTracker.js +307 -0
- package/dist/apps/shared/signing/enrollmentView.d.ts +57 -0
- package/dist/apps/shared/signing/enrollmentView.js +214 -0
- package/dist/apps/shared/signing/signingInfo.d.ts +11 -0
- package/dist/apps/shared/signing/signingInfo.js +48 -0
- package/dist/apps/shared/signing/useNow.d.ts +2 -0
- package/dist/apps/shared/signing/useNow.js +18 -0
- package/dist/apps/shared/signing/useSigningEnrollmentWatcher.d.ts +16 -0
- package/dist/apps/shared/signing/useSigningEnrollmentWatcher.js +87 -0
- package/dist/apps/shared/styles/app.css +80 -0
- package/dist/apps/www/_layout.d.ts +5 -1
- package/dist/apps/www/_layout.js +3 -2
- package/dist/apps/www/_routes.js +1 -0
- package/dist/apps/www/calendar/index.js +3 -4
- package/dist/apps/www/contacts/[uid].js +5 -7
- package/dist/apps/www/contacts/index.js +14 -21
- package/dist/apps/www/index.js +37 -19
- package/dist/apps/www/messages/[uid].js +3 -1
- package/dist/apps/www/settings/appearance/index.d.ts +4 -0
- package/dist/apps/www/settings/appearance/index.js +13 -0
- package/dist/apps/www/settings/auto-reply/index.js +3 -6
- package/dist/apps/www/settings/encryption/index.js +103 -95
- package/dist/apps/www/settings/filters/[uid].js +3 -1
- package/dist/apps/www/settings/filters/new/index.js +3 -1
- package/dist/apps/www/settings/privacy/index.js +5 -8
- package/dist/apps/www/settings/read-receipts/index.js +3 -6
- package/dist/apps/www/settings/sharing/index.js +19 -33
- package/dist/apps/www/settings/signatures/[uid].js +3 -1
- package/dist/apps/www/settings/signatures/new/index.js +3 -2
- package/dist/apps/www/tasks/index.js +8 -14
- package/package.json +2 -2
- package/apps/shared/components/mail/NewMailToasts.tsx +0 -141
- package/apps/shared/components/mail/compose/SendFailureAlert.tsx +0 -48
- package/dist/apps/shared/components/mail/NewMailToasts.d.ts +0 -19
- package/dist/apps/shared/components/mail/NewMailToasts.js +0 -55
- package/dist/apps/shared/components/mail/compose/SendFailureAlert.d.ts +0 -14
- package/dist/apps/shared/components/mail/compose/SendFailureAlert.js +0 -11
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
|
|
6
|
+
import {
|
|
7
|
+
Attachment,
|
|
8
|
+
ComposeRecipientInput,
|
|
9
|
+
Mailbox,
|
|
10
|
+
Message,
|
|
11
|
+
assembleDraft,
|
|
12
|
+
assembleDraftRaw,
|
|
13
|
+
getMailbox,
|
|
14
|
+
getMessage,
|
|
15
|
+
queueMessageSend,
|
|
16
|
+
sendMessage,
|
|
17
|
+
setMessageRequestReceipt,
|
|
18
|
+
} from "@rapidmx/react-shared/mail/mailApi.js";
|
|
19
|
+
import { describeSendFailure } from "@rapidmx/react-shared/mail/sendFailure.js";
|
|
20
|
+
import { RecipientEncryptionStatus, resolveRecipientEncryption } from "@rapidmx/react-shared/crypto/composeSecurity.js";
|
|
21
|
+
import { getUnlockedKeys } from "@rapidmx/react-shared/crypto/keySession.js";
|
|
22
|
+
import { EncryptionPolicy, findActivePublicKey, getEncryptionPolicy, lookupKeys } from "@rapidmx/react-shared/crypto/keyvaultApi.js";
|
|
23
|
+
import { fromBase64 } from "@rapidmx/react-shared/crypto/encoding.js";
|
|
24
|
+
import type { ProtectedHeaders } from "@rapidmx/react-shared/crypto/smimeMessage.js";
|
|
25
|
+
import { policyCanAutoEncrypt } from "../../components/mail/compose/encryptionRequirement.js";
|
|
26
|
+
import { NotificationAction, dismiss, notify } from "../../notifications/store.js";
|
|
27
|
+
import { INLINE_IMAGE_PATTERN, SendBlock, SendDecisionInput, decideSend } from "./sendDecision.js";
|
|
28
|
+
import { beginPendingSend, finishPendingSend, setPendingStage } from "./pendingSends.js";
|
|
29
|
+
import { openComposeFromOutside, requestUnlockFromOutside } from "./composeBridge.js";
|
|
30
|
+
import { OutboxCountTracker, sendState } from "./sendState.js";
|
|
31
|
+
|
|
32
|
+
/** Everything the background send needs, captured when Send is clicked: the window it came from is gone by the time it runs. */
|
|
33
|
+
export interface SendRequest {
|
|
34
|
+
/** The window's server draft. */
|
|
35
|
+
draft: Message;
|
|
36
|
+
mailboxUid: string;
|
|
37
|
+
/** The sender's mailbox as the window had loaded it - `undefined` when that load had not succeeded (the send then tries again itself). */
|
|
38
|
+
mailbox: Mailbox | undefined;
|
|
39
|
+
/** The encryption policy as the window had loaded it, `undefined` likewise. */
|
|
40
|
+
policy: EncryptionPolicy | undefined;
|
|
41
|
+
/** The window's To/Cc/Bcc field text, kept so "Open draft" restores them exactly. */
|
|
42
|
+
toText: string;
|
|
43
|
+
ccText: string;
|
|
44
|
+
bccText: string;
|
|
45
|
+
to: ComposeRecipientInput[];
|
|
46
|
+
cc: ComposeRecipientInput[];
|
|
47
|
+
bcc: ComposeRecipientInput[];
|
|
48
|
+
subject: string;
|
|
49
|
+
html: string;
|
|
50
|
+
attachments: Attachment[];
|
|
51
|
+
requestReceipt: boolean;
|
|
52
|
+
/** Send later: an ISO time in the future. Absent for an immediate send. */
|
|
53
|
+
scheduledSendTime?: string;
|
|
54
|
+
signEnabled: boolean;
|
|
55
|
+
/** The sign / encrypt options were shown to the sender at some point this compose session (their keys were unlocked). */
|
|
56
|
+
offeredSign: boolean;
|
|
57
|
+
offeredEncrypt: boolean;
|
|
58
|
+
encryptRequested: boolean;
|
|
59
|
+
/** The sender's explicit choice to send without encryption/signing checks (an override). */
|
|
60
|
+
forcePlaintext: boolean;
|
|
61
|
+
/** Settles when the window's own autosaves have landed, so none can overwrite the assembly below. */
|
|
62
|
+
saved?: Promise<unknown>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** How long a background send waits for the mailbox / encryption policy it did not have, before it goes ahead treating them as unknown. Nobody waits for it. */
|
|
66
|
+
export const CONTEXT_GRACE_MS = 4_000;
|
|
67
|
+
|
|
68
|
+
export function registerOutboxCounter(tracker: (mailboxUid: string) => OutboxCountTracker, onQueued: (mailboxUid: string) => void): () => void {
|
|
69
|
+
sendState.countTracker = tracker;
|
|
70
|
+
sendState.queuedListener = onQueued;
|
|
71
|
+
return () => {
|
|
72
|
+
if (sendState.countTracker === tracker) {
|
|
73
|
+
sendState.countTracker = undefined;
|
|
74
|
+
sendState.queuedListener = undefined;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const RETAINED_LIMIT = 25;
|
|
80
|
+
|
|
81
|
+
/** The request a message was queued from, while this tab still holds it: what lets "Open draft" and "Retry" work on a failure the server reports later. */
|
|
82
|
+
export function retainedRequest(draftUid: string): SendRequest | undefined {
|
|
83
|
+
return sendState.retained.get(draftUid);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function forgetRetainedRequest(draftUid: string): void {
|
|
87
|
+
sendState.retained.delete(draftUid);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function retain(request: SendRequest): void {
|
|
91
|
+
sendState.retained.delete(request.draft.uid);
|
|
92
|
+
sendState.retained.set(request.draft.uid, request);
|
|
93
|
+
if (sendState.retained.size > RETAINED_LIMIT) {
|
|
94
|
+
sendState.retained.delete(sendState.retained.keys().next().value!);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const UNSAFE_DISPLAY_NAME_PATTERN = /[@@﹫\r\n]/;
|
|
99
|
+
|
|
100
|
+
/** The sender's signing/encryption key state right now, read from the tab's key session (they can lock mid-send). */
|
|
101
|
+
export function readSendKeys(mailboxUid: string, signEnabled: boolean, mailbox: Mailbox | undefined) {
|
|
102
|
+
const stored = getUnlockedKeys(mailboxUid);
|
|
103
|
+
const unlocked = stored?.destroyed ? undefined : stored;
|
|
104
|
+
return {
|
|
105
|
+
unlocked,
|
|
106
|
+
canSign: signEnabled && !!mailbox && !!unlocked?.signingPrivateKey && !!unlocked.signingCertDer,
|
|
107
|
+
canEncryptSelf: !!unlocked?.encryptionPrivateKey && !!unlocked.encryptionCertDer,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Whether this sender could encrypt at all: an encryption key unlocked here, enrolled on the mailbox, or offered earlier this session. */
|
|
112
|
+
export function senderHasEncryptionKey(request: Pick<SendRequest, "mailbox" | "offeredEncrypt">, canEncryptSelf: boolean): boolean {
|
|
113
|
+
return canEncryptSelf || request.offeredEncrypt || !!findActivePublicKey(request.mailbox?.keys ?? [], "encrypt");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The input `decideSend()` reads, from a request and what has been looked up. */
|
|
117
|
+
export function sendDecisionInput(
|
|
118
|
+
request: SendRequest,
|
|
119
|
+
mailbox: Mailbox | undefined,
|
|
120
|
+
policy: EncryptionPolicy | undefined,
|
|
121
|
+
recipients: (RecipientEncryptionStatus | undefined)[],
|
|
122
|
+
lookupsComplete: boolean,
|
|
123
|
+
): SendDecisionInput {
|
|
124
|
+
const keys = readSendKeys(request.mailboxUid, request.signEnabled, mailbox);
|
|
125
|
+
return {
|
|
126
|
+
forcePlaintext: request.forcePlaintext,
|
|
127
|
+
signEnabled: request.signEnabled,
|
|
128
|
+
offeredSign: request.offeredSign,
|
|
129
|
+
encryptRequested: request.encryptRequested,
|
|
130
|
+
policy,
|
|
131
|
+
mailboxLoaded: !!mailbox,
|
|
132
|
+
hasEncryptionKey: senderHasEncryptionKey({ mailbox, offeredEncrypt: request.offeredEncrypt }, keys.canEncryptSelf),
|
|
133
|
+
keys: { canSign: keys.canSign, canEncryptSelf: keys.canEncryptSelf, unlocked: !!keys.unlocked },
|
|
134
|
+
recipients,
|
|
135
|
+
lookupsComplete,
|
|
136
|
+
hasBcc: request.bcc.length > 0,
|
|
137
|
+
hasAttachments: request.attachments.length > 0,
|
|
138
|
+
hasInlineImages: INLINE_IMAGE_PATTERN.test(request.html),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** A send that did not go: the plain reason, the technical lines, and - for a refusal the sender can override - which. */
|
|
143
|
+
interface Failure {
|
|
144
|
+
message: string;
|
|
145
|
+
details: string[];
|
|
146
|
+
block?: SendBlock;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
type Outcome = { kind: "queued" | "sent" | "scheduled" } | { kind: "failed"; failure: Failure };
|
|
150
|
+
|
|
151
|
+
const OPEN_POLICY: EncryptionPolicy = { encryptSameOrg: "optional", encryptFederated: "optional", encryptExternal: "optional" };
|
|
152
|
+
|
|
153
|
+
/** The mailbox and policy this send is missing, loaded now: the sender is not waiting, so a slow answer costs nothing - but it is not waited on for ever. */
|
|
154
|
+
async function completeContext(request: SendRequest): Promise<{ mailbox: Mailbox | undefined; policy: EncryptionPolicy | undefined }> {
|
|
155
|
+
let mailbox = request.mailbox;
|
|
156
|
+
let policy = request.policy;
|
|
157
|
+
const keysNow = readSendKeys(request.mailboxUid, request.signEnabled, mailbox);
|
|
158
|
+
const loads: Promise<unknown>[] = [];
|
|
159
|
+
if (!mailbox) {
|
|
160
|
+
loads.push(getMailbox(request.mailboxUid).then((loaded) => void (mailbox = loaded)));
|
|
161
|
+
}
|
|
162
|
+
if (!policy && (!mailbox || senderHasEncryptionKey({ mailbox, offeredEncrypt: request.offeredEncrypt }, keysNow.canEncryptSelf))) {
|
|
163
|
+
loads.push(getEncryptionPolicy().then((loaded) => void (policy = loaded)));
|
|
164
|
+
}
|
|
165
|
+
if (loads.length > 0) {
|
|
166
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
167
|
+
const grace = new Promise<void>((resolve) => {
|
|
168
|
+
timer = setTimeout(resolve, CONTEXT_GRACE_MS);
|
|
169
|
+
});
|
|
170
|
+
await Promise.race([Promise.allSettled(loads), grace]);
|
|
171
|
+
clearTimeout(timer);
|
|
172
|
+
}
|
|
173
|
+
return { mailbox, policy };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Builds the message's final content into the draft (plain, signed, or signed and encrypted in this browser) and returns the stored message. */
|
|
177
|
+
async function assemble(
|
|
178
|
+
request: SendRequest,
|
|
179
|
+
mailbox: Mailbox | undefined,
|
|
180
|
+
mode: "plain" | "sign" | "encrypt",
|
|
181
|
+
statuses: (RecipientEncryptionStatus | undefined)[],
|
|
182
|
+
withSignature: boolean,
|
|
183
|
+
): Promise<Message> {
|
|
184
|
+
const { draft, to, cc, bcc, subject, html } = request;
|
|
185
|
+
if (mode === "plain") {
|
|
186
|
+
return assembleDraft(draft.uid, { to, cc, bcc, subject, html });
|
|
187
|
+
}
|
|
188
|
+
const keys = readSendKeys(request.mailboxUid, request.signEnabled, mailbox);
|
|
189
|
+
const own = mailbox!;
|
|
190
|
+
const domain = own.primarySmtpAddress.split("@")[1] ?? "localhost";
|
|
191
|
+
const displayName = own.displayName && !UNSAFE_DISPLAY_NAME_PATTERN.test(own.displayName) ? own.displayName : "";
|
|
192
|
+
const protectedHeaders: ProtectedHeaders = {
|
|
193
|
+
from: displayName ? `"${displayName.replace(/"/g, '\\"')}" <${own.primarySmtpAddress}>` : own.primarySmtpAddress,
|
|
194
|
+
to: to.map((r) => r.address).join(", "),
|
|
195
|
+
cc: cc.length > 0 ? cc.map((r) => r.address).join(", ") : undefined,
|
|
196
|
+
date: new Date().toUTCString(),
|
|
197
|
+
subject,
|
|
198
|
+
messageId: `<${crypto.randomUUID()}@${domain}>`,
|
|
199
|
+
};
|
|
200
|
+
const bodyContentType = 'text/html; charset="utf-8"';
|
|
201
|
+
const signing = withSignature ? { certDer: keys.unlocked!.signingCertDer!, privateKey: keys.unlocked!.signingPrivateKey! } : undefined;
|
|
202
|
+
// The S/MIME code (PKI.js and the ASN.1/X.509 libraries, over half a megabyte) is only needed here, to sign or encrypt - a plain message
|
|
203
|
+
// never loads it, and it is kept out of the compose window's own chunk.
|
|
204
|
+
const { applyBaselineOuterHeaders, assembleOutboundMime, buildEncryptedMessage, buildSignedOnlyMessage } = await import(
|
|
205
|
+
"@rapidmx/react-shared/crypto/smimeMessage.js"
|
|
206
|
+
);
|
|
207
|
+
const encrypt = mode === "encrypt";
|
|
208
|
+
const outerHeaders = encrypt ? applyBaselineOuterHeaders(protectedHeaders) : protectedHeaders;
|
|
209
|
+
const mimePart = encrypt
|
|
210
|
+
? await buildEncryptedMessage(
|
|
211
|
+
bodyContentType,
|
|
212
|
+
html,
|
|
213
|
+
protectedHeaders,
|
|
214
|
+
outerHeaders,
|
|
215
|
+
[keys.unlocked!.encryptionCertDer!, ...statuses.map((status) => fromBase64(status!.encryptCert!.publicKey))],
|
|
216
|
+
signing,
|
|
217
|
+
)
|
|
218
|
+
: await buildSignedOnlyMessage(bodyContentType, html, protectedHeaders, signing!.certDer, signing!.privateKey);
|
|
219
|
+
const rawMime = assembleOutboundMime(outerHeaders, mimePart);
|
|
220
|
+
return assembleDraftRaw(draft.uid, { to, cc, bcc, subject: outerHeaders.subject, rawMime });
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function failureOf(err: unknown, fallback: string): Failure {
|
|
224
|
+
const failure = describeSendFailure(err, fallback);
|
|
225
|
+
return { message: failure.message, details: failure.lines };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Whether the server already holds `request`'s message as accepted (out of Drafts, or leased) - the answer to "did that request that never returned actually land?". */
|
|
229
|
+
async function alreadyAccepted(request: SendRequest): Promise<boolean> {
|
|
230
|
+
try {
|
|
231
|
+
const fresh = await getMessage(request.draft.uid);
|
|
232
|
+
return fresh.folderUid !== request.draft.folderUid || !!fresh.scheduledSendLeaseExpiresAt || !!fresh.scheduledSendRelayedAt;
|
|
233
|
+
} catch {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** The whole client-side path of one send: settle, decide, assemble, hand over. Never rejects. */
|
|
239
|
+
async function attempt(request: SendRequest): Promise<Outcome> {
|
|
240
|
+
try {
|
|
241
|
+
await request.saved?.catch(() => undefined);
|
|
242
|
+
const all = [...request.to, ...request.cc, ...request.bcc];
|
|
243
|
+
let mailbox = request.mailbox;
|
|
244
|
+
let policy = request.policy;
|
|
245
|
+
let statuses: (RecipientEncryptionStatus | undefined)[] = all.map(() => undefined);
|
|
246
|
+
let lookupsComplete = false;
|
|
247
|
+
|
|
248
|
+
if (!request.forcePlaintext) {
|
|
249
|
+
({ mailbox, policy } = await completeContext(request));
|
|
250
|
+
const keys = readSendKeys(request.mailboxUid, request.signEnabled, mailbox);
|
|
251
|
+
const hasKey = senderHasEncryptionKey({ mailbox, offeredEncrypt: request.offeredEncrypt }, keys.canEncryptSelf);
|
|
252
|
+
// Recipients' keys are only looked up when the answer can matter: encryption was asked for, or the loaded policy auto-applies.
|
|
253
|
+
if (mailbox && hasKey && (request.encryptRequested || (policy && policyCanAutoEncrypt(policy)))) {
|
|
254
|
+
const own = mailbox;
|
|
255
|
+
const ownPrefersMutual = own.encryptPreference?.preferEncrypt === "mutual";
|
|
256
|
+
const lookups = await Promise.all(
|
|
257
|
+
all.map((recipient) =>
|
|
258
|
+
lookupKeys(request.mailboxUid, recipient.address).then(
|
|
259
|
+
(lookup) => ({ lookup }),
|
|
260
|
+
() => null,
|
|
261
|
+
),
|
|
262
|
+
),
|
|
263
|
+
);
|
|
264
|
+
statuses = all.map((recipient, index) => {
|
|
265
|
+
const found = lookups[index];
|
|
266
|
+
return found ? resolveRecipientEncryption(own.primarySmtpAddress, ownPrefersMutual, policy ?? OPEN_POLICY, recipient.address, found.lookup) : undefined;
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
lookupsComplete = true;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const decision = decideSend(sendDecisionInput(request, mailbox, policy, statuses, lookupsComplete));
|
|
273
|
+
if (decision.action === "blocked") {
|
|
274
|
+
return { kind: "failed", failure: { message: decision.block.message, details: [], block: decision.block } };
|
|
275
|
+
}
|
|
276
|
+
if (decision.action === "rejected") {
|
|
277
|
+
return { kind: "failed", failure: { message: decision.message, details: [] } };
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const assembled = await assemble(request, mailbox, decision.action, statuses, decision.action === "sign" || (decision.action === "encrypt" && decision.sign));
|
|
281
|
+
const withReceipt = request.requestReceipt ? await setMessageRequestReceipt(assembled, true) : assembled;
|
|
282
|
+
setPendingStage(request.draft.uid, "queuing");
|
|
283
|
+
try {
|
|
284
|
+
if (request.scheduledSendTime) {
|
|
285
|
+
await sendMessage(withReceipt.uid, { scheduledSendTime: request.scheduledSendTime });
|
|
286
|
+
return { kind: "scheduled" };
|
|
287
|
+
}
|
|
288
|
+
const result = await queueMessageSend(withReceipt.uid);
|
|
289
|
+
return { kind: result.queued ? "queued" : "sent" };
|
|
290
|
+
} catch (err) {
|
|
291
|
+
// A request that never came back may still have landed: never offer to send it twice if it did.
|
|
292
|
+
if (!(err instanceof ApiRequestError) && (await alreadyAccepted(request))) {
|
|
293
|
+
return { kind: request.scheduledSendTime ? "scheduled" : "queued" };
|
|
294
|
+
}
|
|
295
|
+
throw err;
|
|
296
|
+
}
|
|
297
|
+
} catch (err) {
|
|
298
|
+
return { kind: "failed", failure: failureOf(err, request.scheduledSendTime ? "Could not schedule this message." : "Could not send this message.") };
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function recipientSummary(request: SendRequest): string {
|
|
303
|
+
const all = [...request.to, ...request.cc, ...request.bcc].map((recipient) => recipient.address);
|
|
304
|
+
return all.length <= 2 ? all.join(" and ") : `${all[0]} and ${all.length - 1} others`;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** "Message to a@b.c and 2 others (\"Subject\")" - which message a pop-up is about. */
|
|
308
|
+
export function describeMessage(subject: string, recipients: string): string {
|
|
309
|
+
return `${recipients ? `To ${recipients}` : "Message"}${subject ? ` - "${subject}"` : ""}`;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** Re-opens the compose window around a request's message, with everything as it was typed. */
|
|
313
|
+
export function openDraftFromRequest(request: SendRequest): boolean {
|
|
314
|
+
return openComposeFromOutside({
|
|
315
|
+
mailboxUid: request.mailboxUid,
|
|
316
|
+
resume: {
|
|
317
|
+
draft: request.draft,
|
|
318
|
+
mailboxUid: request.mailboxUid,
|
|
319
|
+
to: request.toText,
|
|
320
|
+
cc: request.ccText,
|
|
321
|
+
bcc: request.bccText,
|
|
322
|
+
subject: request.subject,
|
|
323
|
+
html: request.html,
|
|
324
|
+
attachments: request.attachments,
|
|
325
|
+
requestReceipt: request.requestReceipt,
|
|
326
|
+
signEnabled: request.signEnabled,
|
|
327
|
+
encryptRequested: request.encryptRequested,
|
|
328
|
+
},
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function failureNotificationId(draftUid: string): string {
|
|
333
|
+
return `send-failed:${draftUid}`;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** The sticky "This message wasn't sent" pop-up for a send that failed on this side, with what can be done about it. */
|
|
337
|
+
function notifyFailure(request: SendRequest, failure: Failure): void {
|
|
338
|
+
const uid = request.draft.uid;
|
|
339
|
+
const actions: NotificationAction[] = [];
|
|
340
|
+
const { block } = failure;
|
|
341
|
+
if (block?.keysLocked && request.mailbox?.keys?.length) {
|
|
342
|
+
actions.push({
|
|
343
|
+
label: "Unlock",
|
|
344
|
+
onClick: () => {
|
|
345
|
+
void requestUnlockFromOutside(request.mailboxUid, request.mailbox!.keys!).then(
|
|
346
|
+
() => void retrySend(request),
|
|
347
|
+
() => undefined,
|
|
348
|
+
);
|
|
349
|
+
},
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
if (block) {
|
|
353
|
+
actions.push({ label: block.overrideLabel, onClick: () => void retrySend({ ...request, forcePlaintext: true }) });
|
|
354
|
+
} else {
|
|
355
|
+
actions.push({ label: "Retry", onClick: () => void retrySend(request) });
|
|
356
|
+
}
|
|
357
|
+
actions.push({ label: "Open draft", onClick: () => void openDraftFromRequest(request) });
|
|
358
|
+
notify({
|
|
359
|
+
id: failureNotificationId(uid),
|
|
360
|
+
kind: "error",
|
|
361
|
+
title: "This message wasn't sent",
|
|
362
|
+
message: `${describeMessage(request.subject, recipientSummary(request))}: ${failure.message}`,
|
|
363
|
+
details: failure.details,
|
|
364
|
+
actions,
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const SENT_BURST_MS = 6_000;
|
|
369
|
+
|
|
370
|
+
/** The short "Message sent" confirmation - several sent close together are one pop-up counting up, never a stack of them. */
|
|
371
|
+
export function notifySent(message = "Message sent"): void {
|
|
372
|
+
const now = Date.now();
|
|
373
|
+
const { sentBurst } = sendState;
|
|
374
|
+
sendState.sentBurst = { count: now - sentBurst.at > SENT_BURST_MS ? 1 : sentBurst.count + 1, at: now };
|
|
375
|
+
notify({ id: "message-sent", kind: "success", title: sendState.sentBurst.count > 1 ? `${sendState.sentBurst.count} messages sent` : message, timeoutMs: 4_000 });
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Sends `request`'s draft in the background and returns at once, `true` - or `false` (doing nothing) when a send of this draft is already
|
|
380
|
+
* under way here. The outcome is shown as pop-ups and the Outbox indicator, never as a window that waits: a failure at any stage (assembling,
|
|
381
|
+
* encrypting, the request) is a sticky "This message wasn't sent" with the reason, and Retry / Open draft; the server's own later outcome
|
|
382
|
+
* (`send-succeeded`, `send-failed`, `send-retrying`) is `handleSendEvent()`'s.
|
|
383
|
+
*/
|
|
384
|
+
export function startSend(request: SendRequest): boolean {
|
|
385
|
+
const uid = request.draft.uid;
|
|
386
|
+
const recipients = [...request.to, ...request.cc, ...request.bcc].map((recipient) => recipient.address);
|
|
387
|
+
if (!beginPendingSend({ draftUid: uid, mailboxUid: request.mailboxUid, subject: request.subject, recipients, scheduled: !!request.scheduledSendTime })) {
|
|
388
|
+
return false;
|
|
389
|
+
}
|
|
390
|
+
// The failure of an earlier attempt is resolved by trying again.
|
|
391
|
+
dismiss(failureNotificationId(uid));
|
|
392
|
+
const tracker = sendState.countTracker?.(request.mailboxUid);
|
|
393
|
+
void attempt(request).then((outcome) => {
|
|
394
|
+
finishPendingSend(uid);
|
|
395
|
+
if (outcome.kind === "failed") {
|
|
396
|
+
tracker?.revert();
|
|
397
|
+
notifyFailure(request, outcome.failure);
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
tracker?.settle();
|
|
401
|
+
if (outcome.kind === "queued") {
|
|
402
|
+
retain(request);
|
|
403
|
+
sendState.queuedListener?.(request.mailboxUid);
|
|
404
|
+
} else if (outcome.kind === "sent") {
|
|
405
|
+
notifySent();
|
|
406
|
+
} else {
|
|
407
|
+
notify({
|
|
408
|
+
id: `scheduled:${uid}`,
|
|
409
|
+
kind: "success",
|
|
410
|
+
title: "Message scheduled",
|
|
411
|
+
message: `It will be sent ${new Date(request.scheduledSendTime!).toLocaleString()}.`,
|
|
412
|
+
timeoutMs: 5_000,
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
return true;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/** Tries a failed send again - unless the server already has the message (an earlier request that seemed to fail did land), which it must not send twice. */
|
|
420
|
+
export async function retrySend(request: SendRequest): Promise<void> {
|
|
421
|
+
if (await alreadyAccepted(request)) {
|
|
422
|
+
dismiss(failureNotificationId(request.draft.uid));
|
|
423
|
+
notify({ id: `already-sent:${request.draft.uid}`, kind: "info", title: "This message is already on its way", timeoutMs: 5_000 });
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
startSend({ ...request, saved: undefined });
|
|
427
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import { Message, cancelScheduledSend, getMessage, listAttachments, listFolders, queueMessageSend } from "@rapidmx/react-shared/mail/mailApi.js";
|
|
6
|
+
import { SendEvent, describeSendEventError } from "@rapidmx/react-shared/mail/sendEvents.js";
|
|
7
|
+
import { formatRecipient } from "../../components/mail/compose/recipients.js";
|
|
8
|
+
import { loadOriginalMessage } from "../../components/mail/compose/quotedBody.js";
|
|
9
|
+
import { notifyApiError } from "../../notifications/apiErrors.js";
|
|
10
|
+
import { dismiss, notify } from "../../notifications/store.js";
|
|
11
|
+
import { beginPendingSend, finishPendingSend, setPendingStage } from "./pendingSends.js";
|
|
12
|
+
import { openComposeFromOutside } from "./composeBridge.js";
|
|
13
|
+
import { describeMessage, forgetRetainedRequest, notifySent, openDraftFromRequest, retainedRequest } from "./sendJob.js";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* What the user is told when the server reports how a queued message went (`send-succeeded`, `send-failed`, `send-retrying` push events,
|
|
17
|
+
* see `@rapidmx/react-shared`'s `parseSendEvent()`): a quiet, single "Message sent" for a message this tab sent (several close together are
|
|
18
|
+
* one pop-up counting up), an info pop-up when a delivery is retried, and - only when it finally failed - the sticky "This message wasn't sent" with the
|
|
19
|
+
* server's reason, its technical details and what to do about it. The Outbox count, list and pill update themselves from the same events
|
|
20
|
+
* (`useMailLiveUpdates()` refreshes on them).
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const retryId = (uid: string) => `send-retry:${uid}`;
|
|
24
|
+
const failedId = (uid: string) => `send-failed:${uid}`;
|
|
25
|
+
|
|
26
|
+
function summary(recipients: string[]): string {
|
|
27
|
+
return recipients.length <= 2 ? recipients.join(" and ") : `${recipients[0]} and ${recipients.length - 1} others`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Moves a message the server failed to relay back into Drafts (the only place it can be edited or sent again), and returns it as it is there. */
|
|
31
|
+
async function moveBackToDrafts(uid: string, mailboxUid: string): Promise<Message> {
|
|
32
|
+
const message = await getMessage(uid);
|
|
33
|
+
const drafts = (await listFolders(mailboxUid)).find((folder) => folder.type === "drafts");
|
|
34
|
+
if (!drafts || message.folderUid === drafts.uid) {
|
|
35
|
+
return message;
|
|
36
|
+
}
|
|
37
|
+
return cancelScheduledSend(message, drafts.uid);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function escapeHtml(text: string): string {
|
|
41
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** "Open draft" for a message the server failed to relay: back into Drafts, and into a compose window with what was written. */
|
|
45
|
+
async function openFailedDraft(event: SendEvent): Promise<void> {
|
|
46
|
+
try {
|
|
47
|
+
const moved = await moveBackToDrafts(event.uid, event.mailboxUid ?? "");
|
|
48
|
+
const request = retainedRequest(event.uid);
|
|
49
|
+
if (request) {
|
|
50
|
+
openDraftFromRequest({ ...request, draft: moved });
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (moved.encrypted) {
|
|
54
|
+
notify({
|
|
55
|
+
id: `open-draft:${event.uid}`,
|
|
56
|
+
kind: "info",
|
|
57
|
+
title: "This message is encrypted",
|
|
58
|
+
message: "It was moved back to Drafts, but it can only be edited in the tab that wrote it. Open it from Drafts to send it again.",
|
|
59
|
+
timeoutMs: 8_000,
|
|
60
|
+
});
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const original = await loadOriginalMessage(moved, null);
|
|
64
|
+
const attachments = await listAttachments(moved.folderUid, moved.uid).catch(() => []);
|
|
65
|
+
const byType = (type: "to" | "cc" | "bcc") => moved.recipients.filter((recipient) => recipient.type === type).map(formatRecipient).join(", ");
|
|
66
|
+
openComposeFromOutside({
|
|
67
|
+
mailboxUid: moved.mailboxUid,
|
|
68
|
+
resume: {
|
|
69
|
+
draft: moved,
|
|
70
|
+
mailboxUid: moved.mailboxUid,
|
|
71
|
+
to: byType("to"),
|
|
72
|
+
cc: byType("cc"),
|
|
73
|
+
bcc: byType("bcc"),
|
|
74
|
+
subject: moved.subject ?? event.subject,
|
|
75
|
+
html: original.body.html ?? (original.body.text ? `<p>${escapeHtml(original.body.text).replace(/\r?\n/g, "<br>")}</p>` : ""),
|
|
76
|
+
attachments,
|
|
77
|
+
requestReceipt: !!moved.requestReceipt,
|
|
78
|
+
signEnabled: true,
|
|
79
|
+
encryptRequested: false,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
} catch (err) {
|
|
83
|
+
notifyApiError(err, "Couldn't open this draft");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** "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). */
|
|
88
|
+
async function retryFailed(event: SendEvent): Promise<void> {
|
|
89
|
+
if (!beginPendingSend({ draftUid: event.uid, mailboxUid: event.mailboxUid ?? "", subject: event.subject, recipients: event.recipients, scheduled: false })) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
dismiss(failedId(event.uid));
|
|
93
|
+
try {
|
|
94
|
+
setPendingStage(event.uid, "queuing");
|
|
95
|
+
const result = await queueMessageSend(event.uid);
|
|
96
|
+
if (!result.queued) {
|
|
97
|
+
notifySent();
|
|
98
|
+
}
|
|
99
|
+
} catch (err) {
|
|
100
|
+
notifyApiError(err, "This message wasn't sent", { dedupeKey: failedId(event.uid) });
|
|
101
|
+
} finally {
|
|
102
|
+
finishPendingSend(event.uid);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Shows what a send event means to the user. */
|
|
107
|
+
export function handleSendEvent(event: SendEvent): void {
|
|
108
|
+
if (event.action === "send-succeeded") {
|
|
109
|
+
dismiss(retryId(event.uid));
|
|
110
|
+
dismiss(failedId(event.uid));
|
|
111
|
+
// The server reports every message it relays, scheduled ones from long ago included: only a message this tab queued in the background is
|
|
112
|
+
// worth a confirmation (several are one pop-up counting up). Anything else - a send-later message going out, another tab's send - is quiet.
|
|
113
|
+
if (retainedRequest(event.uid)) {
|
|
114
|
+
forgetRetainedRequest(event.uid);
|
|
115
|
+
notifySent();
|
|
116
|
+
}
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const failure = describeSendEventError(event.error, event.action === "send-failed" ? "The server couldn't send this message." : "The server couldn't send this message yet.");
|
|
120
|
+
const what = describeMessage(event.subject, summary(event.recipients));
|
|
121
|
+
if (event.action === "send-retrying") {
|
|
122
|
+
const next = event.nextAttemptAt ? Date.parse(event.nextAttemptAt) : NaN;
|
|
123
|
+
notify({
|
|
124
|
+
id: retryId(event.uid),
|
|
125
|
+
kind: "info",
|
|
126
|
+
title: "Retrying to send",
|
|
127
|
+
message: `${what} (attempt ${event.attempt + 1}${Number.isNaN(next) ? "" : `, at ${new Date(next).toLocaleTimeString()}`}). ${failure.message}`,
|
|
128
|
+
details: failure.lines,
|
|
129
|
+
sticky: false,
|
|
130
|
+
timeoutMs: 8_000,
|
|
131
|
+
});
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
dismiss(retryId(event.uid));
|
|
135
|
+
notify({
|
|
136
|
+
id: failedId(event.uid),
|
|
137
|
+
kind: "error",
|
|
138
|
+
title: "This message wasn't sent",
|
|
139
|
+
message: `${what}: ${failure.message}`,
|
|
140
|
+
details: failure.lines,
|
|
141
|
+
actions: [
|
|
142
|
+
{ label: "Retry", onClick: () => void retryFailed(event) },
|
|
143
|
+
{ label: "Open draft", onClick: () => void openFailedDraft(event) },
|
|
144
|
+
],
|
|
145
|
+
});
|
|
146
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import type { SendRequest } from "./sendJob.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The module-level state of the background send (`sendJob.ts`), kept in a module with no imports of its own: a test setup can reset it after each
|
|
9
|
+
* test without loading the send code (and everything that code imports) before a test file has had the chance to mock it.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** Registered by the frame: puts an optimistic +1 on the Outbox count for `mailboxUid`, at once, and says how to settle or take it back. */
|
|
13
|
+
export interface OutboxCountTracker {
|
|
14
|
+
settle(): void;
|
|
15
|
+
revert(): void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const sendState: {
|
|
19
|
+
countTracker: ((mailboxUid: string) => OutboxCountTracker) | undefined;
|
|
20
|
+
/** Called after the server accepted a message into Outbox - the frame reads the folders back (the Outbox may not have existed before). */
|
|
21
|
+
queuedListener: ((mailboxUid: string) => void) | undefined;
|
|
22
|
+
/** What is kept of each message the server accepted, so a later failure reported by push event can offer "Open draft" and "Retry" with
|
|
23
|
+
* the content intact (a message that was encrypted before it was stored can't be read back from the server). Bounded; this tab's only. */
|
|
24
|
+
retained: Map<string, SendRequest>;
|
|
25
|
+
/** "Message sent" confirmations close together are one pop-up counting up. */
|
|
26
|
+
sentBurst: { count: number; at: number };
|
|
27
|
+
} = { countTracker: undefined, queuedListener: undefined, retained: new Map(), sentBurst: { count: 0, at: 0 } };
|
|
28
|
+
|
|
29
|
+
/** Forgets everything - for a test. */
|
|
30
|
+
export function resetSendJobs(): void {
|
|
31
|
+
sendState.countTracker = undefined;
|
|
32
|
+
sendState.queuedListener = undefined;
|
|
33
|
+
sendState.retained.clear();
|
|
34
|
+
sendState.sentBurst = { count: 0, at: 0 };
|
|
35
|
+
}
|