@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
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { mergeAttributes, Node } from "@tiptap/react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Saved rich content (a signature, an auto-reply) in the composer's
|
|
5
|
+
* editor. Its images are already in R2, so the editor shows them from there
|
|
6
|
+
* as `storedImage` nodes instead of uploading them again; a message sends
|
|
7
|
+
* them as references (`storedImages`) and the Worker copies them in, and a
|
|
8
|
+
* saved editor keeps them by content id (worker/mail/rich-content.ts).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Saved HTML made ready for the editor: each `cid:` image becomes a stored
|
|
13
|
+
* image of `ownerId`, shown from `imageUrl(contentId)`.
|
|
14
|
+
*/
|
|
15
|
+
export function storedImagesHtml(
|
|
16
|
+
html: string,
|
|
17
|
+
ownerId: string,
|
|
18
|
+
imageUrl: (contentId: string) => string
|
|
19
|
+
) {
|
|
20
|
+
const document = new DOMParser().parseFromString(html, "text/html");
|
|
21
|
+
|
|
22
|
+
for (const image of document.querySelectorAll("img")) {
|
|
23
|
+
const source = image.getAttribute("src") ?? "";
|
|
24
|
+
|
|
25
|
+
if (!source.startsWith("cid:")) {
|
|
26
|
+
image.remove();
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
image.dataset.storedOwner = ownerId;
|
|
31
|
+
image.dataset.src = imageUrl(source.slice(4));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return document.body.innerHTML;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Takes the stored images out of serialized editor HTML: their references,
|
|
39
|
+
* with the `img` left as a plain `cid:` image for sending or saving.
|
|
40
|
+
*/
|
|
41
|
+
export function takeStoredImages(root: Element) {
|
|
42
|
+
return Array.from(
|
|
43
|
+
root.querySelectorAll<HTMLImageElement>("img[data-stored-owner]"),
|
|
44
|
+
(image) => {
|
|
45
|
+
const ownerId = image.dataset.storedOwner ?? "";
|
|
46
|
+
const contentId = (image.getAttribute("src") ?? "").replace(/^cid:/u, "");
|
|
47
|
+
delete image.dataset.storedOwner;
|
|
48
|
+
|
|
49
|
+
return { ownerId, contentId };
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** An image of saved rich content, shown from where it is stored. */
|
|
55
|
+
export const StoredImage = Node.create({
|
|
56
|
+
name: "storedImage",
|
|
57
|
+
group: "inline",
|
|
58
|
+
inline: true,
|
|
59
|
+
atom: true,
|
|
60
|
+
draggable: true,
|
|
61
|
+
selectable: true,
|
|
62
|
+
|
|
63
|
+
// Each read from the saved `img` that storedImagesHtml prepared.
|
|
64
|
+
addAttributes() {
|
|
65
|
+
return {
|
|
66
|
+
ownerId: {
|
|
67
|
+
default: "",
|
|
68
|
+
rendered: false,
|
|
69
|
+
parseHTML: (element) => element.dataset.storedOwner ?? "",
|
|
70
|
+
},
|
|
71
|
+
contentId: {
|
|
72
|
+
default: "",
|
|
73
|
+
rendered: false,
|
|
74
|
+
parseHTML: (element) =>
|
|
75
|
+
element.dataset.cid ??
|
|
76
|
+
(element.getAttribute("src") ?? "").replace(/^cid:/u, ""),
|
|
77
|
+
},
|
|
78
|
+
src: {
|
|
79
|
+
default: "",
|
|
80
|
+
rendered: false,
|
|
81
|
+
parseHTML: (element) => element.dataset.src ?? "",
|
|
82
|
+
},
|
|
83
|
+
alt: {
|
|
84
|
+
default: "",
|
|
85
|
+
rendered: false,
|
|
86
|
+
parseHTML: (element) => element.getAttribute("alt") ?? "",
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
parseHTML() {
|
|
92
|
+
return [{ tag: "img[data-stored-owner]" }];
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
// Serialized with its content id in `data-cid`, not `src`: the editor
|
|
96
|
+
// serializes in the page's document, where a `cid:` src would be fetched
|
|
97
|
+
// (and fail). composerContent turns it into the `cid:` image it sends,
|
|
98
|
+
// marked for takeStoredImages.
|
|
99
|
+
renderHTML({ node, HTMLAttributes }) {
|
|
100
|
+
return [
|
|
101
|
+
"img",
|
|
102
|
+
mergeAttributes(HTMLAttributes, {
|
|
103
|
+
"data-cid": String(node.attrs.contentId),
|
|
104
|
+
alt: node.attrs.alt,
|
|
105
|
+
title: node.attrs.alt,
|
|
106
|
+
"data-stored-owner": node.attrs.ownerId,
|
|
107
|
+
}),
|
|
108
|
+
];
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
renderText({ node }) {
|
|
112
|
+
return String(node.attrs.alt);
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
// Shown in the editor from its stored copy.
|
|
116
|
+
addNodeView() {
|
|
117
|
+
return ({ node }) => {
|
|
118
|
+
const image = document.createElement("img");
|
|
119
|
+
image.className = "composer-inline-image";
|
|
120
|
+
image.src = String(node.attrs.src);
|
|
121
|
+
image.alt = String(node.attrs.alt);
|
|
122
|
+
image.title = String(node.attrs.alt);
|
|
123
|
+
image.draggable = false;
|
|
124
|
+
|
|
125
|
+
return { dom: image };
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import DOMPurify from "dompurify";
|
|
2
2
|
|
|
3
3
|
import { isComposerInlineImageContentType } from "../../shared/mail";
|
|
4
|
+
import { safeLink } from "../../shared/mail-html";
|
|
4
5
|
import { isRemoteHttpUrl, mailRemoteProxyPath } from "../../shared/mail-remote";
|
|
6
|
+
import { normalizedContentId } from "../../shared/rich-content";
|
|
5
7
|
import type { MessageAttachment } from "./types";
|
|
6
8
|
|
|
7
9
|
const FORBIDDEN_TAGS = [
|
|
@@ -25,13 +27,19 @@ const FORBIDDEN_TAGS = [
|
|
|
25
27
|
"math",
|
|
26
28
|
];
|
|
27
29
|
|
|
28
|
-
const FORBIDDEN_ATTRIBUTES = [
|
|
30
|
+
const FORBIDDEN_ATTRIBUTES = [
|
|
31
|
+
"poster",
|
|
32
|
+
"action",
|
|
33
|
+
"formaction",
|
|
34
|
+
"data-mail-quote",
|
|
35
|
+
];
|
|
29
36
|
|
|
30
37
|
const COMPOSER_TAGS = [
|
|
31
38
|
"a",
|
|
32
39
|
"b",
|
|
33
40
|
"blockquote",
|
|
34
41
|
"br",
|
|
42
|
+
"caption",
|
|
35
43
|
"code",
|
|
36
44
|
"div",
|
|
37
45
|
"em",
|
|
@@ -45,26 +53,39 @@ const COMPOSER_TAGS = [
|
|
|
45
53
|
"section",
|
|
46
54
|
"span",
|
|
47
55
|
"strong",
|
|
56
|
+
"table",
|
|
57
|
+
"tbody",
|
|
58
|
+
"td",
|
|
59
|
+
"tfoot",
|
|
60
|
+
"th",
|
|
61
|
+
"thead",
|
|
62
|
+
"tr",
|
|
48
63
|
"u",
|
|
49
64
|
"ul",
|
|
50
65
|
];
|
|
51
66
|
|
|
52
67
|
const COMPOSER_ATTRIBUTES = [
|
|
53
68
|
"alt",
|
|
69
|
+
"colspan",
|
|
54
70
|
"data-forwarded-message",
|
|
71
|
+
"data-mail-quote",
|
|
55
72
|
"data-linked-attachment-card",
|
|
56
73
|
"href",
|
|
57
74
|
"loading",
|
|
58
75
|
"referrerpolicy",
|
|
59
76
|
"rel",
|
|
77
|
+
"rowspan",
|
|
60
78
|
"src",
|
|
61
79
|
"srcset",
|
|
62
80
|
"target",
|
|
63
81
|
"title",
|
|
64
82
|
];
|
|
65
83
|
|
|
84
|
+
// A backslash escape spells any of these without the letters (`u\72l(` is
|
|
85
|
+
// `url(`), and `image-set()` loads plain strings as URLs; neither is
|
|
86
|
+
// left for the browser to read.
|
|
66
87
|
const DANGEROUS_CSS =
|
|
67
|
-
/expression\s*\(|-moz-binding|behavior\s*:|@import|javascript\s*:|vbscript\s*:|data\s*:\s*text\/html
|
|
88
|
+
/expression\s*\(|-moz-binding|behavior\s*:|@import|javascript\s*:|vbscript\s*:|data\s*:\s*text\/html|image-set\s*\(|\\/giu;
|
|
68
89
|
|
|
69
90
|
/**
|
|
70
91
|
* Keep email layout CSS while blocking scriptable CSS.
|
|
@@ -81,9 +102,20 @@ export function sanitizeEmailCss(
|
|
|
81
102
|
"/* blocked */"
|
|
82
103
|
);
|
|
83
104
|
|
|
105
|
+
// A quoted URL holds anything but its own quote; an unquoted one no
|
|
106
|
+
// quote or parenthesis. Any other `url(` is not left for the
|
|
107
|
+
// browser to read some other way.
|
|
84
108
|
return withoutDanger.replaceAll(
|
|
85
|
-
/url\s*\(\s*([
|
|
86
|
-
(
|
|
109
|
+
/url\s*\(\s*(?:"([^"]*)"|'([^']*)'|([^"'()]*))\s*\)|url\s*\(/giu,
|
|
110
|
+
(
|
|
111
|
+
match,
|
|
112
|
+
doubleQuoted: string | undefined,
|
|
113
|
+
singleQuoted: string | undefined,
|
|
114
|
+
unquoted: string | undefined
|
|
115
|
+
) => {
|
|
116
|
+
const rawUrl = doubleQuoted ?? singleQuoted ?? unquoted;
|
|
117
|
+
|
|
118
|
+
if (rawUrl === undefined) return "/* blocked */";
|
|
87
119
|
const url = rawUrl.trim();
|
|
88
120
|
|
|
89
121
|
if (/^data:image\/(?:gif|jpeg|jpg|png|webp)/iu.test(url)) return match;
|
|
@@ -101,32 +133,6 @@ export function sanitizeEmailCss(
|
|
|
101
133
|
);
|
|
102
134
|
}
|
|
103
135
|
|
|
104
|
-
function normalizedContentId(value: string) {
|
|
105
|
-
let decoded = value;
|
|
106
|
-
|
|
107
|
-
try {
|
|
108
|
-
decoded = decodeURIComponent(value);
|
|
109
|
-
} catch {
|
|
110
|
-
// Malformed percent escapes are treated as an opaque content ID.
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return decoded
|
|
114
|
-
.replace(/^cid:/iu, "")
|
|
115
|
-
.replaceAll(/^<|>$/gu, "")
|
|
116
|
-
.trim()
|
|
117
|
-
.toLocaleLowerCase();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function safeLink(value: string) {
|
|
121
|
-
try {
|
|
122
|
-
const url = new URL(value);
|
|
123
|
-
|
|
124
|
-
return ["http:", "https:", "mailto:"].includes(url.protocol);
|
|
125
|
-
} catch {
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
136
|
function inlineAttachmentUrls(
|
|
131
137
|
mailboxId: string,
|
|
132
138
|
messageId: string,
|
|
@@ -250,6 +256,7 @@ type SafeEmailDocument = {
|
|
|
250
256
|
srcDoc: string;
|
|
251
257
|
proxiedRemoteImages: number;
|
|
252
258
|
renderAsHtml: boolean;
|
|
259
|
+
hasHtmlQuote: boolean;
|
|
253
260
|
};
|
|
254
261
|
|
|
255
262
|
/**
|
|
@@ -264,7 +271,7 @@ export function sanitizeEmailHtml(input: {
|
|
|
264
271
|
messageId: string;
|
|
265
272
|
attachments: MessageAttachment[];
|
|
266
273
|
remoteTokens: Record<string, string> | null;
|
|
267
|
-
})
|
|
274
|
+
}) {
|
|
268
275
|
const { remoteTokens } = input;
|
|
269
276
|
|
|
270
277
|
const rewriteRemoteUrl = (url: string) => {
|
|
@@ -279,6 +286,7 @@ export function sanitizeEmailHtml(input: {
|
|
|
279
286
|
const sanitized = DOMPurify.sanitize(input.html, {
|
|
280
287
|
USE_PROFILES: { html: true },
|
|
281
288
|
ADD_TAGS: ["style"],
|
|
289
|
+
FORCE_BODY: true,
|
|
282
290
|
ADD_ATTR: [
|
|
283
291
|
"style",
|
|
284
292
|
"bgcolor",
|
|
@@ -379,6 +387,12 @@ export function sanitizeEmailHtml(input: {
|
|
|
379
387
|
.map((node) => node.outerHTML)
|
|
380
388
|
.join("\n");
|
|
381
389
|
|
|
390
|
+
// Keep only the quote marker when stripping sender classes for composer HTML.
|
|
391
|
+
const quotes = document.querySelectorAll<HTMLElement>(
|
|
392
|
+
'.gmail_quote:has(blockquote), blockquote.gmail_quote, blockquote[type="cite" i]'
|
|
393
|
+
);
|
|
394
|
+
|
|
395
|
+
for (const quote of quotes) quote.dataset.mailQuote = "";
|
|
382
396
|
const body = document.body.innerHTML;
|
|
383
397
|
|
|
384
398
|
// Composer HTML is rendered in the app document, so sender-controlled CSS,
|
|
@@ -416,6 +430,7 @@ export function sanitizeEmailHtml(input: {
|
|
|
416
430
|
</style>
|
|
417
431
|
${headStyles}
|
|
418
432
|
<style>
|
|
433
|
+
html[data-hide-quote] [data-mail-quote] { display: none !important; }
|
|
419
434
|
html, body {
|
|
420
435
|
width: 100% !important;
|
|
421
436
|
max-width: 100% !important;
|
|
@@ -429,5 +444,11 @@ export function sanitizeEmailHtml(input: {
|
|
|
429
444
|
<body>${body}</body>
|
|
430
445
|
</html>`;
|
|
431
446
|
|
|
432
|
-
return {
|
|
447
|
+
return {
|
|
448
|
+
composerHtml,
|
|
449
|
+
srcDoc,
|
|
450
|
+
proxiedRemoteImages,
|
|
451
|
+
renderAsHtml,
|
|
452
|
+
hasHtmlQuote: quotes.length > 0,
|
|
453
|
+
} satisfies SafeEmailDocument;
|
|
433
454
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
1
|
+
import { Fragment, useState } from "react";
|
|
2
2
|
import { toast } from "sonner";
|
|
3
3
|
|
|
4
|
+
import type { ConversationPlace } from "../../shared/mail";
|
|
5
|
+
import { FilterMessagesDialog } from "./mailbox-rules";
|
|
4
6
|
import {
|
|
5
7
|
BlockSenderDialog,
|
|
6
8
|
senderLabel,
|
|
@@ -8,53 +10,66 @@ import {
|
|
|
8
10
|
} from "./sender-dialogs";
|
|
9
11
|
import type { Mailbox, MessageDetail } from "./types";
|
|
10
12
|
import {
|
|
11
|
-
useNotSpam,
|
|
12
13
|
useReportMessage,
|
|
13
14
|
useTrustSender,
|
|
14
15
|
useUnblockSender,
|
|
16
|
+
useUndoSpamDecision,
|
|
15
17
|
} from "./use-mail-safety";
|
|
16
18
|
|
|
17
|
-
type SenderDialogKind = "unsubscribe" | "block";
|
|
19
|
+
type SenderDialogKind = "unsubscribe" | "block" | "filter";
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
|
-
* Sender-level actions (unsubscribe, block, report, trust) and their
|
|
22
|
+
* Sender-level actions (unsubscribe, block, filter, report, trust) and their
|
|
21
23
|
* confirmation dialogs, shared by the message menus and the command bar.
|
|
24
|
+
* Report spam here is a message's, from its menu; the bar reports or
|
|
25
|
+
* clears the whole conversation as a selection does (`useConversationActions`).
|
|
22
26
|
*/
|
|
23
27
|
export function useSenderActions({
|
|
24
28
|
mailbox,
|
|
25
|
-
|
|
26
|
-
onOpenConversation,
|
|
29
|
+
onPlaces,
|
|
27
30
|
}: {
|
|
28
31
|
mailbox?: Mailbox;
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
-
/** Called with the conversation a message rejoined (Not spam) and its folder, to open it instead. */
|
|
32
|
-
onOpenConversation: (conversationId: string, folder: string) => void;
|
|
32
|
+
/** What an action did to conversations, for the view to follow (`followOwnChange`). */
|
|
33
|
+
onPlaces: (places: readonly ConversationPlace[]) => void;
|
|
33
34
|
}) {
|
|
34
35
|
const [dialog, setDialog] = useState<{
|
|
35
36
|
kind: SenderDialogKind;
|
|
36
37
|
message: MessageDetail;
|
|
37
38
|
open: boolean;
|
|
39
|
+
/** Counts the openings, so each starts a fresh dialog, its choices unset. */
|
|
40
|
+
opening: number;
|
|
38
41
|
} | null>(null);
|
|
39
42
|
|
|
40
43
|
const report = useReportMessage();
|
|
44
|
+
const undo = useUndoSpamDecision();
|
|
41
45
|
const unblock = useUnblockSender();
|
|
42
46
|
const trust = useTrustSender();
|
|
43
|
-
const notSpam = useNotSpam();
|
|
44
47
|
|
|
45
48
|
function setOpen(open: boolean) {
|
|
46
49
|
setDialog((current) => current && { ...current, open });
|
|
47
50
|
}
|
|
48
51
|
|
|
52
|
+
/** Report spam of one message, and its sender's others in the thread. */
|
|
49
53
|
function reportSpam(message: MessageDetail) {
|
|
50
54
|
if (!mailbox) return;
|
|
55
|
+
const mailboxId = mailbox.id;
|
|
51
56
|
report.mutate(
|
|
52
|
-
{ mailboxId
|
|
57
|
+
{ mailboxId, messageId: message.id },
|
|
53
58
|
{
|
|
54
|
-
onSuccess: (
|
|
55
|
-
|
|
59
|
+
onSuccess: ({ places, undoId }) => {
|
|
60
|
+
if (undoId) {
|
|
61
|
+
toast.success("Reported as spam", {
|
|
62
|
+
duration: 8000,
|
|
63
|
+
action: {
|
|
64
|
+
label: "Undo",
|
|
65
|
+
onClick: () => undo.mutate({ mailboxId, undoId }),
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
} else {
|
|
69
|
+
toast.warning("There was no mail to report here any more");
|
|
70
|
+
}
|
|
56
71
|
|
|
57
|
-
|
|
72
|
+
onPlaces(places);
|
|
58
73
|
},
|
|
59
74
|
onError: (error) => toast.error(error.message),
|
|
60
75
|
}
|
|
@@ -86,30 +101,9 @@ export function useSenderActions({
|
|
|
86
101
|
);
|
|
87
102
|
}
|
|
88
103
|
|
|
89
|
-
function markNotSpam(message: MessageDetail) {
|
|
90
|
-
if (!mailbox) return;
|
|
91
|
-
notSpam.mutate(
|
|
92
|
-
{ mailboxId: mailbox.id, messageId: message.id },
|
|
93
|
-
{
|
|
94
|
-
onSuccess: (result) => {
|
|
95
|
-
toast.success(
|
|
96
|
-
`${result.rejoined ? "Moved back to its conversation" : "Moved to Inbox"}. Mail from ${message.fromAddress} won't be treated as spam.`
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
if (result.rejoined) {
|
|
100
|
-
onOpenConversation(result.conversationId, result.folder);
|
|
101
|
-
} else {
|
|
102
|
-
onLeaveConversation();
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
onError: (error) => toast.error(error.message),
|
|
106
|
-
}
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
104
|
const dialogs =
|
|
111
105
|
dialog && mailbox ? (
|
|
112
|
-
|
|
106
|
+
<Fragment key={dialog.opening}>
|
|
113
107
|
{dialog.kind === "unsubscribe" && (
|
|
114
108
|
<UnsubscribeDialog
|
|
115
109
|
message={dialog.message}
|
|
@@ -124,24 +118,32 @@ export function useSenderActions({
|
|
|
124
118
|
mailbox={mailbox}
|
|
125
119
|
open={dialog.open}
|
|
126
120
|
onOpenChange={setOpen}
|
|
127
|
-
onMoved={
|
|
121
|
+
onMoved={onPlaces}
|
|
122
|
+
/>
|
|
123
|
+
)}
|
|
124
|
+
{dialog.kind === "filter" && (
|
|
125
|
+
<FilterMessagesDialog
|
|
126
|
+
mailboxId={mailbox.id}
|
|
127
|
+
message={dialog.message}
|
|
128
|
+
open={dialog.open}
|
|
129
|
+
onOpenChange={setOpen}
|
|
128
130
|
/>
|
|
129
131
|
)}
|
|
130
|
-
|
|
132
|
+
</Fragment>
|
|
131
133
|
) : null;
|
|
132
134
|
|
|
133
135
|
return {
|
|
134
136
|
open: (kind: SenderDialogKind, message: MessageDetail) =>
|
|
135
|
-
setDialog(
|
|
137
|
+
setDialog((current) => ({
|
|
138
|
+
kind,
|
|
139
|
+
message,
|
|
140
|
+
open: true,
|
|
141
|
+
opening: (current?.opening ?? 0) + 1,
|
|
142
|
+
})),
|
|
136
143
|
reportSpam,
|
|
137
144
|
unblockSender,
|
|
138
145
|
trustSender,
|
|
139
|
-
|
|
140
|
-
pending:
|
|
141
|
-
report.isPending ||
|
|
142
|
-
unblock.isPending ||
|
|
143
|
-
trust.isPending ||
|
|
144
|
-
notSpam.isPending,
|
|
146
|
+
pending: report.isPending || unblock.isPending || trust.isPending,
|
|
145
147
|
dialogs,
|
|
146
148
|
};
|
|
147
149
|
}
|
|
@@ -18,7 +18,7 @@ type Tone = "pass" | "fail" | "warn" | "neutral";
|
|
|
18
18
|
|
|
19
19
|
function resultTone(
|
|
20
20
|
value: AuthResult | "pass" | "fail" | "none" | null | undefined
|
|
21
|
-
)
|
|
21
|
+
) {
|
|
22
22
|
if (value === "pass") return "pass";
|
|
23
23
|
|
|
24
24
|
if (value === "fail" || value === "permerror") return "fail";
|
|
@@ -15,8 +15,10 @@ import {
|
|
|
15
15
|
import { ExternalLink, LoaderCircle, MailMinus, ShieldBan } from "lucide-react";
|
|
16
16
|
import { useState } from "react";
|
|
17
17
|
import type { ReactNode } from "react";
|
|
18
|
+
import { Controller, useForm } from "react-hook-form";
|
|
18
19
|
import { toast } from "sonner";
|
|
19
20
|
|
|
21
|
+
import type { ConversationPlace } from "../../shared/mail";
|
|
20
22
|
import type { Mailbox, MessageDetail } from "./types";
|
|
21
23
|
import { useBlockSender, useUnsubscribe } from "./use-mail-safety";
|
|
22
24
|
|
|
@@ -250,9 +252,12 @@ export function UnsubscribeDialog({
|
|
|
250
252
|
to {mailbox.address}.
|
|
251
253
|
</p>
|
|
252
254
|
{methods?.oneClick && canMail && (
|
|
253
|
-
<p
|
|
254
|
-
If their server doesn't answer, we'll
|
|
255
|
-
|
|
255
|
+
<p>
|
|
256
|
+
If their server doesn't answer, we'll email{" "}
|
|
257
|
+
<span className="text-foreground font-medium">
|
|
258
|
+
{mailto}
|
|
259
|
+
</span>{" "}
|
|
260
|
+
from {mailbox.address} instead.
|
|
256
261
|
</p>
|
|
257
262
|
)}
|
|
258
263
|
<p>No links in the message are opened.</p>
|
|
@@ -293,34 +298,39 @@ export function BlockSenderDialog({
|
|
|
293
298
|
mailbox: Mailbox;
|
|
294
299
|
open: boolean;
|
|
295
300
|
onOpenChange: (open: boolean) => void;
|
|
296
|
-
|
|
301
|
+
/** Where the sender's mail went, for the view to follow. */
|
|
302
|
+
onMoved?: (places: ConversationPlace[]) => void;
|
|
297
303
|
}) {
|
|
298
304
|
const block = useBlockSender();
|
|
299
|
-
|
|
300
|
-
const
|
|
305
|
+
|
|
306
|
+
const { control, handleSubmit } = useForm<{
|
|
307
|
+
scope: "address" | "domain";
|
|
308
|
+
moveExisting: boolean;
|
|
309
|
+
}>({ defaultValues: { scope: "address", moveExisting: true } });
|
|
310
|
+
|
|
301
311
|
const name = senderLabel(message);
|
|
302
312
|
const domain = addressDomain(message.fromAddress);
|
|
303
313
|
const ownDomain = domain === addressDomain(mailbox.address);
|
|
304
314
|
|
|
305
|
-
|
|
315
|
+
const confirm = handleSubmit(({ scope, moveExisting }) => {
|
|
306
316
|
const pattern = scope === "domain" ? `@${domain}` : message.fromAddress;
|
|
307
317
|
block.mutate(
|
|
308
318
|
{ mailboxId: mailbox.id, pattern, moveExisting },
|
|
309
319
|
{
|
|
310
320
|
onSuccess: (result) => {
|
|
321
|
+
const moved = result.places.length;
|
|
311
322
|
toast.success(
|
|
312
|
-
|
|
313
|
-
? `Blocked ${result.block.pattern}; moved ${
|
|
323
|
+
moved
|
|
324
|
+
? `Blocked ${result.block.pattern}; moved mail from ${moved} conversation${moved === 1 ? "" : "s"} to Spam`
|
|
314
325
|
: `Blocked ${result.block.pattern}`
|
|
315
326
|
);
|
|
316
327
|
onOpenChange(false);
|
|
317
|
-
|
|
318
|
-
if (result.moved) onMoved?.();
|
|
328
|
+
onMoved?.(result.places);
|
|
319
329
|
},
|
|
320
330
|
onError: (error) => toast.error(error.message),
|
|
321
331
|
}
|
|
322
332
|
);
|
|
323
|
-
}
|
|
333
|
+
});
|
|
324
334
|
|
|
325
335
|
return (
|
|
326
336
|
<AlertDialog open={open} onOpenChange={onOpenChange}>
|
|
@@ -335,44 +345,58 @@ export function BlockSenderDialog({
|
|
|
335
345
|
mailbox. The sender isn't told, and you can unblock at any time.
|
|
336
346
|
</AlertDialogDescription>
|
|
337
347
|
</AlertDialogHeader>
|
|
338
|
-
<
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
).map(([value, label, hint]) => (
|
|
349
|
-
<RadioCard
|
|
350
|
-
key={value}
|
|
351
|
-
value={value}
|
|
352
|
-
disabled={value === "domain" && ownDomain}
|
|
353
|
-
className="items-center rounded-md px-3 py-2 data-disabled:opacity-50 *:data-[slot=radio-card-indicator]:mt-0"
|
|
348
|
+
<Controller
|
|
349
|
+
control={control}
|
|
350
|
+
name="scope"
|
|
351
|
+
render={({ field }) => (
|
|
352
|
+
<RadioGroup
|
|
353
|
+
aria-label="What to block"
|
|
354
|
+
value={field.value}
|
|
355
|
+
onValueChange={(value: "address" | "domain") =>
|
|
356
|
+
field.onChange(value)
|
|
357
|
+
}
|
|
354
358
|
>
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
359
|
+
{(
|
|
360
|
+
[
|
|
361
|
+
["address", message.fromAddress, "Only this address"],
|
|
362
|
+
["domain", `@${domain}`, "Everyone at this domain"],
|
|
363
|
+
] as const
|
|
364
|
+
).map(([value, label, hint]) => (
|
|
365
|
+
<RadioCard
|
|
366
|
+
key={value}
|
|
367
|
+
value={value}
|
|
368
|
+
disabled={value === "domain" && ownDomain}
|
|
369
|
+
className="items-center rounded-md px-3 py-2 data-disabled:opacity-50 *:data-[slot=radio-card-indicator]:mt-0"
|
|
370
|
+
>
|
|
371
|
+
<span className="min-w-0">
|
|
372
|
+
<span className="block truncate text-[13px] font-medium">
|
|
373
|
+
{label}
|
|
374
|
+
</span>
|
|
375
|
+
<span className="text-muted-foreground block text-xs">
|
|
376
|
+
{hint}
|
|
377
|
+
</span>
|
|
378
|
+
</span>
|
|
379
|
+
</RadioCard>
|
|
380
|
+
))}
|
|
381
|
+
</RadioGroup>
|
|
382
|
+
)}
|
|
383
|
+
/>
|
|
384
|
+
<Controller
|
|
385
|
+
control={control}
|
|
386
|
+
name="moveExisting"
|
|
387
|
+
render={({ field }) => (
|
|
388
|
+
<CheckRow checked={field.value} onChange={field.onChange}>
|
|
389
|
+
Also move existing conversations to Spam
|
|
390
|
+
</CheckRow>
|
|
391
|
+
)}
|
|
392
|
+
/>
|
|
369
393
|
<AlertDialogFooter>
|
|
370
394
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
371
395
|
<AlertDialogAction
|
|
372
396
|
type="button"
|
|
373
397
|
variant="destructive"
|
|
374
398
|
disabled={block.isPending}
|
|
375
|
-
onClick={confirm}
|
|
399
|
+
onClick={(event) => void confirm(event)}
|
|
376
400
|
>
|
|
377
401
|
{block.isPending && <LoaderCircle className="animate-spin" />}
|
|
378
402
|
Block
|