@rapidmx/web-client 0.15.1 → 0.16.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 +373 -373
- package/apps/admin/branding/index.tsx +39 -39
- package/apps/admin/data-requests/index.tsx +482 -480
- package/apps/admin/domains/[uid].tsx +164 -164
- package/apps/admin/escrow-scopes/[uid].tsx +348 -348
- package/apps/admin/index.tsx +127 -124
- package/apps/admin/mailboxes/[uid].tsx +269 -224
- package/apps/admin/mailboxes/new/index.tsx +28 -28
- package/apps/admin/plugins/index.tsx +15 -15
- package/apps/admin/retention-policy/index.tsx +39 -39
- package/apps/admin/signing-certificates/index.tsx +343 -343
- package/apps/escrow/audit-log/index.tsx +196 -196
- package/apps/escrow/matters/[uid].tsx +621 -621
- package/apps/shared/auth/adminAccess.ts +99 -99
- package/apps/shared/components/admin/layout/AdminShell.tsx +378 -378
- package/apps/shared/components/admin/mailboxes/EraseLeftoverDataDialog.tsx +238 -0
- package/apps/shared/components/admin/mailboxes/EscrowScopeCard.tsx +152 -152
- package/apps/shared/components/admin/mailboxes/LeftoverMailboxesSection.tsx +194 -0
- package/apps/shared/components/admin/settings/BrandingForm.tsx +423 -423
- package/apps/shared/components/admin/settings/EncryptionPolicyForm.tsx +119 -119
- package/apps/shared/components/admin/settings/MailboxCreateForm.tsx +50 -3
- package/apps/shared/components/admin/settings/MailboxPolicyForm.tsx +198 -198
- package/apps/shared/components/admin/settings/PluginsManager.tsx +1545 -1545
- package/apps/shared/components/admin/settings/RetentionPolicyForm.tsx +182 -182
- package/apps/shared/components/admin/setup/EscrowSetupStep.tsx +288 -288
- package/apps/shared/components/admin/setup/SetupWizard.tsx +444 -444
- package/apps/shared/components/admin/usePagedList.tsx +129 -129
- package/apps/shared/components/calendar/EventEditor.tsx +5 -10
- package/apps/shared/components/calendar/EventFormParts.tsx +16 -47
- package/apps/shared/components/calendar/EventModal.tsx +206 -206
- package/apps/shared/components/calendar/GuestInput.tsx +100 -0
- package/apps/shared/components/calendar/MonthView.tsx +185 -185
- package/apps/shared/components/calendar/RecurrenceEditor.tsx +227 -227
- package/apps/shared/components/calendar/RequestChangeForm.tsx +23 -54
- package/apps/shared/components/calendar/SplitDayView.tsx +144 -144
- package/apps/shared/components/calendar/TimeGridView.tsx +246 -246
- package/apps/shared/components/calendar/allDay.ts +124 -124
- package/apps/shared/components/calendar/eventForm.ts +2 -2
- package/apps/shared/components/calendar/eventFormat.ts +49 -22
- package/apps/shared/components/calendar/layout/CalendarShell.tsx +201 -200
- package/apps/shared/components/contacts/ContactForm.tsx +383 -383
- package/apps/shared/components/contacts/ContactsSidebar.tsx +1 -1
- package/apps/shared/components/contacts/ContactsToolbar.tsx +103 -98
- package/apps/shared/components/contacts/layout/ContactsShell.tsx +217 -216
- package/apps/shared/components/escrow/layout/EscrowShell.tsx +155 -155
- package/apps/shared/components/layout/AppShell.tsx +480 -480
- package/apps/shared/components/layout/FloatingActionButton.tsx +31 -0
- package/apps/shared/components/layout/KeyEnrollmentGate.tsx +398 -398
- package/apps/shared/components/layout/MailboxProvisioning.tsx +168 -168
- package/apps/shared/components/layout/ResponsiveToolbar.tsx +315 -315
- package/apps/shared/components/layout/ThemeSwitch.tsx +84 -84
- package/apps/shared/components/layout/UserMenu.tsx +439 -424
- package/apps/shared/components/mail/ConversationList.tsx +323 -323
- package/apps/shared/components/mail/ConversationThreadPane.tsx +612 -491
- package/apps/shared/components/mail/MailSelectionBar.tsx +236 -227
- package/apps/shared/components/mail/MessageDetailPane.tsx +1559 -1559
- package/apps/shared/components/mail/compose/ComposeContext.tsx +312 -312
- package/apps/shared/components/mail/compose/ComposeToolbar.tsx +422 -422
- package/apps/shared/components/mail/compose/ComposeWindow.tsx +1681 -1677
- package/apps/shared/components/mail/compose/RecipientInput.tsx +54 -11
- package/apps/shared/components/mail/compose/RichTextEditor.tsx +147 -147
- package/apps/shared/components/mail/compose/composeFlushRegistry.ts +60 -60
- package/apps/shared/components/mail/compose/quotedBody.ts +161 -161
- package/apps/shared/components/mail/layout/FolderBadgeChip.tsx +21 -0
- package/apps/shared/components/mail/layout/MailShell.tsx +137 -113
- package/apps/shared/components/mail/layout/SidebarSection.tsx +66 -0
- package/apps/shared/components/mail/reading/PendingMessageCard.tsx +68 -0
- package/apps/shared/components/mail/verificationSeals.ts +125 -125
- package/apps/shared/components/rules/RuleBuilder.tsx +311 -311
- package/apps/shared/components/settings/SigningCertificateCard.tsx +344 -344
- package/apps/shared/components/settings/layout/SettingsShell.tsx +255 -254
- package/apps/shared/components/tasks/TasksSidebar.tsx +1 -1
- package/apps/shared/components/tasks/layout/TasksShell.tsx +218 -217
- package/apps/shared/keyboard/GlobalShortcuts.tsx +51 -51
- package/apps/shared/keyboard/ShortcutProvider.tsx +62 -62
- package/apps/shared/keyboard/ShortcutsDialog.tsx +84 -84
- package/apps/shared/keyboard/dispatch.ts +124 -124
- package/apps/shared/keyboard/format.ts +89 -89
- package/apps/shared/keyboard/keymap.ts +114 -114
- package/apps/shared/keyboard/registry.ts +65 -65
- package/apps/shared/keyboard/targets.ts +79 -79
- package/apps/shared/mail/folderCounts.ts +17 -0
- package/apps/shared/mail/folderTree.ts +143 -143
- package/apps/shared/mail/listAllPages.ts +39 -39
- package/apps/shared/mail/newMailNotifications.ts +171 -171
- package/apps/shared/mail/outbox/outgoingReplies.ts +192 -0
- package/apps/shared/mail/outbox/sendJob.ts +19 -1
- package/apps/shared/mail/outbox/sendOutcomes.ts +13 -4
- package/apps/shared/mail/primaryMailbox.ts +71 -0
- package/apps/shared/mail/useCollapsedSections.ts +146 -0
- package/apps/shared/mail/useMailConnection.ts +205 -203
- package/apps/shared/mail/useMailLiveUpdates.ts +277 -277
- package/apps/shared/mail/useMarkMessageRead.ts +47 -47
- package/apps/shared/mail/useNewMailNotifications.ts +178 -178
- package/apps/shared/navigation/AppRouter.tsx +300 -300
- package/apps/shared/navigation/routerContext.tsx +83 -83
- package/apps/shared/notifications/store.ts +560 -560
- package/apps/shared/search/LocalIndexLifecycle.tsx +114 -114
- package/apps/shared/search/crossMailboxSearch.ts +169 -0
- package/apps/shared/search/localIndexBuilder.ts +481 -481
- package/apps/shared/signing/enrollmentStorage.ts +33 -33
- package/apps/shared/signing/enrollmentTracker.ts +385 -385
- package/apps/shared/signing/enrollmentView.ts +251 -251
- package/apps/shared/signing/useNow.ts +19 -19
- package/apps/shared/signing/useSigningEnrollmentWatcher.ts +90 -90
- package/apps/shared/styles/app.css +396 -386
- package/apps/www/calendar/index.tsx +578 -571
- package/apps/www/contacts/[uid].tsx +109 -109
- package/apps/www/contacts/index.tsx +6 -0
- package/apps/www/index.tsx +2847 -2479
- package/apps/www/messages/[uid].tsx +135 -135
- package/apps/www/settings/auto-reply/index.tsx +133 -133
- package/apps/www/settings/encryption/index.tsx +1287 -1287
- package/apps/www/settings/filters/[uid].tsx +176 -176
- package/apps/www/settings/filters/index.tsx +102 -102
- package/apps/www/settings/filters/new/index.tsx +140 -140
- package/apps/www/settings/labels/index.tsx +204 -204
- package/apps/www/settings/privacy/index.tsx +492 -492
- package/apps/www/settings/profile/index.tsx +248 -248
- package/apps/www/settings/read-receipts/index.tsx +147 -147
- package/apps/www/settings/sharing/index.tsx +256 -256
- package/apps/www/settings/signatures/[uid].tsx +172 -172
- package/apps/www/settings/signatures/index.tsx +88 -88
- package/apps/www/settings/signatures/new/index.tsx +135 -135
- package/apps/www/tasks/index.tsx +649 -649
- package/dist/apps/admin/data-requests/index.js +1 -1
- package/dist/apps/admin/index.js +2 -1
- package/dist/apps/admin/mailboxes/[uid].js +12 -2
- package/dist/apps/shared/components/admin/layout/AdminShell.js +2 -2
- package/dist/apps/shared/components/admin/mailboxes/EraseLeftoverDataDialog.d.ts +35 -0
- package/dist/apps/shared/components/admin/mailboxes/EraseLeftoverDataDialog.js +115 -0
- package/dist/apps/shared/components/admin/mailboxes/LeftoverMailboxesSection.d.ts +16 -0
- package/dist/apps/shared/components/admin/mailboxes/LeftoverMailboxesSection.js +92 -0
- package/dist/apps/shared/components/admin/settings/BrandingForm.js +3 -3
- package/dist/apps/shared/components/admin/settings/MailboxCreateForm.js +25 -3
- package/dist/apps/shared/components/calendar/EventEditor.js +5 -10
- package/dist/apps/shared/components/calendar/EventFormParts.d.ts +3 -2
- package/dist/apps/shared/components/calendar/EventFormParts.js +5 -16
- package/dist/apps/shared/components/calendar/GuestInput.d.ts +45 -0
- package/dist/apps/shared/components/calendar/GuestInput.js +30 -0
- package/dist/apps/shared/components/calendar/RequestChangeForm.js +11 -22
- package/dist/apps/shared/components/calendar/eventForm.d.ts +2 -2
- package/dist/apps/shared/components/calendar/eventFormat.d.ts +21 -8
- package/dist/apps/shared/components/calendar/eventFormat.js +50 -23
- package/dist/apps/shared/components/calendar/layout/CalendarShell.js +3 -2
- package/dist/apps/shared/components/contacts/ContactsSidebar.js +1 -1
- package/dist/apps/shared/components/contacts/ContactsToolbar.d.ts +3 -1
- package/dist/apps/shared/components/contacts/ContactsToolbar.js +4 -2
- package/dist/apps/shared/components/contacts/layout/ContactsShell.js +4 -3
- package/dist/apps/shared/components/layout/FloatingActionButton.d.ts +13 -0
- package/dist/apps/shared/components/layout/FloatingActionButton.js +9 -0
- package/dist/apps/shared/components/layout/UserMenu.d.ts +4 -1
- package/dist/apps/shared/components/layout/UserMenu.js +6 -5
- package/dist/apps/shared/components/mail/ConversationThreadPane.js +127 -22
- package/dist/apps/shared/components/mail/MailSelectionBar.d.ts +6 -1
- package/dist/apps/shared/components/mail/MailSelectionBar.js +3 -3
- package/dist/apps/shared/components/mail/compose/ComposeWindow.js +8 -4
- package/dist/apps/shared/components/mail/compose/RecipientInput.d.ts +21 -1
- package/dist/apps/shared/components/mail/compose/RecipientInput.js +18 -10
- package/dist/apps/shared/components/mail/layout/FolderBadgeChip.d.ts +6 -0
- package/dist/apps/shared/components/mail/layout/FolderBadgeChip.js +9 -0
- package/dist/apps/shared/components/mail/layout/MailShell.d.ts +5 -0
- package/dist/apps/shared/components/mail/layout/MailShell.js +64 -45
- package/dist/apps/shared/components/mail/layout/SidebarSection.d.ts +23 -0
- package/dist/apps/shared/components/mail/layout/SidebarSection.js +16 -0
- package/dist/apps/shared/components/mail/reading/PendingMessageCard.d.ts +14 -0
- package/dist/apps/shared/components/mail/reading/PendingMessageCard.js +16 -0
- package/dist/apps/shared/components/settings/layout/SettingsShell.js +6 -5
- package/dist/apps/shared/components/tasks/TasksSidebar.js +1 -1
- package/dist/apps/shared/components/tasks/layout/TasksShell.js +4 -3
- package/dist/apps/shared/mail/folderCounts.d.ts +10 -0
- package/dist/apps/shared/mail/folderCounts.js +12 -0
- package/dist/apps/shared/mail/outbox/outgoingReplies.d.ts +80 -0
- package/dist/apps/shared/mail/outbox/outgoingReplies.js +131 -0
- package/dist/apps/shared/mail/outbox/sendJob.d.ts +5 -1
- package/dist/apps/shared/mail/outbox/sendJob.js +14 -1
- package/dist/apps/shared/mail/outbox/sendOutcomes.js +13 -4
- package/dist/apps/shared/mail/primaryMailbox.d.ts +29 -0
- package/dist/apps/shared/mail/primaryMailbox.js +61 -0
- package/dist/apps/shared/mail/useCollapsedSections.d.ts +32 -0
- package/dist/apps/shared/mail/useCollapsedSections.js +110 -0
- package/dist/apps/shared/mail/useMailConnection.js +3 -1
- package/dist/apps/shared/search/crossMailboxSearch.d.ts +72 -0
- package/dist/apps/shared/search/crossMailboxSearch.js +136 -0
- package/dist/apps/shared/styles/app.css +396 -386
- package/dist/apps/www/calendar/index.js +3 -2
- package/dist/apps/www/contacts/index.js +3 -1
- package/dist/apps/www/index.js +426 -189
- package/package.json +2 -2
|
@@ -1,1559 +1,1559 @@
|
|
|
1
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
-
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
-
import React, { useEffect, useRef, useState } from "react";
|
|
6
|
-
import {
|
|
7
|
-
HiOutlineArchiveBox,
|
|
8
|
-
HiOutlineArrowUturnLeft,
|
|
9
|
-
HiOutlineArrowUturnRight,
|
|
10
|
-
HiOutlineCheck,
|
|
11
|
-
HiOutlineExclamationTriangle,
|
|
12
|
-
HiOutlineFolderArrowDown,
|
|
13
|
-
HiOutlineLockClosed,
|
|
14
|
-
HiOutlineMoon,
|
|
15
|
-
HiOutlineSun,
|
|
16
|
-
} from "react-icons/hi2";
|
|
17
|
-
import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
|
|
18
|
-
import {
|
|
19
|
-
Attachment,
|
|
20
|
-
Folder,
|
|
21
|
-
Message,
|
|
22
|
-
ReceiptType,
|
|
23
|
-
Recipient,
|
|
24
|
-
approveReceipt,
|
|
25
|
-
archiveMessage,
|
|
26
|
-
attachmentContentUrl,
|
|
27
|
-
cancelScheduledSend,
|
|
28
|
-
declineReceipt,
|
|
29
|
-
getMailbox,
|
|
30
|
-
getMessage,
|
|
31
|
-
getMessageRawContent,
|
|
32
|
-
moveMessage,
|
|
33
|
-
recallMessage,
|
|
34
|
-
setMessageLabels,
|
|
35
|
-
} from "@rapidmx/react-shared/mail/mailApi.js";
|
|
36
|
-
import { Label } from "@rapidmx/react-shared/mail/labelsApi.js";
|
|
37
|
-
import {
|
|
38
|
-
buildForwardQuote,
|
|
39
|
-
buildReplyQuote,
|
|
40
|
-
buildReplyRecipients,
|
|
41
|
-
buildReplyThreading,
|
|
42
|
-
forwardSubject,
|
|
43
|
-
replySubject,
|
|
44
|
-
} from "@rapidmx/react-shared/mail/compose/composeQuoting.js";
|
|
45
|
-
import MoveToFolderDialog from "./MoveToFolderDialog.js";
|
|
46
|
-
import InviteCard from "./InviteCard.js";
|
|
47
|
-
import { isCalendarAttachment } from "./invite/inviteFormat.js";
|
|
48
|
-
import { useMessageInvite } from "./invite/inviteStore.js";
|
|
49
|
-
import { getUnlockedKeys, subscribeKeySession } from "@rapidmx/react-shared/crypto/keySession.js";
|
|
50
|
-
import type { MessageSecurityResult, SignatureFailureReason } from "@rapidmx/react-shared/crypto/messageSecurity.js";
|
|
51
|
-
import { extractAddresses, type MimeAttachment } from "@rapidmx/react-shared/crypto/mime.js";
|
|
52
|
-
import { SignerKeyConflictError, signingKeyFingerprints, trustSigner } from "@rapidmx/react-shared/crypto/keyvaultApi.js";
|
|
53
|
-
import { isLikelyMailingList } from "@rapidmx/react-shared/crypto/composeSecurity.js";
|
|
54
|
-
import { SenderKeyState, clearPinnedSignerCache, getPinnedSignerFingerprints, getSignerKeyState } from "./pinnedSigners.js";
|
|
55
|
-
import { currentVerificationSeal, getVaultGeneration, sendVerificationSeal } from "./verificationSeals.js";
|
|
56
|
-
import { getMyMailboxAccess } from "@rapidmx/react-shared/mail/mailboxAccessApi.js";
|
|
57
|
-
import KeyChangeReview from "../contacts/KeyChangeReview.js";
|
|
58
|
-
import { KEY_CHANGE_STALE_MESSAGE, sameFingerprint } from "../contacts/contactKeys.js";
|
|
59
|
-
import { ComposeLateInput, prefetchComposeWindow, useCompose } from "./compose/ComposeContext.js";
|
|
60
|
-
import { loadOriginalMessage, prefetchOriginalMessage } from "./compose/quotedBody.js";
|
|
61
|
-
import { formatRecipient } from "./compose/recipients.js";
|
|
62
|
-
import { formatMailAddress } from "@rapidmx/react-shared/mail/mailAddress.js";
|
|
63
|
-
import MailAddress, { RecipientLine } from "./MailAddress.js";
|
|
64
|
-
import { useMailShell } from "./layout/MailShell.js";
|
|
65
|
-
import { ariaKeyShortcuts, withHint } from "../../keyboard/format.js";
|
|
66
|
-
import { SHORTCUTS, ShortcutDef } from "../../keyboard/keymap.js";
|
|
67
|
-
import { useKeyEnvironment } from "../../keyboard/ShortcutProvider.js";
|
|
68
|
-
import { useShortcut } from "../../keyboard/useShortcut.js";
|
|
69
|
-
import { useUnlockPrompt } from "../layout/UnlockPromptProvider.js";
|
|
70
|
-
import { moveLocalEntity } from "../../search/localIndexRpcClient.js";
|
|
71
|
-
import Modal from "@rapidmx/react-shared/components/overlays/Modal.js";
|
|
72
|
-
import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
|
|
73
|
-
import LabelMenuButton from "./labelMenu.js";
|
|
74
|
-
import Button from "@rapidmx/react-shared/components/buttons/Button.js";
|
|
75
|
-
import EncryptedBody from "./reading/EncryptedBody.js";
|
|
76
|
-
import { displaySubject } from "./reading/EncryptedPreview.js";
|
|
77
|
-
import MessageBody, { BodySkeleton } from "./reading/MessageBody.js";
|
|
78
|
-
import { BODY_FONT_STYLE, CardShell, SenderAvatar, SubjectCard } from "./reading/MessageCard.js";
|
|
79
|
-
import type { BodyContent } from "./reading/bodyContent.js";
|
|
80
|
-
import { useViewOriginal } from "./reading/viewOriginal.js";
|
|
81
|
-
import { ROW_FOCUS_CLASS, UnreadLabel, dateClass, senderClass } from "./unreadStyle.js";
|
|
82
|
-
|
|
83
|
-
/** Labels/styling for `specs/end-to-end_encryption.md`'s "Message Security Indicators" table - kept as
|
|
84
|
-
* plain data (not JSX) so `SecurityIndicator` below stays a trivial lookup. "Signature failed" MUST NOT
|
|
85
|
-
* read as a muted variant of "verified" (a failed signature is a stronger negative than no signature at
|
|
86
|
-
* all), and "Unprotected" MUST NOT read as an error - the class pairs below are chosen so those two
|
|
87
|
-
* never share styling with each other or with the verified states. */
|
|
88
|
-
const SECURITY_INDICATOR: Record<MessageSecurityResult["state"], { label: string; className: string }> = {
|
|
89
|
-
unprotected: { label: "Unprotected", className: "bg-surface-alt text-text-muted" },
|
|
90
|
-
encrypted: { label: "Encrypted", className: "bg-primary/10 text-primary-dark" },
|
|
91
|
-
signed_verified: { label: "Signed & verified", className: "bg-success/10 text-success" },
|
|
92
|
-
encrypted_verified: { label: "Encrypted & verified", className: "bg-success/10 text-success" },
|
|
93
|
-
// A valid signature from a certificate the reader hasn't pinned - anyone can mint a certificate naming the
|
|
94
|
-
// sender, so this must never look like the verified states.
|
|
95
|
-
signed_unverified_signer: { label: "Signed - signer not verified", className: "bg-warning/15 text-text" },
|
|
96
|
-
encrypted_unverified_signer: { label: "Encrypted - signer not verified", className: "bg-warning/15 text-text" },
|
|
97
|
-
signature_failed: { label: "Signature failed", className: "bg-danger-bg text-danger" },
|
|
98
|
-
// Verified when first opened (a verification seal), but not live: muted, never the green verified pill. A signer key
|
|
99
|
-
// later reported compromised switches it to `LATER_COMPROMISED_INDICATOR_CLASS`.
|
|
100
|
-
verified_at_first_open: { label: "Verified when first opened", className: "bg-surface-alt text-text-muted" },
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
/** The amber `verified_at_first_open` badge for a signer key since reported compromised. */
|
|
104
|
-
const LATER_COMPROMISED_INDICATOR_CLASS = "bg-warning/15 text-text";
|
|
105
|
-
|
|
106
|
-
/** Whether a result is (or, for `verified_at_first_open`, was live) a `signer_key_changed` failure. */
|
|
107
|
-
function signerKeyChanged(result: MessageSecurityResult): boolean {
|
|
108
|
-
return result.signatureFailureReason === "signer_key_changed" || result.liveSignatureFailureReason === "signer_key_changed";
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** The detail line under a `verified_at_first_open` badge. */
|
|
112
|
-
export function verifiedAtFirstOpenMessage(result: MessageSecurityResult): string {
|
|
113
|
-
const date = new Date(result.verifiedAt!).toLocaleDateString();
|
|
114
|
-
if (result.laterCompromised) {
|
|
115
|
-
return `This signature was verified on ${date}, but the sender's key was later reported compromised; treat this message with caution.`;
|
|
116
|
-
}
|
|
117
|
-
if (result.liveSignatureFailureReason === "signer_key_changed") {
|
|
118
|
-
return `This signature was verified on ${date}. The sender has since started signing with a different key.`;
|
|
119
|
-
}
|
|
120
|
-
return `This signature was verified on ${date}. The sender's key is no longer trusted since then, for example because it was removed, replaced or revoked.`;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const VERIFIED_STATES = new Set<MessageSecurityResult["state"]>(["signed_verified", "encrypted_verified"]);
|
|
124
|
-
const UNVERIFIED_SIGNER_STATES = new Set<MessageSecurityResult["state"]>(["signed_unverified_signer", "encrypted_unverified_signer"]);
|
|
125
|
-
|
|
126
|
-
/** An `@`, or a look-alike a reader would take for one (fullwidth, small) - restapi's own `AT_SIGN_LIKE`. */
|
|
127
|
-
const AT_SIGN_LIKE = /[@\uFF20\uFE6B]/;
|
|
128
|
-
|
|
129
|
-
export interface SenderNameCheck {
|
|
130
|
-
/** The display name contains an `@` or a look-alike - it reads as (part of) an address. */
|
|
131
|
-
looksLikeAddress: boolean;
|
|
132
|
-
/** It shows an address-shaped token that isn't `actualAddress` - e.g. `"ceo@corp.com" <x@corp-pay.com>`. */
|
|
133
|
-
misleading: boolean;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/** Whether a sender's display name poses as an address, and whether that address differs from the one actually sent
|
|
137
|
-
* from. Compatibility forms are folded first (NFKC turns the fullwidth and small @ into `@`), so a look-alike can't
|
|
138
|
-
* hide the token. */
|
|
139
|
-
export function checkSenderName(displayName: string | undefined, actualAddress: string): SenderNameCheck {
|
|
140
|
-
if (!displayName || !AT_SIGN_LIKE.test(displayName)) {
|
|
141
|
-
return { looksLikeAddress: false, misleading: false };
|
|
142
|
-
}
|
|
143
|
-
const shown = /[^\s<>"'(),;:]+@[^\s<>"'(),;:]+/.exec(displayName.normalize("NFKC"))?.[0];
|
|
144
|
-
return { looksLikeAddress: true, misleading: shown !== undefined && shown.toLowerCase() !== actualAddress.toLowerCase() };
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export const TRUST_SIGNER_CONFLICT_MESSAGE =
|
|
148
|
-
"A different signing key is already trusted for this sender, so this one wasn't trusted. The sender's key may have changed; confirm with them before doing anything.";
|
|
149
|
-
export const TRUST_SIGNER_INVALID_MESSAGE = "This certificate can't be trusted for this sender.";
|
|
150
|
-
export const TRUST_SIGNER_FORBIDDEN_MESSAGE = "You don't have permission to trust signers for this mailbox.";
|
|
151
|
-
export const TRUST_SIGNER_GENERIC_MESSAGE = "Couldn't trust this signer. Try again.";
|
|
152
|
-
export const KEPT_CURRENT_SIGNING_KEY_MESSAGE = "You kept the current signing key for this sender. This message stays unverified.";
|
|
153
|
-
|
|
154
|
-
/** The error text for a failed `trustSigner()`. */
|
|
155
|
-
export function trustSignerErrorMessage(err: unknown): string {
|
|
156
|
-
if (err instanceof SignerKeyConflictError) {
|
|
157
|
-
return TRUST_SIGNER_CONFLICT_MESSAGE;
|
|
158
|
-
}
|
|
159
|
-
if (err instanceof ApiRequestError && err.status === 400) {
|
|
160
|
-
return TRUST_SIGNER_INVALID_MESSAGE;
|
|
161
|
-
}
|
|
162
|
-
if (err instanceof ApiRequestError && err.status === 403) {
|
|
163
|
-
return TRUST_SIGNER_FORBIDDEN_MESSAGE;
|
|
164
|
-
}
|
|
165
|
-
return TRUST_SIGNER_GENERIC_MESSAGE;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/** Groups a fingerprint into 4-character blocks (`AB12 CD34 ...`), ignoring any separators it came with, so it can be
|
|
169
|
-
* read out and compared with the sender over another channel. */
|
|
170
|
-
export function formatFingerprint(fingerprint: string): string {
|
|
171
|
-
const compact = fingerprint.replace(/[\s:]/g, "").toUpperCase();
|
|
172
|
-
return compact.match(/.{1,4}/g)?.join(" ") ?? compact;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/** Saves one attachment recovered from inside a signed/encrypted entity. Always handed to the browser as an
|
|
176
|
-
* opaque download (`application/octet-stream`), never rendered in this origin. */
|
|
177
|
-
function downloadMimeAttachment(attachment: MimeAttachment): void {
|
|
178
|
-
// `decode()` is `undefined` only for invalid base64 - an empty file is the honest result then.
|
|
179
|
-
const bytes = attachment.decode() ?? new Uint8Array(0);
|
|
180
|
-
const url = URL.createObjectURL(new Blob([bytes as BlobPart], { type: "application/octet-stream" }));
|
|
181
|
-
const a = document.createElement("a");
|
|
182
|
-
a.href = url;
|
|
183
|
-
a.download = attachment.filename ?? "attachment";
|
|
184
|
-
document.body.appendChild(a);
|
|
185
|
-
a.click();
|
|
186
|
-
a.remove();
|
|
187
|
-
// Some browsers are still reading the blob after `click()` returns.
|
|
188
|
-
setTimeout(() => URL.revokeObjectURL(url), 60_000);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* One of the reading pane's own actions - Reply, Reply All, Forward, Archive, Move to Other - as an icon
|
|
193
|
-
* button. The action's name is its `aria-label` *and* its tooltip, so it has the same accessible name a
|
|
194
|
-
* labelled button had, and is never drawn beside the icon at any width: the row is icon-only everywhere,
|
|
195
|
-
* the way Outlook's own reading-pane command bar is, so it reads the same in the ~396px pane beside the
|
|
196
|
-
* message list and in a maximised window rather than changing shape at a breakpoint.
|
|
197
|
-
*
|
|
198
|
-
* A plain `<button>` rather than react-shared's `Button`, whose padding and minimum width are sized for a
|
|
199
|
-
* text label. Ordinary DOM order, so the keyboard reaches these in the order they are read.
|
|
200
|
-
*/
|
|
201
|
-
function IconAction({
|
|
202
|
-
icon,
|
|
203
|
-
label,
|
|
204
|
-
onClick,
|
|
205
|
-
disabled,
|
|
206
|
-
busy,
|
|
207
|
-
onPrefetch,
|
|
208
|
-
shortcut,
|
|
209
|
-
}: {
|
|
210
|
-
icon: React.ReactNode;
|
|
211
|
-
label: string;
|
|
212
|
-
onClick: () => void;
|
|
213
|
-
disabled?: boolean;
|
|
214
|
-
busy?: boolean;
|
|
215
|
-
/** Called when the pointer or keyboard reaches the button - the moment to start fetching what a click will need. */
|
|
216
|
-
onPrefetch?: () => void;
|
|
217
|
-
/** The keyboard shortcut that does what this button does, when it is registered right now: named in the tooltip (`Reply (Ctrl+R)`) and
|
|
218
|
-
* in `aria-keyshortcuts` - the accessible name stays the bare label. */
|
|
219
|
-
shortcut?: ShortcutDef;
|
|
220
|
-
}) {
|
|
221
|
-
const env = useKeyEnvironment();
|
|
222
|
-
return (
|
|
223
|
-
<button
|
|
224
|
-
type="button"
|
|
225
|
-
aria-label={label}
|
|
226
|
-
title={shortcut ? withHint(label, shortcut, env) : label}
|
|
227
|
-
aria-keyshortcuts={shortcut ? ariaKeyShortcuts(shortcut, env) : undefined}
|
|
228
|
-
aria-busy={busy || undefined}
|
|
229
|
-
disabled={disabled}
|
|
230
|
-
onClick={onClick}
|
|
231
|
-
onPointerEnter={onPrefetch}
|
|
232
|
-
onFocus={onPrefetch}
|
|
233
|
-
className="inline-flex items-center justify-center p-1.5 rounded-md border border-border text-sm text-text hover:bg-surface-alt disabled:opacity-50 disabled:hover:bg-transparent"
|
|
234
|
-
>
|
|
235
|
-
{icon}
|
|
236
|
-
</button>
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function SecurityIndicator({ security }: { security: MessageSecurityResult }) {
|
|
241
|
-
const { label, className } = SECURITY_INDICATOR[security.state];
|
|
242
|
-
if (security.state !== "verified_at_first_open") {
|
|
243
|
-
// Every encrypted state carries a small lock, so the badge reads at a glance; the words are unchanged.
|
|
244
|
-
const encrypted = security.state.startsWith("encrypted");
|
|
245
|
-
return (
|
|
246
|
-
<span className={`inline-flex items-center gap-1 text-xs font-medium shrink-0 py-1 px-2.5 rounded-pill ${className}`}>
|
|
247
|
-
{encrypted && <HiOutlineLockClosed size={12} aria-hidden="true" />}
|
|
248
|
-
{label}
|
|
249
|
-
</span>
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
return (
|
|
253
|
-
<span
|
|
254
|
-
className={`inline-flex items-center gap-1 text-xs font-medium shrink-0 py-1 px-2.5 rounded-pill ${
|
|
255
|
-
security.laterCompromised ? LATER_COMPROMISED_INDICATOR_CLASS : className
|
|
256
|
-
}`}
|
|
257
|
-
>
|
|
258
|
-
{security.laterCompromised ? (
|
|
259
|
-
<HiOutlineExclamationTriangle size={12} aria-hidden="true" />
|
|
260
|
-
) : (
|
|
261
|
-
<HiOutlineCheck size={12} aria-hidden="true" />
|
|
262
|
-
)}
|
|
263
|
-
{label}
|
|
264
|
-
</span>
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/** User-facing explanation for each `signatureFailureReason` - shown alongside the "Signature failed"
|
|
269
|
-
* badge so an unverifiable (e.g. foreign/unparseable) signed message reads as "not verified, and here's
|
|
270
|
-
* why" rather than as a bare error. The body itself stays visible either way. */
|
|
271
|
-
const SIGNATURE_FAILURE_MESSAGE: Record<SignatureFailureReason, string> = {
|
|
272
|
-
invalid_signature:
|
|
273
|
-
"This message's digital signature couldn't be verified - it may be malformed, use an unsupported format, or the content may have been altered after signing. Treat it as unverified.",
|
|
274
|
-
untrusted_signer: "This message was signed with a certificate that doesn't match the sender's known key. Treat it as unverified.",
|
|
275
|
-
// Never shown: the dedicated "signing key changed" notice replaces it. Present so every reason has copy.
|
|
276
|
-
signer_key_changed: "This message was signed with a different key than the one you trust for this sender. Treat it as unverified.",
|
|
277
|
-
signer_identity_mismatch:
|
|
278
|
-
"This message's signing certificate doesn't belong to the sender shown in From. Treat it as unverified.",
|
|
279
|
-
header_mismatch:
|
|
280
|
-
"The sender/recipients this message was signed with don't match its visible From/To, or it repeats a From, To, Cc or Sender header. Treat it as unverified.",
|
|
281
|
-
};
|
|
282
|
-
const GENERIC_SIGNATURE_FAILURE_MESSAGE = "This message's digital signature couldn't be verified. Treat it as unverified.";
|
|
283
|
-
|
|
284
|
-
/** Fallback when the raw MIME for an encrypted message can't even be fetched/evaluated - an encrypted
|
|
285
|
-
* message must never be mislabeled "Unprotected" just because loading failed. */
|
|
286
|
-
const ENCRYPTED_LOAD_ERROR = "Couldn't load this message's encrypted content.";
|
|
287
|
-
|
|
288
|
-
export interface MessageDetailPaneProps {
|
|
289
|
-
message: Message | null;
|
|
290
|
-
attachments: Attachment[];
|
|
291
|
-
/** Present only on the mobile detail route — renders a "back to messages" link above the header. Absent
|
|
292
|
-
* on the desktop reading pane, which never navigates away (selecting a different message just swaps
|
|
293
|
-
* `message` in place). */
|
|
294
|
-
backHref?: string;
|
|
295
|
-
/** Whether `message` currently lives in Sent Items — the only folder recall is offered from, matching
|
|
296
|
-
* Outlook's own restriction (and `BaseMessageRoute.recall()`'s own server-side check). Each caller
|
|
297
|
-
* computes this from its own already-loaded folder list rather than this component fetching folders
|
|
298
|
-
* itself. */
|
|
299
|
-
isSentItems?: boolean;
|
|
300
|
-
/** Called with the server's updated copy (carrying `recallRequestedAt`) after a successful recall, so
|
|
301
|
-
* the caller can patch its own in-memory message/list state — mirrors `mailDetailHooks.ts`'s
|
|
302
|
-
* `useMarkMessageRead`'s identical `onUpdated` callback. */
|
|
303
|
-
onRecalled?: (updated: Message) => void;
|
|
304
|
-
/** Whether `message` currently lives in Outbox — the only folder a scheduled send can be canceled
|
|
305
|
-
* from. Each caller computes this the same way it computes `isSentItems`. */
|
|
306
|
-
isOutbox?: boolean;
|
|
307
|
-
/** The mailbox's Drafts folder uid — required when `isOutbox` is `true`, since canceling a
|
|
308
|
-
* scheduled send moves the message back into Drafts (see `cancelScheduledSend()`'s own doc comment
|
|
309
|
-
* on why clearing `scheduledSendTime` alone doesn't do that). */
|
|
310
|
-
draftsFolderUid?: string;
|
|
311
|
-
/** Called with the server's updated copy (now back in Drafts, `scheduledSendTime` cleared) after
|
|
312
|
-
* successfully canceling a scheduled send. */
|
|
313
|
-
onScheduledSendCanceled?: (updated: Message) => void;
|
|
314
|
-
/** Every folder of this message's own mailbox, for the Move to prompt's destination list. Absent or
|
|
315
|
-
* empty simply hides the control — there is nowhere to move to. Each caller already resolves this to
|
|
316
|
-
* work out `isSentItems`/`isOutbox`/`draftsFolderUid`, so nothing new is fetched for it. */
|
|
317
|
-
folders?: Folder[];
|
|
318
|
-
/** Called with the server's updated copy (now in the chosen folder) after a successful Move to. A move
|
|
319
|
-
* takes the message out of whichever folder is being listed, so callers remove it from their list
|
|
320
|
-
* rather than patching it — unlike `onClassified`, which this replaces. */
|
|
321
|
-
onMoved?: (updated: Message) => void;
|
|
322
|
-
/** A folder created from the Move to prompt, so the caller's own list and the folder sidebar pick it up
|
|
323
|
-
* without a page load. */
|
|
324
|
-
onFolderCreated?: (folder: Folder) => void;
|
|
325
|
-
/** Called with the server's updated copy after approving/declining a pending delivery/read receipt —
|
|
326
|
-
* mirrors `onRecalled`'s identical shape. No gating prop needed (unlike `isSentItems`/`isOutbox`):
|
|
327
|
-
* `deliveryReceiptPending`/`readReceiptPending` already live directly on `message` and are only ever
|
|
328
|
-
* `true` on a real delivered copy, so the banner below is self-gating. */
|
|
329
|
-
onReceiptHandled?: (updated: Message) => void;
|
|
330
|
-
/** Called with the server's updated copy (now filed under the mailbox's Archive folder) after a
|
|
331
|
-
* successful archive — mirrors `onRecalled`'s identical shape. Archiving itself is offered for any
|
|
332
|
-
* message except one currently in Drafts or Outbox (mirrors `BaseMessageRoute.archive()`'s own
|
|
333
|
-
* server-side 400 guard); Drafts is detected via `draftsFolderUid` (already passed by every caller
|
|
334
|
-
* for the Outbox-cancel flow) rather than a new prop. */
|
|
335
|
-
onArchived?: (updated: Message) => void;
|
|
336
|
-
/** Every label defined in this message's mailbox, for the label-assignment popover below — each
|
|
337
|
-
* caller fetches its own mailbox's labels the same way it already resolves `draftsFolderUid`
|
|
338
|
-
* (`listLabels()`). Absent/empty simply hides the Labels control - there's nothing to assign. */
|
|
339
|
-
labels?: Label[];
|
|
340
|
-
/** Called with the server's updated copy (carrying the new `labelUids`) after successfully toggling
|
|
341
|
-
* a label — always patches in place, never removes from a caller's list (unlike `onArchived`):
|
|
342
|
-
* changing labels never moves a message between folders. */
|
|
343
|
-
onLabelsChanged?: (updated: Message) => void;
|
|
344
|
-
/** Handed a label created from the Labels menu, for the caller to add to `labels`. Without it the menu
|
|
345
|
-
* offers no "New label" row, only the link to where labels are managed. */
|
|
346
|
-
onLabelCreated?: (label: Label) => void;
|
|
347
|
-
/** Rendered as one message of a thread (`ConversationThreadPane`) rather than as the pane itself: only its card is drawn - the thread
|
|
348
|
-
* owns the subject card, the scrolling and the `h1` - and the message's own subject appears (as an `h3`) only when it differs from the
|
|
349
|
-
* thread's (`threadSubject`). Everything else - the badges, the actions, the body - is identical. */
|
|
350
|
-
inThread?: boolean;
|
|
351
|
-
/** The thread's subject, for a message of a thread to tell whether its own subject is worth showing. */
|
|
352
|
-
threadSubject?: string;
|
|
353
|
-
/** In a thread, what makes the sender line of this expanded card the button that collapses it: the id of the body it controls, whether the
|
|
354
|
-
* message is unread (which draws the accent bar and tint), what it does, and where to put its ref. */
|
|
355
|
-
threadHeader?: {
|
|
356
|
-
bodyId: string;
|
|
357
|
-
unread: boolean;
|
|
358
|
-
onToggle: () => void;
|
|
359
|
-
buttonRef: (node: HTMLButtonElement | null) => void;
|
|
360
|
-
};
|
|
361
|
-
/** Draw the Reply and Forward buttons at the foot of the card - by default for the single-message pane, and in a thread only where the
|
|
362
|
-
* caller asks (the newest expanded message). */
|
|
363
|
-
footer?: boolean;
|
|
364
|
-
/**
|
|
365
|
-
* Registers this pane's keyboard shortcuts - Reply, Reply all, Forward, Archive, Move to - so they act on this message. Only the message
|
|
366
|
-
* the keyboard is acting on should set it: the one pane beside the list, or the opened message of a thread (each expanded message of a
|
|
367
|
-
* thread is a pane, and two of them must not both claim Ctrl+R). Also puts the shortcut in those buttons' tooltips.
|
|
368
|
-
*/
|
|
369
|
-
shortcuts?: boolean;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/** A subject without its \`Re:\`/\`Fwd:\` prefixes, lower-cased - what makes two messages of one thread the same subject. */
|
|
373
|
-
function subjectCore(subject: string | undefined): string {
|
|
374
|
-
return (subject ?? "").replace(/^(\s*(re|fw|fwd|aw|sv)\s*:)+/i, "").trim().toLowerCase();
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
/** Whether a message's subject says nothing its thread's subject doesn't. */
|
|
378
|
-
function sameSubject(subject: string, threadSubject: string | undefined): boolean {
|
|
379
|
-
return subjectCore(subject) === subjectCore(threadSubject);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
function formatBytes(bytes: number): string {
|
|
383
|
-
if (bytes >= 1_000_000) return `${(bytes / 1_000_000).toFixed(1)} MB`;
|
|
384
|
-
if (bytes >= 1_000) return `${(bytes / 1_000).toFixed(1)} KB`;
|
|
385
|
-
return `${bytes} B`;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
* A message's reading pane - a subject card, and under it the message as a card: header (sender, recipients, time, actions), notices, attachments,
|
|
390
|
-
* the body (`reading/MessageBody`: an isolated frame exactly as tall as its content, or text) and a footer. Rendered with `inThread`, only the card.
|
|
391
|
-
* Shared by the desktop inline pane (`apps/www/index.tsx`, always visible alongside the message list),
|
|
392
|
-
* and the mobile detail route (`apps/www/messages/[uid].tsx`, a full page on its own reached by tapping
|
|
393
|
-
* a message row) — see each call site for how `message`/`attachments`/`isSentItems` are sourced. The
|
|
394
|
-
* desktop pane shows whichever message the list opened, including one opened from a conversation row.
|
|
395
|
-
*/
|
|
396
|
-
export default function MessageDetailPane(props: MessageDetailPaneProps) {
|
|
397
|
-
if (!props.message) {
|
|
398
|
-
return <p className="p-8 text-sm text-text-muted">Select a message to read it.</p>;
|
|
399
|
-
}
|
|
400
|
-
// Keyed by uid so every piece of per-message state below (security result, open modals, in-flight
|
|
401
|
-
// flags, errors) resets cleanly when a caller swaps `message` in place rather than remounting.
|
|
402
|
-
return <MessageDetailContent key={props.message.uid} {...props} message={props.message} />;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
/** Whether a message's raw MIME has to be fetched to evaluate its security state. `encrypted` is the
|
|
406
|
-
* server's own classification; there is no server-side "signed" flag, but every S/MIME-signed shape
|
|
407
|
-
* (detached `multipart/signed`'s `smime.p7s`, opaque-signed `smime.p7m`) is stored with its CMS part
|
|
408
|
-
* surfaced as an attachment - so a message with neither flag can't carry a signature to verify, and
|
|
409
|
-
* fetching its full raw source (attachments included) would be pure waste. */
|
|
410
|
-
function needsRawSecurityEvaluation(message: Message): boolean {
|
|
411
|
-
return !!message.encrypted || message.hasAttachments;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
function MessageDetailContent({
|
|
415
|
-
message: messageProp,
|
|
416
|
-
attachments,
|
|
417
|
-
backHref,
|
|
418
|
-
isSentItems,
|
|
419
|
-
onRecalled,
|
|
420
|
-
isOutbox,
|
|
421
|
-
draftsFolderUid,
|
|
422
|
-
onScheduledSendCanceled,
|
|
423
|
-
folders,
|
|
424
|
-
onMoved,
|
|
425
|
-
onFolderCreated,
|
|
426
|
-
onReceiptHandled,
|
|
427
|
-
onArchived,
|
|
428
|
-
labels,
|
|
429
|
-
onLabelsChanged,
|
|
430
|
-
onLabelCreated,
|
|
431
|
-
inThread,
|
|
432
|
-
threadSubject,
|
|
433
|
-
threadHeader,
|
|
434
|
-
footer,
|
|
435
|
-
shortcuts,
|
|
436
|
-
}: MessageDetailPaneProps & { message: Message }) {
|
|
437
|
-
// A copy re-read from the server after an Outbox action was refused (409/403) or a send lease ran out - see
|
|
438
|
-
// `reloadMessage()`. A prop copy newer by `version` wins; an equal-version reload is kept, since claiming a send
|
|
439
|
-
// lease need not bump `version`.
|
|
440
|
-
const [reloaded, setReloaded] = useState<Message | null>(null);
|
|
441
|
-
const message = reloaded && reloaded.version >= messageProp.version ? reloaded : messageProp;
|
|
442
|
-
// A reload that finds the message already moved on (sent, or moved to Drafts elsewhere) leaves Outbox.
|
|
443
|
-
const inOutbox = !!isOutbox && message.folderUid === messageProp.folderUid;
|
|
444
|
-
const { openCompose } = useCompose();
|
|
445
|
-
const [confirming, setConfirming] = useState(false);
|
|
446
|
-
const [recalling, setRecalling] = useState(false);
|
|
447
|
-
const [canceling, setCanceling] = useState(false);
|
|
448
|
-
const [archiving, setArchiving] = useState(false);
|
|
449
|
-
const [archiveError, setArchiveError] = useState<string | null>(null);
|
|
450
|
-
const [savingLabels, setSavingLabels] = useState(false);
|
|
451
|
-
const [labelsError, setLabelsError] = useState<string | null>(null);
|
|
452
|
-
const [error, setError] = useState<string | null>(null);
|
|
453
|
-
// Kept separate from `error` (the Recall flow's own state) since this renders inline in the main
|
|
454
|
-
// pane rather than inside a confirmation modal — the two flows never need to share one message.
|
|
455
|
-
const [cancelError, setCancelError] = useState<string | null>(null);
|
|
456
|
-
const [movePrompt, setMovePrompt] = useState(false);
|
|
457
|
-
// Names which pending receipt (`"delivery"`/`"read"`) is currently being approved/declined, if any —
|
|
458
|
-
// `deliveryReceiptPending`/`readReceiptPending` can both be true independently, so a single boolean
|
|
459
|
-
// wouldn't distinguish which row's buttons should show a loading state.
|
|
460
|
-
const [receiptBusy, setReceiptBusy] = useState<ReceiptType | null>(null);
|
|
461
|
-
const [receiptError, setReceiptError] = useState<string | null>(null);
|
|
462
|
-
const [security, setSecurity] = useState<MessageSecurityResult | null>(null);
|
|
463
|
-
// Whether the pinned-signer lookup for the sender *succeeded* and found no signing keys - the only case "Trust this
|
|
464
|
-
// signer" is offered in. A failed lookup could be hiding an existing pin, and trusting never replaces one.
|
|
465
|
-
const [senderUnpinned, setSenderUnpinned] = useState(false);
|
|
466
|
-
const [trustConfirmOpen, setTrustConfirmOpen] = useState(false);
|
|
467
|
-
const [trusting, setTrusting] = useState(false);
|
|
468
|
-
const [trustError, setTrustError] = useState<string | null>(null);
|
|
469
|
-
// The sender's stored signing-key state, loaded for a `signer_key_changed` result (the comparison) and for an
|
|
470
|
-
// unverified signer with no pins (a recorded conflict sends the reader to the contact instead of offering trust).
|
|
471
|
-
// `undefined` when not needed or it couldn't be loaded.
|
|
472
|
-
const [senderKeyState, setSenderKeyState] = useState<SenderKeyState | undefined>(undefined);
|
|
473
|
-
// Whether the reader may update this mailbox (resolving a key change needs it) - `undefined` when unknown.
|
|
474
|
-
const [canUpdateMailbox, setCanUpdateMailbox] = useState<boolean | undefined>(undefined);
|
|
475
|
-
// "Keys changed while you were looking" after a 409, or the outcome of keeping the current key. Survives the
|
|
476
|
-
// re-evaluation that follows.
|
|
477
|
-
const [keyChangeNotice, setKeyChangeNotice] = useState<string | null>(null);
|
|
478
|
-
// "Now", for deciding whether a scheduled send's lease is still live - advanced when the lease runs out.
|
|
479
|
-
const [nowMs, setNowMs] = useState(() => Date.now());
|
|
480
|
-
const { mailboxes, trackMessageChange } = useMailShell();
|
|
481
|
-
const { requestUnlock } = useUnlockPrompt();
|
|
482
|
-
// Bumped after a successful on-demand unlock to re-run the effect below - it's not a dependency the
|
|
483
|
-
// effect could read reactively otherwise (getUnlockedKeys() is a plain module-level read, not React
|
|
484
|
-
// state; see keySession.ts's own doc comment).
|
|
485
|
-
const [unlockRefresh, setUnlockRefresh] = useState(0);
|
|
486
|
-
// "View original": this message exactly as its author wrote it instead of adapted to the theme, remembered for the session. Offered only
|
|
487
|
-
// once the body says adapting would change something (`MessageBody`'s `onAdaptable`), or when the reader already chose it.
|
|
488
|
-
const [viewOriginal, setViewOriginal] = useViewOriginal(messageProp.uid);
|
|
489
|
-
const [adaptable, setAdaptable] = useState(viewOriginal);
|
|
490
|
-
// The locked body's Unlock button is waiting on the unlock prompt; and, once it has answered, the focus is to move to the body region.
|
|
491
|
-
const [unlocking, setUnlocking] = useState(false);
|
|
492
|
-
const focusBodyRef = useRef(false);
|
|
493
|
-
const bodyRegionRef = useRef<HTMLDivElement>(null);
|
|
494
|
-
|
|
495
|
-
// The newest copy of this message known to the Labels popover - normally just the `message` prop,
|
|
496
|
-
// but a successful label toggle's server response is held here too, so a follow-up toggle always
|
|
497
|
-
// builds on the latest `labelUids`/`version` even before (or without) the caller patching its own
|
|
498
|
-
// state via `onLabelsChanged`. A prop copy at least as new (by `version`) always wins.
|
|
499
|
-
const [labelsMessage, setLabelsMessage] = useState<Message>(message);
|
|
500
|
-
const currentLabelsMessage = message.version >= labelsMessage.version ? message : labelsMessage;
|
|
501
|
-
const latestLabelsMessageRef = useRef<Message>(message);
|
|
502
|
-
const rawEvaluationNeeded = needsRawSecurityEvaluation(message);
|
|
503
|
-
// Every address the viewing mailbox receives at (primary first), as one string so the effect below only
|
|
504
|
-
// re-runs when they actually change.
|
|
505
|
-
const readerMailbox = mailboxes.find((mb) => mb.uid === message.mailboxUid);
|
|
506
|
-
const readerAddressesKey = readerMailbox ? [readerMailbox.primarySmtpAddress, ...(readerMailbox.aliasAddresses ?? [])].join(" ") : "";
|
|
507
|
-
|
|
508
|
-
// Evaluates a message's security state from its raw MIME - only for a message that can actually be
|
|
509
|
-
// encrypted or signed (see `needsRawSecurityEvaluation()`); anything else is "Unprotected" without a
|
|
510
|
-
// fetch. A detached `multipart/signed` message needs its raw MIME read (a sanitized HTML body never
|
|
511
|
-
// carries the signature part) to tell "Signed & verified" apart from plain "Unprotected". A
|
|
512
|
-
// fetch/parse failure degrades to "Unprotected" (or, for a server-flagged encrypted message, to
|
|
513
|
-
// "Encrypted" with an explanation) rather than hiding the message.
|
|
514
|
-
//
|
|
515
|
-
// `getMessageRawContent()` takes no `AbortSignal`, so a superseded fetch can't be aborted - its
|
|
516
|
-
// result is ignored via `cancelled` instead (and never handed to `evaluateMessageSecurity()`).
|
|
517
|
-
useEffect(() => {
|
|
518
|
-
if (!rawEvaluationNeeded) {
|
|
519
|
-
setSecurity({ state: "unprotected" });
|
|
520
|
-
return;
|
|
521
|
-
}
|
|
522
|
-
let cancelled = false;
|
|
523
|
-
setSecurity(null);
|
|
524
|
-
setSenderUnpinned(false);
|
|
525
|
-
setSenderKeyState(undefined);
|
|
526
|
-
// The sender's trusted signing keys: what key discovery pinned on this mailbox's contacts, plus this
|
|
527
|
-
// mailbox's own signing keys when it sent the message itself. A failed lookup means no pins, which can only
|
|
528
|
-
// ever make a signature "signer not verified", never verified.
|
|
529
|
-
const senderAddress = message.from.address;
|
|
530
|
-
const pinsPromise = getPinnedSignerFingerprints(message.mailboxUid, senderAddress).then(
|
|
531
|
-
(fingerprints) => ({ loaded: true, fingerprints }),
|
|
532
|
-
() => ({ loaded: false, fingerprints: [] as string[] }),
|
|
533
|
-
);
|
|
534
|
-
// Verification seals (see `verificationSeals.ts`) need unlocked keys and the vault's current master key
|
|
535
|
-
// generation; without either the message is evaluated exactly as before, with no seal. The sender's key records
|
|
536
|
-
// are loaded alongside, so a seal can say when the signer key was later revoked as compromised.
|
|
537
|
-
let keyStatePromise: Promise<SenderKeyState | undefined> | undefined;
|
|
538
|
-
const loadKeyState = () => (keyStatePromise ??= getSignerKeyState(message.mailboxUid, senderAddress).catch(() => undefined));
|
|
539
|
-
const sealContextPromise = getUnlockedKeys(message.mailboxUid)
|
|
540
|
-
? getVaultGeneration(message.mailboxUid).then(async (generation) =>
|
|
541
|
-
generation === undefined ? undefined : { generation, keyState: await loadKeyState() },
|
|
542
|
-
)
|
|
543
|
-
: undefined;
|
|
544
|
-
getMessageRawContent(message.uid)
|
|
545
|
-
.then(async (rawMime) => {
|
|
546
|
-
if (cancelled) {
|
|
547
|
-
return;
|
|
548
|
-
}
|
|
549
|
-
// The S/MIME code (PKI.js and the ASN.1/X.509 libraries) loads here, only for a message that is signed or
|
|
550
|
-
// encrypted - it is over half a megabyte, and the pane opens plain messages without it.
|
|
551
|
-
const messageSecurity = await import("@rapidmx/react-shared/crypto/messageSecurity.js");
|
|
552
|
-
const [primaryAddress, ...aliasAddresses] = readerAddressesKey ? readerAddressesKey.split(" ") : [];
|
|
553
|
-
const ownAddresses = readerAddressesKey.toLowerCase().split(" ");
|
|
554
|
-
const ownKeys = ownAddresses.includes(senderAddress.toLowerCase()) ? (readerMailbox!.keys ?? []) : [];
|
|
555
|
-
const ownPins = signingKeyFingerprints(ownKeys);
|
|
556
|
-
const [contactPins, sealContext] = await Promise.all([pinsPromise, sealContextPromise]);
|
|
557
|
-
const pins = [...new Set([...contactPins.fingerprints, ...ownPins])];
|
|
558
|
-
const pinned = pins.length > 0 ? pins : undefined;
|
|
559
|
-
// The raw content is a byte string - only ever handed to evaluateMessageSecurity(), never shown. Keys
|
|
560
|
-
// are read after the pin lookup's await, so a lock that happened meanwhile is honored.
|
|
561
|
-
const unlocked = getUnlockedKeys(message.mailboxUid);
|
|
562
|
-
let result: MessageSecurityResult;
|
|
563
|
-
if (sealContext && unlocked) {
|
|
564
|
-
const signerKeys = [
|
|
565
|
-
...(sealContext.keyState?.pinned ?? []),
|
|
566
|
-
...(sealContext.keyState?.previous ?? []),
|
|
567
|
-
...ownKeys,
|
|
568
|
-
];
|
|
569
|
-
result = await messageSecurity.evaluateMessageSecurityWithSeal(rawMime, unlocked, pinned, primaryAddress, {
|
|
570
|
-
mailboxUid: message.mailboxUid,
|
|
571
|
-
messageUid: message.uid,
|
|
572
|
-
...currentVerificationSeal(message),
|
|
573
|
-
masterKeyGeneration: sealContext.generation,
|
|
574
|
-
signerKeys,
|
|
575
|
-
}).catch(() =>
|
|
576
|
-
// Only a lock while sealing throws: evaluate as locked (the lock itself re-evaluates too).
|
|
577
|
-
messageSecurity.evaluateMessageSecurity(rawMime, undefined, pinned, primaryAddress),
|
|
578
|
-
);
|
|
579
|
-
if (result.sealToWrite) {
|
|
580
|
-
// Best effort and in the background: never awaited, never shown.
|
|
581
|
-
void sendVerificationSeal(message.uid, result.sealToWrite);
|
|
582
|
-
}
|
|
583
|
-
} else {
|
|
584
|
-
result = await messageSecurity.evaluateMessageSecurity(rawMime, unlocked, pinned, primaryAddress);
|
|
585
|
-
}
|
|
586
|
-
// Only one reader address can be checked per evaluation: a message sent to one of this mailbox's
|
|
587
|
-
// aliases isn't "not addressed to you", so each alias is tried before saying so.
|
|
588
|
-
for (const alias of aliasAddresses) {
|
|
589
|
-
if (!result.notAddressedToReader) {
|
|
590
|
-
break;
|
|
591
|
-
}
|
|
592
|
-
const viaAlias = await messageSecurity.evaluateMessageSecurity(rawMime, unlocked, pinned, alias);
|
|
593
|
-
result = { ...result, notAddressedToReader: viaAlias.notAddressedToReader };
|
|
594
|
-
}
|
|
595
|
-
const unpinned = contactPins.loaded && pins.length === 0;
|
|
596
|
-
const keyChanged = signerKeyChanged(result);
|
|
597
|
-
const [keyState, access] = await Promise.all([
|
|
598
|
-
keyChanged || (unpinned && UNVERIFIED_SIGNER_STATES.has(result.state)) ? loadKeyState() : undefined,
|
|
599
|
-
keyChanged ? getMyMailboxAccess(message.mailboxUid).then((a) => a.canUpdate, () => undefined) : undefined,
|
|
600
|
-
]);
|
|
601
|
-
if (!cancelled) {
|
|
602
|
-
setSecurity(result);
|
|
603
|
-
setSenderUnpinned(unpinned);
|
|
604
|
-
setSenderKeyState(keyState);
|
|
605
|
-
setCanUpdateMailbox(access);
|
|
606
|
-
}
|
|
607
|
-
})
|
|
608
|
-
.catch(() => {
|
|
609
|
-
if (!cancelled) {
|
|
610
|
-
setSecurity(
|
|
611
|
-
message.encrypted ? { state: "encrypted", decryptError: ENCRYPTED_LOAD_ERROR } : { state: "unprotected" },
|
|
612
|
-
);
|
|
613
|
-
}
|
|
614
|
-
});
|
|
615
|
-
return () => {
|
|
616
|
-
cancelled = true;
|
|
617
|
-
};
|
|
618
|
-
}, [message.uid, message.mailboxUid, message.from.address, message.encrypted, rawEvaluationNeeded, unlockRefresh, readerAddressesKey]);
|
|
619
|
-
|
|
620
|
-
// Whether the body is the locked state right now (an encrypted message this device holds no unlocked keys for), for the subscription below.
|
|
621
|
-
const lockedRef = useRef(false);
|
|
622
|
-
lockedRef.current = security?.decryptError !== undefined && !getUnlockedKeys(message.mailboxUid);
|
|
623
|
-
|
|
624
|
-
// After an unlock from the button, the message (or the reason it can't be read) is where the reader's attention is: the focus moves to it once it is
|
|
625
|
-
// there, since the button that had it is gone.
|
|
626
|
-
useEffect(() => {
|
|
627
|
-
if (focusBodyRef.current && security !== null) {
|
|
628
|
-
focusBodyRef.current = false;
|
|
629
|
-
bodyRegionRef.current?.focus({ preventScroll: true });
|
|
630
|
-
}
|
|
631
|
-
}, [security]);
|
|
632
|
-
|
|
633
|
-
// Decrypted plaintext must not outlive the key session that produced it: the moment this mailbox's
|
|
634
|
-
// keys are destroyed (logout, idle timeout, explicit lock), drop the recovered html/text and
|
|
635
|
-
// re-evaluate - an encrypted message then falls back to its locked state. And the other way round: keys unlocked
|
|
636
|
-
// from anywhere (compose, another message, the unlock prompt) open a message that was waiting on them, in place.
|
|
637
|
-
useEffect(
|
|
638
|
-
() =>
|
|
639
|
-
subscribeKeySession((event) => {
|
|
640
|
-
if (event.mailboxUid !== message.mailboxUid) {
|
|
641
|
-
return;
|
|
642
|
-
}
|
|
643
|
-
if (event.state === "locked") {
|
|
644
|
-
setSecurity(null);
|
|
645
|
-
setUnlockRefresh((n) => n + 1);
|
|
646
|
-
} else if (lockedRef.current) {
|
|
647
|
-
setUnlockRefresh((n) => n + 1);
|
|
648
|
-
}
|
|
649
|
-
}),
|
|
650
|
-
[message.mailboxUid],
|
|
651
|
-
);
|
|
652
|
-
|
|
653
|
-
// While restapi's ScheduledSendJob holds a send lease the message is being relayed: cancelling or moving it would be
|
|
654
|
-
// refused (409/403), so the Outbox controls are replaced by "Sending...". When the lease runs out the message is
|
|
655
|
-
// re-read - it has either been sent (and left Outbox) or been released back to its schedule.
|
|
656
|
-
const leaseExpiresMs = message.scheduledSendLeaseExpiresAt ? Date.parse(message.scheduledSendLeaseExpiresAt) : NaN;
|
|
657
|
-
const sendInProgress = inOutbox && leaseExpiresMs > nowMs;
|
|
658
|
-
useEffect(() => {
|
|
659
|
-
if (!sendInProgress) {
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
662
|
-
const timer = setTimeout(() => {
|
|
663
|
-
setNowMs(Date.now());
|
|
664
|
-
void reloadMessage();
|
|
665
|
-
}, leaseExpiresMs - nowMs + 1);
|
|
666
|
-
return () => clearTimeout(timer);
|
|
667
|
-
}, [sendInProgress, leaseExpiresMs, nowMs]);
|
|
668
|
-
|
|
669
|
-
async function reloadMessage() {
|
|
670
|
-
try {
|
|
671
|
-
setReloaded(await getMessage(message.uid));
|
|
672
|
-
setNowMs(Date.now());
|
|
673
|
-
} catch {
|
|
674
|
-
// Keep showing what we have - the next refused action or lease expiry tries again.
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
// Offered only when this device genuinely has no unlocked session for this message's mailbox at all
|
|
679
|
-
// (as opposed to being unlocked but still unable to decrypt - a wrong/since-rotated key, which
|
|
680
|
-
// re-unlocking the same session can't fix) - see `evaluateMessageSecurity()`'s own doc comment on why
|
|
681
|
-
// `decryptError` alone can't distinguish those two cases.
|
|
682
|
-
async function handleUnlockToView() {
|
|
683
|
-
const mailboxUid = message.mailboxUid;
|
|
684
|
-
const mailboxKeys = mailboxes.find((mb) => mb.uid === mailboxUid)?.keys ?? [];
|
|
685
|
-
setUnlocking(true);
|
|
686
|
-
try {
|
|
687
|
-
await requestUnlock(mailboxUid, mailboxKeys);
|
|
688
|
-
// The Unlock button is about to be replaced by the message (or by why it can't be read): the focus goes there, once it has been evaluated.
|
|
689
|
-
focusBodyRef.current = true;
|
|
690
|
-
setUnlockRefresh((n) => n + 1);
|
|
691
|
-
} catch {
|
|
692
|
-
// User dismissed the unlock dialog - security state stays exactly as it was.
|
|
693
|
-
} finally {
|
|
694
|
-
setUnlocking(false);
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
// Only ever invoked from the "Trust this signer" dialog, which only opens for an unverified-signer result carrying
|
|
699
|
-
// `signerCertificate`. The pin goes on the contact in the mailbox the message belongs to; the evaluation is then
|
|
700
|
-
// re-run against a fresh pinned-signer lookup, so the badge turns verified.
|
|
701
|
-
async function handleTrustSigner(address: string, certificate: string) {
|
|
702
|
-
setTrusting(true);
|
|
703
|
-
setTrustError(null);
|
|
704
|
-
try {
|
|
705
|
-
await trustSigner(message.mailboxUid, { address, certificate });
|
|
706
|
-
clearPinnedSignerCache();
|
|
707
|
-
setTrustConfirmOpen(false);
|
|
708
|
-
setUnlockRefresh((n) => n + 1);
|
|
709
|
-
} catch (err) {
|
|
710
|
-
setTrustError(trustSignerErrorMessage(err));
|
|
711
|
-
} finally {
|
|
712
|
-
setTrusting(false);
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
// After a key change was accepted or kept (or the pinned key moved meanwhile): the pinned signers are re-read and
|
|
717
|
-
// the message re-evaluated, so an accepted key turns the badge verified.
|
|
718
|
-
function refreshAfterKeyChange(notice: string | null) {
|
|
719
|
-
setKeyChangeNotice(notice);
|
|
720
|
-
clearPinnedSignerCache();
|
|
721
|
-
setUnlockRefresh((n) => n + 1);
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
// Reply, Reply All and Forward first load the full body to quote (see `loadQuotedBody()`), so the buttons are
|
|
725
|
-
// disabled meanwhile - a second click would open a second window. An encrypted original keeps its reply
|
|
726
|
-
// encrypted, since the quote may carry its decrypted content.
|
|
727
|
-
const [preparingCompose, setPreparingCompose] = useState(false);
|
|
728
|
-
|
|
729
|
-
/** The replying mailbox's own addresses (primary and aliases), which a reply never goes to - from the mail shell's
|
|
730
|
-
* mailbox list, else fetched; none when neither is available. */
|
|
731
|
-
async function ownAddresses(): Promise<string[]> {
|
|
732
|
-
const mailbox = readerMailbox ?? (await getMailbox(message.mailboxUid).catch(() => undefined));
|
|
733
|
-
return mailbox ? [mailbox.primarySmtpAddress, ...(mailbox.aliasAddresses ?? [])] : [];
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
/** Starts fetching what Reply/Reply All/Forward will need (the compose window's code, the original's body) as the
|
|
737
|
-
* pointer or keyboard reaches one of their buttons, so the click itself finds it already on its way or here. */
|
|
738
|
-
function prefetchReply() {
|
|
739
|
-
prefetchComposeWindow();
|
|
740
|
-
prefetchOriginalMessage(message);
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
/**
|
|
744
|
-
* Opens the compose window at once from what is already in memory - the message's own subject and sender, and the
|
|
745
|
-
* mailbox it was read in - and fetches what needs the network meanwhile: the original's body to quote, and for Reply All
|
|
746
|
-
* the recipients its headers name. Both reach the window through `OpenComposeInput.pending` when they arrive, so the
|
|
747
|
-
* window is on screen on the click's own frame rather than after two or three sequential requests.
|
|
748
|
-
*/
|
|
749
|
-
async function handleReplyOrForward(kind: "reply" | "replyAll" | "forward") {
|
|
750
|
-
setPreparingCompose(true);
|
|
751
|
-
try {
|
|
752
|
-
const encrypt = !!message.encrypted;
|
|
753
|
-
// What makes the new message part of this one's thread rather than a conversation of its own:
|
|
754
|
-
// the server composes the MIME from the recipients, subject and HTML alone, so nothing else
|
|
755
|
-
// recovers what is being replied to. A forward carries it for the same reason - it continues
|
|
756
|
-
// the thread it came from, which is where its recipient will file the reply to it.
|
|
757
|
-
const threading = buildReplyThreading(message);
|
|
758
|
-
const format = (list: Recipient[]) => list.map((r) => formatRecipient(r)).join(", ");
|
|
759
|
-
// Known without a request when the shell has already listed the mailbox; otherwise fetched with the body, and
|
|
760
|
-
// the window's recipients are corrected by `late` below if that changes who they are.
|
|
761
|
-
const knownOwn = readerAddressesKey ? readerAddressesKey.split(" ") : undefined;
|
|
762
|
-
// Never rejects: loadOriginalMessage() and ownAddresses() don't, and the rest is pure.
|
|
763
|
-
const late = (async (): Promise<ComposeLateInput> => {
|
|
764
|
-
const [original, own] = await Promise.all([
|
|
765
|
-
loadOriginalMessage(message, security, { recipients: kind === "replyAll" }),
|
|
766
|
-
kind === "forward" ? [] : (knownOwn ?? ownAddresses()),
|
|
767
|
-
]);
|
|
768
|
-
if (kind === "forward") {
|
|
769
|
-
return { quotedHtml: buildForwardQuote(message, original.body) };
|
|
770
|
-
}
|
|
771
|
-
// The message's own recipients are only the envelope recipient of a delivered message, so Reply All
|
|
772
|
-
// answers whoever its headers actually name, with anything the record holds that they don't.
|
|
773
|
-
const known = new Set((original.recipients ?? []).map((r) => r.address.trim().toLowerCase()));
|
|
774
|
-
const recipients = buildReplyRecipients(
|
|
775
|
-
{ ...message, recipients: [...(original.recipients ?? []), ...message.recipients.filter((r) => !known.has(r.address.trim().toLowerCase()))] },
|
|
776
|
-
own,
|
|
777
|
-
kind === "replyAll",
|
|
778
|
-
);
|
|
779
|
-
return { quotedHtml: buildReplyQuote(message, original.body), to: format(recipients.to), cc: format(recipients.cc) };
|
|
780
|
-
})();
|
|
781
|
-
if (kind === "forward") {
|
|
782
|
-
openCompose({
|
|
783
|
-
mailboxUid: message.mailboxUid,
|
|
784
|
-
subject: forwardSubject(message.subject),
|
|
785
|
-
signatureContext: "reply_forward",
|
|
786
|
-
encrypt,
|
|
787
|
-
threading,
|
|
788
|
-
pending: late,
|
|
789
|
-
});
|
|
790
|
-
} else {
|
|
791
|
-
const first = buildReplyRecipients(message, knownOwn ?? [], kind === "replyAll");
|
|
792
|
-
openCompose({
|
|
793
|
-
mailboxUid: message.mailboxUid,
|
|
794
|
-
to: format(first.to),
|
|
795
|
-
cc: first.cc.length > 0 ? format(first.cc) : undefined,
|
|
796
|
-
subject: replySubject(message.subject),
|
|
797
|
-
signatureContext: "reply_forward",
|
|
798
|
-
suppressSigning: isLikelyMailingList({ listUnsubscribe: message.listUnsubscribeHeader }),
|
|
799
|
-
encrypt,
|
|
800
|
-
threading,
|
|
801
|
-
pending: late,
|
|
802
|
-
});
|
|
803
|
-
}
|
|
804
|
-
// Held until the quote is in, so a second click can't open a second window for the same message meanwhile.
|
|
805
|
-
await late;
|
|
806
|
-
} finally {
|
|
807
|
-
setPreparingCompose(false);
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
async function handleRecall() {
|
|
812
|
-
// Only ever invoked from the confirmation modal below, which itself only renders once `message`
|
|
813
|
-
// is loaded (the early return above covers the only other state) — the non-null assertion
|
|
814
|
-
// reflects that real invariant, matching this codebase's established pattern for the same class
|
|
815
|
-
// of always-true-in-practice guard.
|
|
816
|
-
setRecalling(true);
|
|
817
|
-
setError(null);
|
|
818
|
-
try {
|
|
819
|
-
const updated = await recallMessage(message.uid);
|
|
820
|
-
setConfirming(false);
|
|
821
|
-
onRecalled?.(updated);
|
|
822
|
-
} catch (err) {
|
|
823
|
-
setError(err instanceof ApiRequestError ? err.message : "Could not recall this message.");
|
|
824
|
-
} finally {
|
|
825
|
-
setRecalling(false);
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
// Only ever invoked from the "Cancel" button below (`isOutbox` and `message.scheduledSendTime` both truthy -
|
|
830
|
-
// `draftsFolderUid` is required whenever `isOutbox` is, see the prop's own doc comment), or from "Move to
|
|
831
|
-
// Drafts" (an Outbox message with no active schedule, which checks `draftsFolderUid` itself), so the non-null
|
|
832
|
-
// assertion reflects a real invariant, matching `handleRecall`'s identical pattern just above.
|
|
833
|
-
async function handleCancelScheduledSend() {
|
|
834
|
-
setCanceling(true);
|
|
835
|
-
setCancelError(null);
|
|
836
|
-
try {
|
|
837
|
-
const updated = await cancelScheduledSend(message, draftsFolderUid!);
|
|
838
|
-
// Keeps a `folder:`-scoped Tier 2 local search from still finding it in its old folder.
|
|
839
|
-
void moveLocalEntity(updated.mailboxUid, updated.uid, updated.folderUid);
|
|
840
|
-
// Out of Outbox, into Drafts: both folders' badges.
|
|
841
|
-
trackMessageChange(message, updated).settle();
|
|
842
|
-
onScheduledSendCanceled?.(updated);
|
|
843
|
-
} catch (err) {
|
|
844
|
-
const fallback = message.scheduledSendTime ? "Could not cancel this scheduled send." : "Could not move this message to Drafts.";
|
|
845
|
-
setCancelError(err instanceof ApiRequestError ? err.message : fallback);
|
|
846
|
-
// A conflict or refusal usually means the send job claimed (or already relayed) the message meanwhile -
|
|
847
|
-
// re-read it so the pane shows "Sending..." or its new state instead of the stale controls.
|
|
848
|
-
if (err instanceof ApiRequestError && (err.status === 409 || err.status === 403)) {
|
|
849
|
-
void reloadMessage();
|
|
850
|
-
}
|
|
851
|
-
} finally {
|
|
852
|
-
setCanceling(false);
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
// Only ever invoked from the Archive button below, which itself only renders once `message` is
|
|
857
|
-
// loaded and this isn't a Drafts/Outbox message (the button's own guard mirrors
|
|
858
|
-
// `BaseMessageRoute.archive()`'s server-side 400) — same real invariant as `handleRecall` above.
|
|
859
|
-
async function handleArchive() {
|
|
860
|
-
setArchiving(true);
|
|
861
|
-
setArchiveError(null);
|
|
862
|
-
try {
|
|
863
|
-
const updated = await archiveMessage(message.uid);
|
|
864
|
-
void moveLocalEntity(updated.mailboxUid, updated.uid, updated.folderUid);
|
|
865
|
-
trackMessageChange(message, updated).settle();
|
|
866
|
-
onArchived?.(updated);
|
|
867
|
-
} catch (err) {
|
|
868
|
-
setArchiveError(err instanceof ApiRequestError ? err.message : "Could not archive this message.");
|
|
869
|
-
} finally {
|
|
870
|
-
setArchiving(false);
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
// Only ever invoked from the Labels menu below, which itself only renders once `message` is loaded.
|
|
875
|
-
// Several labels are ticked in the menu and saved together here, in one `setMessageLabels()` call:
|
|
876
|
-
// that call replaces the whole `labelUids` list rather than patching one entry, so a menu that saved
|
|
877
|
-
// per tick would send a request (and burn an optimistic-lock `version`) for every single tick.
|
|
878
|
-
//
|
|
879
|
-
// The list is computed from the newest copy known (`latestLabelsMessageRef`, never a stale render
|
|
880
|
-
// closure), so a save that follows another still carries the `version` the server last handed back.
|
|
881
|
-
async function handleApplyLabels(labelUids: string[]) {
|
|
882
|
-
setSavingLabels(true);
|
|
883
|
-
setLabelsError(null);
|
|
884
|
-
try {
|
|
885
|
-
const base = message.version >= latestLabelsMessageRef.current.version ? message : latestLabelsMessageRef.current;
|
|
886
|
-
const updated = await setMessageLabels(base, labelUids);
|
|
887
|
-
latestLabelsMessageRef.current = updated;
|
|
888
|
-
setLabelsMessage(updated);
|
|
889
|
-
onLabelsChanged?.(updated);
|
|
890
|
-
} catch (err) {
|
|
891
|
-
setLabelsError(err instanceof ApiRequestError ? err.message : "Could not update this message's labels.");
|
|
892
|
-
} finally {
|
|
893
|
-
setSavingLabels(false);
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
/**
|
|
898
|
-
* Moves this message into the folder picked in the Move to prompt. Deliberately *not* caught here:
|
|
899
|
-
* `MoveToFolderDialog` shows a failure beside the destination that would retry it, and closes only
|
|
900
|
-
* once the move has actually landed.
|
|
901
|
-
*
|
|
902
|
-
* The move is awaited on its own line rather than written as `onMoved?.(await moveMessage(...))` -
|
|
903
|
-
* an optional call whose callee is absent never evaluates its arguments at all, so a caller that
|
|
904
|
-
* passes no `onMoved` would have had nothing moved while the prompt closed as if it had.
|
|
905
|
-
*/
|
|
906
|
-
async function handleMove(folderUid: string) {
|
|
907
|
-
const updated = await moveMessage(message, folderUid);
|
|
908
|
-
// Move to, Delete and Report junk are all this: the source folder's badge goes down, the target's up.
|
|
909
|
-
trackMessageChange(message, updated).settle();
|
|
910
|
-
onMoved?.(updated);
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
// Keyboard shortcuts for the message this pane shows. They call the same handlers as the buttons below, and exist only where the
|
|
914
|
-
// button does (Archive not for Drafts/Outbox, Move to only with folders to move to). A shortcut pressed while its action is already
|
|
915
|
-
// running is consumed and does nothing, exactly as the disabled button would: a browser must not act on Ctrl+R meanwhile.
|
|
916
|
-
const archivable = !inOutbox && message.folderUid !== draftsFolderUid;
|
|
917
|
-
const movable = !!folders && folders.length > 0;
|
|
918
|
-
const keyboard = !!shortcuts;
|
|
919
|
-
useShortcut(SHORTCUTS.mail.reply, () => void (!preparingCompose && handleReplyOrForward("reply")), { enabled: keyboard });
|
|
920
|
-
useShortcut(SHORTCUTS.mail.replyAll, () => void (!preparingCompose && handleReplyOrForward("replyAll")), { enabled: keyboard });
|
|
921
|
-
useShortcut(SHORTCUTS.mail.forward, () => void (!preparingCompose && handleReplyOrForward("forward")), { enabled: keyboard });
|
|
922
|
-
useShortcut(SHORTCUTS.mail.archive, () => void (!archiving && handleArchive()), { enabled: keyboard && archivable });
|
|
923
|
-
useShortcut(SHORTCUTS.mail.move, () => setMovePrompt(true), { enabled: keyboard && movable });
|
|
924
|
-
|
|
925
|
-
// Only ever invoked from the pending-receipt banner below, which itself only renders once `message`
|
|
926
|
-
// is loaded — same real invariant as every other handler above.
|
|
927
|
-
async function handleReceipt(type: ReceiptType, action: "approve" | "decline") {
|
|
928
|
-
setReceiptBusy(type);
|
|
929
|
-
setReceiptError(null);
|
|
930
|
-
try {
|
|
931
|
-
const updated = await (action === "approve" ? approveReceipt : declineReceipt)(message.uid, type);
|
|
932
|
-
onReceiptHandled?.(updated);
|
|
933
|
-
} catch (err) {
|
|
934
|
-
setReceiptError(err instanceof ApiRequestError ? err.message : "Could not handle this receipt request.");
|
|
935
|
-
} finally {
|
|
936
|
-
setReceiptBusy(null);
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
const verified = security !== null && VERIFIED_STATES.has(security.state);
|
|
941
|
-
// A seal proves the signature verified when first opened, and the live check still passed everything but the signer
|
|
942
|
-
// key's status - so the signed Subject and attachments are shown as for a verified message, under its own badge.
|
|
943
|
-
const verifiedOrSealed = verified || security?.state === "verified_at_first_open";
|
|
944
|
-
// Under a verified badge, the Subject shown is the one the signature covers (RFC 9788 protected headers), when
|
|
945
|
-
// the message carries one - the outer Subject is unsigned and anyone relaying the message could change it.
|
|
946
|
-
const protectedSubject = verifiedOrSealed ? security.protectedHeaders?.subject : undefined;
|
|
947
|
-
// Only meaningful for signed-only mail: an encrypted message's outer Subject is deliberately obscured. Not a
|
|
948
|
-
// signature failure (mailing lists legitimately tag subjects), just worth pointing out.
|
|
949
|
-
const subjectDiffers = protectedSubject !== undefined && (security!.state === "signed_verified" || security!.sealedState === "signed_verified") && protectedSubject !== message.subject;
|
|
950
|
-
// Attachments inside the signed/decrypted entity. Under a verified badge only these are listed - the server's
|
|
951
|
-
// attachment records also include parts outside the signature, which the badge doesn't vouch for. For decrypted
|
|
952
|
-
// mail the server only ever saw the encrypted blob, so these are the real attachments.
|
|
953
|
-
// A decrypted message whose signature failed still only has these (the server list is just `smime.p7m`); they're
|
|
954
|
-
// listed with a warning. A signed-only failure never carries recovered attachments.
|
|
955
|
-
const innerAttachments =
|
|
956
|
-
security?.attachments !== undefined &&
|
|
957
|
-
(verifiedOrSealed || security.state === "encrypted" || security.state === "encrypted_unverified_signer" || security.state === "signature_failed")
|
|
958
|
-
? security.attachments
|
|
959
|
-
: undefined;
|
|
960
|
-
// Any state that involves a signature shows the address actually signed for (the protected From when the message
|
|
961
|
-
// carries one - it equals the outer From's address, or verification would have failed) next to the badge, never a
|
|
962
|
-
// display name alone: anyone can put "ceo@corp.com" in the name of a message sent from x@corp-pay.com.
|
|
963
|
-
const signatureShown = security !== null && security.state !== "unprotected" && security.state !== "encrypted";
|
|
964
|
-
const senderAddress = (signatureShown ? extractAddresses(security.protectedHeaders?.from)[0] : undefined) ?? message.from.address;
|
|
965
|
-
const senderName = message.from.displayName;
|
|
966
|
-
const senderNameCheck = checkSenderName(senderName, senderAddress);
|
|
967
|
-
// Always `Name <address>` (or the bare address): a name alone hides who a message is really from.
|
|
968
|
-
const senderLabel = formatMailAddress({ displayName: senderName, address: senderAddress });
|
|
969
|
-
// Offered only for a valid signature from a certificate nobody pinned for this sender - never to replace a pin.
|
|
970
|
-
// A recorded signing-key conflict for this sender is resolved from the contact, never by trusting another key.
|
|
971
|
-
const pendingConflict = senderUnpinned && senderKeyState?.conflict !== undefined;
|
|
972
|
-
const trustableCertificate =
|
|
973
|
-
security !== null && UNVERIFIED_SIGNER_STATES.has(security.state) && senderUnpinned && !pendingConflict
|
|
974
|
-
? security.signerCertificate
|
|
975
|
-
: undefined;
|
|
976
|
-
const keyChanged = security && signerKeyChanged(security) ? security : undefined;
|
|
977
|
-
const pinnedSignerKey = senderKeyState?.pinned[0];
|
|
978
|
-
const recordedConflict =
|
|
979
|
-
keyChanged && sameFingerprint(senderKeyState?.conflict?.observedKey.fingerprint, keyChanged.signerFingerprint)
|
|
980
|
-
? senderKeyState!.conflict
|
|
981
|
-
: undefined;
|
|
982
|
-
|
|
983
|
-
const shownSubject = (protectedSubject ?? displaySubject(message.subject)) || "(no subject)";
|
|
984
|
-
// What the body area shows. Text or HTML the client recovered from a signed or encrypted message is shown as it is (its own sanitizing
|
|
985
|
-
// happens in `MessageBody`, like every body's); anything else is the server's own `/content`. An encrypted message has nothing worth
|
|
986
|
-
// fetching until it has been decrypted (the server only has the ciphertext), so it shows the skeleton meanwhile.
|
|
987
|
-
const bodyContent: BodyContent | undefined =
|
|
988
|
-
security?.text !== undefined
|
|
989
|
-
? { kind: "text", text: security.text }
|
|
990
|
-
: security?.html !== undefined
|
|
991
|
-
? { kind: "html", html: security.html }
|
|
992
|
-
: undefined;
|
|
993
|
-
const bodyTitle = message.subject || "Message content";
|
|
994
|
-
const answered = message.flags.answered === true;
|
|
995
|
-
const forwarded = message.flags.forwarded === true;
|
|
996
|
-
const cardUnread = threadHeader?.unread ?? false;
|
|
997
|
-
const showFooter = footer ?? !inThread;
|
|
998
|
-
// Only a message the server can read and that carries a calendar file is worth asking about an invitation. An encrypted message is out: the
|
|
999
|
-
// server holds only its ciphertext (the calendar file is inside it), so there is nothing for it to find. Drafts and Outbox hold messages
|
|
1000
|
-
// that are being written or sent, not received invitations.
|
|
1001
|
-
const mayHoldInvite = !message.encrypted && !inOutbox && message.folderUid !== draftsFolderUid && attachments.some(isCalendarAttachment);
|
|
1002
|
-
// The calendar file of a message whose invitation card is drawn is the card, not a chip in the attachment list (a nameless "attachment" to click):
|
|
1003
|
-
// it is listed again if the card could not be drawn (no invitation the server can read, or the lookup failed), so the file is never out of reach.
|
|
1004
|
-
const { invite: shownInvite } = useMessageInvite(message.uid, mayHoldInvite);
|
|
1005
|
-
const listedAttachments = shownInvite ? attachments.filter((attachment) => !isCalendarAttachment(attachment)) : attachments;
|
|
1006
|
-
|
|
1007
|
-
const senderRecipient = { displayName: senderName, address: senderAddress };
|
|
1008
|
-
const sendingStatus = (
|
|
1009
|
-
<>
|
|
1010
|
-
{sendInProgress && (
|
|
1011
|
-
<span className="text-xs font-medium text-text-muted shrink-0 py-1 px-2.5 rounded-pill bg-surface-alt">Sending…</span>
|
|
1012
|
-
)}
|
|
1013
|
-
{isSentItems &&
|
|
1014
|
-
(message.recallRequestedAt ? (
|
|
1015
|
-
<span className="text-xs font-medium text-text-muted shrink-0 py-1 px-2.5 rounded-pill bg-surface-alt">Recall requested</span>
|
|
1016
|
-
) : (
|
|
1017
|
-
<Button type="button" variant="secondary" className="!w-auto shrink-0" onClick={() => setConfirming(true)}>
|
|
1018
|
-
Recall this message
|
|
1019
|
-
</Button>
|
|
1020
|
-
))}
|
|
1021
|
-
{inOutbox && !sendInProgress && message.scheduledSendTime && (
|
|
1022
|
-
<div className="flex items-center gap-2 shrink-0">
|
|
1023
|
-
<span className="text-xs font-medium text-text-muted py-1 px-2.5 rounded-pill bg-surface-alt">
|
|
1024
|
-
Scheduled for {new Date(message.scheduledSendTime).toLocaleString()}
|
|
1025
|
-
</span>
|
|
1026
|
-
<Button type="button" variant="secondary" className="!w-auto" loading={canceling} disabled={canceling} onClick={handleCancelScheduledSend}>
|
|
1027
|
-
Cancel
|
|
1028
|
-
</Button>
|
|
1029
|
-
</div>
|
|
1030
|
-
)}
|
|
1031
|
-
{/* A message left in Outbox with no active schedule - a scheduled send that failed or was refused
|
|
1032
|
-
(restapi's ScheduledSendJob clears scheduledSendTime and leaves it there), which can't be sent
|
|
1033
|
-
again from Outbox (409) or archived - would otherwise be stuck. Moving it back to Drafts works for
|
|
1034
|
-
any Outbox message. */}
|
|
1035
|
-
{inOutbox && !sendInProgress && !message.scheduledSendTime && draftsFolderUid && (
|
|
1036
|
-
<Button type="button" variant="secondary" className="!w-auto shrink-0" loading={canceling} disabled={canceling} onClick={handleCancelScheduledSend}>
|
|
1037
|
-
Move to Drafts
|
|
1038
|
-
</Button>
|
|
1039
|
-
)}
|
|
1040
|
-
</>
|
|
1041
|
-
);
|
|
1042
|
-
|
|
1043
|
-
const card = (
|
|
1044
|
-
<CardShell unread={cardUnread}>
|
|
1045
|
-
{/* Header row: who it is from, when, and what can be done with it. Wraps: on a phone the actions drop under the sender. */}
|
|
1046
|
-
<div className={["flex flex-wrap items-start gap-x-3 gap-y-1 px-4 pt-3 pb-2", cardUnread ? "bg-primary/[0.07]" : ""].join(" ")}>
|
|
1047
|
-
<SenderAvatar from={senderRecipient} />
|
|
1048
|
-
<div className="flex-1 min-w-[12rem]">
|
|
1049
|
-
<div className="flex flex-wrap items-center gap-x-2 gap-y-1">
|
|
1050
|
-
{threadHeader ? (
|
|
1051
|
-
// The sender line of a message in a thread is the button that collapses it again.
|
|
1052
|
-
<h2 className="min-w-0 flex-1" style={BODY_FONT_STYLE}>
|
|
1053
|
-
<button
|
|
1054
|
-
type="button"
|
|
1055
|
-
ref={threadHeader.buttonRef}
|
|
1056
|
-
onClick={threadHeader.onToggle}
|
|
1057
|
-
aria-expanded={true}
|
|
1058
|
-
aria-controls={threadHeader.bodyId}
|
|
1059
|
-
className={[
|
|
1060
|
-
"w-full text-left rounded-sm text-sm",
|
|
1061
|
-
ROW_FOCUS_CLASS,
|
|
1062
|
-
].join(" ")}
|
|
1063
|
-
>
|
|
1064
|
-
<UnreadLabel unread={cardUnread} />
|
|
1065
|
-
<MailAddress recipient={senderRecipient} className={senderClass(cardUnread)} />
|
|
1066
|
-
</button>
|
|
1067
|
-
</h2>
|
|
1068
|
-
) : (
|
|
1069
|
-
<p className="text-sm break-words min-w-0">
|
|
1070
|
-
From <span className="font-semibold text-text">{senderLabel}</span>
|
|
1071
|
-
</p>
|
|
1072
|
-
)}
|
|
1073
|
-
{security && <SecurityIndicator security={security} />}
|
|
1074
|
-
</div>
|
|
1075
|
-
{senderNameCheck.misleading && (
|
|
1076
|
-
<p role="status" className="mt-2 py-2 px-3 rounded-sm text-sm bg-warning/15 text-text">
|
|
1077
|
-
The sender’s name “{senderName}” looks like an email address, but this message was
|
|
1078
|
-
sent from <span className="font-medium">{senderAddress}</span>. Don’t trust it based on the name.
|
|
1079
|
-
</p>
|
|
1080
|
-
)}
|
|
1081
|
-
{/* Every recipient with their address, grouped as the sender addressed them; a long list folds. */}
|
|
1082
|
-
<RecipientLine label="To" recipients={message.recipients.filter((r) => r.type !== "cc" && r.type !== "bcc")} />
|
|
1083
|
-
<RecipientLine label="Cc" recipients={message.recipients.filter((r) => r.type === "cc")} />
|
|
1084
|
-
<RecipientLine label="Bcc" recipients={message.recipients.filter((r) => r.type === "bcc")} />
|
|
1085
|
-
</div>
|
|
1086
|
-
<div className="ml-auto flex flex-wrap items-center justify-end gap-1">
|
|
1087
|
-
<time dateTime={message.receivedDate} className={["text-xs mr-1", dateClass(cardUnread)].join(" ")}>
|
|
1088
|
-
{new Date(message.receivedDate).toLocaleString()}
|
|
1089
|
-
</time>
|
|
1090
|
-
{adaptable && (
|
|
1091
|
-
<button
|
|
1092
|
-
type="button"
|
|
1093
|
-
aria-label="View original"
|
|
1094
|
-
aria-pressed={viewOriginal}
|
|
1095
|
-
title={viewOriginal ? "Follow the theme" : "View original"}
|
|
1096
|
-
onClick={() => setViewOriginal(!viewOriginal)}
|
|
1097
|
-
className={[
|
|
1098
|
-
"inline-flex items-center justify-center p-1.5 rounded-md border border-border text-sm text-text hover:bg-surface-alt",
|
|
1099
|
-
viewOriginal ? "bg-primary/10" : "",
|
|
1100
|
-
].join(" ")}
|
|
1101
|
-
>
|
|
1102
|
-
{viewOriginal ? <HiOutlineMoon size={16} aria-hidden="true" /> : <HiOutlineSun size={16} aria-hidden="true" />}
|
|
1103
|
-
</button>
|
|
1104
|
-
)}
|
|
1105
|
-
{/* Wraps: in a thread the pane can be as narrow as the reading pane gets (the list takes
|
|
1106
|
-
384px of it), and these are six controls. */}
|
|
1107
|
-
<IconAction
|
|
1108
|
-
icon={<HiOutlineArrowUturnLeft size={16} aria-hidden="true" />}
|
|
1109
|
-
label="Reply"
|
|
1110
|
-
shortcut={keyboard ? SHORTCUTS.mail.reply : undefined}
|
|
1111
|
-
disabled={preparingCompose}
|
|
1112
|
-
onPrefetch={prefetchReply}
|
|
1113
|
-
onClick={() => void handleReplyOrForward("reply")}
|
|
1114
|
-
/>
|
|
1115
|
-
<IconAction
|
|
1116
|
-
icon={
|
|
1117
|
-
// The conventional reply-all glyph: the reply arrow, doubled. `hi2` has no
|
|
1118
|
-
// reply-all icon of its own, and nothing else in it means "answer everyone".
|
|
1119
|
-
<span className="inline-flex items-center" aria-hidden="true">
|
|
1120
|
-
<HiOutlineArrowUturnLeft size={16} />
|
|
1121
|
-
<HiOutlineArrowUturnLeft size={16} className="-ml-2.5" />
|
|
1122
|
-
</span>
|
|
1123
|
-
}
|
|
1124
|
-
label="Reply All"
|
|
1125
|
-
shortcut={keyboard ? SHORTCUTS.mail.replyAll : undefined}
|
|
1126
|
-
disabled={preparingCompose}
|
|
1127
|
-
onPrefetch={prefetchReply}
|
|
1128
|
-
onClick={() => void handleReplyOrForward("replyAll")}
|
|
1129
|
-
/>
|
|
1130
|
-
<IconAction
|
|
1131
|
-
icon={<HiOutlineArrowUturnRight size={16} aria-hidden="true" />}
|
|
1132
|
-
label="Forward"
|
|
1133
|
-
shortcut={keyboard ? SHORTCUTS.mail.forward : undefined}
|
|
1134
|
-
disabled={preparingCompose}
|
|
1135
|
-
onPrefetch={prefetchReply}
|
|
1136
|
-
onClick={() => void handleReplyOrForward("forward")}
|
|
1137
|
-
/>
|
|
1138
|
-
{archivable && (
|
|
1139
|
-
<IconAction
|
|
1140
|
-
icon={<HiOutlineArchiveBox size={16} aria-hidden="true" />}
|
|
1141
|
-
label="Archive"
|
|
1142
|
-
shortcut={keyboard ? SHORTCUTS.mail.archive : undefined}
|
|
1143
|
-
busy={archiving}
|
|
1144
|
-
disabled={archiving}
|
|
1145
|
-
onClick={handleArchive}
|
|
1146
|
-
/>
|
|
1147
|
-
)}
|
|
1148
|
-
{movable && (
|
|
1149
|
-
<IconAction
|
|
1150
|
-
icon={<HiOutlineFolderArrowDown size={16} aria-hidden="true" />}
|
|
1151
|
-
label="Move to"
|
|
1152
|
-
shortcut={keyboard ? SHORTCUTS.mail.move : undefined}
|
|
1153
|
-
onClick={() => setMovePrompt(true)}
|
|
1154
|
-
/>
|
|
1155
|
-
)}
|
|
1156
|
-
{labels && labels.length > 0 && (
|
|
1157
|
-
<LabelMenuButton
|
|
1158
|
-
aria-label="Labels"
|
|
1159
|
-
label="Labels"
|
|
1160
|
-
className="border border-border py-1.5"
|
|
1161
|
-
labels={labels}
|
|
1162
|
-
mailboxUid={message.mailboxUid}
|
|
1163
|
-
onLabelCreated={onLabelCreated}
|
|
1164
|
-
applied={currentLabelsMessage.labelUids ?? []}
|
|
1165
|
-
onCommit={(labelUids) => void handleApplyLabels(labelUids)}
|
|
1166
|
-
busy={savingLabels}
|
|
1167
|
-
note="Ticked labels are applied to this message and unticked ones removed."
|
|
1168
|
-
emptyNote="This mailbox has no labels yet."
|
|
1169
|
-
commit={{ label: "Apply" }}
|
|
1170
|
-
clear={{ label: "Remove all labels" }}
|
|
1171
|
-
/>
|
|
1172
|
-
)}
|
|
1173
|
-
</div>
|
|
1174
|
-
</div>
|
|
1175
|
-
|
|
1176
|
-
{/* A slim bar for what has been done with the message. */}
|
|
1177
|
-
{(answered || forwarded) && (
|
|
1178
|
-
<p className="px-4 py-1.5 text-xs text-text-muted bg-surface-alt border-y border-border">
|
|
1179
|
-
{answered && forwarded ? "You replied to and forwarded this message." : answered ? "You replied to this message." : "You forwarded this message."}
|
|
1180
|
-
</p>
|
|
1181
|
-
)}
|
|
1182
|
-
|
|
1183
|
-
<div id={threadHeader?.bodyId} className="px-4 pb-3 flex flex-col gap-2">
|
|
1184
|
-
{inThread && (subjectDiffers || !sameSubject(shownSubject, threadSubject)) && (
|
|
1185
|
-
<h3 className="text-sm font-semibold break-words">{shownSubject}</h3>
|
|
1186
|
-
)}
|
|
1187
|
-
<div className="flex flex-wrap items-center gap-2 empty:hidden">{sendingStatus}</div>
|
|
1188
|
-
{inOutbox && message.scheduledSendError && <Alert>This message wasn’t sent: {message.scheduledSendError}</Alert>}
|
|
1189
|
-
{cancelError && <Alert>{cancelError}</Alert>}
|
|
1190
|
-
{keyChangeNotice && (
|
|
1191
|
-
<p role="status" className="py-2 px-3 rounded-sm text-sm bg-surface-alt text-text">
|
|
1192
|
-
{keyChangeNotice}
|
|
1193
|
-
</p>
|
|
1194
|
-
)}
|
|
1195
|
-
{security && UNVERIFIED_SIGNER_STATES.has(security.state) && (
|
|
1196
|
-
// Informational: the signature is intact, but nothing ties its certificate to this sender - anyone can
|
|
1197
|
-
// create a certificate naming any address. "Trust this signer" (below) pins it once the reader has
|
|
1198
|
-
// confirmed the fingerprint.
|
|
1199
|
-
<p role="status" className="py-2 px-3 rounded-sm text-sm bg-surface-alt text-text">
|
|
1200
|
-
Signed, but the signer isn’t a trusted contact key, so the sender isn’t verified.
|
|
1201
|
-
{security.signerEmails && security.signerEmails.length > 0 && <> Certificate for {security.signerEmails.join(", ")}.</>}
|
|
1202
|
-
{security.signerFingerprint && (
|
|
1203
|
-
<>
|
|
1204
|
-
{" "}
|
|
1205
|
-
Fingerprint <span className="font-mono text-xs break-all">{security.signerFingerprint}</span>.
|
|
1206
|
-
</>
|
|
1207
|
-
)}
|
|
1208
|
-
</p>
|
|
1209
|
-
)}
|
|
1210
|
-
{pendingConflict && (
|
|
1211
|
-
// Only an unverified signer's result loads the key state while the sender is unpinned, and a conflict
|
|
1212
|
-
// always comes from a matching contact, so its uid is known.
|
|
1213
|
-
<p role="status" className="py-2 px-3 rounded-sm text-sm bg-warning/15 text-text">
|
|
1214
|
-
This sender has a signing key change waiting for your review, so this signer can’t be trusted from
|
|
1215
|
-
here.{" "}
|
|
1216
|
-
<a
|
|
1217
|
-
href={`/contacts/${encodeURIComponent(senderKeyState.contactUid!)}`}
|
|
1218
|
-
className="font-medium text-primary-dark hover:underline"
|
|
1219
|
-
>
|
|
1220
|
-
Review it in Contacts
|
|
1221
|
-
</a>
|
|
1222
|
-
</p>
|
|
1223
|
-
)}
|
|
1224
|
-
{trustableCertificate && (
|
|
1225
|
-
<div>
|
|
1226
|
-
<Button
|
|
1227
|
-
type="button"
|
|
1228
|
-
variant="secondary"
|
|
1229
|
-
className="!w-auto"
|
|
1230
|
-
disabled={trusting}
|
|
1231
|
-
onClick={() => {
|
|
1232
|
-
setTrustError(null);
|
|
1233
|
-
setTrustConfirmOpen(true);
|
|
1234
|
-
}}
|
|
1235
|
-
>
|
|
1236
|
-
Trust this signer
|
|
1237
|
-
</Button>
|
|
1238
|
-
</div>
|
|
1239
|
-
)}
|
|
1240
|
-
{subjectDiffers && (
|
|
1241
|
-
<p role="status" className="py-2 px-3 rounded-sm text-sm bg-surface-alt text-text">
|
|
1242
|
-
The subject shown above is the one the sender signed. It differs from the subject this message was
|
|
1243
|
-
delivered with (“{message.subject}”), which may have been changed on the way, e.g. by a
|
|
1244
|
-
mailing list.
|
|
1245
|
-
</p>
|
|
1246
|
-
)}
|
|
1247
|
-
{security?.headerTamperDetected && (
|
|
1248
|
-
<Alert>
|
|
1249
|
-
This message's visible From/To/Cc/Date/Subject don't match what the sender actually signed or
|
|
1250
|
-
encrypted — an intermediary may have altered them after sending. Treat the fields shown above with
|
|
1251
|
-
caution.
|
|
1252
|
-
</Alert>
|
|
1253
|
-
)}
|
|
1254
|
-
{security?.state === "verified_at_first_open" && (
|
|
1255
|
-
// A seal outranks only a key-status failure (see `evaluateMessageSecurityWithSeal()`). A signer key
|
|
1256
|
-
// later reported compromised is a warning, never reassurance.
|
|
1257
|
-
<p
|
|
1258
|
-
role="status"
|
|
1259
|
-
className={`py-2 px-3 rounded-sm text-sm text-text ${security.laterCompromised ? "bg-warning/15" : "bg-surface-alt"}`}
|
|
1260
|
-
>
|
|
1261
|
-
{verifiedAtFirstOpenMessage(security)}
|
|
1262
|
-
</p>
|
|
1263
|
-
)}
|
|
1264
|
-
{keyChanged && (
|
|
1265
|
-
<section aria-label="Signing key changed" className="py-3 px-3 rounded-sm text-sm bg-warning/15 text-text flex flex-col gap-2">
|
|
1266
|
-
<h2 className="font-semibold">This sender’s signing key changed</h2>
|
|
1267
|
-
<p>
|
|
1268
|
-
The signature on this message is valid and its certificate names {senderAddress}, but it was made
|
|
1269
|
-
with a different key than the one you trust for this sender
|
|
1270
|
-
{keyChanged.state === "verified_at_first_open" ? "." : <>, so it isn’t verified.</>}
|
|
1271
|
-
</p>
|
|
1272
|
-
<KeyChangeReview
|
|
1273
|
-
mailboxUid={message.mailboxUid}
|
|
1274
|
-
address={senderAddress}
|
|
1275
|
-
useType="sign"
|
|
1276
|
-
ownerName="the sender"
|
|
1277
|
-
current={pinnedSignerKey && { fingerprint: pinnedSignerKey.fingerprint, since: senderKeyState.pinnedSince! }}
|
|
1278
|
-
proposed={{
|
|
1279
|
-
fingerprint: keyChanged.signerFingerprint!,
|
|
1280
|
-
emails: keyChanged.signerEmails,
|
|
1281
|
-
observedAt: recordedConflict?.observedAt,
|
|
1282
|
-
source: recordedConflict?.source,
|
|
1283
|
-
}}
|
|
1284
|
-
certificate={keyChanged.signerCertificate}
|
|
1285
|
-
canReject={recordedConflict !== undefined}
|
|
1286
|
-
canResolve={canUpdateMailbox}
|
|
1287
|
-
onResolved={(action) => refreshAfterKeyChange(action === "reject" ? KEPT_CURRENT_SIGNING_KEY_MESSAGE : null)}
|
|
1288
|
-
onPinnedKeyChanged={() => refreshAfterKeyChange(KEY_CHANGE_STALE_MESSAGE)}
|
|
1289
|
-
/>
|
|
1290
|
-
</section>
|
|
1291
|
-
)}
|
|
1292
|
-
{security?.state === "signature_failed" && !keyChanged && (
|
|
1293
|
-
// Deliberately an informational notice, not an error `Alert`: an unverifiable signature
|
|
1294
|
-
// means "don't trust the signer", not "this message is broken" - the body stays readable.
|
|
1295
|
-
<p role="status" className="py-2 px-3 rounded-sm text-sm bg-surface-alt text-text">
|
|
1296
|
-
{security.signatureFailureReason
|
|
1297
|
-
? SIGNATURE_FAILURE_MESSAGE[security.signatureFailureReason]
|
|
1298
|
-
: GENERIC_SIGNATURE_FAILURE_MESSAGE}
|
|
1299
|
-
</p>
|
|
1300
|
-
)}
|
|
1301
|
-
{verifiedOrSealed && !security.protectedHeaders && (
|
|
1302
|
-
// A legacy S/MIME sender signs only the body: the outer Subject/To/Cc shown here were never signed.
|
|
1303
|
-
<p role="status" className="py-2 px-3 rounded-sm text-sm bg-surface-alt text-text">
|
|
1304
|
-
The signature covers this message’s content and attachments only. Its Subject, To and Cc
|
|
1305
|
-
weren’t signed, so they could have been changed after it was sent.
|
|
1306
|
-
</p>
|
|
1307
|
-
)}
|
|
1308
|
-
{security?.notAddressedToReader && !isSentItems && (
|
|
1309
|
-
// Informational, like the notice above: a Bcc recipient legitimately sees this too. Never shown in Sent
|
|
1310
|
-
// Items: the sender's own address is (by design, see ComposeWindow/sendJob) never one of the protected
|
|
1311
|
-
// To/Cc headers of a message it sent to someone else, so this would otherwise fire on every ordinary sent
|
|
1312
|
-
// message rather than the genuine forwarded/re-sent/Bcc cases it's meant to flag.
|
|
1313
|
-
<p role="status" className="py-2 px-3 rounded-sm text-sm bg-surface-alt text-text">
|
|
1314
|
-
The recipients this message was signed or encrypted for don’t include this mailbox - it may have
|
|
1315
|
-
been forwarded or re-sent to you unchanged, or you were Bcc’d.
|
|
1316
|
-
</p>
|
|
1317
|
-
)}
|
|
1318
|
-
{archiveError && <Alert>{archiveError}</Alert>}
|
|
1319
|
-
{labelsError && <Alert>{labelsError}</Alert>}
|
|
1320
|
-
{labels && (currentLabelsMessage.labelUids?.length ?? 0) > 0 && (
|
|
1321
|
-
<div className="flex flex-wrap items-center gap-1.5">
|
|
1322
|
-
{currentLabelsMessage
|
|
1323
|
-
.labelUids!.map((uid) => labels.find((l) => l.uid === uid))
|
|
1324
|
-
.filter((l): l is Label => !!l)
|
|
1325
|
-
.map((l) => (
|
|
1326
|
-
<span
|
|
1327
|
-
key={l.uid}
|
|
1328
|
-
className="inline-flex items-center gap-1.5 text-xs font-medium py-1 px-2.5 rounded-pill bg-surface-alt"
|
|
1329
|
-
>
|
|
1330
|
-
<span className="w-2 h-2 rounded-full shrink-0" style={{ backgroundColor: l.color ?? "#6366f1" }} />
|
|
1331
|
-
{l.name}
|
|
1332
|
-
</span>
|
|
1333
|
-
))}
|
|
1334
|
-
</div>
|
|
1335
|
-
)}
|
|
1336
|
-
{/* A failed reclassification is reported inside the confirmation dialog it was started
|
|
1337
|
-
from, next to the Move button that would retry it - not out here behind it. */}
|
|
1338
|
-
{(["delivery", "read"] as const)
|
|
1339
|
-
.filter((type) => (type === "delivery" ? message.deliveryReceiptPending : message.readReceiptPending))
|
|
1340
|
-
.map((type) => (
|
|
1341
|
-
<div key={type} className="flex flex-wrap items-center gap-2 py-2 px-3 rounded-sm bg-surface-alt text-sm">
|
|
1342
|
-
<span>
|
|
1343
|
-
{senderLabel} requested a {type} receipt for this
|
|
1344
|
-
message.
|
|
1345
|
-
</span>
|
|
1346
|
-
<Button
|
|
1347
|
-
type="button"
|
|
1348
|
-
variant="secondary"
|
|
1349
|
-
className="!w-auto"
|
|
1350
|
-
loading={receiptBusy === type}
|
|
1351
|
-
disabled={receiptBusy !== null}
|
|
1352
|
-
onClick={() => handleReceipt(type, "approve")}
|
|
1353
|
-
>
|
|
1354
|
-
Send receipt
|
|
1355
|
-
</Button>
|
|
1356
|
-
<Button type="button" variant="text" disabled={receiptBusy !== null} onClick={() => handleReceipt(type, "decline")}>
|
|
1357
|
-
Decline
|
|
1358
|
-
</Button>
|
|
1359
|
-
</div>
|
|
1360
|
-
))}
|
|
1361
|
-
{receiptError && <Alert>{receiptError}</Alert>}
|
|
1362
|
-
{mayHoldInvite && <InviteCard messageUid={message.uid} headingLevel={inThread ? 3 : 2} />}
|
|
1363
|
-
{security?.state === "signature_failed" && innerAttachments && innerAttachments.length > 0 && (
|
|
1364
|
-
<p role="status" className="py-2 px-3 rounded-sm text-sm bg-warning/15 text-text">
|
|
1365
|
-
These attachments come from a message whose signature couldn’t be verified. Open them only if
|
|
1366
|
-
you trust the sender.
|
|
1367
|
-
</p>
|
|
1368
|
-
)}
|
|
1369
|
-
{innerAttachments
|
|
1370
|
-
? innerAttachments.length > 0 && (
|
|
1371
|
-
<ul className="flex flex-wrap gap-2">
|
|
1372
|
-
{innerAttachments.map((attachment, index) => (
|
|
1373
|
-
<li key={`${index}:${attachment.filename ?? ""}`}>
|
|
1374
|
-
<button
|
|
1375
|
-
type="button"
|
|
1376
|
-
onClick={() => downloadMimeAttachment(attachment)}
|
|
1377
|
-
className="text-xs font-medium py-1 px-2.5 rounded-pill bg-surface-alt text-text-muted hover:text-primary-dark"
|
|
1378
|
-
>
|
|
1379
|
-
{attachment.filename ?? `Unnamed ${attachment.contentType} attachment`}
|
|
1380
|
-
</button>
|
|
1381
|
-
</li>
|
|
1382
|
-
))}
|
|
1383
|
-
</ul>
|
|
1384
|
-
)
|
|
1385
|
-
: listedAttachments.length > 0 && (
|
|
1386
|
-
<ul className="flex flex-wrap gap-2">
|
|
1387
|
-
{listedAttachments.map((attachment) => (
|
|
1388
|
-
<li key={attachment.uid}>
|
|
1389
|
-
<a
|
|
1390
|
-
href={attachmentContentUrl(attachment.uid)}
|
|
1391
|
-
className="text-xs font-medium py-1 px-2.5 rounded-pill bg-surface-alt text-text-muted hover:text-primary-dark"
|
|
1392
|
-
>
|
|
1393
|
-
{attachment.filename} ({formatBytes(attachment.sizeBytes)})
|
|
1394
|
-
</a>
|
|
1395
|
-
</li>
|
|
1396
|
-
))}
|
|
1397
|
-
</ul>
|
|
1398
|
-
)}
|
|
1399
|
-
{/* The body: an isolated frame exactly as tall as its content (or text), in the card's own place. A decrypted or verified
|
|
1400
|
-
body never came through the server's own sanitizer (the server never saw the plaintext); `MessageBody` sanitizes every body
|
|
1401
|
-
client-side regardless, behind a no-remote-loads CSP, in a frame that runs no script. */}
|
|
1402
|
-
<div ref={bodyRegionRef} tabIndex={-1} className="outline-none">
|
|
1403
|
-
{message.encrypted && security === null ? (
|
|
1404
|
-
<BodySkeleton />
|
|
1405
|
-
) : security?.decryptError !== undefined ? (
|
|
1406
|
-
// An encrypted message that could not be read: locked (no unlocked keys - the button asks the app's own unlock prompt, and the message
|
|
1407
|
-
// then decrypts in place) or genuinely unreadable (keys unlocked and it still didn't open - the reason, and nothing to click).
|
|
1408
|
-
<EncryptedBody locked={lockedRef.current} reason={security.decryptError} unlocking={unlocking} onUnlock={() => void handleUnlockToView()} />
|
|
1409
|
-
) : (
|
|
1410
|
-
<MessageBody
|
|
1411
|
-
messageUid={message.uid}
|
|
1412
|
-
messageVersion={message.version}
|
|
1413
|
-
title={bodyTitle}
|
|
1414
|
-
content={bodyContent}
|
|
1415
|
-
attachments={attachments}
|
|
1416
|
-
inlineParts={innerAttachments}
|
|
1417
|
-
original={viewOriginal}
|
|
1418
|
-
onAdaptable={setAdaptable}
|
|
1419
|
-
/>
|
|
1420
|
-
)}
|
|
1421
|
-
</div>
|
|
1422
|
-
</div>
|
|
1423
|
-
|
|
1424
|
-
{showFooter && (
|
|
1425
|
-
<div className="flex flex-wrap gap-2 px-4 py-3 border-t border-border print:hidden">
|
|
1426
|
-
<Button
|
|
1427
|
-
type="button"
|
|
1428
|
-
variant="secondary"
|
|
1429
|
-
className="!w-auto"
|
|
1430
|
-
aria-label="Reply to this message"
|
|
1431
|
-
disabled={preparingCompose}
|
|
1432
|
-
onClick={() => void handleReplyOrForward("reply")}
|
|
1433
|
-
>
|
|
1434
|
-
Reply
|
|
1435
|
-
</Button>
|
|
1436
|
-
<Button
|
|
1437
|
-
type="button"
|
|
1438
|
-
variant="secondary"
|
|
1439
|
-
className="!w-auto"
|
|
1440
|
-
aria-label="Reply all to this message"
|
|
1441
|
-
disabled={preparingCompose}
|
|
1442
|
-
onClick={() => void handleReplyOrForward("replyAll")}
|
|
1443
|
-
>
|
|
1444
|
-
Reply All
|
|
1445
|
-
</Button>
|
|
1446
|
-
<Button
|
|
1447
|
-
type="button"
|
|
1448
|
-
variant="secondary"
|
|
1449
|
-
className="!w-auto"
|
|
1450
|
-
aria-label="Forward this message"
|
|
1451
|
-
disabled={preparingCompose}
|
|
1452
|
-
onClick={() => void handleReplyOrForward("forward")}
|
|
1453
|
-
>
|
|
1454
|
-
Forward
|
|
1455
|
-
</Button>
|
|
1456
|
-
</div>
|
|
1457
|
-
)}
|
|
1458
|
-
</CardShell>
|
|
1459
|
-
);
|
|
1460
|
-
|
|
1461
|
-
return (
|
|
1462
|
-
// `h-full` outside a thread only: the standalone message route renders this pane straight into a
|
|
1463
|
-
// *block* (`MailShell`'s own `<main>`), where nothing stretches it and a percentage of that block's
|
|
1464
|
-
// own resolved height is the height. Inside a thread the card is one row of the thread's own list.
|
|
1465
|
-
<div className={inThread ? "min-w-0" : "flex-1 min-w-0 min-h-0 flex flex-col h-full"}>
|
|
1466
|
-
{inThread ? (
|
|
1467
|
-
card
|
|
1468
|
-
) : (
|
|
1469
|
-
<>
|
|
1470
|
-
{backHref && (
|
|
1471
|
-
<a href={backHref} className="text-sm text-primary-dark hover:underline block px-4 pt-3">
|
|
1472
|
-
← Back to messages
|
|
1473
|
-
</a>
|
|
1474
|
-
)}
|
|
1475
|
-
{/* The subject has a card of its own, above the message, that stays put while the message scrolls. */}
|
|
1476
|
-
<SubjectCard subject={shownSubject} />
|
|
1477
|
-
<div className="flex-1 min-h-0 overflow-y-auto p-2 sm:p-3 flex flex-col gap-3">{card}</div>
|
|
1478
|
-
</>
|
|
1479
|
-
)}
|
|
1480
|
-
|
|
1481
|
-
<MoveToFolderDialog
|
|
1482
|
-
open={movePrompt}
|
|
1483
|
-
onClose={() => setMovePrompt(false)}
|
|
1484
|
-
mailboxUid={message.mailboxUid}
|
|
1485
|
-
folders={folders ?? []}
|
|
1486
|
-
currentFolderUid={message.folderUid}
|
|
1487
|
-
onMove={handleMove}
|
|
1488
|
-
onFolderCreated={onFolderCreated}
|
|
1489
|
-
/>
|
|
1490
|
-
<Modal open={confirming} onClose={() => setConfirming(false)} title="Recall this message?">
|
|
1491
|
-
<p className="text-sm text-text-muted mb-4">
|
|
1492
|
-
This asks every original recipient's mail system to delete their copy, but only if it's
|
|
1493
|
-
still unread there — there's no way to guarantee it, and no confirmation once it either
|
|
1494
|
-
succeeds or fails. Recipients who already read the message will keep it.
|
|
1495
|
-
</p>
|
|
1496
|
-
{error && <Alert>{error}</Alert>}
|
|
1497
|
-
<div className="flex gap-3">
|
|
1498
|
-
<Button type="button" loading={recalling} disabled={recalling} onClick={handleRecall} className="!w-auto">
|
|
1499
|
-
Recall message
|
|
1500
|
-
</Button>
|
|
1501
|
-
<Button
|
|
1502
|
-
type="button"
|
|
1503
|
-
variant="secondary"
|
|
1504
|
-
disabled={recalling}
|
|
1505
|
-
onClick={() => setConfirming(false)}
|
|
1506
|
-
className="!w-auto"
|
|
1507
|
-
>
|
|
1508
|
-
Cancel
|
|
1509
|
-
</Button>
|
|
1510
|
-
</div>
|
|
1511
|
-
</Modal>
|
|
1512
|
-
<Modal
|
|
1513
|
-
open={trustConfirmOpen && !!trustableCertificate}
|
|
1514
|
-
onClose={() => !trusting && setTrustConfirmOpen(false)}
|
|
1515
|
-
title="Trust this signer?"
|
|
1516
|
-
>
|
|
1517
|
-
<div className="flex flex-col gap-3 text-sm">
|
|
1518
|
-
<p>
|
|
1519
|
-
Mail from <span className="font-medium">{senderAddress}</span> signed with this certificate will show as
|
|
1520
|
-
verified.
|
|
1521
|
-
</p>
|
|
1522
|
-
<dl className="flex flex-col gap-1">
|
|
1523
|
-
<dt className="text-xs text-text-muted">Certificate issued to</dt>
|
|
1524
|
-
<dd>{security?.signerEmails?.length ? security.signerEmails.join(", ") : "No email address"}</dd>
|
|
1525
|
-
<dt className="text-xs text-text-muted">Fingerprint</dt>
|
|
1526
|
-
<dd className="font-mono text-xs break-all">
|
|
1527
|
-
{security?.signerFingerprint ? formatFingerprint(security.signerFingerprint) : "Unknown"}
|
|
1528
|
-
</dd>
|
|
1529
|
-
</dl>
|
|
1530
|
-
<p className="text-text-muted">
|
|
1531
|
-
Anyone can create a certificate naming any address. Before trusting it, confirm this fingerprint with
|
|
1532
|
-
the sender through another channel, such as a phone call.
|
|
1533
|
-
</p>
|
|
1534
|
-
{trustError && <Alert>{trustError}</Alert>}
|
|
1535
|
-
<div className="flex gap-3">
|
|
1536
|
-
<Button
|
|
1537
|
-
type="button"
|
|
1538
|
-
className="!w-auto"
|
|
1539
|
-
loading={trusting}
|
|
1540
|
-
disabled={trusting}
|
|
1541
|
-
onClick={() => handleTrustSigner(senderAddress, trustableCertificate!)}
|
|
1542
|
-
>
|
|
1543
|
-
Trust
|
|
1544
|
-
</Button>
|
|
1545
|
-
<Button
|
|
1546
|
-
type="button"
|
|
1547
|
-
variant="secondary"
|
|
1548
|
-
className="!w-auto"
|
|
1549
|
-
disabled={trusting}
|
|
1550
|
-
onClick={() => setTrustConfirmOpen(false)}
|
|
1551
|
-
>
|
|
1552
|
-
Cancel
|
|
1553
|
-
</Button>
|
|
1554
|
-
</div>
|
|
1555
|
-
</div>
|
|
1556
|
-
</Modal>
|
|
1557
|
-
</div>
|
|
1558
|
-
);
|
|
1559
|
-
}
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
6
|
+
import {
|
|
7
|
+
HiOutlineArchiveBox,
|
|
8
|
+
HiOutlineArrowUturnLeft,
|
|
9
|
+
HiOutlineArrowUturnRight,
|
|
10
|
+
HiOutlineCheck,
|
|
11
|
+
HiOutlineExclamationTriangle,
|
|
12
|
+
HiOutlineFolderArrowDown,
|
|
13
|
+
HiOutlineLockClosed,
|
|
14
|
+
HiOutlineMoon,
|
|
15
|
+
HiOutlineSun,
|
|
16
|
+
} from "react-icons/hi2";
|
|
17
|
+
import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
|
|
18
|
+
import {
|
|
19
|
+
Attachment,
|
|
20
|
+
Folder,
|
|
21
|
+
Message,
|
|
22
|
+
ReceiptType,
|
|
23
|
+
Recipient,
|
|
24
|
+
approveReceipt,
|
|
25
|
+
archiveMessage,
|
|
26
|
+
attachmentContentUrl,
|
|
27
|
+
cancelScheduledSend,
|
|
28
|
+
declineReceipt,
|
|
29
|
+
getMailbox,
|
|
30
|
+
getMessage,
|
|
31
|
+
getMessageRawContent,
|
|
32
|
+
moveMessage,
|
|
33
|
+
recallMessage,
|
|
34
|
+
setMessageLabels,
|
|
35
|
+
} from "@rapidmx/react-shared/mail/mailApi.js";
|
|
36
|
+
import { Label } from "@rapidmx/react-shared/mail/labelsApi.js";
|
|
37
|
+
import {
|
|
38
|
+
buildForwardQuote,
|
|
39
|
+
buildReplyQuote,
|
|
40
|
+
buildReplyRecipients,
|
|
41
|
+
buildReplyThreading,
|
|
42
|
+
forwardSubject,
|
|
43
|
+
replySubject,
|
|
44
|
+
} from "@rapidmx/react-shared/mail/compose/composeQuoting.js";
|
|
45
|
+
import MoveToFolderDialog from "./MoveToFolderDialog.js";
|
|
46
|
+
import InviteCard from "./InviteCard.js";
|
|
47
|
+
import { isCalendarAttachment } from "./invite/inviteFormat.js";
|
|
48
|
+
import { useMessageInvite } from "./invite/inviteStore.js";
|
|
49
|
+
import { getUnlockedKeys, subscribeKeySession } from "@rapidmx/react-shared/crypto/keySession.js";
|
|
50
|
+
import type { MessageSecurityResult, SignatureFailureReason } from "@rapidmx/react-shared/crypto/messageSecurity.js";
|
|
51
|
+
import { extractAddresses, type MimeAttachment } from "@rapidmx/react-shared/crypto/mime.js";
|
|
52
|
+
import { SignerKeyConflictError, signingKeyFingerprints, trustSigner } from "@rapidmx/react-shared/crypto/keyvaultApi.js";
|
|
53
|
+
import { isLikelyMailingList } from "@rapidmx/react-shared/crypto/composeSecurity.js";
|
|
54
|
+
import { SenderKeyState, clearPinnedSignerCache, getPinnedSignerFingerprints, getSignerKeyState } from "./pinnedSigners.js";
|
|
55
|
+
import { currentVerificationSeal, getVaultGeneration, sendVerificationSeal } from "./verificationSeals.js";
|
|
56
|
+
import { getMyMailboxAccess } from "@rapidmx/react-shared/mail/mailboxAccessApi.js";
|
|
57
|
+
import KeyChangeReview from "../contacts/KeyChangeReview.js";
|
|
58
|
+
import { KEY_CHANGE_STALE_MESSAGE, sameFingerprint } from "../contacts/contactKeys.js";
|
|
59
|
+
import { ComposeLateInput, prefetchComposeWindow, useCompose } from "./compose/ComposeContext.js";
|
|
60
|
+
import { loadOriginalMessage, prefetchOriginalMessage } from "./compose/quotedBody.js";
|
|
61
|
+
import { formatRecipient } from "./compose/recipients.js";
|
|
62
|
+
import { formatMailAddress } from "@rapidmx/react-shared/mail/mailAddress.js";
|
|
63
|
+
import MailAddress, { RecipientLine } from "./MailAddress.js";
|
|
64
|
+
import { useMailShell } from "./layout/MailShell.js";
|
|
65
|
+
import { ariaKeyShortcuts, withHint } from "../../keyboard/format.js";
|
|
66
|
+
import { SHORTCUTS, ShortcutDef } from "../../keyboard/keymap.js";
|
|
67
|
+
import { useKeyEnvironment } from "../../keyboard/ShortcutProvider.js";
|
|
68
|
+
import { useShortcut } from "../../keyboard/useShortcut.js";
|
|
69
|
+
import { useUnlockPrompt } from "../layout/UnlockPromptProvider.js";
|
|
70
|
+
import { moveLocalEntity } from "../../search/localIndexRpcClient.js";
|
|
71
|
+
import Modal from "@rapidmx/react-shared/components/overlays/Modal.js";
|
|
72
|
+
import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
|
|
73
|
+
import LabelMenuButton from "./labelMenu.js";
|
|
74
|
+
import Button from "@rapidmx/react-shared/components/buttons/Button.js";
|
|
75
|
+
import EncryptedBody from "./reading/EncryptedBody.js";
|
|
76
|
+
import { displaySubject } from "./reading/EncryptedPreview.js";
|
|
77
|
+
import MessageBody, { BodySkeleton } from "./reading/MessageBody.js";
|
|
78
|
+
import { BODY_FONT_STYLE, CardShell, SenderAvatar, SubjectCard } from "./reading/MessageCard.js";
|
|
79
|
+
import type { BodyContent } from "./reading/bodyContent.js";
|
|
80
|
+
import { useViewOriginal } from "./reading/viewOriginal.js";
|
|
81
|
+
import { ROW_FOCUS_CLASS, UnreadLabel, dateClass, senderClass } from "./unreadStyle.js";
|
|
82
|
+
|
|
83
|
+
/** Labels/styling for `specs/end-to-end_encryption.md`'s "Message Security Indicators" table - kept as
|
|
84
|
+
* plain data (not JSX) so `SecurityIndicator` below stays a trivial lookup. "Signature failed" MUST NOT
|
|
85
|
+
* read as a muted variant of "verified" (a failed signature is a stronger negative than no signature at
|
|
86
|
+
* all), and "Unprotected" MUST NOT read as an error - the class pairs below are chosen so those two
|
|
87
|
+
* never share styling with each other or with the verified states. */
|
|
88
|
+
const SECURITY_INDICATOR: Record<MessageSecurityResult["state"], { label: string; className: string }> = {
|
|
89
|
+
unprotected: { label: "Unprotected", className: "bg-surface-alt text-text-muted" },
|
|
90
|
+
encrypted: { label: "Encrypted", className: "bg-primary/10 text-primary-dark" },
|
|
91
|
+
signed_verified: { label: "Signed & verified", className: "bg-success/10 text-success" },
|
|
92
|
+
encrypted_verified: { label: "Encrypted & verified", className: "bg-success/10 text-success" },
|
|
93
|
+
// A valid signature from a certificate the reader hasn't pinned - anyone can mint a certificate naming the
|
|
94
|
+
// sender, so this must never look like the verified states.
|
|
95
|
+
signed_unverified_signer: { label: "Signed - signer not verified", className: "bg-warning/15 text-text" },
|
|
96
|
+
encrypted_unverified_signer: { label: "Encrypted - signer not verified", className: "bg-warning/15 text-text" },
|
|
97
|
+
signature_failed: { label: "Signature failed", className: "bg-danger-bg text-danger" },
|
|
98
|
+
// Verified when first opened (a verification seal), but not live: muted, never the green verified pill. A signer key
|
|
99
|
+
// later reported compromised switches it to `LATER_COMPROMISED_INDICATOR_CLASS`.
|
|
100
|
+
verified_at_first_open: { label: "Verified when first opened", className: "bg-surface-alt text-text-muted" },
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/** The amber `verified_at_first_open` badge for a signer key since reported compromised. */
|
|
104
|
+
const LATER_COMPROMISED_INDICATOR_CLASS = "bg-warning/15 text-text";
|
|
105
|
+
|
|
106
|
+
/** Whether a result is (or, for `verified_at_first_open`, was live) a `signer_key_changed` failure. */
|
|
107
|
+
function signerKeyChanged(result: MessageSecurityResult): boolean {
|
|
108
|
+
return result.signatureFailureReason === "signer_key_changed" || result.liveSignatureFailureReason === "signer_key_changed";
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The detail line under a `verified_at_first_open` badge. */
|
|
112
|
+
export function verifiedAtFirstOpenMessage(result: MessageSecurityResult): string {
|
|
113
|
+
const date = new Date(result.verifiedAt!).toLocaleDateString();
|
|
114
|
+
if (result.laterCompromised) {
|
|
115
|
+
return `This signature was verified on ${date}, but the sender's key was later reported compromised; treat this message with caution.`;
|
|
116
|
+
}
|
|
117
|
+
if (result.liveSignatureFailureReason === "signer_key_changed") {
|
|
118
|
+
return `This signature was verified on ${date}. The sender has since started signing with a different key.`;
|
|
119
|
+
}
|
|
120
|
+
return `This signature was verified on ${date}. The sender's key is no longer trusted since then, for example because it was removed, replaced or revoked.`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const VERIFIED_STATES = new Set<MessageSecurityResult["state"]>(["signed_verified", "encrypted_verified"]);
|
|
124
|
+
const UNVERIFIED_SIGNER_STATES = new Set<MessageSecurityResult["state"]>(["signed_unverified_signer", "encrypted_unverified_signer"]);
|
|
125
|
+
|
|
126
|
+
/** An `@`, or a look-alike a reader would take for one (fullwidth, small) - restapi's own `AT_SIGN_LIKE`. */
|
|
127
|
+
const AT_SIGN_LIKE = /[@\uFF20\uFE6B]/;
|
|
128
|
+
|
|
129
|
+
export interface SenderNameCheck {
|
|
130
|
+
/** The display name contains an `@` or a look-alike - it reads as (part of) an address. */
|
|
131
|
+
looksLikeAddress: boolean;
|
|
132
|
+
/** It shows an address-shaped token that isn't `actualAddress` - e.g. `"ceo@corp.com" <x@corp-pay.com>`. */
|
|
133
|
+
misleading: boolean;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Whether a sender's display name poses as an address, and whether that address differs from the one actually sent
|
|
137
|
+
* from. Compatibility forms are folded first (NFKC turns the fullwidth and small @ into `@`), so a look-alike can't
|
|
138
|
+
* hide the token. */
|
|
139
|
+
export function checkSenderName(displayName: string | undefined, actualAddress: string): SenderNameCheck {
|
|
140
|
+
if (!displayName || !AT_SIGN_LIKE.test(displayName)) {
|
|
141
|
+
return { looksLikeAddress: false, misleading: false };
|
|
142
|
+
}
|
|
143
|
+
const shown = /[^\s<>"'(),;:]+@[^\s<>"'(),;:]+/.exec(displayName.normalize("NFKC"))?.[0];
|
|
144
|
+
return { looksLikeAddress: true, misleading: shown !== undefined && shown.toLowerCase() !== actualAddress.toLowerCase() };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export const TRUST_SIGNER_CONFLICT_MESSAGE =
|
|
148
|
+
"A different signing key is already trusted for this sender, so this one wasn't trusted. The sender's key may have changed; confirm with them before doing anything.";
|
|
149
|
+
export const TRUST_SIGNER_INVALID_MESSAGE = "This certificate can't be trusted for this sender.";
|
|
150
|
+
export const TRUST_SIGNER_FORBIDDEN_MESSAGE = "You don't have permission to trust signers for this mailbox.";
|
|
151
|
+
export const TRUST_SIGNER_GENERIC_MESSAGE = "Couldn't trust this signer. Try again.";
|
|
152
|
+
export const KEPT_CURRENT_SIGNING_KEY_MESSAGE = "You kept the current signing key for this sender. This message stays unverified.";
|
|
153
|
+
|
|
154
|
+
/** The error text for a failed `trustSigner()`. */
|
|
155
|
+
export function trustSignerErrorMessage(err: unknown): string {
|
|
156
|
+
if (err instanceof SignerKeyConflictError) {
|
|
157
|
+
return TRUST_SIGNER_CONFLICT_MESSAGE;
|
|
158
|
+
}
|
|
159
|
+
if (err instanceof ApiRequestError && err.status === 400) {
|
|
160
|
+
return TRUST_SIGNER_INVALID_MESSAGE;
|
|
161
|
+
}
|
|
162
|
+
if (err instanceof ApiRequestError && err.status === 403) {
|
|
163
|
+
return TRUST_SIGNER_FORBIDDEN_MESSAGE;
|
|
164
|
+
}
|
|
165
|
+
return TRUST_SIGNER_GENERIC_MESSAGE;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Groups a fingerprint into 4-character blocks (`AB12 CD34 ...`), ignoring any separators it came with, so it can be
|
|
169
|
+
* read out and compared with the sender over another channel. */
|
|
170
|
+
export function formatFingerprint(fingerprint: string): string {
|
|
171
|
+
const compact = fingerprint.replace(/[\s:]/g, "").toUpperCase();
|
|
172
|
+
return compact.match(/.{1,4}/g)?.join(" ") ?? compact;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Saves one attachment recovered from inside a signed/encrypted entity. Always handed to the browser as an
|
|
176
|
+
* opaque download (`application/octet-stream`), never rendered in this origin. */
|
|
177
|
+
function downloadMimeAttachment(attachment: MimeAttachment): void {
|
|
178
|
+
// `decode()` is `undefined` only for invalid base64 - an empty file is the honest result then.
|
|
179
|
+
const bytes = attachment.decode() ?? new Uint8Array(0);
|
|
180
|
+
const url = URL.createObjectURL(new Blob([bytes as BlobPart], { type: "application/octet-stream" }));
|
|
181
|
+
const a = document.createElement("a");
|
|
182
|
+
a.href = url;
|
|
183
|
+
a.download = attachment.filename ?? "attachment";
|
|
184
|
+
document.body.appendChild(a);
|
|
185
|
+
a.click();
|
|
186
|
+
a.remove();
|
|
187
|
+
// Some browsers are still reading the blob after `click()` returns.
|
|
188
|
+
setTimeout(() => URL.revokeObjectURL(url), 60_000);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* One of the reading pane's own actions - Reply, Reply All, Forward, Archive, Move to Other - as an icon
|
|
193
|
+
* button. The action's name is its `aria-label` *and* its tooltip, so it has the same accessible name a
|
|
194
|
+
* labelled button had, and is never drawn beside the icon at any width: the row is icon-only everywhere,
|
|
195
|
+
* the way Outlook's own reading-pane command bar is, so it reads the same in the ~396px pane beside the
|
|
196
|
+
* message list and in a maximised window rather than changing shape at a breakpoint.
|
|
197
|
+
*
|
|
198
|
+
* A plain `<button>` rather than react-shared's `Button`, whose padding and minimum width are sized for a
|
|
199
|
+
* text label. Ordinary DOM order, so the keyboard reaches these in the order they are read.
|
|
200
|
+
*/
|
|
201
|
+
function IconAction({
|
|
202
|
+
icon,
|
|
203
|
+
label,
|
|
204
|
+
onClick,
|
|
205
|
+
disabled,
|
|
206
|
+
busy,
|
|
207
|
+
onPrefetch,
|
|
208
|
+
shortcut,
|
|
209
|
+
}: {
|
|
210
|
+
icon: React.ReactNode;
|
|
211
|
+
label: string;
|
|
212
|
+
onClick: () => void;
|
|
213
|
+
disabled?: boolean;
|
|
214
|
+
busy?: boolean;
|
|
215
|
+
/** Called when the pointer or keyboard reaches the button - the moment to start fetching what a click will need. */
|
|
216
|
+
onPrefetch?: () => void;
|
|
217
|
+
/** The keyboard shortcut that does what this button does, when it is registered right now: named in the tooltip (`Reply (Ctrl+R)`) and
|
|
218
|
+
* in `aria-keyshortcuts` - the accessible name stays the bare label. */
|
|
219
|
+
shortcut?: ShortcutDef;
|
|
220
|
+
}) {
|
|
221
|
+
const env = useKeyEnvironment();
|
|
222
|
+
return (
|
|
223
|
+
<button
|
|
224
|
+
type="button"
|
|
225
|
+
aria-label={label}
|
|
226
|
+
title={shortcut ? withHint(label, shortcut, env) : label}
|
|
227
|
+
aria-keyshortcuts={shortcut ? ariaKeyShortcuts(shortcut, env) : undefined}
|
|
228
|
+
aria-busy={busy || undefined}
|
|
229
|
+
disabled={disabled}
|
|
230
|
+
onClick={onClick}
|
|
231
|
+
onPointerEnter={onPrefetch}
|
|
232
|
+
onFocus={onPrefetch}
|
|
233
|
+
className="inline-flex items-center justify-center p-1.5 rounded-md border border-border text-sm text-text hover:bg-surface-alt disabled:opacity-50 disabled:hover:bg-transparent"
|
|
234
|
+
>
|
|
235
|
+
{icon}
|
|
236
|
+
</button>
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function SecurityIndicator({ security }: { security: MessageSecurityResult }) {
|
|
241
|
+
const { label, className } = SECURITY_INDICATOR[security.state];
|
|
242
|
+
if (security.state !== "verified_at_first_open") {
|
|
243
|
+
// Every encrypted state carries a small lock, so the badge reads at a glance; the words are unchanged.
|
|
244
|
+
const encrypted = security.state.startsWith("encrypted");
|
|
245
|
+
return (
|
|
246
|
+
<span className={`inline-flex items-center gap-1 text-xs font-medium shrink-0 py-1 px-2.5 rounded-pill ${className}`}>
|
|
247
|
+
{encrypted && <HiOutlineLockClosed size={12} aria-hidden="true" />}
|
|
248
|
+
{label}
|
|
249
|
+
</span>
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
return (
|
|
253
|
+
<span
|
|
254
|
+
className={`inline-flex items-center gap-1 text-xs font-medium shrink-0 py-1 px-2.5 rounded-pill ${
|
|
255
|
+
security.laterCompromised ? LATER_COMPROMISED_INDICATOR_CLASS : className
|
|
256
|
+
}`}
|
|
257
|
+
>
|
|
258
|
+
{security.laterCompromised ? (
|
|
259
|
+
<HiOutlineExclamationTriangle size={12} aria-hidden="true" />
|
|
260
|
+
) : (
|
|
261
|
+
<HiOutlineCheck size={12} aria-hidden="true" />
|
|
262
|
+
)}
|
|
263
|
+
{label}
|
|
264
|
+
</span>
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** User-facing explanation for each `signatureFailureReason` - shown alongside the "Signature failed"
|
|
269
|
+
* badge so an unverifiable (e.g. foreign/unparseable) signed message reads as "not verified, and here's
|
|
270
|
+
* why" rather than as a bare error. The body itself stays visible either way. */
|
|
271
|
+
const SIGNATURE_FAILURE_MESSAGE: Record<SignatureFailureReason, string> = {
|
|
272
|
+
invalid_signature:
|
|
273
|
+
"This message's digital signature couldn't be verified - it may be malformed, use an unsupported format, or the content may have been altered after signing. Treat it as unverified.",
|
|
274
|
+
untrusted_signer: "This message was signed with a certificate that doesn't match the sender's known key. Treat it as unverified.",
|
|
275
|
+
// Never shown: the dedicated "signing key changed" notice replaces it. Present so every reason has copy.
|
|
276
|
+
signer_key_changed: "This message was signed with a different key than the one you trust for this sender. Treat it as unverified.",
|
|
277
|
+
signer_identity_mismatch:
|
|
278
|
+
"This message's signing certificate doesn't belong to the sender shown in From. Treat it as unverified.",
|
|
279
|
+
header_mismatch:
|
|
280
|
+
"The sender/recipients this message was signed with don't match its visible From/To, or it repeats a From, To, Cc or Sender header. Treat it as unverified.",
|
|
281
|
+
};
|
|
282
|
+
const GENERIC_SIGNATURE_FAILURE_MESSAGE = "This message's digital signature couldn't be verified. Treat it as unverified.";
|
|
283
|
+
|
|
284
|
+
/** Fallback when the raw MIME for an encrypted message can't even be fetched/evaluated - an encrypted
|
|
285
|
+
* message must never be mislabeled "Unprotected" just because loading failed. */
|
|
286
|
+
const ENCRYPTED_LOAD_ERROR = "Couldn't load this message's encrypted content.";
|
|
287
|
+
|
|
288
|
+
export interface MessageDetailPaneProps {
|
|
289
|
+
message: Message | null;
|
|
290
|
+
attachments: Attachment[];
|
|
291
|
+
/** Present only on the mobile detail route — renders a "back to messages" link above the header. Absent
|
|
292
|
+
* on the desktop reading pane, which never navigates away (selecting a different message just swaps
|
|
293
|
+
* `message` in place). */
|
|
294
|
+
backHref?: string;
|
|
295
|
+
/** Whether `message` currently lives in Sent Items — the only folder recall is offered from, matching
|
|
296
|
+
* Outlook's own restriction (and `BaseMessageRoute.recall()`'s own server-side check). Each caller
|
|
297
|
+
* computes this from its own already-loaded folder list rather than this component fetching folders
|
|
298
|
+
* itself. */
|
|
299
|
+
isSentItems?: boolean;
|
|
300
|
+
/** Called with the server's updated copy (carrying `recallRequestedAt`) after a successful recall, so
|
|
301
|
+
* the caller can patch its own in-memory message/list state — mirrors `mailDetailHooks.ts`'s
|
|
302
|
+
* `useMarkMessageRead`'s identical `onUpdated` callback. */
|
|
303
|
+
onRecalled?: (updated: Message) => void;
|
|
304
|
+
/** Whether `message` currently lives in Outbox — the only folder a scheduled send can be canceled
|
|
305
|
+
* from. Each caller computes this the same way it computes `isSentItems`. */
|
|
306
|
+
isOutbox?: boolean;
|
|
307
|
+
/** The mailbox's Drafts folder uid — required when `isOutbox` is `true`, since canceling a
|
|
308
|
+
* scheduled send moves the message back into Drafts (see `cancelScheduledSend()`'s own doc comment
|
|
309
|
+
* on why clearing `scheduledSendTime` alone doesn't do that). */
|
|
310
|
+
draftsFolderUid?: string;
|
|
311
|
+
/** Called with the server's updated copy (now back in Drafts, `scheduledSendTime` cleared) after
|
|
312
|
+
* successfully canceling a scheduled send. */
|
|
313
|
+
onScheduledSendCanceled?: (updated: Message) => void;
|
|
314
|
+
/** Every folder of this message's own mailbox, for the Move to prompt's destination list. Absent or
|
|
315
|
+
* empty simply hides the control — there is nowhere to move to. Each caller already resolves this to
|
|
316
|
+
* work out `isSentItems`/`isOutbox`/`draftsFolderUid`, so nothing new is fetched for it. */
|
|
317
|
+
folders?: Folder[];
|
|
318
|
+
/** Called with the server's updated copy (now in the chosen folder) after a successful Move to. A move
|
|
319
|
+
* takes the message out of whichever folder is being listed, so callers remove it from their list
|
|
320
|
+
* rather than patching it — unlike `onClassified`, which this replaces. */
|
|
321
|
+
onMoved?: (updated: Message) => void;
|
|
322
|
+
/** A folder created from the Move to prompt, so the caller's own list and the folder sidebar pick it up
|
|
323
|
+
* without a page load. */
|
|
324
|
+
onFolderCreated?: (folder: Folder) => void;
|
|
325
|
+
/** Called with the server's updated copy after approving/declining a pending delivery/read receipt —
|
|
326
|
+
* mirrors `onRecalled`'s identical shape. No gating prop needed (unlike `isSentItems`/`isOutbox`):
|
|
327
|
+
* `deliveryReceiptPending`/`readReceiptPending` already live directly on `message` and are only ever
|
|
328
|
+
* `true` on a real delivered copy, so the banner below is self-gating. */
|
|
329
|
+
onReceiptHandled?: (updated: Message) => void;
|
|
330
|
+
/** Called with the server's updated copy (now filed under the mailbox's Archive folder) after a
|
|
331
|
+
* successful archive — mirrors `onRecalled`'s identical shape. Archiving itself is offered for any
|
|
332
|
+
* message except one currently in Drafts or Outbox (mirrors `BaseMessageRoute.archive()`'s own
|
|
333
|
+
* server-side 400 guard); Drafts is detected via `draftsFolderUid` (already passed by every caller
|
|
334
|
+
* for the Outbox-cancel flow) rather than a new prop. */
|
|
335
|
+
onArchived?: (updated: Message) => void;
|
|
336
|
+
/** Every label defined in this message's mailbox, for the label-assignment popover below — each
|
|
337
|
+
* caller fetches its own mailbox's labels the same way it already resolves `draftsFolderUid`
|
|
338
|
+
* (`listLabels()`). Absent/empty simply hides the Labels control - there's nothing to assign. */
|
|
339
|
+
labels?: Label[];
|
|
340
|
+
/** Called with the server's updated copy (carrying the new `labelUids`) after successfully toggling
|
|
341
|
+
* a label — always patches in place, never removes from a caller's list (unlike `onArchived`):
|
|
342
|
+
* changing labels never moves a message between folders. */
|
|
343
|
+
onLabelsChanged?: (updated: Message) => void;
|
|
344
|
+
/** Handed a label created from the Labels menu, for the caller to add to `labels`. Without it the menu
|
|
345
|
+
* offers no "New label" row, only the link to where labels are managed. */
|
|
346
|
+
onLabelCreated?: (label: Label) => void;
|
|
347
|
+
/** Rendered as one message of a thread (`ConversationThreadPane`) rather than as the pane itself: only its card is drawn - the thread
|
|
348
|
+
* owns the subject card, the scrolling and the `h1` - and the message's own subject appears (as an `h3`) only when it differs from the
|
|
349
|
+
* thread's (`threadSubject`). Everything else - the badges, the actions, the body - is identical. */
|
|
350
|
+
inThread?: boolean;
|
|
351
|
+
/** The thread's subject, for a message of a thread to tell whether its own subject is worth showing. */
|
|
352
|
+
threadSubject?: string;
|
|
353
|
+
/** In a thread, what makes the sender line of this expanded card the button that collapses it: the id of the body it controls, whether the
|
|
354
|
+
* message is unread (which draws the accent bar and tint), what it does, and where to put its ref. */
|
|
355
|
+
threadHeader?: {
|
|
356
|
+
bodyId: string;
|
|
357
|
+
unread: boolean;
|
|
358
|
+
onToggle: () => void;
|
|
359
|
+
buttonRef: (node: HTMLButtonElement | null) => void;
|
|
360
|
+
};
|
|
361
|
+
/** Draw the Reply and Forward buttons at the foot of the card - by default for the single-message pane, and in a thread only where the
|
|
362
|
+
* caller asks (the newest expanded message). */
|
|
363
|
+
footer?: boolean;
|
|
364
|
+
/**
|
|
365
|
+
* Registers this pane's keyboard shortcuts - Reply, Reply all, Forward, Archive, Move to - so they act on this message. Only the message
|
|
366
|
+
* the keyboard is acting on should set it: the one pane beside the list, or the opened message of a thread (each expanded message of a
|
|
367
|
+
* thread is a pane, and two of them must not both claim Ctrl+R). Also puts the shortcut in those buttons' tooltips.
|
|
368
|
+
*/
|
|
369
|
+
shortcuts?: boolean;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** A subject without its \`Re:\`/\`Fwd:\` prefixes, lower-cased - what makes two messages of one thread the same subject. */
|
|
373
|
+
function subjectCore(subject: string | undefined): string {
|
|
374
|
+
return (subject ?? "").replace(/^(\s*(re|fw|fwd|aw|sv)\s*:)+/i, "").trim().toLowerCase();
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/** Whether a message's subject says nothing its thread's subject doesn't. */
|
|
378
|
+
function sameSubject(subject: string, threadSubject: string | undefined): boolean {
|
|
379
|
+
return subjectCore(subject) === subjectCore(threadSubject);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function formatBytes(bytes: number): string {
|
|
383
|
+
if (bytes >= 1_000_000) return `${(bytes / 1_000_000).toFixed(1)} MB`;
|
|
384
|
+
if (bytes >= 1_000) return `${(bytes / 1_000).toFixed(1)} KB`;
|
|
385
|
+
return `${bytes} B`;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* A message's reading pane - a subject card, and under it the message as a card: header (sender, recipients, time, actions), notices, attachments,
|
|
390
|
+
* the body (`reading/MessageBody`: an isolated frame exactly as tall as its content, or text) and a footer. Rendered with `inThread`, only the card.
|
|
391
|
+
* Shared by the desktop inline pane (`apps/www/index.tsx`, always visible alongside the message list),
|
|
392
|
+
* and the mobile detail route (`apps/www/messages/[uid].tsx`, a full page on its own reached by tapping
|
|
393
|
+
* a message row) — see each call site for how `message`/`attachments`/`isSentItems` are sourced. The
|
|
394
|
+
* desktop pane shows whichever message the list opened, including one opened from a conversation row.
|
|
395
|
+
*/
|
|
396
|
+
export default function MessageDetailPane(props: MessageDetailPaneProps) {
|
|
397
|
+
if (!props.message) {
|
|
398
|
+
return <p className="p-8 text-sm text-text-muted">Select a message to read it.</p>;
|
|
399
|
+
}
|
|
400
|
+
// Keyed by uid so every piece of per-message state below (security result, open modals, in-flight
|
|
401
|
+
// flags, errors) resets cleanly when a caller swaps `message` in place rather than remounting.
|
|
402
|
+
return <MessageDetailContent key={props.message.uid} {...props} message={props.message} />;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/** Whether a message's raw MIME has to be fetched to evaluate its security state. `encrypted` is the
|
|
406
|
+
* server's own classification; there is no server-side "signed" flag, but every S/MIME-signed shape
|
|
407
|
+
* (detached `multipart/signed`'s `smime.p7s`, opaque-signed `smime.p7m`) is stored with its CMS part
|
|
408
|
+
* surfaced as an attachment - so a message with neither flag can't carry a signature to verify, and
|
|
409
|
+
* fetching its full raw source (attachments included) would be pure waste. */
|
|
410
|
+
function needsRawSecurityEvaluation(message: Message): boolean {
|
|
411
|
+
return !!message.encrypted || message.hasAttachments;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function MessageDetailContent({
|
|
415
|
+
message: messageProp,
|
|
416
|
+
attachments,
|
|
417
|
+
backHref,
|
|
418
|
+
isSentItems,
|
|
419
|
+
onRecalled,
|
|
420
|
+
isOutbox,
|
|
421
|
+
draftsFolderUid,
|
|
422
|
+
onScheduledSendCanceled,
|
|
423
|
+
folders,
|
|
424
|
+
onMoved,
|
|
425
|
+
onFolderCreated,
|
|
426
|
+
onReceiptHandled,
|
|
427
|
+
onArchived,
|
|
428
|
+
labels,
|
|
429
|
+
onLabelsChanged,
|
|
430
|
+
onLabelCreated,
|
|
431
|
+
inThread,
|
|
432
|
+
threadSubject,
|
|
433
|
+
threadHeader,
|
|
434
|
+
footer,
|
|
435
|
+
shortcuts,
|
|
436
|
+
}: MessageDetailPaneProps & { message: Message }) {
|
|
437
|
+
// A copy re-read from the server after an Outbox action was refused (409/403) or a send lease ran out - see
|
|
438
|
+
// `reloadMessage()`. A prop copy newer by `version` wins; an equal-version reload is kept, since claiming a send
|
|
439
|
+
// lease need not bump `version`.
|
|
440
|
+
const [reloaded, setReloaded] = useState<Message | null>(null);
|
|
441
|
+
const message = reloaded && reloaded.version >= messageProp.version ? reloaded : messageProp;
|
|
442
|
+
// A reload that finds the message already moved on (sent, or moved to Drafts elsewhere) leaves Outbox.
|
|
443
|
+
const inOutbox = !!isOutbox && message.folderUid === messageProp.folderUid;
|
|
444
|
+
const { openCompose } = useCompose();
|
|
445
|
+
const [confirming, setConfirming] = useState(false);
|
|
446
|
+
const [recalling, setRecalling] = useState(false);
|
|
447
|
+
const [canceling, setCanceling] = useState(false);
|
|
448
|
+
const [archiving, setArchiving] = useState(false);
|
|
449
|
+
const [archiveError, setArchiveError] = useState<string | null>(null);
|
|
450
|
+
const [savingLabels, setSavingLabels] = useState(false);
|
|
451
|
+
const [labelsError, setLabelsError] = useState<string | null>(null);
|
|
452
|
+
const [error, setError] = useState<string | null>(null);
|
|
453
|
+
// Kept separate from `error` (the Recall flow's own state) since this renders inline in the main
|
|
454
|
+
// pane rather than inside a confirmation modal — the two flows never need to share one message.
|
|
455
|
+
const [cancelError, setCancelError] = useState<string | null>(null);
|
|
456
|
+
const [movePrompt, setMovePrompt] = useState(false);
|
|
457
|
+
// Names which pending receipt (`"delivery"`/`"read"`) is currently being approved/declined, if any —
|
|
458
|
+
// `deliveryReceiptPending`/`readReceiptPending` can both be true independently, so a single boolean
|
|
459
|
+
// wouldn't distinguish which row's buttons should show a loading state.
|
|
460
|
+
const [receiptBusy, setReceiptBusy] = useState<ReceiptType | null>(null);
|
|
461
|
+
const [receiptError, setReceiptError] = useState<string | null>(null);
|
|
462
|
+
const [security, setSecurity] = useState<MessageSecurityResult | null>(null);
|
|
463
|
+
// Whether the pinned-signer lookup for the sender *succeeded* and found no signing keys - the only case "Trust this
|
|
464
|
+
// signer" is offered in. A failed lookup could be hiding an existing pin, and trusting never replaces one.
|
|
465
|
+
const [senderUnpinned, setSenderUnpinned] = useState(false);
|
|
466
|
+
const [trustConfirmOpen, setTrustConfirmOpen] = useState(false);
|
|
467
|
+
const [trusting, setTrusting] = useState(false);
|
|
468
|
+
const [trustError, setTrustError] = useState<string | null>(null);
|
|
469
|
+
// The sender's stored signing-key state, loaded for a `signer_key_changed` result (the comparison) and for an
|
|
470
|
+
// unverified signer with no pins (a recorded conflict sends the reader to the contact instead of offering trust).
|
|
471
|
+
// `undefined` when not needed or it couldn't be loaded.
|
|
472
|
+
const [senderKeyState, setSenderKeyState] = useState<SenderKeyState | undefined>(undefined);
|
|
473
|
+
// Whether the reader may update this mailbox (resolving a key change needs it) - `undefined` when unknown.
|
|
474
|
+
const [canUpdateMailbox, setCanUpdateMailbox] = useState<boolean | undefined>(undefined);
|
|
475
|
+
// "Keys changed while you were looking" after a 409, or the outcome of keeping the current key. Survives the
|
|
476
|
+
// re-evaluation that follows.
|
|
477
|
+
const [keyChangeNotice, setKeyChangeNotice] = useState<string | null>(null);
|
|
478
|
+
// "Now", for deciding whether a scheduled send's lease is still live - advanced when the lease runs out.
|
|
479
|
+
const [nowMs, setNowMs] = useState(() => Date.now());
|
|
480
|
+
const { mailboxes, trackMessageChange } = useMailShell();
|
|
481
|
+
const { requestUnlock } = useUnlockPrompt();
|
|
482
|
+
// Bumped after a successful on-demand unlock to re-run the effect below - it's not a dependency the
|
|
483
|
+
// effect could read reactively otherwise (getUnlockedKeys() is a plain module-level read, not React
|
|
484
|
+
// state; see keySession.ts's own doc comment).
|
|
485
|
+
const [unlockRefresh, setUnlockRefresh] = useState(0);
|
|
486
|
+
// "View original": this message exactly as its author wrote it instead of adapted to the theme, remembered for the session. Offered only
|
|
487
|
+
// once the body says adapting would change something (`MessageBody`'s `onAdaptable`), or when the reader already chose it.
|
|
488
|
+
const [viewOriginal, setViewOriginal] = useViewOriginal(messageProp.uid);
|
|
489
|
+
const [adaptable, setAdaptable] = useState(viewOriginal);
|
|
490
|
+
// The locked body's Unlock button is waiting on the unlock prompt; and, once it has answered, the focus is to move to the body region.
|
|
491
|
+
const [unlocking, setUnlocking] = useState(false);
|
|
492
|
+
const focusBodyRef = useRef(false);
|
|
493
|
+
const bodyRegionRef = useRef<HTMLDivElement>(null);
|
|
494
|
+
|
|
495
|
+
// The newest copy of this message known to the Labels popover - normally just the `message` prop,
|
|
496
|
+
// but a successful label toggle's server response is held here too, so a follow-up toggle always
|
|
497
|
+
// builds on the latest `labelUids`/`version` even before (or without) the caller patching its own
|
|
498
|
+
// state via `onLabelsChanged`. A prop copy at least as new (by `version`) always wins.
|
|
499
|
+
const [labelsMessage, setLabelsMessage] = useState<Message>(message);
|
|
500
|
+
const currentLabelsMessage = message.version >= labelsMessage.version ? message : labelsMessage;
|
|
501
|
+
const latestLabelsMessageRef = useRef<Message>(message);
|
|
502
|
+
const rawEvaluationNeeded = needsRawSecurityEvaluation(message);
|
|
503
|
+
// Every address the viewing mailbox receives at (primary first), as one string so the effect below only
|
|
504
|
+
// re-runs when they actually change.
|
|
505
|
+
const readerMailbox = mailboxes.find((mb) => mb.uid === message.mailboxUid);
|
|
506
|
+
const readerAddressesKey = readerMailbox ? [readerMailbox.primarySmtpAddress, ...(readerMailbox.aliasAddresses ?? [])].join(" ") : "";
|
|
507
|
+
|
|
508
|
+
// Evaluates a message's security state from its raw MIME - only for a message that can actually be
|
|
509
|
+
// encrypted or signed (see `needsRawSecurityEvaluation()`); anything else is "Unprotected" without a
|
|
510
|
+
// fetch. A detached `multipart/signed` message needs its raw MIME read (a sanitized HTML body never
|
|
511
|
+
// carries the signature part) to tell "Signed & verified" apart from plain "Unprotected". A
|
|
512
|
+
// fetch/parse failure degrades to "Unprotected" (or, for a server-flagged encrypted message, to
|
|
513
|
+
// "Encrypted" with an explanation) rather than hiding the message.
|
|
514
|
+
//
|
|
515
|
+
// `getMessageRawContent()` takes no `AbortSignal`, so a superseded fetch can't be aborted - its
|
|
516
|
+
// result is ignored via `cancelled` instead (and never handed to `evaluateMessageSecurity()`).
|
|
517
|
+
useEffect(() => {
|
|
518
|
+
if (!rawEvaluationNeeded) {
|
|
519
|
+
setSecurity({ state: "unprotected" });
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
let cancelled = false;
|
|
523
|
+
setSecurity(null);
|
|
524
|
+
setSenderUnpinned(false);
|
|
525
|
+
setSenderKeyState(undefined);
|
|
526
|
+
// The sender's trusted signing keys: what key discovery pinned on this mailbox's contacts, plus this
|
|
527
|
+
// mailbox's own signing keys when it sent the message itself. A failed lookup means no pins, which can only
|
|
528
|
+
// ever make a signature "signer not verified", never verified.
|
|
529
|
+
const senderAddress = message.from.address;
|
|
530
|
+
const pinsPromise = getPinnedSignerFingerprints(message.mailboxUid, senderAddress).then(
|
|
531
|
+
(fingerprints) => ({ loaded: true, fingerprints }),
|
|
532
|
+
() => ({ loaded: false, fingerprints: [] as string[] }),
|
|
533
|
+
);
|
|
534
|
+
// Verification seals (see `verificationSeals.ts`) need unlocked keys and the vault's current master key
|
|
535
|
+
// generation; without either the message is evaluated exactly as before, with no seal. The sender's key records
|
|
536
|
+
// are loaded alongside, so a seal can say when the signer key was later revoked as compromised.
|
|
537
|
+
let keyStatePromise: Promise<SenderKeyState | undefined> | undefined;
|
|
538
|
+
const loadKeyState = () => (keyStatePromise ??= getSignerKeyState(message.mailboxUid, senderAddress).catch(() => undefined));
|
|
539
|
+
const sealContextPromise = getUnlockedKeys(message.mailboxUid)
|
|
540
|
+
? getVaultGeneration(message.mailboxUid).then(async (generation) =>
|
|
541
|
+
generation === undefined ? undefined : { generation, keyState: await loadKeyState() },
|
|
542
|
+
)
|
|
543
|
+
: undefined;
|
|
544
|
+
getMessageRawContent(message.uid)
|
|
545
|
+
.then(async (rawMime) => {
|
|
546
|
+
if (cancelled) {
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
// The S/MIME code (PKI.js and the ASN.1/X.509 libraries) loads here, only for a message that is signed or
|
|
550
|
+
// encrypted - it is over half a megabyte, and the pane opens plain messages without it.
|
|
551
|
+
const messageSecurity = await import("@rapidmx/react-shared/crypto/messageSecurity.js");
|
|
552
|
+
const [primaryAddress, ...aliasAddresses] = readerAddressesKey ? readerAddressesKey.split(" ") : [];
|
|
553
|
+
const ownAddresses = readerAddressesKey.toLowerCase().split(" ");
|
|
554
|
+
const ownKeys = ownAddresses.includes(senderAddress.toLowerCase()) ? (readerMailbox!.keys ?? []) : [];
|
|
555
|
+
const ownPins = signingKeyFingerprints(ownKeys);
|
|
556
|
+
const [contactPins, sealContext] = await Promise.all([pinsPromise, sealContextPromise]);
|
|
557
|
+
const pins = [...new Set([...contactPins.fingerprints, ...ownPins])];
|
|
558
|
+
const pinned = pins.length > 0 ? pins : undefined;
|
|
559
|
+
// The raw content is a byte string - only ever handed to evaluateMessageSecurity(), never shown. Keys
|
|
560
|
+
// are read after the pin lookup's await, so a lock that happened meanwhile is honored.
|
|
561
|
+
const unlocked = getUnlockedKeys(message.mailboxUid);
|
|
562
|
+
let result: MessageSecurityResult;
|
|
563
|
+
if (sealContext && unlocked) {
|
|
564
|
+
const signerKeys = [
|
|
565
|
+
...(sealContext.keyState?.pinned ?? []),
|
|
566
|
+
...(sealContext.keyState?.previous ?? []),
|
|
567
|
+
...ownKeys,
|
|
568
|
+
];
|
|
569
|
+
result = await messageSecurity.evaluateMessageSecurityWithSeal(rawMime, unlocked, pinned, primaryAddress, {
|
|
570
|
+
mailboxUid: message.mailboxUid,
|
|
571
|
+
messageUid: message.uid,
|
|
572
|
+
...currentVerificationSeal(message),
|
|
573
|
+
masterKeyGeneration: sealContext.generation,
|
|
574
|
+
signerKeys,
|
|
575
|
+
}).catch(() =>
|
|
576
|
+
// Only a lock while sealing throws: evaluate as locked (the lock itself re-evaluates too).
|
|
577
|
+
messageSecurity.evaluateMessageSecurity(rawMime, undefined, pinned, primaryAddress),
|
|
578
|
+
);
|
|
579
|
+
if (result.sealToWrite) {
|
|
580
|
+
// Best effort and in the background: never awaited, never shown.
|
|
581
|
+
void sendVerificationSeal(message.uid, result.sealToWrite);
|
|
582
|
+
}
|
|
583
|
+
} else {
|
|
584
|
+
result = await messageSecurity.evaluateMessageSecurity(rawMime, unlocked, pinned, primaryAddress);
|
|
585
|
+
}
|
|
586
|
+
// Only one reader address can be checked per evaluation: a message sent to one of this mailbox's
|
|
587
|
+
// aliases isn't "not addressed to you", so each alias is tried before saying so.
|
|
588
|
+
for (const alias of aliasAddresses) {
|
|
589
|
+
if (!result.notAddressedToReader) {
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
592
|
+
const viaAlias = await messageSecurity.evaluateMessageSecurity(rawMime, unlocked, pinned, alias);
|
|
593
|
+
result = { ...result, notAddressedToReader: viaAlias.notAddressedToReader };
|
|
594
|
+
}
|
|
595
|
+
const unpinned = contactPins.loaded && pins.length === 0;
|
|
596
|
+
const keyChanged = signerKeyChanged(result);
|
|
597
|
+
const [keyState, access] = await Promise.all([
|
|
598
|
+
keyChanged || (unpinned && UNVERIFIED_SIGNER_STATES.has(result.state)) ? loadKeyState() : undefined,
|
|
599
|
+
keyChanged ? getMyMailboxAccess(message.mailboxUid).then((a) => a.canUpdate, () => undefined) : undefined,
|
|
600
|
+
]);
|
|
601
|
+
if (!cancelled) {
|
|
602
|
+
setSecurity(result);
|
|
603
|
+
setSenderUnpinned(unpinned);
|
|
604
|
+
setSenderKeyState(keyState);
|
|
605
|
+
setCanUpdateMailbox(access);
|
|
606
|
+
}
|
|
607
|
+
})
|
|
608
|
+
.catch(() => {
|
|
609
|
+
if (!cancelled) {
|
|
610
|
+
setSecurity(
|
|
611
|
+
message.encrypted ? { state: "encrypted", decryptError: ENCRYPTED_LOAD_ERROR } : { state: "unprotected" },
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
return () => {
|
|
616
|
+
cancelled = true;
|
|
617
|
+
};
|
|
618
|
+
}, [message.uid, message.mailboxUid, message.from.address, message.encrypted, rawEvaluationNeeded, unlockRefresh, readerAddressesKey]);
|
|
619
|
+
|
|
620
|
+
// Whether the body is the locked state right now (an encrypted message this device holds no unlocked keys for), for the subscription below.
|
|
621
|
+
const lockedRef = useRef(false);
|
|
622
|
+
lockedRef.current = security?.decryptError !== undefined && !getUnlockedKeys(message.mailboxUid);
|
|
623
|
+
|
|
624
|
+
// After an unlock from the button, the message (or the reason it can't be read) is where the reader's attention is: the focus moves to it once it is
|
|
625
|
+
// there, since the button that had it is gone.
|
|
626
|
+
useEffect(() => {
|
|
627
|
+
if (focusBodyRef.current && security !== null) {
|
|
628
|
+
focusBodyRef.current = false;
|
|
629
|
+
bodyRegionRef.current?.focus({ preventScroll: true });
|
|
630
|
+
}
|
|
631
|
+
}, [security]);
|
|
632
|
+
|
|
633
|
+
// Decrypted plaintext must not outlive the key session that produced it: the moment this mailbox's
|
|
634
|
+
// keys are destroyed (logout, idle timeout, explicit lock), drop the recovered html/text and
|
|
635
|
+
// re-evaluate - an encrypted message then falls back to its locked state. And the other way round: keys unlocked
|
|
636
|
+
// from anywhere (compose, another message, the unlock prompt) open a message that was waiting on them, in place.
|
|
637
|
+
useEffect(
|
|
638
|
+
() =>
|
|
639
|
+
subscribeKeySession((event) => {
|
|
640
|
+
if (event.mailboxUid !== message.mailboxUid) {
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
if (event.state === "locked") {
|
|
644
|
+
setSecurity(null);
|
|
645
|
+
setUnlockRefresh((n) => n + 1);
|
|
646
|
+
} else if (lockedRef.current) {
|
|
647
|
+
setUnlockRefresh((n) => n + 1);
|
|
648
|
+
}
|
|
649
|
+
}),
|
|
650
|
+
[message.mailboxUid],
|
|
651
|
+
);
|
|
652
|
+
|
|
653
|
+
// While restapi's ScheduledSendJob holds a send lease the message is being relayed: cancelling or moving it would be
|
|
654
|
+
// refused (409/403), so the Outbox controls are replaced by "Sending...". When the lease runs out the message is
|
|
655
|
+
// re-read - it has either been sent (and left Outbox) or been released back to its schedule.
|
|
656
|
+
const leaseExpiresMs = message.scheduledSendLeaseExpiresAt ? Date.parse(message.scheduledSendLeaseExpiresAt) : NaN;
|
|
657
|
+
const sendInProgress = inOutbox && leaseExpiresMs > nowMs;
|
|
658
|
+
useEffect(() => {
|
|
659
|
+
if (!sendInProgress) {
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
const timer = setTimeout(() => {
|
|
663
|
+
setNowMs(Date.now());
|
|
664
|
+
void reloadMessage();
|
|
665
|
+
}, leaseExpiresMs - nowMs + 1);
|
|
666
|
+
return () => clearTimeout(timer);
|
|
667
|
+
}, [sendInProgress, leaseExpiresMs, nowMs]);
|
|
668
|
+
|
|
669
|
+
async function reloadMessage() {
|
|
670
|
+
try {
|
|
671
|
+
setReloaded(await getMessage(message.uid));
|
|
672
|
+
setNowMs(Date.now());
|
|
673
|
+
} catch {
|
|
674
|
+
// Keep showing what we have - the next refused action or lease expiry tries again.
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// Offered only when this device genuinely has no unlocked session for this message's mailbox at all
|
|
679
|
+
// (as opposed to being unlocked but still unable to decrypt - a wrong/since-rotated key, which
|
|
680
|
+
// re-unlocking the same session can't fix) - see `evaluateMessageSecurity()`'s own doc comment on why
|
|
681
|
+
// `decryptError` alone can't distinguish those two cases.
|
|
682
|
+
async function handleUnlockToView() {
|
|
683
|
+
const mailboxUid = message.mailboxUid;
|
|
684
|
+
const mailboxKeys = mailboxes.find((mb) => mb.uid === mailboxUid)?.keys ?? [];
|
|
685
|
+
setUnlocking(true);
|
|
686
|
+
try {
|
|
687
|
+
await requestUnlock(mailboxUid, mailboxKeys);
|
|
688
|
+
// The Unlock button is about to be replaced by the message (or by why it can't be read): the focus goes there, once it has been evaluated.
|
|
689
|
+
focusBodyRef.current = true;
|
|
690
|
+
setUnlockRefresh((n) => n + 1);
|
|
691
|
+
} catch {
|
|
692
|
+
// User dismissed the unlock dialog - security state stays exactly as it was.
|
|
693
|
+
} finally {
|
|
694
|
+
setUnlocking(false);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// Only ever invoked from the "Trust this signer" dialog, which only opens for an unverified-signer result carrying
|
|
699
|
+
// `signerCertificate`. The pin goes on the contact in the mailbox the message belongs to; the evaluation is then
|
|
700
|
+
// re-run against a fresh pinned-signer lookup, so the badge turns verified.
|
|
701
|
+
async function handleTrustSigner(address: string, certificate: string) {
|
|
702
|
+
setTrusting(true);
|
|
703
|
+
setTrustError(null);
|
|
704
|
+
try {
|
|
705
|
+
await trustSigner(message.mailboxUid, { address, certificate });
|
|
706
|
+
clearPinnedSignerCache();
|
|
707
|
+
setTrustConfirmOpen(false);
|
|
708
|
+
setUnlockRefresh((n) => n + 1);
|
|
709
|
+
} catch (err) {
|
|
710
|
+
setTrustError(trustSignerErrorMessage(err));
|
|
711
|
+
} finally {
|
|
712
|
+
setTrusting(false);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
// After a key change was accepted or kept (or the pinned key moved meanwhile): the pinned signers are re-read and
|
|
717
|
+
// the message re-evaluated, so an accepted key turns the badge verified.
|
|
718
|
+
function refreshAfterKeyChange(notice: string | null) {
|
|
719
|
+
setKeyChangeNotice(notice);
|
|
720
|
+
clearPinnedSignerCache();
|
|
721
|
+
setUnlockRefresh((n) => n + 1);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// Reply, Reply All and Forward first load the full body to quote (see `loadQuotedBody()`), so the buttons are
|
|
725
|
+
// disabled meanwhile - a second click would open a second window. An encrypted original keeps its reply
|
|
726
|
+
// encrypted, since the quote may carry its decrypted content.
|
|
727
|
+
const [preparingCompose, setPreparingCompose] = useState(false);
|
|
728
|
+
|
|
729
|
+
/** The replying mailbox's own addresses (primary and aliases), which a reply never goes to - from the mail shell's
|
|
730
|
+
* mailbox list, else fetched; none when neither is available. */
|
|
731
|
+
async function ownAddresses(): Promise<string[]> {
|
|
732
|
+
const mailbox = readerMailbox ?? (await getMailbox(message.mailboxUid).catch(() => undefined));
|
|
733
|
+
return mailbox ? [mailbox.primarySmtpAddress, ...(mailbox.aliasAddresses ?? [])] : [];
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
/** Starts fetching what Reply/Reply All/Forward will need (the compose window's code, the original's body) as the
|
|
737
|
+
* pointer or keyboard reaches one of their buttons, so the click itself finds it already on its way or here. */
|
|
738
|
+
function prefetchReply() {
|
|
739
|
+
prefetchComposeWindow();
|
|
740
|
+
prefetchOriginalMessage(message);
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* Opens the compose window at once from what is already in memory - the message's own subject and sender, and the
|
|
745
|
+
* mailbox it was read in - and fetches what needs the network meanwhile: the original's body to quote, and for Reply All
|
|
746
|
+
* the recipients its headers name. Both reach the window through `OpenComposeInput.pending` when they arrive, so the
|
|
747
|
+
* window is on screen on the click's own frame rather than after two or three sequential requests.
|
|
748
|
+
*/
|
|
749
|
+
async function handleReplyOrForward(kind: "reply" | "replyAll" | "forward") {
|
|
750
|
+
setPreparingCompose(true);
|
|
751
|
+
try {
|
|
752
|
+
const encrypt = !!message.encrypted;
|
|
753
|
+
// What makes the new message part of this one's thread rather than a conversation of its own:
|
|
754
|
+
// the server composes the MIME from the recipients, subject and HTML alone, so nothing else
|
|
755
|
+
// recovers what is being replied to. A forward carries it for the same reason - it continues
|
|
756
|
+
// the thread it came from, which is where its recipient will file the reply to it.
|
|
757
|
+
const threading = buildReplyThreading(message);
|
|
758
|
+
const format = (list: Recipient[]) => list.map((r) => formatRecipient(r)).join(", ");
|
|
759
|
+
// Known without a request when the shell has already listed the mailbox; otherwise fetched with the body, and
|
|
760
|
+
// the window's recipients are corrected by `late` below if that changes who they are.
|
|
761
|
+
const knownOwn = readerAddressesKey ? readerAddressesKey.split(" ") : undefined;
|
|
762
|
+
// Never rejects: loadOriginalMessage() and ownAddresses() don't, and the rest is pure.
|
|
763
|
+
const late = (async (): Promise<ComposeLateInput> => {
|
|
764
|
+
const [original, own] = await Promise.all([
|
|
765
|
+
loadOriginalMessage(message, security, { recipients: kind === "replyAll" }),
|
|
766
|
+
kind === "forward" ? [] : (knownOwn ?? ownAddresses()),
|
|
767
|
+
]);
|
|
768
|
+
if (kind === "forward") {
|
|
769
|
+
return { quotedHtml: buildForwardQuote(message, original.body) };
|
|
770
|
+
}
|
|
771
|
+
// The message's own recipients are only the envelope recipient of a delivered message, so Reply All
|
|
772
|
+
// answers whoever its headers actually name, with anything the record holds that they don't.
|
|
773
|
+
const known = new Set((original.recipients ?? []).map((r) => r.address.trim().toLowerCase()));
|
|
774
|
+
const recipients = buildReplyRecipients(
|
|
775
|
+
{ ...message, recipients: [...(original.recipients ?? []), ...message.recipients.filter((r) => !known.has(r.address.trim().toLowerCase()))] },
|
|
776
|
+
own,
|
|
777
|
+
kind === "replyAll",
|
|
778
|
+
);
|
|
779
|
+
return { quotedHtml: buildReplyQuote(message, original.body), to: format(recipients.to), cc: format(recipients.cc) };
|
|
780
|
+
})();
|
|
781
|
+
if (kind === "forward") {
|
|
782
|
+
openCompose({
|
|
783
|
+
mailboxUid: message.mailboxUid,
|
|
784
|
+
subject: forwardSubject(message.subject),
|
|
785
|
+
signatureContext: "reply_forward",
|
|
786
|
+
encrypt,
|
|
787
|
+
threading,
|
|
788
|
+
pending: late,
|
|
789
|
+
});
|
|
790
|
+
} else {
|
|
791
|
+
const first = buildReplyRecipients(message, knownOwn ?? [], kind === "replyAll");
|
|
792
|
+
openCompose({
|
|
793
|
+
mailboxUid: message.mailboxUid,
|
|
794
|
+
to: format(first.to),
|
|
795
|
+
cc: first.cc.length > 0 ? format(first.cc) : undefined,
|
|
796
|
+
subject: replySubject(message.subject),
|
|
797
|
+
signatureContext: "reply_forward",
|
|
798
|
+
suppressSigning: isLikelyMailingList({ listUnsubscribe: message.listUnsubscribeHeader }),
|
|
799
|
+
encrypt,
|
|
800
|
+
threading,
|
|
801
|
+
pending: late,
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
// Held until the quote is in, so a second click can't open a second window for the same message meanwhile.
|
|
805
|
+
await late;
|
|
806
|
+
} finally {
|
|
807
|
+
setPreparingCompose(false);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
async function handleRecall() {
|
|
812
|
+
// Only ever invoked from the confirmation modal below, which itself only renders once `message`
|
|
813
|
+
// is loaded (the early return above covers the only other state) — the non-null assertion
|
|
814
|
+
// reflects that real invariant, matching this codebase's established pattern for the same class
|
|
815
|
+
// of always-true-in-practice guard.
|
|
816
|
+
setRecalling(true);
|
|
817
|
+
setError(null);
|
|
818
|
+
try {
|
|
819
|
+
const updated = await recallMessage(message.uid);
|
|
820
|
+
setConfirming(false);
|
|
821
|
+
onRecalled?.(updated);
|
|
822
|
+
} catch (err) {
|
|
823
|
+
setError(err instanceof ApiRequestError ? err.message : "Could not recall this message.");
|
|
824
|
+
} finally {
|
|
825
|
+
setRecalling(false);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// Only ever invoked from the "Cancel" button below (`isOutbox` and `message.scheduledSendTime` both truthy -
|
|
830
|
+
// `draftsFolderUid` is required whenever `isOutbox` is, see the prop's own doc comment), or from "Move to
|
|
831
|
+
// Drafts" (an Outbox message with no active schedule, which checks `draftsFolderUid` itself), so the non-null
|
|
832
|
+
// assertion reflects a real invariant, matching `handleRecall`'s identical pattern just above.
|
|
833
|
+
async function handleCancelScheduledSend() {
|
|
834
|
+
setCanceling(true);
|
|
835
|
+
setCancelError(null);
|
|
836
|
+
try {
|
|
837
|
+
const updated = await cancelScheduledSend(message, draftsFolderUid!);
|
|
838
|
+
// Keeps a `folder:`-scoped Tier 2 local search from still finding it in its old folder.
|
|
839
|
+
void moveLocalEntity(updated.mailboxUid, updated.uid, updated.folderUid);
|
|
840
|
+
// Out of Outbox, into Drafts: both folders' badges.
|
|
841
|
+
trackMessageChange(message, updated).settle();
|
|
842
|
+
onScheduledSendCanceled?.(updated);
|
|
843
|
+
} catch (err) {
|
|
844
|
+
const fallback = message.scheduledSendTime ? "Could not cancel this scheduled send." : "Could not move this message to Drafts.";
|
|
845
|
+
setCancelError(err instanceof ApiRequestError ? err.message : fallback);
|
|
846
|
+
// A conflict or refusal usually means the send job claimed (or already relayed) the message meanwhile -
|
|
847
|
+
// re-read it so the pane shows "Sending..." or its new state instead of the stale controls.
|
|
848
|
+
if (err instanceof ApiRequestError && (err.status === 409 || err.status === 403)) {
|
|
849
|
+
void reloadMessage();
|
|
850
|
+
}
|
|
851
|
+
} finally {
|
|
852
|
+
setCanceling(false);
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
// Only ever invoked from the Archive button below, which itself only renders once `message` is
|
|
857
|
+
// loaded and this isn't a Drafts/Outbox message (the button's own guard mirrors
|
|
858
|
+
// `BaseMessageRoute.archive()`'s server-side 400) — same real invariant as `handleRecall` above.
|
|
859
|
+
async function handleArchive() {
|
|
860
|
+
setArchiving(true);
|
|
861
|
+
setArchiveError(null);
|
|
862
|
+
try {
|
|
863
|
+
const updated = await archiveMessage(message.uid);
|
|
864
|
+
void moveLocalEntity(updated.mailboxUid, updated.uid, updated.folderUid);
|
|
865
|
+
trackMessageChange(message, updated).settle();
|
|
866
|
+
onArchived?.(updated);
|
|
867
|
+
} catch (err) {
|
|
868
|
+
setArchiveError(err instanceof ApiRequestError ? err.message : "Could not archive this message.");
|
|
869
|
+
} finally {
|
|
870
|
+
setArchiving(false);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
// Only ever invoked from the Labels menu below, which itself only renders once `message` is loaded.
|
|
875
|
+
// Several labels are ticked in the menu and saved together here, in one `setMessageLabels()` call:
|
|
876
|
+
// that call replaces the whole `labelUids` list rather than patching one entry, so a menu that saved
|
|
877
|
+
// per tick would send a request (and burn an optimistic-lock `version`) for every single tick.
|
|
878
|
+
//
|
|
879
|
+
// The list is computed from the newest copy known (`latestLabelsMessageRef`, never a stale render
|
|
880
|
+
// closure), so a save that follows another still carries the `version` the server last handed back.
|
|
881
|
+
async function handleApplyLabels(labelUids: string[]) {
|
|
882
|
+
setSavingLabels(true);
|
|
883
|
+
setLabelsError(null);
|
|
884
|
+
try {
|
|
885
|
+
const base = message.version >= latestLabelsMessageRef.current.version ? message : latestLabelsMessageRef.current;
|
|
886
|
+
const updated = await setMessageLabels(base, labelUids);
|
|
887
|
+
latestLabelsMessageRef.current = updated;
|
|
888
|
+
setLabelsMessage(updated);
|
|
889
|
+
onLabelsChanged?.(updated);
|
|
890
|
+
} catch (err) {
|
|
891
|
+
setLabelsError(err instanceof ApiRequestError ? err.message : "Could not update this message's labels.");
|
|
892
|
+
} finally {
|
|
893
|
+
setSavingLabels(false);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
/**
|
|
898
|
+
* Moves this message into the folder picked in the Move to prompt. Deliberately *not* caught here:
|
|
899
|
+
* `MoveToFolderDialog` shows a failure beside the destination that would retry it, and closes only
|
|
900
|
+
* once the move has actually landed.
|
|
901
|
+
*
|
|
902
|
+
* The move is awaited on its own line rather than written as `onMoved?.(await moveMessage(...))` -
|
|
903
|
+
* an optional call whose callee is absent never evaluates its arguments at all, so a caller that
|
|
904
|
+
* passes no `onMoved` would have had nothing moved while the prompt closed as if it had.
|
|
905
|
+
*/
|
|
906
|
+
async function handleMove(folderUid: string) {
|
|
907
|
+
const updated = await moveMessage(message, folderUid);
|
|
908
|
+
// Move to, Delete and Report junk are all this: the source folder's badge goes down, the target's up.
|
|
909
|
+
trackMessageChange(message, updated).settle();
|
|
910
|
+
onMoved?.(updated);
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// Keyboard shortcuts for the message this pane shows. They call the same handlers as the buttons below, and exist only where the
|
|
914
|
+
// button does (Archive not for Drafts/Outbox, Move to only with folders to move to). A shortcut pressed while its action is already
|
|
915
|
+
// running is consumed and does nothing, exactly as the disabled button would: a browser must not act on Ctrl+R meanwhile.
|
|
916
|
+
const archivable = !inOutbox && message.folderUid !== draftsFolderUid;
|
|
917
|
+
const movable = !!folders && folders.length > 0;
|
|
918
|
+
const keyboard = !!shortcuts;
|
|
919
|
+
useShortcut(SHORTCUTS.mail.reply, () => void (!preparingCompose && handleReplyOrForward("reply")), { enabled: keyboard });
|
|
920
|
+
useShortcut(SHORTCUTS.mail.replyAll, () => void (!preparingCompose && handleReplyOrForward("replyAll")), { enabled: keyboard });
|
|
921
|
+
useShortcut(SHORTCUTS.mail.forward, () => void (!preparingCompose && handleReplyOrForward("forward")), { enabled: keyboard });
|
|
922
|
+
useShortcut(SHORTCUTS.mail.archive, () => void (!archiving && handleArchive()), { enabled: keyboard && archivable });
|
|
923
|
+
useShortcut(SHORTCUTS.mail.move, () => setMovePrompt(true), { enabled: keyboard && movable });
|
|
924
|
+
|
|
925
|
+
// Only ever invoked from the pending-receipt banner below, which itself only renders once `message`
|
|
926
|
+
// is loaded — same real invariant as every other handler above.
|
|
927
|
+
async function handleReceipt(type: ReceiptType, action: "approve" | "decline") {
|
|
928
|
+
setReceiptBusy(type);
|
|
929
|
+
setReceiptError(null);
|
|
930
|
+
try {
|
|
931
|
+
const updated = await (action === "approve" ? approveReceipt : declineReceipt)(message.uid, type);
|
|
932
|
+
onReceiptHandled?.(updated);
|
|
933
|
+
} catch (err) {
|
|
934
|
+
setReceiptError(err instanceof ApiRequestError ? err.message : "Could not handle this receipt request.");
|
|
935
|
+
} finally {
|
|
936
|
+
setReceiptBusy(null);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
const verified = security !== null && VERIFIED_STATES.has(security.state);
|
|
941
|
+
// A seal proves the signature verified when first opened, and the live check still passed everything but the signer
|
|
942
|
+
// key's status - so the signed Subject and attachments are shown as for a verified message, under its own badge.
|
|
943
|
+
const verifiedOrSealed = verified || security?.state === "verified_at_first_open";
|
|
944
|
+
// Under a verified badge, the Subject shown is the one the signature covers (RFC 9788 protected headers), when
|
|
945
|
+
// the message carries one - the outer Subject is unsigned and anyone relaying the message could change it.
|
|
946
|
+
const protectedSubject = verifiedOrSealed ? security.protectedHeaders?.subject : undefined;
|
|
947
|
+
// Only meaningful for signed-only mail: an encrypted message's outer Subject is deliberately obscured. Not a
|
|
948
|
+
// signature failure (mailing lists legitimately tag subjects), just worth pointing out.
|
|
949
|
+
const subjectDiffers = protectedSubject !== undefined && (security!.state === "signed_verified" || security!.sealedState === "signed_verified") && protectedSubject !== message.subject;
|
|
950
|
+
// Attachments inside the signed/decrypted entity. Under a verified badge only these are listed - the server's
|
|
951
|
+
// attachment records also include parts outside the signature, which the badge doesn't vouch for. For decrypted
|
|
952
|
+
// mail the server only ever saw the encrypted blob, so these are the real attachments.
|
|
953
|
+
// A decrypted message whose signature failed still only has these (the server list is just `smime.p7m`); they're
|
|
954
|
+
// listed with a warning. A signed-only failure never carries recovered attachments.
|
|
955
|
+
const innerAttachments =
|
|
956
|
+
security?.attachments !== undefined &&
|
|
957
|
+
(verifiedOrSealed || security.state === "encrypted" || security.state === "encrypted_unverified_signer" || security.state === "signature_failed")
|
|
958
|
+
? security.attachments
|
|
959
|
+
: undefined;
|
|
960
|
+
// Any state that involves a signature shows the address actually signed for (the protected From when the message
|
|
961
|
+
// carries one - it equals the outer From's address, or verification would have failed) next to the badge, never a
|
|
962
|
+
// display name alone: anyone can put "ceo@corp.com" in the name of a message sent from x@corp-pay.com.
|
|
963
|
+
const signatureShown = security !== null && security.state !== "unprotected" && security.state !== "encrypted";
|
|
964
|
+
const senderAddress = (signatureShown ? extractAddresses(security.protectedHeaders?.from)[0] : undefined) ?? message.from.address;
|
|
965
|
+
const senderName = message.from.displayName;
|
|
966
|
+
const senderNameCheck = checkSenderName(senderName, senderAddress);
|
|
967
|
+
// Always `Name <address>` (or the bare address): a name alone hides who a message is really from.
|
|
968
|
+
const senderLabel = formatMailAddress({ displayName: senderName, address: senderAddress });
|
|
969
|
+
// Offered only for a valid signature from a certificate nobody pinned for this sender - never to replace a pin.
|
|
970
|
+
// A recorded signing-key conflict for this sender is resolved from the contact, never by trusting another key.
|
|
971
|
+
const pendingConflict = senderUnpinned && senderKeyState?.conflict !== undefined;
|
|
972
|
+
const trustableCertificate =
|
|
973
|
+
security !== null && UNVERIFIED_SIGNER_STATES.has(security.state) && senderUnpinned && !pendingConflict
|
|
974
|
+
? security.signerCertificate
|
|
975
|
+
: undefined;
|
|
976
|
+
const keyChanged = security && signerKeyChanged(security) ? security : undefined;
|
|
977
|
+
const pinnedSignerKey = senderKeyState?.pinned[0];
|
|
978
|
+
const recordedConflict =
|
|
979
|
+
keyChanged && sameFingerprint(senderKeyState?.conflict?.observedKey.fingerprint, keyChanged.signerFingerprint)
|
|
980
|
+
? senderKeyState!.conflict
|
|
981
|
+
: undefined;
|
|
982
|
+
|
|
983
|
+
const shownSubject = (protectedSubject ?? displaySubject(message.subject)) || "(no subject)";
|
|
984
|
+
// What the body area shows. Text or HTML the client recovered from a signed or encrypted message is shown as it is (its own sanitizing
|
|
985
|
+
// happens in `MessageBody`, like every body's); anything else is the server's own `/content`. An encrypted message has nothing worth
|
|
986
|
+
// fetching until it has been decrypted (the server only has the ciphertext), so it shows the skeleton meanwhile.
|
|
987
|
+
const bodyContent: BodyContent | undefined =
|
|
988
|
+
security?.text !== undefined
|
|
989
|
+
? { kind: "text", text: security.text }
|
|
990
|
+
: security?.html !== undefined
|
|
991
|
+
? { kind: "html", html: security.html }
|
|
992
|
+
: undefined;
|
|
993
|
+
const bodyTitle = message.subject || "Message content";
|
|
994
|
+
const answered = message.flags.answered === true;
|
|
995
|
+
const forwarded = message.flags.forwarded === true;
|
|
996
|
+
const cardUnread = threadHeader?.unread ?? false;
|
|
997
|
+
const showFooter = footer ?? !inThread;
|
|
998
|
+
// Only a message the server can read and that carries a calendar file is worth asking about an invitation. An encrypted message is out: the
|
|
999
|
+
// server holds only its ciphertext (the calendar file is inside it), so there is nothing for it to find. Drafts and Outbox hold messages
|
|
1000
|
+
// that are being written or sent, not received invitations.
|
|
1001
|
+
const mayHoldInvite = !message.encrypted && !inOutbox && message.folderUid !== draftsFolderUid && attachments.some(isCalendarAttachment);
|
|
1002
|
+
// The calendar file of a message whose invitation card is drawn is the card, not a chip in the attachment list (a nameless "attachment" to click):
|
|
1003
|
+
// it is listed again if the card could not be drawn (no invitation the server can read, or the lookup failed), so the file is never out of reach.
|
|
1004
|
+
const { invite: shownInvite } = useMessageInvite(message.uid, mayHoldInvite);
|
|
1005
|
+
const listedAttachments = shownInvite ? attachments.filter((attachment) => !isCalendarAttachment(attachment)) : attachments;
|
|
1006
|
+
|
|
1007
|
+
const senderRecipient = { displayName: senderName, address: senderAddress };
|
|
1008
|
+
const sendingStatus = (
|
|
1009
|
+
<>
|
|
1010
|
+
{sendInProgress && (
|
|
1011
|
+
<span className="text-xs font-medium text-text-muted shrink-0 py-1 px-2.5 rounded-pill bg-surface-alt">Sending…</span>
|
|
1012
|
+
)}
|
|
1013
|
+
{isSentItems &&
|
|
1014
|
+
(message.recallRequestedAt ? (
|
|
1015
|
+
<span className="text-xs font-medium text-text-muted shrink-0 py-1 px-2.5 rounded-pill bg-surface-alt">Recall requested</span>
|
|
1016
|
+
) : (
|
|
1017
|
+
<Button type="button" variant="secondary" className="!w-auto shrink-0" onClick={() => setConfirming(true)}>
|
|
1018
|
+
Recall this message
|
|
1019
|
+
</Button>
|
|
1020
|
+
))}
|
|
1021
|
+
{inOutbox && !sendInProgress && message.scheduledSendTime && (
|
|
1022
|
+
<div className="flex items-center gap-2 shrink-0">
|
|
1023
|
+
<span className="text-xs font-medium text-text-muted py-1 px-2.5 rounded-pill bg-surface-alt">
|
|
1024
|
+
Scheduled for {new Date(message.scheduledSendTime).toLocaleString()}
|
|
1025
|
+
</span>
|
|
1026
|
+
<Button type="button" variant="secondary" className="!w-auto" loading={canceling} disabled={canceling} onClick={handleCancelScheduledSend}>
|
|
1027
|
+
Cancel
|
|
1028
|
+
</Button>
|
|
1029
|
+
</div>
|
|
1030
|
+
)}
|
|
1031
|
+
{/* A message left in Outbox with no active schedule - a scheduled send that failed or was refused
|
|
1032
|
+
(restapi's ScheduledSendJob clears scheduledSendTime and leaves it there), which can't be sent
|
|
1033
|
+
again from Outbox (409) or archived - would otherwise be stuck. Moving it back to Drafts works for
|
|
1034
|
+
any Outbox message. */}
|
|
1035
|
+
{inOutbox && !sendInProgress && !message.scheduledSendTime && draftsFolderUid && (
|
|
1036
|
+
<Button type="button" variant="secondary" className="!w-auto shrink-0" loading={canceling} disabled={canceling} onClick={handleCancelScheduledSend}>
|
|
1037
|
+
Move to Drafts
|
|
1038
|
+
</Button>
|
|
1039
|
+
)}
|
|
1040
|
+
</>
|
|
1041
|
+
);
|
|
1042
|
+
|
|
1043
|
+
const card = (
|
|
1044
|
+
<CardShell unread={cardUnread}>
|
|
1045
|
+
{/* Header row: who it is from, when, and what can be done with it. Wraps: on a phone the actions drop under the sender. */}
|
|
1046
|
+
<div className={["flex flex-wrap items-start gap-x-3 gap-y-1 px-4 pt-3 pb-2", cardUnread ? "bg-primary/[0.07]" : ""].join(" ")}>
|
|
1047
|
+
<SenderAvatar from={senderRecipient} />
|
|
1048
|
+
<div className="flex-1 min-w-[12rem]">
|
|
1049
|
+
<div className="flex flex-wrap items-center gap-x-2 gap-y-1">
|
|
1050
|
+
{threadHeader ? (
|
|
1051
|
+
// The sender line of a message in a thread is the button that collapses it again.
|
|
1052
|
+
<h2 className="min-w-0 flex-1" style={BODY_FONT_STYLE}>
|
|
1053
|
+
<button
|
|
1054
|
+
type="button"
|
|
1055
|
+
ref={threadHeader.buttonRef}
|
|
1056
|
+
onClick={threadHeader.onToggle}
|
|
1057
|
+
aria-expanded={true}
|
|
1058
|
+
aria-controls={threadHeader.bodyId}
|
|
1059
|
+
className={[
|
|
1060
|
+
"w-full text-left rounded-sm text-sm",
|
|
1061
|
+
ROW_FOCUS_CLASS,
|
|
1062
|
+
].join(" ")}
|
|
1063
|
+
>
|
|
1064
|
+
<UnreadLabel unread={cardUnread} />
|
|
1065
|
+
<MailAddress recipient={senderRecipient} className={senderClass(cardUnread)} />
|
|
1066
|
+
</button>
|
|
1067
|
+
</h2>
|
|
1068
|
+
) : (
|
|
1069
|
+
<p className="text-sm break-words min-w-0">
|
|
1070
|
+
From <span className="font-semibold text-text">{senderLabel}</span>
|
|
1071
|
+
</p>
|
|
1072
|
+
)}
|
|
1073
|
+
{security && <SecurityIndicator security={security} />}
|
|
1074
|
+
</div>
|
|
1075
|
+
{senderNameCheck.misleading && (
|
|
1076
|
+
<p role="status" className="mt-2 py-2 px-3 rounded-sm text-sm bg-warning/15 text-text">
|
|
1077
|
+
The sender’s name “{senderName}” looks like an email address, but this message was
|
|
1078
|
+
sent from <span className="font-medium">{senderAddress}</span>. Don’t trust it based on the name.
|
|
1079
|
+
</p>
|
|
1080
|
+
)}
|
|
1081
|
+
{/* Every recipient with their address, grouped as the sender addressed them; a long list folds. */}
|
|
1082
|
+
<RecipientLine label="To" recipients={message.recipients.filter((r) => r.type !== "cc" && r.type !== "bcc")} />
|
|
1083
|
+
<RecipientLine label="Cc" recipients={message.recipients.filter((r) => r.type === "cc")} />
|
|
1084
|
+
<RecipientLine label="Bcc" recipients={message.recipients.filter((r) => r.type === "bcc")} />
|
|
1085
|
+
</div>
|
|
1086
|
+
<div className="ml-auto flex flex-wrap items-center justify-end gap-1">
|
|
1087
|
+
<time dateTime={message.receivedDate} className={["text-xs mr-1", dateClass(cardUnread)].join(" ")}>
|
|
1088
|
+
{new Date(message.receivedDate).toLocaleString()}
|
|
1089
|
+
</time>
|
|
1090
|
+
{adaptable && (
|
|
1091
|
+
<button
|
|
1092
|
+
type="button"
|
|
1093
|
+
aria-label="View original"
|
|
1094
|
+
aria-pressed={viewOriginal}
|
|
1095
|
+
title={viewOriginal ? "Follow the theme" : "View original"}
|
|
1096
|
+
onClick={() => setViewOriginal(!viewOriginal)}
|
|
1097
|
+
className={[
|
|
1098
|
+
"inline-flex items-center justify-center p-1.5 rounded-md border border-border text-sm text-text hover:bg-surface-alt",
|
|
1099
|
+
viewOriginal ? "bg-primary/10" : "",
|
|
1100
|
+
].join(" ")}
|
|
1101
|
+
>
|
|
1102
|
+
{viewOriginal ? <HiOutlineMoon size={16} aria-hidden="true" /> : <HiOutlineSun size={16} aria-hidden="true" />}
|
|
1103
|
+
</button>
|
|
1104
|
+
)}
|
|
1105
|
+
{/* Wraps: in a thread the pane can be as narrow as the reading pane gets (the list takes
|
|
1106
|
+
384px of it), and these are six controls. */}
|
|
1107
|
+
<IconAction
|
|
1108
|
+
icon={<HiOutlineArrowUturnLeft size={16} aria-hidden="true" />}
|
|
1109
|
+
label="Reply"
|
|
1110
|
+
shortcut={keyboard ? SHORTCUTS.mail.reply : undefined}
|
|
1111
|
+
disabled={preparingCompose}
|
|
1112
|
+
onPrefetch={prefetchReply}
|
|
1113
|
+
onClick={() => void handleReplyOrForward("reply")}
|
|
1114
|
+
/>
|
|
1115
|
+
<IconAction
|
|
1116
|
+
icon={
|
|
1117
|
+
// The conventional reply-all glyph: the reply arrow, doubled. `hi2` has no
|
|
1118
|
+
// reply-all icon of its own, and nothing else in it means "answer everyone".
|
|
1119
|
+
<span className="inline-flex items-center" aria-hidden="true">
|
|
1120
|
+
<HiOutlineArrowUturnLeft size={16} />
|
|
1121
|
+
<HiOutlineArrowUturnLeft size={16} className="-ml-2.5" />
|
|
1122
|
+
</span>
|
|
1123
|
+
}
|
|
1124
|
+
label="Reply All"
|
|
1125
|
+
shortcut={keyboard ? SHORTCUTS.mail.replyAll : undefined}
|
|
1126
|
+
disabled={preparingCompose}
|
|
1127
|
+
onPrefetch={prefetchReply}
|
|
1128
|
+
onClick={() => void handleReplyOrForward("replyAll")}
|
|
1129
|
+
/>
|
|
1130
|
+
<IconAction
|
|
1131
|
+
icon={<HiOutlineArrowUturnRight size={16} aria-hidden="true" />}
|
|
1132
|
+
label="Forward"
|
|
1133
|
+
shortcut={keyboard ? SHORTCUTS.mail.forward : undefined}
|
|
1134
|
+
disabled={preparingCompose}
|
|
1135
|
+
onPrefetch={prefetchReply}
|
|
1136
|
+
onClick={() => void handleReplyOrForward("forward")}
|
|
1137
|
+
/>
|
|
1138
|
+
{archivable && (
|
|
1139
|
+
<IconAction
|
|
1140
|
+
icon={<HiOutlineArchiveBox size={16} aria-hidden="true" />}
|
|
1141
|
+
label="Archive"
|
|
1142
|
+
shortcut={keyboard ? SHORTCUTS.mail.archive : undefined}
|
|
1143
|
+
busy={archiving}
|
|
1144
|
+
disabled={archiving}
|
|
1145
|
+
onClick={handleArchive}
|
|
1146
|
+
/>
|
|
1147
|
+
)}
|
|
1148
|
+
{movable && (
|
|
1149
|
+
<IconAction
|
|
1150
|
+
icon={<HiOutlineFolderArrowDown size={16} aria-hidden="true" />}
|
|
1151
|
+
label="Move to"
|
|
1152
|
+
shortcut={keyboard ? SHORTCUTS.mail.move : undefined}
|
|
1153
|
+
onClick={() => setMovePrompt(true)}
|
|
1154
|
+
/>
|
|
1155
|
+
)}
|
|
1156
|
+
{labels && labels.length > 0 && (
|
|
1157
|
+
<LabelMenuButton
|
|
1158
|
+
aria-label="Labels"
|
|
1159
|
+
label="Labels"
|
|
1160
|
+
className="border border-border py-1.5"
|
|
1161
|
+
labels={labels}
|
|
1162
|
+
mailboxUid={message.mailboxUid}
|
|
1163
|
+
onLabelCreated={onLabelCreated}
|
|
1164
|
+
applied={currentLabelsMessage.labelUids ?? []}
|
|
1165
|
+
onCommit={(labelUids) => void handleApplyLabels(labelUids)}
|
|
1166
|
+
busy={savingLabels}
|
|
1167
|
+
note="Ticked labels are applied to this message and unticked ones removed."
|
|
1168
|
+
emptyNote="This mailbox has no labels yet."
|
|
1169
|
+
commit={{ label: "Apply" }}
|
|
1170
|
+
clear={{ label: "Remove all labels" }}
|
|
1171
|
+
/>
|
|
1172
|
+
)}
|
|
1173
|
+
</div>
|
|
1174
|
+
</div>
|
|
1175
|
+
|
|
1176
|
+
{/* A slim bar for what has been done with the message. */}
|
|
1177
|
+
{(answered || forwarded) && (
|
|
1178
|
+
<p className="px-4 py-1.5 text-xs text-text-muted bg-surface-alt border-y border-border">
|
|
1179
|
+
{answered && forwarded ? "You replied to and forwarded this message." : answered ? "You replied to this message." : "You forwarded this message."}
|
|
1180
|
+
</p>
|
|
1181
|
+
)}
|
|
1182
|
+
|
|
1183
|
+
<div id={threadHeader?.bodyId} className="px-4 pb-3 flex flex-col gap-2">
|
|
1184
|
+
{inThread && (subjectDiffers || !sameSubject(shownSubject, threadSubject)) && (
|
|
1185
|
+
<h3 className="text-sm font-semibold break-words">{shownSubject}</h3>
|
|
1186
|
+
)}
|
|
1187
|
+
<div className="flex flex-wrap items-center gap-2 empty:hidden">{sendingStatus}</div>
|
|
1188
|
+
{inOutbox && message.scheduledSendError && <Alert>This message wasn’t sent: {message.scheduledSendError}</Alert>}
|
|
1189
|
+
{cancelError && <Alert>{cancelError}</Alert>}
|
|
1190
|
+
{keyChangeNotice && (
|
|
1191
|
+
<p role="status" className="py-2 px-3 rounded-sm text-sm bg-surface-alt text-text">
|
|
1192
|
+
{keyChangeNotice}
|
|
1193
|
+
</p>
|
|
1194
|
+
)}
|
|
1195
|
+
{security && UNVERIFIED_SIGNER_STATES.has(security.state) && (
|
|
1196
|
+
// Informational: the signature is intact, but nothing ties its certificate to this sender - anyone can
|
|
1197
|
+
// create a certificate naming any address. "Trust this signer" (below) pins it once the reader has
|
|
1198
|
+
// confirmed the fingerprint.
|
|
1199
|
+
<p role="status" className="py-2 px-3 rounded-sm text-sm bg-surface-alt text-text">
|
|
1200
|
+
Signed, but the signer isn’t a trusted contact key, so the sender isn’t verified.
|
|
1201
|
+
{security.signerEmails && security.signerEmails.length > 0 && <> Certificate for {security.signerEmails.join(", ")}.</>}
|
|
1202
|
+
{security.signerFingerprint && (
|
|
1203
|
+
<>
|
|
1204
|
+
{" "}
|
|
1205
|
+
Fingerprint <span className="font-mono text-xs break-all">{security.signerFingerprint}</span>.
|
|
1206
|
+
</>
|
|
1207
|
+
)}
|
|
1208
|
+
</p>
|
|
1209
|
+
)}
|
|
1210
|
+
{pendingConflict && (
|
|
1211
|
+
// Only an unverified signer's result loads the key state while the sender is unpinned, and a conflict
|
|
1212
|
+
// always comes from a matching contact, so its uid is known.
|
|
1213
|
+
<p role="status" className="py-2 px-3 rounded-sm text-sm bg-warning/15 text-text">
|
|
1214
|
+
This sender has a signing key change waiting for your review, so this signer can’t be trusted from
|
|
1215
|
+
here.{" "}
|
|
1216
|
+
<a
|
|
1217
|
+
href={`/contacts/${encodeURIComponent(senderKeyState.contactUid!)}`}
|
|
1218
|
+
className="font-medium text-primary-dark hover:underline"
|
|
1219
|
+
>
|
|
1220
|
+
Review it in Contacts
|
|
1221
|
+
</a>
|
|
1222
|
+
</p>
|
|
1223
|
+
)}
|
|
1224
|
+
{trustableCertificate && (
|
|
1225
|
+
<div>
|
|
1226
|
+
<Button
|
|
1227
|
+
type="button"
|
|
1228
|
+
variant="secondary"
|
|
1229
|
+
className="!w-auto"
|
|
1230
|
+
disabled={trusting}
|
|
1231
|
+
onClick={() => {
|
|
1232
|
+
setTrustError(null);
|
|
1233
|
+
setTrustConfirmOpen(true);
|
|
1234
|
+
}}
|
|
1235
|
+
>
|
|
1236
|
+
Trust this signer
|
|
1237
|
+
</Button>
|
|
1238
|
+
</div>
|
|
1239
|
+
)}
|
|
1240
|
+
{subjectDiffers && (
|
|
1241
|
+
<p role="status" className="py-2 px-3 rounded-sm text-sm bg-surface-alt text-text">
|
|
1242
|
+
The subject shown above is the one the sender signed. It differs from the subject this message was
|
|
1243
|
+
delivered with (“{message.subject}”), which may have been changed on the way, e.g. by a
|
|
1244
|
+
mailing list.
|
|
1245
|
+
</p>
|
|
1246
|
+
)}
|
|
1247
|
+
{security?.headerTamperDetected && (
|
|
1248
|
+
<Alert>
|
|
1249
|
+
This message's visible From/To/Cc/Date/Subject don't match what the sender actually signed or
|
|
1250
|
+
encrypted — an intermediary may have altered them after sending. Treat the fields shown above with
|
|
1251
|
+
caution.
|
|
1252
|
+
</Alert>
|
|
1253
|
+
)}
|
|
1254
|
+
{security?.state === "verified_at_first_open" && (
|
|
1255
|
+
// A seal outranks only a key-status failure (see `evaluateMessageSecurityWithSeal()`). A signer key
|
|
1256
|
+
// later reported compromised is a warning, never reassurance.
|
|
1257
|
+
<p
|
|
1258
|
+
role="status"
|
|
1259
|
+
className={`py-2 px-3 rounded-sm text-sm text-text ${security.laterCompromised ? "bg-warning/15" : "bg-surface-alt"}`}
|
|
1260
|
+
>
|
|
1261
|
+
{verifiedAtFirstOpenMessage(security)}
|
|
1262
|
+
</p>
|
|
1263
|
+
)}
|
|
1264
|
+
{keyChanged && (
|
|
1265
|
+
<section aria-label="Signing key changed" className="py-3 px-3 rounded-sm text-sm bg-warning/15 text-text flex flex-col gap-2">
|
|
1266
|
+
<h2 className="font-semibold">This sender’s signing key changed</h2>
|
|
1267
|
+
<p>
|
|
1268
|
+
The signature on this message is valid and its certificate names {senderAddress}, but it was made
|
|
1269
|
+
with a different key than the one you trust for this sender
|
|
1270
|
+
{keyChanged.state === "verified_at_first_open" ? "." : <>, so it isn’t verified.</>}
|
|
1271
|
+
</p>
|
|
1272
|
+
<KeyChangeReview
|
|
1273
|
+
mailboxUid={message.mailboxUid}
|
|
1274
|
+
address={senderAddress}
|
|
1275
|
+
useType="sign"
|
|
1276
|
+
ownerName="the sender"
|
|
1277
|
+
current={pinnedSignerKey && { fingerprint: pinnedSignerKey.fingerprint, since: senderKeyState.pinnedSince! }}
|
|
1278
|
+
proposed={{
|
|
1279
|
+
fingerprint: keyChanged.signerFingerprint!,
|
|
1280
|
+
emails: keyChanged.signerEmails,
|
|
1281
|
+
observedAt: recordedConflict?.observedAt,
|
|
1282
|
+
source: recordedConflict?.source,
|
|
1283
|
+
}}
|
|
1284
|
+
certificate={keyChanged.signerCertificate}
|
|
1285
|
+
canReject={recordedConflict !== undefined}
|
|
1286
|
+
canResolve={canUpdateMailbox}
|
|
1287
|
+
onResolved={(action) => refreshAfterKeyChange(action === "reject" ? KEPT_CURRENT_SIGNING_KEY_MESSAGE : null)}
|
|
1288
|
+
onPinnedKeyChanged={() => refreshAfterKeyChange(KEY_CHANGE_STALE_MESSAGE)}
|
|
1289
|
+
/>
|
|
1290
|
+
</section>
|
|
1291
|
+
)}
|
|
1292
|
+
{security?.state === "signature_failed" && !keyChanged && (
|
|
1293
|
+
// Deliberately an informational notice, not an error `Alert`: an unverifiable signature
|
|
1294
|
+
// means "don't trust the signer", not "this message is broken" - the body stays readable.
|
|
1295
|
+
<p role="status" className="py-2 px-3 rounded-sm text-sm bg-surface-alt text-text">
|
|
1296
|
+
{security.signatureFailureReason
|
|
1297
|
+
? SIGNATURE_FAILURE_MESSAGE[security.signatureFailureReason]
|
|
1298
|
+
: GENERIC_SIGNATURE_FAILURE_MESSAGE}
|
|
1299
|
+
</p>
|
|
1300
|
+
)}
|
|
1301
|
+
{verifiedOrSealed && !security.protectedHeaders && (
|
|
1302
|
+
// A legacy S/MIME sender signs only the body: the outer Subject/To/Cc shown here were never signed.
|
|
1303
|
+
<p role="status" className="py-2 px-3 rounded-sm text-sm bg-surface-alt text-text">
|
|
1304
|
+
The signature covers this message’s content and attachments only. Its Subject, To and Cc
|
|
1305
|
+
weren’t signed, so they could have been changed after it was sent.
|
|
1306
|
+
</p>
|
|
1307
|
+
)}
|
|
1308
|
+
{security?.notAddressedToReader && !isSentItems && (
|
|
1309
|
+
// Informational, like the notice above: a Bcc recipient legitimately sees this too. Never shown in Sent
|
|
1310
|
+
// Items: the sender's own address is (by design, see ComposeWindow/sendJob) never one of the protected
|
|
1311
|
+
// To/Cc headers of a message it sent to someone else, so this would otherwise fire on every ordinary sent
|
|
1312
|
+
// message rather than the genuine forwarded/re-sent/Bcc cases it's meant to flag.
|
|
1313
|
+
<p role="status" className="py-2 px-3 rounded-sm text-sm bg-surface-alt text-text">
|
|
1314
|
+
The recipients this message was signed or encrypted for don’t include this mailbox - it may have
|
|
1315
|
+
been forwarded or re-sent to you unchanged, or you were Bcc’d.
|
|
1316
|
+
</p>
|
|
1317
|
+
)}
|
|
1318
|
+
{archiveError && <Alert>{archiveError}</Alert>}
|
|
1319
|
+
{labelsError && <Alert>{labelsError}</Alert>}
|
|
1320
|
+
{labels && (currentLabelsMessage.labelUids?.length ?? 0) > 0 && (
|
|
1321
|
+
<div className="flex flex-wrap items-center gap-1.5">
|
|
1322
|
+
{currentLabelsMessage
|
|
1323
|
+
.labelUids!.map((uid) => labels.find((l) => l.uid === uid))
|
|
1324
|
+
.filter((l): l is Label => !!l)
|
|
1325
|
+
.map((l) => (
|
|
1326
|
+
<span
|
|
1327
|
+
key={l.uid}
|
|
1328
|
+
className="inline-flex items-center gap-1.5 text-xs font-medium py-1 px-2.5 rounded-pill bg-surface-alt"
|
|
1329
|
+
>
|
|
1330
|
+
<span className="w-2 h-2 rounded-full shrink-0" style={{ backgroundColor: l.color ?? "#6366f1" }} />
|
|
1331
|
+
{l.name}
|
|
1332
|
+
</span>
|
|
1333
|
+
))}
|
|
1334
|
+
</div>
|
|
1335
|
+
)}
|
|
1336
|
+
{/* A failed reclassification is reported inside the confirmation dialog it was started
|
|
1337
|
+
from, next to the Move button that would retry it - not out here behind it. */}
|
|
1338
|
+
{(["delivery", "read"] as const)
|
|
1339
|
+
.filter((type) => (type === "delivery" ? message.deliveryReceiptPending : message.readReceiptPending))
|
|
1340
|
+
.map((type) => (
|
|
1341
|
+
<div key={type} className="flex flex-wrap items-center gap-2 py-2 px-3 rounded-sm bg-surface-alt text-sm">
|
|
1342
|
+
<span>
|
|
1343
|
+
{senderLabel} requested a {type} receipt for this
|
|
1344
|
+
message.
|
|
1345
|
+
</span>
|
|
1346
|
+
<Button
|
|
1347
|
+
type="button"
|
|
1348
|
+
variant="secondary"
|
|
1349
|
+
className="!w-auto"
|
|
1350
|
+
loading={receiptBusy === type}
|
|
1351
|
+
disabled={receiptBusy !== null}
|
|
1352
|
+
onClick={() => handleReceipt(type, "approve")}
|
|
1353
|
+
>
|
|
1354
|
+
Send receipt
|
|
1355
|
+
</Button>
|
|
1356
|
+
<Button type="button" variant="text" disabled={receiptBusy !== null} onClick={() => handleReceipt(type, "decline")}>
|
|
1357
|
+
Decline
|
|
1358
|
+
</Button>
|
|
1359
|
+
</div>
|
|
1360
|
+
))}
|
|
1361
|
+
{receiptError && <Alert>{receiptError}</Alert>}
|
|
1362
|
+
{mayHoldInvite && <InviteCard messageUid={message.uid} headingLevel={inThread ? 3 : 2} />}
|
|
1363
|
+
{security?.state === "signature_failed" && innerAttachments && innerAttachments.length > 0 && (
|
|
1364
|
+
<p role="status" className="py-2 px-3 rounded-sm text-sm bg-warning/15 text-text">
|
|
1365
|
+
These attachments come from a message whose signature couldn’t be verified. Open them only if
|
|
1366
|
+
you trust the sender.
|
|
1367
|
+
</p>
|
|
1368
|
+
)}
|
|
1369
|
+
{innerAttachments
|
|
1370
|
+
? innerAttachments.length > 0 && (
|
|
1371
|
+
<ul className="flex flex-wrap gap-2">
|
|
1372
|
+
{innerAttachments.map((attachment, index) => (
|
|
1373
|
+
<li key={`${index}:${attachment.filename ?? ""}`}>
|
|
1374
|
+
<button
|
|
1375
|
+
type="button"
|
|
1376
|
+
onClick={() => downloadMimeAttachment(attachment)}
|
|
1377
|
+
className="text-xs font-medium py-1 px-2.5 rounded-pill bg-surface-alt text-text-muted hover:text-primary-dark"
|
|
1378
|
+
>
|
|
1379
|
+
{attachment.filename ?? `Unnamed ${attachment.contentType} attachment`}
|
|
1380
|
+
</button>
|
|
1381
|
+
</li>
|
|
1382
|
+
))}
|
|
1383
|
+
</ul>
|
|
1384
|
+
)
|
|
1385
|
+
: listedAttachments.length > 0 && (
|
|
1386
|
+
<ul className="flex flex-wrap gap-2">
|
|
1387
|
+
{listedAttachments.map((attachment) => (
|
|
1388
|
+
<li key={attachment.uid}>
|
|
1389
|
+
<a
|
|
1390
|
+
href={attachmentContentUrl(attachment.uid)}
|
|
1391
|
+
className="text-xs font-medium py-1 px-2.5 rounded-pill bg-surface-alt text-text-muted hover:text-primary-dark"
|
|
1392
|
+
>
|
|
1393
|
+
{attachment.filename} ({formatBytes(attachment.sizeBytes)})
|
|
1394
|
+
</a>
|
|
1395
|
+
</li>
|
|
1396
|
+
))}
|
|
1397
|
+
</ul>
|
|
1398
|
+
)}
|
|
1399
|
+
{/* The body: an isolated frame exactly as tall as its content (or text), in the card's own place. A decrypted or verified
|
|
1400
|
+
body never came through the server's own sanitizer (the server never saw the plaintext); `MessageBody` sanitizes every body
|
|
1401
|
+
client-side regardless, behind a no-remote-loads CSP, in a frame that runs no script. */}
|
|
1402
|
+
<div ref={bodyRegionRef} tabIndex={-1} className="outline-none">
|
|
1403
|
+
{message.encrypted && security === null ? (
|
|
1404
|
+
<BodySkeleton />
|
|
1405
|
+
) : security?.decryptError !== undefined ? (
|
|
1406
|
+
// An encrypted message that could not be read: locked (no unlocked keys - the button asks the app's own unlock prompt, and the message
|
|
1407
|
+
// then decrypts in place) or genuinely unreadable (keys unlocked and it still didn't open - the reason, and nothing to click).
|
|
1408
|
+
<EncryptedBody locked={lockedRef.current} reason={security.decryptError} unlocking={unlocking} onUnlock={() => void handleUnlockToView()} />
|
|
1409
|
+
) : (
|
|
1410
|
+
<MessageBody
|
|
1411
|
+
messageUid={message.uid}
|
|
1412
|
+
messageVersion={message.version}
|
|
1413
|
+
title={bodyTitle}
|
|
1414
|
+
content={bodyContent}
|
|
1415
|
+
attachments={attachments}
|
|
1416
|
+
inlineParts={innerAttachments}
|
|
1417
|
+
original={viewOriginal}
|
|
1418
|
+
onAdaptable={setAdaptable}
|
|
1419
|
+
/>
|
|
1420
|
+
)}
|
|
1421
|
+
</div>
|
|
1422
|
+
</div>
|
|
1423
|
+
|
|
1424
|
+
{showFooter && (
|
|
1425
|
+
<div className="flex flex-wrap gap-2 px-4 py-3 border-t border-border print:hidden">
|
|
1426
|
+
<Button
|
|
1427
|
+
type="button"
|
|
1428
|
+
variant="secondary"
|
|
1429
|
+
className="!w-auto"
|
|
1430
|
+
aria-label="Reply to this message"
|
|
1431
|
+
disabled={preparingCompose}
|
|
1432
|
+
onClick={() => void handleReplyOrForward("reply")}
|
|
1433
|
+
>
|
|
1434
|
+
Reply
|
|
1435
|
+
</Button>
|
|
1436
|
+
<Button
|
|
1437
|
+
type="button"
|
|
1438
|
+
variant="secondary"
|
|
1439
|
+
className="!w-auto"
|
|
1440
|
+
aria-label="Reply all to this message"
|
|
1441
|
+
disabled={preparingCompose}
|
|
1442
|
+
onClick={() => void handleReplyOrForward("replyAll")}
|
|
1443
|
+
>
|
|
1444
|
+
Reply All
|
|
1445
|
+
</Button>
|
|
1446
|
+
<Button
|
|
1447
|
+
type="button"
|
|
1448
|
+
variant="secondary"
|
|
1449
|
+
className="!w-auto"
|
|
1450
|
+
aria-label="Forward this message"
|
|
1451
|
+
disabled={preparingCompose}
|
|
1452
|
+
onClick={() => void handleReplyOrForward("forward")}
|
|
1453
|
+
>
|
|
1454
|
+
Forward
|
|
1455
|
+
</Button>
|
|
1456
|
+
</div>
|
|
1457
|
+
)}
|
|
1458
|
+
</CardShell>
|
|
1459
|
+
);
|
|
1460
|
+
|
|
1461
|
+
return (
|
|
1462
|
+
// `h-full` outside a thread only: the standalone message route renders this pane straight into a
|
|
1463
|
+
// *block* (`MailShell`'s own `<main>`), where nothing stretches it and a percentage of that block's
|
|
1464
|
+
// own resolved height is the height. Inside a thread the card is one row of the thread's own list.
|
|
1465
|
+
<div className={inThread ? "min-w-0" : "flex-1 min-w-0 min-h-0 flex flex-col h-full"}>
|
|
1466
|
+
{inThread ? (
|
|
1467
|
+
card
|
|
1468
|
+
) : (
|
|
1469
|
+
<>
|
|
1470
|
+
{backHref && (
|
|
1471
|
+
<a href={backHref} className="text-sm text-primary-dark hover:underline block px-4 pt-3">
|
|
1472
|
+
← Back to messages
|
|
1473
|
+
</a>
|
|
1474
|
+
)}
|
|
1475
|
+
{/* The subject has a card of its own, above the message, that stays put while the message scrolls. */}
|
|
1476
|
+
<SubjectCard subject={shownSubject} />
|
|
1477
|
+
<div className="flex-1 min-h-0 overflow-y-auto p-2 sm:p-3 flex flex-col gap-3">{card}</div>
|
|
1478
|
+
</>
|
|
1479
|
+
)}
|
|
1480
|
+
|
|
1481
|
+
<MoveToFolderDialog
|
|
1482
|
+
open={movePrompt}
|
|
1483
|
+
onClose={() => setMovePrompt(false)}
|
|
1484
|
+
mailboxUid={message.mailboxUid}
|
|
1485
|
+
folders={folders ?? []}
|
|
1486
|
+
currentFolderUid={message.folderUid}
|
|
1487
|
+
onMove={handleMove}
|
|
1488
|
+
onFolderCreated={onFolderCreated}
|
|
1489
|
+
/>
|
|
1490
|
+
<Modal open={confirming} onClose={() => setConfirming(false)} title="Recall this message?">
|
|
1491
|
+
<p className="text-sm text-text-muted mb-4">
|
|
1492
|
+
This asks every original recipient's mail system to delete their copy, but only if it's
|
|
1493
|
+
still unread there — there's no way to guarantee it, and no confirmation once it either
|
|
1494
|
+
succeeds or fails. Recipients who already read the message will keep it.
|
|
1495
|
+
</p>
|
|
1496
|
+
{error && <Alert>{error}</Alert>}
|
|
1497
|
+
<div className="flex gap-3">
|
|
1498
|
+
<Button type="button" loading={recalling} disabled={recalling} onClick={handleRecall} className="!w-auto">
|
|
1499
|
+
Recall message
|
|
1500
|
+
</Button>
|
|
1501
|
+
<Button
|
|
1502
|
+
type="button"
|
|
1503
|
+
variant="secondary"
|
|
1504
|
+
disabled={recalling}
|
|
1505
|
+
onClick={() => setConfirming(false)}
|
|
1506
|
+
className="!w-auto"
|
|
1507
|
+
>
|
|
1508
|
+
Cancel
|
|
1509
|
+
</Button>
|
|
1510
|
+
</div>
|
|
1511
|
+
</Modal>
|
|
1512
|
+
<Modal
|
|
1513
|
+
open={trustConfirmOpen && !!trustableCertificate}
|
|
1514
|
+
onClose={() => !trusting && setTrustConfirmOpen(false)}
|
|
1515
|
+
title="Trust this signer?"
|
|
1516
|
+
>
|
|
1517
|
+
<div className="flex flex-col gap-3 text-sm">
|
|
1518
|
+
<p>
|
|
1519
|
+
Mail from <span className="font-medium">{senderAddress}</span> signed with this certificate will show as
|
|
1520
|
+
verified.
|
|
1521
|
+
</p>
|
|
1522
|
+
<dl className="flex flex-col gap-1">
|
|
1523
|
+
<dt className="text-xs text-text-muted">Certificate issued to</dt>
|
|
1524
|
+
<dd>{security?.signerEmails?.length ? security.signerEmails.join(", ") : "No email address"}</dd>
|
|
1525
|
+
<dt className="text-xs text-text-muted">Fingerprint</dt>
|
|
1526
|
+
<dd className="font-mono text-xs break-all">
|
|
1527
|
+
{security?.signerFingerprint ? formatFingerprint(security.signerFingerprint) : "Unknown"}
|
|
1528
|
+
</dd>
|
|
1529
|
+
</dl>
|
|
1530
|
+
<p className="text-text-muted">
|
|
1531
|
+
Anyone can create a certificate naming any address. Before trusting it, confirm this fingerprint with
|
|
1532
|
+
the sender through another channel, such as a phone call.
|
|
1533
|
+
</p>
|
|
1534
|
+
{trustError && <Alert>{trustError}</Alert>}
|
|
1535
|
+
<div className="flex gap-3">
|
|
1536
|
+
<Button
|
|
1537
|
+
type="button"
|
|
1538
|
+
className="!w-auto"
|
|
1539
|
+
loading={trusting}
|
|
1540
|
+
disabled={trusting}
|
|
1541
|
+
onClick={() => handleTrustSigner(senderAddress, trustableCertificate!)}
|
|
1542
|
+
>
|
|
1543
|
+
Trust
|
|
1544
|
+
</Button>
|
|
1545
|
+
<Button
|
|
1546
|
+
type="button"
|
|
1547
|
+
variant="secondary"
|
|
1548
|
+
className="!w-auto"
|
|
1549
|
+
disabled={trusting}
|
|
1550
|
+
onClick={() => setTrustConfirmOpen(false)}
|
|
1551
|
+
>
|
|
1552
|
+
Cancel
|
|
1553
|
+
</Button>
|
|
1554
|
+
</div>
|
|
1555
|
+
</div>
|
|
1556
|
+
</Modal>
|
|
1557
|
+
</div>
|
|
1558
|
+
);
|
|
1559
|
+
}
|