inboxer 0.4.7 → 0.4.9

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 CHANGED
@@ -146,7 +146,7 @@ With roster's default isolation the site runs in its own process, so the databas
146
146
  | `ui.undoSec` | Seconds a Send or Discard in the UI waits before it happens, with an Undo button |
147
147
  | `ui.maxUploadMb` | Largest file a reviewer can attach to a draft |
148
148
 
149
- `mailboxes` is an object keyed by id rather than an array, so a per-environment override can replace one mailbox without repeating the others. Mail sent to an address that matches no mailbox lands in the reserved `catchall` mailbox, which can be read but cannot send.
149
+ `mailboxes` is an object keyed by id rather than an array, so a per-environment override can replace one mailbox without repeating the others. Mail sent to an address that matches no mailbox lands in the reserved `catchall` mailbox, grouped by that address. Replies go out from the address that was written to, with the name and signature of a mailbox on the same domain; the catch-all cannot start new mail.
150
150
 
151
151
  ## Providers
152
152
 
@@ -74,6 +74,7 @@ export declare class Mail {
74
74
  readonly provider: MailProvider;
75
75
  readonly cfg: InboxerConfig;
76
76
  private readonly ownAddresses;
77
+ private readonly domains;
77
78
  private readonly timers;
78
79
  private readonly files;
79
80
  constructor(store: Store, provider: MailProvider, cfg: InboxerConfig);
@@ -82,11 +83,20 @@ export declare class Mail {
82
83
  address: string;
83
84
  name: string;
84
85
  }[];
86
+ /** A configured mailbox address or any other address on its domains, such as one the catch-all received. */
87
+ isOwn(address: string): boolean;
88
+ /** The first address on our domains that is not a configured mailbox: the one a catch-all message was written to. */
89
+ private catchAllAddress;
90
+ /** The account a thread belongs to: its mailbox or, in the catch-all, the address it was written to. */
91
+ accountOf(thread: Thread): string;
92
+ /** Mailboxes in scope, with the catch-all split into the addresses it has received mail for. */
93
+ listAccounts(scope: Scope): Promise<string[]>;
85
94
  requireMessage(id: string, scope: Scope): Promise<Message>;
86
95
  requireThread(id: string, scope: Scope): Promise<Thread>;
87
96
  /** Scoped actors only reach contacts that take part in one of their threads. */
88
97
  private requireContactAccess;
89
98
  private mailboxFor;
99
+ /** Who sends for `id`; the catch-all answers as `address`, with the name and signature of a mailbox on that domain. */
90
100
  private sendingMailbox;
91
101
  /**
92
102
  * Stores an inbound message once per provider id and returns its id. Attachments are copied to
package/dist/core/mail.js CHANGED
@@ -28,6 +28,7 @@ export class Mail {
28
28
  provider;
29
29
  cfg;
30
30
  ownAddresses;
31
+ domains;
31
32
  timers = new Map();
32
33
  files;
33
34
  constructor(store, provider, cfg) {
@@ -35,6 +36,7 @@ export class Mail {
35
36
  this.provider = provider;
36
37
  this.cfg = cfg;
37
38
  this.ownAddresses = new Set(Object.values(cfg.mailboxes).map(m => bareAddress(m.address)));
39
+ this.domains = new Set(Object.values(cfg.mailboxes).map(m => domainOf(m.address)));
38
40
  this.files = new AttachmentFiles(cfg.dataDir);
39
41
  }
40
42
  listMailboxes(scope) {
@@ -43,6 +45,27 @@ export class Mail {
43
45
  { id: CATCHALL, address: "*", name: "Catch-all" },
44
46
  ].filter(m => reaches(scope, m.id));
45
47
  }
48
+ /** A configured mailbox address or any other address on its domains, such as one the catch-all received. */
49
+ isOwn(address) {
50
+ const bare = bareAddress(address);
51
+ return this.ownAddresses.has(bare) || this.domains.has(domainOf(bare));
52
+ }
53
+ /** The first address on our domains that is not a configured mailbox: the one a catch-all message was written to. */
54
+ catchAllAddress(addresses) {
55
+ return addresses.map(bareAddress).find(a => this.domains.has(domainOf(a)) && !this.ownAddresses.has(a)) ?? null;
56
+ }
57
+ /** The account a thread belongs to: its mailbox or, in the catch-all, the address it was written to. */
58
+ accountOf(thread) {
59
+ return thread.mailbox === CATCHALL ? this.catchAllAddress(thread.participants) ?? CATCHALL : thread.mailbox;
60
+ }
61
+ /** Mailboxes in scope, with the catch-all split into the addresses it has received mail for. */
62
+ async listAccounts(scope) {
63
+ const mailboxes = this.listMailboxes(scope).map(m => m.id).filter(id => id !== CATCHALL);
64
+ if (!reaches(scope, CATCHALL))
65
+ return mailboxes;
66
+ const caught = (await this.store.allThreads()).filter(t => t.mailbox === CATCHALL).map(t => this.accountOf(t));
67
+ return [...mailboxes, ...[...new Set(caught)].sort()];
68
+ }
46
69
  // Out of scope reads as missing, so a scoped token cannot probe other mailboxes.
47
70
  async requireMessage(id, scope) {
48
71
  const message = await this.store.requireMessage(id);
@@ -73,7 +96,11 @@ export class Mail {
73
96
  }
74
97
  return CATCHALL;
75
98
  }
76
- sendingMailbox(id) {
99
+ /** Who sends for `id`; the catch-all answers as `address`, with the name and signature of a mailbox on that domain. */
100
+ sendingMailbox(id, address) {
101
+ const peer = id === CATCHALL && address ? Object.values(this.cfg.mailboxes).find(m => domainOf(m.address) === domainOf(address)) : undefined;
102
+ if (peer && address)
103
+ return { name: peer.name, address: bareAddress(address), signatureText: peer.signatureText, signatureHtml: peer.signatureHtml };
77
104
  const mailbox = this.cfg.mailboxes[id];
78
105
  if (!mailbox)
79
106
  throw new InvalidRequestError(`Mailbox "${id}" cannot send (configured: ${Object.keys(this.cfg.mailboxes).join(", ")})`);
@@ -110,7 +137,7 @@ export class Mail {
110
137
  subject: inbound.subject,
111
138
  participants,
112
139
  at: inbound.receivedAt,
113
- }, this.ownAddresses, this.cfg.threadWindowDays);
140
+ }, address => this.isOwn(address), this.cfg.threadWindowDays);
114
141
  const message = {
115
142
  id: nid(),
116
143
  provider: this.provider.name,
@@ -195,7 +222,7 @@ export class Mail {
195
222
  return false;
196
223
  if (byMeta && !byMeta(t.id, t.participants))
197
224
  return false;
198
- if (input.mailbox && t.mailbox !== input.mailbox)
225
+ if (input.mailbox && t.mailbox !== input.mailbox && this.accountOf(t) !== input.mailbox)
199
226
  return false;
200
227
  if (input.label && !t.labels[input.label])
201
228
  return false;
@@ -242,7 +269,7 @@ export class Mail {
242
269
  }
243
270
  /** The thread's own context and the contacts of its external participants that have one. */
244
271
  async contextOf(thread) {
245
- const external = thread.participants.filter(p => !this.ownAddresses.has(p));
272
+ const external = thread.participants.filter(p => !this.isOwn(p));
246
273
  const contacts = (await Promise.all(external.map(p => this.store.getContact(p)))).filter((c) => !!c);
247
274
  return { context: await this.store.getThreadContext(thread.id), contacts };
248
275
  }
@@ -340,13 +367,16 @@ export class Mail {
340
367
  replyDefaults(original, given, replyAll) {
341
368
  const mailbox = given.mailbox ?? original.mailbox;
342
369
  const to = given.to ?? (original.direction === "in" ? (original.reply_to.length ? original.reply_to : [original.from]) : original.to);
343
- const already = new Set([bareAddress(this.sendingMailbox(mailbox).address), ...to.map(bareAddress)]);
370
+ const caught = mailbox === CATCHALL ? this.catchAllAddress(original.direction === "out" ? [original.from] : [...original.to, ...original.cc]) : null;
371
+ const sender = this.sendingMailbox(mailbox, caught);
372
+ const already = new Set([bareAddress(sender.address), ...to.map(bareAddress)]);
344
373
  const cc = replyAll ? [...original.to, ...original.cc].filter(a => !already.has(bareAddress(a))) : [];
345
- return { mailbox, to, cc, subject: replySubject(original.subject) };
374
+ return { mailbox, sender, to, cc, subject: replySubject(original.subject) };
346
375
  }
347
376
  async createDraftUnlocked(input, actor) {
348
377
  const now = new Date().toISOString();
349
378
  let mailbox;
379
+ let sender;
350
380
  let to;
351
381
  let cc = input.cc ?? [];
352
382
  let subject;
@@ -357,6 +387,7 @@ export class Mail {
357
387
  const original = await this.requireMessage(input.replyToId, actor.scope);
358
388
  const defaults = this.replyDefaults(original, input, !!input.replyAll && !input.cc);
359
389
  mailbox = defaults.mailbox;
390
+ sender = defaults.sender;
360
391
  to = defaults.to;
361
392
  if (!input.cc)
362
393
  cc = defaults.cc;
@@ -373,11 +404,11 @@ export class Mail {
373
404
  if (input.subject === undefined)
374
405
  throw new InvalidRequestError("subject is required when not replying");
375
406
  mailbox = input.mailbox;
407
+ sender = this.sendingMailbox(mailbox, null);
376
408
  to = input.to;
377
409
  subject = input.subject;
378
410
  threadId = nid();
379
411
  }
380
- const sender = this.sendingMailbox(mailbox);
381
412
  if (!reaches(actor.scope, mailbox))
382
413
  throw new InvalidRequestError(`Mailbox "${mailbox}" is not available to ${actor.name}`);
383
414
  const draft = {
@@ -573,7 +604,7 @@ export class Mail {
573
604
  */
574
605
  async sendDraftUnlocked(id, actor) {
575
606
  const draft = await this.requireDraft(id, actor.scope);
576
- const sender = this.sendingMailbox(draft.mailbox);
607
+ const sender = this.sendingMailbox(draft.mailbox, draft.from);
577
608
  if (!draft.message_id) {
578
609
  draft.message_id = `<${randomUUID()}@${domainOf(sender.address)}>`;
579
610
  await this.store.putMessage(draft);
@@ -15,7 +15,7 @@ export interface ThreadLookup {
15
15
  * 2. Same normalized subject and a shared external participant, within the window.
16
16
  * 3. A new thread.
17
17
  */
18
- export declare function resolveThreadId(store: Store, lookup: ThreadLookup, ownAddresses: Set<string>, windowDays: number): Promise<string>;
18
+ export declare function resolveThreadId(store: Store, lookup: ThreadLookup, isOwn: (address: string) => boolean, windowDays: number): Promise<string>;
19
19
  export declare function threadMessages(store: Store, thread: Thread): Promise<Message[]>;
20
20
  /** Recomputes the thread summary, adding `newMessageId` when given. A thread left with only discarded drafts is removed. */
21
21
  export declare function refreshThread(store: Store, threadId: string, newMessageId?: string): Promise<Thread | null>;
@@ -13,7 +13,7 @@ export function participantsOf(message) {
13
13
  * 2. Same normalized subject and a shared external participant, within the window.
14
14
  * 3. A new thread.
15
15
  */
16
- export async function resolveThreadId(store, lookup, ownAddresses, windowDays) {
16
+ export async function resolveThreadId(store, lookup, isOwn, windowDays) {
17
17
  for (const ref of [lookup.inReplyTo, ...[...lookup.references].reverse()]) {
18
18
  if (!ref)
19
19
  continue;
@@ -23,7 +23,7 @@ export async function resolveThreadId(store, lookup, ownAddresses, windowDays) {
23
23
  return message.thread_id;
24
24
  }
25
25
  const subject = normalizeSubject(lookup.subject);
26
- const external = new Set(lookup.participants.filter(p => !ownAddresses.has(p)));
26
+ const external = new Set(lookup.participants.filter(p => !isOwn(p)));
27
27
  if (subject && external.size) {
28
28
  const since = new Date(lookup.at).getTime() - windowDays * DAY_MS;
29
29
  const match = (await store.allThreads())
package/dist/ui/routes.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { deleteCookie, getCookie, getSignedCookie, setCookie, setSignedCookie } from "hono/cookie";
2
- import { bareAddress, domainOf, splitAddresses } from "../core/address.js";
2
+ import { domainOf, splitAddresses } from "../core/address.js";
3
3
  import { ConflictError, InvalidRequestError, toView } from "../core/mail.js";
4
4
  import { CATCHALL } from "../types.js";
5
5
  import { S } from "./strings.js";
@@ -23,12 +23,12 @@ function uiActor(session) {
23
23
  export function registerUi(app, mail, access, cfg) {
24
24
  const secret = cfg.ui.cookieSecret;
25
25
  const cookieOptions = { httpOnly: true, secure: true, sameSite: "Lax", path: "/", maxAge: COOKIE_MAX_AGE };
26
- const own = new Set(Object.values(cfg.mailboxes).map(m => bareAddress(m.address)));
27
- /** Recipients that are our own mailboxes are implied by the mailbox badge. */
26
+ const own = (address) => mail.isOwn(address);
27
+ /** Recipients that are our own addresses are implied by the mailbox badge. */
28
28
  const shown = (m) => ({
29
29
  ...m,
30
- to: m.to.filter(a => !own.has(bareAddress(a))),
31
- cc: m.cc.filter(a => !own.has(bareAddress(a))),
30
+ to: m.to.filter(a => !own(a)),
31
+ cc: m.cc.filter(a => !own(a)),
32
32
  });
33
33
  /** Mailboxes a session can send from: every one in its scope but the catch-all. */
34
34
  const senders = (session) => mail.listMailboxes(session.scope).filter(m => m.id !== CATCHALL);
@@ -96,8 +96,9 @@ export function registerUi(app, mail, access, cfg) {
96
96
  return V.draftCard(draft);
97
97
  };
98
98
  app.get("/", async (c) => {
99
- const drafts = await mail.listDrafts(undefined, c.get("session").scope);
100
- return page(c, S.navDrafts, V.inboxPage(V.draftList(drafts, null), null), "drafts");
99
+ const session = c.get("session");
100
+ const drafts = await mail.listDrafts(undefined, session.scope);
101
+ return page(c, S.navDrafts, V.inboxPage(V.draftList(drafts, domainsOf(session), null), null), "drafts");
101
102
  });
102
103
  app.get("/drafts/:id", async (c) => {
103
104
  const session = c.get("session");
@@ -106,7 +107,7 @@ export function registerUi(app, mail, access, cfg) {
106
107
  return c.redirect(`/threads/${draft.thread_id}?status=all`, 303);
107
108
  const { thread, view } = await threadPane(c, draft.thread_id, "/");
108
109
  const drafts = await mail.listDrafts(undefined, session.scope);
109
- return page(c, thread.subject || S.navDrafts, V.inboxPage(V.draftList(drafts, draft.id), view), "drafts", 200, true);
110
+ return page(c, thread.subject || S.navDrafts, V.inboxPage(V.draftList(drafts, domainsOf(session), draft.id), view), "drafts", 200, true);
110
111
  });
111
112
  app.get("/drafts/:id/card", async (c) => c.html(await draftView(c, c.req.param("id"))));
112
113
  app.get("/drafts/:id/edit", async (c) => {
@@ -194,8 +195,8 @@ export function registerUi(app, mail, access, cfg) {
194
195
  const session = c.get("session");
195
196
  const filter = inboxFilter(c);
196
197
  const threads = await mail.listThreads({ mailbox: filter.mailbox || undefined, status: filter.status, limit: 200 }, session.scope);
197
- const mailboxes = mail.listMailboxes(session.scope).map(m => m.id);
198
- return V.threadList(threads, { mailboxes, domains: domainsOf(session), filter, own, current });
198
+ const accounts = await mail.listAccounts(session.scope);
199
+ return V.threadList(threads, { accounts, accountOf: t => mail.accountOf(t), domains: domainsOf(session), filter, own, current });
199
200
  };
200
201
  app.get("/inbox", async (c) => page(c, S.navInbox, V.inboxPage(await threadList(c, null), null), "inbox"));
201
202
  /** A thread with its drafts in place; opening it marks it read. */
@@ -207,13 +208,14 @@ export function registerUi(app, mail, access, cfg) {
207
208
  thread = await mail.requireThread(id, session.scope);
208
209
  }
209
210
  const { messages, context, contacts } = await mail.getThread(id, session.scope);
210
- const people = thread.participants.filter(p => !own.has(p));
211
+ const people = thread.participants.filter(p => !own(p));
211
212
  const entries = await Promise.all(messages.map(async (m) => ({
212
213
  at: m.date,
213
214
  view: m.status === "draft" ? V.draftCard(await mail.store.requireMessage(m.id)) : V.messageBubble(shown(m), people.length > 1),
214
215
  })));
215
- const reply = { allowed: senders(session).some(m => m.id === thread.mailbox), replyAll: people.length > 1 };
216
- return { thread, view: V.threadView(thread, entries, { context, contacts }, { back, filter: inboxFilter(c), own, reply }) };
216
+ const account = mail.accountOf(thread);
217
+ const reply = { allowed: account !== CATCHALL && (thread.mailbox === CATCHALL || senders(session).some(m => m.id === thread.mailbox)), replyAll: people.length > 1 };
218
+ return { thread, view: V.threadView(thread, entries, { context, contacts }, { back, filter: inboxFilter(c), own, account, reply }) };
217
219
  };
218
220
  app.get("/threads/:id", async (c) => {
219
221
  const id = c.req.param("id");
@@ -38,7 +38,7 @@ h1 { font-size: 2rem; line-height: 1.1; letter-spacing: -0.04em; font-weight: 70
38
38
  .sidebar { display: none; }
39
39
  body.app { padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }
40
40
  body.app.full { padding-bottom: 0; }
41
- .page { max-width: 760px; margin: 0 auto; padding: 24px 16px 32px; }
41
+ .page { max-width: 760px; padding: 24px 16px 32px; }
42
42
 
43
43
  .tabbar {
44
44
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
@@ -75,7 +75,7 @@ body.full .tabbar { display: none; }
75
75
  display: flex; flex-direction: column; gap: 4px;
76
76
  padding: 20px 14px; border-right: 1px solid var(--line);
77
77
  }
78
- .brand { font-size: 20px; font-weight: 700; letter-spacing: -0.03em; padding: 0 12px; }
78
+ .brand { font-size: 21px; line-height: 1.2; font-weight: 700; letter-spacing: -0.03em; text-transform: lowercase; padding: 0 12px; }
79
79
  .brand span { color: var(--accent); }
80
80
  .new-mail { display: flex; align-items: center; justify-content: center; gap: 8px; height: 44px; border-radius: 12px; margin: 16px 0 14px; }
81
81
  .side-nav { display: flex; flex-direction: column; gap: 2px; }
@@ -103,8 +103,9 @@ body.full .tabbar { display: none; }
103
103
  body.context-open .split .list { display: none; }
104
104
  }
105
105
 
106
- .list-head { padding: 18px 16px 12px; }
106
+ .list-head { padding: 20px 16px 12px; }
107
107
  .list-head h1 { font-size: 21px; line-height: 1.2; letter-spacing: -0.02em; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
108
+ .list-head small { font-size: 13px; font-weight: 500; letter-spacing: 0; color: var(--muted); margin-left: 4px; }
108
109
  .filters { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
109
110
  .chips { display: flex; flex: none; gap: 8px; }
110
111
  .filters .select { min-width: 0; }
@@ -200,8 +201,9 @@ button.thread-title:hover { background: var(--soft); border: none; }
200
201
  }
201
202
  .composer textarea:focus { border-color: var(--focus); }
202
203
  .composer .send { width: 44px; height: 44px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
203
- .reply-all { flex-basis: 100%; display: flex; align-items: center; gap: 8px; padding: 2px 8px; font-family: var(--mono); font-size: .72rem; color: var(--muted); cursor: pointer; }
204
- .reply-all input { accent-color: var(--accent); }
204
+ .reply-all { flex-basis: 100%; display: flex; align-items: center; gap: 8px; padding: 2px 0; font-family: var(--mono); font-size: .72rem; color: var(--muted); cursor: pointer; }
205
+ /* Centered over the + button below it, which is 44px wide. */
206
+ .reply-all input { width: 16px; height: 16px; margin: 0 0 0 14px; flex: none; accent-color: var(--accent); }
205
207
 
206
208
  /* Context: a side panel on a wide screen, a bottom sheet on a phone */
207
209
  .context-panel { display: none; background: var(--bg); }
@@ -394,6 +396,7 @@ textarea {
394
396
  .setting label { font-weight: 500; }
395
397
  .row.device:hover { background: none; }
396
398
  .row.device .avatar { color: var(--muted); }
399
+ .row.device form { display: contents; }
397
400
  .row.device .danger { align-self: center; padding: 0; height: auto; border: none; background: none; }
398
401
  .row.device .danger:hover { text-decoration: underline; }
399
402
  .setting .danger, .setting .danger:hover { padding: 0; height: auto; border: none; background: none; }
@@ -1,6 +1,6 @@
1
1
  import type { HtmlEscapedString } from "hono/utils/html";
2
2
  import type { MessageView } from "../core/mail.ts";
3
- import type { Contact, Context, Message, Session, Thread } from "../types.ts";
3
+ import { type Contact, type Context, type Message, type Session, type Thread } from "../types.ts";
4
4
  export type View = HtmlEscapedString;
5
5
  export type Theme = "system" | "light" | "dark";
6
6
  export type Page = "drafts" | "inbox" | "devices" | "settings" | null;
@@ -50,20 +50,24 @@ export declare function draftEditor(d: Message, form: DraftForm, conflict: Messa
50
50
  export declare function draftFiles(d: Message, error: string | null): View;
51
51
  export declare function draftDone(id: string, text: string): View;
52
52
  /** Drafts waiting for review, listed like the inbox; each opens its thread. */
53
- export declare function draftList(drafts: Message[], current: string | null): View;
53
+ export declare function draftList(drafts: Message[], domains: string[], current: string | null): View;
54
54
  export interface InboxFilter {
55
55
  mailbox: string;
56
56
  status: string;
57
57
  }
58
58
  export declare function inboxQuery(filter: InboxFilter): string;
59
59
  /** The thread list; on a wide screen it stays beside the open thread. */
60
- export declare function threadList(threads: Thread[], opts: {
61
- mailboxes: string[];
60
+ export declare function threadList(threads: Thread[], opts: ThreadListOptions & {
62
61
  domains: string[];
62
+ }): View;
63
+ interface ThreadListOptions {
64
+ /** Mailbox ids and catch-all addresses, as filter values. */
65
+ accounts: string[];
66
+ accountOf: (t: Thread) => string;
63
67
  filter: InboxFilter;
64
- own: Set<string>;
68
+ own: (address: string) => boolean;
65
69
  current: string | null;
66
- }): View;
70
+ }
67
71
  /** The thread list and the open thread side by side; a phone shows one of the two. */
68
72
  export declare function inboxPage(list: View, thread: View | null): View;
69
73
  export interface ThreadEntry {
@@ -74,7 +78,8 @@ export interface ThreadEntry {
74
78
  export declare function threadView(thread: Thread, entries: ThreadEntry[], ctx: ContextView, opts: {
75
79
  back: string;
76
80
  filter: InboxFilter;
77
- own: Set<string>;
81
+ own: (address: string) => boolean;
82
+ account: string;
78
83
  reply: {
79
84
  allowed: boolean;
80
85
  replyAll: boolean;
@@ -83,3 +88,4 @@ export declare function threadView(thread: Thread, entries: ThreadEntry[], ctx:
83
88
  export declare function archiveButton(thread: Thread): View;
84
89
  export declare function devicesPage(sessions: Session[], currentId: string): View;
85
90
  export declare function settingsPage(theme: Theme): View;
91
+ export {};
package/dist/ui/views.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { html, raw } from "hono/html";
2
2
  import { bareAddress } from "../core/address.js";
3
+ import { CATCHALL } from "../types.js";
3
4
  import { ASSETS } from "./assets.js";
4
5
  import { S } from "./strings.js";
5
6
  /** Views never await, so `html` returns a plain escaped string. */
@@ -155,8 +156,12 @@ export function signIn(token, valid) {
155
156
  <form method="post" action="/auth/${token}"><button class="primary">${S.signInButton}</button></form>
156
157
  </div>`;
157
158
  }
158
- function mailboxBadge(mailbox) {
159
- return h `<span class="badge mailbox">${mailbox}</span>`;
159
+ /** An account by its mailbox id, or by the local part of an address the catch-all received. */
160
+ function mailboxBadge(account) {
161
+ return h `<span class="badge mailbox">${account.includes("@") ? account.slice(0, account.lastIndexOf("@")) : account}</span>`;
162
+ }
163
+ function draftAccount(d) {
164
+ return d.mailbox === CATCHALL ? bareAddress(d.from) : d.mailbox;
160
165
  }
161
166
  const PREVIEWABLE = new Set(["image/png", "image/jpeg", "image/gif", "image/webp", "image/avif"]);
162
167
  /** Image types a browser renders without running code; SVG is left out on purpose. */
@@ -239,7 +244,7 @@ export function draftCard(d) {
239
244
  return h `<article class="card draft" id="draft-${d.id}">
240
245
  <div class="meta">
241
246
  <span class="badge draft">${S.draft}</span>
242
- ${mailboxBadge(d.mailbox)}
247
+ ${mailboxBadge(draftAccount(d))}
243
248
  <span>${d.edited_by_human ? S.editedByHuman : S.byAgent} · ${formatDate(d.created_at)}</span>
244
249
  </div>
245
250
  <div class="draft-head">
@@ -263,7 +268,7 @@ export function draftEditor(d, form, conflict) {
263
268
  <div class="grabber" aria-hidden="true"></div>
264
269
  <div class="drop-hint">${S.dropFiles}</div>
265
270
  <button type="button" class="icon-btn sheet-close" data-close aria-label="${S.close}">${icon("close")}</button>
266
- <div class="sheet-head"><span class="badge draft">${S.draft}</span>${mailboxBadge(d.mailbox)}</div>
271
+ <div class="sheet-head"><span class="badge draft">${S.draft}</span>${mailboxBadge(draftAccount(d))}</div>
267
272
  ${when(d.note, () => h `<div class="note">${d.note}</div>`)}
268
273
  ${when(conflict, () => h `<div class="sheet-conflict">
269
274
  <p class="warn">${S.conflictTitle}</p>
@@ -307,10 +312,16 @@ export function draftFiles(d, error) {
307
312
  export function draftDone(id, text) {
308
313
  return h `<article class="card notice" id="draft-${id}">${text}</article>`;
309
314
  }
315
+ /** A list's title: the session's sending domains, with the list's name beside them. */
316
+ function listTitle(domains, label) {
317
+ return domains.length
318
+ ? h `<h1>${domains.join(" · ")} <small>${label}</small></h1>`
319
+ : h `<h1>${label}</h1>`;
320
+ }
310
321
  /** Drafts waiting for review, listed like the inbox; each opens its thread. */
311
- export function draftList(drafts, current) {
322
+ export function draftList(drafts, domains, current) {
312
323
  return h `<section class="list">
313
- <header class="list-head"><h1>${S.navDrafts}</h1></header>
324
+ <header class="list-head">${listTitle(domains, S.navDrafts)}</header>
314
325
  ${drafts.length ? join(drafts.map(d => h `<a class="row" href="/drafts/${d.id}" ${raw(d.id === current ? 'aria-current="page"' : "")}>
315
326
  <span class="avatar" aria-hidden="true">${initials(d.to[0] ?? d.mailbox)}</span>
316
327
  <span class="row-main">
@@ -334,13 +345,13 @@ export function threadList(threads, opts) {
334
345
  const tab = (status, label) => h `<a class="chip" href="/inbox?${inboxQuery({ ...filter, status })}" ${raw(filter.status === status ? 'aria-current="page"' : "")}>${label}</a>`;
335
346
  return h `<section class="list">
336
347
  <header class="list-head">
337
- <h1>${opts.domains.length ? opts.domains.join(" · ") : S.navInbox}</h1>
348
+ ${listTitle(opts.domains, S.navInbox)}
338
349
  <form class="filters" method="get" action="/inbox">
339
350
  <input type="hidden" name="status" value="${filter.status}">
340
351
  <nav class="chips" aria-label="${S.filter}">${tab("unanswered", S.filterPending)}${tab("all", S.filterAll)}${tab("archived", S.filterArchived)}</nav>
341
- ${when(opts.mailboxes.length > 1, () => h `<span class="select"><select name="mailbox" aria-label="${S.allMailboxes}" onchange="this.form.submit()">
352
+ ${when(opts.accounts.length > 1, () => h `<span class="select"><select name="mailbox" aria-label="${S.allMailboxes}" onchange="this.form.submit()">
342
353
  <option value="">${S.allMailboxes}</option>
343
- ${join(opts.mailboxes.map(m => h `<option value="${m}" ${raw(m === filter.mailbox ? "selected" : "")}>${m}</option>`))}
354
+ ${join(opts.accounts.map(m => h `<option value="${m}" ${raw(m === filter.mailbox ? "selected" : "")}>${m}</option>`))}
344
355
  </select></span>`)}
345
356
  </form>
346
357
  </header>
@@ -348,15 +359,15 @@ export function threadList(threads, opts) {
348
359
  </section>`;
349
360
  }
350
361
  function threadRow(t, opts) {
351
- const people = t.participants.filter(p => !opts.own.has(p));
362
+ const people = t.participants.filter(p => !opts.own(p));
352
363
  return h `<a class="row ${t.unread ? "unread" : ""}" href="/threads/${t.id}?${inboxQuery(opts.filter)}" ${raw(t.id === opts.current ? 'aria-current="page"' : "")}>
353
364
  <span class="avatar" aria-hidden="true">${initials(people[0] ?? t.mailbox)}</span>
354
365
  <span class="row-main">
355
366
  <span class="row-top"><span class="who">${people.join(", ") || t.mailbox}</span><time datetime="${t.last_at}">${formatDate(t.last_at)}</time></span>
356
367
  <span class="row-subject">${t.subject || "—"}</span>
357
- ${when(t.has_draft || opts.mailboxes.length > 1 || t.unread, () => h `<span class="row-tags">
368
+ ${when(t.has_draft || opts.accounts.length > 1 || t.unread, () => h `<span class="row-tags">
358
369
  ${when(t.has_draft, () => h `<span class="badge draft">${S.hasDraft}</span>`)}
359
- ${when(opts.mailboxes.length > 1, () => mailboxBadge(t.mailbox))}
370
+ ${when(opts.accounts.length > 1, () => mailboxBadge(opts.accountOf(t)))}
360
371
  ${when(t.unread, () => h `<span class="dot" title="${S.unread}"></span>`)}
361
372
  </span>`)}
362
373
  </span>
@@ -370,8 +381,8 @@ export function inboxPage(list, thread) {
370
381
  export function threadView(thread, entries, ctx, opts) {
371
382
  const query = inboxQuery(opts.filter);
372
383
  const rows = contextRows(ctx);
373
- const people = thread.participants.filter(p => !opts.own.has(p));
374
- const title = h `<span class="thread-subject">${thread.subject || "—"}</span><span class="thread-meta">${[...people, thread.mailbox].join(" · ")}</span>`;
384
+ const people = thread.participants.filter(p => !opts.own(p));
385
+ const title = h `<span class="thread-subject">${thread.subject || "—"}</span><span class="thread-meta">${[...people, opts.account].join(" · ")}</span>`;
375
386
  const items = [];
376
387
  let day = "";
377
388
  for (const entry of entries) {
@@ -426,7 +437,9 @@ export function devicesPage(sessions, currentId) {
426
437
  <span class="row-by">${S.signedIn} ${formatDate(s.created_at)} · ${S.createdBy} ${s.created_by}</span>
427
438
  </span>
428
439
  </span>
429
- ${when(s.id !== currentId, () => h `<button class="danger" hx-post="/devices/${s.id}/revoke" hx-target="#session-${s.id}" hx-swap="delete">${S.revoke}</button>`)}
440
+ ${s.id === currentId
441
+ ? h `<form method="post" action="/logout"><button class="danger">${S.logout}</button></form>`
442
+ : h `<button class="danger" hx-post="/devices/${s.id}/revoke" hx-target="#session-${s.id}" hx-swap="delete">${S.revoke}</button>`}
430
443
  </div>`)) : h `<p class="empty">${S.devicesEmpty}</p>`}
431
444
  </section>`;
432
445
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inboxer",
3
- "version": "0.4.7",
3
+ "version": "0.4.9",
4
4
  "description": "A self-hosted mail layer for agents: persists every inbound and outbound email, exposes an MCP server, and ships a minimal UI to review drafts.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -32,7 +32,7 @@ const config = {
32
32
  ```
33
33
 
34
34
  - Every key above is required except the mailbox signatures and mailbox tokens; `createInboxer` throws on a missing or invalid one. There are no defaults.
35
- - `mailboxes` is an object keyed by id. `catchall` is reserved: unknown recipients land there, and it cannot send.
35
+ - `mailboxes` is an object keyed by id. `catchall` is reserved: unknown recipients land there, grouped by the address they were written to. It answers as that address, with the name and signature of a mailbox on the same domain, and cannot start new mail.
36
36
  - `provider.apiKey`, `provider.webhookSecret`, every token and `ui.cookieSecret` are secrets: keep them out of Git and out of logs.
37
37
 
38
38
  ## Serve
@@ -105,7 +105,7 @@ Rules for agents:
105
105
  - `search` matches every term, ignoring case and accents, across subject, body, from and to; narrow with `mailbox`, `from`, `since`, `until`, `meta`. Pass `query`, `meta`, or both.
106
106
  - Messages list their `attachments` (`inline: true` is an image embedded in the body). `get_attachment` returns the content: images as images you can look at, text as text, other files (PDF, documents) as an embedded resource. Files over `mcp.maxAttachmentMb` return an error. Agents cannot attach files to drafts; the reviewer can, in the UI, and they are listed in the draft's `attachments`.
107
107
  - Threads, messages and drafts in results carry `url`, which opens them in the review UI (scrolled to the draft). When telling the user what you drafted or sent, include that `url`.
108
- - Times are ISO 8601. `catchall` messages can be read and labeled but not answered from Inboxer.
108
+ - Times are ISO 8601. A `catchall` reply goes out from the address the message was written to; `list_threads` also takes that address as `mailbox`.
109
109
 
110
110
  Context:
111
111
 
package/src/core/mail.ts CHANGED
@@ -98,6 +98,7 @@ export class Mail {
98
98
  readonly provider: MailProvider;
99
99
  readonly cfg: InboxerConfig;
100
100
  private readonly ownAddresses: Set<string>;
101
+ private readonly domains: Set<string>;
101
102
  private readonly timers = new Map<string, ReturnType<typeof setTimeout>>();
102
103
  private readonly files: AttachmentFiles;
103
104
 
@@ -106,6 +107,7 @@ export class Mail {
106
107
  this.provider = provider;
107
108
  this.cfg = cfg;
108
109
  this.ownAddresses = new Set(Object.values(cfg.mailboxes).map(m => bareAddress(m.address)));
110
+ this.domains = new Set(Object.values(cfg.mailboxes).map(m => domainOf(m.address)));
109
111
  this.files = new AttachmentFiles(cfg.dataDir);
110
112
  }
111
113
 
@@ -116,6 +118,30 @@ export class Mail {
116
118
  ].filter(m => reaches(scope, m.id));
117
119
  }
118
120
 
121
+ /** A configured mailbox address or any other address on its domains, such as one the catch-all received. */
122
+ isOwn(address: string): boolean {
123
+ const bare = bareAddress(address);
124
+ return this.ownAddresses.has(bare) || this.domains.has(domainOf(bare));
125
+ }
126
+
127
+ /** The first address on our domains that is not a configured mailbox: the one a catch-all message was written to. */
128
+ private catchAllAddress(addresses: string[]): string | null {
129
+ return addresses.map(bareAddress).find(a => this.domains.has(domainOf(a)) && !this.ownAddresses.has(a)) ?? null;
130
+ }
131
+
132
+ /** The account a thread belongs to: its mailbox or, in the catch-all, the address it was written to. */
133
+ accountOf(thread: Thread): string {
134
+ return thread.mailbox === CATCHALL ? this.catchAllAddress(thread.participants) ?? CATCHALL : thread.mailbox;
135
+ }
136
+
137
+ /** Mailboxes in scope, with the catch-all split into the addresses it has received mail for. */
138
+ async listAccounts(scope: Scope): Promise<string[]> {
139
+ const mailboxes = this.listMailboxes(scope).map(m => m.id).filter(id => id !== CATCHALL);
140
+ if (!reaches(scope, CATCHALL)) return mailboxes;
141
+ const caught = (await this.store.allThreads()).filter(t => t.mailbox === CATCHALL).map(t => this.accountOf(t));
142
+ return [...mailboxes, ...[...new Set(caught)].sort()];
143
+ }
144
+
119
145
  // Out of scope reads as missing, so a scoped token cannot probe other mailboxes.
120
146
 
121
147
  async requireMessage(id: string, scope: Scope): Promise<Message> {
@@ -147,7 +173,10 @@ export class Mail {
147
173
  return CATCHALL;
148
174
  }
149
175
 
150
- private sendingMailbox(id: string): MailboxConfig {
176
+ /** Who sends for `id`; the catch-all answers as `address`, with the name and signature of a mailbox on that domain. */
177
+ private sendingMailbox(id: string, address: string | null): MailboxConfig {
178
+ const peer = id === CATCHALL && address ? Object.values(this.cfg.mailboxes).find(m => domainOf(m.address) === domainOf(address)) : undefined;
179
+ if (peer && address) return { name: peer.name, address: bareAddress(address), signatureText: peer.signatureText, signatureHtml: peer.signatureHtml };
151
180
  const mailbox = this.cfg.mailboxes[id];
152
181
  if (!mailbox) throw new InvalidRequestError(`Mailbox "${id}" cannot send (configured: ${Object.keys(this.cfg.mailboxes).join(", ")})`);
153
182
  return mailbox;
@@ -189,7 +218,7 @@ export class Mail {
189
218
  participants,
190
219
  at: inbound.receivedAt,
191
220
  },
192
- this.ownAddresses,
221
+ address => this.isOwn(address),
193
222
  this.cfg.threadWindowDays,
194
223
  );
195
224
  const message: Message = {
@@ -275,7 +304,7 @@ export class Mail {
275
304
  const threads = (await this.store.allThreads()).filter(t => {
276
305
  if (!reaches(scope, t.mailbox)) return false;
277
306
  if (byMeta && !byMeta(t.id, t.participants)) return false;
278
- if (input.mailbox && t.mailbox !== input.mailbox) return false;
307
+ if (input.mailbox && t.mailbox !== input.mailbox && this.accountOf(t) !== input.mailbox) return false;
279
308
  if (input.label && !t.labels[input.label]) return false;
280
309
  if (input.since && t.last_at < input.since) return false;
281
310
  if (status === "archived") return t.archived;
@@ -313,7 +342,7 @@ export class Mail {
313
342
 
314
343
  /** The thread's own context and the contacts of its external participants that have one. */
315
344
  async contextOf(thread: Thread): Promise<{ context: Context | null; contacts: Contact[] }> {
316
- const external = thread.participants.filter(p => !this.ownAddresses.has(p));
345
+ const external = thread.participants.filter(p => !this.isOwn(p));
317
346
  const contacts = (await Promise.all(external.map(p => this.store.getContact(p)))).filter((c): c is Contact => !!c);
318
347
  return { context: await this.store.getThreadContext(thread.id), contacts };
319
348
  }
@@ -417,14 +446,17 @@ export class Mail {
417
446
  private replyDefaults(original: Message, given: { mailbox?: string; to?: string[] }, replyAll: boolean) {
418
447
  const mailbox = given.mailbox ?? original.mailbox;
419
448
  const to = given.to ?? (original.direction === "in" ? (original.reply_to.length ? original.reply_to : [original.from]) : original.to);
420
- const already = new Set([bareAddress(this.sendingMailbox(mailbox).address), ...to.map(bareAddress)]);
449
+ const caught = mailbox === CATCHALL ? this.catchAllAddress(original.direction === "out" ? [original.from] : [...original.to, ...original.cc]) : null;
450
+ const sender = this.sendingMailbox(mailbox, caught);
451
+ const already = new Set([bareAddress(sender.address), ...to.map(bareAddress)]);
421
452
  const cc = replyAll ? [...original.to, ...original.cc].filter(a => !already.has(bareAddress(a))) : [];
422
- return { mailbox, to, cc, subject: replySubject(original.subject) };
453
+ return { mailbox, sender, to, cc, subject: replySubject(original.subject) };
423
454
  }
424
455
 
425
456
  private async createDraftUnlocked(input: CreateDraftInput, actor: Actor): Promise<Message> {
426
457
  const now = new Date().toISOString();
427
458
  let mailbox: string;
459
+ let sender: MailboxConfig;
428
460
  let to: string[];
429
461
  let cc = input.cc ?? [];
430
462
  let subject: string;
@@ -436,6 +468,7 @@ export class Mail {
436
468
  const original = await this.requireMessage(input.replyToId, actor.scope);
437
469
  const defaults = this.replyDefaults(original, input, !!input.replyAll && !input.cc);
438
470
  mailbox = defaults.mailbox;
471
+ sender = defaults.sender;
439
472
  to = defaults.to;
440
473
  if (!input.cc) cc = defaults.cc;
441
474
  subject = input.subject ?? defaults.subject;
@@ -447,11 +480,11 @@ export class Mail {
447
480
  if (!input.to?.length) throw new InvalidRequestError("to is required when not replying");
448
481
  if (input.subject === undefined) throw new InvalidRequestError("subject is required when not replying");
449
482
  mailbox = input.mailbox;
483
+ sender = this.sendingMailbox(mailbox, null);
450
484
  to = input.to;
451
485
  subject = input.subject;
452
486
  threadId = nid();
453
487
  }
454
- const sender = this.sendingMailbox(mailbox);
455
488
  if (!reaches(actor.scope, mailbox)) throw new InvalidRequestError(`Mailbox "${mailbox}" is not available to ${actor.name}`);
456
489
 
457
490
  const draft: Message = {
@@ -650,7 +683,7 @@ export class Mail {
650
683
  */
651
684
  private async sendDraftUnlocked(id: string, actor: Actor): Promise<Message> {
652
685
  const draft = await this.requireDraft(id, actor.scope);
653
- const sender = this.sendingMailbox(draft.mailbox);
686
+ const sender = this.sendingMailbox(draft.mailbox, draft.from);
654
687
  if (!draft.message_id) {
655
688
  draft.message_id = `<${randomUUID()}@${domainOf(sender.address)}>`;
656
689
  await this.store.putMessage(draft);
@@ -30,7 +30,7 @@ export interface ThreadLookup {
30
30
  export async function resolveThreadId(
31
31
  store: Store,
32
32
  lookup: ThreadLookup,
33
- ownAddresses: Set<string>,
33
+ isOwn: (address: string) => boolean,
34
34
  windowDays: number,
35
35
  ): Promise<string> {
36
36
  for (const ref of [lookup.inReplyTo, ...[...lookup.references].reverse()]) {
@@ -41,7 +41,7 @@ export async function resolveThreadId(
41
41
  }
42
42
 
43
43
  const subject = normalizeSubject(lookup.subject);
44
- const external = new Set(lookup.participants.filter(p => !ownAddresses.has(p)));
44
+ const external = new Set(lookup.participants.filter(p => !isOwn(p)));
45
45
  if (subject && external.size) {
46
46
  const since = new Date(lookup.at).getTime() - windowDays * DAY_MS;
47
47
  const match = (await store.allThreads())
package/src/ui/routes.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Context, Hono } from "hono";
2
2
  import { deleteCookie, getCookie, getSignedCookie, setCookie, setSignedCookie } from "hono/cookie";
3
3
  import type { Access } from "../auth.ts";
4
- import { bareAddress, domainOf, splitAddresses } from "../core/address.ts";
4
+ import { domainOf, splitAddresses } from "../core/address.ts";
5
5
  import { ConflictError, InvalidRequestError, toView, type Mail, type MessageView, type ThreadStatus } from "../core/mail.ts";
6
6
  import { CATCHALL, type Actor, type InboxerConfig, type Message, type Session } from "../types.ts";
7
7
  import { S } from "./strings.ts";
@@ -33,12 +33,12 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
33
33
  const secret = cfg.ui.cookieSecret;
34
34
  const cookieOptions = { httpOnly: true, secure: true, sameSite: "Lax", path: "/", maxAge: COOKIE_MAX_AGE } as const;
35
35
 
36
- const own = new Set(Object.values(cfg.mailboxes).map(m => bareAddress(m.address)));
37
- /** Recipients that are our own mailboxes are implied by the mailbox badge. */
36
+ const own = (address: string): boolean => mail.isOwn(address);
37
+ /** Recipients that are our own addresses are implied by the mailbox badge. */
38
38
  const shown = (m: MessageView): MessageView => ({
39
39
  ...m,
40
- to: m.to.filter(a => !own.has(bareAddress(a))),
41
- cc: m.cc.filter(a => !own.has(bareAddress(a))),
40
+ to: m.to.filter(a => !own(a)),
41
+ cc: m.cc.filter(a => !own(a)),
42
42
  });
43
43
 
44
44
  /** Mailboxes a session can send from: every one in its scope but the catch-all. */
@@ -210,8 +210,8 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
210
210
  const session = c.get("session");
211
211
  const filter = inboxFilter(c);
212
212
  const threads = await mail.listThreads({ mailbox: filter.mailbox || undefined, status: filter.status as ThreadStatus, limit: 200 }, session.scope);
213
- const mailboxes = mail.listMailboxes(session.scope).map(m => m.id);
214
- return V.threadList(threads, { mailboxes, domains: domainsOf(session), filter, own, current });
213
+ const accounts = await mail.listAccounts(session.scope);
214
+ return V.threadList(threads, { accounts, accountOf: t => mail.accountOf(t), domains: domainsOf(session), filter, own, current });
215
215
  };
216
216
 
217
217
  app.get("/inbox", async c => page(c, S.navInbox, V.inboxPage(await threadList(c, null), null), "inbox"));
@@ -225,13 +225,14 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
225
225
  thread = await mail.requireThread(id, session.scope);
226
226
  }
227
227
  const { messages, context, contacts } = await mail.getThread(id, session.scope);
228
- const people = thread.participants.filter(p => !own.has(p));
228
+ const people = thread.participants.filter(p => !own(p));
229
229
  const entries = await Promise.all(messages.map(async m => ({
230
230
  at: m.date,
231
231
  view: m.status === "draft" ? V.draftCard(await mail.store.requireMessage(m.id)) : V.messageBubble(shown(m), people.length > 1),
232
232
  })));
233
- const reply = { allowed: senders(session).some(m => m.id === thread.mailbox), replyAll: people.length > 1 };
234
- return { thread, view: V.threadView(thread, entries, { context, contacts }, { back, filter: inboxFilter(c), own, reply }) };
233
+ const account = mail.accountOf(thread);
234
+ const reply = { allowed: account !== CATCHALL && (thread.mailbox === CATCHALL || senders(session).some(m => m.id === thread.mailbox)), replyAll: people.length > 1 };
235
+ return { thread, view: V.threadView(thread, entries, { context, contacts }, { back, filter: inboxFilter(c), own, account, reply }) };
235
236
  };
236
237
 
237
238
  app.get("/threads/:id", async c => {
package/src/ui/views.ts CHANGED
@@ -2,7 +2,7 @@ import { html, raw } from "hono/html";
2
2
  import type { HtmlEscapedString } from "hono/utils/html";
3
3
  import { bareAddress } from "../core/address.ts";
4
4
  import type { MessageView } from "../core/mail.ts";
5
- import type { Contact, Context, Message, Session, Thread } from "../types.ts";
5
+ import { CATCHALL, type Contact, type Context, type Message, type Session, type Thread } from "../types.ts";
6
6
  import { ASSETS } from "./assets.ts";
7
7
  import { S } from "./strings.ts";
8
8
 
@@ -195,8 +195,13 @@ export function signIn(token: string, valid: boolean): View {
195
195
  </div>`;
196
196
  }
197
197
 
198
- function mailboxBadge(mailbox: string): View {
199
- return h`<span class="badge mailbox">${mailbox}</span>`;
198
+ /** An account by its mailbox id, or by the local part of an address the catch-all received. */
199
+ function mailboxBadge(account: string): View {
200
+ return h`<span class="badge mailbox">${account.includes("@") ? account.slice(0, account.lastIndexOf("@")) : account}</span>`;
201
+ }
202
+
203
+ function draftAccount(d: Message): string {
204
+ return d.mailbox === CATCHALL ? bareAddress(d.from) : d.mailbox;
200
205
  }
201
206
 
202
207
  const PREVIEWABLE = new Set(["image/png", "image/jpeg", "image/gif", "image/webp", "image/avif"]);
@@ -290,7 +295,7 @@ export function draftCard(d: Message): View {
290
295
  return h`<article class="card draft" id="draft-${d.id}">
291
296
  <div class="meta">
292
297
  <span class="badge draft">${S.draft}</span>
293
- ${mailboxBadge(d.mailbox)}
298
+ ${mailboxBadge(draftAccount(d))}
294
299
  <span>${d.edited_by_human ? S.editedByHuman : S.byAgent} · ${formatDate(d.created_at)}</span>
295
300
  </div>
296
301
  <div class="draft-head">
@@ -322,7 +327,7 @@ export function draftEditor(d: Message, form: DraftForm, conflict: Message | nul
322
327
  <div class="grabber" aria-hidden="true"></div>
323
328
  <div class="drop-hint">${S.dropFiles}</div>
324
329
  <button type="button" class="icon-btn sheet-close" data-close aria-label="${S.close}">${icon("close")}</button>
325
- <div class="sheet-head"><span class="badge draft">${S.draft}</span>${mailboxBadge(d.mailbox)}</div>
330
+ <div class="sheet-head"><span class="badge draft">${S.draft}</span>${mailboxBadge(draftAccount(d))}</div>
326
331
  ${when(d.note, () => h`<div class="note">${d.note}</div>`)}
327
332
  ${when(conflict, () => h`<div class="sheet-conflict">
328
333
  <p class="warn">${S.conflictTitle}</p>
@@ -405,7 +410,7 @@ export function inboxQuery(filter: InboxFilter): string {
405
410
  }
406
411
 
407
412
  /** The thread list; on a wide screen it stays beside the open thread. */
408
- export function threadList(threads: Thread[], opts: { mailboxes: string[]; domains: string[]; filter: InboxFilter; own: Set<string>; current: string | null }): View {
413
+ export function threadList(threads: Thread[], opts: ThreadListOptions & { domains: string[] }): View {
409
414
  const { filter } = opts;
410
415
  const tab = (status: string, label: string) =>
411
416
  h`<a class="chip" href="/inbox?${inboxQuery({ ...filter, status })}" ${raw(filter.status === status ? 'aria-current="page"' : "")}>${label}</a>`;
@@ -415,9 +420,9 @@ export function threadList(threads: Thread[], opts: { mailboxes: string[]; domai
415
420
  <form class="filters" method="get" action="/inbox">
416
421
  <input type="hidden" name="status" value="${filter.status}">
417
422
  <nav class="chips" aria-label="${S.filter}">${tab("unanswered", S.filterPending)}${tab("all", S.filterAll)}${tab("archived", S.filterArchived)}</nav>
418
- ${when(opts.mailboxes.length > 1, () => h`<span class="select"><select name="mailbox" aria-label="${S.allMailboxes}" onchange="this.form.submit()">
423
+ ${when(opts.accounts.length > 1, () => h`<span class="select"><select name="mailbox" aria-label="${S.allMailboxes}" onchange="this.form.submit()">
419
424
  <option value="">${S.allMailboxes}</option>
420
- ${join(opts.mailboxes.map(m => h`<option value="${m}" ${raw(m === filter.mailbox ? "selected" : "")}>${m}</option>`))}
425
+ ${join(opts.accounts.map(m => h`<option value="${m}" ${raw(m === filter.mailbox ? "selected" : "")}>${m}</option>`))}
421
426
  </select></span>`)}
422
427
  </form>
423
428
  </header>
@@ -425,16 +430,25 @@ export function threadList(threads: Thread[], opts: { mailboxes: string[]; domai
425
430
  </section>`;
426
431
  }
427
432
 
428
- function threadRow(t: Thread, opts: { mailboxes: string[]; filter: InboxFilter; own: Set<string>; current: string | null }): View {
429
- const people = t.participants.filter(p => !opts.own.has(p));
433
+ interface ThreadListOptions {
434
+ /** Mailbox ids and catch-all addresses, as filter values. */
435
+ accounts: string[];
436
+ accountOf: (t: Thread) => string;
437
+ filter: InboxFilter;
438
+ own: (address: string) => boolean;
439
+ current: string | null;
440
+ }
441
+
442
+ function threadRow(t: Thread, opts: ThreadListOptions): View {
443
+ const people = t.participants.filter(p => !opts.own(p));
430
444
  return h`<a class="row ${t.unread ? "unread" : ""}" href="/threads/${t.id}?${inboxQuery(opts.filter)}" ${raw(t.id === opts.current ? 'aria-current="page"' : "")}>
431
445
  <span class="avatar" aria-hidden="true">${initials(people[0] ?? t.mailbox)}</span>
432
446
  <span class="row-main">
433
447
  <span class="row-top"><span class="who">${people.join(", ") || t.mailbox}</span><time datetime="${t.last_at}">${formatDate(t.last_at)}</time></span>
434
448
  <span class="row-subject">${t.subject || "—"}</span>
435
- ${when(t.has_draft || opts.mailboxes.length > 1 || t.unread, () => h`<span class="row-tags">
449
+ ${when(t.has_draft || opts.accounts.length > 1 || t.unread, () => h`<span class="row-tags">
436
450
  ${when(t.has_draft, () => h`<span class="badge draft">${S.hasDraft}</span>`)}
437
- ${when(opts.mailboxes.length > 1, () => mailboxBadge(t.mailbox))}
451
+ ${when(opts.accounts.length > 1, () => mailboxBadge(opts.accountOf(t)))}
438
452
  ${when(t.unread, () => h`<span class="dot" title="${S.unread}"></span>`)}
439
453
  </span>`)}
440
454
  </span>
@@ -452,11 +466,11 @@ export interface ThreadEntry {
452
466
  }
453
467
 
454
468
  /** The conversation, oldest first, with day separators, a reply box and the context panel. */
455
- export function threadView(thread: Thread, entries: ThreadEntry[], ctx: ContextView, opts: { back: string; filter: InboxFilter; own: Set<string>; reply: { allowed: boolean; replyAll: boolean } }): View {
469
+ export function threadView(thread: Thread, entries: ThreadEntry[], ctx: ContextView, opts: { back: string; filter: InboxFilter; own: (address: string) => boolean; account: string; reply: { allowed: boolean; replyAll: boolean } }): View {
456
470
  const query = inboxQuery(opts.filter);
457
471
  const rows = contextRows(ctx);
458
- const people = thread.participants.filter(p => !opts.own.has(p));
459
- const title = h`<span class="thread-subject">${thread.subject || "—"}</span><span class="thread-meta">${[...people, thread.mailbox].join(" · ")}</span>`;
472
+ const people = thread.participants.filter(p => !opts.own(p));
473
+ const title = h`<span class="thread-subject">${thread.subject || "—"}</span><span class="thread-meta">${[...people, opts.account].join(" · ")}</span>`;
460
474
  const items: View[] = [];
461
475
  let day = "";
462
476
  for (const entry of entries) {