inboxer 0.4.12 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -20
- package/dist/app.js +4 -3
- package/dist/config.d.ts +2 -4
- package/dist/config.js +13 -4
- package/dist/core/address.d.ts +5 -1
- package/dist/core/address.js +11 -1
- package/dist/core/mail.d.ts +24 -13
- package/dist/core/mail.js +158 -85
- package/dist/core/sync.d.ts +6 -0
- package/dist/core/sync.js +22 -7
- package/dist/core/threads.d.ts +2 -0
- package/dist/core/threads.js +12 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +5 -5
- package/dist/mcp.js +8 -8
- package/dist/provider/index.d.ts +2 -1
- package/dist/provider/index.js +10 -6
- package/dist/provider/kapso.d.ts +8 -0
- package/dist/provider/kapso.js +198 -0
- package/dist/provider/resend.d.ts +1 -1
- package/dist/provider/resend.js +14 -10
- package/dist/provider/types.d.ts +35 -16
- package/dist/store.d.ts +2 -2
- package/dist/store.js +4 -4
- package/dist/types.d.ts +10 -2
- package/dist/ui/routes.js +15 -11
- package/dist/ui/views.d.ts +7 -5
- package/dist/ui/views.js +18 -16
- package/package.json +1 -1
- package/skills/inboxer/SKILL.md +15 -8
- package/src/app.ts +4 -3
- package/src/config.ts +10 -3
- package/src/core/address.ts +13 -1
- package/src/core/mail.ts +162 -89
- package/src/core/sync.ts +23 -7
- package/src/core/threads.ts +12 -1
- package/src/index.ts +10 -8
- package/src/mcp.ts +8 -8
- package/src/provider/index.ts +9 -5
- package/src/provider/kapso.ts +251 -0
- package/src/provider/resend.ts +15 -11
- package/src/provider/types.ts +38 -14
- package/src/store.ts +4 -4
- package/src/types.ts +10 -2
- package/src/ui/routes.ts +16 -11
- package/src/ui/views.ts +20 -17
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
|
|
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
|
|
47
|
-
const senders = (session: Session): V.Mailbox[] =>
|
|
48
|
-
const domainsOf = (session: Session): string[] =>
|
|
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
|
|
237
|
-
|
|
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 => {
|
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
|
}
|
|
@@ -305,8 +305,8 @@ function pendingCard(d: Message): View {
|
|
|
305
305
|
</article>`;
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
-
/** A draft for review, on our side of its thread. */
|
|
309
|
-
export function draftCard(d: Message): View {
|
|
308
|
+
/** A draft for review, on our side of its thread; without actions where the session can only read. */
|
|
309
|
+
export function draftCard(d: Message, canAct: boolean): View {
|
|
310
310
|
if (d.pending) return pendingCard(d);
|
|
311
311
|
return h`<article class="card draft" id="draft-${d.id}">
|
|
312
312
|
<div class="meta">
|
|
@@ -316,16 +316,16 @@ export function draftCard(d: Message): View {
|
|
|
316
316
|
</div>
|
|
317
317
|
<div class="draft-head">
|
|
318
318
|
<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
|
-
|
|
319
|
+
${when(d.subject, () => h`<div class="subject">${d.subject}</div>`)}
|
|
320
320
|
</div>
|
|
321
321
|
${when(d.note, () => h`<div class="note">${d.note}</div>`)}
|
|
322
322
|
<pre class="body">${d.text}</pre>
|
|
323
323
|
${attachments(d)}
|
|
324
|
-
|
|
324
|
+
${when(canAct, () => h`<div class="actions">
|
|
325
325
|
<button class="danger" hx-post="/drafts/${d.id}/discard" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.discard}</button>
|
|
326
326
|
<button hx-get="/drafts/${d.id}/edit" hx-target="#edit-sheet" hx-swap="innerHTML">${S.edit}</button>
|
|
327
327
|
<button class="primary" hx-post="/drafts/${d.id}/send" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.send}</button>
|
|
328
|
-
</div
|
|
328
|
+
</div>`)}
|
|
329
329
|
</article>`;
|
|
330
330
|
}
|
|
331
331
|
|
|
@@ -336,8 +336,8 @@ export interface DraftForm {
|
|
|
336
336
|
text: string;
|
|
337
337
|
}
|
|
338
338
|
|
|
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 {
|
|
339
|
+
/** The edit sheet's content; one draft is edited at a time. A chat message has a recipient and a body only. */
|
|
340
|
+
export function draftEditor(d: Message, form: DraftForm, conflict: Message | null, chat: boolean): View {
|
|
341
341
|
const version = conflict ? conflict.version : d.version;
|
|
342
342
|
return h`<form class="${conflict ? "conflict" : ""}" hx-post="/drafts/${d.id}/save" hx-target="#edit-sheet" hx-swap="innerHTML" data-drop>
|
|
343
343
|
<div class="grabber" aria-hidden="true"></div>
|
|
@@ -358,16 +358,16 @@ export function draftEditor(d: Message, form: DraftForm, conflict: Message | nul
|
|
|
358
358
|
<div class="field">
|
|
359
359
|
<label for="to-${d.id}">${S.to}</label>
|
|
360
360
|
<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>`)}
|
|
361
|
+
${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
362
|
</div>
|
|
363
|
-
|
|
363
|
+
${when(!chat, () => h`<div class="field" id="cc-row-${d.id}" ${raw(form.cc ? "" : "hidden")}>
|
|
364
364
|
<label for="cc-${d.id}">${S.cc}</label>
|
|
365
365
|
<input id="cc-${d.id}" name="cc" value="${form.cc}" autocomplete="off">
|
|
366
366
|
</div>
|
|
367
367
|
<div class="field">
|
|
368
368
|
<label for="subject-${d.id}">${S.subject}</label>
|
|
369
369
|
<input id="subject-${d.id}" name="subject" value="${form.subject}" required>
|
|
370
|
-
</div
|
|
370
|
+
</div>`)}
|
|
371
371
|
<textarea id="text-${d.id}" name="text" aria-label="${S.body}" required>${form.text}</textarea>
|
|
372
372
|
<div class="sheet-actions">
|
|
373
373
|
${draftFiles(d, null)}
|
|
@@ -454,16 +454,18 @@ interface ThreadListOptions {
|
|
|
454
454
|
addressOf: (account: string) => string;
|
|
455
455
|
filter: InboxFilter;
|
|
456
456
|
own: (address: string) => boolean;
|
|
457
|
+
isChat: (mailbox: string) => boolean;
|
|
457
458
|
current: string | null;
|
|
458
459
|
}
|
|
459
460
|
|
|
460
461
|
function threadRow(t: Thread, opts: ThreadListOptions): View {
|
|
461
|
-
const
|
|
462
|
+
const chat = opts.isChat(t.mailbox);
|
|
463
|
+
const people = t.participants.filter(p => !opts.own(p)).map(p => (chat && t.names[p]) || p);
|
|
462
464
|
return h`<a class="row ${t.unread ? "unread" : ""}" href="/threads/${t.id}?${inboxQuery(opts.filter)}" ${raw(t.id === opts.current ? 'aria-current="page"' : "")}>
|
|
463
465
|
<span class="avatar" aria-hidden="true">${initials(people[0] ?? t.mailbox)}</span>
|
|
464
466
|
<span class="row-main">
|
|
465
467
|
<span class="row-top"><span class="who">${people.join(", ") || t.mailbox}</span><time datetime="${t.last_at}">${formatDate(t.last_at)}</time></span>
|
|
466
|
-
|
|
468
|
+
${when(!chat, () => h`<span class="row-subject">${t.subject || "—"}</span>`)}
|
|
467
469
|
${when(t.has_draft || opts.accounts.length > 1 || t.unread, () => h`<span class="row-tags">
|
|
468
470
|
${when(t.has_draft, () => h`<span class="badge draft">${S.hasDraft}</span>`)}
|
|
469
471
|
${when(opts.accounts.length > 1, () => mailboxBadge(opts.addressOf(opts.accountOf(t))))}
|
|
@@ -483,12 +485,13 @@ export interface ThreadEntry {
|
|
|
483
485
|
view: View;
|
|
484
486
|
}
|
|
485
487
|
|
|
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 {
|
|
488
|
+
/** The conversation, oldest first, with day separators, a reply box and the context panel. A chat is titled by who it is with. */
|
|
489
|
+
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
490
|
const query = inboxQuery(opts.filter);
|
|
489
491
|
const rows = contextRows(ctx);
|
|
490
492
|
const people = thread.participants.filter(p => !opts.own(p));
|
|
491
|
-
const
|
|
493
|
+
const heading = opts.chat ? people.map(p => thread.names[p] ?? p).join(", ") : thread.subject;
|
|
494
|
+
const title = h`<span class="thread-subject">${heading || "—"}</span><span class="thread-meta">${[...people, opts.account].join(" · ")}</span>`;
|
|
492
495
|
const items: View[] = [];
|
|
493
496
|
let day = "";
|
|
494
497
|
for (const entry of entries) {
|
|
@@ -509,7 +512,7 @@ export function threadView(thread: Thread, entries: ThreadEntry[], ctx: ContextV
|
|
|
509
512
|
<div class="messages" id="messages" data-live data-scroll-end>${join(items)}</div>
|
|
510
513
|
${when(opts.reply.allowed, () => h`<form class="composer" method="post" action="/threads/${thread.id}/reply?${query}">
|
|
511
514
|
${when(opts.reply.replyAll, () => h`<label class="reply-all"><input type="checkbox" name="reply_all" value="1">${S.replyAll}</label>`)}
|
|
512
|
-
|
|
515
|
+
${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
516
|
<textarea name="text" rows="1" aria-label="${S.reply}" placeholder="${S.reply}…" required></textarea>
|
|
514
517
|
<button type="submit" name="action" value="save" class="icon-btn" aria-label="${S.saveDraft}" title="${S.saveDraft}">${icon("drafts")}</button>
|
|
515
518
|
<button type="submit" name="action" value="send" class="primary send" aria-label="${S.send}" title="${S.send}">${icon("send")}</button>
|