@open-workspace/email 0.4.2 → 0.5.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 +9 -4
- package/alchemy/index.ts +130 -2
- package/drizzle/mailbox/0003_after_0_4_2.sql +180 -0
- package/drizzle/mailbox/meta/0003_snapshot.json +1507 -0
- package/drizzle/mailbox/meta/_journal.json +7 -0
- package/drizzle/mailbox/migrations.js +3 -1
- package/migrations/0002_after_0_4_2.sql +35 -0
- package/migrations/meta/0002_snapshot.json +807 -0
- package/migrations/meta/_journal.json +7 -0
- package/package.json +23 -7
- package/shared/attachment-preview.ts +18 -8
- package/shared/folder-order.ts +31 -6
- package/shared/mail-headers.ts +3 -3
- package/shared/mail-html.ts +25 -0
- package/shared/mail-import.ts +0 -7
- package/shared/mail-received.ts +4 -4
- package/shared/mail-rule-actions.ts +47 -0
- package/shared/mail.ts +70 -4
- package/shared/office-preview.ts +0 -4
- package/shared/pdfjs-assets.ts +1 -3
- package/shared/rich-content.ts +35 -0
- package/shared/signature.ts +15 -0
- package/src/admin/address-auto-reply.tsx +49 -0
- package/src/admin/blocked-senders.tsx +86 -66
- package/src/admin/forward-destinations.tsx +140 -0
- package/src/admin/mail-archive.tsx +134 -0
- package/src/admin/team-signature.tsx +90 -0
- package/src/client.tsx +130 -16
- package/src/mail/attachment-preview-dialog.tsx +13 -5
- package/src/mail/auto-reply-banner.tsx +61 -0
- package/src/mail/blocked-senders.tsx +124 -91
- package/src/mail/compose-window-chrome.tsx +20 -8
- package/src/mail/compose-window.tsx +387 -365
- package/src/mail/composer-asset-bookmarks.ts +47 -12
- package/src/mail/composer-attachment-list.tsx +42 -17
- package/src/mail/composer-editor-document.ts +54 -10
- package/src/mail/composer-editor.tsx +44 -44
- package/src/mail/composer-link-text.ts +42 -0
- package/src/mail/composer-recipient-fields.tsx +25 -16
- package/src/mail/composer-recipients.ts +62 -16
- package/src/mail/composer-session.ts +107 -23
- package/src/mail/composer-toolbar.tsx +15 -1
- package/src/mail/composer-upload-client.ts +29 -1
- package/src/mail/composer-upload-progress.ts +2 -2
- package/src/mail/conversation-actions-model.ts +56 -0
- package/src/mail/conversation-list.tsx +263 -128
- package/src/mail/conversation-loading-skeleton.tsx +165 -90
- package/src/mail/conversation-message.tsx +257 -102
- package/src/mail/conversation-order.ts +12 -0
- package/src/mail/conversation-reply.tsx +313 -189
- package/src/mail/conversation-selection-toolbar.tsx +188 -143
- package/src/mail/conversation-view.tsx +315 -85
- package/src/mail/delivery-indicator.tsx +33 -12
- package/src/mail/draft-attachments.ts +194 -0
- package/src/mail/email-html-body.tsx +97 -53
- package/src/mail/folder-cleanup-bar.tsx +193 -0
- package/src/mail/folder-glyph.tsx +5 -0
- package/src/mail/folder-manager.tsx +71 -38
- package/src/mail/mail-app-bar.tsx +15 -3
- package/src/mail/mail-dock.tsx +19 -3
- package/src/mail/mail-focus.ts +48 -0
- package/src/mail/mail-folders.ts +14 -2
- package/src/mail/mail-layout.css +20 -0
- package/src/mail/mail-mailbox-sheet.tsx +22 -69
- package/src/mail/mail-nav-rail.tsx +7 -4
- package/src/mail/mail-nav.tsx +66 -46
- package/src/mail/mail-prefetch.ts +30 -9
- package/src/mail/mail-primitives.tsx +6 -4
- package/src/mail/mail-queries.ts +122 -20
- package/src/mail/mail-query-cache.ts +1085 -173
- package/src/mail/mail-search-params.ts +35 -0
- package/src/mail/mail-shell.tsx +32 -9
- package/src/mail/mailbox-ai-settings.tsx +56 -42
- package/src/mail/mailbox-realtime.tsx +4 -12
- package/src/mail/mailbox-rules.tsx +898 -0
- package/src/mail/message-actions.tsx +38 -26
- package/src/mail/message-attachments.tsx +20 -12
- package/src/mail/message-body.ts +53 -0
- package/src/mail/message-format.ts +8 -2
- package/src/mail/message-header.tsx +3 -1
- package/src/mail/message-translation.tsx +34 -67
- package/src/mail/original-message-sheet.tsx +63 -50
- package/src/mail/original-message.ts +6 -6
- package/src/mail/pane-splitter.tsx +3 -3
- package/src/mail/pdf-preview.tsx +70 -62
- package/src/mail/plain-message-text.tsx +28 -0
- package/src/mail/print-message.ts +31 -36
- package/src/mail/reader-pane.tsx +134 -103
- package/src/mail/recipient-combobox.tsx +52 -29
- package/src/mail/recipient-field-row.tsx +3 -0
- package/src/mail/rich-content.ts +128 -0
- package/src/mail/sanitize-email-html.ts +53 -32
- package/src/mail/sender-actions.tsx +48 -46
- package/src/mail/sender-authentication.tsx +1 -1
- package/src/mail/sender-dialogs.tsx +67 -43
- package/src/mail/sender-security.tsx +9 -10
- package/src/mail/signature.ts +43 -0
- package/src/mail/translation-html.ts +3 -3
- package/src/mail/types.ts +12 -0
- package/src/mail/use-composer-attachment-preflight.ts +23 -60
- package/src/mail/use-composer-core.ts +286 -0
- package/src/mail/use-composer-navigation.ts +120 -0
- package/src/mail/use-composer-submission.ts +154 -19
- package/src/mail/use-conversation-actions.ts +292 -0
- package/src/mail/use-conversation-position.ts +51 -0
- package/src/mail/use-conversation-selection.ts +192 -89
- package/src/mail/use-draft-autosave.ts +394 -0
- package/src/mail/use-drafts.ts +194 -0
- package/src/mail/use-mail-controller.ts +754 -213
- package/src/mail/use-mail-data.ts +210 -100
- package/src/mail/use-mail-safety.ts +19 -38
- package/src/mail/use-mail-send.ts +18 -6
- package/src/mail/use-pdf-translation.ts +1 -1
- package/src/mail/use-reply-cc.ts +61 -0
- package/src/mail/use-visible-message-read.ts +128 -64
- package/src/pwa/push-key.ts +18 -0
- package/src/pwa/push-subscription.ts +88 -26
- package/src/settings/auto-reply-editor.tsx +454 -0
- package/src/settings/auto-reply-page.tsx +59 -0
- package/src/settings/mail-apps-page.tsx +52 -43
- package/src/settings/notifications-page.tsx +82 -67
- package/src/settings/rich-content-editor.tsx +182 -0
- package/src/settings/settings-queries.ts +57 -0
- package/src/settings/signature-editor.tsx +142 -0
- package/src/settings/signature-page.tsx +70 -0
- package/worker/admin/blocked-sender-routes.ts +10 -16
- package/worker/backups/eml.ts +185 -0
- package/worker/backups/file-parts.ts +140 -0
- package/worker/backups/mail-backup.ts +644 -0
- package/worker/backups/settings-backup.ts +866 -0
- package/worker/backups/stream-eml.ts +73 -0
- package/worker/db/schema.ts +89 -5
- package/worker/jmap/attachment-blobs.ts +113 -0
- package/worker/jmap/blobs.ts +162 -0
- package/worker/jmap/draft-content.ts +42 -0
- package/worker/jmap/drafts.ts +70 -0
- package/worker/jmap/email-body.ts +152 -0
- package/worker/jmap/email-methods.ts +1223 -0
- package/worker/jmap/eventsource.ts +9 -8
- package/worker/jmap/import-methods.ts +205 -0
- package/worker/jmap/mailbox-methods.ts +187 -0
- package/worker/jmap/method-core.ts +379 -0
- package/worker/jmap/methods.ts +108 -1815
- package/worker/jmap/push-subscription-methods.ts +373 -0
- package/worker/jmap/push-types.ts +46 -2
- package/worker/jmap/push.ts +24 -31
- package/worker/jmap/routes.ts +144 -153
- package/worker/jmap/submission-methods.ts +395 -0
- package/worker/mail/access.ts +35 -12
- package/worker/mail/ai-classification.ts +2 -2
- package/worker/mail/archive-object.ts +96 -0
- package/worker/mail/archive-routes.ts +35 -0
- package/worker/mail/archive.ts +682 -0
- package/worker/mail/auth-headers.ts +48 -40
- package/worker/mail/auto-reply-routes.ts +255 -0
- package/worker/mail/auto-reply.ts +243 -0
- package/worker/mail/bimi.ts +53 -36
- package/worker/mail/bootstrap.ts +11 -3
- package/worker/mail/capabilities.ts +69 -0
- package/worker/mail/classification-signals.ts +1 -1
- package/worker/mail/confusables-data.ts +9 -0
- package/worker/mail/conversation-cursor.ts +6 -15
- package/worker/mail/delivery-events.ts +9 -7
- package/worker/mail/delivery-facts.ts +1 -1
- package/worker/mail/demo-routes.ts +3 -3
- package/worker/mail/doh.ts +3 -3
- package/worker/mail/download-links.ts +153 -0
- package/worker/mail/downloads.ts +2 -6
- package/worker/mail/draft-routes.ts +473 -0
- package/worker/mail/draft-sender.ts +54 -0
- package/worker/mail/edge-cache.ts +41 -55
- package/worker/mail/email-routing.ts +123 -0
- package/worker/mail/forward-destinations.ts +114 -0
- package/worker/mail/forward-downloads.ts +115 -0
- package/worker/mail/forward-html.ts +85 -0
- package/worker/mail/header-metadata.ts +2 -5
- package/worker/mail/impersonation.ts +102 -101
- package/worker/mail/import-routes.ts +29 -82
- package/worker/mail/import.ts +130 -0
- package/worker/mail/inbound-delivery.ts +6 -5
- package/worker/mail/inbound.ts +58 -28
- package/worker/mail/ip-intel.ts +8 -17
- package/worker/mail/isolate-cache.ts +1 -1
- package/worker/mail/mailbox-deletion.ts +33 -12
- package/worker/mail/mailbox-directory.ts +39 -65
- package/worker/mail/mailing-list.ts +29 -58
- package/worker/mail/message-security.ts +3 -3
- package/worker/mail/message-view.ts +12 -10
- package/worker/mail/office-conversion.ts +3 -5
- package/worker/mail/office-preview-container.ts +3 -8
- package/worker/mail/outbound-content.ts +139 -65
- package/worker/mail/outbound-delivery.ts +20 -17
- package/worker/mail/outbound-service.ts +34 -9
- package/worker/mail/outbound.ts +146 -75
- package/worker/mail/outgoing-context.ts +60 -30
- package/worker/mail/participants.ts +10 -15
- package/worker/mail/plain-body.ts +39 -0
- package/worker/mail/push-endpoint.ts +17 -0
- package/worker/mail/push-notifications.ts +53 -62
- package/worker/mail/quote-parser.ts +36 -24
- package/worker/mail/receive.ts +146 -39
- package/worker/mail/recipients.ts +1 -1
- package/worker/mail/remote-proxy.ts +3 -3
- package/worker/mail/repeat.ts +1 -1
- package/worker/mail/reply-plan.ts +124 -26
- package/worker/mail/rfc.ts +15 -7
- package/worker/mail/rich-content.ts +207 -0
- package/worker/mail/routes.ts +696 -304
- package/worker/mail/routing.ts +274 -0
- package/worker/mail/rules.ts +230 -0
- package/worker/mail/safety-routes.ts +88 -86
- package/worker/mail/schemas.ts +222 -31
- package/worker/mail/search.ts +25 -2
- package/worker/mail/security-settings.ts +4 -10
- package/worker/mail/send-message.ts +238 -0
- package/worker/mail/sender-intel.ts +12 -20
- package/worker/mail/signature-routes.ts +201 -0
- package/worker/mail/signatures.ts +195 -0
- package/worker/mail/spamhaus.ts +28 -16
- package/worker/mail/storage-keys.ts +35 -0
- package/worker/mail/unsubscribe.ts +19 -41
- package/worker/mail/uploads.ts +192 -80
- package/worker/mail/webhook-source.ts +3 -2
- package/worker/mail/workspace-safety.ts +194 -60
- package/worker/mailbox/demo.ts +13 -15
- package/worker/mailbox/email-index.ts +65 -35
- package/worker/mailbox/folder-model.ts +0 -20
- package/worker/mailbox/import-placement.ts +21 -36
- package/worker/mailbox/inbound-decision.ts +114 -0
- package/worker/mailbox/inbox-counts.ts +45 -25
- package/worker/mailbox/index.ts +756 -3201
- package/worker/mailbox/jmap-change-log.ts +195 -0
- package/worker/mailbox/jmap-email-rows.ts +186 -0
- package/worker/mailbox/jmap-mailboxes.ts +116 -0
- package/worker/mailbox/jmap-placement.ts +139 -0
- package/worker/mailbox/jmap-query-filter.ts +231 -0
- package/worker/mailbox/jmap-store.ts +167 -299
- package/worker/mailbox/mailbox-auto-reply.ts +301 -0
- package/worker/mailbox/mailbox-backup.ts +538 -0
- package/worker/mailbox/mailbox-drafts.ts +417 -0
- package/worker/mailbox/mailbox-folders.ts +242 -0
- package/worker/mailbox/mailbox-import.ts +450 -0
- package/worker/mailbox/mailbox-inbound.ts +934 -0
- package/worker/mailbox/mailbox-jmap.ts +294 -0
- package/worker/mailbox/mailbox-outbound.ts +413 -0
- package/worker/mailbox/mailbox-rules.ts +336 -0
- package/worker/mailbox/mailbox-senders.ts +294 -0
- package/worker/mailbox/mailbox-storage.ts +438 -0
- package/worker/mailbox/mailbox-views.ts +891 -0
- package/worker/mailbox/model.ts +1 -0
- package/worker/mailbox/office-preview-jobs.ts +59 -47
- package/worker/mailbox/placement.ts +933 -0
- package/worker/mailbox/restore-thread.ts +52 -0
- package/worker/mailbox/retention.ts +36 -0
- package/worker/mailbox/schema.ts +200 -1
- package/worker/mailbox/senders.ts +216 -178
- package/worker/mailbox/spam-undo-filing.ts +138 -0
- package/worker/mailbox/spam-undo.ts +240 -0
- package/worker/mailbox/support.ts +416 -0
- package/worker/mcp/mail-action-tools.ts +156 -0
- package/worker/mcp/mail-compose-tools.ts +7 -1
- package/worker/mcp/mail-safety-tools.ts +4 -4
- package/worker/module.ts +23 -4
- package/src/mail/use-compose-submission.ts +0 -208
- package/src/mail/use-reply-submission.ts +0 -114
- package/worker/mail/capped-body.ts +0 -36
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
Forward,
|
|
22
22
|
Globe,
|
|
23
23
|
Languages,
|
|
24
|
+
ListFilter,
|
|
24
25
|
Mail,
|
|
25
26
|
MailMinus,
|
|
26
27
|
OctagonAlert,
|
|
@@ -35,7 +36,7 @@ import { ReplyActionIcon } from "./conversation-reply";
|
|
|
35
36
|
import { senderName } from "./message-format";
|
|
36
37
|
import { languageName } from "./message-translation";
|
|
37
38
|
import type { MessageTranslationState } from "./message-translation";
|
|
38
|
-
import { printMessage
|
|
39
|
+
import { printMessage } from "./print-message";
|
|
39
40
|
import { ToolbarTooltip } from "./toolbar-tooltip";
|
|
40
41
|
import type { MessageDetail, ReplyAction } from "./types";
|
|
41
42
|
|
|
@@ -48,9 +49,11 @@ const originalShortcutLabel =
|
|
|
48
49
|
|
|
49
50
|
export type MessageHandlers = {
|
|
50
51
|
onViewed: () => Promise<void>;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
send?: {
|
|
53
|
+
reply: (message: MessageDetail, action: ReplyAction) => void;
|
|
54
|
+
forward: (message: MessageDetail) => void;
|
|
55
|
+
resend: (message: MessageDetail) => void;
|
|
56
|
+
};
|
|
54
57
|
/** Present when the message has a stored original to inspect. */
|
|
55
58
|
onShowOriginal?: () => void;
|
|
56
59
|
/** Download URL of the stored original (.eml). */
|
|
@@ -65,6 +68,8 @@ export type SenderHandlers = {
|
|
|
65
68
|
onUnsubscribe?: () => void;
|
|
66
69
|
onBlock?: () => void;
|
|
67
70
|
onUnblock?: () => void;
|
|
71
|
+
/** Opens a new rule with this sender (and list) filled in. */
|
|
72
|
+
onFilter?: () => void;
|
|
68
73
|
/** Reporting spam moves the conversation to Spam; absent where that makes no sense. */
|
|
69
74
|
onReportSpam?: () => void;
|
|
70
75
|
/** "Looks safe": trusts the sender and hides caution hints. */
|
|
@@ -93,28 +98,26 @@ export function actionButtonLabel(action: ReplyAction) {
|
|
|
93
98
|
/** A message's reply button and its "More actions" menu. */
|
|
94
99
|
export function MessageActions({
|
|
95
100
|
message,
|
|
96
|
-
canForward,
|
|
97
101
|
translation,
|
|
98
102
|
resendPending,
|
|
99
103
|
handlers,
|
|
100
104
|
}: {
|
|
101
105
|
message: MessageDetail;
|
|
102
|
-
mailboxId?: string;
|
|
103
|
-
canForward: boolean;
|
|
104
106
|
translation: MessageTranslationState;
|
|
105
107
|
resendPending: boolean;
|
|
106
108
|
handlers: MessageHandlers;
|
|
107
109
|
}) {
|
|
110
|
+
const { send } = handlers;
|
|
108
111
|
const [primaryAction, ...otherActions] = message.replyPlan.actions;
|
|
109
112
|
const senderHandlers = handlers.sender;
|
|
110
113
|
|
|
111
114
|
return (
|
|
112
115
|
<div className="-mr-1.5 flex shrink-0 items-center">
|
|
113
|
-
{primaryAction && (
|
|
116
|
+
{send && primaryAction && (
|
|
114
117
|
<IconAction
|
|
115
118
|
label={`${actionButtonLabel(primaryAction)} to this message`}
|
|
116
119
|
tooltip={actionButtonLabel(primaryAction)}
|
|
117
|
-
onClick={() =>
|
|
120
|
+
onClick={() => send.reply(message, primaryAction)}
|
|
118
121
|
>
|
|
119
122
|
<ReplyActionIcon mode={primaryAction.mode} />
|
|
120
123
|
</IconAction>
|
|
@@ -138,21 +141,23 @@ export function MessageActions({
|
|
|
138
141
|
<DropdownMenuContent align="end" className="w-64">
|
|
139
142
|
{menuGroups([
|
|
140
143
|
[
|
|
141
|
-
...
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
144
|
+
...(send
|
|
145
|
+
? otherActions.map((action) => (
|
|
146
|
+
<DropdownMenuItem
|
|
147
|
+
key={action.mode}
|
|
148
|
+
aria-label={`${actionButtonLabel(action)} to this message`}
|
|
149
|
+
onClick={() => send.reply(message, action)}
|
|
150
|
+
>
|
|
151
|
+
<ReplyActionIcon mode={action.mode} />{" "}
|
|
152
|
+
{actionButtonLabel(action)}
|
|
153
|
+
</DropdownMenuItem>
|
|
154
|
+
))
|
|
155
|
+
: []),
|
|
156
|
+
send && (
|
|
152
157
|
<DropdownMenuItem
|
|
153
158
|
key="forward"
|
|
154
159
|
aria-label="Forward this message"
|
|
155
|
-
onClick={
|
|
160
|
+
onClick={() => send.forward(message)}
|
|
156
161
|
>
|
|
157
162
|
<Forward /> Forward
|
|
158
163
|
</DropdownMenuItem>
|
|
@@ -164,11 +169,11 @@ export function MessageActions({
|
|
|
164
169
|
<Mail /> Mark as unread from here
|
|
165
170
|
</DropdownMenuItem>
|
|
166
171
|
),
|
|
167
|
-
canRetry(message) && (
|
|
172
|
+
send && canRetry(message) && (
|
|
168
173
|
<DropdownMenuItem
|
|
169
174
|
key="resend"
|
|
170
175
|
disabled={resendPending}
|
|
171
|
-
onClick={
|
|
176
|
+
onClick={() => send.resend(message)}
|
|
172
177
|
>
|
|
173
178
|
<RotateCw />{" "}
|
|
174
179
|
{message.transportState === "failed"
|
|
@@ -206,6 +211,14 @@ export function MessageActions({
|
|
|
206
211
|
</span>
|
|
207
212
|
</DropdownMenuItem>
|
|
208
213
|
) : null,
|
|
214
|
+
senderHandlers?.onFilter && (
|
|
215
|
+
<DropdownMenuItem
|
|
216
|
+
key="filter"
|
|
217
|
+
onClick={senderHandlers.onFilter}
|
|
218
|
+
>
|
|
219
|
+
<ListFilter /> Filter messages like this
|
|
220
|
+
</DropdownMenuItem>
|
|
221
|
+
),
|
|
209
222
|
],
|
|
210
223
|
[
|
|
211
224
|
senderHandlers?.onReportSpam && (
|
|
@@ -270,9 +283,8 @@ export function MessageActions({
|
|
|
270
283
|
[
|
|
271
284
|
<DropdownMenuItem
|
|
272
285
|
key="print"
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
286
|
+
disabled={!translation.ready}
|
|
287
|
+
onClick={() => printMessage(message, translation.body)}
|
|
276
288
|
>
|
|
277
289
|
<Printer /> Print
|
|
278
290
|
</DropdownMenuItem>,
|
|
@@ -29,13 +29,15 @@ const SHEET = /^(xlsx?|xlsm|ods|csv|tsv|numbers)$/u;
|
|
|
29
29
|
const SLIDES = /^(pptx?|odp|key)$/u;
|
|
30
30
|
const DOCUMENT = /^(docx?|odt|rtf|pages|txt|md)$/u;
|
|
31
31
|
|
|
32
|
-
function fileHueStyle(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
function fileHueStyle(hue: number) {
|
|
33
|
+
const style: CSSProperties & Record<"--file-hue", number> = {
|
|
34
|
+
"--file-hue": hue,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return style;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
function fileKind(attachment: MessageAttachment)
|
|
40
|
+
function fileKind(attachment: MessageAttachment) {
|
|
39
41
|
const { filename } = attachment;
|
|
40
42
|
const dot = filename.lastIndexOf(".");
|
|
41
43
|
const extension = dot === -1 ? "" : filename.slice(dot + 1).toLowerCase();
|
|
@@ -44,24 +46,30 @@ function fileKind(attachment: MessageAttachment): FileKind {
|
|
|
44
46
|
const label = extension ? extension.toUpperCase().slice(0, 5) : "File";
|
|
45
47
|
|
|
46
48
|
if (type === "application/pdf" || extension === "pdf") {
|
|
47
|
-
return { label: "PDF", Icon: FileText, hue: 25 };
|
|
49
|
+
return { label: "PDF", Icon: FileText, hue: 25 } satisfies FileKind;
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
if (type.startsWith("image/"))
|
|
52
|
+
if (type.startsWith("image/")) {
|
|
53
|
+
return { label, Icon: FileImage, hue: 300 } satisfies FileKind;
|
|
54
|
+
}
|
|
51
55
|
|
|
52
|
-
if (SHEET.test(extension))
|
|
56
|
+
if (SHEET.test(extension)) {
|
|
57
|
+
return { label, Icon: FileSpreadsheet, hue: 150 } satisfies FileKind;
|
|
58
|
+
}
|
|
53
59
|
|
|
54
|
-
if (SLIDES.test(extension))
|
|
60
|
+
if (SLIDES.test(extension)) {
|
|
61
|
+
return { label, Icon: Presentation, hue: 55 } satisfies FileKind;
|
|
62
|
+
}
|
|
55
63
|
|
|
56
64
|
if (DOCUMENT.test(extension) || type.startsWith("text/")) {
|
|
57
|
-
return { label, Icon: FileText, hue: 255 };
|
|
65
|
+
return { label, Icon: FileText, hue: 255 } satisfies FileKind;
|
|
58
66
|
}
|
|
59
67
|
|
|
60
68
|
if (ARCHIVE.test(extension) || type.includes("zip")) {
|
|
61
|
-
return { label, Icon: FileArchive, hue: 80 };
|
|
69
|
+
return { label, Icon: FileArchive, hue: 80 } satisfies FileKind;
|
|
62
70
|
}
|
|
63
71
|
|
|
64
|
-
return { label, Icon: File, hue: 260 };
|
|
72
|
+
return { label, Icon: File, hue: 260 } satisfies FileKind;
|
|
65
73
|
}
|
|
66
74
|
|
|
67
75
|
export function MessageAttachments({
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
|
|
3
|
+
import type { MessageDetail } from "./types";
|
|
4
|
+
import { useSanitizedEmailHtml } from "./use-sanitized-email-html";
|
|
5
|
+
|
|
6
|
+
export const TranslationEnabled = createContext(false);
|
|
7
|
+
|
|
8
|
+
/** Incoming HTML keeps its isolated document. Composer HTML is safe in the app itself. */
|
|
9
|
+
export type MessageBodyContent = {
|
|
10
|
+
format: "document" | "html" | "text";
|
|
11
|
+
value: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function useMessageBody(
|
|
15
|
+
mailboxId: string | undefined,
|
|
16
|
+
message: MessageDetail
|
|
17
|
+
) {
|
|
18
|
+
const html = useSanitizedEmailHtml(mailboxId ?? "", message);
|
|
19
|
+
|
|
20
|
+
let body: MessageBodyContent = {
|
|
21
|
+
format: "text",
|
|
22
|
+
value:
|
|
23
|
+
message.bodyText ||
|
|
24
|
+
(message.quotedText && !message.bodyHtml
|
|
25
|
+
? "No new text"
|
|
26
|
+
: message.preview || "No text body"),
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
if (
|
|
30
|
+
mailboxId &&
|
|
31
|
+
message.direction === "incoming" &&
|
|
32
|
+
html.data?.renderAsHtml
|
|
33
|
+
) {
|
|
34
|
+
body = { format: "document", value: html.data.srcDoc };
|
|
35
|
+
} else if (
|
|
36
|
+
mailboxId &&
|
|
37
|
+
message.direction === "outgoing" &&
|
|
38
|
+
html.data?.composerHtml
|
|
39
|
+
) {
|
|
40
|
+
body = { format: "html", value: html.data.composerHtml };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
body,
|
|
45
|
+
quoteInBody: Boolean(
|
|
46
|
+
message.quotedText &&
|
|
47
|
+
!message.hasSeparateHtmlQuote &&
|
|
48
|
+
body.format !== "text" &&
|
|
49
|
+
html.data?.hasHtmlQuote
|
|
50
|
+
),
|
|
51
|
+
ready: !(mailboxId && message.bodyHtml && html.isPending),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -3,7 +3,9 @@ import { format, isThisYear, isToday } from "date-fns";
|
|
|
3
3
|
|
|
4
4
|
import type { Mailbox, MessageDetail } from "./types";
|
|
5
5
|
|
|
6
|
-
export function senderName(
|
|
6
|
+
export function senderName(
|
|
7
|
+
message: Pick<MessageDetail, "fromName" | "fromAddress">
|
|
8
|
+
) {
|
|
7
9
|
return message.fromName || message.fromAddress;
|
|
8
10
|
}
|
|
9
11
|
|
|
@@ -45,7 +47,11 @@ function recipientLabel(address: string, mailbox?: Mailbox) {
|
|
|
45
47
|
return isOwnAddress(address, mailbox) ? "me" : address;
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
export function recipientSummary(
|
|
50
|
+
export function recipientSummary(
|
|
51
|
+
message: Pick<MessageDetail, "toAddresses" | "ccAddresses" | "bccAddresses"> &
|
|
52
|
+
Partial<Pick<MessageDetail, "viaList">>,
|
|
53
|
+
mailbox?: Mailbox
|
|
54
|
+
) {
|
|
49
55
|
const to = message.toAddresses.map((address) =>
|
|
50
56
|
recipientLabel(address, mailbox)
|
|
51
57
|
);
|
|
@@ -73,7 +73,9 @@ export function SenderLine({
|
|
|
73
73
|
own,
|
|
74
74
|
onCollapse,
|
|
75
75
|
}: {
|
|
76
|
-
message
|
|
76
|
+
/** A message, or the list row's sender while the message loads. */
|
|
77
|
+
message: Pick<MessageDetail, "fromAddress"> &
|
|
78
|
+
Partial<Pick<MessageDetail, "security" | "sender">>;
|
|
77
79
|
sender: string;
|
|
78
80
|
own: boolean;
|
|
79
81
|
onCollapse?: () => void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { responseJson } from "@open-workspace/core/ui";
|
|
2
2
|
import { useMutation } from "@tanstack/react-query";
|
|
3
3
|
import { Languages, LoaderCircle } from "lucide-react";
|
|
4
|
-
import {
|
|
4
|
+
import { useContext, useState } from "react";
|
|
5
5
|
import { toast } from "sonner";
|
|
6
6
|
|
|
7
7
|
import {
|
|
@@ -9,11 +9,11 @@ import {
|
|
|
9
9
|
MAX_TRANSLATION_SEGMENTS,
|
|
10
10
|
} from "../../shared/mail-translation";
|
|
11
11
|
import { mailApi } from "../lib/mail-api";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import { TranslationEnabled } from "./message-body";
|
|
13
|
+
import type { MessageBodyContent } from "./message-body";
|
|
14
|
+
import { emailHtmlTextSegments, translatedEmailHtml } from "./translation-html";
|
|
14
15
|
import { browserLanguage, COMMON_LANGUAGES } from "./translation-language";
|
|
15
16
|
import type { MessageDetail } from "./types";
|
|
16
|
-
import { useSanitizedEmailHtml } from "./use-sanitized-email-html";
|
|
17
17
|
|
|
18
18
|
type TranslationResult = {
|
|
19
19
|
messageId: string;
|
|
@@ -36,29 +36,14 @@ export type MessageTranslationState = ReturnType<typeof useMessageTranslation>;
|
|
|
36
36
|
*/
|
|
37
37
|
export function useMessageTranslation(
|
|
38
38
|
message: MessageDetail,
|
|
39
|
+
source: MessageBodyContent,
|
|
40
|
+
ready: boolean,
|
|
39
41
|
mailboxId?: string
|
|
40
42
|
) {
|
|
41
43
|
const [language, setLanguage] = useState(browserLanguage);
|
|
42
44
|
const [result, setResult] = useState<TranslationResult | null>(null);
|
|
43
45
|
const [showTranslation, setShowTranslation] = useState(false);
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const sourceHtml =
|
|
47
|
-
message.direction === "incoming"
|
|
48
|
-
? html.data?.renderAsHtml
|
|
49
|
-
? html.data.srcDoc
|
|
50
|
-
: null
|
|
51
|
-
: html.data?.composerHtml || null;
|
|
52
|
-
|
|
53
|
-
const segments = useMemo(
|
|
54
|
-
() =>
|
|
55
|
-
sourceHtml
|
|
56
|
-
? emailHtmlTextSegments(sourceHtml)
|
|
57
|
-
: [message.bodyText || message.preview].filter((text) =>
|
|
58
|
-
Boolean(text.trim())
|
|
59
|
-
),
|
|
60
|
-
[message.bodyText, message.preview, sourceHtml]
|
|
61
|
-
);
|
|
46
|
+
const enabled = useContext(TranslationEnabled);
|
|
62
47
|
|
|
63
48
|
const mutation = useMutation({
|
|
64
49
|
mutationFn: async ({
|
|
@@ -79,7 +64,23 @@ export function useMessageTranslation(
|
|
|
79
64
|
});
|
|
80
65
|
|
|
81
66
|
const cached = result?.messageId === message.id ? result : null;
|
|
82
|
-
const visible = showTranslation && cached?.language === language;
|
|
67
|
+
const visible = enabled && showTranslation && cached?.language === language;
|
|
68
|
+
const translations = visible ? cached.translations : undefined;
|
|
69
|
+
const { format, value } = source;
|
|
70
|
+
|
|
71
|
+
const body: MessageBodyContent = translations
|
|
72
|
+
? {
|
|
73
|
+
format,
|
|
74
|
+
value:
|
|
75
|
+
(format === "text"
|
|
76
|
+
? translations[0]
|
|
77
|
+
: translatedEmailHtml(
|
|
78
|
+
value,
|
|
79
|
+
translations,
|
|
80
|
+
format === "document"
|
|
81
|
+
)) ?? value,
|
|
82
|
+
}
|
|
83
|
+
: { format, value };
|
|
83
84
|
|
|
84
85
|
const languages = COMMON_LANGUAGES.includes(language)
|
|
85
86
|
? COMMON_LANGUAGES
|
|
@@ -96,6 +97,11 @@ export function useMessageTranslation(
|
|
|
96
97
|
|
|
97
98
|
setShowTranslation(false);
|
|
98
99
|
|
|
100
|
+
const segments =
|
|
101
|
+
format === "text"
|
|
102
|
+
? [value].filter((text) => text.trim())
|
|
103
|
+
: emailHtmlTextSegments(value);
|
|
104
|
+
|
|
99
105
|
if (!segments.length) {
|
|
100
106
|
toast.error("Message has no text to translate");
|
|
101
107
|
|
|
@@ -133,16 +139,17 @@ export function useMessageTranslation(
|
|
|
133
139
|
}
|
|
134
140
|
|
|
135
141
|
return {
|
|
136
|
-
available: Boolean(
|
|
137
|
-
|
|
142
|
+
available: Boolean(
|
|
143
|
+
enabled && mailboxId && (message.bodyText || message.bodyHtml)
|
|
144
|
+
),
|
|
145
|
+
ready,
|
|
138
146
|
pending: mutation.isPending,
|
|
139
147
|
language,
|
|
140
148
|
languages,
|
|
141
149
|
/** Translated text is cached for the current language. */
|
|
142
150
|
hasResult: cached?.language === language,
|
|
143
151
|
visible,
|
|
144
|
-
|
|
145
|
-
sourceHtml,
|
|
152
|
+
body,
|
|
146
153
|
translate,
|
|
147
154
|
showOriginal: () => setShowTranslation(false),
|
|
148
155
|
};
|
|
@@ -183,43 +190,3 @@ export function TranslationBar({
|
|
|
183
190
|
</div>
|
|
184
191
|
);
|
|
185
192
|
}
|
|
186
|
-
|
|
187
|
-
/** Message body: sanitized HTML, composer HTML or plain text, translated in place when requested. */
|
|
188
|
-
export function MessageBody({
|
|
189
|
-
message,
|
|
190
|
-
mailboxId,
|
|
191
|
-
translation,
|
|
192
|
-
}: {
|
|
193
|
-
message: MessageDetail;
|
|
194
|
-
mailboxId?: string;
|
|
195
|
-
translation: MessageTranslationState;
|
|
196
|
-
}) {
|
|
197
|
-
if (!mailboxId || !(message.bodyText || message.bodyHtml)) {
|
|
198
|
-
return (
|
|
199
|
-
<div className={messageTextClassName}>
|
|
200
|
-
{message.bodyText ||
|
|
201
|
-
(message.quotedText
|
|
202
|
-
? "No new text"
|
|
203
|
-
: message.preview || "No text body")}
|
|
204
|
-
</div>
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const { translations } = translation;
|
|
209
|
-
|
|
210
|
-
if (message.bodyHtml && (!translations || translation.sourceHtml)) {
|
|
211
|
-
return (
|
|
212
|
-
<EmailHtmlBody
|
|
213
|
-
mailboxId={mailboxId}
|
|
214
|
-
message={message}
|
|
215
|
-
translations={translations}
|
|
216
|
-
/>
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
return (
|
|
221
|
-
<div className={messageTextClassName}>
|
|
222
|
-
{translations ? translations[0] : message.bodyText}
|
|
223
|
-
</div>
|
|
224
|
-
);
|
|
225
|
-
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Button,
|
|
3
3
|
buttonVariants,
|
|
4
|
+
DelayedFallback,
|
|
4
5
|
Sheet,
|
|
5
6
|
SheetContent,
|
|
6
7
|
SheetDescription,
|
|
@@ -23,7 +24,7 @@ import {
|
|
|
23
24
|
ShieldCheck,
|
|
24
25
|
Sparkles,
|
|
25
26
|
} from "lucide-react";
|
|
26
|
-
import {
|
|
27
|
+
import { useState } from "react";
|
|
27
28
|
import type { ReactNode } from "react";
|
|
28
29
|
import { z } from "zod";
|
|
29
30
|
|
|
@@ -384,23 +385,20 @@ function OriginalMessageBody({
|
|
|
384
385
|
const original = details.data?.original;
|
|
385
386
|
const senderIntel = details.data?.senderIntel ?? message.senderIntel;
|
|
386
387
|
|
|
387
|
-
const
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
source.data ? new TextEncoder().encode(source.data).byteLength : null,
|
|
402
|
-
[source.data]
|
|
403
|
-
);
|
|
388
|
+
const hops = source.data ? receivedHops(source.data) : [];
|
|
389
|
+
|
|
390
|
+
const parsed = source.data
|
|
391
|
+
? {
|
|
392
|
+
hops,
|
|
393
|
+
transit: transitTime(source.data, hops),
|
|
394
|
+
sender: originalSenderDetails(source.data, authentication, hops),
|
|
395
|
+
parts: mimeStructure(source.data),
|
|
396
|
+
}
|
|
397
|
+
: null;
|
|
398
|
+
|
|
399
|
+
const sourceBytes = source.data
|
|
400
|
+
? new TextEncoder().encode(source.data).byteLength
|
|
401
|
+
: null;
|
|
404
402
|
|
|
405
403
|
function senderRows(sender: NonNullable<typeof parsed>["sender"]) {
|
|
406
404
|
const rows: [string, ReactNode][] = [
|
|
@@ -503,18 +501,23 @@ function OriginalMessageBody({
|
|
|
503
501
|
) : undefined
|
|
504
502
|
}
|
|
505
503
|
>
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
504
|
+
<DelayedFallback
|
|
505
|
+
pending={details.isLoading}
|
|
506
|
+
fallback={
|
|
507
|
+
<p className="text-muted-foreground flex items-center gap-2 py-2 text-xs">
|
|
508
|
+
<LoaderCircle className="size-3.5 animate-spin" /> Reading
|
|
509
|
+
authentication results…
|
|
510
|
+
</p>
|
|
511
|
+
}
|
|
512
|
+
>
|
|
513
|
+
{details.isError ? (
|
|
514
|
+
<p className="text-destructive text-xs">
|
|
515
|
+
{details.error.message}
|
|
516
|
+
</p>
|
|
517
|
+
) : (
|
|
518
|
+
<SenderAuthentication authentication={authentication} />
|
|
519
|
+
)}
|
|
520
|
+
</DelayedFallback>
|
|
518
521
|
</Section>
|
|
519
522
|
|
|
520
523
|
{parsed && (
|
|
@@ -525,15 +528,20 @@ function OriginalMessageBody({
|
|
|
525
528
|
</div>
|
|
526
529
|
<div className="min-w-0">
|
|
527
530
|
<Section title="Delivery path">
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
531
|
+
<DelayedFallback
|
|
532
|
+
pending={!parsed}
|
|
533
|
+
fallback={
|
|
534
|
+
<p className="text-muted-foreground text-xs">Loading…</p>
|
|
535
|
+
}
|
|
536
|
+
>
|
|
537
|
+
{parsed ? (
|
|
538
|
+
<DeliveryPath
|
|
539
|
+
hops={parsed.hops}
|
|
540
|
+
transit={parsed.transit}
|
|
541
|
+
deliveredAt={new Date(message.timelineAt)}
|
|
542
|
+
/>
|
|
543
|
+
) : null}
|
|
544
|
+
</DelayedFallback>
|
|
537
545
|
</Section>
|
|
538
546
|
{parsed && parsed.parts.length > 0 && (
|
|
539
547
|
<Section title="Structure">
|
|
@@ -570,17 +578,22 @@ function OriginalMessageBody({
|
|
|
570
578
|
</div>
|
|
571
579
|
}
|
|
572
580
|
>
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
581
|
+
<DelayedFallback
|
|
582
|
+
pending={source.isLoading}
|
|
583
|
+
fallback={
|
|
584
|
+
<div className="bg-surface-sunken text-muted-foreground grid h-40 place-items-center rounded-md">
|
|
585
|
+
<LoaderCircle className="size-4 animate-spin" />
|
|
586
|
+
</div>
|
|
587
|
+
}
|
|
588
|
+
>
|
|
589
|
+
{source.isError ? (
|
|
590
|
+
<p className="text-destructive text-xs">{source.error.message}</p>
|
|
591
|
+
) : (
|
|
592
|
+
<pre className="bg-surface-sunken ring-border max-h-[50dvh] overflow-auto rounded-md p-3 font-mono text-[11px] leading-[1.6] whitespace-pre ring-1">
|
|
593
|
+
{source.data}
|
|
594
|
+
</pre>
|
|
595
|
+
)}
|
|
596
|
+
</DelayedFallback>
|
|
584
597
|
</Section>
|
|
585
598
|
</div>
|
|
586
599
|
);
|
|
@@ -27,7 +27,7 @@ export function dkimSigningDomains(raw: string) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
function headerValue(raw: string, name: string) {
|
|
30
|
-
return originalHeaderValues(raw, name)
|
|
30
|
+
return originalHeaderValues(raw, name).at(0) ?? null;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
function tagValue(value: string, tag: string) {
|
|
@@ -44,7 +44,7 @@ type DkimSignature = {
|
|
|
44
44
|
signedHeaders: string[];
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
export function dkimSignatures(raw: string)
|
|
47
|
+
export function dkimSignatures(raw: string) {
|
|
48
48
|
return originalHeaderValues(raw, "dkim-signature").flatMap((signature) => {
|
|
49
49
|
const domain = tagValue(signature, "d");
|
|
50
50
|
|
|
@@ -59,7 +59,7 @@ export function dkimSignatures(raw: string): DkimSignature[] {
|
|
|
59
59
|
.split(":")
|
|
60
60
|
.map((header) => header.trim().toLocaleLowerCase())
|
|
61
61
|
.filter(Boolean),
|
|
62
|
-
},
|
|
62
|
+
} satisfies DkimSignature,
|
|
63
63
|
];
|
|
64
64
|
});
|
|
65
65
|
}
|
|
@@ -122,7 +122,7 @@ function walkMime(entity: string, depth: number, parts: MimePart[]) {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
/** Flattened MIME tree, parents before children, capped for huge messages. */
|
|
125
|
-
export function mimeStructure(raw: string)
|
|
125
|
+
export function mimeStructure(raw: string) {
|
|
126
126
|
const parts: MimePart[] = [];
|
|
127
127
|
walkMime(raw, 0, parts);
|
|
128
128
|
|
|
@@ -146,7 +146,7 @@ export function originalSenderDetails(
|
|
|
146
146
|
"remoteIp" | "envelopeFrom"
|
|
147
147
|
> | null = null,
|
|
148
148
|
hops: ReceivedHop[] = receivedHops(raw)
|
|
149
|
-
)
|
|
149
|
+
) {
|
|
150
150
|
const trustedHop = hops.find((hop) => hop.trusted);
|
|
151
151
|
|
|
152
152
|
return {
|
|
@@ -158,7 +158,7 @@ export function originalSenderDetails(
|
|
|
158
158
|
mailer: headerValue(raw, "x-mailer") ?? headerValue(raw, "user-agent"),
|
|
159
159
|
listId: headerValue(raw, "list-id"),
|
|
160
160
|
precedence: headerValue(raw, "precedence"),
|
|
161
|
-
};
|
|
161
|
+
} satisfies OriginalSenderDetails;
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
/**
|