inboxer 0.4.12 → 0.5.1

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 (50) hide show
  1. package/README.md +40 -20
  2. package/dist/app.js +4 -3
  3. package/dist/config.d.ts +2 -4
  4. package/dist/config.js +13 -4
  5. package/dist/core/address.d.ts +5 -1
  6. package/dist/core/address.js +11 -1
  7. package/dist/core/mail.d.ts +24 -13
  8. package/dist/core/mail.js +158 -85
  9. package/dist/core/sync.d.ts +6 -0
  10. package/dist/core/sync.js +22 -7
  11. package/dist/core/threads.d.ts +2 -0
  12. package/dist/core/threads.js +12 -1
  13. package/dist/index.d.ts +3 -3
  14. package/dist/index.js +5 -5
  15. package/dist/mcp.js +8 -8
  16. package/dist/provider/index.d.ts +2 -1
  17. package/dist/provider/index.js +10 -6
  18. package/dist/provider/kapso.d.ts +8 -0
  19. package/dist/provider/kapso.js +198 -0
  20. package/dist/provider/resend.d.ts +1 -1
  21. package/dist/provider/resend.js +14 -10
  22. package/dist/provider/types.d.ts +35 -16
  23. package/dist/store.d.ts +2 -2
  24. package/dist/store.js +4 -4
  25. package/dist/types.d.ts +10 -2
  26. package/dist/ui/routes.js +15 -11
  27. package/dist/ui/static/app.js +19 -3
  28. package/dist/ui/static/style.css +21 -5
  29. package/dist/ui/views.d.ts +7 -5
  30. package/dist/ui/views.js +39 -23
  31. package/package.json +1 -1
  32. package/skills/inboxer/SKILL.md +15 -8
  33. package/src/app.ts +4 -3
  34. package/src/config.ts +10 -3
  35. package/src/core/address.ts +13 -1
  36. package/src/core/mail.ts +162 -89
  37. package/src/core/sync.ts +23 -7
  38. package/src/core/threads.ts +12 -1
  39. package/src/index.ts +10 -8
  40. package/src/mcp.ts +8 -8
  41. package/src/provider/index.ts +9 -5
  42. package/src/provider/kapso.ts +251 -0
  43. package/src/provider/resend.ts +15 -11
  44. package/src/provider/types.ts +38 -14
  45. package/src/store.ts +4 -4
  46. package/src/types.ts +10 -2
  47. package/src/ui/routes.ts +16 -11
  48. package/src/ui/static/app.js +19 -3
  49. package/src/ui/static/style.css +21 -5
  50. package/src/ui/views.ts +41 -24
package/src/ui/routes.ts CHANGED
@@ -34,7 +34,11 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
34
34
  const secret = cfg.ui.cookieSecret;
35
35
  const cookieOptions = { httpOnly: true, secure: true, sameSite: "Lax", path: "/", maxAge: COOKIE_MAX_AGE } as const;
36
36
 
37
- const hue = V.accentHue([...new Set(Object.values(cfg.mailboxes).map(m => domainOf(m.address)))]);
37
+ const mailDomains = (mailboxes: { address: string; kind: string }[]): string[] =>
38
+ [...new Set(mailboxes.filter(m => m.kind === "mail").map(m => domainOf(m.address)))];
39
+ const mailboxesOf = (session: Session) => mail.listMailboxes(session.scope).filter(m => m.id !== CATCHALL);
40
+ const hue = V.accentHue(mailDomains(mail.listMailboxes(null).filter(m => m.id !== CATCHALL)));
41
+ const isChat = (mailbox: string): boolean => mail.kindOf(mailbox) === "chat";
38
42
  const own = (address: string): boolean => mail.isOwn(address);
39
43
  /** Recipients that are our own addresses are implied by the mailbox badge. */
40
44
  const shown = (m: MessageView): MessageView => ({
@@ -43,9 +47,9 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
43
47
  cc: m.cc.filter(a => !own(a)),
44
48
  });
45
49
 
46
- /** Mailboxes a session can send from: every one in its scope but the catch-all. */
47
- const senders = (session: Session): V.Mailbox[] => mail.listMailboxes(session.scope).filter(m => m.id !== CATCHALL);
48
- const domainsOf = (session: Session): string[] => [...new Set(senders(session).map(m => domainOf(m.address)))];
50
+ /** Mailboxes a session can start new mail from: the mail ones in its scope it may write in, but the catch-all. */
51
+ const senders = (session: Session): V.Mailbox[] => mailboxesOf(session).filter(m => m.kind === "mail" && mail.uiCanWrite(m.id));
52
+ const domainsOf = (session: Session): string[] => mailDomains(mailboxesOf(session));
49
53
 
50
54
  const page = async (c: Context<UiEnv>, title: string, body: V.View, current: V.Page, status: 200 | 400 | 401 | 404 = 200, fullScreen = false) => {
51
55
  const session = c.get("session");
@@ -106,7 +110,7 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
106
110
  const draft = await mail.requireMessage(id, c.get("session").scope);
107
111
  if (draft.status === "discarded") return V.draftDone(id, S.discarded);
108
112
  if (draft.status !== "draft") return V.messageBubble(shown(toView(draft)), false);
109
- return V.draftCard(draft);
113
+ return V.draftCard(draft, mail.uiCanWrite(draft.mailbox));
110
114
  };
111
115
 
112
116
  app.get("/", async c => {
@@ -133,7 +137,7 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
133
137
  return c.body(null, 204);
134
138
  }
135
139
  const form = { to: draft.to.join(", "), cc: draft.cc.join(", "), subject: draft.subject, text: draft.text };
136
- return c.html(V.draftEditor(draft, form, null));
140
+ return c.html(V.draftEditor(draft, form, null, isChat(draft.mailbox)));
137
141
  });
138
142
 
139
143
  app.post("/drafts/:id/save", async c => {
@@ -152,7 +156,7 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
152
156
  c.header("HX-Refresh", "true");
153
157
  return c.html(await draftView(c, id));
154
158
  } catch (err) {
155
- if (err instanceof ConflictError) return c.html(V.draftEditor(err.current, form, err.current));
159
+ if (err instanceof ConflictError) return c.html(V.draftEditor(err.current, form, err.current, isChat(err.current.mailbox)));
156
160
  if (err instanceof InvalidRequestError) return c.html(V.draftDone(id, err.message));
157
161
  throw err;
158
162
  }
@@ -213,7 +217,7 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
213
217
  const filter = inboxFilter(c);
214
218
  const threads = await mail.listThreads({ mailbox: filter.mailbox || undefined, status: filter.status as ThreadStatus, limit: 200 }, session.scope);
215
219
  const accounts = await mail.listAccounts(session.scope);
216
- return V.threadList(threads, { accounts, accountOf: t => mail.accountOf(t), addressOf: a => mail.addressOf(a), domains: domainsOf(session), filter, own, current });
220
+ return V.threadList(threads, { accounts, accountOf: t => mail.accountOf(t), addressOf: a => mail.addressOf(a), domains: domainsOf(session), filter, own, isChat, current });
217
221
  };
218
222
 
219
223
  app.get("/inbox", async c => page(c, S.navInbox, V.inboxPage(await threadList(c, null), null), "inbox"));
@@ -230,11 +234,12 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
230
234
  const people = thread.participants.filter(p => !own(p));
231
235
  const entries = await Promise.all(messages.map(async m => ({
232
236
  at: m.date,
233
- view: m.status === "draft" ? V.draftCard(await mail.store.requireMessage(m.id)) : V.messageBubble(shown(m), people.length > 1),
237
+ view: m.status === "draft" ? V.draftCard(await mail.store.requireMessage(m.id), mail.uiCanWrite(m.mailbox)) : V.messageBubble(shown(m), people.length > 1),
234
238
  })));
235
239
  const account = mail.accountOf(thread);
236
- const reply = { allowed: account !== CATCHALL && (thread.mailbox === CATCHALL || senders(session).some(m => m.id === thread.mailbox)), replyAll: people.length > 1 };
237
- return { thread, view: V.threadView(thread, entries, { context, contacts }, { back, filter: inboxFilter(c), own, account, reply }) };
240
+ const chat = isChat(thread.mailbox);
241
+ const reply = { allowed: account !== CATCHALL && mail.uiCanWrite(thread.mailbox), replyAll: people.length > 1 && !chat };
242
+ return { thread, view: V.threadView(thread, entries, { context, contacts }, { back, filter: inboxFilter(c), own, account, chat, reply }) };
238
243
  };
239
244
 
240
245
  app.get("/threads/:id", async c => {
@@ -1,4 +1,4 @@
1
- // New mail opens as a modal sheet; a click on its backdrop or a [data-close] button closes it.
1
+ // New mail opens as a modal sheet; a [data-close] button closes it, and so does a click outside it (closedby="any").
2
2
  document.addEventListener("click", event => {
3
3
  const target = event.target instanceof Element ? event.target : null;
4
4
  if (!target) return;
@@ -8,13 +8,29 @@ document.addEventListener("click", event => {
8
8
  dialog.querySelector("#compose-to").focus();
9
9
  } else if (target.closest("[data-close]")) {
10
10
  target.closest("dialog").close();
11
- } else if (target instanceof HTMLDialogElement && target.open) {
12
- target.close();
13
11
  } else if (target.closest("[data-context-toggle]")) {
14
12
  document.body.classList.toggle("context-open");
15
13
  }
16
14
  });
17
15
 
16
+ // Where closedby is missing, a press and a release that are both outside the sheet close it,
17
+ // so a text selection dragged onto the backdrop does not.
18
+ if (!("closedBy" in HTMLDialogElement.prototype)) {
19
+ const outside = (event, dialog) => {
20
+ const box = dialog.getBoundingClientRect();
21
+ return event.clientX < box.left || event.clientX > box.right || event.clientY < box.top || event.clientY > box.bottom;
22
+ };
23
+ let pressed = null;
24
+ document.addEventListener("pointerdown", event => {
25
+ const dialog = event.target instanceof Element ? event.target.closest('dialog[closedby="any"]') : null;
26
+ pressed = dialog && outside(event, dialog) ? dialog : null;
27
+ });
28
+ document.addEventListener("pointerup", event => {
29
+ if (pressed?.open && outside(event, pressed)) pressed.close();
30
+ pressed = null;
31
+ });
32
+ }
33
+
18
34
  // A draft's editor opens in the edit sheet; one draft is edited at a time.
19
35
  document.addEventListener("htmx:afterSwap", event => {
20
36
  const sheet = event.detail.target;
@@ -29,6 +29,7 @@
29
29
 
30
30
  * { box-sizing: border-box; }
31
31
  [hidden] { display: none !important; }
32
+ .visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
32
33
  body { margin: 0; background: var(--bg); color: var(--fg); }
33
34
  a { color: inherit; text-decoration: none; }
34
35
  h1 { font-size: 2rem; line-height: 1.1; letter-spacing: -0.04em; font-weight: 700; margin: 0 0 24px; }
@@ -155,6 +156,9 @@ body.full .tabbar { display: none; }
155
156
  display: inline-flex; align-items: center; justify-content: center; background: none; color: var(--fg);
156
157
  }
157
158
  .icon-btn:hover { background: var(--soft); border: none; }
159
+ /* A file picker's label carries the focus ring of the input hidden inside it. */
160
+ label.icon-btn { position: relative; }
161
+ label.icon-btn:has(:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
158
162
  .thread-head form { margin: 0; }
159
163
  .thread-title {
160
164
  flex: 1; min-width: 0; height: auto; padding: 4px 6px; border: none; border-radius: 12px;
@@ -219,7 +223,7 @@ body.context-open .context-panel { display: flex; flex-direction: column; }
219
223
  body.context-open .context-panel {
220
224
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; height: 70dvh;
221
225
  border-radius: 22px 22px 0 0; box-shadow: 0 -8px 30px rgb(0 0 0 / .25);
222
- padding-bottom: env(safe-area-inset-bottom); animation: rise .2s ease-out;
226
+ padding-bottom: env(safe-area-inset-bottom);
223
227
  }
224
228
  .context-panel::before {
225
229
  content: ""; position: absolute; top: 8px; left: 50%; width: 40px; height: 5px; margin-left: -20px;
@@ -237,6 +241,9 @@ body.context-open .context-panel { display: flex; flex-direction: column; }
237
241
  body.context-open .context-panel { grid-column: 2; grid-row: 1 / -1; border-left: 1px solid var(--line); min-height: 0; }
238
242
  .composer { padding: 0 24px 20px; background: none; border: none; }
239
243
  }
244
+ @media (max-width: 899px) and (prefers-reduced-motion: no-preference) {
245
+ body.context-open .context-panel, dialog.sheet[open] { animation: rise .2s ease-out; }
246
+ }
240
247
  @keyframes rise { from { transform: translateY(100%); } to { transform: translateY(0); } }
241
248
 
242
249
  /* Context rows, shared by the panel and the folded block on a draft */
@@ -254,8 +261,9 @@ dialog.sheet {
254
261
  border: none; border-radius: 22px 22px 0 0; background: var(--bg); color: var(--fg);
255
262
  box-shadow: 0 -8px 30px rgb(0 0 0 / .25);
256
263
  }
257
- dialog.sheet[open] { animation: rise .2s ease-out; }
258
- dialog.sheet::backdrop { background: var(--backdrop); }
264
+ /* Scrolling inside the sheet or over its backdrop stays off the page behind. */
265
+ dialog.sheet:modal { overscroll-behavior: contain; }
266
+ dialog.sheet::backdrop { background: var(--backdrop); overflow: hidden; overscroll-behavior: contain; }
259
267
  dialog.sheet form { position: relative; height: 100%; display: flex; flex-direction: column; }
260
268
  .grabber { width: 40px; height: 5px; border-radius: 999px; background: var(--line); margin: 8px auto 9px; flex: none; }
261
269
  .sheet-close { position: absolute; top: 8px; right: 8px; color: var(--muted); z-index: 1; }
@@ -263,6 +271,7 @@ dialog.sheet .field { padding: 0 16px; }
263
271
  dialog.sheet .field.compact { padding-right: 60px; margin-top: 12px; }
264
272
  dialog.sheet .field output { font-family: var(--mono); font-size: .8rem; padding: 10px 0; }
265
273
  dialog.sheet textarea { flex: 1; min-height: 0; margin: 0; padding: 12px 16px; resize: none; }
274
+ dialog.sheet textarea:focus + .sheet-actions { border-top-color: var(--focus); }
266
275
  .sheet-actions {
267
276
  display: flex; gap: 8px;
268
277
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
@@ -275,7 +284,6 @@ dialog.sheet .note { margin: 0 16px 8px; flex: none; }
275
284
  .sheet-files { flex: 1; min-width: 0; align-self: center; font-family: var(--mono); font-size: .75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
276
285
  @media (min-width: 900px) {
277
286
  dialog.sheet { margin: auto; width: 640px; height: min(640px, 80dvh); border-radius: 18px; }
278
- dialog.sheet[open] { animation: none; }
279
287
  .grabber { visibility: hidden; }
280
288
  }
281
289
 
@@ -299,6 +307,7 @@ dialog.sheet .note { margin: 0 16px 8px; flex: none; }
299
307
  .note { background: var(--soft); border-radius: 10px; padding: 6px 10px; margin: 12px 0; white-space: pre-wrap; font-size: .8125rem; color: var(--muted); }
300
308
  .messages .note { background: var(--chip); }
301
309
  .body { white-space: pre-wrap; overflow-wrap: anywhere; margin: 14px 0 0; font: inherit; }
310
+ .body a { text-decoration: underline; text-underline-offset: 2px; }
302
311
  .images { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin-top: 12px; }
303
312
  .images a { display: block; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--soft); }
304
313
  .images img { width: 100%; height: 100%; object-fit: cover; display: block; transition: opacity .15s; }
@@ -330,8 +339,15 @@ dialog.sheet .note { margin: 0 16px 8px; flex: none; }
330
339
  .pending-row span { min-width: 0; overflow-wrap: anywhere; color: var(--muted); }
331
340
  .pending-row strong { color: var(--fg); font-weight: 500; }
332
341
  .countdown { position: absolute; left: 0; top: -1px; height: 1px; width: 100%; background: var(--accent); transform-origin: left; animation: countdown linear forwards; }
333
- .messages .countdown { left: 14px; right: 14px; width: auto; top: auto; bottom: 6px; }
342
+ .messages .countdown {
343
+ inset: -1.5px; width: auto; height: auto; padding: 1.5px; border-radius: inherit; pointer-events: none;
344
+ background: conic-gradient(var(--accent) var(--countdown-angle), transparent 0);
345
+ mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
346
+ animation-name: countdown-ring;
347
+ }
348
+ @property --countdown-angle { syntax: "<angle>"; inherits: false; initial-value: 360deg; }
334
349
  @keyframes countdown { from { transform: scaleX(1); } to { transform: scaleX(0); } }
350
+ @keyframes countdown-ring { from { --countdown-angle: 360deg; } to { --countdown-angle: 0deg; } }
335
351
  .sheet-conflict { padding: 0 16px 8px; max-height: 40%; overflow-y: auto; flex: none; }
336
352
  .sheet-conflict .warn { color: var(--danger); font-weight: 600; margin: 0; }
337
353
  .sheet-conflict details summary { margin-top: 8px; }
package/src/ui/views.ts CHANGED
@@ -76,7 +76,7 @@ function displayName(address: string): string {
76
76
  }
77
77
 
78
78
  function initials(address: string): string {
79
- const name = displayName(address);
79
+ const name = displayName(address).replace(/^\+/, "");
80
80
  const words = (name.includes("@") ? name.split("@")[0]! : name).split(/[\s._-]+/).filter(Boolean);
81
81
  return (words.length > 1 ? words[0]![0]! + words[1]![0]! : (words[0] ?? "?").slice(0, 2)).toUpperCase();
82
82
  }
@@ -143,7 +143,7 @@ ${when(opts.signedIn, () => h`<nav class="tabbar" id="tabbar" data-live aria-lab
143
143
  ${link("settings", "/settings", S.navSettings, "settings")}
144
144
  </nav>`)}
145
145
  ${when(opts.signedIn && canSend, () => composeDialog(opts.senders!))}
146
- ${when(opts.signedIn, () => h`<dialog class="sheet" id="edit-sheet" aria-label="${S.edit}"></dialog>`)}
146
+ ${when(opts.signedIn, () => h`<dialog class="sheet" id="edit-sheet" closedby="any" aria-label="${S.edit}"></dialog>`)}
147
147
  </body>
148
148
  </html>`;
149
149
  }
@@ -153,7 +153,7 @@ function composeDialog(senders: Mailbox[]): View {
153
153
  const from = senders.length > 1
154
154
  ? h`<span class="select"><select id="compose-from" name="mailbox">${join(senders.map(m => h`<option value="${m.id}">${m.address}</option>`))}</select></span>`
155
155
  : h`<input type="hidden" name="mailbox" value="${senders[0]!.id}"><output id="compose-from">${senders[0]!.address}</output>`;
156
- return h`<dialog class="sheet" id="compose" aria-label="${S.newMail}">${mailForm("compose", "/compose", {
156
+ return h`<dialog class="sheet" id="compose" closedby="any" aria-label="${S.newMail}">${mailForm("compose", "/compose", {
157
157
  head: h`<div class="field compact"><label for="compose-from">${S.from}</label>${from}</div>`, headIsRow: true, to: "", cc: "", subject: "", text: "",
158
158
  })}</dialog>`;
159
159
  }
@@ -187,7 +187,7 @@ function mailForm(id: string, action: string, f: { head: View; headIsRow?: boole
187
187
  </div>
188
188
  <textarea name="text" aria-label="${S.body}" required>${f.text}</textarea>
189
189
  <div class="sheet-actions">
190
- <label class="icon-btn" aria-label="${S.attach}">${icon("attach")}<input type="file" name="files" multiple hidden data-file-names></label>
190
+ <label class="icon-btn">${icon("attach")}<input type="file" name="files" multiple class="visually-hidden" aria-label="${S.attach}" data-file-names></label>
191
191
  <output class="sheet-files"></output>
192
192
  <button type="submit" name="action" value="save">${S.saveDraft}</button>
193
193
  <button type="submit" name="action" value="send" class="primary">${S.send}${icon("send")}</button>
@@ -255,6 +255,20 @@ function withoutImagePlaceholders(m: MessageView): string {
255
255
  return text.replace(/\n{3,}/g, "\n\n").trim();
256
256
  }
257
257
 
258
+ /** Plain text with its web addresses turned into links; the punctuation that closes a sentence stays outside them. */
259
+ function linked(text: string): View {
260
+ const parts: View[] = [];
261
+ let last = 0;
262
+ for (const match of text.matchAll(/https?:\/\/[^\s<>"]+/g)) {
263
+ let url = match[0];
264
+ while (/[.,;:!?'*]$/.test(url) || (url.endsWith(")") && url.split(")").length > url.split("(").length)) url = url.slice(0, -1);
265
+ parts.push(h`${text.slice(last, match.index)}<a href="${url}" target="_blank" rel="noopener noreferrer">${url}</a>`);
266
+ last = match.index + url.length;
267
+ }
268
+ parts.push(h`${text.slice(last)}`);
269
+ return join(parts);
270
+ }
271
+
258
272
  function recipients(m: MessageView): View | "" {
259
273
  if (!m.to.length && !m.cc.length) return "";
260
274
  return h`<div class="meta">${when(m.to.length, () => h`<span>${S.to}: ${m.to.join(", ")}</span>`)}${when(m.cc.length, () => h`<span>${S.cc}: ${m.cc.join(", ")}</span>`)}</div>`;
@@ -267,7 +281,7 @@ export function messageBubble(m: MessageView, showSender: boolean): View {
267
281
  return h`<article class="msg ${mine ? "mine" : "theirs"}" id="m-${m.id}">
268
282
  ${when(showSender && !mine, () => h`<div class="msg-from">${displayName(m.from)}</div>`)}
269
283
  ${extra ? recipients(m) : ""}
270
- <pre class="body">${withoutImagePlaceholders(m)}</pre>
284
+ <pre class="body">${linked(withoutImagePlaceholders(m))}</pre>
271
285
  ${attachments(m)}
272
286
  <span class="msg-time">${formatTime(m.date)}${mine ? ` · ${m.status}` : ""}</span>
273
287
  </article>`;
@@ -305,8 +319,8 @@ function pendingCard(d: Message): View {
305
319
  </article>`;
306
320
  }
307
321
 
308
- /** A draft for review, on our side of its thread. */
309
- export function draftCard(d: Message): View {
322
+ /** A draft for review, on our side of its thread; without actions where the session can only read. */
323
+ export function draftCard(d: Message, canAct: boolean): View {
310
324
  if (d.pending) return pendingCard(d);
311
325
  return h`<article class="card draft" id="draft-${d.id}">
312
326
  <div class="meta">
@@ -316,16 +330,16 @@ export function draftCard(d: Message): View {
316
330
  </div>
317
331
  <div class="draft-head">
318
332
  <div class="meta"><span>${S.to}: <strong>${d.to.join(", ")}</strong></span>${when(d.cc.length, () => h`<span>${S.cc}: ${d.cc.join(", ")}</span>`)}</div>
319
- <div class="subject">${d.subject}</div>
333
+ ${when(d.subject, () => h`<div class="subject">${d.subject}</div>`)}
320
334
  </div>
321
335
  ${when(d.note, () => h`<div class="note">${d.note}</div>`)}
322
- <pre class="body">${d.text}</pre>
336
+ <pre class="body">${linked(d.text)}</pre>
323
337
  ${attachments(d)}
324
- <div class="actions">
338
+ ${when(canAct, () => h`<div class="actions">
325
339
  <button class="danger" hx-post="/drafts/${d.id}/discard" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.discard}</button>
326
340
  <button hx-get="/drafts/${d.id}/edit" hx-target="#edit-sheet" hx-swap="innerHTML">${S.edit}</button>
327
341
  <button class="primary" hx-post="/drafts/${d.id}/send" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.send}</button>
328
- </div>
342
+ </div>`)}
329
343
  </article>`;
330
344
  }
331
345
 
@@ -336,8 +350,8 @@ export interface DraftForm {
336
350
  text: string;
337
351
  }
338
352
 
339
- /** The edit sheet's content; one draft is edited at a time. */
340
- export function draftEditor(d: Message, form: DraftForm, conflict: Message | null): View {
353
+ /** The edit sheet's content; one draft is edited at a time. A chat message has a recipient and a body only. */
354
+ export function draftEditor(d: Message, form: DraftForm, conflict: Message | null, chat: boolean): View {
341
355
  const version = conflict ? conflict.version : d.version;
342
356
  return h`<form class="${conflict ? "conflict" : ""}" hx-post="/drafts/${d.id}/save" hx-target="#edit-sheet" hx-swap="innerHTML" data-drop>
343
357
  <div class="grabber" aria-hidden="true"></div>
@@ -351,23 +365,23 @@ export function draftEditor(d: Message, form: DraftForm, conflict: Message | nul
351
365
  <summary>${S.currentVersion}</summary>
352
366
  <div class="meta"><span>${S.to}: ${conflict!.to.join(", ")}</span>${when(conflict!.cc.length, () => h`<span>${S.cc}: ${conflict!.cc.join(", ")}</span>`)}</div>
353
367
  <div class="subject">${conflict!.subject}</div>
354
- <pre class="body">${conflict!.text}</pre>
368
+ <pre class="body">${linked(conflict!.text)}</pre>
355
369
  </details>
356
370
  </div>`)}
357
371
  <input type="hidden" name="version" value="${version}">
358
372
  <div class="field">
359
373
  <label for="to-${d.id}">${S.to}</label>
360
374
  <input id="to-${d.id}" name="to" value="${form.to}" autocomplete="off" required>
361
- ${when(!form.cc, () => h`<button type="button" class="link" onclick="this.remove();var r=document.getElementById('cc-row-${d.id}');r.hidden=false;r.querySelector('input').focus()">${S.cc}</button>`)}
375
+ ${when(!chat && !form.cc, () => h`<button type="button" class="link" onclick="this.remove();var r=document.getElementById('cc-row-${d.id}');r.hidden=false;r.querySelector('input').focus()">${S.cc}</button>`)}
362
376
  </div>
363
- <div class="field" id="cc-row-${d.id}" ${raw(form.cc ? "" : "hidden")}>
377
+ ${when(!chat, () => h`<div class="field" id="cc-row-${d.id}" ${raw(form.cc ? "" : "hidden")}>
364
378
  <label for="cc-${d.id}">${S.cc}</label>
365
379
  <input id="cc-${d.id}" name="cc" value="${form.cc}" autocomplete="off">
366
380
  </div>
367
381
  <div class="field">
368
382
  <label for="subject-${d.id}">${S.subject}</label>
369
383
  <input id="subject-${d.id}" name="subject" value="${form.subject}" required>
370
- </div>
384
+ </div>`)}
371
385
  <textarea id="text-${d.id}" name="text" aria-label="${S.body}" required>${form.text}</textarea>
372
386
  <div class="sheet-actions">
373
387
  ${draftFiles(d, null)}
@@ -380,7 +394,7 @@ export function draftEditor(d: Message, form: DraftForm, conflict: Message | nul
380
394
  /** The editor's attachment list with remove buttons, and the picker that drag and drop also feeds. */
381
395
  export function draftFiles(d: Message, error: string | null): View {
382
396
  return h`<div class="draft-files" id="files-${d.id}">
383
- <label class="icon-btn" aria-label="${S.attach}">${icon("attach")}<input type="file" name="files" multiple hidden hx-post="/drafts/${d.id}/attachments" hx-encoding="multipart/form-data" hx-trigger="change" hx-target="#files-${d.id}" hx-swap="outerHTML" hx-include="this"></label>
397
+ <label class="icon-btn">${icon("attach")}<input type="file" name="files" multiple class="visually-hidden" aria-label="${S.attach}" hx-post="/drafts/${d.id}/attachments" hx-encoding="multipart/form-data" hx-trigger="change" hx-target="#files-${d.id}" hx-swap="outerHTML" hx-include="this"></label>
384
398
  ${join(d.attachments.map(a => h`<span class="file"><span>${a.filename}</span><span class="size">${formatSize(a.size)}</span><button type="button" class="link" aria-label="${S.remove} ${a.filename}" hx-post="/drafts/${d.id}/attachments/${a.id}/remove" hx-target="#files-${d.id}" hx-swap="outerHTML">×</button></span>`))}
385
399
  ${when(error, () => h`<p class="warn">${error}</p>`)}
386
400
  </div>`;
@@ -454,16 +468,18 @@ interface ThreadListOptions {
454
468
  addressOf: (account: string) => string;
455
469
  filter: InboxFilter;
456
470
  own: (address: string) => boolean;
471
+ isChat: (mailbox: string) => boolean;
457
472
  current: string | null;
458
473
  }
459
474
 
460
475
  function threadRow(t: Thread, opts: ThreadListOptions): View {
461
- const people = t.participants.filter(p => !opts.own(p));
476
+ const chat = opts.isChat(t.mailbox);
477
+ const people = t.participants.filter(p => !opts.own(p)).map(p => (chat && t.names[p]) || p);
462
478
  return h`<a class="row ${t.unread ? "unread" : ""}" href="/threads/${t.id}?${inboxQuery(opts.filter)}" ${raw(t.id === opts.current ? 'aria-current="page"' : "")}>
463
479
  <span class="avatar" aria-hidden="true">${initials(people[0] ?? t.mailbox)}</span>
464
480
  <span class="row-main">
465
481
  <span class="row-top"><span class="who">${people.join(", ") || t.mailbox}</span><time datetime="${t.last_at}">${formatDate(t.last_at)}</time></span>
466
- <span class="row-subject">${t.subject || "—"}</span>
482
+ ${when(!chat, () => h`<span class="row-subject">${t.subject || "—"}</span>`)}
467
483
  ${when(t.has_draft || opts.accounts.length > 1 || t.unread, () => h`<span class="row-tags">
468
484
  ${when(t.has_draft, () => h`<span class="badge draft">${S.hasDraft}</span>`)}
469
485
  ${when(opts.accounts.length > 1, () => mailboxBadge(opts.addressOf(opts.accountOf(t))))}
@@ -483,12 +499,13 @@ export interface ThreadEntry {
483
499
  view: View;
484
500
  }
485
501
 
486
- /** The conversation, oldest first, with day separators, a reply box and the context panel. */
487
- 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 {
502
+ /** The conversation, oldest first, with day separators, a reply box and the context panel. A chat is titled by who it is with. */
503
+ export function threadView(thread: Thread, entries: ThreadEntry[], ctx: ContextView, opts: { back: string; filter: InboxFilter; own: (address: string) => boolean; account: string; chat: boolean; reply: { allowed: boolean; replyAll: boolean } }): View {
488
504
  const query = inboxQuery(opts.filter);
489
505
  const rows = contextRows(ctx);
490
506
  const people = thread.participants.filter(p => !opts.own(p));
491
- const title = h`<span class="thread-subject">${thread.subject || "—"}</span><span class="thread-meta">${[...people, opts.account].join(" · ")}</span>`;
507
+ const heading = opts.chat ? people.map(p => thread.names[p] ?? p).join(", ") : thread.subject;
508
+ const title = h`<span class="thread-subject">${heading || "—"}</span><span class="thread-meta">${[...people, opts.account].join(" · ")}</span>`;
492
509
  const items: View[] = [];
493
510
  let day = "";
494
511
  for (const entry of entries) {
@@ -509,7 +526,7 @@ export function threadView(thread: Thread, entries: ThreadEntry[], ctx: ContextV
509
526
  <div class="messages" id="messages" data-live data-scroll-end>${join(items)}</div>
510
527
  ${when(opts.reply.allowed, () => h`<form class="composer" method="post" action="/threads/${thread.id}/reply?${query}">
511
528
  ${when(opts.reply.replyAll, () => h`<label class="reply-all"><input type="checkbox" name="reply_all" value="1">${S.replyAll}</label>`)}
512
- <button type="button" class="icon-btn" aria-label="${S.fullReply}" title="${S.fullReply}" hx-get="/threads/${thread.id}/reply/full?${query}" hx-include="closest form" hx-target="#edit-sheet" hx-swap="innerHTML">${icon("plus")}</button>
529
+ ${when(!opts.chat, () => h`<button type="button" class="icon-btn" aria-label="${S.fullReply}" title="${S.fullReply}" hx-get="/threads/${thread.id}/reply/full?${query}" hx-include="closest form" hx-target="#edit-sheet" hx-swap="innerHTML">${icon("plus")}</button>`)}
513
530
  <textarea name="text" rows="1" aria-label="${S.reply}" placeholder="${S.reply}…" required></textarea>
514
531
  <button type="submit" name="action" value="save" class="icon-btn" aria-label="${S.saveDraft}" title="${S.saveDraft}">${icon("drafts")}</button>
515
532
  <button type="submit" name="action" value="send" class="primary send" aria-label="${S.send}" title="${S.send}">${icon("send")}</button>