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
@@ -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; }
@@ -40,16 +40,16 @@ export interface ContextView {
40
40
  context: Context | null;
41
41
  contacts: Contact[];
42
42
  }
43
- /** A draft for review, on our side of its thread. */
44
- export declare function draftCard(d: Message): View;
43
+ /** A draft for review, on our side of its thread; without actions where the session can only read. */
44
+ export declare function draftCard(d: Message, canAct: boolean): View;
45
45
  export interface DraftForm {
46
46
  to: string;
47
47
  cc: string;
48
48
  subject: string;
49
49
  text: string;
50
50
  }
51
- /** The edit sheet's content; one draft is edited at a time. */
52
- export declare function draftEditor(d: Message, form: DraftForm, conflict: Message | null): View;
51
+ /** The edit sheet's content; one draft is edited at a time. A chat message has a recipient and a body only. */
52
+ export declare function draftEditor(d: Message, form: DraftForm, conflict: Message | null, chat: boolean): View;
53
53
  /** The editor's attachment list with remove buttons, and the picker that drag and drop also feeds. */
54
54
  export declare function draftFiles(d: Message, error: string | null): View;
55
55
  export declare function draftDone(id: string, text: string): View;
@@ -71,6 +71,7 @@ interface ThreadListOptions {
71
71
  addressOf: (account: string) => string;
72
72
  filter: InboxFilter;
73
73
  own: (address: string) => boolean;
74
+ isChat: (mailbox: string) => boolean;
74
75
  current: string | null;
75
76
  }
76
77
  /** The thread list and the open thread side by side; a phone shows one of the two. */
@@ -79,12 +80,13 @@ export interface ThreadEntry {
79
80
  at: string;
80
81
  view: View;
81
82
  }
82
- /** The conversation, oldest first, with day separators, a reply box and the context panel. */
83
+ /** The conversation, oldest first, with day separators, a reply box and the context panel. A chat is titled by who it is with. */
83
84
  export declare function threadView(thread: Thread, entries: ThreadEntry[], ctx: ContextView, opts: {
84
85
  back: string;
85
86
  filter: InboxFilter;
86
87
  own: (address: string) => boolean;
87
88
  account: string;
89
+ chat: boolean;
88
90
  reply: {
89
91
  allowed: boolean;
90
92
  replyAll: boolean;
package/dist/ui/views.js CHANGED
@@ -60,7 +60,7 @@ function displayName(address) {
60
60
  return match ? match[1] : bareAddress(address);
61
61
  }
62
62
  function initials(address) {
63
- const name = displayName(address);
63
+ const name = displayName(address).replace(/^\+/, "");
64
64
  const words = (name.includes("@") ? name.split("@")[0] : name).split(/[\s._-]+/).filter(Boolean);
65
65
  return (words.length > 1 ? words[0][0] + words[1][0] : (words[0] ?? "?").slice(0, 2)).toUpperCase();
66
66
  }
@@ -105,7 +105,7 @@ ${when(opts.signedIn, () => h `<nav class="tabbar" id="tabbar" data-live aria-la
105
105
  ${link("settings", "/settings", S.navSettings, "settings")}
106
106
  </nav>`)}
107
107
  ${when(opts.signedIn && canSend, () => composeDialog(opts.senders))}
108
- ${when(opts.signedIn, () => h `<dialog class="sheet" id="edit-sheet" aria-label="${S.edit}"></dialog>`)}
108
+ ${when(opts.signedIn, () => h `<dialog class="sheet" id="edit-sheet" closedby="any" aria-label="${S.edit}"></dialog>`)}
109
109
  </body>
110
110
  </html>`;
111
111
  }
@@ -114,7 +114,7 @@ function composeDialog(senders) {
114
114
  const from = senders.length > 1
115
115
  ? h `<span class="select"><select id="compose-from" name="mailbox">${join(senders.map(m => h `<option value="${m.id}">${m.address}</option>`))}</select></span>`
116
116
  : h `<input type="hidden" name="mailbox" value="${senders[0].id}"><output id="compose-from">${senders[0].address}</output>`;
117
- return h `<dialog class="sheet" id="compose" aria-label="${S.newMail}">${mailForm("compose", "/compose", {
117
+ return h `<dialog class="sheet" id="compose" closedby="any" aria-label="${S.newMail}">${mailForm("compose", "/compose", {
118
118
  head: h `<div class="field compact"><label for="compose-from">${S.from}</label>${from}</div>`, headIsRow: true, to: "", cc: "", subject: "", text: "",
119
119
  })}</dialog>`;
120
120
  }
@@ -146,7 +146,7 @@ function mailForm(id, action, f) {
146
146
  </div>
147
147
  <textarea name="text" aria-label="${S.body}" required>${f.text}</textarea>
148
148
  <div class="sheet-actions">
149
- <label class="icon-btn" aria-label="${S.attach}">${icon("attach")}<input type="file" name="files" multiple hidden data-file-names></label>
149
+ <label class="icon-btn">${icon("attach")}<input type="file" name="files" multiple class="visually-hidden" aria-label="${S.attach}" data-file-names></label>
150
150
  <output class="sheet-files"></output>
151
151
  <button type="submit" name="action" value="save">${S.saveDraft}</button>
152
152
  <button type="submit" name="action" value="send" class="primary">${S.send}${icon("send")}</button>
@@ -207,6 +207,20 @@ function withoutImagePlaceholders(m) {
207
207
  }
208
208
  return text.replace(/\n{3,}/g, "\n\n").trim();
209
209
  }
210
+ /** Plain text with its web addresses turned into links; the punctuation that closes a sentence stays outside them. */
211
+ function linked(text) {
212
+ const parts = [];
213
+ let last = 0;
214
+ for (const match of text.matchAll(/https?:\/\/[^\s<>"]+/g)) {
215
+ let url = match[0];
216
+ while (/[.,;:!?'*]$/.test(url) || (url.endsWith(")") && url.split(")").length > url.split("(").length))
217
+ url = url.slice(0, -1);
218
+ parts.push(h `${text.slice(last, match.index)}<a href="${url}" target="_blank" rel="noopener noreferrer">${url}</a>`);
219
+ last = match.index + url.length;
220
+ }
221
+ parts.push(h `${text.slice(last)}`);
222
+ return join(parts);
223
+ }
210
224
  function recipients(m) {
211
225
  if (!m.to.length && !m.cc.length)
212
226
  return "";
@@ -219,7 +233,7 @@ export function messageBubble(m, showSender) {
219
233
  return h `<article class="msg ${mine ? "mine" : "theirs"}" id="m-${m.id}">
220
234
  ${when(showSender && !mine, () => h `<div class="msg-from">${displayName(m.from)}</div>`)}
221
235
  ${extra ? recipients(m) : ""}
222
- <pre class="body">${withoutImagePlaceholders(m)}</pre>
236
+ <pre class="body">${linked(withoutImagePlaceholders(m))}</pre>
223
237
  ${attachments(m)}
224
238
  <span class="msg-time">${formatTime(m.date)}${mine ? ` · ${m.status}` : ""}</span>
225
239
  </article>`;
@@ -248,8 +262,8 @@ function pendingCard(d) {
248
262
  <i class="countdown" style="animation-duration: ${left}ms"></i>
249
263
  </article>`;
250
264
  }
251
- /** A draft for review, on our side of its thread. */
252
- export function draftCard(d) {
265
+ /** A draft for review, on our side of its thread; without actions where the session can only read. */
266
+ export function draftCard(d, canAct) {
253
267
  if (d.pending)
254
268
  return pendingCard(d);
255
269
  return h `<article class="card draft" id="draft-${d.id}">
@@ -260,20 +274,20 @@ export function draftCard(d) {
260
274
  </div>
261
275
  <div class="draft-head">
262
276
  <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>
263
- <div class="subject">${d.subject}</div>
277
+ ${when(d.subject, () => h `<div class="subject">${d.subject}</div>`)}
264
278
  </div>
265
279
  ${when(d.note, () => h `<div class="note">${d.note}</div>`)}
266
- <pre class="body">${d.text}</pre>
280
+ <pre class="body">${linked(d.text)}</pre>
267
281
  ${attachments(d)}
268
- <div class="actions">
282
+ ${when(canAct, () => h `<div class="actions">
269
283
  <button class="danger" hx-post="/drafts/${d.id}/discard" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.discard}</button>
270
284
  <button hx-get="/drafts/${d.id}/edit" hx-target="#edit-sheet" hx-swap="innerHTML">${S.edit}</button>
271
285
  <button class="primary" hx-post="/drafts/${d.id}/send" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.send}</button>
272
- </div>
286
+ </div>`)}
273
287
  </article>`;
274
288
  }
275
- /** The edit sheet's content; one draft is edited at a time. */
276
- export function draftEditor(d, form, conflict) {
289
+ /** The edit sheet's content; one draft is edited at a time. A chat message has a recipient and a body only. */
290
+ export function draftEditor(d, form, conflict, chat) {
277
291
  const version = conflict ? conflict.version : d.version;
278
292
  return h `<form class="${conflict ? "conflict" : ""}" hx-post="/drafts/${d.id}/save" hx-target="#edit-sheet" hx-swap="innerHTML" data-drop>
279
293
  <div class="grabber" aria-hidden="true"></div>
@@ -287,23 +301,23 @@ export function draftEditor(d, form, conflict) {
287
301
  <summary>${S.currentVersion}</summary>
288
302
  <div class="meta"><span>${S.to}: ${conflict.to.join(", ")}</span>${when(conflict.cc.length, () => h `<span>${S.cc}: ${conflict.cc.join(", ")}</span>`)}</div>
289
303
  <div class="subject">${conflict.subject}</div>
290
- <pre class="body">${conflict.text}</pre>
304
+ <pre class="body">${linked(conflict.text)}</pre>
291
305
  </details>
292
306
  </div>`)}
293
307
  <input type="hidden" name="version" value="${version}">
294
308
  <div class="field">
295
309
  <label for="to-${d.id}">${S.to}</label>
296
310
  <input id="to-${d.id}" name="to" value="${form.to}" autocomplete="off" required>
297
- ${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>`)}
311
+ ${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>`)}
298
312
  </div>
299
- <div class="field" id="cc-row-${d.id}" ${raw(form.cc ? "" : "hidden")}>
313
+ ${when(!chat, () => h `<div class="field" id="cc-row-${d.id}" ${raw(form.cc ? "" : "hidden")}>
300
314
  <label for="cc-${d.id}">${S.cc}</label>
301
315
  <input id="cc-${d.id}" name="cc" value="${form.cc}" autocomplete="off">
302
316
  </div>
303
317
  <div class="field">
304
318
  <label for="subject-${d.id}">${S.subject}</label>
305
319
  <input id="subject-${d.id}" name="subject" value="${form.subject}" required>
306
- </div>
320
+ </div>`)}
307
321
  <textarea id="text-${d.id}" name="text" aria-label="${S.body}" required>${form.text}</textarea>
308
322
  <div class="sheet-actions">
309
323
  ${draftFiles(d, null)}
@@ -315,7 +329,7 @@ export function draftEditor(d, form, conflict) {
315
329
  /** The editor's attachment list with remove buttons, and the picker that drag and drop also feeds. */
316
330
  export function draftFiles(d, error) {
317
331
  return h `<div class="draft-files" id="files-${d.id}">
318
- <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>
332
+ <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>
319
333
  ${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>`))}
320
334
  ${when(error, () => h `<p class="warn">${error}</p>`)}
321
335
  </div>`;
@@ -371,12 +385,13 @@ export function threadList(threads, opts) {
371
385
  </section>`;
372
386
  }
373
387
  function threadRow(t, opts) {
374
- const people = t.participants.filter(p => !opts.own(p));
388
+ const chat = opts.isChat(t.mailbox);
389
+ const people = t.participants.filter(p => !opts.own(p)).map(p => (chat && t.names[p]) || p);
375
390
  return h `<a class="row ${t.unread ? "unread" : ""}" href="/threads/${t.id}?${inboxQuery(opts.filter)}" ${raw(t.id === opts.current ? 'aria-current="page"' : "")}>
376
391
  <span class="avatar" aria-hidden="true">${initials(people[0] ?? t.mailbox)}</span>
377
392
  <span class="row-main">
378
393
  <span class="row-top"><span class="who">${people.join(", ") || t.mailbox}</span><time datetime="${t.last_at}">${formatDate(t.last_at)}</time></span>
379
- <span class="row-subject">${t.subject || "—"}</span>
394
+ ${when(!chat, () => h `<span class="row-subject">${t.subject || "—"}</span>`)}
380
395
  ${when(t.has_draft || opts.accounts.length > 1 || t.unread, () => h `<span class="row-tags">
381
396
  ${when(t.has_draft, () => h `<span class="badge draft">${S.hasDraft}</span>`)}
382
397
  ${when(opts.accounts.length > 1, () => mailboxBadge(opts.addressOf(opts.accountOf(t))))}
@@ -389,12 +404,13 @@ function threadRow(t, opts) {
389
404
  export function inboxPage(list, thread) {
390
405
  return h `<div class="split ${thread ? "has-thread" : ""}">${list}<section class="pane">${thread ?? ""}</section></div>`;
391
406
  }
392
- /** The conversation, oldest first, with day separators, a reply box and the context panel. */
407
+ /** The conversation, oldest first, with day separators, a reply box and the context panel. A chat is titled by who it is with. */
393
408
  export function threadView(thread, entries, ctx, opts) {
394
409
  const query = inboxQuery(opts.filter);
395
410
  const rows = contextRows(ctx);
396
411
  const people = thread.participants.filter(p => !opts.own(p));
397
- const title = h `<span class="thread-subject">${thread.subject || "—"}</span><span class="thread-meta">${[...people, opts.account].join(" · ")}</span>`;
412
+ const heading = opts.chat ? people.map(p => thread.names[p] ?? p).join(", ") : thread.subject;
413
+ const title = h `<span class="thread-subject">${heading || "—"}</span><span class="thread-meta">${[...people, opts.account].join(" · ")}</span>`;
398
414
  const items = [];
399
415
  let day = "";
400
416
  for (const entry of entries) {
@@ -416,7 +432,7 @@ export function threadView(thread, entries, ctx, opts) {
416
432
  <div class="messages" id="messages" data-live data-scroll-end>${join(items)}</div>
417
433
  ${when(opts.reply.allowed, () => h `<form class="composer" method="post" action="/threads/${thread.id}/reply?${query}">
418
434
  ${when(opts.reply.replyAll, () => h `<label class="reply-all"><input type="checkbox" name="reply_all" value="1">${S.replyAll}</label>`)}
419
- <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>
435
+ ${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>`)}
420
436
  <textarea name="text" rows="1" aria-label="${S.reply}" placeholder="${S.reply}…" required></textarea>
421
437
  <button type="submit" name="action" value="save" class="icon-btn" aria-label="${S.saveDraft}" title="${S.saveDraft}">${icon("drafts")}</button>
422
438
  <button type="submit" name="action" value="send" class="primary send" aria-label="${S.send}" title="${S.send}">${icon("send")}</button>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inboxer",
3
- "version": "0.4.12",
3
+ "version": "0.5.1",
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",
@@ -21,23 +21,25 @@ const config = {
21
21
  syncIntervalMin: 10,
22
22
  threadWindowDays: 30,
23
23
  mailboxes: {
24
- support: { address: "support@example.com", name: "Example Support",
24
+ support: { address: "support@example.com", name: "Example Support", provider: "resend",
25
25
  signatureText: "-- Example Support", signatureHtml: "<p>-- Example Support</p>",
26
26
  tokens: { "support-schedule": "<openssl rand -hex 32>" } } // support only
27
27
  },
28
- provider: { type: "resend", apiKey: "re_...", webhookSecret: "whsec_..." },
28
+ providers: { resend: { type: "resend", apiKey: "re_...", webhookSecret: "whsec_..." } },
29
29
  mcp: { tokens: { "admin": "<openssl rand -hex 32>" }, maxAttachmentMb: 10 }, // every mailbox
30
30
  ui: { cookieSecret: "<openssl rand -hex 32>", loginLinkTtlMin: 10, undoSec: 10, maxUploadMb: 20 }
31
31
  };
32
32
  ```
33
33
 
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.
34
+ - Every key above is required except the mailbox signatures, mailbox tokens and `uiReadOnly`; `createInboxer` throws on a missing or invalid one. There are no defaults.
35
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
- - `provider.apiKey`, `provider.webhookSecret`, every token and `ui.cookieSecret` are secrets: keep them out of Git and out of logs.
36
+ - Each mailbox names its `provider`, a key of `providers`. That key is the webhook route (`/webhooks/<name>`) and is stored on every message: do not rename it once there is data.
37
+ - `uiReadOnly: true` on a mailbox lets browser sessions read and organize it but not draft or send; MCP tokens still can.
38
+ - Every provider `apiKey` and `webhookSecret`, every token and `ui.cookieSecret` are secrets: keep them out of Git and out of logs.
37
39
 
38
40
  ## Serve
39
41
 
40
- `createInboxer(cfg, { provider? })` is synchronous, does not listen, and returns `{ fetch, handler, ready, close }`. Requests wait for `ready`.
42
+ `createInboxer(cfg, { providers? })` is synchronous, does not listen, and returns `{ fetch, handler, ready, close }`. Requests wait for `ready`.
41
43
 
42
44
  ```typescript
43
45
  import { createInboxer } from "inboxer";
@@ -60,16 +62,20 @@ Keep two domains apart: the app runs on its own host, e.g. `inboxer.example.com`
60
62
  2. MX and TXT — `send` (bounces and SPF): MX `send` → `feedback-smtp.us-east-1.amazonses.com`, priority `10`; TXT `send` → `v=spf1 include:amazonses.com ~all`.
61
63
  3. TXT — DMARC: `_dmarc` → `v=DMARC1; p=none; rua=mailto:dmarc@example.com`.
62
64
  4. MX — receiving: `@` → `inbound-smtp.us-east-1.amazonaws.com`, priority `10`. This moves the whole domain's mail to Resend; unknown addresses land in `catchall`. To keep the root elsewhere, put the addresses and this MX on a subdomain. Wait until Resend shows the domain verified.
63
- 5. Create a full-access API key (Inboxer reads emails, not only sends) → `provider.apiKey`.
65
+ 5. Create a full-access API key (Inboxer reads emails, not only sends) → the provider's `apiKey`.
64
66
  6. Deploy Inboxer over HTTPS at `publicUrl`.
65
- 7. Create a webhook at `<publicUrl>/webhooks/resend` for `email.received`, `email.sent`, `email.delivered`, `email.bounced`, `email.failed`, `email.suppressed` → its signing secret is `provider.webhookSecret`.
67
+ 7. Create a webhook at `<publicUrl>/webhooks/resend` for `email.received`, `email.sent`, `email.delivered`, `email.bounced`, `email.failed`, `email.suppressed` → its signing secret is the provider's `webhookSecret`.
66
68
  8. Restart and send a test email from outside. A webhook `401` means a wrong signing secret.
67
69
 
68
70
  Missed webhooks are recovered by the periodic sync.
69
71
 
72
+ ## WhatsApp through Kapso
73
+
74
+ A WhatsApp number is a mailbox of kind `chat`: `mailboxes: { whatsapp: { address: "+12025550100", name: "Example", provider: "whatsapp" } }` with `providers: { whatsapp: { type: "kapso", apiKey, webhookSecret, phoneNumberId } }`. In Kapso, add a webhook of kind `kapso` on the number at `<publicUrl>/webhooks/whatsapp` for `whatsapp.message.received`, `.sent`, `.delivered`, `.read` and `.failed`; its secret is `webhookSecret`. A number takes several webhooks, so an existing bot keeps its own. Inboxer mirrors everything on the line, including what a bot sends through Kapso directly, and its first sync reads the whole history.
75
+
70
76
  ## Another provider
71
77
 
72
- Implement `MailProvider` (exported types) and pass it as `createInboxer(cfg, { provider })`; `cfg.provider.type` is then not required. `send()` must not deliver twice for the same `idempotencyKey` (Inboxer passes the draft id). `parseWebhook()` throws `WebhookSignatureError` on a bad signature.
78
+ Implement `MailProvider` (exported types) and pass it as `createInboxer(cfg, { providers: { <name>: instance } })`; `cfg.providers` is then not read. `send()` must not deliver twice for the same `idempotencyKey` (Inboxer passes the draft id). `parseWebhook()` throws `WebhookSignatureError` on a bad signature.
73
79
 
74
80
  ## Connect an MCP client
75
81
 
@@ -97,6 +103,7 @@ Rules for agents:
97
103
  - Pass a **message id** as `reply_to_id` or `message_id`. Recipients, `Re:` subject, `In-Reply-To` and `References` are derived; do not set them by hand. `reply_all` adds the original To/Cc minus the mailbox itself.
98
104
  - Put what the reviewer must do or check in `note`, not in the body. The note is never sent.
99
105
  - A new conversation needs `mailbox`, `to` and `subject`.
106
+ - `list_mailboxes` gives each mailbox's `kind`. In a `chat` mailbox (a phone line) addresses are phone numbers, a thread is the whole conversation with one number, and a message is plain text: no `subject`, `cc`, `bcc` or `html`. `send({ mailbox, to: ["+5491155550000"], text })` joins that number's thread. Messages with status `read` were seen by the recipient. WhatsApp only delivers free text within 24 hours of the person's last message; a later send fails.
100
107
  - `update_draft` needs the draft's current `version`. On a conflict the error includes `current`; re-read it before retrying.
101
108
  - A draft whose `pending` is set is in the reviewer's undo window and is about to be sent or discarded; `update_draft` fails until it ends.
102
109
  - Never `force` an update of a draft with `edited_by_human: true` unless the user explicitly asks; the human's edit wins.
package/src/app.ts CHANGED
@@ -33,15 +33,16 @@ export function buildApp(mail: Mail, access: Access, cfg: InboxerConfig, ready:
33
33
 
34
34
  // A failure answers 500 so the provider retries; ingest is idempotent.
35
35
  app.post("/webhooks/:provider", async c => {
36
- if (c.req.param("provider") !== mail.provider.name) return c.notFound();
36
+ const name = c.req.param("provider");
37
+ if (!Object.hasOwn(mail.providers, name)) return c.notFound();
37
38
  let events;
38
39
  try {
39
- events = mail.provider.parseWebhook({ headers: c.req.raw.headers, body: await c.req.text() });
40
+ events = mail.providers[name]!.parseWebhook({ headers: c.req.raw.headers, body: await c.req.text() });
40
41
  } catch (err) {
41
42
  if (err instanceof WebhookSignatureError) return c.text("Invalid signature", 401);
42
43
  throw err;
43
44
  }
44
- for (const event of events) await mail.applyEvent(event);
45
+ for (const event of events) await mail.applyEvent(name, event);
45
46
  return c.json({ ok: true });
46
47
  });
47
48
 
package/src/config.ts CHANGED
@@ -23,23 +23,30 @@ function requirePositive(value: unknown, path: string): void {
23
23
  if (typeof value !== "number" || !(value > 0)) fail(path, "a positive number");
24
24
  }
25
25
 
26
- /** Asserts the shape `createInboxer` relies on. */
27
- export function assertConfig(cfg: InboxerConfig, { requireProvider }: { requireProvider: boolean }): void {
26
+ /** Asserts the shape `createInboxer` relies on. `injectedProviders` names provider instances passed in place of `cfg.providers`. */
27
+ export function assertConfig(cfg: InboxerConfig, injectedProviders?: string[]): void {
28
28
  requireString(cfg.publicUrl, "publicUrl");
29
29
  requireString(cfg.dataDir, "dataDir");
30
30
  if (!isAbsolute(cfg.dataDir)) fail("dataDir", "an absolute path");
31
31
  requirePositive(cfg.syncIntervalMin, "syncIntervalMin");
32
32
  requirePositive(cfg.threadWindowDays, "threadWindowDays");
33
33
 
34
+ if (!injectedProviders) {
35
+ if (!cfg.providers || typeof cfg.providers !== "object") fail("providers", "an object keyed by provider name");
36
+ for (const [name, provider] of Object.entries(cfg.providers)) requireString(provider?.type, `providers.${name}.type`);
37
+ }
38
+ const providers = injectedProviders ?? Object.keys(cfg.providers);
39
+
34
40
  if (!cfg.mailboxes || typeof cfg.mailboxes !== "object") fail("mailboxes", "an object keyed by mailbox id");
35
41
  if (CATCHALL in cfg.mailboxes) fail(`mailboxes.${CATCHALL}`, "absent (the id is reserved)");
36
42
  for (const [id, mailbox] of Object.entries(cfg.mailboxes)) {
37
43
  requireString(mailbox.address, `mailboxes.${id}.address`);
38
44
  requireString(mailbox.name, `mailboxes.${id}.name`);
45
+ if (!providers.includes(mailbox.provider)) fail(`mailboxes.${id}.provider`, `one of: ${providers.join(", ")}`);
46
+ if (mailbox.uiReadOnly !== undefined && mailbox.uiReadOnly !== true) fail(`mailboxes.${id}.uiReadOnly`, "true or absent");
39
47
  if (mailbox.tokens !== undefined && (!mailbox.tokens || typeof mailbox.tokens !== "object")) fail(`mailboxes.${id}.tokens`, "an object of named tokens");
40
48
  }
41
49
 
42
- if (requireProvider) requireString(cfg.provider?.type, "provider.type");
43
50
  if (!cfg.mcp?.tokens || typeof cfg.mcp.tokens !== "object") fail("mcp.tokens", "an object of named tokens");
44
51
  for (const [name, token] of Object.entries(cfg.mcp.tokens)) requireString(token, `mcp.tokens.${name}`);
45
52
  mcpTokens(cfg);
@@ -1,9 +1,21 @@
1
- /** Bare, lowercased address from `Name <a@b.com>` or `a@b.com`. */
1
+ /** Bare, lowercased address from `Name <a@b.com>` or `a@b.com`. A chat address is a phone number: `+5491155550000`. */
2
2
  export function bareAddress(value: string): string {
3
3
  const match = /<([^<>]+)>\s*$/.exec(value);
4
4
  return (match ? match[1]! : value).trim().toLowerCase();
5
5
  }
6
6
 
7
+ /** Display name from `Name <address>`, or null when there is none. */
8
+ export function nameOf(value: string): string | null {
9
+ const match = /^\s*"?([^"<]+?)"?\s*</.exec(value);
10
+ return match ? match[1]! : null;
11
+ }
12
+
13
+ /** The E.164 address of a phone number written with or without the plus, spaces or dashes; null when it is not one. */
14
+ export function phoneAddress(value: string): string | null {
15
+ const digits = bareAddress(value).replace(/[\s().-]/g, "").replace(/^\+/, "");
16
+ return /^[1-9]\d{6,14}$/.test(digits) ? `+${digits}` : null;
17
+ }
18
+
7
19
  export function formatAddress(name: string, address: string): string {
8
20
  return `"${name.replace(/["\\]/g, "\\$&")}" <${address}>`;
9
21
  }