@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
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MailClient } from './client.ts';
|
|
2
|
+
import type { DraftAttachment } from './types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* A file, uploaded and ready to go on a draft.
|
|
5
|
+
*
|
|
6
|
+
* `client.upload` gives back a blob id, a type and a size, and a draft needs
|
|
7
|
+
* a name too, which is the file's and which the upload never sees. This is
|
|
8
|
+
* the one line of glue between the two, here rather than in the composer so
|
|
9
|
+
* an application with its own layout does not write it again.
|
|
10
|
+
*
|
|
11
|
+
* **The type is the file's own, not a guess.** A browser fills `File.type`
|
|
12
|
+
* from the extension and leaves it empty for one it does not know; empty
|
|
13
|
+
* becomes `application/octet-stream`, which is what the sender's mail client
|
|
14
|
+
* would have said too, rather than a type invented from the name here.
|
|
15
|
+
*/
|
|
16
|
+
export declare function attach(client: MailClient, file: Blob & {
|
|
17
|
+
readonly name?: string;
|
|
18
|
+
}, options?: {
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
}): Promise<DraftAttachment>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A file, uploaded and ready to go on a draft.
|
|
3
|
+
*
|
|
4
|
+
* `client.upload` gives back a blob id, a type and a size, and a draft needs
|
|
5
|
+
* a name too, which is the file's and which the upload never sees. This is
|
|
6
|
+
* the one line of glue between the two, here rather than in the composer so
|
|
7
|
+
* an application with its own layout does not write it again.
|
|
8
|
+
*
|
|
9
|
+
* **The type is the file's own, not a guess.** A browser fills `File.type`
|
|
10
|
+
* from the extension and leaves it empty for one it does not know; empty
|
|
11
|
+
* becomes `application/octet-stream`, which is what the sender's mail client
|
|
12
|
+
* would have said too, rather than a type invented from the name here.
|
|
13
|
+
*/
|
|
14
|
+
export async function attach(client, file, options = {}) {
|
|
15
|
+
const declared = file.type || 'application/octet-stream';
|
|
16
|
+
const blob = await client.upload(file, declared, options);
|
|
17
|
+
return {
|
|
18
|
+
blobId: blob.blobId,
|
|
19
|
+
name: file.name || 'attachment',
|
|
20
|
+
type: blob.type || declared,
|
|
21
|
+
disposition: 'attachment',
|
|
22
|
+
size: blob.size,
|
|
23
|
+
};
|
|
24
|
+
}
|
package/dist/mailbox/client.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ type SessionDocument = {
|
|
|
10
10
|
uploadUrl: string;
|
|
11
11
|
eventSourceUrl: string;
|
|
12
12
|
state: string;
|
|
13
|
+
capabilities?: Record<string, Record<string, unknown> | undefined>;
|
|
13
14
|
accounts: Record<string, {
|
|
14
15
|
name: string;
|
|
15
16
|
isReadOnly: boolean;
|
|
@@ -67,8 +68,16 @@ export declare class MailClient {
|
|
|
67
68
|
/** The `Authorization` header value every request carries, for a caller
|
|
68
69
|
* fetching a download URL itself. */
|
|
69
70
|
get authorization(): string;
|
|
70
|
-
/**
|
|
71
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Upload bytes and get back a blob id a draft can attach.
|
|
73
|
+
*
|
|
74
|
+
* **Too large is refused here, before the request.** The session says how
|
|
75
|
+
* much the server takes, and a 60 MB file sent to a 50 MB limit is 60 MB
|
|
76
|
+
* of somebody's upstream spent to be told no at the end of it.
|
|
77
|
+
*/
|
|
78
|
+
upload(body: Blob | ArrayBuffer | Uint8Array | string, type?: string, options?: {
|
|
79
|
+
signal?: AbortSignal;
|
|
80
|
+
}): Promise<{
|
|
72
81
|
blobId: string;
|
|
73
82
|
type: string;
|
|
74
83
|
size: number;
|
package/dist/mailbox/client.js
CHANGED
|
@@ -3,6 +3,24 @@ import { MailError, guard } from "./errors.js";
|
|
|
3
3
|
import { expandTemplate } from "./uri.js";
|
|
4
4
|
export const MAIL_CAPABILITY = 'urn:ietf:params:jmap:mail';
|
|
5
5
|
export const SUBMISSION_CAPABILITY = 'urn:ietf:params:jmap:submission';
|
|
6
|
+
/** A size limit, or `null` for anything that is not a usable one. */
|
|
7
|
+
function positive(value) {
|
|
8
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : null;
|
|
9
|
+
}
|
|
10
|
+
function maxSizeUpload(doc) {
|
|
11
|
+
return positive(doc.capabilities?.['urn:ietf:params:jmap:core']?.maxSizeUpload);
|
|
12
|
+
}
|
|
13
|
+
/** What an upload body weighs on the wire. A string goes as UTF-8. A `Blob`
|
|
14
|
+
* is recognised by its `size` rather than by `instanceof`, because a page
|
|
15
|
+
* can hold more than one realm's `Blob` and a `File` from any of them is
|
|
16
|
+
* still a file. */
|
|
17
|
+
function sizeOf(body) {
|
|
18
|
+
if (typeof body === 'string')
|
|
19
|
+
return new TextEncoder().encode(body).byteLength;
|
|
20
|
+
if ('size' in body && typeof body.size === 'number')
|
|
21
|
+
return body.size;
|
|
22
|
+
return body.byteLength;
|
|
23
|
+
}
|
|
6
24
|
function looksLikeSession(value) {
|
|
7
25
|
return (typeof value === 'object' &&
|
|
8
26
|
value !== null &&
|
|
@@ -162,6 +180,9 @@ export class MailClient {
|
|
|
162
180
|
accountName: account?.name ?? '',
|
|
163
181
|
isReadOnly: account?.isReadOnly ?? false,
|
|
164
182
|
maySubmit: Boolean(account?.accountCapabilities?.[SUBMISSION_CAPABILITY]),
|
|
183
|
+
maxSizeUpload: maxSizeUpload(doc),
|
|
184
|
+
maxSizeAttachmentsPerEmail: positive(account?.accountCapabilities?.[MAIL_CAPABILITY]
|
|
185
|
+
?.maxSizeAttachmentsPerEmail),
|
|
165
186
|
};
|
|
166
187
|
}
|
|
167
188
|
async accountId() {
|
|
@@ -185,13 +206,28 @@ export class MailClient {
|
|
|
185
206
|
get authorization() {
|
|
186
207
|
return this.#authorization;
|
|
187
208
|
}
|
|
188
|
-
/**
|
|
189
|
-
|
|
190
|
-
|
|
209
|
+
/**
|
|
210
|
+
* Upload bytes and get back a blob id a draft can attach.
|
|
211
|
+
*
|
|
212
|
+
* **Too large is refused here, before the request.** The session says how
|
|
213
|
+
* much the server takes, and a 60 MB file sent to a 50 MB limit is 60 MB
|
|
214
|
+
* of somebody's upstream spent to be told no at the end of it.
|
|
215
|
+
*/
|
|
216
|
+
async upload(body, type = 'application/octet-stream', options = {}) {
|
|
217
|
+
const { jam, doc, accountId } = await this.connect();
|
|
218
|
+
const max = maxSizeUpload(doc);
|
|
219
|
+
const size = sizeOf(body);
|
|
220
|
+
if (max !== null && size > max) {
|
|
221
|
+
throw new MailError(`the upload is ${size} bytes, over the server's limit of ${max}`, {
|
|
222
|
+
type: 'urn:ietf:params:jmap:error:limit',
|
|
223
|
+
operation: 'client.upload',
|
|
224
|
+
});
|
|
225
|
+
}
|
|
191
226
|
return guard('client.upload', async () => {
|
|
192
227
|
const result = await jam.uploadBlob(accountId, body, {
|
|
193
228
|
headers: { Authorization: this.#authorization, 'Content-Type': type },
|
|
194
229
|
...NO_BROWSER_CREDENTIALS,
|
|
230
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
195
231
|
});
|
|
196
232
|
return { blobId: result.blobId, type: result.type, size: result.size };
|
|
197
233
|
});
|
package/dist/mailbox/drafts.js
CHANGED
|
@@ -42,6 +42,8 @@ export type FakeOptions = {
|
|
|
42
42
|
now?: Date;
|
|
43
43
|
/** Milliseconds of delay on every request, for looking at a loading state. */
|
|
44
44
|
latency?: number;
|
|
45
|
+
/** The session's `maxSizeUpload`. Stalwart's own default when not given. */
|
|
46
|
+
maxSizeUpload?: number;
|
|
45
47
|
};
|
|
46
48
|
export declare class FakeMailbox {
|
|
47
49
|
#private;
|
|
@@ -52,6 +54,13 @@ export declare class FakeMailbox {
|
|
|
52
54
|
emailId: string;
|
|
53
55
|
identityId: string;
|
|
54
56
|
}[];
|
|
57
|
+
/** Every blob uploaded, for a test that asserts the bytes reached the
|
|
58
|
+
* server rather than only the composer. */
|
|
59
|
+
readonly uploads: {
|
|
60
|
+
blobId: string;
|
|
61
|
+
type: string;
|
|
62
|
+
size: number;
|
|
63
|
+
}[];
|
|
55
64
|
constructor(options?: FakeOptions);
|
|
56
65
|
/** Put a thread in the mailbox. Returns its id. */
|
|
57
66
|
add(seed: SeedThread): string;
|
|
@@ -23,20 +23,27 @@ const MAILBOXES = [
|
|
|
23
23
|
{ id: 'mb-junk', name: 'Junk Mail', role: 'junk' },
|
|
24
24
|
{ id: 'mb-trash', name: 'Deleted Items', role: 'trash' },
|
|
25
25
|
];
|
|
26
|
+
/** Stalwart's default for both limits, as `fixtures/instance-one.json` has it. */
|
|
27
|
+
const STALWART_MAX_SIZE = 50_000_000;
|
|
26
28
|
export class FakeMailbox {
|
|
27
29
|
me;
|
|
28
30
|
#now;
|
|
29
31
|
#latency;
|
|
32
|
+
#maxSizeUpload;
|
|
30
33
|
#emails = [];
|
|
31
34
|
#threads = new Map();
|
|
32
35
|
#counter = 0;
|
|
33
36
|
/** Everything `EmailSubmission/set` accepted, for a test that asserts a
|
|
34
37
|
* message was actually sent rather than only composed. */
|
|
35
38
|
submissions = [];
|
|
39
|
+
/** Every blob uploaded, for a test that asserts the bytes reached the
|
|
40
|
+
* server rather than only the composer. */
|
|
41
|
+
uploads = [];
|
|
36
42
|
constructor(options = {}) {
|
|
37
43
|
this.me = options.me ?? { name: 'Ada Lovelace', email: 'ada@example.com' };
|
|
38
44
|
this.#now = options.now ?? new Date('2026-09-07T12:00:00Z');
|
|
39
45
|
this.#latency = options.latency ?? 0;
|
|
46
|
+
this.#maxSizeUpload = options.maxSizeUpload ?? STALWART_MAX_SIZE;
|
|
40
47
|
for (const seed of options.threads ?? [])
|
|
41
48
|
this.add(seed);
|
|
42
49
|
}
|
|
@@ -57,6 +64,26 @@ export class FakeMailbox {
|
|
|
57
64
|
disposition: 'attachment',
|
|
58
65
|
cid: null,
|
|
59
66
|
}));
|
|
67
|
+
const textPart = {
|
|
68
|
+
partId: 't',
|
|
69
|
+
blobId: `blob-${id}-t`,
|
|
70
|
+
size: message.text.length,
|
|
71
|
+
name: null,
|
|
72
|
+
type: 'text/plain',
|
|
73
|
+
charset: 'UTF-8',
|
|
74
|
+
disposition: null,
|
|
75
|
+
cid: null,
|
|
76
|
+
};
|
|
77
|
+
const htmlPart = {
|
|
78
|
+
partId: 'h',
|
|
79
|
+
blobId: `blob-${id}-h`,
|
|
80
|
+
size: message.html?.length ?? 0,
|
|
81
|
+
name: null,
|
|
82
|
+
type: 'text/html',
|
|
83
|
+
charset: 'UTF-8',
|
|
84
|
+
disposition: null,
|
|
85
|
+
cid: null,
|
|
86
|
+
};
|
|
60
87
|
this.#emails.push({
|
|
61
88
|
id,
|
|
62
89
|
blobId: `blob-${id}`,
|
|
@@ -80,32 +107,12 @@ export class FakeMailbox {
|
|
|
80
107
|
subject: message.subject,
|
|
81
108
|
preview: message.text.slice(0, 80),
|
|
82
109
|
hasAttachment: attachments.length > 0,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
type: 'text/plain',
|
|
90
|
-
charset: 'UTF-8',
|
|
91
|
-
disposition: null,
|
|
92
|
-
cid: null,
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
htmlBody: message.html
|
|
96
|
-
? [
|
|
97
|
-
{
|
|
98
|
-
partId: 'h',
|
|
99
|
-
blobId: `blob-${id}-h`,
|
|
100
|
-
size: message.html.length,
|
|
101
|
-
name: null,
|
|
102
|
-
type: 'text/html',
|
|
103
|
-
charset: 'UTF-8',
|
|
104
|
-
disposition: null,
|
|
105
|
-
cid: null,
|
|
106
|
-
},
|
|
107
|
-
]
|
|
108
|
-
: [],
|
|
110
|
+
/* Each list falls back to the other's part, as RFC 8621 §4.1.4 has a
|
|
111
|
+
server do: an HTML-only message lists its HTML in `textBody` too,
|
|
112
|
+
and a plain one its text in `htmlBody`. A fake that kept them apart
|
|
113
|
+
would let a client that confuses the two pass every test. */
|
|
114
|
+
textBody: [message.text || !message.html ? textPart : htmlPart],
|
|
115
|
+
htmlBody: [message.html ? htmlPart : textPart],
|
|
109
116
|
attachments,
|
|
110
117
|
bodyValues: {
|
|
111
118
|
t: { value: message.text, isEncodingProblem: false, isTruncated: false },
|
|
@@ -144,7 +151,7 @@ export class FakeMailbox {
|
|
|
144
151
|
session(origin = 'https://email.example.com') {
|
|
145
152
|
return {
|
|
146
153
|
capabilities: {
|
|
147
|
-
'urn:ietf:params:jmap:core': {},
|
|
154
|
+
'urn:ietf:params:jmap:core': { maxSizeUpload: this.#maxSizeUpload },
|
|
148
155
|
'urn:ietf:params:jmap:mail': {},
|
|
149
156
|
'urn:ietf:params:jmap:submission': {},
|
|
150
157
|
},
|
|
@@ -154,7 +161,7 @@ export class FakeMailbox {
|
|
|
154
161
|
isPersonal: true,
|
|
155
162
|
isReadOnly: false,
|
|
156
163
|
accountCapabilities: {
|
|
157
|
-
'urn:ietf:params:jmap:mail': {},
|
|
164
|
+
'urn:ietf:params:jmap:mail': { maxSizeAttachmentsPerEmail: STALWART_MAX_SIZE },
|
|
158
165
|
'urn:ietf:params:jmap:submission': {},
|
|
159
166
|
},
|
|
160
167
|
},
|
|
@@ -406,6 +413,26 @@ export class FakeMailbox {
|
|
|
406
413
|
}
|
|
407
414
|
return json(this.session(new URL(url).origin));
|
|
408
415
|
}
|
|
416
|
+
/* An upload is the one POST that is not a JMAP request: raw bytes in,
|
|
417
|
+
RFC 8620 §6.1's `{accountId, blobId, type, size}` out. The size is
|
|
418
|
+
measured, not taken from a header, which is what a server does. An
|
|
419
|
+
aborted request never gets here in a browser; here it has to be
|
|
420
|
+
checked, or a test that cancels an upload would see it land. */
|
|
421
|
+
if (url.includes('/jmap/upload/')) {
|
|
422
|
+
init.signal?.throwIfAborted();
|
|
423
|
+
const size = await measure(init.body);
|
|
424
|
+
if (size > this.#maxSizeUpload) {
|
|
425
|
+
return new Response(JSON.stringify({
|
|
426
|
+
type: 'urn:ietf:params:jmap:error:limit',
|
|
427
|
+
limit: 'maxSizeUpload',
|
|
428
|
+
status: 413,
|
|
429
|
+
}), { status: 413, headers: { 'Content-Type': 'application/problem+json' } });
|
|
430
|
+
}
|
|
431
|
+
const type = new Headers(init.headers).get('Content-Type') ?? 'application/octet-stream';
|
|
432
|
+
const blob = { blobId: `upload-${this.uploads.length + 1}`, type, size };
|
|
433
|
+
this.uploads.push(blob);
|
|
434
|
+
return json({ accountId: ACCOUNT, ...blob });
|
|
435
|
+
}
|
|
409
436
|
const body = JSON.parse(String(init.body));
|
|
410
437
|
const responses = [];
|
|
411
438
|
for (const [method, args, id] of body.methodCalls) {
|
|
@@ -431,6 +458,21 @@ export class FakeMailbox {
|
|
|
431
458
|
return out;
|
|
432
459
|
}
|
|
433
460
|
}
|
|
461
|
+
/** How many bytes an upload body carries, whatever shape `fetch` was given it
|
|
462
|
+
* in. A `File` from a test's DOM is recognised by its `size`, since it is
|
|
463
|
+
* not this realm's `Blob`. */
|
|
464
|
+
async function measure(body) {
|
|
465
|
+
if (body === null || body === undefined)
|
|
466
|
+
return 0;
|
|
467
|
+
if (typeof body === 'string')
|
|
468
|
+
return new TextEncoder().encode(body).byteLength;
|
|
469
|
+
if (typeof body === 'object' && 'size' in body && typeof body.size === 'number') {
|
|
470
|
+
return body.size;
|
|
471
|
+
}
|
|
472
|
+
if (body instanceof ArrayBuffer || ArrayBuffer.isView(body))
|
|
473
|
+
return body.byteLength;
|
|
474
|
+
return (await new Response(body).arrayBuffer()).byteLength;
|
|
475
|
+
}
|
|
434
476
|
/** RFC 6901 §3 in reverse: one patch-key segment, unescaped. A mailbox id is
|
|
435
477
|
* the server's to choose, so a key built from one may carry `~0` or `~1`. */
|
|
436
478
|
function unpointer(segment) {
|
|
@@ -163,9 +163,11 @@ export const SAMPLE = [
|
|
|
163
163
|
},
|
|
164
164
|
],
|
|
165
165
|
},
|
|
166
|
-
/* Only an HTML body,
|
|
167
|
-
|
|
168
|
-
|
|
166
|
+
/* Only an HTML body, drawn in the sandboxed frame. It carries what a real
|
|
167
|
+
newsletter does -- a stylesheet, a table layout, a header image, a
|
|
168
|
+
tracking pixel, and a script that must not run -- so the frame, the
|
|
169
|
+
withheld-images bar and the sanitiser are all reachable from the list
|
|
170
|
+
rather than only from a unit test. */
|
|
169
171
|
{
|
|
170
172
|
mailbox: 'mb-inbox',
|
|
171
173
|
messages: [
|
|
@@ -173,7 +175,22 @@ export const SAMPLE = [
|
|
|
173
175
|
from: { email: 'campaigns@marketing.example.com' },
|
|
174
176
|
subject: 'Your weekly digest, beautifully formatted',
|
|
175
177
|
text: '',
|
|
176
|
-
html:
|
|
178
|
+
html: [
|
|
179
|
+
'<html><head><style>',
|
|
180
|
+
'.card{max-width:560px;margin:0 auto;background:#fff;border-radius:8px;padding:24px}',
|
|
181
|
+
'h1{font-family:Georgia,serif;color:#2b2118} .more{color:#8a5a00}',
|
|
182
|
+
'</style></head>',
|
|
183
|
+
'<body style="background:#f4f1ea;padding:16px" onload="alert(1)">',
|
|
184
|
+
'<table role="presentation" width="100%"><tr><td>',
|
|
185
|
+
'<div class="card">',
|
|
186
|
+
'<img src="https://images.marketing.example.com/header.png" width="512" height="96" alt="The week, in pictures">',
|
|
187
|
+
'<h1>This week</h1>',
|
|
188
|
+
'<p>Three essays on the Analytical Engine, and a letter from the mill.</p>',
|
|
189
|
+
'<p><a class="more" href="https://marketing.example.com/digest">Read it on the web</a></p>',
|
|
190
|
+
'<script>document.title = "ran"</script>',
|
|
191
|
+
'<img src="https://t.marketing.example.com/open.gif" width="1" height="1" alt="">',
|
|
192
|
+
'</div></td></tr></table></body></html>',
|
|
193
|
+
].join(''),
|
|
177
194
|
agoMinutes: 30 * HOUR,
|
|
178
195
|
},
|
|
179
196
|
],
|
package/dist/mailbox/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export { attribution, formatAddress, forwardDraft, forwardIntroduction, forwardS
|
|
|
21
21
|
export type { ForwardOptions, ReplyOptions } from './drafts.ts';
|
|
22
22
|
export { draftToEmail, send, sentPatch } from './submit.ts';
|
|
23
23
|
export type { SendOptions } from './submit.ts';
|
|
24
|
+
export { attach } from './attach.ts';
|
|
24
25
|
export { moveThread, moveToRole, removeFromMailbox, setFlagged, setRead, } from './mutate.ts';
|
|
25
26
|
export type { MoveOptions } from './mutate.ts';
|
|
26
27
|
export { DEFAULT_MAX_DOWNLOAD_BYTES, downloadAttachment } from './download.ts';
|
package/dist/mailbox/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export { search } from "./search.js";
|
|
|
13
13
|
export { identities } from "./identities.js";
|
|
14
14
|
export { attribution, formatAddress, forwardDraft, forwardIntroduction, forwardSubject, quoteText, replyDraft, replySubject, } from "./drafts.js";
|
|
15
15
|
export { draftToEmail, send, sentPatch } from "./submit.js";
|
|
16
|
+
export { attach } from "./attach.js";
|
|
16
17
|
export { moveThread, moveToRole, removeFromMailbox, setFlagged, setRead, } from "./mutate.js";
|
|
17
18
|
export { DEFAULT_MAX_DOWNLOAD_BYTES, downloadAttachment } from "./download.js";
|
|
18
19
|
export { push } from "./push.js";
|
package/dist/mailbox/mail.css
CHANGED
|
@@ -882,6 +882,31 @@
|
|
|
882
882
|
justify-items: start;
|
|
883
883
|
}
|
|
884
884
|
|
|
885
|
+
/* The frame's document paints its own white paper -- mail is written for
|
|
886
|
+
it, in either theme -- so the frame declares itself light too. A frame
|
|
887
|
+
whose scheme differs from its document's gets an opaque backdrop from the
|
|
888
|
+
browser, which in the dark theme is a black band under a white page. It
|
|
889
|
+
starts at a line's height and `HtmlBody` sets the rest from the document. */
|
|
890
|
+
.message-frame {
|
|
891
|
+
display: block;
|
|
892
|
+
justify-self: stretch;
|
|
893
|
+
width: 100%;
|
|
894
|
+
min-height: var(--space-6);
|
|
895
|
+
border: var(--border-width) solid var(--border);
|
|
896
|
+
border-radius: var(--radius);
|
|
897
|
+
color-scheme: light;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
.message-images {
|
|
901
|
+
display: flex;
|
|
902
|
+
flex-wrap: wrap;
|
|
903
|
+
align-items: center;
|
|
904
|
+
gap: var(--space-2);
|
|
905
|
+
margin: 0;
|
|
906
|
+
color: var(--muted);
|
|
907
|
+
font-size: var(--text-xs);
|
|
908
|
+
}
|
|
909
|
+
|
|
885
910
|
.attachments {
|
|
886
911
|
list-style: none;
|
|
887
912
|
display: flex;
|
|
@@ -939,6 +964,15 @@
|
|
|
939
964
|
.composer {
|
|
940
965
|
display: grid;
|
|
941
966
|
gap: var(--space-3);
|
|
967
|
+
border-radius: var(--radius);
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
/* Where a dragged file will land, said before it is let go. An outline rather
|
|
971
|
+
than a border, so the form does not shift under the pointer by the width
|
|
972
|
+
of one. */
|
|
973
|
+
.composer.is-dropping {
|
|
974
|
+
outline: 2px dashed var(--accent);
|
|
975
|
+
outline-offset: var(--space-1);
|
|
942
976
|
}
|
|
943
977
|
|
|
944
978
|
.composer-addresses {
|
|
@@ -981,11 +1015,40 @@
|
|
|
981
1015
|
|
|
982
1016
|
.composer-files li {
|
|
983
1017
|
display: flex;
|
|
1018
|
+
flex-wrap: wrap;
|
|
984
1019
|
align-items: center;
|
|
985
1020
|
gap: var(--space-2);
|
|
986
1021
|
}
|
|
987
1022
|
|
|
1023
|
+
.composer-file-icon {
|
|
1024
|
+
flex: none;
|
|
1025
|
+
color: var(--muted);
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
.composer-files li.is-stuck .composer-file-icon {
|
|
1029
|
+
color: var(--bad);
|
|
1030
|
+
}
|
|
1031
|
+
|
|
988
1032
|
.composer-file {
|
|
1033
|
+
min-width: 0;
|
|
1034
|
+
overflow: hidden;
|
|
1035
|
+
text-overflow: ellipsis;
|
|
1036
|
+
white-space: nowrap;
|
|
1037
|
+
font-size: var(--text-xs);
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
.composer-file-size {
|
|
1041
|
+
color: var(--muted);
|
|
1042
|
+
font-size: var(--text-xs);
|
|
1043
|
+
font-variant-numeric: tabular-nums;
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
/* Its own line under the name, so a long reason does not push the buttons
|
|
1047
|
+
off the end of the row. */
|
|
1048
|
+
.composer-file-problem {
|
|
1049
|
+
flex-basis: 100%;
|
|
1050
|
+
margin: 0;
|
|
1051
|
+
color: var(--bad);
|
|
989
1052
|
font-size: var(--text-xs);
|
|
990
1053
|
}
|
|
991
1054
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Draft, EmailAddress, MailIdentity } from '../types.ts';
|
|
1
|
+
import type { Draft, DraftAttachment, EmailAddress, MailIdentity } from '../types.ts';
|
|
2
2
|
/**
|
|
3
3
|
* Writing one.
|
|
4
4
|
*
|
|
@@ -23,20 +23,51 @@ import type { Draft, EmailAddress, MailIdentity } from '../types.ts';
|
|
|
23
23
|
*
|
|
24
24
|
* The draft is the caller's state, so a reply arrives already filled in by
|
|
25
25
|
* `replyDraft` and this is only the surface that edits it.
|
|
26
|
+
*
|
|
27
|
+
* **A file is on the draft only once it has uploaded.** Until then it is this
|
|
28
|
+
* component's, shown with a spinner in the same list, and Send waits: a draft
|
|
29
|
+
* that went while a file was still on its way would arrive without it, and
|
|
30
|
+
* nobody finds out until the reply asks where the attachment is. A file that
|
|
31
|
+
* failed, or that the server would refuse, stays in the list saying why, and
|
|
32
|
+
* Send waits for that too — a row the person has to remove is how the
|
|
33
|
+
* message they meant to send and the one that goes stay the same message.
|
|
34
|
+
*
|
|
35
|
+
* **Uploading needs a client and this has none**, so it takes `onAttach`, and
|
|
36
|
+
* without one there is no Attach button and nothing to drop onto. `Mail`
|
|
37
|
+
* supplies it from `attach`.
|
|
26
38
|
*/
|
|
39
|
+
/** What the server will take, from its session document. */
|
|
40
|
+
export type AttachmentLimits = {
|
|
41
|
+
/** The largest single file, in bytes (`maxSizeUpload`). */
|
|
42
|
+
file?: number;
|
|
43
|
+
/** The most one message's attachments may add up to (`maxSizeAttachmentsPerEmail`). */
|
|
44
|
+
message?: number;
|
|
45
|
+
};
|
|
27
46
|
export type ComposerProps = {
|
|
28
47
|
draft: Draft;
|
|
29
48
|
onChange: (draft: Draft) => void;
|
|
30
49
|
onSend: () => void | Promise<void>;
|
|
31
50
|
onCancel?: () => void;
|
|
32
51
|
identities: readonly MailIdentity[];
|
|
52
|
+
/** Upload a file and resolve with what the draft should carry. Aborted
|
|
53
|
+
* when the person removes the file or closes the composer. */
|
|
54
|
+
onAttach?: (file: File, signal: AbortSignal) => Promise<DraftAttachment>;
|
|
55
|
+
/** Checked before uploading, so an oversize file is refused in a sentence
|
|
56
|
+
* rather than after sending all of it. */
|
|
57
|
+
limits?: AttachmentLimits;
|
|
33
58
|
/** Set while a send is in flight, so the buttons cannot be pressed twice. */
|
|
34
59
|
sending?: boolean;
|
|
35
60
|
/** What went wrong with the last send. */
|
|
36
61
|
error?: string;
|
|
37
62
|
className?: string;
|
|
38
63
|
};
|
|
64
|
+
/**
|
|
65
|
+
* The sentence for a file the limits rule out, or `null` when it may go.
|
|
66
|
+
* `pending` is what the draft's attachments and the uploads already under
|
|
67
|
+
* way weigh, so two 30 MB files picked together are measured together.
|
|
68
|
+
*/
|
|
69
|
+
export declare function refusal(file: File, pending: number, limits?: AttachmentLimits): string | null;
|
|
39
70
|
/** Split what somebody typed into addresses. Commas and semicolons both
|
|
40
71
|
* separate, because both get typed and both get pasted. */
|
|
41
72
|
export declare function parseAddresses(text: string): EmailAddress[];
|
|
42
|
-
export declare function Composer({ draft, onChange, onSend, onCancel, identities, sending, error, className, }: ComposerProps): import("react").JSX.Element;
|
|
73
|
+
export declare function Composer({ draft, onChange, onSend, onCancel, identities, onAttach, limits, sending, error, className, }: ComposerProps): import("react").JSX.Element;
|