inboxer 0.3.1 → 0.4.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/dist/ui/routes.js +58 -41
- package/dist/ui/static/app.js +19 -0
- package/dist/ui/static/style.css +31 -19
- package/dist/ui/strings.d.ts +0 -4
- package/dist/ui/strings.js +0 -4
- package/dist/ui/views.d.ts +8 -10
- package/dist/ui/views.js +80 -88
- package/package.json +3 -2
- package/src/ui/routes.ts +59 -41
- package/src/ui/static/app.js +19 -0
- package/src/ui/static/style.css +31 -19
- package/src/ui/strings.ts +0 -4
- package/src/ui/views.ts +82 -90
package/dist/ui/views.js
CHANGED
|
@@ -23,6 +23,7 @@ const ICONS = {
|
|
|
23
23
|
settings: '<circle cx="12" cy="12" r="3"/><path d="M12 2v3M12 19v3M4.2 4.2l2.1 2.1M17.7 17.7l2.1 2.1M2 12h3M19 12h3M4.2 19.8l2.1-2.1M17.7 6.3l2.1-2.1"/>',
|
|
24
24
|
send: '<path d="M5 12h14"/><path d="M13 6l6 6-6 6"/>',
|
|
25
25
|
close: '<path d="M6 6l12 12M18 6L6 18"/>',
|
|
26
|
+
attach: '<path d="M20.5 11.5l-8.2 8.2a5 5 0 01-7-7l8.2-8.2a3.3 3.3 0 014.7 4.7l-8.2 8.2a1.7 1.7 0 01-2.4-2.4l7.6-7.6"/>',
|
|
26
27
|
};
|
|
27
28
|
function icon(name) {
|
|
28
29
|
return raw(`<svg class="icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${ICONS[name]}</svg>`);
|
|
@@ -78,7 +79,6 @@ export function layout(title, body, opts) {
|
|
|
78
79
|
<body class="${opts.signedIn ? "app" : ""} ${opts.fullScreen ? "full" : ""}">
|
|
79
80
|
${when(opts.signedIn, () => h `<aside class="sidebar">
|
|
80
81
|
<div class="brand">${S.appName}<span>.</span></div>
|
|
81
|
-
${when(opts.domains?.length, () => h `<div class="domain">${opts.domains.join(" · ")}</div>`)}
|
|
82
82
|
${when(canSend, () => h `<button type="button" class="primary new-mail" data-compose>${icon("plus")}${S.newMail}</button>`)}
|
|
83
83
|
<nav class="side-nav" aria-label="${S.mainNav}">
|
|
84
84
|
${link("drafts", "/", S.navDrafts, "drafts", count)}
|
|
@@ -96,13 +96,14 @@ ${when(opts.signedIn, () => h `<nav class="tabbar" aria-label="${S.mainNav}">
|
|
|
96
96
|
${link("settings", "/settings", S.navSettings, "settings")}
|
|
97
97
|
</nav>`)}
|
|
98
98
|
${when(opts.signedIn && canSend, () => composeDialog(opts.senders))}
|
|
99
|
+
${when(opts.signedIn, () => h `<dialog class="sheet" id="edit-sheet" aria-label="${S.edit}"></dialog>`)}
|
|
99
100
|
</body>
|
|
100
101
|
</html>`;
|
|
101
102
|
}
|
|
102
103
|
/** New mail, opened from the sidebar or the tab bar; a bottom sheet on a phone. */
|
|
103
104
|
function composeDialog(senders) {
|
|
104
105
|
return h `<dialog class="sheet" id="compose" aria-label="${S.newMail}">
|
|
105
|
-
<form method="post" action="/compose">
|
|
106
|
+
<form method="post" action="/compose" enctype="multipart/form-data" data-drop>
|
|
106
107
|
<div class="grabber" aria-hidden="true"></div>
|
|
107
108
|
<button type="button" class="icon-btn sheet-close" data-close aria-label="${S.close}">${icon("close")}</button>
|
|
108
109
|
<div class="field compact">
|
|
@@ -126,6 +127,8 @@ function composeDialog(senders) {
|
|
|
126
127
|
</div>
|
|
127
128
|
<textarea name="text" aria-label="${S.body}" required></textarea>
|
|
128
129
|
<div class="sheet-actions">
|
|
130
|
+
<label class="icon-btn" aria-label="${S.attach}">${icon("attach")}<input type="file" name="files" id="compose-files" multiple hidden></label>
|
|
131
|
+
<output class="sheet-files" id="compose-file-names"></output>
|
|
129
132
|
<button type="submit" name="action" value="save">${S.saveDraft}</button>
|
|
130
133
|
<button type="submit" name="action" value="send" class="primary">${S.send}${icon("send")}</button>
|
|
131
134
|
</div>
|
|
@@ -184,19 +187,6 @@ function recipients(m) {
|
|
|
184
187
|
return "";
|
|
185
188
|
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>`;
|
|
186
189
|
}
|
|
187
|
-
/** A message in a draft's history on the Drafts page. */
|
|
188
|
-
export function messageCard(m) {
|
|
189
|
-
return h `<article class="card ${m.direction}">
|
|
190
|
-
<div class="meta">
|
|
191
|
-
<strong>${m.from}</strong>
|
|
192
|
-
<span>${formatDate(m.date)}</span>
|
|
193
|
-
${when(m.direction === "out" && m.status !== "draft", () => h `<span>${m.status}</span>`)}
|
|
194
|
-
</div>
|
|
195
|
-
${recipients(m)}
|
|
196
|
-
<pre class="body">${withoutImagePlaceholders(m)}</pre>
|
|
197
|
-
${attachments(m)}
|
|
198
|
-
</article>`;
|
|
199
|
-
}
|
|
200
190
|
/** A message in a thread: received ones on the left, ours on the right. */
|
|
201
191
|
export function messageBubble(m, showSender) {
|
|
202
192
|
const mine = m.direction === "out";
|
|
@@ -222,15 +212,6 @@ function contextSections(rows) {
|
|
|
222
212
|
${when(r.note, () => h `<p>${r.note}</p>`)}
|
|
223
213
|
</section>`));
|
|
224
214
|
}
|
|
225
|
-
/** Read-only context agents attached to the thread and its participants, folded on a draft card. */
|
|
226
|
-
function contextBlock(ctx) {
|
|
227
|
-
if (!ctx)
|
|
228
|
-
return "";
|
|
229
|
-
const rows = contextRows(ctx);
|
|
230
|
-
if (!rows.length)
|
|
231
|
-
return "";
|
|
232
|
-
return h `<details class="context"><summary>${S.context}</summary>${contextSections(rows)}</details>`;
|
|
233
|
-
}
|
|
234
215
|
/** A send or discard in its undo window; reloads itself when the window closes. */
|
|
235
216
|
function pendingCard(d) {
|
|
236
217
|
const left = Math.max(0, Date.parse(d.pending.at) - Date.now());
|
|
@@ -242,8 +223,8 @@ function pendingCard(d) {
|
|
|
242
223
|
<i class="countdown" style="animation-duration: ${left}ms"></i>
|
|
243
224
|
</article>`;
|
|
244
225
|
}
|
|
245
|
-
/** A draft for review
|
|
246
|
-
export function draftCard(d
|
|
226
|
+
/** A draft for review, on our side of its thread. */
|
|
227
|
+
export function draftCard(d) {
|
|
247
228
|
if (d.pending)
|
|
248
229
|
return pendingCard(d);
|
|
249
230
|
return h `<article class="card draft" id="draft-${d.id}">
|
|
@@ -256,77 +237,88 @@ export function draftCard(d, history, ctx) {
|
|
|
256
237
|
<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>
|
|
257
238
|
<div class="subject">${d.subject}</div>
|
|
258
239
|
</div>
|
|
259
|
-
${contextBlock(ctx)}
|
|
260
240
|
${when(d.note, () => h `<div class="note">${d.note}</div>`)}
|
|
261
241
|
<pre class="body">${d.text}</pre>
|
|
262
242
|
${attachments(d)}
|
|
263
243
|
<div class="actions">
|
|
264
244
|
<button class="danger" hx-post="/drafts/${d.id}/discard" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.discard}</button>
|
|
265
|
-
<button hx-get="/drafts/${d.id}/edit" hx-target="#
|
|
245
|
+
<button hx-get="/drafts/${d.id}/edit" hx-target="#edit-sheet" hx-swap="innerHTML">${S.edit}</button>
|
|
266
246
|
<button class="primary" hx-post="/drafts/${d.id}/send" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.send}</button>
|
|
267
247
|
</div>
|
|
268
|
-
${when(history.length, () => h `<details>
|
|
269
|
-
<summary>${S.thread} (${history.length})</summary>
|
|
270
|
-
${join(history.map(messageCard))}
|
|
271
|
-
</details>`)}
|
|
272
248
|
</article>`;
|
|
273
249
|
}
|
|
250
|
+
/** The edit sheet's content; one draft is edited at a time. */
|
|
274
251
|
export function draftEditor(d, form, conflict) {
|
|
275
252
|
const version = conflict ? conflict.version : d.version;
|
|
276
|
-
return h `<
|
|
253
|
+
return h `<form class="${conflict ? "conflict" : ""}" hx-post="/drafts/${d.id}/save" hx-target="#edit-sheet" hx-swap="innerHTML" data-drop>
|
|
254
|
+
<div class="grabber" aria-hidden="true"></div>
|
|
277
255
|
<div class="drop-hint">${S.dropFiles}</div>
|
|
278
|
-
<
|
|
256
|
+
<button type="button" class="icon-btn sheet-close" data-close aria-label="${S.close}">${icon("close")}</button>
|
|
257
|
+
<div class="sheet-head"><span class="badge draft">${S.draft}</span>${mailboxBadge(d.mailbox)}</div>
|
|
279
258
|
${when(d.note, () => h `<div class="note">${d.note}</div>`)}
|
|
280
|
-
${when(conflict, () => h `<
|
|
281
|
-
|
|
282
|
-
<
|
|
283
|
-
|
|
284
|
-
<label for="to-${d.id}">${S.to}</label>
|
|
285
|
-
<input id="to-${d.id}" name="to" value="${form.to}" autocomplete="off" required>
|
|
286
|
-
${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>`)}
|
|
287
|
-
</div>
|
|
288
|
-
<div class="field" id="cc-row-${d.id}" ${raw(form.cc ? "" : "hidden")}>
|
|
289
|
-
<label for="cc-${d.id}">${S.cc}</label>
|
|
290
|
-
<input id="cc-${d.id}" name="cc" value="${form.cc}" autocomplete="off">
|
|
291
|
-
</div>
|
|
292
|
-
<div class="field">
|
|
293
|
-
<label for="subject-${d.id}">${S.subject}</label>
|
|
294
|
-
<input id="subject-${d.id}" name="subject" value="${form.subject}" required>
|
|
295
|
-
</div>
|
|
296
|
-
<textarea id="text-${d.id}" name="text" aria-label="${S.body}" required>${form.text}</textarea>
|
|
297
|
-
${draftFiles(d, null)}
|
|
298
|
-
<div class="actions">
|
|
299
|
-
<button type="button" class="link" hx-get="/drafts/${d.id}/card" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.cancel}</button>
|
|
300
|
-
<button type="submit">${S.save}</button>
|
|
301
|
-
<button type="submit" name="send" value="1" class="primary">${S.saveAndSend}</button>
|
|
302
|
-
</div>
|
|
303
|
-
</form>
|
|
304
|
-
${when(conflict, () => h `<details open>
|
|
305
|
-
<summary>${S.currentVersion}</summary>
|
|
306
|
-
<div class="card">
|
|
259
|
+
${when(conflict, () => h `<div class="sheet-conflict">
|
|
260
|
+
<p class="warn">${S.conflictTitle}</p>
|
|
261
|
+
<details>
|
|
262
|
+
<summary>${S.currentVersion}</summary>
|
|
307
263
|
<div class="meta"><span>${S.to}: ${conflict.to.join(", ")}</span>${when(conflict.cc.length, () => h `<span>${S.cc}: ${conflict.cc.join(", ")}</span>`)}</div>
|
|
308
264
|
<div class="subject">${conflict.subject}</div>
|
|
309
265
|
<pre class="body">${conflict.text}</pre>
|
|
310
|
-
</
|
|
311
|
-
</
|
|
312
|
-
|
|
266
|
+
</details>
|
|
267
|
+
</div>`)}
|
|
268
|
+
<input type="hidden" name="version" value="${version}">
|
|
269
|
+
<div class="field">
|
|
270
|
+
<label for="to-${d.id}">${S.to}</label>
|
|
271
|
+
<input id="to-${d.id}" name="to" value="${form.to}" autocomplete="off" required>
|
|
272
|
+
${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>`)}
|
|
273
|
+
</div>
|
|
274
|
+
<div class="field" id="cc-row-${d.id}" ${raw(form.cc ? "" : "hidden")}>
|
|
275
|
+
<label for="cc-${d.id}">${S.cc}</label>
|
|
276
|
+
<input id="cc-${d.id}" name="cc" value="${form.cc}" autocomplete="off">
|
|
277
|
+
</div>
|
|
278
|
+
<div class="field">
|
|
279
|
+
<label for="subject-${d.id}">${S.subject}</label>
|
|
280
|
+
<input id="subject-${d.id}" name="subject" value="${form.subject}" required>
|
|
281
|
+
</div>
|
|
282
|
+
<textarea id="text-${d.id}" name="text" aria-label="${S.body}" required>${form.text}</textarea>
|
|
283
|
+
<div class="sheet-actions">
|
|
284
|
+
${draftFiles(d, null)}
|
|
285
|
+
<button type="submit">${S.save}</button>
|
|
286
|
+
<button type="submit" name="send" value="1" class="primary">${S.saveAndSend}</button>
|
|
287
|
+
</div>
|
|
288
|
+
</form>`;
|
|
289
|
+
}
|
|
290
|
+
/** A reply opened in the edit sheet from the reply box; the thread reloads when the sheet closes, to show the new draft. */
|
|
291
|
+
export function newReplyEditor(d) {
|
|
292
|
+
return h `<div data-reload-on-close hidden></div>${draftEditor(d, { to: d.to.join(", "), cc: d.cc.join(", "), subject: d.subject, text: d.text }, null)}`;
|
|
313
293
|
}
|
|
314
294
|
/** The editor's attachment list with remove buttons, and the picker that drag and drop also feeds. */
|
|
315
295
|
export function draftFiles(d, error) {
|
|
316
296
|
return h `<div class="draft-files" id="files-${d.id}">
|
|
297
|
+
<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>
|
|
317
298
|
${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>`))}
|
|
318
|
-
<label class="file attach">${S.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>
|
|
319
299
|
${when(error, () => h `<p class="warn">${error}</p>`)}
|
|
320
300
|
</div>`;
|
|
321
301
|
}
|
|
322
302
|
export function draftDone(id, text) {
|
|
323
303
|
return h `<article class="card notice" id="draft-${id}">${text}</article>`;
|
|
324
304
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
305
|
+
/** Drafts waiting for review, listed like the inbox; each opens its thread. */
|
|
306
|
+
export function draftList(drafts, current) {
|
|
307
|
+
return h `<section class="list">
|
|
308
|
+
<header class="list-head"><h1>${S.navDrafts}</h1></header>
|
|
309
|
+
${drafts.length ? join(drafts.map(d => h `<a class="row" href="/drafts/${d.id}" ${raw(d.id === current ? 'aria-current="page"' : "")}>
|
|
310
|
+
<span class="avatar" aria-hidden="true">${initials(d.to[0] ?? d.mailbox)}</span>
|
|
311
|
+
<span class="row-main">
|
|
312
|
+
<span class="row-top"><span class="who">${d.to.map(displayName).join(", ") || "—"}</span><time datetime="${d.created_at}">${formatDate(d.created_at)}</time></span>
|
|
313
|
+
<span class="row-subject">${d.subject || "—"}</span>
|
|
314
|
+
<span class="row-snippet">${d.text}</span>
|
|
315
|
+
<span class="row-tags">
|
|
316
|
+
${mailboxBadge(d.mailbox)}
|
|
317
|
+
<span class="row-by">${d.edited_by_human ? S.editedByHuman : S.byAgent}</span>
|
|
318
|
+
</span>
|
|
319
|
+
</span>
|
|
320
|
+
</a>`)) : h `<p class="empty">${S.draftsEmpty}</p>`}
|
|
321
|
+
</section>`;
|
|
330
322
|
}
|
|
331
323
|
export function inboxQuery(filter) {
|
|
332
324
|
return new URLSearchParams({ status: filter.status, ...(filter.mailbox ? { mailbox: filter.mailbox } : {}) }).toString();
|
|
@@ -386,7 +378,7 @@ export function threadView(thread, entries, ctx, opts) {
|
|
|
386
378
|
}
|
|
387
379
|
return h `<div class="thread">
|
|
388
380
|
<header class="thread-head">
|
|
389
|
-
<a class="icon-btn back" href="
|
|
381
|
+
<a class="icon-btn back" href="${opts.back}" aria-label="${S.back}">${icon("back")}</a>
|
|
390
382
|
${rows.length
|
|
391
383
|
? h `<button type="button" class="thread-title" data-context-toggle aria-controls="context">${title}</button>`
|
|
392
384
|
: h `<div class="thread-title">${title}</div>`}
|
|
@@ -396,6 +388,7 @@ export function threadView(thread, entries, ctx, opts) {
|
|
|
396
388
|
<div class="messages" data-scroll-end>${join(items)}</div>
|
|
397
389
|
${when(opts.reply.allowed, () => h `<form class="composer" method="post" action="/threads/${thread.id}/reply?${query}">
|
|
398
390
|
${when(opts.reply.replyAll, () => h `<label class="reply-all"><input type="checkbox" name="reply_all" value="1">${S.replyAll}</label>`)}
|
|
391
|
+
<button type="button" class="icon-btn" aria-label="${S.attach}" title="${S.attach}" hx-post="/threads/${thread.id}/reply/full" hx-target="#edit-sheet" hx-swap="innerHTML">${icon("attach")}</button>
|
|
399
392
|
<textarea name="text" rows="1" aria-label="${S.reply}" placeholder="${S.reply}…" required></textarea>
|
|
400
393
|
<button type="submit" name="action" value="save" class="icon-btn" aria-label="${S.saveDraft}" title="${S.saveDraft}">${icon("drafts")}</button>
|
|
401
394
|
<button type="submit" name="action" value="send" class="primary send" aria-label="${S.send}" title="${S.send}">${icon("send")}</button>
|
|
@@ -415,23 +408,22 @@ export function archiveButton(thread) {
|
|
|
415
408
|
</form>`;
|
|
416
409
|
}
|
|
417
410
|
export function devicesPage(sessions, currentId) {
|
|
418
|
-
return h `<
|
|
419
|
-
<h1>${S.navDevices}</h1>
|
|
420
|
-
${sessions.length ? join(sessions.map(s => h `<
|
|
421
|
-
|
|
422
|
-
<
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
</
|
|
434
|
-
</div>`;
|
|
411
|
+
return h `<section class="list">
|
|
412
|
+
<header class="list-head"><h1>${S.navDevices}</h1></header>
|
|
413
|
+
${sessions.length ? join(sessions.map(s => h `<div class="row device" id="session-${s.id}">
|
|
414
|
+
<span class="avatar" aria-hidden="true">${icon("devices")}</span>
|
|
415
|
+
<span class="row-main">
|
|
416
|
+
<span class="row-top"><span class="who">${s.label ?? s.user_agent ?? S.unknownDevice}</span><time datetime="${s.last_seen}">${formatDate(s.last_seen)}</time></span>
|
|
417
|
+
${when(s.label && s.user_agent, () => h `<span class="row-subject">${s.user_agent}</span>`)}
|
|
418
|
+
<span class="row-tags">
|
|
419
|
+
${when(s.id === currentId, () => h `<span class="badge">${S.thisDevice}</span>`)}
|
|
420
|
+
${when(s.scope, () => join(s.scope.map(mailboxBadge)))}
|
|
421
|
+
<span class="row-by">${S.signedIn} ${formatDate(s.created_at)} · ${S.createdBy} ${s.created_by}</span>
|
|
422
|
+
</span>
|
|
423
|
+
</span>
|
|
424
|
+
${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>`)}
|
|
425
|
+
</div>`)) : h `<p class="empty">${S.devicesEmpty}</p>`}
|
|
426
|
+
</section>`;
|
|
435
427
|
}
|
|
436
428
|
export function settingsPage(theme) {
|
|
437
429
|
return h `<div class="page">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inboxer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
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",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
25
25
|
"test": "node --test 'test/**/*.test.ts'",
|
|
26
26
|
"test:bun": "bun test test",
|
|
27
|
-
"prepack": "npm run build"
|
|
27
|
+
"prepack": "npm run build",
|
|
28
|
+
"preview": "node scripts/preview.ts"
|
|
28
29
|
},
|
|
29
30
|
"keywords": [
|
|
30
31
|
"email",
|
package/src/ui/routes.ts
CHANGED
|
@@ -2,7 +2,7 @@ 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
4
|
import { bareAddress, domainOf, splitAddresses } from "../core/address.ts";
|
|
5
|
-
import { ConflictError, InvalidRequestError, type Mail, type MessageView, type ThreadStatus } from "../core/mail.ts";
|
|
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";
|
|
8
8
|
import * as V from "./views.ts";
|
|
@@ -25,12 +25,6 @@ function clientInfo(c: Context) {
|
|
|
25
25
|
return { ip: forwarded || c.req.header("x-real-ip") || null, userAgent: c.req.header("user-agent") ?? null };
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
/** htmx sends the page URL; draft cards on a thread page leave out the thread around them. */
|
|
29
|
-
function onThreadPage(c: Context): boolean {
|
|
30
|
-
const current = c.req.header("hx-current-url");
|
|
31
|
-
return !!current && new URL(current).pathname.startsWith("/threads/");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
28
|
function uiActor(session: Session): Actor {
|
|
35
29
|
return { kind: "ui", name: session.label ?? session.id.slice(0, 12), scope: session.scope };
|
|
36
30
|
}
|
|
@@ -54,7 +48,7 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
|
|
|
54
48
|
const page = async (c: Context<UiEnv>, title: string, body: V.View, current: V.Page, status: 200 | 400 | 401 | 404 = 200, fullScreen = false) => {
|
|
55
49
|
const session = c.get("session");
|
|
56
50
|
const shell = session
|
|
57
|
-
? { draftCount: (await mail.listDrafts(undefined, session.scope)).length,
|
|
51
|
+
? { draftCount: (await mail.listDrafts(undefined, session.scope)).length, senders: senders(session) }
|
|
58
52
|
: {};
|
|
59
53
|
return c.html(V.layout(title, body, { theme: theme(c), page: current, signedIn: !!session, fullScreen, ...shell }), status);
|
|
60
54
|
};
|
|
@@ -105,36 +99,36 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
|
|
|
105
99
|
});
|
|
106
100
|
}
|
|
107
101
|
|
|
108
|
-
/** The
|
|
109
|
-
const draftExtras = async (draft: Message, session: Session): Promise<{ history: MessageView[]; ctx: V.ContextView }> => {
|
|
110
|
-
const { messages, context, contacts } = await mail.getThread(draft.thread_id, session.scope);
|
|
111
|
-
const history = messages.filter(m => m.id !== draft.id && m.status !== "draft").reverse().map(shown);
|
|
112
|
-
return { history, ctx: { context, contacts } };
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
/** The card for a draft in whatever state it is now. */
|
|
102
|
+
/** The card for a draft in whatever state it is now; once sent, its message in the thread. */
|
|
116
103
|
const draftView = async (c: Context<UiEnv>, id: string): Promise<V.View> => {
|
|
117
|
-
const
|
|
118
|
-
const draft = await mail.requireMessage(id, session.scope);
|
|
104
|
+
const draft = await mail.requireMessage(id, c.get("session").scope);
|
|
119
105
|
if (draft.status === "discarded") return V.draftDone(id, S.discarded);
|
|
120
|
-
if (draft.status !== "draft") return V.
|
|
121
|
-
|
|
122
|
-
const { history, ctx } = await draftExtras(draft, session);
|
|
123
|
-
return V.draftCard(draft, history, ctx);
|
|
106
|
+
if (draft.status !== "draft") return V.messageBubble(shown(toView(draft)), false);
|
|
107
|
+
return V.draftCard(draft);
|
|
124
108
|
};
|
|
125
109
|
|
|
126
110
|
app.get("/", async c => {
|
|
111
|
+
const drafts = await mail.listDrafts(undefined, c.get("session").scope);
|
|
112
|
+
return page(c, S.navDrafts, V.inboxPage(V.draftList(drafts, null), null), "drafts");
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
app.get("/drafts/:id", async c => {
|
|
127
116
|
const session = c.get("session");
|
|
117
|
+
const draft = await mail.requireMessage(c.req.param("id"), session.scope);
|
|
118
|
+
if (draft.status !== "draft") return c.redirect(`/threads/${draft.thread_id}?status=all`, 303);
|
|
119
|
+
const { thread, view } = await threadPane(c, draft.thread_id, "/");
|
|
128
120
|
const drafts = await mail.listDrafts(undefined, session.scope);
|
|
129
|
-
|
|
130
|
-
return page(c, S.navDrafts, V.draftsPage(items), "drafts");
|
|
121
|
+
return page(c, thread.subject || S.navDrafts, V.inboxPage(V.draftList(drafts, draft.id), view), "drafts", 200, true);
|
|
131
122
|
});
|
|
132
123
|
|
|
133
124
|
app.get("/drafts/:id/card", async c => c.html(await draftView(c, c.req.param("id"))));
|
|
134
125
|
|
|
135
126
|
app.get("/drafts/:id/edit", async c => {
|
|
136
127
|
const draft = await mail.requireMessage(c.req.param("id"), c.get("session").scope);
|
|
137
|
-
if (draft.status !== "draft" || draft.pending)
|
|
128
|
+
if (draft.status !== "draft" || draft.pending) {
|
|
129
|
+
c.header("HX-Refresh", "true");
|
|
130
|
+
return c.body(null, 204);
|
|
131
|
+
}
|
|
138
132
|
const form = { to: draft.to.join(", "), cc: draft.cc.join(", "), subject: draft.subject, text: draft.text };
|
|
139
133
|
return c.html(V.draftEditor(draft, form, null));
|
|
140
134
|
});
|
|
@@ -152,6 +146,7 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
|
|
|
152
146
|
text: form.text,
|
|
153
147
|
}, actor);
|
|
154
148
|
if (body.send === "1") await mail.schedule(id, "send", actor);
|
|
149
|
+
c.header("HX-Refresh", "true");
|
|
155
150
|
return c.html(await draftView(c, id));
|
|
156
151
|
} catch (err) {
|
|
157
152
|
if (err instanceof ConflictError) return c.html(V.draftEditor(err.current, form, err.current));
|
|
@@ -160,20 +155,24 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
|
|
|
160
155
|
}
|
|
161
156
|
});
|
|
162
157
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
const body = await c.req.parseBody({ all: true });
|
|
167
|
-
const files = ([] as unknown[]).concat(body.files ?? []).filter((f): f is File => f instanceof File);
|
|
158
|
+
/** Uploaded files within the size limit, and a message naming the last one over it. */
|
|
159
|
+
const uploads = (body: Record<string, unknown>): { files: File[]; error: string | null } => {
|
|
160
|
+
const all = ([] as unknown[]).concat(body.files ?? []).filter((f): f is File => f instanceof File && f.name !== "");
|
|
168
161
|
const limit = cfg.ui.maxUploadMb * 1024 * 1024;
|
|
169
|
-
|
|
162
|
+
const over = all.filter(f => f.size > limit).at(-1);
|
|
163
|
+
return { files: all.filter(f => f.size <= limit), error: over ? `${over.name} ${S.tooLarge} ${cfg.ui.maxUploadMb} MB` : null };
|
|
164
|
+
};
|
|
165
|
+
const attachAll = async (draftId: string, files: File[], actor: Actor) => {
|
|
170
166
|
for (const file of files) {
|
|
171
|
-
|
|
172
|
-
error = `${file.name} ${S.tooLarge} ${cfg.ui.maxUploadMb} MB`;
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
await mail.attach(id, { filename: file.name, contentType: file.type, body: new Uint8Array(await file.arrayBuffer()) }, actor);
|
|
167
|
+
await mail.attach(draftId, { filename: file.name, contentType: file.type, body: new Uint8Array(await file.arrayBuffer()) }, actor);
|
|
176
168
|
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
app.post("/drafts/:id/attachments", async c => {
|
|
172
|
+
const id = c.req.param("id");
|
|
173
|
+
const actor = uiActor(c.get("session"));
|
|
174
|
+
const { files, error } = uploads(await c.req.parseBody({ all: true }));
|
|
175
|
+
await attachAll(id, files, actor);
|
|
177
176
|
return c.html(V.draftFiles(await mail.requireMessage(id, actor.scope), error));
|
|
178
177
|
});
|
|
179
178
|
|
|
@@ -216,8 +215,8 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
|
|
|
216
215
|
|
|
217
216
|
app.get("/inbox", async c => page(c, S.navInbox, V.inboxPage(await threadList(c, null), null), "inbox"));
|
|
218
217
|
|
|
219
|
-
|
|
220
|
-
|
|
218
|
+
/** A thread with its drafts in place; opening it marks it read. */
|
|
219
|
+
const threadPane = async (c: Context<UiEnv>, id: string, back: string) => {
|
|
221
220
|
const session = c.get("session");
|
|
222
221
|
let thread = await mail.requireThread(id, session.scope);
|
|
223
222
|
if (thread.unread) {
|
|
@@ -228,14 +227,30 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
|
|
|
228
227
|
const people = thread.participants.filter(p => !own.has(p));
|
|
229
228
|
const entries = await Promise.all(messages.map(async m => ({
|
|
230
229
|
at: m.date,
|
|
231
|
-
view: m.status === "draft" ? V.draftCard(await mail.store.requireMessage(m.id)
|
|
230
|
+
view: m.status === "draft" ? V.draftCard(await mail.store.requireMessage(m.id)) : V.messageBubble(shown(m), people.length > 1),
|
|
232
231
|
})));
|
|
233
232
|
const reply = { allowed: senders(session).some(m => m.id === thread.mailbox), replyAll: people.length > 1 };
|
|
234
|
-
|
|
233
|
+
return { thread, view: V.threadView(thread, entries, { context, contacts }, { back, filter: inboxFilter(c), own, reply }) };
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
app.get("/threads/:id", async c => {
|
|
237
|
+
const id = c.req.param("id");
|
|
238
|
+
const { thread, view } = await threadPane(c, id, `/inbox?${V.inboxQuery(inboxFilter(c))}`);
|
|
235
239
|
return page(c, thread.subject || S.navInbox, V.inboxPage(await threadList(c, id), view), "inbox", 200, true);
|
|
236
240
|
});
|
|
237
241
|
|
|
238
242
|
/** Replies to the latest message; a reply sent from here gets the same undo window as a draft. */
|
|
243
|
+
/** Opens a reply to the latest message in the edit sheet, for Cc, subject and attachments. */
|
|
244
|
+
app.post("/threads/:id/reply/full", async c => {
|
|
245
|
+
const actor = uiActor(c.get("session"));
|
|
246
|
+
const body = await c.req.parseBody();
|
|
247
|
+
const { messages } = await mail.getThread(c.req.param("id"), actor.scope);
|
|
248
|
+
const latest = messages.filter(m => m.status !== "draft").at(-1);
|
|
249
|
+
if (!latest) throw new InvalidRequestError("nothing to reply to");
|
|
250
|
+
const draft = await mail.createDraft({ replyToId: latest.id, replyAll: body.reply_all === "1", text: String(body.text ?? "") }, actor);
|
|
251
|
+
return c.html(V.newReplyEditor(draft));
|
|
252
|
+
});
|
|
253
|
+
|
|
239
254
|
app.post("/threads/:id/reply", async c => {
|
|
240
255
|
const id = c.req.param("id");
|
|
241
256
|
const actor = uiActor(c.get("session"));
|
|
@@ -257,7 +272,9 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
|
|
|
257
272
|
|
|
258
273
|
app.post("/compose", async c => {
|
|
259
274
|
const actor = uiActor(c.get("session"));
|
|
260
|
-
const body = await c.req.parseBody();
|
|
275
|
+
const body = await c.req.parseBody({ all: true });
|
|
276
|
+
const { files, error } = uploads(body);
|
|
277
|
+
if (error) return page(c, S.newMail, V.message([error]), null, 400);
|
|
261
278
|
try {
|
|
262
279
|
const draft = await mail.createDraft({
|
|
263
280
|
mailbox: String(body.mailbox ?? ""),
|
|
@@ -266,6 +283,7 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
|
|
|
266
283
|
subject: String(body.subject ?? ""),
|
|
267
284
|
text: String(body.text ?? ""),
|
|
268
285
|
}, actor);
|
|
286
|
+
await attachAll(draft.id, files, actor);
|
|
269
287
|
if (body.action === "send") await mail.schedule(draft.id, "send", actor);
|
|
270
288
|
return c.redirect(`/threads/${draft.thread_id}?status=all`, 303);
|
|
271
289
|
} catch (err) {
|
package/src/ui/static/app.js
CHANGED
|
@@ -15,6 +15,25 @@ document.addEventListener("click", event => {
|
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
+
// A draft's editor opens in the edit sheet; one draft is edited at a time.
|
|
19
|
+
document.addEventListener("htmx:afterSwap", event => {
|
|
20
|
+
const sheet = event.detail.target;
|
|
21
|
+
if (sheet.id !== "edit-sheet") return;
|
|
22
|
+
if (!sheet.open) sheet.showModal();
|
|
23
|
+
sheet.querySelector("textarea")?.focus();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Closing the sheet on a reply started from the reply box shows its new draft in the thread.
|
|
27
|
+
document.addEventListener("close", event => {
|
|
28
|
+
if (event.target.id === "edit-sheet" && event.target.querySelector("[data-reload-on-close]")) location.reload();
|
|
29
|
+
}, true);
|
|
30
|
+
|
|
31
|
+
document.addEventListener("change", event => {
|
|
32
|
+
if (event.target.id === "compose-files") {
|
|
33
|
+
document.getElementById("compose-file-names").textContent = [...event.target.files].map(f => f.name).join(", ");
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
18
37
|
document.addEventListener("keydown", event => {
|
|
19
38
|
if (event.key === "Escape") document.body.classList.remove("context-open");
|
|
20
39
|
});
|