@wtfalch/email 0.6.1 → 0.8.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/dist/mailbox/attach.d.ts +20 -0
- package/dist/mailbox/attach.js +24 -0
- package/dist/mailbox/client.d.ts +11 -2
- package/dist/mailbox/client.js +39 -3
- package/dist/mailbox/drafts.js +1 -0
- package/dist/mailbox/fake/mailbox.d.ts +9 -0
- package/dist/mailbox/fake/mailbox.js +70 -28
- package/dist/mailbox/fake/sample.js +21 -4
- package/dist/mailbox/index.d.ts +1 -0
- package/dist/mailbox/index.js +1 -0
- package/dist/mailbox/mail.css +63 -0
- package/dist/mailbox/react/Composer.d.ts +33 -2
- package/dist/mailbox/react/Composer.js +165 -6
- package/dist/mailbox/react/HtmlBody.d.ts +63 -0
- package/dist/mailbox/react/HtmlBody.js +168 -0
- package/dist/mailbox/react/Mail.js +46 -2
- package/dist/mailbox/react/ThreadView.d.ts +16 -8
- package/dist/mailbox/react/ThreadView.js +7 -17
- package/dist/mailbox/react/index.d.ts +3 -1
- package/dist/mailbox/react/index.js +1 -0
- package/dist/mailbox/react/sanitise.d.ts +73 -0
- package/dist/mailbox/react/sanitise.js +529 -0
- package/dist/mailbox/thread.js +16 -3
- package/dist/mailbox/types.d.ts +11 -0
- package/dist/postmaster/apply.d.ts +5 -4
- package/dist/postmaster/apply.js +27 -12
- package/dist/postmaster/audit.d.ts +56 -0
- package/dist/postmaster/audit.js +13 -0
- package/dist/postmaster/index.d.ts +1 -0
- package/dist/postmaster/index.js +1 -0
- package/package.json +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Button, Empty, Icon, Identity, Menu, ScrollArea, Skeleton } from '@wtfalch/design';
|
|
3
3
|
import { useEffect, useState } from 'react';
|
|
4
|
-
|
|
4
|
+
import { HtmlBody } from "./HtmlBody.js";
|
|
5
|
+
export function ThreadView({ thread, loading = false, onReply, onForward, onArchive, onTrash, onMarkUnread, onFlag, flagged = false, busy = false, onDownload, downloading, fetchInline, onBack, className, }) {
|
|
5
6
|
if (loading && !thread) {
|
|
6
7
|
return (_jsxs("div", { className: `thread${className ? ` ${className}` : ''}`, "aria-busy": "true", children: [_jsxs("header", { className: "thread-head", children: [_jsx(Skeleton, { width: "52%", height: 5 }), _jsx(Skeleton, { width: "28%", height: 2.5 })] }), _jsx("div", { className: "thread-body", children: _jsxs("div", { className: "message open", children: [_jsxs("div", { className: "message-head", children: [_jsx(Skeleton, { variant: "circular", width: "2rem", height: 8 }), _jsx(Skeleton, { width: "30%", height: 3 })] }), _jsx("div", { className: "message-body", children: _jsx(Skeleton, { lines: 6, height: 2.5 }) })] }) })] }));
|
|
7
8
|
}
|
|
@@ -13,7 +14,7 @@ export function ThreadView({ thread, loading = false, onReply, onForward, onArch
|
|
|
13
14
|
const people = [
|
|
14
15
|
...new Map(thread.messages.flatMap((message) => message.from.map((who) => [who.email, who.name?.trim() || who.email]))).values(),
|
|
15
16
|
];
|
|
16
|
-
return (_jsxs("div", { className: `thread${className ? ` ${className}` : ''}`, children: [_jsxs("header", { className: "thread-head", children: [_jsxs("div", { className: "thread-headline", children: [onBack && (_jsx(Button, { kind: "ghost", iconOnly: true, onClick: onBack, "aria-label": "Back to the list", children: _jsx(Icon, { name: "back" }) })), _jsxs("div", { className: "thread-heading", children: [_jsx("h2", { className: "thread-title", children: thread.subject || '(no subject)' }), _jsxs("p", { className: "thread-meta", children: [people.join(', '), _jsx("span", { className: "thread-meta-sep", children: "\u00B7" }), thread.messages.length === 1 ? '1 message' : `${thread.messages.length} messages`] })] })] }), _jsx(Toolbar, { message: newest, onReply: onReply, onForward: onForward, onArchive: onArchive, onTrash: onTrash, onMarkUnread: onMarkUnread, onFlag: onFlag, flagged: flagged, busy: busy })] }), _jsxs(ScrollArea, { className: "thread-body", label: "Messages in this conversation", children: [_jsx("ol", { className: "messages", children: thread.messages.map((message, index) => (_jsx("li", { children: _jsx(MessageCard, { message: message, defaultOpen: index === last, onReply: onReply, onForward: onForward, onDownload: onDownload, downloading: downloading }) }, message.id))) }), onReply && newest && (_jsxs("div", { className: "thread-foot", children: [_jsxs(Button, { kind: "primary", onClick: () => onReply(newest, false), disabled: busy, children: [_jsx(Icon, { name: "reply" }), " Reply"] }), _jsx(Button, { kind: "ghost", onClick: () => onReply(newest, true), disabled: busy, children: "Reply all" }), onForward && (_jsx(Button, { kind: "ghost", onClick: () => onForward(newest), disabled: busy, children: "Forward" }))] }))] })] }));
|
|
17
|
+
return (_jsxs("div", { className: `thread${className ? ` ${className}` : ''}`, children: [_jsxs("header", { className: "thread-head", children: [_jsxs("div", { className: "thread-headline", children: [onBack && (_jsx(Button, { kind: "ghost", iconOnly: true, onClick: onBack, "aria-label": "Back to the list", children: _jsx(Icon, { name: "back" }) })), _jsxs("div", { className: "thread-heading", children: [_jsx("h2", { className: "thread-title", children: thread.subject || '(no subject)' }), _jsxs("p", { className: "thread-meta", children: [people.join(', '), _jsx("span", { className: "thread-meta-sep", children: "\u00B7" }), thread.messages.length === 1 ? '1 message' : `${thread.messages.length} messages`] })] })] }), _jsx(Toolbar, { message: newest, onReply: onReply, onForward: onForward, onArchive: onArchive, onTrash: onTrash, onMarkUnread: onMarkUnread, onFlag: onFlag, flagged: flagged, busy: busy })] }), _jsxs(ScrollArea, { className: "thread-body", label: "Messages in this conversation", children: [_jsx("ol", { className: "messages", children: thread.messages.map((message, index) => (_jsx("li", { children: _jsx(MessageCard, { message: message, defaultOpen: index === last, onReply: onReply, onForward: onForward, onDownload: onDownload, downloading: downloading, fetchInline: fetchInline }) }, message.id))) }), onReply && newest && (_jsxs("div", { className: "thread-foot", children: [_jsxs(Button, { kind: "primary", onClick: () => onReply(newest, false), disabled: busy, children: [_jsx(Icon, { name: "reply" }), " Reply"] }), _jsx(Button, { kind: "ghost", onClick: () => onReply(newest, true), disabled: busy, children: "Reply all" }), onForward && (_jsx(Button, { kind: "ghost", onClick: () => onForward(newest), disabled: busy, children: "Forward" }))] }))] })] }));
|
|
17
18
|
}
|
|
18
19
|
/** A hover hint on a control that has only a glyph. `aria-hidden` on the
|
|
19
20
|
* wrapper is wrong -- the button inside it has to stay in the tree -- so
|
|
@@ -74,8 +75,9 @@ function Toolbar({ message, onReply, onForward, onArchive, onTrash, onMarkUnread
|
|
|
74
75
|
];
|
|
75
76
|
return (_jsxs("div", { className: "thread-tools", children: [onReply && (_jsx(Hint, { says: "Reply \u2014 R", children: _jsx(Button, { kind: "ghost", iconOnly: true, disabled: busy, onClick: () => onReply(message, false), "aria-label": "Reply", children: _jsx(Icon, { name: "reply" }) }) })), onForward && (_jsx(Hint, { says: "Forward \u2014 F", children: _jsx(Button, { kind: "ghost", iconOnly: true, disabled: busy, onClick: () => onForward?.(message), "aria-label": "Forward", children: _jsx(Icon, { name: "forward" }) }) })), _jsx("span", { className: "thread-tools-rule", "aria-hidden": "true" }), onFlag && (_jsx(Hint, { says: flagged ? 'Unflag — S' : 'Flag — S', children: _jsx(Button, { kind: "ghost", iconOnly: true, disabled: busy, onClick: () => onFlag(!flagged), "aria-pressed": flagged, "aria-label": flagged ? 'Unflag' : 'Flag', className: flagged ? 'is-flagged' : undefined, children: _jsx(Icon, { name: flagged ? 'star-filled' : 'star' }) }) })), onArchive && (_jsx(Hint, { says: "Archive \u2014 E", children: _jsx(Button, { kind: "ghost", iconOnly: true, disabled: busy, onClick: onArchive, "aria-label": "Archive", children: _jsx(Icon, { name: "folder" }) }) })), onTrash && (_jsx(Hint, { says: "Delete \u2014 #", children: _jsx(Button, { kind: "ghost", iconOnly: true, disabled: busy, onClick: onTrash, "aria-label": "Delete", children: _jsx(Icon, { name: "trash" }) }) })), overflow.length > 0 && (_jsx(Menu, { label: "More actions", placement: "bottom end", trigger: _jsx(Button, { kind: "ghost", iconOnly: true, disabled: busy, "aria-label": "More actions", children: _jsx(Icon, { name: "more" }) }), items: overflow }))] }));
|
|
76
77
|
}
|
|
77
|
-
function MessageCard({ message, defaultOpen, onReply, onForward, onDownload, downloading, }) {
|
|
78
|
+
function MessageCard({ message, defaultOpen, onReply, onForward, onDownload, downloading, fetchInline, }) {
|
|
78
79
|
const [open, setOpen] = useState(defaultOpen);
|
|
80
|
+
const [formatted, setFormatted] = useState(false);
|
|
79
81
|
/* The newest message changes when a reply arrives, and the card that was
|
|
80
82
|
newest should not stay open while the new one opens under it. */
|
|
81
83
|
useEffect(() => setOpen(defaultOpen), [defaultOpen]);
|
|
@@ -113,11 +115,11 @@ function MessageCard({ message, defaultOpen, onReply, onForward, onDownload, dow
|
|
|
113
115
|
},
|
|
114
116
|
]
|
|
115
117
|
: []),
|
|
116
|
-
] }))] }), open && (_jsxs("div", { className: "message-body", children: [_jsx(Recipients, { message: message }), message.text !== null ? (
|
|
118
|
+
] }))] }), open && (_jsxs("div", { className: "message-body", children: [_jsx(Recipients, { message: message }), message.html !== null && (message.text === null || formatted) ? (_jsx(HtmlBody, { html: message.html, attachments: message.attachments, fetchInline: fetchInline })) : message.text !== null ? (
|
|
117
119
|
/* `pre-wrap`, not a paragraph split: plain-text mail is laid out
|
|
118
120
|
with its own line breaks and its own quote markers, and
|
|
119
121
|
reflowing it destroys both. */
|
|
120
|
-
_jsx("pre", { className: "message-text", children: message.text })) :
|
|
122
|
+
_jsx("pre", { className: "message-text", children: message.text })) : (_jsx("p", { className: "message-quiet", children: "This message has no body." })), message.html !== null && message.text !== null && (_jsx(Button, { kind: "ghost", size: "sm", onClick: () => setFormatted((was) => !was), children: formatted ? 'Show the plain text' : 'Show it formatted' })), message.isTruncated && (_jsx("p", { className: "message-quiet", children: "This message was cut short at half a megabyte. The rest has not been fetched." })), message.attachments.length > 0 && (_jsx("ul", { className: "attachments", children: message.attachments
|
|
121
123
|
.filter((file) => file.disposition !== 'inline')
|
|
122
124
|
.map((file) => {
|
|
123
125
|
const busy = downloading?.has(file.blobId) ?? false;
|
|
@@ -128,18 +130,6 @@ function Recipients({ message }) {
|
|
|
128
130
|
const line = (label, people) => people.length === 0 ? null : (_jsxs("p", { className: "message-line", children: [_jsx("span", { className: "message-line-label", children: label }), _jsx("span", { children: people.map((p) => p.name?.trim() || p.email).join(', ') })] }));
|
|
129
131
|
return (_jsxs("div", { className: "message-lines", children: [line('To', message.to), line('Cc', message.cc)] }));
|
|
130
132
|
}
|
|
131
|
-
/**
|
|
132
|
-
* A message with only an HTML body.
|
|
133
|
-
*
|
|
134
|
-
* Not rendered, and the reason is said out loud rather than left as a blank
|
|
135
|
-
* pane: injecting a stranger's markup into the client's own document is the
|
|
136
|
-
* bug this refuses to ship. The source is offered because a person who wants
|
|
137
|
-
* it should not have to leave to get it.
|
|
138
|
-
*/
|
|
139
|
-
function HtmlNotice({ html }) {
|
|
140
|
-
const [shown, setShown] = useState(false);
|
|
141
|
-
return (_jsxs("div", { className: "message-html", children: [_jsx("p", { className: "message-quiet", children: "This message has an HTML body and no plain-text one. It is not rendered here: a mail client that puts a stranger's markup into its own page is one script tag from being read by them." }), _jsx(Button, { kind: "ghost", size: "sm", onClick: () => setShown((was) => !was), children: shown ? 'Hide the source' : 'Show the source' }), shown && _jsx("pre", { className: "message-source", children: html })] }));
|
|
142
|
-
}
|
|
143
133
|
/** Bytes, the way a mail client says them. */
|
|
144
134
|
export function bytes(size) {
|
|
145
135
|
if (size < 1024)
|
|
@@ -18,8 +18,10 @@ export { ThreadList, dayGroup, shortTime } from './ThreadList.tsx';
|
|
|
18
18
|
export type { ThreadListProps } from './ThreadList.tsx';
|
|
19
19
|
export { ThreadView, bytes } from './ThreadView.tsx';
|
|
20
20
|
export type { ThreadActions, ThreadViewProps } from './ThreadView.tsx';
|
|
21
|
+
export { HtmlBody } from './HtmlBody.tsx';
|
|
22
|
+
export type { HtmlBodyProps } from './HtmlBody.tsx';
|
|
21
23
|
export { Composer, parseAddresses } from './Composer.tsx';
|
|
22
|
-
export type { ComposerProps } from './Composer.tsx';
|
|
24
|
+
export type { AttachmentLimits, ComposerProps } from './Composer.tsx';
|
|
23
25
|
export { Mail } from './Mail.tsx';
|
|
24
26
|
export type { MailLocation, MailProps } from './Mail.tsx';
|
|
25
27
|
export { usePanes } from './layout.ts';
|
|
@@ -14,6 +14,7 @@ export { useIdentities, useMailboxes, usePush, useThread, useThreads, } from "./
|
|
|
14
14
|
export { MailboxTree, flatMailboxes, orderForReading } from "./MailboxTree.js";
|
|
15
15
|
export { ThreadList, dayGroup, shortTime } from "./ThreadList.js";
|
|
16
16
|
export { ThreadView, bytes } from "./ThreadView.js";
|
|
17
|
+
export { HtmlBody } from "./HtmlBody.js";
|
|
17
18
|
export { Composer, parseAddresses } from "./Composer.js";
|
|
18
19
|
export { Mail } from "./Mail.js";
|
|
19
20
|
export { usePanes } from "./layout.js";
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A stranger's HTML, made fit to draw.
|
|
3
|
+
*
|
|
4
|
+
* **This is the third wall, not the only one.** The body is drawn in a frame
|
|
5
|
+
* with no `allow-scripts`, under a content policy of its own that forbids
|
|
6
|
+
* scripts, frames, forms, fonts and every fetch but the images the reader
|
|
7
|
+
* allowed. Each of those holds if this file has a bug. What this adds is what
|
|
8
|
+
* neither can do: taking out the things that misbehave in a frame that
|
|
9
|
+
* cannot run code. A `<meta http-equiv="refresh">` navigates it; a `<base>`
|
|
10
|
+
* repoints every link in it; a `ping` reports a click; a relative `src`
|
|
11
|
+
* resolves against the application's own origin and fetches from it with the
|
|
12
|
+
* reader's cookies.
|
|
13
|
+
*
|
|
14
|
+
* **An allowlist, walked over an inert document.** `DOMParser` builds a
|
|
15
|
+
* document with no browsing context, so nothing in it loads and nothing in it
|
|
16
|
+
* runs while it is being cleaned. Elements not on the list are unwrapped, so
|
|
17
|
+
* their text survives; the few whose content is itself the problem — scripts,
|
|
18
|
+
* frames, plugins, forms' controls, SVG and MathML, and the raw-text elements
|
|
19
|
+
* that parse differently the second time — go whole. Attributes are kept by
|
|
20
|
+
* name, never removed by name, so an attribute the list has not heard of is
|
|
21
|
+
* gone rather than let through.
|
|
22
|
+
*
|
|
23
|
+
* **CSS is read by the browser, not by a regular expression.** `u\72l(` is a
|
|
24
|
+
* `url(`, and so is a dozen other spellings a pattern would miss. Declarations
|
|
25
|
+
* go through the CSSOM, which resolves the escapes, and one that fetches
|
|
26
|
+
* anything the reader has not allowed is dropped. A stylesheet is parsed with
|
|
27
|
+
* `CSSStyleSheet.replaceSync`, which refuses `@import` by itself; `@font-face`
|
|
28
|
+
* and every other at-rule but `@media` and `@supports` are dropped. Where the
|
|
29
|
+
* constructor does not exist the stylesheets are dropped rather than passed.
|
|
30
|
+
*
|
|
31
|
+
* **Why not DOMPurify.** It is the right tool for putting sanitised markup
|
|
32
|
+
* into a live document, where its mutation-XSS defences are the only thing
|
|
33
|
+
* between a parser quirk and script. Here the markup never reaches a document
|
|
34
|
+
* that can run script, the package keeps one runtime dependency on purpose,
|
|
35
|
+
* and what this needs that DOMPurify leaves to hooks — withholding remote
|
|
36
|
+
* images, counting them, resolving `cid:`, reading CSS — is most of the code
|
|
37
|
+
* either way.
|
|
38
|
+
*/
|
|
39
|
+
/** What may load. Everything else is withheld or dropped. */
|
|
40
|
+
export type ImagePolicy = {
|
|
41
|
+
/** Whether `http:` and `https:` images load. Off until the reader asks:
|
|
42
|
+
* a remote image is a request the sender sees, carrying when the message
|
|
43
|
+
* was opened and from where. */
|
|
44
|
+
remote: boolean;
|
|
45
|
+
/** Inline parts by Content-ID, as `data:` URLs the caller already
|
|
46
|
+
* fetched. A `cid:` reference with no entry here is dropped. */
|
|
47
|
+
inline?: ReadonlyMap<string, string>;
|
|
48
|
+
/** The page's own origin. An image on it, or on a sibling under the same
|
|
49
|
+
* parent domain, is refused even when remote images are allowed: the
|
|
50
|
+
* frame is same-origin with the page, so the request would be same-site,
|
|
51
|
+
* made by a stranger's markup, and carry the reader's cookies to this
|
|
52
|
+
* application or its neighbours — a GET somebody wrote as an action. */
|
|
53
|
+
origin?: string;
|
|
54
|
+
};
|
|
55
|
+
export type MailDocument = {
|
|
56
|
+
/** The whole document, for the frame's `srcdoc`. */
|
|
57
|
+
srcdoc: string;
|
|
58
|
+
/** Distinct remote addresses withheld — images, backgrounds, CSS — so the
|
|
59
|
+
* reader can be told there is something to show. Zero once allowed. */
|
|
60
|
+
blocked: number;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* The frame's own content policy, stated in full rather than left to
|
|
64
|
+
* `default-src`: `form-action` and `base-uri` do not fall back to it.
|
|
65
|
+
* Inline styles are allowed because mail is nothing but inline styles, and
|
|
66
|
+
* nothing else is.
|
|
67
|
+
*/
|
|
68
|
+
export declare function contentPolicy(remote: boolean): string;
|
|
69
|
+
/** A message's HTML body as a document for a sandboxed frame. Browser only:
|
|
70
|
+
* it needs `DOMParser`. */
|
|
71
|
+
export declare function mailDocument(html: string, policy: ImagePolicy): MailDocument;
|
|
72
|
+
/** Whether an inline part is a picture this will draw from a `data:` URL. */
|
|
73
|
+
export declare function isInlineImage(type: string): boolean;
|