inboxer 0.4.8 → 0.4.10
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/core/mail.d.ts +16 -0
- package/dist/core/mail.js +67 -23
- package/dist/core/threads.d.ts +1 -1
- package/dist/core/threads.js +2 -2
- package/dist/ui/routes.js +28 -17
- package/dist/ui/static/app.js +64 -3
- package/dist/ui/static/style.css +14 -10
- package/dist/ui/views.d.ts +19 -8
- package/dist/ui/views.js +51 -26
- package/package.json +1 -1
- package/src/core/mail.ts +30 -15
- package/src/ui/routes.ts +15 -5
- package/src/ui/static/app.js +64 -3
- package/src/ui/static/style.css +6 -5
- package/src/ui/views.ts +38 -20
package/dist/core/mail.d.ts
CHANGED
|
@@ -74,19 +74,35 @@ export declare class Mail {
|
|
|
74
74
|
readonly provider: MailProvider;
|
|
75
75
|
readonly cfg: InboxerConfig;
|
|
76
76
|
private readonly ownAddresses;
|
|
77
|
+
private readonly domains;
|
|
77
78
|
private readonly timers;
|
|
78
79
|
private readonly files;
|
|
80
|
+
/** Fires "change" after every write, so open pages can refresh. */
|
|
81
|
+
readonly changes: EventTarget;
|
|
79
82
|
constructor(store: Store, provider: MailProvider, cfg: InboxerConfig);
|
|
83
|
+
/** Runs `fn` in the store's write queue, then announces the change. */
|
|
84
|
+
private write;
|
|
80
85
|
listMailboxes(scope: Scope): {
|
|
81
86
|
id: string;
|
|
82
87
|
address: string;
|
|
83
88
|
name: string;
|
|
84
89
|
}[];
|
|
90
|
+
/** A configured mailbox address or any other address on its domains, such as one the catch-all received. */
|
|
91
|
+
isOwn(address: string): boolean;
|
|
92
|
+
/** The first address on our domains that is not a configured mailbox: the one a catch-all message was written to. */
|
|
93
|
+
private catchAllAddress;
|
|
94
|
+
/** The account a thread belongs to: its mailbox or, in the catch-all, the address it was written to. */
|
|
95
|
+
accountOf(thread: Thread): string;
|
|
96
|
+
/** The address an account receives mail at: a configured mailbox's address, or the catch-all address itself. */
|
|
97
|
+
addressOf(account: string): string;
|
|
98
|
+
/** Mailboxes in scope, with the catch-all split into the addresses it has received mail for. */
|
|
99
|
+
listAccounts(scope: Scope): Promise<string[]>;
|
|
85
100
|
requireMessage(id: string, scope: Scope): Promise<Message>;
|
|
86
101
|
requireThread(id: string, scope: Scope): Promise<Thread>;
|
|
87
102
|
/** Scoped actors only reach contacts that take part in one of their threads. */
|
|
88
103
|
private requireContactAccess;
|
|
89
104
|
private mailboxFor;
|
|
105
|
+
/** Who sends for `id`; the catch-all answers as `address`, with the name and signature of a mailbox on that domain. */
|
|
90
106
|
private sendingMailbox;
|
|
91
107
|
/**
|
|
92
108
|
* Stores an inbound message once per provider id and returns its id. Attachments are copied to
|
package/dist/core/mail.js
CHANGED
|
@@ -28,21 +28,57 @@ export class Mail {
|
|
|
28
28
|
provider;
|
|
29
29
|
cfg;
|
|
30
30
|
ownAddresses;
|
|
31
|
+
domains;
|
|
31
32
|
timers = new Map();
|
|
32
33
|
files;
|
|
34
|
+
/** Fires "change" after every write, so open pages can refresh. */
|
|
35
|
+
changes = new EventTarget();
|
|
33
36
|
constructor(store, provider, cfg) {
|
|
34
37
|
this.store = store;
|
|
35
38
|
this.provider = provider;
|
|
36
39
|
this.cfg = cfg;
|
|
37
40
|
this.ownAddresses = new Set(Object.values(cfg.mailboxes).map(m => bareAddress(m.address)));
|
|
41
|
+
this.domains = new Set(Object.values(cfg.mailboxes).map(m => domainOf(m.address)));
|
|
38
42
|
this.files = new AttachmentFiles(cfg.dataDir);
|
|
39
43
|
}
|
|
44
|
+
/** Runs `fn` in the store's write queue, then announces the change. */
|
|
45
|
+
async write(fn) {
|
|
46
|
+
const result = await this.store.serialize(fn);
|
|
47
|
+
this.changes.dispatchEvent(new Event("change"));
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
40
50
|
listMailboxes(scope) {
|
|
41
51
|
return [
|
|
42
52
|
...Object.entries(this.cfg.mailboxes).map(([id, m]) => ({ id, address: m.address, name: m.name })),
|
|
43
53
|
{ id: CATCHALL, address: "*", name: "Catch-all" },
|
|
44
54
|
].filter(m => reaches(scope, m.id));
|
|
45
55
|
}
|
|
56
|
+
/** A configured mailbox address or any other address on its domains, such as one the catch-all received. */
|
|
57
|
+
isOwn(address) {
|
|
58
|
+
const bare = bareAddress(address);
|
|
59
|
+
return this.ownAddresses.has(bare) || this.domains.has(domainOf(bare));
|
|
60
|
+
}
|
|
61
|
+
/** The first address on our domains that is not a configured mailbox: the one a catch-all message was written to. */
|
|
62
|
+
catchAllAddress(addresses) {
|
|
63
|
+
return addresses.map(bareAddress).find(a => this.domains.has(domainOf(a)) && !this.ownAddresses.has(a)) ?? null;
|
|
64
|
+
}
|
|
65
|
+
/** The account a thread belongs to: its mailbox or, in the catch-all, the address it was written to. */
|
|
66
|
+
accountOf(thread) {
|
|
67
|
+
return thread.mailbox === CATCHALL ? this.catchAllAddress(thread.participants) ?? CATCHALL : thread.mailbox;
|
|
68
|
+
}
|
|
69
|
+
/** The address an account receives mail at: a configured mailbox's address, or the catch-all address itself. */
|
|
70
|
+
addressOf(account) {
|
|
71
|
+
const mailbox = this.cfg.mailboxes[account];
|
|
72
|
+
return mailbox ? bareAddress(mailbox.address) : account;
|
|
73
|
+
}
|
|
74
|
+
/** Mailboxes in scope, with the catch-all split into the addresses it has received mail for. */
|
|
75
|
+
async listAccounts(scope) {
|
|
76
|
+
const mailboxes = this.listMailboxes(scope).map(m => m.id).filter(id => id !== CATCHALL);
|
|
77
|
+
if (!reaches(scope, CATCHALL))
|
|
78
|
+
return mailboxes;
|
|
79
|
+
const caught = (await this.store.allThreads()).filter(t => t.mailbox === CATCHALL).map(t => this.accountOf(t));
|
|
80
|
+
return [...mailboxes, ...[...new Set(caught)].sort()];
|
|
81
|
+
}
|
|
46
82
|
// Out of scope reads as missing, so a scoped token cannot probe other mailboxes.
|
|
47
83
|
async requireMessage(id, scope) {
|
|
48
84
|
const message = await this.store.requireMessage(id);
|
|
@@ -73,7 +109,11 @@ export class Mail {
|
|
|
73
109
|
}
|
|
74
110
|
return CATCHALL;
|
|
75
111
|
}
|
|
76
|
-
|
|
112
|
+
/** Who sends for `id`; the catch-all answers as `address`, with the name and signature of a mailbox on that domain. */
|
|
113
|
+
sendingMailbox(id, address) {
|
|
114
|
+
const peer = id === CATCHALL && address ? Object.values(this.cfg.mailboxes).find(m => domainOf(m.address) === domainOf(address)) : undefined;
|
|
115
|
+
if (peer && address)
|
|
116
|
+
return { name: peer.name, address: bareAddress(address), signatureText: peer.signatureText, signatureHtml: peer.signatureHtml };
|
|
77
117
|
const mailbox = this.cfg.mailboxes[id];
|
|
78
118
|
if (!mailbox)
|
|
79
119
|
throw new InvalidRequestError(`Mailbox "${id}" cannot send (configured: ${Object.keys(this.cfg.mailboxes).join(", ")})`);
|
|
@@ -97,7 +137,7 @@ export class Mail {
|
|
|
97
137
|
return id;
|
|
98
138
|
}
|
|
99
139
|
storeInbound(providerId, inbound) {
|
|
100
|
-
return this.
|
|
140
|
+
return this.write(async () => {
|
|
101
141
|
const existing = await this.store.lookupProviderId(this.provider.name, providerId);
|
|
102
142
|
if (existing)
|
|
103
143
|
return existing;
|
|
@@ -110,7 +150,7 @@ export class Mail {
|
|
|
110
150
|
subject: inbound.subject,
|
|
111
151
|
participants,
|
|
112
152
|
at: inbound.receivedAt,
|
|
113
|
-
}, this.
|
|
153
|
+
}, address => this.isOwn(address), this.cfg.threadWindowDays);
|
|
114
154
|
const message = {
|
|
115
155
|
id: nid(),
|
|
116
156
|
provider: this.provider.name,
|
|
@@ -160,7 +200,7 @@ export class Mail {
|
|
|
160
200
|
}
|
|
161
201
|
/** Status updates never move backwards: a late `sent` does not overwrite `delivered`. */
|
|
162
202
|
applyStatus(providerId, status, messageId) {
|
|
163
|
-
return this.
|
|
203
|
+
return this.write(async () => {
|
|
164
204
|
const id = await this.store.lookupProviderId(this.provider.name, providerId);
|
|
165
205
|
if (!id)
|
|
166
206
|
return;
|
|
@@ -195,7 +235,7 @@ export class Mail {
|
|
|
195
235
|
return false;
|
|
196
236
|
if (byMeta && !byMeta(t.id, t.participants))
|
|
197
237
|
return false;
|
|
198
|
-
if (input.mailbox && t.mailbox !== input.mailbox)
|
|
238
|
+
if (input.mailbox && t.mailbox !== input.mailbox && this.accountOf(t) !== input.mailbox)
|
|
199
239
|
return false;
|
|
200
240
|
if (input.label && !t.labels[input.label])
|
|
201
241
|
return false;
|
|
@@ -242,7 +282,7 @@ export class Mail {
|
|
|
242
282
|
}
|
|
243
283
|
/** The thread's own context and the contacts of its external participants that have one. */
|
|
244
284
|
async contextOf(thread) {
|
|
245
|
-
const external = thread.participants.filter(p => !this.
|
|
285
|
+
const external = thread.participants.filter(p => !this.isOwn(p));
|
|
246
286
|
const contacts = (await Promise.all(external.map(p => this.store.getContact(p)))).filter((c) => !!c);
|
|
247
287
|
return { context: await this.store.getThreadContext(thread.id), contacts };
|
|
248
288
|
}
|
|
@@ -257,7 +297,7 @@ export class Mail {
|
|
|
257
297
|
if (!bare.includes("@"))
|
|
258
298
|
throw new InvalidRequestError(`"${address}" is not an email address`);
|
|
259
299
|
await this.requireContactAccess(bare, actor.scope);
|
|
260
|
-
return this.
|
|
300
|
+
return this.write(async () => {
|
|
261
301
|
const contact = { address: bare, ...this.merge(await this.store.getContact(bare), patch, actor) };
|
|
262
302
|
await this.store.putContact(contact);
|
|
263
303
|
await this.store.audit("contact.update", actor, bare, { ...patch });
|
|
@@ -265,7 +305,7 @@ export class Mail {
|
|
|
265
305
|
});
|
|
266
306
|
}
|
|
267
307
|
setThreadContext(threadId, patch, actor) {
|
|
268
|
-
return this.
|
|
308
|
+
return this.write(async () => {
|
|
269
309
|
await this.requireThread(threadId, actor.scope);
|
|
270
310
|
const context = this.merge(await this.store.getThreadContext(threadId), patch, actor);
|
|
271
311
|
await this.store.putThreadContext(threadId, context);
|
|
@@ -298,7 +338,7 @@ export class Mail {
|
|
|
298
338
|
return [...new Set(out)];
|
|
299
339
|
}
|
|
300
340
|
updateMessages(ids, actor, action, change) {
|
|
301
|
-
return this.
|
|
341
|
+
return this.write(async () => {
|
|
302
342
|
const messageIds = await this.resolveMessageIds(ids, actor.scope);
|
|
303
343
|
const threads = new Set();
|
|
304
344
|
for (const id of messageIds) {
|
|
@@ -331,7 +371,7 @@ export class Mail {
|
|
|
331
371
|
}
|
|
332
372
|
// Drafts and sending
|
|
333
373
|
createDraft(input, actor) {
|
|
334
|
-
return this.
|
|
374
|
+
return this.write(() => this.createDraftUnlocked(input, actor));
|
|
335
375
|
}
|
|
336
376
|
/** Who a reply to `replyToId` goes to and its subject, without creating anything. */
|
|
337
377
|
async replyTo(replyToId, replyAll, scope) {
|
|
@@ -340,13 +380,16 @@ export class Mail {
|
|
|
340
380
|
replyDefaults(original, given, replyAll) {
|
|
341
381
|
const mailbox = given.mailbox ?? original.mailbox;
|
|
342
382
|
const to = given.to ?? (original.direction === "in" ? (original.reply_to.length ? original.reply_to : [original.from]) : original.to);
|
|
343
|
-
const
|
|
383
|
+
const caught = mailbox === CATCHALL ? this.catchAllAddress(original.direction === "out" ? [original.from] : [...original.to, ...original.cc]) : null;
|
|
384
|
+
const sender = this.sendingMailbox(mailbox, caught);
|
|
385
|
+
const already = new Set([bareAddress(sender.address), ...to.map(bareAddress)]);
|
|
344
386
|
const cc = replyAll ? [...original.to, ...original.cc].filter(a => !already.has(bareAddress(a))) : [];
|
|
345
|
-
return { mailbox, to, cc, subject: replySubject(original.subject) };
|
|
387
|
+
return { mailbox, sender, to, cc, subject: replySubject(original.subject) };
|
|
346
388
|
}
|
|
347
389
|
async createDraftUnlocked(input, actor) {
|
|
348
390
|
const now = new Date().toISOString();
|
|
349
391
|
let mailbox;
|
|
392
|
+
let sender;
|
|
350
393
|
let to;
|
|
351
394
|
let cc = input.cc ?? [];
|
|
352
395
|
let subject;
|
|
@@ -357,6 +400,7 @@ export class Mail {
|
|
|
357
400
|
const original = await this.requireMessage(input.replyToId, actor.scope);
|
|
358
401
|
const defaults = this.replyDefaults(original, input, !!input.replyAll && !input.cc);
|
|
359
402
|
mailbox = defaults.mailbox;
|
|
403
|
+
sender = defaults.sender;
|
|
360
404
|
to = defaults.to;
|
|
361
405
|
if (!input.cc)
|
|
362
406
|
cc = defaults.cc;
|
|
@@ -373,11 +417,11 @@ export class Mail {
|
|
|
373
417
|
if (input.subject === undefined)
|
|
374
418
|
throw new InvalidRequestError("subject is required when not replying");
|
|
375
419
|
mailbox = input.mailbox;
|
|
420
|
+
sender = this.sendingMailbox(mailbox, null);
|
|
376
421
|
to = input.to;
|
|
377
422
|
subject = input.subject;
|
|
378
423
|
threadId = nid();
|
|
379
424
|
}
|
|
380
|
-
const sender = this.sendingMailbox(mailbox);
|
|
381
425
|
if (!reaches(actor.scope, mailbox))
|
|
382
426
|
throw new InvalidRequestError(`Mailbox "${mailbox}" is not available to ${actor.name}`);
|
|
383
427
|
const draft = {
|
|
@@ -429,7 +473,7 @@ export class Mail {
|
|
|
429
473
|
* human edited unless it passes `force`. A UI edit regenerates the HTML from the text at send time.
|
|
430
474
|
*/
|
|
431
475
|
updateDraft(id, version, patch, actor, force = false) {
|
|
432
|
-
return this.
|
|
476
|
+
return this.write(async () => {
|
|
433
477
|
const draft = await this.requireDraft(id, actor.scope);
|
|
434
478
|
if (draft.version !== version)
|
|
435
479
|
throw new ConflictError(draft);
|
|
@@ -453,7 +497,7 @@ export class Mail {
|
|
|
453
497
|
});
|
|
454
498
|
}
|
|
455
499
|
discardDraft(id, actor) {
|
|
456
|
-
return this.
|
|
500
|
+
return this.write(() => this.discardDraftUnlocked(id, actor));
|
|
457
501
|
}
|
|
458
502
|
async discardDraftUnlocked(id, actor) {
|
|
459
503
|
const draft = await this.requireDraft(id, actor.scope);
|
|
@@ -466,7 +510,7 @@ export class Mail {
|
|
|
466
510
|
}
|
|
467
511
|
/** Attaching does not change `version`: it never conflicts with text edits in flight. */
|
|
468
512
|
attach(id, file, actor) {
|
|
469
|
-
return this.
|
|
513
|
+
return this.write(async () => {
|
|
470
514
|
const draft = await this.requireDraft(id, actor.scope);
|
|
471
515
|
if (draft.pending)
|
|
472
516
|
throw new InvalidRequestError(`Draft ${id} is about to ${draft.pending.action}; undo it first`);
|
|
@@ -486,7 +530,7 @@ export class Mail {
|
|
|
486
530
|
});
|
|
487
531
|
}
|
|
488
532
|
detach(id, attachmentId, actor) {
|
|
489
|
-
return this.
|
|
533
|
+
return this.write(async () => {
|
|
490
534
|
const draft = await this.requireDraft(id, actor.scope);
|
|
491
535
|
if (draft.pending)
|
|
492
536
|
throw new InvalidRequestError(`Draft ${id} is about to ${draft.pending.action}; undo it first`);
|
|
@@ -502,7 +546,7 @@ export class Mail {
|
|
|
502
546
|
// Undo window: a human's send or discard waits `ui.undoSec` and survives a restart.
|
|
503
547
|
/** Starts the undo window for a send or discard. Calling it again keeps the first one. */
|
|
504
548
|
schedule(id, action, actor) {
|
|
505
|
-
return this.
|
|
549
|
+
return this.write(async () => {
|
|
506
550
|
const draft = await this.requireDraft(id, actor.scope);
|
|
507
551
|
if (!draft.pending) {
|
|
508
552
|
draft.pending = { action, at: new Date(Date.now() + this.cfg.ui.undoSec * 1000).toISOString(), by: actor.name };
|
|
@@ -514,7 +558,7 @@ export class Mail {
|
|
|
514
558
|
});
|
|
515
559
|
}
|
|
516
560
|
undo(id, actor) {
|
|
517
|
-
return this.
|
|
561
|
+
return this.write(async () => {
|
|
518
562
|
const draft = await this.requireDraft(id, actor.scope);
|
|
519
563
|
clearTimeout(this.timers.get(id));
|
|
520
564
|
this.timers.delete(id);
|
|
@@ -550,7 +594,7 @@ export class Mail {
|
|
|
550
594
|
/** A failed send leaves a plain pending draft, so the reviewer sees it was not sent. */
|
|
551
595
|
runPending(id) {
|
|
552
596
|
this.timers.delete(id);
|
|
553
|
-
return this.
|
|
597
|
+
return this.write(async () => {
|
|
554
598
|
const draft = await this.store.getMessage(id);
|
|
555
599
|
if (!draft || draft.status !== "draft" || !draft.pending)
|
|
556
600
|
return;
|
|
@@ -565,7 +609,7 @@ export class Mail {
|
|
|
565
609
|
});
|
|
566
610
|
}
|
|
567
611
|
sendDraft(id, actor) {
|
|
568
|
-
return this.
|
|
612
|
+
return this.write(() => this.sendDraftUnlocked(id, actor));
|
|
569
613
|
}
|
|
570
614
|
/**
|
|
571
615
|
* The draft id is the idempotency key and the Message-ID is stored before the provider call,
|
|
@@ -573,7 +617,7 @@ export class Mail {
|
|
|
573
617
|
*/
|
|
574
618
|
async sendDraftUnlocked(id, actor) {
|
|
575
619
|
const draft = await this.requireDraft(id, actor.scope);
|
|
576
|
-
const sender = this.sendingMailbox(draft.mailbox);
|
|
620
|
+
const sender = this.sendingMailbox(draft.mailbox, draft.from);
|
|
577
621
|
if (!draft.message_id) {
|
|
578
622
|
draft.message_id = `<${randomUUID()}@${domainOf(sender.address)}>`;
|
|
579
623
|
await this.store.putMessage(draft);
|
|
@@ -615,7 +659,7 @@ export class Mail {
|
|
|
615
659
|
}
|
|
616
660
|
/** Direct send. If the provider fails, the message stays as a pending draft. */
|
|
617
661
|
send(input, actor) {
|
|
618
|
-
return this.
|
|
662
|
+
return this.write(async () => {
|
|
619
663
|
const draft = await this.createDraftUnlocked(input, actor);
|
|
620
664
|
return this.sendDraftUnlocked(draft.id, actor);
|
|
621
665
|
});
|
package/dist/core/threads.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface ThreadLookup {
|
|
|
15
15
|
* 2. Same normalized subject and a shared external participant, within the window.
|
|
16
16
|
* 3. A new thread.
|
|
17
17
|
*/
|
|
18
|
-
export declare function resolveThreadId(store: Store, lookup: ThreadLookup,
|
|
18
|
+
export declare function resolveThreadId(store: Store, lookup: ThreadLookup, isOwn: (address: string) => boolean, windowDays: number): Promise<string>;
|
|
19
19
|
export declare function threadMessages(store: Store, thread: Thread): Promise<Message[]>;
|
|
20
20
|
/** Recomputes the thread summary, adding `newMessageId` when given. A thread left with only discarded drafts is removed. */
|
|
21
21
|
export declare function refreshThread(store: Store, threadId: string, newMessageId?: string): Promise<Thread | null>;
|
package/dist/core/threads.js
CHANGED
|
@@ -13,7 +13,7 @@ export function participantsOf(message) {
|
|
|
13
13
|
* 2. Same normalized subject and a shared external participant, within the window.
|
|
14
14
|
* 3. A new thread.
|
|
15
15
|
*/
|
|
16
|
-
export async function resolveThreadId(store, lookup,
|
|
16
|
+
export async function resolveThreadId(store, lookup, isOwn, windowDays) {
|
|
17
17
|
for (const ref of [lookup.inReplyTo, ...[...lookup.references].reverse()]) {
|
|
18
18
|
if (!ref)
|
|
19
19
|
continue;
|
|
@@ -23,7 +23,7 @@ export async function resolveThreadId(store, lookup, ownAddresses, windowDays) {
|
|
|
23
23
|
return message.thread_id;
|
|
24
24
|
}
|
|
25
25
|
const subject = normalizeSubject(lookup.subject);
|
|
26
|
-
const external = new Set(lookup.participants.filter(p => !
|
|
26
|
+
const external = new Set(lookup.participants.filter(p => !isOwn(p)));
|
|
27
27
|
if (subject && external.size) {
|
|
28
28
|
const since = new Date(lookup.at).getTime() - windowDays * DAY_MS;
|
|
29
29
|
const match = (await store.allThreads())
|
package/dist/ui/routes.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { deleteCookie, getCookie, getSignedCookie, setCookie, setSignedCookie } from "hono/cookie";
|
|
2
|
-
import {
|
|
2
|
+
import { streamSSE } from "hono/streaming";
|
|
3
|
+
import { domainOf, splitAddresses } from "../core/address.js";
|
|
3
4
|
import { ConflictError, InvalidRequestError, toView } from "../core/mail.js";
|
|
4
5
|
import { CATCHALL } from "../types.js";
|
|
5
6
|
import { S } from "./strings.js";
|
|
@@ -23,12 +24,13 @@ function uiActor(session) {
|
|
|
23
24
|
export function registerUi(app, mail, access, cfg) {
|
|
24
25
|
const secret = cfg.ui.cookieSecret;
|
|
25
26
|
const cookieOptions = { httpOnly: true, secure: true, sameSite: "Lax", path: "/", maxAge: COOKIE_MAX_AGE };
|
|
26
|
-
const
|
|
27
|
-
|
|
27
|
+
const hue = V.accentHue([...new Set(Object.values(cfg.mailboxes).map(m => domainOf(m.address)))]);
|
|
28
|
+
const own = (address) => mail.isOwn(address);
|
|
29
|
+
/** Recipients that are our own addresses are implied by the mailbox badge. */
|
|
28
30
|
const shown = (m) => ({
|
|
29
31
|
...m,
|
|
30
|
-
to: m.to.filter(a => !own
|
|
31
|
-
cc: m.cc.filter(a => !own
|
|
32
|
+
to: m.to.filter(a => !own(a)),
|
|
33
|
+
cc: m.cc.filter(a => !own(a)),
|
|
32
34
|
});
|
|
33
35
|
/** Mailboxes a session can send from: every one in its scope but the catch-all. */
|
|
34
36
|
const senders = (session) => mail.listMailboxes(session.scope).filter(m => m.id !== CATCHALL);
|
|
@@ -38,7 +40,7 @@ export function registerUi(app, mail, access, cfg) {
|
|
|
38
40
|
const shell = session
|
|
39
41
|
? { draftCount: (await mail.listDrafts(undefined, session.scope)).length, senders: senders(session) }
|
|
40
42
|
: {};
|
|
41
|
-
return c.html(V.layout(title, body, { theme: theme(c), page: current, signedIn: !!session, fullScreen, ...shell }), status);
|
|
43
|
+
return c.html(V.layout(title, body, { theme: theme(c), hue, page: current, signedIn: !!session, fullScreen, ...shell }), status);
|
|
42
44
|
};
|
|
43
45
|
// Sign-in: GET only shows a button, so link previews and scanners do not burn the link.
|
|
44
46
|
// A used or expired link on a browser that is already signed in just opens the app.
|
|
@@ -70,7 +72,7 @@ export function registerUi(app, mail, access, cfg) {
|
|
|
70
72
|
const path = back && new URL(back).origin === new URL(c.req.url).origin ? new URL(back).pathname + new URL(back).search : "/";
|
|
71
73
|
return c.redirect(path, 303);
|
|
72
74
|
});
|
|
73
|
-
const ui = ["/", "/inbox", "/threads/*", "/drafts/*", "/attachments/*", "/compose", "/devices", "/devices/*", "/settings", "/logout"];
|
|
75
|
+
const ui = ["/", "/inbox", "/threads/*", "/drafts/*", "/attachments/*", "/compose", "/devices", "/devices/*", "/settings", "/logout", "/events"];
|
|
74
76
|
for (const path of ui) {
|
|
75
77
|
app.use(path, async (c, next) => {
|
|
76
78
|
const value = await getSignedCookie(c, secret, SESSION_COOKIE);
|
|
@@ -96,8 +98,9 @@ export function registerUi(app, mail, access, cfg) {
|
|
|
96
98
|
return V.draftCard(draft);
|
|
97
99
|
};
|
|
98
100
|
app.get("/", async (c) => {
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
+
const session = c.get("session");
|
|
102
|
+
const drafts = await mail.listDrafts(undefined, session.scope);
|
|
103
|
+
return page(c, S.navDrafts, V.inboxPage(V.draftList(drafts, domainsOf(session), null), null), "drafts");
|
|
101
104
|
});
|
|
102
105
|
app.get("/drafts/:id", async (c) => {
|
|
103
106
|
const session = c.get("session");
|
|
@@ -106,7 +109,7 @@ export function registerUi(app, mail, access, cfg) {
|
|
|
106
109
|
return c.redirect(`/threads/${draft.thread_id}?status=all`, 303);
|
|
107
110
|
const { thread, view } = await threadPane(c, draft.thread_id, "/");
|
|
108
111
|
const drafts = await mail.listDrafts(undefined, session.scope);
|
|
109
|
-
return page(c, thread.subject || S.navDrafts, V.inboxPage(V.draftList(drafts, draft.id), view), "drafts", 200, true);
|
|
112
|
+
return page(c, thread.subject || S.navDrafts, V.inboxPage(V.draftList(drafts, domainsOf(session), draft.id), view), "drafts", 200, true);
|
|
110
113
|
});
|
|
111
114
|
app.get("/drafts/:id/card", async (c) => c.html(await draftView(c, c.req.param("id"))));
|
|
112
115
|
app.get("/drafts/:id/edit", async (c) => {
|
|
@@ -194,8 +197,8 @@ export function registerUi(app, mail, access, cfg) {
|
|
|
194
197
|
const session = c.get("session");
|
|
195
198
|
const filter = inboxFilter(c);
|
|
196
199
|
const threads = await mail.listThreads({ mailbox: filter.mailbox || undefined, status: filter.status, limit: 200 }, session.scope);
|
|
197
|
-
const
|
|
198
|
-
return V.threadList(threads, {
|
|
200
|
+
const accounts = await mail.listAccounts(session.scope);
|
|
201
|
+
return V.threadList(threads, { accounts, accountOf: t => mail.accountOf(t), addressOf: a => mail.addressOf(a), domains: domainsOf(session), filter, own, current });
|
|
199
202
|
};
|
|
200
203
|
app.get("/inbox", async (c) => page(c, S.navInbox, V.inboxPage(await threadList(c, null), null), "inbox"));
|
|
201
204
|
/** A thread with its drafts in place; opening it marks it read. */
|
|
@@ -207,13 +210,14 @@ export function registerUi(app, mail, access, cfg) {
|
|
|
207
210
|
thread = await mail.requireThread(id, session.scope);
|
|
208
211
|
}
|
|
209
212
|
const { messages, context, contacts } = await mail.getThread(id, session.scope);
|
|
210
|
-
const people = thread.participants.filter(p => !own
|
|
213
|
+
const people = thread.participants.filter(p => !own(p));
|
|
211
214
|
const entries = await Promise.all(messages.map(async (m) => ({
|
|
212
215
|
at: m.date,
|
|
213
216
|
view: m.status === "draft" ? V.draftCard(await mail.store.requireMessage(m.id)) : V.messageBubble(shown(m), people.length > 1),
|
|
214
217
|
})));
|
|
215
|
-
const
|
|
216
|
-
|
|
218
|
+
const account = mail.accountOf(thread);
|
|
219
|
+
const reply = { allowed: account !== CATCHALL && (thread.mailbox === CATCHALL || senders(session).some(m => m.id === thread.mailbox)), replyAll: people.length > 1 };
|
|
220
|
+
return { thread, view: V.threadView(thread, entries, { context, contacts }, { back, filter: inboxFilter(c), own, account, reply }) };
|
|
217
221
|
};
|
|
218
222
|
app.get("/threads/:id", async (c) => {
|
|
219
223
|
const id = c.req.param("id");
|
|
@@ -325,8 +329,15 @@ export function registerUi(app, mail, access, cfg) {
|
|
|
325
329
|
});
|
|
326
330
|
app.get("/devices", async (c) => {
|
|
327
331
|
const session = c.get("session");
|
|
328
|
-
return page(c, S.navDevices, V.devicesPage(await access.listSessions(session.scope), session.id), "devices");
|
|
332
|
+
return page(c, S.navDevices, V.devicesPage(await access.listSessions(session.scope), session.id, a => mail.addressOf(a)), "devices");
|
|
329
333
|
});
|
|
334
|
+
// Every write pings open pages, which refetch their live regions; the stream carries no mail data.
|
|
335
|
+
app.get("/events", c => streamSSE(c, async (stream) => {
|
|
336
|
+
const ping = () => void stream.writeSSE({ event: "change", data: "1" });
|
|
337
|
+
mail.changes.addEventListener("change", ping);
|
|
338
|
+
await new Promise(resolve => stream.onAbort(resolve));
|
|
339
|
+
mail.changes.removeEventListener("change", ping);
|
|
340
|
+
}));
|
|
330
341
|
app.get("/settings", async (c) => page(c, S.navSettings, V.settingsPage(theme(c)), "settings"));
|
|
331
342
|
app.post("/devices/:id/revoke", async (c) => {
|
|
332
343
|
await access.revokeSession(c.req.param("id"), uiActor(c.get("session")));
|
|
@@ -336,6 +347,6 @@ export function registerUi(app, mail, access, cfg) {
|
|
|
336
347
|
const session = c.get("session");
|
|
337
348
|
await access.revokeSession(session.id, uiActor(session), "session.logout");
|
|
338
349
|
deleteCookie(c, SESSION_COOKIE, { path: "/", secure: true });
|
|
339
|
-
return c.html(V.layout(S.signedOut, V.message([S.signedOut]), { theme: theme(c), page: null, signedIn: false }));
|
|
350
|
+
return c.html(V.layout(S.signedOut, V.message([S.signedOut]), { theme: theme(c), hue, page: null, signedIn: false }));
|
|
340
351
|
});
|
|
341
352
|
}
|
package/dist/ui/static/app.js
CHANGED
|
@@ -33,11 +33,72 @@ document.addEventListener("keydown", event => {
|
|
|
33
33
|
if (event.key === "Escape") document.body.classList.remove("context-open");
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
//
|
|
37
|
-
|
|
36
|
+
// Links and forms load the next page with htmx and swap only the body, so scripts and styles stay loaded.
|
|
37
|
+
// The body's classes come from the new page, and an error page shows instead of nothing.
|
|
38
|
+
// Back and forward reload the page (see htmx-config), so a page is never restored with stale mail.
|
|
39
|
+
document.addEventListener("htmx:beforeSwap", event => {
|
|
40
|
+
if (!event.detail.boosted) return;
|
|
41
|
+
if (event.detail.xhr.status >= 400) {
|
|
42
|
+
event.detail.shouldSwap = true;
|
|
43
|
+
event.detail.isError = false;
|
|
44
|
+
}
|
|
45
|
+
document.body.className = /<body[^>]*class="([^"]*)"/.exec(event.detail.serverResponse)?.[1] ?? "";
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
document.addEventListener("htmx:afterSwap", event => {
|
|
49
|
+
if (event.detail.boosted) pageShown();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
document.addEventListener("DOMContentLoaded", pageShown);
|
|
53
|
+
|
|
54
|
+
// A thread opens at its latest message; a signed-in page listens for changes.
|
|
55
|
+
function pageShown() {
|
|
38
56
|
const messages = document.querySelector("[data-scroll-end]");
|
|
39
57
|
if (messages) messages.scrollTop = messages.scrollHeight;
|
|
40
|
-
|
|
58
|
+
listen();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// The server reports every change to the mail; the page then refetches itself once and swaps in its
|
|
62
|
+
// [data-live] regions by id. A burst of changes waits for a short quiet spell.
|
|
63
|
+
const REFRESH_DELAY_MS = 300;
|
|
64
|
+
let source = null;
|
|
65
|
+
let timer = null;
|
|
66
|
+
|
|
67
|
+
function listen() {
|
|
68
|
+
const signedIn = document.body.classList.contains("app");
|
|
69
|
+
if (signedIn && !source) {
|
|
70
|
+
source = new EventSource("/events");
|
|
71
|
+
source.addEventListener("change", refreshSoon);
|
|
72
|
+
// After a reconnect, changes made while it was down are caught up.
|
|
73
|
+
let opened = false;
|
|
74
|
+
source.addEventListener("open", () => opened ? refreshSoon() : opened = true);
|
|
75
|
+
} else if (!signedIn && source) {
|
|
76
|
+
source.close();
|
|
77
|
+
source = null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function refreshSoon() {
|
|
82
|
+
clearTimeout(timer);
|
|
83
|
+
timer = setTimeout(refresh, REFRESH_DELAY_MS);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function refresh() {
|
|
87
|
+
if (!document.querySelector("[data-live]")) return;
|
|
88
|
+
const url = location.href;
|
|
89
|
+
const res = await fetch(url);
|
|
90
|
+
if (!res.ok || location.href !== url) return;
|
|
91
|
+
const next = new DOMParser().parseFromString(await res.text(), "text/html");
|
|
92
|
+
for (const region of document.querySelectorAll("[data-live]")) {
|
|
93
|
+
const fresh = next.getElementById(region.id);
|
|
94
|
+
if (!fresh || region.contains(document.activeElement?.closest("input, select, textarea"))) continue;
|
|
95
|
+
const atEnd = region.scrollHeight - region.scrollTop - region.clientHeight < 2;
|
|
96
|
+
const scrollTop = region.scrollTop;
|
|
97
|
+
region.replaceWith(fresh);
|
|
98
|
+
fresh.scrollTop = fresh.hasAttribute("data-scroll-end") && atEnd ? fresh.scrollHeight : scrollTop;
|
|
99
|
+
htmx.process(fresh);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
41
102
|
|
|
42
103
|
// Files dropped on a [data-drop] zone go to its file input, which uploads them through htmx.
|
|
43
104
|
const zoneOf = event => event.target instanceof Element ? event.target.closest("[data-drop]") : null;
|
package/dist/ui/static/style.css
CHANGED
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
--soft: light-dark(#f1f1ef, #1f1f1e);
|
|
8
8
|
--chip: light-dark(#e9e9e6, #333331);
|
|
9
9
|
--surface: light-dark(#ffffff, #2e2e2c);
|
|
10
|
-
--
|
|
11
|
-
--mine
|
|
12
|
-
--
|
|
13
|
-
--accent
|
|
10
|
+
/* --hue is set per instance on <html>, from its mail domains. */
|
|
11
|
+
--mine: light-dark(oklch(0.95 0.03 var(--hue)), oklch(0.33 0.045 var(--hue)));
|
|
12
|
+
--mine-line: light-dark(oklch(0.89 0.055 var(--hue)), oklch(0.4 0.06 var(--hue)));
|
|
13
|
+
--accent: light-dark(oklch(0.75 0.13 var(--hue)), oklch(0.78 0.11 var(--hue)));
|
|
14
|
+
--accent-text: light-dark(oklch(0.5 0.13 var(--hue)), oklch(0.83 0.09 var(--hue)));
|
|
14
15
|
--focus: light-dark(#0a0a0a, #a3a39e);
|
|
15
16
|
--primary-bg: light-dark(#0a0a0a, #ececea);
|
|
16
17
|
--primary-fg: light-dark(#fbfbfa, #1f1f1e);
|
|
@@ -31,14 +32,14 @@
|
|
|
31
32
|
body { margin: 0; background: var(--bg); color: var(--fg); }
|
|
32
33
|
a { color: inherit; text-decoration: none; }
|
|
33
34
|
h1 { font-size: 2rem; line-height: 1.1; letter-spacing: -0.04em; font-weight: 700; margin: 0 0 24px; }
|
|
34
|
-
::selection { background: var(--accent); color: #
|
|
35
|
+
::selection { background: var(--accent); color: #1f1f1e; }
|
|
35
36
|
.icon { flex: none; }
|
|
36
37
|
|
|
37
38
|
/* Shell: a tab bar on a phone, a sidebar on a wide screen */
|
|
38
39
|
.sidebar { display: none; }
|
|
39
40
|
body.app { padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }
|
|
40
41
|
body.app.full { padding-bottom: 0; }
|
|
41
|
-
.page { max-width: 760px;
|
|
42
|
+
.page { max-width: 760px; padding: 24px 16px 32px; }
|
|
42
43
|
|
|
43
44
|
.tabbar {
|
|
44
45
|
position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
|
|
@@ -75,7 +76,7 @@ body.full .tabbar { display: none; }
|
|
|
75
76
|
display: flex; flex-direction: column; gap: 4px;
|
|
76
77
|
padding: 20px 14px; border-right: 1px solid var(--line);
|
|
77
78
|
}
|
|
78
|
-
.brand { font-size:
|
|
79
|
+
.brand { font-size: 21px; line-height: 1.2; font-weight: 700; letter-spacing: -0.03em; text-transform: lowercase; padding: 0 12px; }
|
|
79
80
|
.brand span { color: var(--accent); }
|
|
80
81
|
.new-mail { display: flex; align-items: center; justify-content: center; gap: 8px; height: 44px; border-radius: 12px; margin: 16px 0 14px; }
|
|
81
82
|
.side-nav { display: flex; flex-direction: column; gap: 2px; }
|
|
@@ -103,8 +104,9 @@ body.full .tabbar { display: none; }
|
|
|
103
104
|
body.context-open .split .list { display: none; }
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
.list-head { padding:
|
|
107
|
+
.list-head { padding: 20px 16px 12px; }
|
|
107
108
|
.list-head h1 { font-size: 21px; line-height: 1.2; letter-spacing: -0.02em; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
109
|
+
.list-head small { font-size: 13px; font-weight: 500; letter-spacing: 0; color: var(--muted); margin-left: 4px; }
|
|
108
110
|
.filters { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
|
|
109
111
|
.chips { display: flex; flex: none; gap: 8px; }
|
|
110
112
|
.filters .select { min-width: 0; }
|
|
@@ -200,8 +202,9 @@ button.thread-title:hover { background: var(--soft); border: none; }
|
|
|
200
202
|
}
|
|
201
203
|
.composer textarea:focus { border-color: var(--focus); }
|
|
202
204
|
.composer .send { width: 44px; height: 44px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
|
|
203
|
-
.reply-all { flex-basis: 100%; display: flex; align-items: center; gap: 8px; padding: 2px
|
|
204
|
-
|
|
205
|
+
.reply-all { flex-basis: 100%; display: flex; align-items: center; gap: 8px; padding: 2px 0; font-family: var(--mono); font-size: .72rem; color: var(--muted); cursor: pointer; }
|
|
206
|
+
/* Centered over the + button below it, which is 44px wide. */
|
|
207
|
+
.reply-all input { width: 16px; height: 16px; margin: 0 0 0 14px; flex: none; accent-color: var(--accent); }
|
|
205
208
|
|
|
206
209
|
/* Context: a side panel on a wide screen, a bottom sheet on a phone */
|
|
207
210
|
.context-panel { display: none; background: var(--bg); }
|
|
@@ -394,6 +397,7 @@ textarea {
|
|
|
394
397
|
.setting label { font-weight: 500; }
|
|
395
398
|
.row.device:hover { background: none; }
|
|
396
399
|
.row.device .avatar { color: var(--muted); }
|
|
400
|
+
.row.device form { display: contents; }
|
|
397
401
|
.row.device .danger { align-self: center; padding: 0; height: auto; border: none; background: none; }
|
|
398
402
|
.row.device .danger:hover { text-decoration: underline; }
|
|
399
403
|
.setting .danger, .setting .danger:hover { padding: 0; height: auto; border: none; background: none; }
|