clavarium 0.2.472-next.1 → 0.2.474-next.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.
- package/npm-shrinkwrap.json +6 -6
- package/package.json +2 -2
- package/server/api.mjs +8 -0
- package/server/contactview.mjs +121 -0
- package/server/mailview.mjs +203 -0
- package/server/settingswords.mjs +13 -0
- package/web/app.js +210 -10
- package/web/style.css +30 -0
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.474-next.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.474-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"clavarium-binder": "0.1.63-next.1",
|
|
15
15
|
"clavarium-docket": "0.1.2-next.2",
|
|
16
16
|
"clavarium-parley": "0.17.95-next.1",
|
|
17
|
-
"clavarium-tether": "0.1.0-next.
|
|
17
|
+
"clavarium-tether": "0.1.0-next.71",
|
|
18
18
|
"mammoth": "1.13.0",
|
|
19
19
|
"mermaid": "11.17.2",
|
|
20
20
|
"node-pty": "^1.1.0",
|
|
@@ -800,9 +800,9 @@
|
|
|
800
800
|
}
|
|
801
801
|
},
|
|
802
802
|
"node_modules/clavarium-tether": {
|
|
803
|
-
"version": "0.1.0-next.
|
|
804
|
-
"resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.
|
|
805
|
-
"integrity": "sha512-
|
|
803
|
+
"version": "0.1.0-next.71",
|
|
804
|
+
"resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.71.tgz",
|
|
805
|
+
"integrity": "sha512-frcFmLxpQZ1v+ZoybFkZ8+aAjlvqyS+lDUoiqfIL5qPAxJupLr1nhle23FHt8lVG1PtIifoFSNUvyyt6q8BBOw==",
|
|
806
806
|
"license": "MIT",
|
|
807
807
|
"bin": {
|
|
808
808
|
"tether": "bin/cli.mjs",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.474-next.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"clavarium-binder": "0.1.63-next.1",
|
|
49
49
|
"clavarium-docket": "0.1.2-next.2",
|
|
50
50
|
"clavarium-parley": "0.17.95-next.1",
|
|
51
|
-
"clavarium-tether": "0.1.0-next.
|
|
51
|
+
"clavarium-tether": "0.1.0-next.71",
|
|
52
52
|
"mammoth": "1.13.0",
|
|
53
53
|
"mermaid": "11.17.2",
|
|
54
54
|
"node-pty": "^1.1.0",
|
package/server/api.mjs
CHANGED
|
@@ -173,6 +173,8 @@
|
|
|
173
173
|
* GET /api/files/download?c=...&r=...&p=<path> one file
|
|
174
174
|
* GET /api/mail/open?ref=mail:...&c= GET /api/mail/page?ref=... a mail cited by its reference, read now (mailref.mjs)
|
|
175
175
|
* POST /api/tether/agenda {target, from?, to?}: a calendar's events of a window, read now (agenda.mjs)
|
|
176
|
+
* POST /api/tether/mail-list|mail-read {target, folder?, text?} | {target, id, folder?}: a mailbox's latest messages, one as text (mailview.mjs)
|
|
177
|
+
* POST /api/tether/contacts|contact {target, text?} | {target, id}: an address book's contacts, one (contactview.mjs)
|
|
176
178
|
* POST /api/files/import?c=...&r=...&p=<folder>&name=<file name>[&dir=<subfolders>&exists=keep|replace|skip&batch=<id>] the body IS the file
|
|
177
179
|
* GET /api/files/thumb|text POST /api/files/save|make|rename|move|remove|taken ?c=...&r=...&p=... (see files.mjs)
|
|
178
180
|
*
|
|
@@ -190,6 +192,8 @@ import { VmUnknown } from './vm.mjs';
|
|
|
190
192
|
import { list, download, importFile, page, PAGE_HEADERS, changeRoute, IMAGE_HEADERS, mailFile, mailPage } from './files.mjs';
|
|
191
193
|
import { mailRoute } from './mailref.mjs';
|
|
192
194
|
import { readAgenda } from './agenda.mjs';
|
|
195
|
+
import { readMailList, readMail } from './mailview.mjs';
|
|
196
|
+
import { readContacts, readContact } from './contactview.mjs';
|
|
193
197
|
import { WORK_TAB } from './resources.mjs';
|
|
194
198
|
import { transcribe, AUDIO_MAX } from './voice.mjs';
|
|
195
199
|
import { FILE_MAX } from './setup.mjs';
|
|
@@ -728,6 +732,10 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
728
732
|
/* A calendar's agenda, read now through Tether as the owner's own read (agenda.mjs, 16-11): seen in its asset
|
|
729
733
|
panel, so the calendar need not stay open elsewhere. A POST, for this site's own pages only (checked above). */
|
|
730
734
|
if (pathname === '/api/tether/agenda' && tethers) return send(200, await readAgenda(tethers, body ?? {}, { who: { id: `person:${identity || 'owner'}`, name: identity || 'Owner' } })), true;
|
|
735
|
+
/* A mailbox's latest messages and one as text, an address book's contacts and one, read the same way (16-11:
|
|
736
|
+
mailview.mjs, contactview.mjs): never marked read, nothing changed. */
|
|
737
|
+
const peek = { '/api/tether/mail-list': readMailList, '/api/tether/mail-read': readMail, '/api/tether/contacts': readContacts, '/api/tether/contact': readContact }[pathname];
|
|
738
|
+
if (peek && tethers) return send(200, await peek(tethers, body ?? {}, { who: { id: `person:${identity || 'owner'}`, name: identity || 'Owner' } })), true;
|
|
731
739
|
/* A mailbox's signature (Markdown), added under what the agent sends from it. */
|
|
732
740
|
if (pathname === '/api/tether/signature' && tethers) {
|
|
733
741
|
const t = tethers.store().target(String(body.target ?? ''));
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/* AN ADDRESS BOOK, SEEN BY ITS OWNER (16-11): the contacts of a contacts asset (a Tether target of kind contacts:
|
|
2
|
+
* Microsoft over Graph, Google or a classic book over CardDAV), shown in its asset panel, as the agenda is (agenda.mjs).
|
|
3
|
+
*
|
|
4
|
+
* POST /api/tether/contacts {target, text?} the contacts, or those whose name or email matches (Tether's
|
|
5
|
+
* contacts.search). -> { target, title, text, contacts: [{id, name, emails, phones,
|
|
6
|
+
* company}], more, partial }
|
|
7
|
+
* POST /api/tether/contact {target, id} one contact. -> { target, id, name, emails, phones, company,
|
|
8
|
+
* facts: [[word, value]], notes, partial }
|
|
9
|
+
*
|
|
10
|
+
* READ THROUGH TETHER, as an agent's contacts-list is: the sign-in stays in this server, never in the answer, never
|
|
11
|
+
* in the browser; the read is the owner's own in Tether's journal, never an agent's. READ ONLY. Nothing is kept here.
|
|
12
|
+
*
|
|
13
|
+
* A Tether that hands its contacts as data (`data.contacts`, `data.contact`: the fields below) gives them all; one that
|
|
14
|
+
* gives only its text lines (0.1.0-next.69) gives name, emails and phones in one line, no company: `partial`. */
|
|
15
|
+
import { Refusal } from './conversations.mjs';
|
|
16
|
+
import { READ_MS } from './mailview.mjs';
|
|
17
|
+
|
|
18
|
+
export const CONTACTS_MAX = 200;
|
|
19
|
+
export const SEARCH_MAX = 200;
|
|
20
|
+
export const NOTES_MAX = 4000;
|
|
21
|
+
const LINE_MAX = 400;
|
|
22
|
+
const refused = (status, kind, message) => Object.assign(new Refusal(status, message), { kind });
|
|
23
|
+
const line = (v, max = LINE_MAX) => String(v ?? '').replace(/[\u0000-\u001f\u007f]+/g, ' ').trim().slice(0, max);
|
|
24
|
+
const lines = (v, max = 20) => (Array.isArray(v) ? v : v ? [v] : []).map((x) => line(x)).filter(Boolean).slice(0, max);
|
|
25
|
+
|
|
26
|
+
function bookOf(tethers, target) {
|
|
27
|
+
if (!tethers) throw refused(503, 'unreachable', 'Address books are not reached from this server.');
|
|
28
|
+
const t = tethers.store().target(String(target ?? ''));
|
|
29
|
+
if (!t || t.kind !== 'contacts') throw refused(404, 'gone', 'No such address book.');
|
|
30
|
+
return t;
|
|
31
|
+
}
|
|
32
|
+
async function asked(tethers, t, verb, args, who, wait) {
|
|
33
|
+
let timer;
|
|
34
|
+
const late = new Promise((resolve) => { timer = setTimeout(() => resolve(null), wait); timer.unref?.(); });
|
|
35
|
+
let got;
|
|
36
|
+
try { got = await Promise.race([tethers.read(verb, { target: t.id, ...args }, who), late]); }
|
|
37
|
+
finally { clearTimeout(timer); }
|
|
38
|
+
if (got === null) throw refused(504, 'late', `${t.title} did not answer in time. Try again.`);
|
|
39
|
+
if (!got?.ok) throw refused(/no such contact/.test(String(got?.text)) ? 404 : 502, 'unreachable', `${t.title} could not be read: ${line(got?.text, 300) || 'no answer'}.`);
|
|
40
|
+
return got;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* One contact Tether handed as data, kept to what the list shows. */
|
|
44
|
+
export function contactOf(c) {
|
|
45
|
+
const id = line(c?.id, 2048);
|
|
46
|
+
if (!id) return null;
|
|
47
|
+
return { id, name: line(c.name) || '(no name)', emails: lines(c.emails ?? c.email), phones: lines(c.phones ?? c.phone), company: line(c.company) || null };
|
|
48
|
+
}
|
|
49
|
+
/* The text lines Tether's contacts-list and contacts-search say ("ID", then " Name <a, b> tel 1 2"), read back.
|
|
50
|
+
Its phones are joined by spaces, which a phone has too: they stay one line. */
|
|
51
|
+
export function contactsOfText(text) {
|
|
52
|
+
const out = [];
|
|
53
|
+
const all = String(text ?? '').split('\n');
|
|
54
|
+
for (let i = 0; i < all.length; i++) {
|
|
55
|
+
const head = all[i];
|
|
56
|
+
if (!head || head.startsWith(' ') || head.startsWith('(') || /^No contact/.test(head)) continue;
|
|
57
|
+
const next = all[i + 1] ?? '';
|
|
58
|
+
if (!next.startsWith(' ') || next.startsWith(' ')) continue;
|
|
59
|
+
i++;
|
|
60
|
+
const m = /^ {2}(.*?)(?: {2}<([^>]*)>)?(?: {2}tel (.*))?$/.exec(next);
|
|
61
|
+
out.push(contactOf({ id: head, name: m[1] === '(no name)' ? '' : m[1], emails: (m[2] ?? '').split(', '), phones: m[3] ? [m[3]] : [] }));
|
|
62
|
+
}
|
|
63
|
+
return out.filter(Boolean);
|
|
64
|
+
}
|
|
65
|
+
const cutSaid = (text) => /\((Showing the first|Looked at the first) \d+/.test(String(text ?? ''));
|
|
66
|
+
|
|
67
|
+
/* THE CONTACTS OF AN ADDRESS BOOK TARGET, or those matching `text`, read now. */
|
|
68
|
+
export async function readContacts(tethers, { target, text } = {}, { who, wait = READ_MS } = {}) {
|
|
69
|
+
const t = bookOf(tethers, target);
|
|
70
|
+
const q = line(text, SEARCH_MAX);
|
|
71
|
+
const got = await asked(tethers, t, q ? 'contacts.search' : 'contacts.list', q ? { text: q } : {}, who, wait);
|
|
72
|
+
const given = Array.isArray(got.data?.contacts);
|
|
73
|
+
const all = (given ? got.data.contacts.map(contactOf).filter(Boolean) : contactsOfText(got.text))
|
|
74
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
75
|
+
const more = all.length > CONTACTS_MAX || got.data?.more === true || cutSaid(got.text);
|
|
76
|
+
return { target: t.id, title: t.title, text: q, contacts: all.slice(0, CONTACTS_MAX), more, partial: !given };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* ---------- one contact ---------- */
|
|
80
|
+
const notesOf = (v) => String(v ?? '').replace(/\r\n?/g, '\n').replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g, '').replace(/\n{3,}/g, '\n\n').trim().slice(0, NOTES_MAX);
|
|
81
|
+
const vcardValue = (v) => v.replace(/\\n/gi, '\n').replace(/\\([,;\\])/g, '$1');
|
|
82
|
+
/* The text Tether's contacts-read says, read back: the name, then " email: x", " tel (mobile): x", " company: X, T",
|
|
83
|
+
" address (work): ...", " birthday: ..."; then (Microsoft) its notes and "id: ..."; (CardDAV) its vCard, of
|
|
84
|
+
which only the company, title and note are kept. */
|
|
85
|
+
export function contactOfText(text, id) {
|
|
86
|
+
const all = String(text ?? '').replace(/\r\n?/g, '\n').split('\n');
|
|
87
|
+
const c = { id, name: all[0] === '(no name)' ? '' : all[0] ?? '', emails: [], phones: [], company: '', facts: [], notes: '' };
|
|
88
|
+
let i = 1;
|
|
89
|
+
for (; i < all.length && all[i].startsWith(' '); i++) {
|
|
90
|
+
const kv = /^ {2}([a-z]+)(?: \(([^)]*)\))?: (.*)$/.exec(all[i]);
|
|
91
|
+
if (!kv) continue;
|
|
92
|
+
const [, k, kind, v] = kv;
|
|
93
|
+
if (k === 'email') c.emails.push(v);
|
|
94
|
+
else if (k === 'tel') c.phones.push(kind ? `${v} (${kind})` : v);
|
|
95
|
+
else if (k === 'company') c.company = v;
|
|
96
|
+
else c.facts.push([kind ? `${k} (${kind})` : k, v]);
|
|
97
|
+
}
|
|
98
|
+
const rest = all.slice(i).join('\n').trim();
|
|
99
|
+
if (/^BEGIN:VCARD/i.test(rest)) {
|
|
100
|
+
const card = rest.replace(/\n[ \t]/g, '');
|
|
101
|
+
const one = (name) => { const m = new RegExp(`^${name}[^:\\n]*:(.*)$`, 'im').exec(card); return m ? vcardValue(m[1].trim()) : ''; };
|
|
102
|
+
const org = one('ORG').split(';').filter(Boolean).join(', ');
|
|
103
|
+
if (org) c.company = org;
|
|
104
|
+
const title = one('TITLE'); if (title) c.facts.push(['title', title]);
|
|
105
|
+
c.notes = one('NOTE');
|
|
106
|
+
} else c.notes = rest.replace(/\n*id: \S+$/, '');
|
|
107
|
+
return c;
|
|
108
|
+
}
|
|
109
|
+
/* ONE CONTACT OF AN ADDRESS BOOK TARGET, read now: its fields as text. */
|
|
110
|
+
export async function readContact(tethers, { target, id } = {}, { who, wait = READ_MS } = {}) {
|
|
111
|
+
const t = bookOf(tethers, target);
|
|
112
|
+
const cid = String(id ?? '').trim();
|
|
113
|
+
if (!cid || cid.length > 2048 || /[\s\0]/.test(cid)) throw refused(400, 'bad-contact', 'No such contact.');
|
|
114
|
+
const got = await asked(tethers, t, 'contacts.read', { id: cid }, who, wait);
|
|
115
|
+
const given = got.data?.contact && typeof got.data.contact === 'object';
|
|
116
|
+
const c = given ? got.data.contact : contactOfText(got.text, cid);
|
|
117
|
+
const facts = (Array.isArray(c.facts) ? c.facts : []).filter((f) => Array.isArray(f) && f[1]).map(([k, v]) => [line(k, 60), line(v, 1000)]).slice(0, 40);
|
|
118
|
+
if (given) for (const k of ['title', 'birthday']) if (c[k]) facts.push([k, line(c[k], 1000)]);
|
|
119
|
+
if (given) for (const a of lines(c.addresses, 5)) facts.push(['address', a]);
|
|
120
|
+
return { target: t.id, id: cid, name: line(c.name) || '(no name)', emails: lines(c.emails), phones: lines(c.phones), company: line(c.company) || null, facts, notes: notesOf(c.notes), partial: !given };
|
|
121
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/* A MAILBOX, SEEN BY ITS OWNER (16-11): the latest messages of a mailbox asset (a Tether target of kind mail:
|
|
2
|
+
* Microsoft over Graph, Google or a classic box over IMAP), shown in its asset panel, as the agenda is (agenda.mjs).
|
|
3
|
+
*
|
|
4
|
+
* POST /api/tether/mail-list {target, folder?, text?} the newest messages of a folder (inbox by default), or
|
|
5
|
+
* those whose text matches (Tether's mail.search). -> { target, title, folder, text,
|
|
6
|
+
* folders, messages: [...], more, partial }
|
|
7
|
+
* POST /api/tether/mail-read {target, id, folder?} one message, as text. -> { target, id, ref, from, to, cc,
|
|
8
|
+
* date, subject, text, attachments: [{name, type, size}], cut, partial }
|
|
9
|
+
*
|
|
10
|
+
* READ THROUGH TETHER, as an agent's mail-list is: the same connector, the same sign-in -- which stays in this server,
|
|
11
|
+
* never in the answer, never in the browser. The read is the owner's own in Tether's journal, never an agent's, never
|
|
12
|
+
* asked of anyone. Nothing is kept here.
|
|
13
|
+
*
|
|
14
|
+
* NEVER MARKED READ: Tether reads with EXAMINE and BODY.PEEK over IMAP, a GET over Graph -- as the mail viewer's
|
|
15
|
+
* mail.open (mailref.mjs). READ ONLY: nothing is moved, flagged or sent.
|
|
16
|
+
*
|
|
17
|
+
* TEXT ONLY: a message's words come as text from Tether (its HTML made text there); one still in HTML here is made
|
|
18
|
+
* text again. Attachments are named with their size, never opened. Pictures are never loaded.
|
|
19
|
+
*
|
|
20
|
+
* A Tether that hands its messages as data (`data.messages`, `data.message`: the fields below) gives them all; one
|
|
21
|
+
* that gives only its text lines (0.1.0-next.69) gives who, subject, date, and no unread or attachment mark: the
|
|
22
|
+
* answer says `partial`. */
|
|
23
|
+
import { Refusal } from './conversations.mjs';
|
|
24
|
+
|
|
25
|
+
export const MESSAGES_MAX = 25;
|
|
26
|
+
export const READ_MS = 30_000;
|
|
27
|
+
export const TEXT_MAX = 100_000; /* a message's words shown at most */
|
|
28
|
+
export const SEARCH_MAX = 200;
|
|
29
|
+
/* The folders offered: Graph knows them by these words; an IMAP box names its own, so only its inbox is offered. */
|
|
30
|
+
export const FOLDERS = ['inbox', 'sent', 'drafts', 'archive', 'junk', 'trash'];
|
|
31
|
+
const LINE_MAX = 400;
|
|
32
|
+
const refused = (status, kind, message) => Object.assign(new Refusal(status, message), { kind });
|
|
33
|
+
const line = (v, max = LINE_MAX) => String(v ?? '').replace(/[\u0000-\u001f\u007f]+/g, ' ').trim().slice(0, max);
|
|
34
|
+
|
|
35
|
+
/* ---------- a target, a folder ---------- */
|
|
36
|
+
export function boxOf(tethers, target) {
|
|
37
|
+
if (!tethers) throw refused(503, 'unreachable', 'Mailboxes are not reached from this server.');
|
|
38
|
+
const t = tethers.store().target(String(target ?? ''));
|
|
39
|
+
if (!t || t.kind !== 'mail') throw refused(404, 'gone', 'No such mailbox.');
|
|
40
|
+
return t;
|
|
41
|
+
}
|
|
42
|
+
/* Microsoft over Graph: the folders by their common words. Else (IMAP): the inbox alone. */
|
|
43
|
+
export const foldersOf = (t) => (String(t?.config?.provider ?? '') === 'microsoft' ? FOLDERS : ['inbox']);
|
|
44
|
+
export function folderOf(t, folder) {
|
|
45
|
+
const f = String(folder ?? '').trim().toLowerCase() || 'inbox';
|
|
46
|
+
if (!foldersOf(t).includes(f)) throw refused(400, 'bad-folder', 'No such folder here.');
|
|
47
|
+
return f;
|
|
48
|
+
}
|
|
49
|
+
/* What Tether is given: the inbox is the mailbox's own (its config may name another); Graph takes the other words. */
|
|
50
|
+
const mailboxArg = (f) => (f === 'inbox' ? {} : { mailbox: f });
|
|
51
|
+
|
|
52
|
+
/* ---------- times ---------- */
|
|
53
|
+
const MONTHS = { jan: 1, feb: 2, mar: 3, apr: 4, may: 5, jun: 6, jul: 7, aug: 8, sep: 9, oct: 10, nov: 11, dec: 12 };
|
|
54
|
+
/* An instant as ISO (UTC): Graph's ISO times, IMAP's INTERNALDATE ("16-Nov-2026 09:30:00 +0100"), a Date header. */
|
|
55
|
+
export function dateOf(v) {
|
|
56
|
+
const s = String(v ?? '').trim();
|
|
57
|
+
if (!s) return null;
|
|
58
|
+
const imap = /^(\d{1,2})-([A-Za-z]{3})-(\d{4}) (\d{2}):(\d{2}):(\d{2}) ([+-])(\d{2})(\d{2})$/.exec(s);
|
|
59
|
+
if (imap) {
|
|
60
|
+
const [, d, mon, y, h, mi, se, sign, oh, om] = imap;
|
|
61
|
+
const m = MONTHS[mon.toLowerCase()];
|
|
62
|
+
if (!m) return null;
|
|
63
|
+
const off = (sign === '-' ? -1 : 1) * (Number(oh) * 60 + Number(om));
|
|
64
|
+
return new Date(Date.UTC(Number(y), m - 1, Number(d), Number(h), Number(mi), Number(se)) - off * 60_000).toISOString();
|
|
65
|
+
}
|
|
66
|
+
const ms = Date.parse(s);
|
|
67
|
+
return Number.isNaN(ms) ? null : new Date(ms).toISOString();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* ---------- words, as text ---------- */
|
|
71
|
+
const ENTITIES = { nbsp: ' ', amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", '#39': "'" };
|
|
72
|
+
/* HTML made text: what runs or draws dropped, line breaks kept, the rest of the tags taken away, entities read. */
|
|
73
|
+
export function textOfHtml(html) {
|
|
74
|
+
return String(html ?? '')
|
|
75
|
+
.replace(/<!--[\s\S]*?-->/g, '')
|
|
76
|
+
.replace(/<\s*(script|style|head|title|template|svg|object|iframe)\b[^>]*>[\s\S]*?<\s*\/\s*\1\s*>/gi, ' ')
|
|
77
|
+
.replace(/<\s*br\s*\/?\s*>/gi, '\n').replace(/<\s*\/\s*(p|div|li|tr|h[1-6]|table|blockquote)\s*>/gi, '\n')
|
|
78
|
+
.replace(/<[^>]*>/g, '')
|
|
79
|
+
.replace(/&(nbsp|amp|lt|gt|quot|apos|#39);/gi, (_, e) => ENTITIES[e.toLowerCase()])
|
|
80
|
+
.replace(/&#(\d{1,6});/g, (_, n) => { const c = Number(n); return c > 31 && c < 0x110000 ? String.fromCodePoint(c) : ''; })
|
|
81
|
+
.replace(/[ \t\u00a0]{2,}/g, ' ').replace(/[ \t]+\n/g, '\n').replace(/\n[ \t]+/g, '\n').replace(/\n{3,}/g, '\n\n').trim();
|
|
82
|
+
}
|
|
83
|
+
const looksHtml = (s) => /<\s*(html|body|div|table|p|br|span|img|a)\b[^>]*>/i.test(s);
|
|
84
|
+
/* A message's words: text, control characters dropped, lines kept, short enough. Still HTML: made text. */
|
|
85
|
+
export function wordsOf(v) {
|
|
86
|
+
let s = String(v ?? '').replace(/\r\n?/g, '\n');
|
|
87
|
+
if (looksHtml(s)) s = textOfHtml(s);
|
|
88
|
+
s = s.replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g, '').replace(/\n{3,}/g, '\n\n').trim();
|
|
89
|
+
return { text: s.slice(0, TEXT_MAX), cut: s.length > TEXT_MAX };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/* ---------- a list ---------- */
|
|
93
|
+
const markOf = (v) => (v === true || v === false ? v : null);
|
|
94
|
+
/* One message Tether handed as data, kept to what the page shows. */
|
|
95
|
+
export function messageOf(m) {
|
|
96
|
+
const id = line(m?.id ?? m?.uid, 2048);
|
|
97
|
+
if (!id) return null;
|
|
98
|
+
const n = Number(m.attachments);
|
|
99
|
+
return {
|
|
100
|
+
id, ref: line(m.ref, 2048) || null, from: line(m.from), subject: line(m.subject) || '(no subject)', date: dateOf(m.date),
|
|
101
|
+
unread: markOf(m.unread), attachments: Array.isArray(m.attachments) ? m.attachments.length > 0 : m.attachments === true || m.attachments === false ? m.attachments : Number.isInteger(n) ? n > 0 : null,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/* The text lines Tether's mail-list and mail-search say, read back. IMAP: "#uid date" then " From:", " Subject:",
|
|
105
|
+
" ref:"; Graph: "#id", then " date", " From:", " Subject:", " ref:". */
|
|
106
|
+
export function messagesOfText(text) {
|
|
107
|
+
const out = [];
|
|
108
|
+
let at = null;
|
|
109
|
+
for (const raw of String(text ?? '').split('\n')) {
|
|
110
|
+
const head = /^#(\S+)(?: {2}(.*))?$/.exec(raw);
|
|
111
|
+
if (head) { at = { id: head[1], date: head[2] ?? '' }; out.push(at); continue; }
|
|
112
|
+
if (!at || !raw.startsWith(' ')) { if (raw.trim()) at = null; continue; }
|
|
113
|
+
const l = raw.slice(2);
|
|
114
|
+
const kv = /^(From|Subject|ref): ?(.*)$/.exec(l);
|
|
115
|
+
if (kv) at[kv[1].toLowerCase()] = kv[2];
|
|
116
|
+
else if (!at.date) at.date = l;
|
|
117
|
+
}
|
|
118
|
+
return out.map(messageOf).filter(Boolean);
|
|
119
|
+
}
|
|
120
|
+
const said = (text) => String(text ?? '');
|
|
121
|
+
const cutSaid = (text) => /\(Showing the (first )?\d+ most recent/.test(said(text));
|
|
122
|
+
|
|
123
|
+
/* Tether asked, waited for at most `wait`: its answer, or a refusal in plain words. */
|
|
124
|
+
async function asked(tethers, t, verb, args, who, wait) {
|
|
125
|
+
let timer;
|
|
126
|
+
const late = new Promise((resolve) => { timer = setTimeout(() => resolve(null), wait); timer.unref?.(); });
|
|
127
|
+
let got;
|
|
128
|
+
try { got = await Promise.race([tethers.read(verb, { target: t.id, ...args }, who), late]); }
|
|
129
|
+
finally { clearTimeout(timer); }
|
|
130
|
+
if (got === null) throw refused(504, 'late', `${t.title} did not answer in time. Try again.`);
|
|
131
|
+
if (!got?.ok) throw refused(got?.code === 'gone' ? 404 : 502, got?.code === 'gone' ? 'gone' : 'unreachable', `${t.title} could not be read: ${line(got?.text, 300) || 'no answer'}.`);
|
|
132
|
+
return got;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* THE LATEST MESSAGES OF A MAILBOX TARGET, or those matching `text`, read now. `who`: { id, name }, said in Tether's
|
|
136
|
+
journal. */
|
|
137
|
+
export async function readMailList(tethers, { target, folder, text } = {}, { who, wait = READ_MS } = {}) {
|
|
138
|
+
const t = boxOf(tethers, target);
|
|
139
|
+
const f = folderOf(t, folder);
|
|
140
|
+
const q = line(text, SEARCH_MAX);
|
|
141
|
+
const got = await asked(tethers, t, q ? 'mail.search' : 'mail.list', q ? { text: q, ...mailboxArg(f) } : mailboxArg(f), who, wait);
|
|
142
|
+
const given = Array.isArray(got.data?.messages);
|
|
143
|
+
const all = (given ? got.data.messages.map(messageOf).filter(Boolean) : messagesOfText(got.text))
|
|
144
|
+
.sort((a, b) => String(b.date ?? '').localeCompare(String(a.date ?? '')));
|
|
145
|
+
const more = all.length > MESSAGES_MAX || got.data?.more === true || cutSaid(got.text);
|
|
146
|
+
return { target: t.id, title: t.title, folder: f, text: q, folders: foldersOf(t), messages: all.slice(0, MESSAGES_MAX), more, partial: !given };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/* ---------- one message ---------- */
|
|
150
|
+
const attachmentOf = (a) => {
|
|
151
|
+
const name = line(a?.name, 300);
|
|
152
|
+
if (!name) return null;
|
|
153
|
+
const n = Number(a.size);
|
|
154
|
+
return { name, type: line(a.type, 100) || null, size: Number.isFinite(n) && n >= 0 ? Math.round(n) : null };
|
|
155
|
+
};
|
|
156
|
+
/* "name (type, N KB)" or "name (type, ~N KB)", as Tether's mail-read lists them. */
|
|
157
|
+
const attachmentOfText = (l) => {
|
|
158
|
+
const m = /^\s*(?:- )?(.*?) \(([^,()]*), ~?(\d+) KB\)\s*$/.exec(l);
|
|
159
|
+
return m ? attachmentOf({ name: m[1], type: m[2], size: Number(m[3]) * 1024 }) : null;
|
|
160
|
+
};
|
|
161
|
+
/* The text Tether's mail-read says, read back: "ref:", the head (From, To, Cc, Date, Subject), a blank line, the words,
|
|
162
|
+
then an invitation, then "Attachments:" (Graph) or "--- Attachments (n) ---" (IMAP), then a cut said last. */
|
|
163
|
+
export function messageOfText(text) {
|
|
164
|
+
const lines = String(text ?? '').replace(/\r\n?/g, '\n').split('\n');
|
|
165
|
+
const head = {};
|
|
166
|
+
let i = 0;
|
|
167
|
+
for (; i < lines.length; i++) {
|
|
168
|
+
const kv = /^(ref|From|To|Cc|Date|Subject): ?(.*)$/.exec(lines[i]);
|
|
169
|
+
if (!kv) break;
|
|
170
|
+
head[kv[1].toLowerCase()] = kv[2];
|
|
171
|
+
}
|
|
172
|
+
if (lines[i] === '') i++;
|
|
173
|
+
let body = lines.slice(i);
|
|
174
|
+
let cut = false;
|
|
175
|
+
while (body.length && !body.at(-1).trim()) body.pop();
|
|
176
|
+
if (/^\(Large message/.test(body.at(-1) ?? '')) { cut = true; body.pop(); }
|
|
177
|
+
const attachments = [];
|
|
178
|
+
const mark = body.findIndex((l) => /^(Attachments:|--- Attachments \(\d+\) ---)$/.test(l));
|
|
179
|
+
if (mark >= 0) {
|
|
180
|
+
for (const l of body.slice(mark + 1)) { const a = attachmentOfText(l); if (a) attachments.push(a); }
|
|
181
|
+
body = body.slice(0, mark);
|
|
182
|
+
while (body.length && !body.at(-1).trim()) body.pop();
|
|
183
|
+
}
|
|
184
|
+
return { ...head, text: body.join('\n'), attachments, cut };
|
|
185
|
+
}
|
|
186
|
+
/* ONE MESSAGE OF A MAILBOX TARGET, read now, as text. `id`: its number (IMAP uid) or Graph's id, as the list gave it;
|
|
187
|
+
`folder`: the one it was listed in. */
|
|
188
|
+
export async function readMail(tethers, { target, id, folder } = {}, { who, wait = READ_MS } = {}) {
|
|
189
|
+
const t = boxOf(tethers, target);
|
|
190
|
+
const f = folderOf(t, folder);
|
|
191
|
+
const uid = String(id ?? '').trim();
|
|
192
|
+
if (!uid || uid.length > 1024 || /[\s\0]/.test(uid)) throw refused(400, 'bad-message', 'No such message.');
|
|
193
|
+
const got = await asked(tethers, t, 'mail.read', { uid, ...mailboxArg(f) }, who, wait);
|
|
194
|
+
const given = got.data?.message && typeof got.data.message === 'object';
|
|
195
|
+
const m = given ? got.data.message : messageOfText(got.text);
|
|
196
|
+
const words = wordsOf(m.text ?? m.body);
|
|
197
|
+
return {
|
|
198
|
+
target: t.id, id: uid, ref: line(m.ref, 2048) || null, from: line(m.from), to: line(m.to, 2000), cc: line(m.cc, 2000),
|
|
199
|
+
date: dateOf(m.date), subject: line(m.subject) || '(no subject)', text: words.text,
|
|
200
|
+
attachments: (Array.isArray(m.attachments) ? m.attachments : []).map(attachmentOf).filter(Boolean).slice(0, 100),
|
|
201
|
+
cut: words.cut || m.cut === true, partial: !given,
|
|
202
|
+
};
|
|
203
|
+
}
|
package/server/settingswords.mjs
CHANGED
|
@@ -312,6 +312,19 @@ export const SETTINGS_WORDS_FR = {
|
|
|
312
312
|
'set-ag-when': 'Quand', 'set-ag-where': 'Où', 'set-ag-link': 'Lien', 'set-ag-join': 'Rejoindre en ligne', 'set-ag-organizer': 'Organisateur',
|
|
313
313
|
'set-ag-guests': 'Invités', 'set-ag-notes': 'Invitation', 'set-ag-shown': 'Affiché comme', 'set-ag-show-free': 'Libre', 'set-ag-show-tentative': 'Provisoire',
|
|
314
314
|
'set-ag-show-away': 'Absent', 'set-ag-show-elsewhere': 'Ailleurs',
|
|
315
|
+
/* A mailbox's mail, an address book's contacts, in their asset panel (mailview.mjs, contactview.mjs, 16-11). */
|
|
316
|
+
'set-mv-title': 'Courrier', 'set-mv-search': 'Chercher un message', 'set-mv-folder': 'Dossier', 'set-mv-again': 'Relire',
|
|
317
|
+
'set-mv-failed': 'Boîte illisible pour le moment.', 'set-mv-failed-one': 'Message illisible pour le moment.',
|
|
318
|
+
'set-mv-none': 'Aucun message', 'set-mv-nothing': 'Rien trouvé', 'set-mv-more': 'Les plus récents seulement',
|
|
319
|
+
'set-mv-partial': 'Sans non lu ni pièces jointes, pour l\'instant', 'set-mv-unread': 'Non lu', 'set-mv-has-files': 'Pièces jointes',
|
|
320
|
+
'set-mv-from': 'De', 'set-mv-to': 'À', 'set-mv-cc': 'Cc', 'set-mv-files': 'Pièces jointes', 'set-mv-empty': '(sans texte)',
|
|
321
|
+
'set-mv-cut': 'Message long : son début seulement', 'set-mv-viewer': 'Ouvrir dans le lecteur',
|
|
322
|
+
'set-mv-f-inbox': 'Boîte de réception', 'set-mv-f-sent': 'Envoyés', 'set-mv-f-drafts': 'Brouillons', 'set-mv-f-archive': 'Archives',
|
|
323
|
+
'set-mv-f-junk': 'Indésirables', 'set-mv-f-trash': 'Supprimés',
|
|
324
|
+
'set-ct-title': 'Contacts', 'set-ct-search': 'Chercher un contact', 'set-ct-failed': 'Carnet illisible pour le moment.',
|
|
325
|
+
'set-ct-failed-one': 'Contact illisible pour le moment.', 'set-ct-none': 'Aucun contact', 'set-ct-more': 'Certains contacts masqués : cherchez',
|
|
326
|
+
'set-ct-partial': 'Sans société dans la liste, pour l\'instant', 'set-ct-email': 'Courriel', 'set-ct-phone': 'Téléphone', 'set-ct-company': 'Société',
|
|
327
|
+
'set-ct-f-title': 'Fonction', 'set-ct-f-birthday': 'Anniversaire', 'set-ct-f-address': 'Adresse', 'set-ct-notes': 'Notes',
|
|
315
328
|
'set-ml-short': 'Manque de mémoire', 'set-ml-short-what': 'La plus grosse machine', 'set-ml-force': 'Forcer l’arrêt', 'set-ml-sleep': 'Mettre en veille', 'set-ml-alert': 'Alerter seulement',
|
|
316
329
|
};
|
|
317
330
|
export const settingsWords = (lang) => (String(lang ?? '').toLowerCase().split('-')[0] === 'fr' ? { ...SETTINGS_WORDS_FR } : {});
|
package/web/app.js
CHANGED
|
@@ -4880,7 +4880,7 @@
|
|
|
4880
4880
|
/* `work(item)` for each, `n` at a time. */
|
|
4881
4881
|
const inTurns = async (items, n, work) => { let i = 0; await Promise.all(Array.from({ length: Math.min(n, items.length) }, async () => { while (i < items.length) await work(items[i++]); })); };
|
|
4882
4882
|
/* When a known row was true: the time today, else the day. */
|
|
4883
|
-
const asOfText = (at) => { const d = new Date(at); if (!at || Number.isNaN(d.getTime())) return 'not read yet'; return `as of ${d.toDateString() === new Date().toDateString() ? d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) : d.toLocaleDateString()}`; };
|
|
4883
|
+
const asOfText = (at) => { const d = new Date(at); if (!at || Number.isNaN(d.getTime())) return 'not read yet'; return `as of ${d.toDateString() === new Date().toDateString() ? d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hourCycle: 'h23' }) : d.toLocaleDateString()}`; };
|
|
4884
4884
|
/* What a row is, for the filter: a branch the remote has and that is ahead of it, a branch it does not have, nothing to send. */
|
|
4885
4885
|
const kindOfRow = (out) => (out?.state !== 'ahead' ? 'none' : out.targetExists === false ? 'new' : 'update');
|
|
4886
4886
|
/* A branch that could not be read is not "nothing to send": it stays listed, under every filter, with why. */
|
|
@@ -6125,6 +6125,9 @@
|
|
|
6125
6125
|
/* A CALENDAR'S AGENDA (16-11): its events, under who has it -- read through Tether as the owner's own read
|
|
6126
6126
|
(agenda.mjs), so the calendar need not stay open elsewhere. The owner's page only: a device reads no calendar. */
|
|
6127
6127
|
if (t?.kind === 'calendar' && !DEVICE) parts.push(agendaPart(t));
|
|
6128
|
+
/* A MAILBOX'S MAIL, AN ADDRESS BOOK'S CONTACTS (16-11): read the same way (mailview.mjs, contactview.mjs). */
|
|
6129
|
+
if (t?.kind === 'mail' && !DEVICE) parts.push(mailPart(t));
|
|
6130
|
+
if (t?.kind === 'contacts' && !DEVICE) parts.push(contactsPart(t));
|
|
6128
6131
|
/* WHAT IS IN IT. */
|
|
6129
6132
|
if (copyBox) {
|
|
6130
6133
|
/* Its files: at once in a conversation; in the menu, a button opens them in the panel (the files sheet, moved in). */
|
|
@@ -6301,14 +6304,7 @@
|
|
|
6301
6304
|
fact(uiSaid('set-ag-organizer', 'Organizer'), ev.organizer ? document.createTextNode(ev.organizer) : null);
|
|
6302
6305
|
if (Number.isInteger(ev.attendees) && ev.attendees > 0) fact(uiSaid('set-ag-guests', 'Guests'), document.createTextNode(String(ev.attendees)));
|
|
6303
6306
|
/* ITS INVITATION'S TEXT (16-11): text nodes only -- never HTML, nothing in it runs; a web address (https) alone is a link. */
|
|
6304
|
-
if (ev.notes)
|
|
6305
|
-
const text = el('div', 'ag-notes');
|
|
6306
|
-
for (const part of String(ev.notes).split(/(https:\/\/[^\s<>"')\]]+)/)) {
|
|
6307
|
-
if (/^https:\/\//.test(part)) { const a = el('a', '', part.length > 60 ? `${part.slice(0, 57)}…` : part); a.href = part; a.target = '_blank'; a.rel = 'noopener noreferrer'; text.append(a); }
|
|
6308
|
-
else if (part) text.append(document.createTextNode(part));
|
|
6309
|
-
}
|
|
6310
|
-
fact(uiSaid('set-ag-notes', 'Invitation'), text);
|
|
6311
|
-
}
|
|
6307
|
+
if (ev.notes) fact(uiSaid('set-ag-notes', 'Invitation'), linkedText('ag-notes', ev.notes));
|
|
6312
6308
|
if (ev.show && ev.show !== 'busy') fact(uiSaid('set-ag-shown', 'Shown as'), document.createTextNode(uiSaid(`set-ag-show-${ev.show}`, { free: 'Free', tentative: 'Tentative', away: 'Away', elsewhere: 'Elsewhere' }[ev.show] ?? ev.show)));
|
|
6313
6309
|
box.append(head, facts);
|
|
6314
6310
|
return box;
|
|
@@ -6381,6 +6377,210 @@
|
|
|
6381
6377
|
queueMicrotask(() => { void agendaFill(holder, target.id); });
|
|
6382
6378
|
return { title: uiSaid('set-ag-title', 'Agenda'), extra: [bar], body: [holder], cls: 'as-agenda-part' };
|
|
6383
6379
|
}
|
|
6380
|
+
/* TEXT WITH ITS LINKS (16-11): text nodes only -- never HTML, nothing in it runs; a web address (https) alone is a
|
|
6381
|
+
link. An invitation's text, a mail's words, a contact's notes. */
|
|
6382
|
+
function linkedText(cls, text) {
|
|
6383
|
+
const box = el('div', cls);
|
|
6384
|
+
for (const part of String(text ?? '').split(/(https:\/\/[^\s<>"')\]]+)/)) {
|
|
6385
|
+
if (/^https:\/\//.test(part)) { const a = el('a', '', part.length > 60 ? `${part.slice(0, 57)}…` : part); a.href = part; a.target = '_blank'; a.rel = 'noopener noreferrer'; box.append(a); }
|
|
6386
|
+
else if (part) box.append(document.createTextNode(part));
|
|
6387
|
+
}
|
|
6388
|
+
return box;
|
|
6389
|
+
}
|
|
6390
|
+
/* A READ OF A MAILBOX OR AN ADDRESS BOOK (16-11), kept PEEK_KEEP_MS as the agenda's: a read is journaled by Tether,
|
|
6391
|
+
which paints the panel again -- a paint reads nothing. `key` -> { at, answer } or { at, pending }. */
|
|
6392
|
+
const PEEK_KEEP_MS = 5 * 60_000;
|
|
6393
|
+
const peekKept = new Map();
|
|
6394
|
+
function peekRead(key, path, body, failed, { fresh = false } = {}) {
|
|
6395
|
+
const kept = peekKept.get(key);
|
|
6396
|
+
if (kept && !fresh && (kept.pending || Date.now() - kept.at < PEEK_KEEP_MS)) return kept.pending ?? kept.answer;
|
|
6397
|
+
const pending = post(`${API}/tether/${path}`, body)
|
|
6398
|
+
.then((answer) => { peekKept.set(key, { at: Date.now(), answer }); return answer; })
|
|
6399
|
+
.catch((error) => { peekKept.delete(key); return { error: error.message || failed }; });
|
|
6400
|
+
peekKept.set(key, { at: Date.now(), pending });
|
|
6401
|
+
return pending;
|
|
6402
|
+
}
|
|
6403
|
+
const peekState = new Map(); /* target -> { folder, text, open }: kept across paints */
|
|
6404
|
+
let peekFocus = ''; /* the search box typed in, given its focus again after a paint */
|
|
6405
|
+
const peekOf = (id) => { if (!peekState.has(id)) peekState.set(id, { folder: 'inbox', text: '', draft: '', open: '' }); return peekState.get(id); };
|
|
6406
|
+
/* A search box: Enter searches, emptied it lists again; what is typed survives a paint. */
|
|
6407
|
+
function peekSearch(id, label, onSearch) {
|
|
6408
|
+
const s = peekOf(id);
|
|
6409
|
+
const form = el('form', 'mv-search'); form.setAttribute('role', 'search');
|
|
6410
|
+
const input = el('input'); input.type = 'search'; input.placeholder = label; input.setAttribute('aria-label', label); input.maxLength = 200; input.value = s.draft; input.spellcheck = false;
|
|
6411
|
+
input.addEventListener('input', () => { s.draft = input.value; if (!input.value.trim() && s.text) { s.text = ''; onSearch(); } });
|
|
6412
|
+
input.addEventListener('focus', () => { peekFocus = id; });
|
|
6413
|
+
input.addEventListener('blur', () => { if (input.isConnected && peekFocus === id) peekFocus = ''; });
|
|
6414
|
+
form.addEventListener('submit', (event) => { event.preventDefault(); s.text = input.value.trim(); s.open = ''; onSearch(); });
|
|
6415
|
+
form.append(input);
|
|
6416
|
+
if (peekFocus === id) queueMicrotask(() => { if (input.isConnected) { input.focus(); input.setSelectionRange(input.value.length, input.value.length); } });
|
|
6417
|
+
return form;
|
|
6418
|
+
}
|
|
6419
|
+
/* A mail's time: the hour today, else its day. */
|
|
6420
|
+
const mailWhen = (iso) => {
|
|
6421
|
+
if (!iso) return '';
|
|
6422
|
+
const d = new Date(iso);
|
|
6423
|
+
if (Number.isNaN(d.getTime())) return '';
|
|
6424
|
+
return d.toDateString() === new Date().toDateString() ? d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hourCycle: 'h23' }) : d.toLocaleDateString([], { day: 'numeric', month: 'short', ...(d.getFullYear() !== new Date().getFullYear() ? { year: 'numeric' } : {}) });
|
|
6425
|
+
};
|
|
6426
|
+
const fileSize = (n) => (!Number.isFinite(n) ? '' : n < 1024 ? `${n} B` : n < 1024 * 1024 ? `${Math.round(n / 1024)} KB` : `${(n / 1024 / 1024).toFixed(1)} MB`);
|
|
6427
|
+
const peekFacts = () => {
|
|
6428
|
+
const facts = el('dl', 'ag-facts mv-facts');
|
|
6429
|
+
const fact = (k, v) => { if (!v) return; facts.append(el('dt', '', k)); const dd = el('dd'); dd.append(typeof v === 'string' ? document.createTextNode(v) : v); facts.append(dd); };
|
|
6430
|
+
return { facts, fact };
|
|
6431
|
+
};
|
|
6432
|
+
|
|
6433
|
+
/* THE MAIL OF A MAILBOX ASSET (16-11): its latest messages (25, newest first: who, subject, when, unread, a file);
|
|
6434
|
+
a search through Tether's mail-search; a folder on Microsoft. A message opened: its words AS TEXT, its files
|
|
6435
|
+
named with their size, never opened; its pictures never loaded. Never marked read (Tether peeks). Read only. */
|
|
6436
|
+
async function mailOpenFill(box, target, folder, m) {
|
|
6437
|
+
const body = box.querySelector('.mv-body');
|
|
6438
|
+
if (body.dataset.filled) return;
|
|
6439
|
+
body.dataset.filled = '1';
|
|
6440
|
+
body.replaceChildren(el('p', 'hint', uiSaid('set-ag-reading', 'Reading…')));
|
|
6441
|
+
const got = await peekRead(`mail-read|${target}|${folder}|${m.id}`, 'mail-read', { target, id: m.id, folder }, uiSaid('set-mv-failed-one', 'This message could not be read.'));
|
|
6442
|
+
if (!body.isConnected) return;
|
|
6443
|
+
if (got.error) { delete body.dataset.filled; body.replaceChildren(el('p', 'error', got.error)); return; }
|
|
6444
|
+
const { facts, fact } = peekFacts();
|
|
6445
|
+
fact(uiSaid('set-mv-from', 'From'), got.from);
|
|
6446
|
+
fact(uiSaid('set-mv-to', 'To'), got.to);
|
|
6447
|
+
fact(uiSaid('set-mv-cc', 'Cc'), got.cc);
|
|
6448
|
+
if (got.date) fact(uiSaid('set-ag-when', 'When'), new Date(got.date).toLocaleString([], { dateStyle: 'medium', timeStyle: 'short' }));
|
|
6449
|
+
if ((got.attachments ?? []).length) {
|
|
6450
|
+
const files = el('ul', 'mv-files');
|
|
6451
|
+
for (const a of got.attachments) { const li = el('li'); li.append(el('span', 'mv-file', a.name)); const size = fileSize(a.size); if (size) li.append(el('span', 'hint', ` ${size}`)); files.append(li); }
|
|
6452
|
+
fact(uiSaid('set-mv-files', 'Files'), files);
|
|
6453
|
+
}
|
|
6454
|
+
const text = linkedText('ag-notes mv-text', got.text || uiSaid('set-mv-empty', '(no text)'));
|
|
6455
|
+
const out = [facts, text];
|
|
6456
|
+
if (got.cut) out.push(el('p', 'hint', uiSaid('set-mv-cut', 'Long message: its start only')));
|
|
6457
|
+
/* The whole mail, as it was written: the mail viewer of .eml files (its pictures blocked unless asked). */
|
|
6458
|
+
if (got.ref) { const open = el('button', 'quiet', uiSaid('set-mv-viewer', 'Open in the viewer')); open.type = 'button'; open.addEventListener('click', () => { void openMailRef(got.ref, { label: m.subject, of: '' }); }); out.push(open); }
|
|
6459
|
+
body.replaceChildren(...out);
|
|
6460
|
+
}
|
|
6461
|
+
function mailRow(target, folder, m) {
|
|
6462
|
+
const s = peekOf(target);
|
|
6463
|
+
const box = el('details', 'ag-event mv-msg'); if (m.unread) box.dataset.unread = '1';
|
|
6464
|
+
const head = el('summary', 'ag-row mv-row');
|
|
6465
|
+
const mark = el('span', 'mv-mark');
|
|
6466
|
+
if (m.unread) { mark.append(el('span', 'mv-dot')); mark.title = uiSaid('set-mv-unread', 'Unread'); mark.setAttribute('aria-label', mark.title); }
|
|
6467
|
+
const what = el('span', 'ag-what');
|
|
6468
|
+
what.append(el('span', 'mv-from', m.from || '—'));
|
|
6469
|
+
const subj = el('span', 'ag-title mv-subject', m.subject);
|
|
6470
|
+
what.append(subj);
|
|
6471
|
+
const side = el('span', 'mv-side');
|
|
6472
|
+
if (m.attachments) { const clip = el('span', 'mv-clip'); clip.append(window.clavariumIcons?.icon('paperclip', 'mv-svg') ?? document.createTextNode('+')); clip.title = uiSaid('set-mv-has-files', 'Has files'); clip.setAttribute('aria-label', clip.title); side.append(clip); }
|
|
6473
|
+
side.append(el('span', 'ag-time', mailWhen(m.date)));
|
|
6474
|
+
head.append(mark, what, side);
|
|
6475
|
+
const body = el('div', 'mv-body');
|
|
6476
|
+
box.append(head, body);
|
|
6477
|
+
box.addEventListener('toggle', () => { if (box.open) { s.open = m.id; void mailOpenFill(box, target, folder, m); } else if (s.open === m.id) s.open = ''; });
|
|
6478
|
+
if (s.open === m.id) { box.open = true; }
|
|
6479
|
+
return box;
|
|
6480
|
+
}
|
|
6481
|
+
async function mailFill(holder, target, opts) {
|
|
6482
|
+
const s = peekOf(target);
|
|
6483
|
+
holder.setAttribute('aria-busy', 'true');
|
|
6484
|
+
if (!holder.childElementCount) holder.append(el('p', 'hint', uiSaid('set-ag-reading', 'Reading…')));
|
|
6485
|
+
const answer = await peekRead(`mail-list|${target}|${s.folder}|${s.text}`, 'mail-list', { target, folder: s.folder, text: s.text }, uiSaid('set-mv-failed', 'The mailbox could not be read.'), opts);
|
|
6486
|
+
holder.removeAttribute('aria-busy');
|
|
6487
|
+
if (!holder.isConnected) return;
|
|
6488
|
+
if (answer.error) {
|
|
6489
|
+
const again = el('button', '', uiSaid('set-ag-again', 'Try again')); again.type = 'button';
|
|
6490
|
+
again.addEventListener('click', () => { void mailFill(holder, target, { fresh: true }); });
|
|
6491
|
+
holder.replaceChildren(el('p', 'error', answer.error), again);
|
|
6492
|
+
return;
|
|
6493
|
+
}
|
|
6494
|
+
const pick = holder.closest('.as-mail-part')?.querySelector('.mv-folder');
|
|
6495
|
+
if (pick && (answer.folders ?? []).length > 1 && !pick.options.length) {
|
|
6496
|
+
for (const f of answer.folders) { const o = el('option', '', uiSaid(`set-mv-f-${f}`, { inbox: 'Inbox', sent: 'Sent', drafts: 'Drafts', archive: 'Archive', junk: 'Junk', trash: 'Deleted' }[f] ?? f)); o.value = f; pick.append(o); }
|
|
6497
|
+
pick.value = s.folder; pick.hidden = false;
|
|
6498
|
+
}
|
|
6499
|
+
const list = el('div', 'ag-days mv-list');
|
|
6500
|
+
for (const m of answer.messages ?? []) list.append(mailRow(target, answer.folder, m));
|
|
6501
|
+
const notes = [];
|
|
6502
|
+
if (!(answer.messages ?? []).length) notes.push(el('p', 'hint', answer.text ? uiSaid('set-mv-nothing', 'Nothing found') : uiSaid('set-mv-none', 'No message')));
|
|
6503
|
+
if (answer.more) notes.push(el('p', 'hint', uiSaid('set-mv-more', 'The latest only')));
|
|
6504
|
+
if (answer.partial) notes.push(el('p', 'hint', uiSaid('set-mv-partial', 'No unread or file marks, for now')));
|
|
6505
|
+
holder.replaceChildren(...((answer.messages ?? []).length ? [list] : []), ...notes);
|
|
6506
|
+
}
|
|
6507
|
+
function mailPart(target) {
|
|
6508
|
+
const holder = el('div', 'as-agenda as-mail');
|
|
6509
|
+
const s = peekOf(target.id);
|
|
6510
|
+
const search = peekSearch(target.id, uiSaid('set-mv-search', 'Search mail'), () => { void mailFill(holder, target.id); });
|
|
6511
|
+
const pick = el('select', 'mv-folder'); pick.hidden = true; pick.setAttribute('aria-label', uiSaid('set-mv-folder', 'Folder'));
|
|
6512
|
+
pick.addEventListener('change', () => { s.folder = pick.value; s.open = ''; void mailFill(holder, target.id); });
|
|
6513
|
+
const again = el('button', 'quiet', '↻'); again.type = 'button'; again.title = uiSaid('set-mv-again', 'Read again'); again.setAttribute('aria-label', again.title);
|
|
6514
|
+
again.addEventListener('click', () => { void mailFill(holder, target.id, { fresh: true }); });
|
|
6515
|
+
const bar = el('div', 'ag-bar mv-bar'); bar.append(pick, again);
|
|
6516
|
+
queueMicrotask(() => { void mailFill(holder, target.id); });
|
|
6517
|
+
return { title: uiSaid('set-mv-title', 'Mail'), extra: [bar], body: [search, holder], cls: 'as-agenda-part as-mail-part' };
|
|
6518
|
+
}
|
|
6519
|
+
|
|
6520
|
+
/* THE CONTACTS OF AN ADDRESS BOOK ASSET (16-11): name, email, phone, company; a search through Tether's
|
|
6521
|
+
contacts-search; a contact opened: its details as text. Read only. */
|
|
6522
|
+
async function contactOpenFill(box, target, c) {
|
|
6523
|
+
const body = box.querySelector('.mv-body');
|
|
6524
|
+
if (body.dataset.filled) return;
|
|
6525
|
+
body.dataset.filled = '1';
|
|
6526
|
+
body.replaceChildren(el('p', 'hint', uiSaid('set-ag-reading', 'Reading…')));
|
|
6527
|
+
const got = await peekRead(`contact|${target}|${c.id}`, 'contact', { target, id: c.id }, uiSaid('set-ct-failed-one', 'This contact could not be read.'));
|
|
6528
|
+
if (!body.isConnected) return;
|
|
6529
|
+
if (got.error) { delete body.dataset.filled; body.replaceChildren(el('p', 'error', got.error)); return; }
|
|
6530
|
+
const { facts, fact } = peekFacts();
|
|
6531
|
+
const several = (items, scheme) => { if (!items?.length) return null; const box = el('span', 'mv-lines'); for (const v of items) { const a = el('a', '', v); const bare = v.replace(/ \([^)]*\)$/, ''); a.href = `${scheme}:${scheme === 'tel' ? bare.replace(/[^\d+]/g, '') : bare}`; box.append(a); } return box; };
|
|
6532
|
+
fact(uiSaid('set-ct-email', 'Email'), several(got.emails, 'mailto'));
|
|
6533
|
+
fact(uiSaid('set-ct-phone', 'Phone'), several(got.phones, 'tel'));
|
|
6534
|
+
fact(uiSaid('set-ct-company', 'Company'), got.company);
|
|
6535
|
+
const WORD = { title: uiSaid('set-ct-f-title', 'Title'), birthday: uiSaid('set-ct-f-birthday', 'Birthday'), address: uiSaid('set-ct-f-address', 'Address') };
|
|
6536
|
+
for (const [k, v] of got.facts ?? []) { const [base, kind] = /^(\w+)(?: \((.*)\))?$/.exec(k)?.slice(1) ?? [k]; fact(`${WORD[base] ?? base}${kind ? ` (${kind})` : ''}`, v); }
|
|
6537
|
+
if (got.notes) fact(uiSaid('set-ct-notes', 'Notes'), linkedText('ag-notes', got.notes));
|
|
6538
|
+
body.replaceChildren(facts);
|
|
6539
|
+
}
|
|
6540
|
+
function contactRow(target, c) {
|
|
6541
|
+
const s = peekOf(target);
|
|
6542
|
+
const box = el('details', 'ag-event ct-person');
|
|
6543
|
+
const head = el('summary', 'ag-row ct-row');
|
|
6544
|
+
const what = el('span', 'ag-what');
|
|
6545
|
+
what.append(el('span', 'ag-title', c.name));
|
|
6546
|
+
const sub = [c.emails?.[0], c.company].filter(Boolean).join(' · ');
|
|
6547
|
+
if (sub) what.append(el('span', 'ag-where hint', sub));
|
|
6548
|
+
head.append(what, el('span', 'ag-time ct-phone', c.phones?.[0] ?? ''));
|
|
6549
|
+
box.append(head, el('div', 'mv-body'));
|
|
6550
|
+
box.addEventListener('toggle', () => { if (box.open) { s.open = c.id; void contactOpenFill(box, target, c); } else if (s.open === c.id) s.open = ''; });
|
|
6551
|
+
if (s.open === c.id) box.open = true;
|
|
6552
|
+
return box;
|
|
6553
|
+
}
|
|
6554
|
+
async function contactsFill(holder, target, opts) {
|
|
6555
|
+
const s = peekOf(target);
|
|
6556
|
+
holder.setAttribute('aria-busy', 'true');
|
|
6557
|
+
if (!holder.childElementCount) holder.append(el('p', 'hint', uiSaid('set-ag-reading', 'Reading…')));
|
|
6558
|
+
const answer = await peekRead(`contacts|${target}|${s.text}`, 'contacts', { target, text: s.text }, uiSaid('set-ct-failed', 'The address book could not be read.'), opts);
|
|
6559
|
+
holder.removeAttribute('aria-busy');
|
|
6560
|
+
if (!holder.isConnected) return;
|
|
6561
|
+
if (answer.error) {
|
|
6562
|
+
const again = el('button', '', uiSaid('set-ag-again', 'Try again')); again.type = 'button';
|
|
6563
|
+
again.addEventListener('click', () => { void contactsFill(holder, target, { fresh: true }); });
|
|
6564
|
+
holder.replaceChildren(el('p', 'error', answer.error), again);
|
|
6565
|
+
return;
|
|
6566
|
+
}
|
|
6567
|
+
const list = el('div', 'ag-days mv-list ct-list');
|
|
6568
|
+
for (const c of answer.contacts ?? []) list.append(contactRow(target, c));
|
|
6569
|
+
const notes = [];
|
|
6570
|
+
if (!(answer.contacts ?? []).length) notes.push(el('p', 'hint', answer.text ? uiSaid('set-mv-nothing', 'Nothing found') : uiSaid('set-ct-none', 'No contact')));
|
|
6571
|
+
if (answer.more) notes.push(el('p', 'hint', uiSaid('set-ct-more', 'Some contacts not shown: search')));
|
|
6572
|
+
if (answer.partial) notes.push(el('p', 'hint', uiSaid('set-ct-partial', 'No company in the list, for now')));
|
|
6573
|
+
holder.replaceChildren(...((answer.contacts ?? []).length ? [list] : []), ...notes);
|
|
6574
|
+
}
|
|
6575
|
+
function contactsPart(target) {
|
|
6576
|
+
const holder = el('div', 'as-agenda as-contacts');
|
|
6577
|
+
const search = peekSearch(target.id, uiSaid('set-ct-search', 'Search contacts'), () => { void contactsFill(holder, target.id); });
|
|
6578
|
+
const again = el('button', 'quiet', '↻'); again.type = 'button'; again.title = uiSaid('set-mv-again', 'Read again'); again.setAttribute('aria-label', again.title);
|
|
6579
|
+
again.addEventListener('click', () => { void contactsFill(holder, target.id, { fresh: true }); });
|
|
6580
|
+
const bar = el('div', 'ag-bar mv-bar'); bar.append(again);
|
|
6581
|
+
queueMicrotask(() => { void contactsFill(holder, target.id); });
|
|
6582
|
+
return { title: uiSaid('set-ct-title', 'Contacts'), extra: [bar], body: [search, holder], cls: 'as-agenda-part as-contacts-part' };
|
|
6583
|
+
}
|
|
6384
6584
|
const ASSET_WORD = { folder: 'Folder', git: 'Repository', mailbox: 'Mailbox', agenda: 'Calendar', contacts: 'Contacts', secret: 'Secret', list: LISTS_WORD.one, acces: 'Access' };
|
|
6385
6585
|
/* Under its name: its kind (its group, a chip before it, in the menu). */
|
|
6386
6586
|
function chipsOf(chosen) {
|
|
@@ -10522,7 +10722,7 @@
|
|
|
10522
10722
|
const whenOf = (iso) => {
|
|
10523
10723
|
const d = new Date(iso); if (Number.isNaN(d.getTime())) return '';
|
|
10524
10724
|
const now = new Date();
|
|
10525
|
-
if (d.toDateString() === now.toDateString()) return d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
|
10725
|
+
if (d.toDateString() === now.toDateString()) return d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hourCycle: 'h23' });
|
|
10526
10726
|
return d.toLocaleDateString([], { day: 'numeric', month: 'short', ...(d.getFullYear() === now.getFullYear() ? {} : { year: 'numeric' }) });
|
|
10527
10727
|
};
|
|
10528
10728
|
const innerOf = (name) => (filesAt ? `${filesAt}/${name}` : name);
|
package/web/style.css
CHANGED
|
@@ -1290,6 +1290,36 @@ header .ic, #folders .ic { width: 18px; height: 18px; fill: none; stroke: curren
|
|
|
1290
1290
|
.ag-row { grid-template-columns: 3.8em minmax(0, 1fr); gap: 6px; }
|
|
1291
1291
|
.ag-facts { padding-left: 6px; }
|
|
1292
1292
|
}
|
|
1293
|
+
/* A MAILBOX'S MAIL, AN ADDRESS BOOK'S CONTACTS (16-11, app.js mailPart, contactsPart): the agenda's rows, a search box
|
|
1294
|
+
above. A message opened shows its words as text; a contact, its details. Read only. */
|
|
1295
|
+
.mv-search input { width: 100%; box-sizing: border-box; }
|
|
1296
|
+
.mv-bar select { padding: 4px 8px; }
|
|
1297
|
+
.mv-list { gap: 1px; }
|
|
1298
|
+
.ag-row.mv-row { grid-template-columns: 10px minmax(0, 1fr) auto; }
|
|
1299
|
+
.ag-row.ct-row { grid-template-columns: minmax(0, 1fr) auto; }
|
|
1300
|
+
.mv-mark { align-self: center; display: flex; justify-content: center; }
|
|
1301
|
+
.mv-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--brass-ink); }
|
|
1302
|
+
.mv-from { font-size: .8125rem; color: var(--ink2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1303
|
+
.mv-msg .mv-subject { font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1304
|
+
.mv-msg[data-unread] .mv-subject, .mv-msg[data-unread] .mv-from { font-weight: 600; color: var(--ink); }
|
|
1305
|
+
.mv-msg[open] .mv-subject { white-space: normal; overflow-wrap: anywhere; }
|
|
1306
|
+
.mv-side { display: flex; align-items: baseline; gap: 6px; }
|
|
1307
|
+
.mv-clip { color: var(--ink2); display: inline-flex; align-self: center; }
|
|
1308
|
+
.mv-clip svg { width: 14px; height: 14px; }
|
|
1309
|
+
.ag-facts.mv-facts { padding-left: 22px; }
|
|
1310
|
+
.ct-person .ag-facts.mv-facts { padding-left: 6px; }
|
|
1311
|
+
.mv-body { display: flex; flex-direction: column; gap: 6px; padding-bottom: 6px; }
|
|
1312
|
+
.mv-body > .ag-notes, .mv-body > .hint, .mv-body > button { margin: 0 6px 0 22px; font-size: .8125rem; }
|
|
1313
|
+
.mv-body > button { align-self: flex-start; padding: 3px 10px; min-height: 0; }
|
|
1314
|
+
.mv-text { max-height: 28em; color: var(--ink); }
|
|
1315
|
+
.mv-files { margin: 0; padding: 0; list-style: none; }
|
|
1316
|
+
.mv-file { overflow-wrap: anywhere; }
|
|
1317
|
+
.mv-lines { display: flex; flex-direction: column; }
|
|
1318
|
+
.mv-lines a, .mv-body a { color: var(--brass-ink); }
|
|
1319
|
+
@media (max-width: 600px) {
|
|
1320
|
+
.ag-facts.mv-facts { padding-left: 6px; }
|
|
1321
|
+
.mv-body > .ag-notes, .mv-body > .hint, .mv-body > button { margin-left: 6px; }
|
|
1322
|
+
}
|
|
1293
1323
|
.as-foot { margin-top: 10px; }
|
|
1294
1324
|
.as-form { display: flex; flex-direction: column; gap: 8px; }
|
|
1295
1325
|
.as-form h3 { margin: 0; font-size: 1.125rem; }
|