@open-workspace/email 0.4.2 → 0.5.1
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-sender-intel.ts +5 -1
- 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 +52 -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 +391 -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 +12 -11
- 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 +758 -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 +119 -1816
- 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 +700 -0
- package/worker/mail/auth-headers.ts +57 -43
- package/worker/mail/auto-reply-routes.ts +260 -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-threading.ts +15 -2
- 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 +19 -8
- 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 +698 -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 +206 -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 +316 -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 +455 -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 +253 -0
- package/worker/mailbox/support.ts +416 -0
- package/worker/mcp/mail-action-tools.ts +161 -1
- 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
|
@@ -8,8 +8,6 @@ import {
|
|
|
8
8
|
useQuery,
|
|
9
9
|
useQueryClient,
|
|
10
10
|
} from "@tanstack/react-query";
|
|
11
|
-
import type { InfiniteData } from "@tanstack/react-query";
|
|
12
|
-
import { useEffect } from "react";
|
|
13
11
|
|
|
14
12
|
import { mailApi } from "../lib/mail-api";
|
|
15
13
|
import {
|
|
@@ -17,8 +15,17 @@ import {
|
|
|
17
15
|
conversationsQuery,
|
|
18
16
|
foldersQuery,
|
|
19
17
|
mailboxesQuery,
|
|
18
|
+
prefetchConversation,
|
|
20
19
|
} from "./mail-queries";
|
|
21
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
applyMailboxChange,
|
|
22
|
+
beginOwnChange,
|
|
23
|
+
ownChangeDone,
|
|
24
|
+
ownChangeFailed,
|
|
25
|
+
ownChangeKey,
|
|
26
|
+
ownChangeSettled,
|
|
27
|
+
} from "./mail-query-cache";
|
|
28
|
+
import type { OwnChange, UndoSnapshot } from "./mail-query-cache";
|
|
22
29
|
import type { Folder, MessageDetail } from "./types";
|
|
23
30
|
|
|
24
31
|
export function useMailboxes() {
|
|
@@ -52,47 +59,71 @@ export function useRecipientSuggestions(
|
|
|
52
59
|
});
|
|
53
60
|
}
|
|
54
61
|
|
|
62
|
+
/**
|
|
63
|
+
* A list of conversations. While another one loads (a folder, mailbox,
|
|
64
|
+
* search or filter not seen yet), the one before stays as placeholder data
|
|
65
|
+
* (`isPlaceholderData`), so the list is never replaced by a skeleton; Unread
|
|
66
|
+
* starts from the cached full list's unread rows.
|
|
67
|
+
*/
|
|
55
68
|
export function useConversations(
|
|
56
69
|
mailboxId: string | undefined,
|
|
57
70
|
folder: Folder,
|
|
58
71
|
search: string,
|
|
59
|
-
unreadOnly: boolean
|
|
60
|
-
active = true
|
|
72
|
+
unreadOnly: boolean
|
|
61
73
|
) {
|
|
74
|
+
const client = useQueryClient();
|
|
75
|
+
|
|
62
76
|
return useInfiniteQuery({
|
|
63
77
|
...conversationsQuery(mailboxId, folder, search, unreadOnly),
|
|
64
|
-
enabled: Boolean(mailboxId)
|
|
78
|
+
enabled: Boolean(mailboxId),
|
|
79
|
+
placeholderData: (previous) => {
|
|
80
|
+
const all = unreadOnly
|
|
81
|
+
? client.getQueryData<NonNullable<typeof previous>>(
|
|
82
|
+
conversationsQuery(mailboxId, folder, search, false).queryKey
|
|
83
|
+
)
|
|
84
|
+
: undefined;
|
|
85
|
+
|
|
86
|
+
if (!all) return previous;
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
...all,
|
|
90
|
+
pages: all.pages.map((page) => ({
|
|
91
|
+
...page,
|
|
92
|
+
conversations: page.conversations.filter((item) => item.isUnread),
|
|
93
|
+
})),
|
|
94
|
+
};
|
|
95
|
+
},
|
|
65
96
|
});
|
|
66
97
|
}
|
|
67
98
|
|
|
68
99
|
export function useConversation(
|
|
69
100
|
mailboxId: string | undefined,
|
|
70
|
-
conversationId: string | undefined
|
|
101
|
+
conversationId: string | undefined,
|
|
102
|
+
matchId?: string
|
|
71
103
|
) {
|
|
72
|
-
return useInfiniteQuery(
|
|
104
|
+
return useInfiniteQuery(
|
|
105
|
+
conversationQuery(mailboxId, conversationId, matchId)
|
|
106
|
+
);
|
|
73
107
|
}
|
|
74
108
|
|
|
75
109
|
/**
|
|
76
110
|
* Starts loading a conversation the person is about to open (pointer
|
|
77
|
-
* resting on its row, keyboard focus, or the next and previous one),
|
|
78
|
-
* reader can show it at once.
|
|
111
|
+
* resting on its row, keyboard focus, or the next and previous one), with
|
|
112
|
+
* the bodies it opens with, so the reader can show it at once.
|
|
79
113
|
*/
|
|
80
114
|
export function usePrefetchConversation() {
|
|
81
115
|
const client = useQueryClient();
|
|
82
116
|
|
|
83
117
|
return (
|
|
84
118
|
mailboxId: string | undefined,
|
|
85
|
-
conversationId: string | undefined
|
|
119
|
+
conversationId: string | undefined,
|
|
120
|
+
matchId?: string
|
|
86
121
|
) => {
|
|
87
122
|
if (!mailboxId || !conversationId) return;
|
|
88
|
-
void client
|
|
89
|
-
conversationQuery(mailboxId, conversationId)
|
|
90
|
-
);
|
|
123
|
+
void prefetchConversation(client, mailboxId, conversationId, matchId);
|
|
91
124
|
};
|
|
92
125
|
}
|
|
93
126
|
|
|
94
|
-
type ConversationPage = { messages: MessageDetail[] };
|
|
95
|
-
|
|
96
127
|
function senderIntelQuery(mailboxId: string, messageId: string) {
|
|
97
128
|
return queryOptions({
|
|
98
129
|
queryKey: ["sender-intel", mailboxId, messageId],
|
|
@@ -112,61 +143,40 @@ function senderIntelQuery(mailboxId: string, messageId: string) {
|
|
|
112
143
|
|
|
113
144
|
/**
|
|
114
145
|
* The reader gets a conversation before the sender lookups (DNS, blocklists)
|
|
115
|
-
* of messages that had none finish; this fetches each one's result and
|
|
116
|
-
* it
|
|
146
|
+
* of messages that had none finish; this fetches each one's result and
|
|
147
|
+
* shows it in place of the pending state. A later read of the conversation
|
|
148
|
+
* has the result stored, so it no longer reports the message pending.
|
|
117
149
|
*/
|
|
118
|
-
export function
|
|
150
|
+
export function useSenderIntel(
|
|
119
151
|
mailboxId: string | undefined,
|
|
120
|
-
conversationId: string | undefined,
|
|
121
152
|
messages: MessageDetail[]
|
|
122
153
|
) {
|
|
123
|
-
const
|
|
154
|
+
const pending = mailboxId
|
|
155
|
+
? messages.filter((message) => message.senderIntelPending)
|
|
156
|
+
: [];
|
|
124
157
|
|
|
125
|
-
const
|
|
126
|
-
mailboxId && conversationId
|
|
127
|
-
? messages.filter((message) => message.senderIntelPending)
|
|
128
|
-
: [];
|
|
129
|
-
|
|
130
|
-
const results = useQueries({
|
|
158
|
+
const intel = useQueries({
|
|
131
159
|
queries: mailboxId
|
|
132
160
|
? pending.map((message) => senderIntelQuery(mailboxId, message.id))
|
|
133
161
|
: [],
|
|
134
|
-
|
|
162
|
+
combine: (results) =>
|
|
163
|
+
new Map(
|
|
164
|
+
pending.flatMap((message, index) => {
|
|
165
|
+
const data = results[index]?.data;
|
|
135
166
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
167
|
+
return data ? [[message.id, data] as const] : [];
|
|
168
|
+
})
|
|
169
|
+
),
|
|
170
|
+
});
|
|
139
171
|
|
|
140
|
-
|
|
141
|
-
|
|
172
|
+
return messages.map((message) => {
|
|
173
|
+
const filled = message.senderIntelPending && intel.get(message.id);
|
|
142
174
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
senderIntelQuery(mailboxId, id).queryKey
|
|
146
|
-
);
|
|
175
|
+
if (!filled) return message;
|
|
176
|
+
const { ok: _ok, ...found } = filled;
|
|
147
177
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
client.setQueryData<InfiniteData<ConversationPage>>(
|
|
152
|
-
["conversation", mailboxId, conversationId],
|
|
153
|
-
(data) =>
|
|
154
|
-
data && {
|
|
155
|
-
...data,
|
|
156
|
-
pages: data.pages.map((page) => ({
|
|
157
|
-
...page,
|
|
158
|
-
messages: page.messages.map((message) => {
|
|
159
|
-
const filled = ready.find((item) => item.id === message.id);
|
|
160
|
-
|
|
161
|
-
if (!filled || !message.senderIntelPending) return message;
|
|
162
|
-
const { ok: _ok, ...intel } = filled.data;
|
|
163
|
-
|
|
164
|
-
return { ...message, ...intel };
|
|
165
|
-
}),
|
|
166
|
-
})),
|
|
167
|
-
}
|
|
168
|
-
);
|
|
169
|
-
}, [client, conversationId, mailboxId, readyKey]);
|
|
178
|
+
return { ...message, ...found };
|
|
179
|
+
});
|
|
170
180
|
}
|
|
171
181
|
|
|
172
182
|
export function useResendMessage() {
|
|
@@ -181,15 +191,17 @@ export function useResendMessage() {
|
|
|
181
191
|
})
|
|
182
192
|
),
|
|
183
193
|
onSuccess: (_result, { mailboxId }) =>
|
|
184
|
-
|
|
194
|
+
applyMailboxChange(client, mailboxId),
|
|
185
195
|
});
|
|
186
196
|
}
|
|
187
197
|
|
|
188
|
-
|
|
198
|
+
/** `scope.mailboxId` keys it as an own change of the mailbox (`ownChangeKey`). */
|
|
199
|
+
export function useSetMessageRead(scope: { mailboxId: string | undefined }) {
|
|
189
200
|
const client = useQueryClient();
|
|
190
201
|
const { user } = useAuth();
|
|
191
202
|
|
|
192
203
|
return useMutation({
|
|
204
|
+
mutationKey: ownChangeKey(scope.mailboxId),
|
|
193
205
|
mutationFn: async ({
|
|
194
206
|
id,
|
|
195
207
|
mailboxId,
|
|
@@ -207,22 +219,25 @@ export function useSetMessageRead() {
|
|
|
207
219
|
json: { isRead },
|
|
208
220
|
})
|
|
209
221
|
),
|
|
210
|
-
// The
|
|
211
|
-
//
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
222
|
+
// The message, its row and the counts change at once; the answer's
|
|
223
|
+
// versions say the cache has the change, so its echo reads nothing.
|
|
224
|
+
onMutate: ({ id, mailboxId, conversationId, isRead }) =>
|
|
225
|
+
beginOwnChange(client, mailboxId, {
|
|
226
|
+
type: "message-read",
|
|
227
|
+
conversationId,
|
|
228
|
+
messageId: id,
|
|
229
|
+
isRead,
|
|
230
|
+
reader: user ? { userId: user.id, name: user.name } : undefined,
|
|
231
|
+
}),
|
|
232
|
+
onError: (_error, input, change) =>
|
|
233
|
+
ownChangeFailed(client, input.mailboxId, change),
|
|
234
|
+
onSuccess: ({ previousVersion, version }, input, change) =>
|
|
235
|
+
ownChangeDone(client, input.mailboxId, change, {
|
|
236
|
+
previousVersion,
|
|
237
|
+
version,
|
|
238
|
+
}),
|
|
239
|
+
onSettled: (_result, _error, input) =>
|
|
240
|
+
ownChangeSettled(client, input.mailboxId),
|
|
226
241
|
});
|
|
227
242
|
}
|
|
228
243
|
|
|
@@ -234,46 +249,141 @@ export type BulkConversationAction =
|
|
|
234
249
|
mailboxState?: "active" | "archive" | "spam" | "trash";
|
|
235
250
|
folderId?: string | null;
|
|
236
251
|
};
|
|
252
|
+
/** Puts them back as an Undo: no spam verdict, nobody trusted. */
|
|
253
|
+
undo?: boolean;
|
|
237
254
|
}
|
|
255
|
+
/** Report spam of each conversation's received mail. */
|
|
256
|
+
| { type: "report" }
|
|
257
|
+
/** Not spam for each conversation's received mail, out of Spam. */
|
|
258
|
+
| { type: "not_spam" }
|
|
238
259
|
| { type: "delete_permanently" };
|
|
239
260
|
|
|
240
|
-
export
|
|
261
|
+
export type BulkConversationInput = {
|
|
262
|
+
mailboxId: string;
|
|
263
|
+
/** Where the conversations were acted on: only those still there change. */
|
|
264
|
+
sourceFolderId: string;
|
|
265
|
+
conversationIds: string[];
|
|
266
|
+
action: BulkConversationAction;
|
|
267
|
+
undoSnapshot?: UndoSnapshot;
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
function filingUpdate(
|
|
271
|
+
action: Extract<
|
|
272
|
+
BulkConversationAction,
|
|
273
|
+
{ type: "report" | "not_spam" | "update" }
|
|
274
|
+
>
|
|
275
|
+
) {
|
|
276
|
+
if (action.type === "update") return action.update;
|
|
277
|
+
|
|
278
|
+
return {
|
|
279
|
+
mailboxState:
|
|
280
|
+
action.type === "report" ? ("spam" as const) : ("active" as const),
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** What a bulk action does to the cache at once (`beginOwnChange`). */
|
|
285
|
+
export function bulkOwnChange(
|
|
286
|
+
{
|
|
287
|
+
sourceFolderId,
|
|
288
|
+
conversationIds,
|
|
289
|
+
action,
|
|
290
|
+
undoSnapshot,
|
|
291
|
+
}: BulkConversationInput,
|
|
292
|
+
reader?: { userId: string; name: string }
|
|
293
|
+
) {
|
|
294
|
+
if (action.type === "read") {
|
|
295
|
+
return {
|
|
296
|
+
type: "read",
|
|
297
|
+
sourceFolderId,
|
|
298
|
+
conversationIds,
|
|
299
|
+
isRead: action.isRead,
|
|
300
|
+
reader,
|
|
301
|
+
} satisfies OwnChange;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (action.type === "delete_permanently") {
|
|
305
|
+
return { type: "delete", conversationIds } satisfies OwnChange;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Report spam goes into Spam, Not spam out of it, as a move does.
|
|
309
|
+
|
|
310
|
+
return {
|
|
311
|
+
type: "move",
|
|
312
|
+
sourceFolderId,
|
|
313
|
+
conversationIds,
|
|
314
|
+
update: filingUpdate(action),
|
|
315
|
+
undoSnapshot,
|
|
316
|
+
} satisfies OwnChange;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Moving, marking, reporting and deleting conversations: shown at once
|
|
321
|
+
* (`beginOwnChange`) and put back if the server refuses. Every answer says
|
|
322
|
+
* how many changed and where they went.
|
|
323
|
+
*/
|
|
324
|
+
export function useBulkConversationAction(scope: {
|
|
325
|
+
mailboxId: string | undefined;
|
|
326
|
+
}) {
|
|
241
327
|
const client = useQueryClient();
|
|
328
|
+
const { user } = useAuth();
|
|
242
329
|
|
|
243
330
|
return useMutation({
|
|
331
|
+
mutationKey: ownChangeKey(scope.mailboxId),
|
|
244
332
|
mutationFn: async ({
|
|
245
333
|
mailboxId,
|
|
246
334
|
sourceFolderId,
|
|
247
335
|
conversationIds,
|
|
248
336
|
action,
|
|
249
|
-
}: {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
return responseJson(
|
|
257
|
-
await mailApi.api.mail.conversations.bulk.$patch({
|
|
258
|
-
query: { mailboxId },
|
|
259
|
-
json: {
|
|
260
|
-
type: action.type,
|
|
261
|
-
conversationIds,
|
|
262
|
-
sourceFolderId,
|
|
263
|
-
update: action.update,
|
|
264
|
-
},
|
|
265
|
-
})
|
|
266
|
-
);
|
|
267
|
-
}
|
|
337
|
+
}: BulkConversationInput) => {
|
|
338
|
+
const filing =
|
|
339
|
+
action.type === "report" ||
|
|
340
|
+
action.type === "not_spam" ||
|
|
341
|
+
action.type === "update";
|
|
342
|
+
|
|
343
|
+
const undo = action.type === "update" && action.undo;
|
|
268
344
|
|
|
269
345
|
return responseJson(
|
|
270
346
|
await mailApi.api.mail.conversations.bulk.$patch({
|
|
271
347
|
query: { mailboxId },
|
|
272
|
-
json:
|
|
348
|
+
json: filing
|
|
349
|
+
? {
|
|
350
|
+
type: "update",
|
|
351
|
+
conversationIds,
|
|
352
|
+
sourceFolderId,
|
|
353
|
+
update: filingUpdate(action),
|
|
354
|
+
undo,
|
|
355
|
+
offerUndo: !undo,
|
|
356
|
+
}
|
|
357
|
+
: { conversationIds, ...action },
|
|
273
358
|
})
|
|
274
359
|
);
|
|
275
360
|
},
|
|
276
|
-
|
|
277
|
-
|
|
361
|
+
onMutate: (input) =>
|
|
362
|
+
beginOwnChange(
|
|
363
|
+
client,
|
|
364
|
+
input.mailboxId,
|
|
365
|
+
bulkOwnChange(
|
|
366
|
+
input,
|
|
367
|
+
user ? { userId: user.id, name: user.name } : undefined
|
|
368
|
+
)
|
|
369
|
+
),
|
|
370
|
+
onError: (_error, input, change) =>
|
|
371
|
+
ownChangeFailed(client, input.mailboxId, change),
|
|
372
|
+
onSuccess: (_result, { mailboxId, action }, change) => {
|
|
373
|
+
ownChangeDone(client, mailboxId, change);
|
|
374
|
+
|
|
375
|
+
// A verdict trusts senders (Not spam) and changes who the mailbox
|
|
376
|
+
// hears from.
|
|
377
|
+
if (action.type === "report" || action.type === "not_spam") {
|
|
378
|
+
void client.invalidateQueries({
|
|
379
|
+
queryKey: ["blocked-senders", mailboxId],
|
|
380
|
+
});
|
|
381
|
+
void client.invalidateQueries({
|
|
382
|
+
queryKey: ["recipient-suggestions", mailboxId],
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
},
|
|
386
|
+
onSettled: (_result, _error, input) =>
|
|
387
|
+
ownChangeSettled(client, input.mailboxId),
|
|
278
388
|
});
|
|
279
389
|
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { responseJson } from "@open-workspace/core/ui";
|
|
2
2
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { toast } from "sonner";
|
|
3
4
|
|
|
4
5
|
import { mailApi } from "../lib/mail-api";
|
|
5
|
-
import {
|
|
6
|
+
import { blockedSendersQuery } from "./mail-queries";
|
|
7
|
+
import { applyMailboxChange } from "./mail-query-cache";
|
|
6
8
|
|
|
7
9
|
const blockedKey = (mailboxId: string) =>
|
|
8
|
-
|
|
10
|
+
blockedSendersQuery(mailboxId).queryKey;
|
|
9
11
|
|
|
10
12
|
function useMailboxRefresh() {
|
|
11
13
|
const client = useQueryClient();
|
|
12
14
|
|
|
13
15
|
return (mailboxId: string) => {
|
|
14
|
-
|
|
16
|
+
applyMailboxChange(client, mailboxId);
|
|
15
17
|
void client.invalidateQueries({ queryKey: blockedKey(mailboxId) });
|
|
16
18
|
void client.invalidateQueries({
|
|
17
19
|
queryKey: ["recipient-suggestions", mailboxId],
|
|
@@ -54,51 +56,30 @@ export function useReportMessage() {
|
|
|
54
56
|
});
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
export function
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
mutationFn: async (input: {
|
|
62
|
-
mailboxId: string;
|
|
63
|
-
conversationIds: string[];
|
|
64
|
-
}) =>
|
|
65
|
-
responseJson(
|
|
66
|
-
await mailApi.api.mail.conversations.report.$post({
|
|
67
|
-
query: { mailboxId: input.mailboxId },
|
|
68
|
-
json: { conversationIds: input.conversationIds },
|
|
69
|
-
})
|
|
70
|
-
),
|
|
71
|
-
onSuccess: (_result, { mailboxId }) => refresh(mailboxId),
|
|
72
|
-
});
|
|
59
|
+
export function undoSpamDecision(mailboxId: string, undoId: string) {
|
|
60
|
+
return mailApi.api.mail.conversations["undo-spam"]
|
|
61
|
+
.$post({ query: { mailboxId }, json: { undoId } })
|
|
62
|
+
.then(responseJson);
|
|
73
63
|
}
|
|
74
64
|
|
|
75
|
-
export function
|
|
65
|
+
export function useUndoSpamDecision() {
|
|
76
66
|
const refresh = useMailboxRefresh();
|
|
77
67
|
|
|
78
68
|
return useMutation({
|
|
79
|
-
mutationFn:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
69
|
+
mutationFn: ({
|
|
70
|
+
mailboxId,
|
|
71
|
+
undoId,
|
|
72
|
+
}: {
|
|
73
|
+
mailboxId: string;
|
|
74
|
+
undoId: string;
|
|
75
|
+
}) => undoSpamDecision(mailboxId, undoId),
|
|
76
|
+
onError: (error) => toast.error(error.message),
|
|
86
77
|
onSuccess: (_result, { mailboxId }) => refresh(mailboxId),
|
|
87
78
|
});
|
|
88
79
|
}
|
|
89
80
|
|
|
90
81
|
export function useBlockedSenders(mailboxId: string, enabled: boolean) {
|
|
91
|
-
return useQuery({
|
|
92
|
-
queryKey: blockedKey(mailboxId),
|
|
93
|
-
queryFn: async ({ signal }) =>
|
|
94
|
-
responseJson(
|
|
95
|
-
await mailApi.api.mail.mailboxes[":id"]["blocked-senders"].$get(
|
|
96
|
-
{ param: { id: mailboxId } },
|
|
97
|
-
{ init: { signal } }
|
|
98
|
-
)
|
|
99
|
-
),
|
|
100
|
-
enabled,
|
|
101
|
-
});
|
|
82
|
+
return useQuery({ ...blockedSendersQuery(mailboxId), enabled });
|
|
102
83
|
}
|
|
103
84
|
|
|
104
85
|
export function useBlockSender() {
|
|
@@ -3,9 +3,11 @@ import type { SuccessfulResponse } from "@open-workspace/core/ui";
|
|
|
3
3
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
4
4
|
|
|
5
5
|
import type { ReplyActionMode } from "../../shared/mail";
|
|
6
|
+
import type { StoredImageRef } from "../../shared/rich-content";
|
|
6
7
|
import { mailApi } from "../lib/mail-api";
|
|
7
8
|
import type { SubmittedComposerUpload } from "./composer-session";
|
|
8
|
-
import {
|
|
9
|
+
import { applyMailboxChange } from "./mail-query-cache";
|
|
10
|
+
import { forgetDrafts } from "./use-drafts";
|
|
9
11
|
|
|
10
12
|
export type SubmittedMessage = SuccessfulResponse<
|
|
11
13
|
Awaited<ReturnType<typeof mailApi.api.mail.messages.$post>>
|
|
@@ -17,6 +19,11 @@ type MessageContent = {
|
|
|
17
19
|
bodyText: string;
|
|
18
20
|
bodyHtml?: string;
|
|
19
21
|
uploadedAttachments?: SubmittedComposerUpload[];
|
|
22
|
+
/** Saved images the body shows by `cid:`, e.g. the signature's. */
|
|
23
|
+
storedImages?: StoredImageRef[];
|
|
24
|
+
/** The composer's draft, which the server deletes once the message is accepted. */
|
|
25
|
+
draftId?: string;
|
|
26
|
+
draftVersion?: number;
|
|
20
27
|
};
|
|
21
28
|
|
|
22
29
|
type MailSendInput =
|
|
@@ -37,6 +44,7 @@ type MailSendInput =
|
|
|
37
44
|
})
|
|
38
45
|
| (MessageContent & {
|
|
39
46
|
kind: "forward";
|
|
47
|
+
forwardedAttachmentIds?: string[];
|
|
40
48
|
sourceEmailId: string;
|
|
41
49
|
to: string[];
|
|
42
50
|
cc: string[];
|
|
@@ -50,10 +58,7 @@ type WithoutRequestId<Input> = Input extends MailSendInput
|
|
|
50
58
|
|
|
51
59
|
export type MailSendDraft = WithoutRequestId<MailSendInput>;
|
|
52
60
|
|
|
53
|
-
export function withMailSendRequestId(
|
|
54
|
-
draft: MailSendDraft,
|
|
55
|
-
requestId: string
|
|
56
|
-
): MailSendInput {
|
|
61
|
+
export function withMailSendRequestId(draft: MailSendDraft, requestId: string) {
|
|
57
62
|
switch (draft.kind) {
|
|
58
63
|
case "compose": {
|
|
59
64
|
return { ...draft, requestId };
|
|
@@ -85,6 +90,9 @@ export function useMailSend() {
|
|
|
85
90
|
bodyText: input.bodyText,
|
|
86
91
|
bodyHtml: input.bodyHtml,
|
|
87
92
|
attachments: input.uploadedAttachments ?? [],
|
|
93
|
+
storedImages: input.storedImages ?? [],
|
|
94
|
+
draftId: input.draftId,
|
|
95
|
+
draftVersion: input.draftVersion,
|
|
88
96
|
};
|
|
89
97
|
|
|
90
98
|
if (input.kind === "reply") {
|
|
@@ -106,6 +114,7 @@ export function useMailSend() {
|
|
|
106
114
|
await mailApi.api.mail.messages[":id"].forward.$post({
|
|
107
115
|
param: { id: input.sourceEmailId },
|
|
108
116
|
json: {
|
|
117
|
+
forwardedAttachmentIds: input.forwardedAttachmentIds,
|
|
109
118
|
...request,
|
|
110
119
|
to: input.to,
|
|
111
120
|
cc: input.cc,
|
|
@@ -133,8 +142,11 @@ export function useMailSend() {
|
|
|
133
142
|
// message id from it, so a lost response cannot create a second message.
|
|
134
143
|
retry: (failureCount, error) =>
|
|
135
144
|
failureCount < 1 && (!(error instanceof ApiError) || error.status >= 500),
|
|
145
|
+
// Here, not in the composer: it may be gone (the person moved on) by
|
|
146
|
+
// the time the message is sent, and its draft must not come back.
|
|
136
147
|
onSuccess: (_result, input) => {
|
|
137
|
-
|
|
148
|
+
if (input.draftId) forgetDrafts(client, input.mailboxId, [input.draftId]);
|
|
149
|
+
else applyMailboxChange(client, input.mailboxId);
|
|
138
150
|
},
|
|
139
151
|
});
|
|
140
152
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { recipientField } from "./composer-recipients";
|
|
4
|
+
import type {
|
|
5
|
+
ComposerRecipient,
|
|
6
|
+
RecipientFieldValue,
|
|
7
|
+
} from "./composer-recipients";
|
|
8
|
+
|
|
9
|
+
// A manually added address stays in Cc. A removed one stays out, even after switching back to Reply all.
|
|
10
|
+
function recordCcEdits(
|
|
11
|
+
before: ComposerRecipient[],
|
|
12
|
+
after: ComposerRecipient[],
|
|
13
|
+
edits = new Map<string, ComposerRecipient | null>()
|
|
14
|
+
) {
|
|
15
|
+
const previous = new Set(before.map(({ address }) => address));
|
|
16
|
+
const current = new Set(after.map(({ address }) => address));
|
|
17
|
+
const updated = new Map(edits);
|
|
18
|
+
|
|
19
|
+
for (const address of previous) {
|
|
20
|
+
if (!current.has(address)) updated.set(address, null);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
for (const recipient of after) {
|
|
24
|
+
if (!previous.has(recipient.address)) {
|
|
25
|
+
updated.set(recipient.address, recipient);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return updated;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function useReplyCc(defaultAddresses: string[], saved?: string[]) {
|
|
33
|
+
const defaults = recipientField(defaultAddresses);
|
|
34
|
+
|
|
35
|
+
const [edits, setEdits] = useState(() => {
|
|
36
|
+
const restored = saved ? recipientField(saved) : defaults;
|
|
37
|
+
|
|
38
|
+
return recordCcEdits(defaults.recipients, restored.recipients);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const [typed, setTyped] = useState(() =>
|
|
42
|
+
saved ? recipientField(saved).input : null
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const input = typed ?? defaults.input;
|
|
46
|
+
|
|
47
|
+
const recipients = [
|
|
48
|
+
...defaults.recipients.filter(({ address }) => !edits.has(address)),
|
|
49
|
+
...Array.from(edits.values()).filter((recipient) => recipient !== null),
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
function onChange(next: RecipientFieldValue) {
|
|
53
|
+
if (next.recipients !== recipients) {
|
|
54
|
+
setEdits(recordCcEdits(recipients, next.recipients, edits));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (next.input !== input) setTyped(next.input);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return { value: { recipients, input }, onChange };
|
|
61
|
+
}
|