@wtfalch/email 0.13.1 → 0.14.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.
Files changed (42) hide show
  1. package/README.md +66 -4
  2. package/dist/mailbox/client.d.ts +22 -1
  3. package/dist/mailbox/client.js +45 -0
  4. package/dist/mailbox/fake/mailbox.js +205 -5
  5. package/dist/mailbox/index.d.ts +11 -7
  6. package/dist/mailbox/index.js +5 -3
  7. package/dist/mailbox/mail.css +13 -0
  8. package/dist/mailbox/mailboxes.d.ts +95 -1
  9. package/dist/mailbox/mailboxes.js +243 -1
  10. package/dist/mailbox/mutate.d.ts +21 -0
  11. package/dist/mailbox/mutate.js +71 -0
  12. package/dist/mailbox/quoted.d.ts +94 -0
  13. package/dist/mailbox/quoted.js +158 -0
  14. package/dist/mailbox/react/Composer.js +13 -1
  15. package/dist/mailbox/react/Mail.js +273 -33
  16. package/dist/mailbox/react/ThreadView.d.ts +13 -1
  17. package/dist/mailbox/react/ThreadView.js +5 -4
  18. package/dist/mailbox/react/index.d.ts +3 -1
  19. package/dist/mailbox/react/index.js +2 -1
  20. package/dist/mailbox/react/quotedHtml.d.ts +105 -0
  21. package/dist/mailbox/react/quotedHtml.js +163 -0
  22. package/dist/mailbox/snooze.d.ts +48 -0
  23. package/dist/mailbox/snooze.js +176 -0
  24. package/dist/mailbox/submit.d.ts +26 -0
  25. package/dist/mailbox/submit.js +88 -7
  26. package/dist/mailbox/threads.js +2 -0
  27. package/dist/mailbox/types.d.ts +40 -0
  28. package/dist/postmaster/apply.d.ts +154 -1
  29. package/dist/postmaster/apply.js +336 -1
  30. package/dist/postmaster/audit.d.ts +22 -1
  31. package/dist/postmaster/audit.js +7 -0
  32. package/dist/postmaster/client.d.ts +49 -0
  33. package/dist/postmaster/client.js +43 -0
  34. package/dist/postmaster/index.d.ts +4 -3
  35. package/dist/postmaster/index.js +3 -2
  36. package/dist/postmaster/objects.js +11 -0
  37. package/dist/postmaster/overview.d.ts +4 -0
  38. package/dist/postmaster/queue.d.ts +111 -0
  39. package/dist/postmaster/queue.js +64 -0
  40. package/dist/postmaster/writes.d.ts +59 -0
  41. package/dist/postmaster/writes.js +106 -0
  42. package/package.json +1 -1
package/README.md CHANGED
@@ -39,6 +39,26 @@ const tree = await mailboxes(client);
39
39
  const page = await listThreads(client, findRole(tree, 'inbox').id, { limit: 50 });
40
40
  ```
41
41
 
42
+ A login usually reaches more than one mailbox. `client.accounts()` lists them,
43
+ the person's own first: a shared mailbox such as `hr@` is an ordinary account
44
+ the server puts in the same session with `isPersonal: false`, because the
45
+ account is a member of it. A client stays on the account it was built with, so
46
+ opening another one is `new MailClient({ …, accountId })` with the id from that
47
+ list — which is what keeps one client's cached session honest.
48
+
49
+ **One folder can also be shared on its own**, finer than a whole account:
50
+ `shareMailbox(client, mailboxId, accountId, rights)` grants another account
51
+ some of RFC 8621 §2's ten rights (`mayReadItems`, `mayAddItems`, …) on that one
52
+ mailbox, and `unshareMailbox` takes them back. Both patch `Mailbox/set` at
53
+ `shareWith/<accountId>` rather than sending the whole `shareWith` map, so
54
+ granting or revoking one account's access never touches another's, and needs
55
+ no read first. `mailboxes()` returns each node's own `myRights` (what the
56
+ signed-in login may do there) and `shareWith` (who else can, and with what),
57
+ both always present, every right explicit — RFC 8621 requires `myRights`, and
58
+ the wire has been seen to fill in every unrequested right on `shareWith` as
59
+ `false` too, which `buildTree` also does for a caller-built value that leaves
60
+ some out.
61
+
42
62
  A page of threads is **one round trip**: the query, the newest message per
43
63
  thread, the threads' member ids and the members are four method calls chained
44
64
  by JMAP result reference in a single request.
@@ -55,7 +75,12 @@ regardless. `queued` lists everything still held, soonest first, for a
55
75
  rather than reading the field off an unfiltered one, since that filter is
56
76
  what makes the server recheck each submission against the mail queue and
57
77
  demote one that already went, instead of answering a stale `'pending'`. Every
58
- row it returns is safe to hand straight to `cancel`. `attach` uploads a file
78
+ row it returns is safe to hand straight to `cancel`. `saveDraft` stores a
79
+ draft in Drafts so it outlives the compose sheet, and given the id it returned
80
+ last time, replaces that draft instead of adding one (messages are immutable,
81
+ so the id changes each save). `send(…, { draftId })` sends and removes the
82
+ saved draft. Both refuse an id that is not a `$draft`, since replacing is a
83
+ destroy. `attach` uploads a file
59
84
  and gives back what a draft carries; the
60
85
  upload is refused before any of it is sent when the file is over the
61
86
  session's `maxSizeUpload`, which `client.session()` reports alongside
@@ -74,6 +99,18 @@ await setRead(client, threadId, true);
74
99
  await moveToRole(client, threadId, 'archive', { mailboxes: tree });
75
100
  ```
76
101
 
102
+ `setLabel` puts a label on a thread without moving it: the keyword
103
+ `$label:<name>`, lowercased, since keywords are case-insensitive. A name a
104
+ keyword cannot hold (a space, any of `(){]%*"\`) is refused, not rewritten.
105
+ `ThreadSummary.labels` carries the labels on any message in the thread.
106
+ `listLabels` reads the newest 500 messages (`scan` to change it), because
107
+ JMAP can search for a keyword but cannot list them.
108
+
109
+ `snoozeThread` moves a thread into a top-level Snoozed mailbox, made on first
110
+ use, and stamps it `$snoozed:<unix seconds>`. JMAP has no snooze, so nothing
111
+ brings it back on its own: the host runs `wakeSnoozed(client, now)` on a
112
+ timer, and each thread whose time has come goes back to the Inbox, unread.
113
+
77
114
  Note that a stock Stalwart account has **no Archive mailbox** — it creates
78
115
  Inbox, Drafts, Sent Items, Junk Mail and Deleted Items — so `moveToRole(…,
79
116
  'archive')` throws there rather than doing nothing, and a caller should offer
@@ -81,8 +118,8 @@ the action only where `findRole(tree, 'archive')` finds one.
81
118
 
82
119
  ### The React
83
120
 
84
- `@wtfalch/email/mailbox/react` draws it, on `@wtfalch/design` 0.5.0 or
85
- later. `Mail` is the whole client — mailboxes, list, message, composer,
121
+ `@wtfalch/email/mailbox/react` draws it, on `@wtfalch/design` >=0.16.0.
122
+ `Mail` is the whole client — mailboxes, list, message, composer,
86
123
  search, a toolbar, and a command palette on Cmd-K — and the only piece that
87
124
  holds state or fetches.
88
125
  `MailboxTree`, `ThreadList`, `ThreadView` and `Composer` take their data as
@@ -199,6 +236,17 @@ specifiers, which only compiles under `allowImportingTsExtensions`; nothing of
199
236
  it reaches this package's public types, so a consumer does not inherit the
200
237
  flag.
201
238
 
239
+ **Per-mailbox sharing is real, and it is the plain `Mailbox` object, not a
240
+ separate capability.** `shareWith`/`myRights` are confirmed on the schema at
241
+ `stalwartlabs/stalwart` tag `v0.16.20`
242
+ (`crates/jmap-proto/src/object/mailbox.rs:31-53`) and exercised end to end —
243
+ grant, partial patch, revoke, and the server's own fill-in of every
244
+ unrequested right as `false` on read-back — by the sibling `AddressBook`
245
+ object's ACL suite, `tests/src/jmap/contacts/acl.rs`, which shares the same
246
+ `shareWith`/`myRights` machinery. Not yet confirmed against a live instance
247
+ the way `instance-one.json`'s fixture is: nothing in this package wrote a
248
+ `shareWith` grant before now.
249
+
202
250
  ## @wtfalch/email/postmaster
203
251
 
204
252
  Administer a [Stalwart](https://stalw.art) mail server: its domain, its
@@ -307,6 +355,19 @@ not fail; it deletes somebody's alias, or every app password on their phone.
307
355
  `withAlias`, `withoutAlias` and `withoutAppPassword` exist so that arithmetic
308
356
  is decided by a unit test rather than at the end of a request.
309
357
 
358
+ **A shared mailbox is a `Group` account.** `hr@` that a team reads together is
359
+ an ordinary account whose `@type` is `Group`: same delivery, same aliases, no
360
+ password, because nobody ever signs in as it. Who reads it is written on the
361
+ *people* — an account's `memberGroupIds` names the groups it belongs to, and
362
+ the server turns each one into a second account on that person's own JMAP
363
+ session, which is how `/mailbox`'s `client.accounts()` sees it.
364
+ `createGroupMailbox` makes one, `addToGroup` and `removeFromGroup` say who
365
+ reads it, and `withMembership`/`withoutMembership` do the arithmetic. A
366
+ membership map is a set on the wire (`{"<id>": true}`) and is replaced whole,
367
+ exactly like a `List<T>`. `addToGroup` refuses a group id that turns out to be
368
+ a person's own mailbox: the server would store that happily and it would give
369
+ nobody access to anything.
370
+
310
371
  **There is no conditional write.** JMAP's answer to the above is `ifInState`,
311
372
  and these objects do not offer it: `x:Account/get` returns `accountId`,
312
373
  `list` and `notFound` with no state token, and `x:Account/set` rejects an
@@ -335,7 +396,8 @@ instead.
335
396
 
336
397
  ## The audit
337
398
 
338
- `createMailbox`, `addAlias`, `removeAlias`, `revokeAppPassword` and `enableHolding` take an
399
+ `createMailbox`, `createGroupMailbox`, `addToGroup`, `removeFromGroup`, `addAlias`, `removeAlias`,
400
+ `revokeAppPassword`, `enableHolding`, `retryQueuedMessage` and `purgeQueuedMessage` take an
339
401
  optional last argument, a `PostmasterAudit`: a `write` the host bound to its
340
402
  own ledger, the principal it resolved for this request, and the request id
341
403
  its log uses. Without one, nothing changes.
@@ -1,5 +1,5 @@
1
1
  import { JamClient } from 'jmap-jam';
2
- import type { MailSession } from './types.ts';
2
+ import type { MailAccount, MailSession } from './types.ts';
3
3
  export declare const MAIL_CAPABILITY = "urn:ietf:params:jmap:mail";
4
4
  export declare const SUBMISSION_CAPABILITY = "urn:ietf:params:jmap:submission";
5
5
  /** The parts of the JMAP session document this package uses. */
@@ -13,6 +13,11 @@ type SessionDocument = {
13
13
  capabilities?: Record<string, Record<string, unknown> | undefined>;
14
14
  accounts: Record<string, {
15
15
  name: string;
16
+ /** False for an account this login reaches but does not own: a shared
17
+ * mailbox it is a member of, or one shared with it by an ACL. The
18
+ * server decides this, not the client (`isPersonal` in RFC 8620
19
+ * §1.6.2). */
20
+ isPersonal?: boolean;
16
21
  isReadOnly: boolean;
17
22
  accountCapabilities: Record<string, unknown>;
18
23
  }>;
@@ -56,6 +61,22 @@ export declare class MailClient {
56
61
  /** The signed-in person and the account being read. */
57
62
  session(): Promise<MailSession>;
58
63
  accountId(): Promise<string>;
64
+ /**
65
+ * Every mailbox this login can read, the personal one first.
66
+ *
67
+ * A shared mailbox — `hr@`, a team address — is an ordinary account on the
68
+ * server that the signed-in person is a member of, and the session document
69
+ * lists it beside their own with `isPersonal: false`. Only accounts
70
+ * offering JMAP Mail are returned: a session can carry an account that
71
+ * exists for contacts or a calendar and holds no mail at all, and putting
72
+ * one of those in a mailbox switcher would offer a mailbox that cannot be
73
+ * opened.
74
+ *
75
+ * This client stays on the account it was built with. Reading another one
76
+ * means another client, built with that id — which is also what keeps a
77
+ * cached connection honest.
78
+ */
79
+ accounts(): Promise<MailAccount[]>;
59
80
  /**
60
81
  * The URL that fetches a blob's bytes. It carries no credential, so the
61
82
  * request needs the same `Authorization` header as the API.
@@ -7,6 +7,22 @@ export const SUBMISSION_CAPABILITY = 'urn:ietf:params:jmap:submission';
7
7
  function positive(value) {
8
8
  return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : null;
9
9
  }
10
+ /**
11
+ * Whether an account in this session is the login's own.
12
+ *
13
+ * The server says so (`isPersonal`), and that is what is trusted. The
14
+ * fallback is for a session document that omits the field: the account the
15
+ * session itself names as primary for mail is the personal one, and anything
16
+ * else it lists is reached through a membership or a share. Guessing the
17
+ * other way — treating an unlabelled shared mailbox as personal — would make
18
+ * a switcher claim a team's mail belongs to whoever opened it.
19
+ */
20
+ function personal(doc, accountId) {
21
+ const said = doc.accounts[accountId]?.isPersonal;
22
+ if (typeof said === 'boolean')
23
+ return said;
24
+ return accountId === doc.primaryAccounts?.[MAIL_CAPABILITY];
25
+ }
10
26
  function maxSizeUpload(doc) {
11
27
  return positive(doc.capabilities?.['urn:ietf:params:jmap:core']?.maxSizeUpload);
12
28
  }
@@ -178,6 +194,7 @@ export class MailClient {
178
194
  username: doc.username,
179
195
  accountId,
180
196
  accountName: account?.name ?? '',
197
+ isPersonal: personal(doc, accountId),
181
198
  isReadOnly: account?.isReadOnly ?? false,
182
199
  maySubmit: Boolean(account?.accountCapabilities?.[SUBMISSION_CAPABILITY]),
183
200
  maxSizeUpload: maxSizeUpload(doc),
@@ -188,6 +205,34 @@ export class MailClient {
188
205
  async accountId() {
189
206
  return (await this.connect()).accountId;
190
207
  }
208
+ /**
209
+ * Every mailbox this login can read, the personal one first.
210
+ *
211
+ * A shared mailbox — `hr@`, a team address — is an ordinary account on the
212
+ * server that the signed-in person is a member of, and the session document
213
+ * lists it beside their own with `isPersonal: false`. Only accounts
214
+ * offering JMAP Mail are returned: a session can carry an account that
215
+ * exists for contacts or a calendar and holds no mail at all, and putting
216
+ * one of those in a mailbox switcher would offer a mailbox that cannot be
217
+ * opened.
218
+ *
219
+ * This client stays on the account it was built with. Reading another one
220
+ * means another client, built with that id — which is also what keeps a
221
+ * cached connection honest.
222
+ */
223
+ async accounts() {
224
+ const { doc } = await this.connect();
225
+ return Object.entries(doc.accounts)
226
+ .filter(([, account]) => Boolean(account.accountCapabilities?.[MAIL_CAPABILITY]))
227
+ .map(([id, account]) => ({
228
+ id,
229
+ name: account.name,
230
+ isPersonal: personal(doc, id),
231
+ isReadOnly: account.isReadOnly ?? false,
232
+ maySubmit: Boolean(account.accountCapabilities?.[SUBMISSION_CAPABILITY]),
233
+ }))
234
+ .sort((a, b) => a.isPersonal === b.isPersonal ? a.name.localeCompare(b.name) : a.isPersonal ? -1 : 1);
235
+ }
191
236
  /**
192
237
  * The URL that fetches a blob's bytes. It carries no credential, so the
193
238
  * request needs the same `Authorization` header as the API.
@@ -13,9 +13,28 @@
13
13
  * `unknownMethod`, which is what a real server does and what the error path
14
14
  * expects.
15
15
  */
16
+ /** The fake models a single account, so its own `myRights` on its own
17
+ * mailboxes are always every right, granted -- there is no second login
18
+ * here for `shareWith` to matter *to*. What `shareMailbox`/`unshareMailbox`
19
+ * exercise is what this account grants to OTHER accounts, which is
20
+ * `shareWith`, not `myRights`. */
21
+ const OWNER_RIGHTS = {
22
+ mayReadItems: true,
23
+ mayAddItems: true,
24
+ mayRemoveItems: true,
25
+ maySetSeen: true,
26
+ maySetKeywords: true,
27
+ mayCreateChild: true,
28
+ mayRename: true,
29
+ maySubmit: true,
30
+ mayDelete: true,
31
+ mayShare: true,
32
+ };
16
33
  const ACCOUNT = 'fake-account';
17
34
  /** Stalwart's five, with its names and Stalwart's uniform sortOrder of 0 --
18
- * which is what makes a real tree come out alphabetical. */
35
+ * which is what makes a real tree come out alphabetical. Copied fresh into
36
+ * each instance's `#boxes`, never held here: a rename must not leak from
37
+ * one test's fake into the next. */
19
38
  const MAILBOXES = [
20
39
  { id: 'mb-inbox', name: 'Inbox', role: 'inbox' },
21
40
  { id: 'mb-drafts', name: 'Drafts', role: 'drafts' },
@@ -42,6 +61,9 @@ export class FakeMailbox {
42
61
  #latency;
43
62
  #maxSizeUpload;
44
63
  #emails = [];
64
+ /** Every mailbox: Stalwart's fixed five, then whatever `Mailbox/set` made.
65
+ * A fresh copy per instance -- see `MAILBOXES`'s note on why. */
66
+ #boxes;
45
67
  #threads = new Map();
46
68
  #counter = 0;
47
69
  /** Everything `EmailSubmission/set` accepted, for a test that asserts a
@@ -59,6 +81,15 @@ export class FakeMailbox {
59
81
  this.#now = options.now ?? new Date('2026-09-07T12:00:00Z');
60
82
  this.#latency = options.latency ?? 0;
61
83
  this.#maxSizeUpload = options.maxSizeUpload ?? STALWART_MAX_SIZE;
84
+ this.#boxes = MAILBOXES.map((box) => ({
85
+ id: box.id,
86
+ name: box.name,
87
+ parentId: null,
88
+ role: box.role,
89
+ sortOrder: 0,
90
+ isSubscribed: true,
91
+ shareWith: {},
92
+ }));
62
93
  for (const seed of options.threads ?? [])
63
94
  this.add(seed);
64
95
  }
@@ -149,8 +180,15 @@ export class FakeMailbox {
149
180
  this.#threads.set(threadId, ids);
150
181
  return threadId;
151
182
  }
183
+ /** RFC 8621 §2 on `name`: "There MUST NOT be two sibling Mailboxes with
184
+ * both the same parent and the same name." `excludeId` leaves a
185
+ * mailbox's own current record out, so renaming it to the name it
186
+ * already has is never a collision with itself. */
187
+ #nameCollides(parentId, name, excludeId) {
188
+ return this.#boxes.some((existing) => existing.id !== excludeId && existing.parentId === parentId && existing.name === name);
189
+ }
152
190
  #mailboxes() {
153
- return MAILBOXES.map((box) => {
191
+ return this.#boxes.map((box) => {
154
192
  const inBox = this.#emails.filter((email) => email.mailboxIds[box.id]);
155
193
  const unread = inBox.filter((email) => !email.keywords.$seen);
156
194
  const threads = new Set(inBox.map((email) => email.threadId));
@@ -158,14 +196,16 @@ export class FakeMailbox {
158
196
  return {
159
197
  id: box.id,
160
198
  name: box.name,
161
- parentId: null,
199
+ parentId: box.parentId,
162
200
  role: box.role,
163
- sortOrder: 0,
201
+ sortOrder: box.sortOrder,
164
202
  totalEmails: inBox.length,
165
203
  unreadEmails: unread.length,
166
204
  totalThreads: threads.size,
167
205
  unreadThreads: unreadThreads.size,
168
- isSubscribed: true,
206
+ isSubscribed: box.isSubscribed,
207
+ myRights: OWNER_RIGHTS,
208
+ shareWith: box.shareWith,
169
209
  };
170
210
  });
171
211
  }
@@ -206,6 +246,144 @@ export class FakeMailbox {
206
246
  switch (method) {
207
247
  case 'Mailbox/get':
208
248
  return { accountId: ACCOUNT, state: 'm1', list: this.#mailboxes(), notFound: [] };
249
+ case 'Mailbox/set': {
250
+ const create = (args.create ?? {});
251
+ const created = {};
252
+ const notCreated = {};
253
+ for (const [key, box] of Object.entries(create)) {
254
+ if (typeof box.name !== 'string' || box.name.length === 0) {
255
+ notCreated[key] = {
256
+ type: 'invalidProperties',
257
+ properties: ['name'],
258
+ description: 'a mailbox needs a name',
259
+ };
260
+ continue;
261
+ }
262
+ const parentId = box.parentId ?? null;
263
+ if (parentId !== null && !this.#boxes.some((existing) => existing.id === parentId)) {
264
+ notCreated[key] = {
265
+ type: 'invalidProperties',
266
+ properties: ['parentId'],
267
+ description: `no mailbox ${parentId} to nest under`,
268
+ };
269
+ continue;
270
+ }
271
+ if (this.#nameCollides(parentId, box.name)) {
272
+ notCreated[key] = {
273
+ type: 'invalidProperties',
274
+ properties: ['name'],
275
+ description: `a mailbox named "${box.name}" already exists at that level`,
276
+ };
277
+ continue;
278
+ }
279
+ const id = `mb${++this.#counter}`;
280
+ this.#boxes.push({
281
+ id,
282
+ name: box.name,
283
+ parentId,
284
+ role: box.role ?? null,
285
+ sortOrder: 0,
286
+ isSubscribed: true,
287
+ shareWith: {},
288
+ });
289
+ created[key] = { id };
290
+ }
291
+ // Rename, for `renameMailbox`, and a `shareWith/<accountId>` grant
292
+ // or revoke, for `shareMailbox`/`unshareMailbox` -- the same patch
293
+ // key shape `Email/set` already handles for `mailboxIds/<id>` and
294
+ // `keywords/<name>` below, applied to one account's rights instead:
295
+ // a plain object replaces that one account's whole grant, and
296
+ // `null` deletes it, leaving every other account's grant alone.
297
+ const update = (args.update ?? {});
298
+ const updated = {};
299
+ const notUpdated = {};
300
+ for (const [id, patch] of Object.entries(update)) {
301
+ const box = this.#boxes.find((existing) => existing.id === id);
302
+ if (!box) {
303
+ notUpdated[id] = { type: 'notFound' };
304
+ continue;
305
+ }
306
+ let refused;
307
+ for (const [path, value] of Object.entries(patch)) {
308
+ if (path === 'name') {
309
+ if (typeof value !== 'string' || value.length === 0) {
310
+ refused = { type: 'invalidProperties', description: 'a mailbox needs a name' };
311
+ break;
312
+ }
313
+ if (this.#nameCollides(box.parentId, value, box.id)) {
314
+ refused = {
315
+ type: 'invalidProperties',
316
+ description: `a mailbox named "${value}" already exists at that level`,
317
+ };
318
+ break;
319
+ }
320
+ box.name = value;
321
+ }
322
+ else if (path.startsWith('shareWith/')) {
323
+ const accountId = unpointer(path.slice('shareWith/'.length));
324
+ if (value === null) {
325
+ delete box.shareWith[accountId];
326
+ }
327
+ else {
328
+ box.shareWith[accountId] = { ...value };
329
+ }
330
+ }
331
+ else {
332
+ refused = { type: 'invalidPatch', description: `cannot patch ${path}` };
333
+ break;
334
+ }
335
+ }
336
+ if (refused) {
337
+ notUpdated[id] = refused;
338
+ continue;
339
+ }
340
+ updated[id] = null;
341
+ }
342
+ // Destroy, for `deleteMailbox`. RFC 8621 §2's own refusals: a
343
+ // mailbox still holding children or mail is not silently emptied.
344
+ // The role guard that matters -- refusing to delete an Inbox, a
345
+ // Drafts, ... -- is `deleteMailbox`'s job, not this fake's; a real
346
+ // server's stance on that varies, and this only mirrors the two
347
+ // refusals RFC 8621 actually names.
348
+ const destroy = (args.destroy ?? []);
349
+ const destroyed = [];
350
+ const notDestroyed = {};
351
+ for (const id of destroy) {
352
+ const box = this.#boxes.find((existing) => existing.id === id);
353
+ if (!box) {
354
+ notDestroyed[id] = { type: 'notFound' };
355
+ continue;
356
+ }
357
+ if (this.#boxes.some((existing) => existing.parentId === id)) {
358
+ notDestroyed[id] = {
359
+ type: 'mailboxHasChild',
360
+ description: 'the mailbox still has child mailboxes',
361
+ };
362
+ continue;
363
+ }
364
+ const hasEmail = this.#emails.some((email) => email.mailboxIds[id]);
365
+ if (hasEmail) {
366
+ notDestroyed[id] = {
367
+ type: 'mailboxHasEmail',
368
+ description: 'the mailbox still has mail in it',
369
+ };
370
+ continue;
371
+ }
372
+ this.#boxes = this.#boxes.filter((existing) => existing.id !== id);
373
+ destroyed.push(id);
374
+ }
375
+ return {
376
+ accountId: ACCOUNT,
377
+ oldState: 'm1',
378
+ newState: 'm2',
379
+ created,
380
+ notCreated: Object.keys(notCreated).length > 0 ? notCreated : null,
381
+ updated,
382
+ notUpdated: Object.keys(notUpdated).length > 0 ? notUpdated : null,
383
+ destroyed,
384
+ notDestroyed: Object.keys(notDestroyed).length > 0 ? notDestroyed : null,
385
+ };
386
+ }
209
387
  case 'Identity/get':
210
388
  return {
211
389
  accountId: ACCOUNT,
@@ -338,6 +516,26 @@ export class FakeMailbox {
338
516
  }
339
517
  updated[id] = null;
340
518
  }
519
+ // Destroy, for `saveDraft` replacing an earlier draft and `send`
520
+ // consuming one. Gone from its thread too, and an emptied thread is
521
+ // gone, as a server's derived threads are.
522
+ const destroy = (args.destroy ?? []);
523
+ const destroyed = [];
524
+ const notDestroyed = {};
525
+ for (const id of destroy) {
526
+ const email = this.#emails.find((one) => one.id === id);
527
+ if (!email) {
528
+ notDestroyed[id] = { type: 'notFound' };
529
+ continue;
530
+ }
531
+ this.#emails = this.#emails.filter((one) => one.id !== id);
532
+ const members = (this.#threads.get(email.threadId) ?? []).filter((one) => one !== id);
533
+ if (members.length > 0)
534
+ this.#threads.set(email.threadId, members);
535
+ else
536
+ this.#threads.delete(email.threadId);
537
+ destroyed.push(id);
538
+ }
341
539
  return {
342
540
  accountId: ACCOUNT,
343
541
  oldState: '1',
@@ -346,6 +544,8 @@ export class FakeMailbox {
346
544
  notCreated: null,
347
545
  updated,
348
546
  notUpdated: Object.keys(notUpdated).length > 0 ? notUpdated : null,
547
+ destroyed,
548
+ notDestroyed: Object.keys(notDestroyed).length > 0 ? notDestroyed : null,
349
549
  };
350
550
  }
351
551
  case 'EmailSubmission/set': {
@@ -8,8 +8,8 @@ export { MailClient, MAIL_CAPABILITY, SUBMISSION_CAPABILITY } from './client.ts'
8
8
  export type { MailClientOptions } from './client.ts';
9
9
  export { MailError, toMailError } from './errors.ts';
10
10
  export type { ProblemDetails } from './errors.ts';
11
- export { buildTree, findRole, mailboxes, walk } from './mailboxes.ts';
12
- export type { FlatMailbox } from './mailboxes.ts';
11
+ export { buildTree, createMailbox, deleteMailbox, findRole, mailboxes, renameMailbox, shareMailbox, unshareMailbox, walk, } from './mailboxes.ts';
12
+ export type { CreateMailboxOptions, DeleteMailboxOptions, FlatMailbox, NewMailbox, } from './mailboxes.ts';
13
13
  export { listThreads, queryThreads, summarise } from './threads.ts';
14
14
  export type { ListOptions } from './threads.ts';
15
15
  export { DEFAULT_MAX_BODY_BYTES, thread, toMessage } from './thread.ts';
@@ -19,14 +19,18 @@ export type { SearchOptions } from './search.ts';
19
19
  export { identities } from './identities.ts';
20
20
  export { attribution, formatAddress, forwardDraft, forwardIntroduction, forwardSubject, quoteText, replyDraft, replySubject, } from './drafts.ts';
21
21
  export type { ForwardOptions, ReplyOptions } from './drafts.ts';
22
- export { cancel, draftPatch, draftToEmail, queued, send, sentPatch } from './submit.ts';
23
- export type { CancelOptions, SendOptions } from './submit.ts';
22
+ export { quoteBoundary, splitQuoted } from './quoted.ts';
23
+ export type { QuoteBoundary } from './quoted.ts';
24
+ export { cancel, draftPatch, draftToEmail, queued, saveDraft, send, sentPatch } from './submit.ts';
25
+ export type { CancelOptions, SaveDraftOptions, SendOptions } from './submit.ts';
26
+ export { SNOOZED_MAILBOX, snoozeThread, wakeSnoozed } from './snooze.ts';
27
+ export type { SnoozeOptions } from './snooze.ts';
24
28
  export { attach } from './attach.ts';
25
- export { moveThread, moveToRole, removeFromMailbox, setFlagged, setRead, } from './mutate.ts';
26
- export type { MoveOptions } from './mutate.ts';
29
+ export { labelKeyword, listLabels, moveThread, moveToRole, removeFromMailbox, setFlagged, setLabel, setRead, } from './mutate.ts';
30
+ export type { ListLabelsOptions, MoveOptions } from './mutate.ts';
27
31
  export { DEFAULT_MAX_DOWNLOAD_BYTES, downloadAttachment } from './download.ts';
28
32
  export type { DownloadOptions } from './download.ts';
29
33
  export { push } from './push.ts';
30
34
  export type { PushHandle, PushOptions } from './push.ts';
31
35
  export { expandTemplate } from './uri.ts';
32
- export type { Attachment, ChangedState, Draft, DraftAttachment, EmailAddress, MailFilter, MailIdentity, MailSession, MailSort, MailboxNode, MailboxRole, Message, Queued, Sent, ThreadDetail, ThreadPage, ThreadSummary, } from './types.ts';
36
+ export type { Attachment, ChangedState, Draft, DraftAttachment, EmailAddress, MailAccount, MailFilter, MailIdentity, MailSession, MailSort, MailboxNode, MailboxRight, MailboxRights, MailboxRole, Message, Queued, Sent, ThreadDetail, ThreadPage, ThreadSummary, } from './types.ts';
@@ -6,15 +6,17 @@
6
6
  */
7
7
  export { MailClient, MAIL_CAPABILITY, SUBMISSION_CAPABILITY } from "./client.js";
8
8
  export { MailError, toMailError } from "./errors.js";
9
- export { buildTree, findRole, mailboxes, walk } from "./mailboxes.js";
9
+ export { buildTree, createMailbox, deleteMailbox, findRole, mailboxes, renameMailbox, shareMailbox, unshareMailbox, walk, } from "./mailboxes.js";
10
10
  export { listThreads, queryThreads, summarise } from "./threads.js";
11
11
  export { DEFAULT_MAX_BODY_BYTES, thread, toMessage } from "./thread.js";
12
12
  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
- export { cancel, draftPatch, draftToEmail, queued, send, sentPatch } from "./submit.js";
15
+ export { quoteBoundary, splitQuoted } from "./quoted.js";
16
+ export { cancel, draftPatch, draftToEmail, queued, saveDraft, send, sentPatch } from "./submit.js";
17
+ export { SNOOZED_MAILBOX, snoozeThread, wakeSnoozed } from "./snooze.js";
16
18
  export { attach } from "./attach.js";
17
- export { moveThread, moveToRole, removeFromMailbox, setFlagged, setRead, } from "./mutate.js";
19
+ export { labelKeyword, listLabels, moveThread, moveToRole, removeFromMailbox, setFlagged, setLabel, setRead, } from "./mutate.js";
18
20
  export { DEFAULT_MAX_DOWNLOAD_BYTES, downloadAttachment } from "./download.js";
19
21
  export { push } from "./push.js";
20
22
  export { expandTemplate } from "./uri.js";
@@ -770,6 +770,19 @@
770
770
  border-top: var(--border-width) solid var(--border);
771
771
  }
772
772
 
773
+ /* The reply/forward composer, in the same spot the foot's three quick
774
+ buttons take -- a form, not a row of buttons, so it overrides their flex
775
+ for a block layout. Capped at the same reading measure as a message body,
776
+ or a wide pane leaves its address and subject fields stretched far past
777
+ where anyone types (#56). */
778
+ .thread-compose {
779
+ display: block;
780
+ }
781
+
782
+ .thread-compose .composer {
783
+ max-width: 78ch;
784
+ }
785
+
773
786
  .messages {
774
787
  list-style: none;
775
788
  margin: 0;