@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useState } from "react";
|
|
2
2
|
import type { RefObject } from "react";
|
|
3
3
|
|
|
4
4
|
const STORAGE_KEY = "openworkspace.mail.list-width";
|
|
@@ -25,7 +25,7 @@ function readWidth() {
|
|
|
25
25
|
export function useListWidth() {
|
|
26
26
|
const [storedWidth, setStoredWidth] = useState(readWidth);
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
function rememberWidth(next: number) {
|
|
29
29
|
setStoredWidth(next);
|
|
30
30
|
|
|
31
31
|
try {
|
|
@@ -33,7 +33,7 @@ export function useListWidth() {
|
|
|
33
33
|
} catch {
|
|
34
34
|
// Preference only.
|
|
35
35
|
}
|
|
36
|
-
}
|
|
36
|
+
}
|
|
37
37
|
|
|
38
38
|
return [storedWidth, rememberWidth] as const;
|
|
39
39
|
}
|
package/src/mail/pdf-preview.tsx
CHANGED
|
@@ -7,9 +7,12 @@ import {
|
|
|
7
7
|
DropdownMenuRadioGroup,
|
|
8
8
|
DropdownMenuRadioItem,
|
|
9
9
|
DropdownMenuTrigger,
|
|
10
|
+
useDelayedPending,
|
|
10
11
|
} from "@open-workspace/core/ui";
|
|
11
12
|
import { ChevronDown, Languages, LoaderCircle } from "lucide-react";
|
|
13
|
+
import { useContext } from "react";
|
|
12
14
|
|
|
15
|
+
import { TranslationEnabled } from "./message-body";
|
|
13
16
|
import { languageName } from "./message-translation";
|
|
14
17
|
import { PdfPreviewToolbar } from "./pdf-preview-toolbar";
|
|
15
18
|
import { COMMON_LANGUAGES } from "./translation-language";
|
|
@@ -31,7 +34,9 @@ export default function PdfPreview({
|
|
|
31
34
|
messageId: string;
|
|
32
35
|
mailboxId: string;
|
|
33
36
|
}) {
|
|
37
|
+
const translationEnabled = useContext(TranslationEnabled);
|
|
34
38
|
const { containerRef, pagesRef, ...pdf } = usePdfViewer(url);
|
|
39
|
+
const spinner = useDelayedPending(!pdf.ready && !pdf.error, { min: 0 });
|
|
35
40
|
|
|
36
41
|
const { visible, setVisible, language, setLanguage, translation } =
|
|
37
42
|
usePdfTranslation({
|
|
@@ -65,65 +70,69 @@ export default function PdfPreview({
|
|
|
65
70
|
},
|
|
66
71
|
}}
|
|
67
72
|
/>
|
|
68
|
-
|
|
69
|
-
<
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
{visible && translation.isFetching ? (
|
|
76
|
-
<LoaderCircle className="animate-spin" />
|
|
77
|
-
) : (
|
|
78
|
-
<Languages />
|
|
79
|
-
)}
|
|
80
|
-
{visible ? "Show original" : "Translate"}
|
|
81
|
-
</Button>
|
|
82
|
-
<DropdownMenu>
|
|
83
|
-
<DropdownMenuTrigger
|
|
84
|
-
render={<Button size="xs" variant="outline" className="max-w-40" />}
|
|
85
|
-
aria-label={`PDF translation language: ${languageName(language)}`}
|
|
73
|
+
{translationEnabled && (
|
|
74
|
+
<div className="flex flex-wrap items-center gap-2 border-b px-3 py-1.5">
|
|
75
|
+
<Button
|
|
76
|
+
size="xs"
|
|
77
|
+
variant="ghost"
|
|
78
|
+
disabled={!pdf.ready || Boolean(pdf.error)}
|
|
79
|
+
onClick={() => setVisible(!visible)}
|
|
86
80
|
>
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
<DropdownMenuGroup>
|
|
92
|
-
<DropdownMenuLabel>Translation language</DropdownMenuLabel>
|
|
93
|
-
<DropdownMenuRadioGroup
|
|
94
|
-
value={language}
|
|
95
|
-
onValueChange={(code: string) => setLanguage(code)}
|
|
96
|
-
>
|
|
97
|
-
{languages.map((code) => (
|
|
98
|
-
<DropdownMenuRadioItem key={code} value={code} closeOnClick>
|
|
99
|
-
{languageName(code)}
|
|
100
|
-
</DropdownMenuRadioItem>
|
|
101
|
-
))}
|
|
102
|
-
</DropdownMenuRadioGroup>
|
|
103
|
-
</DropdownMenuGroup>
|
|
104
|
-
</DropdownMenuContent>
|
|
105
|
-
</DropdownMenu>
|
|
106
|
-
{visible && (translation.isError || overlayError) && (
|
|
107
|
-
<div role="alert" className="flex items-center gap-2 text-xs">
|
|
108
|
-
{overlayError ?? translation.error?.message}
|
|
109
|
-
{translation.isError && (
|
|
110
|
-
<Button
|
|
111
|
-
size="xs"
|
|
112
|
-
variant="outline"
|
|
113
|
-
disabled={translation.isFetching}
|
|
114
|
-
onClick={() => void translation.refetch()}
|
|
115
|
-
>
|
|
116
|
-
Retry
|
|
117
|
-
</Button>
|
|
81
|
+
{visible && translation.isFetching ? (
|
|
82
|
+
<LoaderCircle className="animate-spin" />
|
|
83
|
+
) : (
|
|
84
|
+
<Languages />
|
|
118
85
|
)}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
86
|
+
{visible ? "Show original" : "Translate"}
|
|
87
|
+
</Button>
|
|
88
|
+
<DropdownMenu>
|
|
89
|
+
<DropdownMenuTrigger
|
|
90
|
+
render={
|
|
91
|
+
<Button size="xs" variant="outline" className="max-w-40" />
|
|
92
|
+
}
|
|
93
|
+
aria-label={`PDF translation language: ${languageName(language)}`}
|
|
94
|
+
>
|
|
95
|
+
<span className="truncate">{languageName(language)}</span>
|
|
96
|
+
<ChevronDown data-icon="inline-end" />
|
|
97
|
+
</DropdownMenuTrigger>
|
|
98
|
+
<DropdownMenuContent align="start" className="max-h-80 w-48">
|
|
99
|
+
<DropdownMenuGroup>
|
|
100
|
+
<DropdownMenuLabel>Translation language</DropdownMenuLabel>
|
|
101
|
+
<DropdownMenuRadioGroup
|
|
102
|
+
value={language}
|
|
103
|
+
onValueChange={(code: string) => setLanguage(code)}
|
|
104
|
+
>
|
|
105
|
+
{languages.map((code) => (
|
|
106
|
+
<DropdownMenuRadioItem key={code} value={code} closeOnClick>
|
|
107
|
+
{languageName(code)}
|
|
108
|
+
</DropdownMenuRadioItem>
|
|
109
|
+
))}
|
|
110
|
+
</DropdownMenuRadioGroup>
|
|
111
|
+
</DropdownMenuGroup>
|
|
112
|
+
</DropdownMenuContent>
|
|
113
|
+
</DropdownMenu>
|
|
114
|
+
{visible && (translation.isError || overlayError) && (
|
|
115
|
+
<div role="alert" className="flex items-center gap-2 text-xs">
|
|
116
|
+
{overlayError ?? translation.error?.message}
|
|
117
|
+
{translation.isError && (
|
|
118
|
+
<Button
|
|
119
|
+
size="xs"
|
|
120
|
+
variant="outline"
|
|
121
|
+
disabled={translation.isFetching}
|
|
122
|
+
onClick={() => void translation.refetch()}
|
|
123
|
+
>
|
|
124
|
+
Retry
|
|
125
|
+
</Button>
|
|
126
|
+
)}
|
|
127
|
+
</div>
|
|
128
|
+
)}
|
|
129
|
+
{visible && translation.data === null && (
|
|
130
|
+
<span role="status" className="text-muted-foreground text-xs">
|
|
131
|
+
No selectable text on this page
|
|
132
|
+
</span>
|
|
133
|
+
)}
|
|
134
|
+
</div>
|
|
135
|
+
)}
|
|
127
136
|
<div className="flex min-h-0 flex-1 flex-col md:flex-row">
|
|
128
137
|
<div className="bg-surface-sunken relative min-h-0 min-w-0 flex-1">
|
|
129
138
|
<div
|
|
@@ -141,12 +150,11 @@ export default function PdfPreview({
|
|
|
141
150
|
role="status"
|
|
142
151
|
className="bg-surface-sunken text-muted-foreground absolute inset-0 grid place-content-center justify-items-center gap-3 p-6"
|
|
143
152
|
>
|
|
144
|
-
{pdf.error ??
|
|
145
|
-
|
|
153
|
+
{pdf.error ??
|
|
154
|
+
(spinner ? (
|
|
146
155
|
<LoaderCircle className="size-6 animate-spin" />
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
)}
|
|
156
|
+
) : null)}
|
|
157
|
+
{pdf.error ? null : <span className="sr-only">Loading PDF</span>}
|
|
150
158
|
</div>
|
|
151
159
|
)}
|
|
152
160
|
</div>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { tokenize } from "linkifyjs";
|
|
2
|
+
import { memo } from "react";
|
|
3
|
+
|
|
4
|
+
export const PlainMessageText = memo(function PlainMessageText({
|
|
5
|
+
text,
|
|
6
|
+
}: {
|
|
7
|
+
text: string;
|
|
8
|
+
}) {
|
|
9
|
+
if (!/https?:\/\//iu.test(text)) return text;
|
|
10
|
+
|
|
11
|
+
return tokenize(text).map((token) => {
|
|
12
|
+
const value = token.toString();
|
|
13
|
+
|
|
14
|
+
if (!token.isLink || !/^https?:\/\//iu.test(value)) return value;
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<a
|
|
18
|
+
key={token.startIndex()}
|
|
19
|
+
className="text-primary underline"
|
|
20
|
+
href={value}
|
|
21
|
+
target="_blank"
|
|
22
|
+
rel="noopener noreferrer"
|
|
23
|
+
>
|
|
24
|
+
{value}
|
|
25
|
+
</a>
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
import { format } from "date-fns";
|
|
2
2
|
|
|
3
|
+
import { escapeHtml, quotedContextHtml } from "../../shared/mail-html";
|
|
4
|
+
import type { MessageBodyContent } from "./message-body";
|
|
3
5
|
import type { MessageDetail } from "./types";
|
|
4
6
|
|
|
5
|
-
function escapeHtml(value: string) {
|
|
6
|
-
return value.replaceAll(
|
|
7
|
-
/[&<>"']/gu,
|
|
8
|
-
(character) => `&#${character.charCodeAt(0)};`
|
|
9
|
-
);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
7
|
/**
|
|
13
8
|
* Prints one message through a throwaway iframe: a plain header block, then the
|
|
14
|
-
*
|
|
9
|
+
* same sanitized body or text the reader displays.
|
|
15
10
|
*/
|
|
16
|
-
export function printMessage(
|
|
17
|
-
message: MessageDetail,
|
|
18
|
-
renderedHtml: string | null
|
|
19
|
-
) {
|
|
11
|
+
export function printMessage(message: MessageDetail, body: MessageBodyContent) {
|
|
20
12
|
const rows = [
|
|
21
13
|
[
|
|
22
14
|
"From",
|
|
@@ -41,10 +33,6 @@ export function printMessage(
|
|
|
41
33
|
</table>
|
|
42
34
|
<hr style="border:0;border-top:1px solid #ddd;margin:0 0 16px">`;
|
|
43
35
|
|
|
44
|
-
const body =
|
|
45
|
-
renderedHtml ??
|
|
46
|
-
`<pre style="font:14px/1.6 system-ui,sans-serif;white-space:pre-wrap;margin:0">${escapeHtml(message.bodyText ?? message.preview ?? "")}</pre>`;
|
|
47
|
-
|
|
48
36
|
const frame = document.createElement("iframe");
|
|
49
37
|
frame.setAttribute("aria-hidden", "true");
|
|
50
38
|
frame.style.cssText =
|
|
@@ -60,8 +48,34 @@ export function printMessage(
|
|
|
60
48
|
|
|
61
49
|
document_.open();
|
|
62
50
|
document_.write(
|
|
63
|
-
|
|
51
|
+
body.format === "document"
|
|
52
|
+
? body.value
|
|
53
|
+
: "<!doctype html><html><head><meta charset=utf-8></head><body></body></html>"
|
|
64
54
|
);
|
|
55
|
+
|
|
56
|
+
if (body.format === "html") {
|
|
57
|
+
document_.body.innerHTML =
|
|
58
|
+
body.value +
|
|
59
|
+
quotedContextHtml(
|
|
60
|
+
message.hasSeparateHtmlQuote ? message.quotedText : null
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (body.format === "text") {
|
|
65
|
+
const pre = document_.createElement("pre");
|
|
66
|
+
pre.style.cssText =
|
|
67
|
+
"font:14px/1.6 system-ui,sans-serif;white-space:pre-wrap;margin:0";
|
|
68
|
+
pre.textContent = message.quotedText
|
|
69
|
+
? [message.bodyText && body.value, message.quotedText]
|
|
70
|
+
.filter(Boolean)
|
|
71
|
+
.join("\n\n")
|
|
72
|
+
: body.value;
|
|
73
|
+
document_.body.appendChild(pre);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
document_.title = message.subject;
|
|
77
|
+
document_.body.style.margin = "24px";
|
|
78
|
+
document_.body.insertAdjacentHTML("afterbegin", header);
|
|
65
79
|
document_.close();
|
|
66
80
|
const cleanup = () => window.setTimeout(() => frame.remove(), 1000);
|
|
67
81
|
frame.contentWindow?.addEventListener("afterprint", cleanup, { once: true });
|
|
@@ -71,22 +85,3 @@ export function printMessage(
|
|
|
71
85
|
frame.contentWindow?.print();
|
|
72
86
|
}, 250);
|
|
73
87
|
}
|
|
74
|
-
|
|
75
|
-
/** The reader's sanitized HTML body for a message, if it rendered as HTML. */
|
|
76
|
-
export function renderedMessageHtml(messageId: string) {
|
|
77
|
-
const frame = document.querySelector<HTMLIFrameElement>(
|
|
78
|
-
`[data-message-id="${CSS.escape(messageId)}"] iframe`
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
const document_ = frame?.contentDocument;
|
|
82
|
-
|
|
83
|
-
if (!document_?.body) return null;
|
|
84
|
-
|
|
85
|
-
// Keep the email's own stylesheets; the body's contents leave out its
|
|
86
|
-
// fit-to-pane scaling, which is on the body element itself.
|
|
87
|
-
const styles = [...document_.querySelectorAll("style")]
|
|
88
|
-
.map((style) => style.outerHTML)
|
|
89
|
-
.join("");
|
|
90
|
-
|
|
91
|
-
return styles + document_.body.innerHTML;
|
|
92
|
-
}
|