clavarium 0.2.159-beta.1 → 0.2.160-beta.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 +17 -2
- package/server/demandes.mjs +140 -0
- package/server/door.mjs +9 -2
- package/server/files.mjs +36 -1
- package/server/main.mjs +2 -0
- package/server/settingswords.mjs +5 -0
- package/server/talk.mjs +7 -1
- package/server/tethers.mjs +16 -4
- package/web/app.js +137 -153
- package/web/device.html +1 -0
- package/web/index.html +1 -0
- package/web/mail-view.js +386 -0
- package/web/style.css +30 -31
package/web/mail-view.js
ADDED
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/* A MAIL FILE (.eml), read as a mail program shows it (05-11): its subject, who wrote to whom and when,
|
|
2
|
+
* its words, its attachments -- and its source one tap away.
|
|
3
|
+
*
|
|
4
|
+
* parse(bytes) RFC 822 / MIME: headers (RFC 2047 words, RFC 2231 names), multipart
|
|
5
|
+
* alternative / mixed / related, quoted-printable, base64, charsets.
|
|
6
|
+
* sanitize(html, opts) the HTML of a mail, which a stranger wrote: kept are the tags and the
|
|
7
|
+
* attributes that draw a page, nothing that runs, submits or frames;
|
|
8
|
+
* remote pictures and styles blocked unless `remote`; `cid:` pictures
|
|
9
|
+
* drawn from the mail itself.
|
|
10
|
+
* pageOf(mail, opts) the document the viewer's frame shows (srcdoc), its own rules in it.
|
|
11
|
+
* linkify(text) plain words cut into text and links (http, https, mailto), for the page to draw.
|
|
12
|
+
*
|
|
13
|
+
* Pure: no DOM, no network. The page (app.js) draws it in a frame that runs nothing (sandbox without
|
|
14
|
+
* scripts or same-origin); the server (files.mjs) uses the same code when remote pictures are asked for.
|
|
15
|
+
* Loaded as a classic script (index.html, device.html): window.clavariumMail. */
|
|
16
|
+
(function (root) {
|
|
17
|
+
/* ---------- bytes and words ---------- */
|
|
18
|
+
const latin = (bytes) => {
|
|
19
|
+
let s = '';
|
|
20
|
+
for (let i = 0; i < bytes.length; i += 8192) s += String.fromCharCode.apply(null, bytes.subarray(i, i + 8192));
|
|
21
|
+
return s;
|
|
22
|
+
};
|
|
23
|
+
const bytesOf = (binary) => { const b = new Uint8Array(binary.length); for (let i = 0; i < binary.length; i++) b[i] = binary.charCodeAt(i) & 255; return b; };
|
|
24
|
+
const ALIASES = { 'utf8': 'utf-8', 'latin1': 'iso-8859-1', 'latin-1': 'iso-8859-1', 'cp1252': 'windows-1252', 'us-ascii': 'utf-8', 'ascii': 'utf-8', 'ansi_x3.4-1968': 'utf-8', 'unknown-8bit': 'windows-1252', 'x-unknown': 'windows-1252' };
|
|
25
|
+
/* Bytes in a charset; one a browser does not know is read as UTF-8, and failing that as Windows-1252. */
|
|
26
|
+
function decode(bytes, charset) {
|
|
27
|
+
let label = String(charset || 'utf-8').trim().toLowerCase().replace(/^["']|["']$/g, '');
|
|
28
|
+
label = ALIASES[label] || label;
|
|
29
|
+
try { return new TextDecoder(label, { fatal: label === 'utf-8' }).decode(bytes); } catch { /* unknown, or not UTF-8 after all */ }
|
|
30
|
+
try { return new TextDecoder('utf-8', { fatal: true }).decode(bytes); } catch { /* 8-bit */ }
|
|
31
|
+
try { return new TextDecoder('windows-1252').decode(bytes); } catch { return latin(bytes); }
|
|
32
|
+
}
|
|
33
|
+
function fromBase64(text) {
|
|
34
|
+
const clean = String(text).replace(/[^A-Za-z0-9+/]/g, '');
|
|
35
|
+
const out = new Uint8Array(Math.floor((clean.length * 3) / 4));
|
|
36
|
+
const at = (c) => { const n = c.charCodeAt(0); return n >= 97 ? n - 71 : n >= 65 ? n - 65 : n >= 48 ? n + 4 : n === 43 ? 62 : 63; };
|
|
37
|
+
let o = 0;
|
|
38
|
+
for (let i = 0; i + 1 < clean.length; i += 4) {
|
|
39
|
+
const a = at(clean[i]); const b = at(clean[i + 1]); const c = i + 2 < clean.length ? at(clean[i + 2]) : -1; const d = i + 3 < clean.length ? at(clean[i + 3]) : -1;
|
|
40
|
+
out[o++] = (a << 2) | (b >> 4);
|
|
41
|
+
if (c >= 0) out[o++] = ((b & 15) << 4) | (c >> 2);
|
|
42
|
+
if (d >= 0) out[o++] = ((c & 3) << 6) | d;
|
|
43
|
+
}
|
|
44
|
+
return out.subarray(0, o);
|
|
45
|
+
}
|
|
46
|
+
const B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
47
|
+
function toBase64(bytes) {
|
|
48
|
+
let s = '';
|
|
49
|
+
for (let i = 0; i < bytes.length; i += 3) {
|
|
50
|
+
const n = (bytes[i] << 16) | ((bytes[i + 1] ?? 0) << 8) | (bytes[i + 2] ?? 0);
|
|
51
|
+
s += B64[(n >> 18) & 63] + B64[(n >> 12) & 63] + (i + 1 < bytes.length ? B64[(n >> 6) & 63] : '=') + (i + 2 < bytes.length ? B64[n & 63] : '=');
|
|
52
|
+
}
|
|
53
|
+
return s;
|
|
54
|
+
}
|
|
55
|
+
/* Quoted-printable, on the binary string: "=XX" a byte, "=" at a line's end a soft break. */
|
|
56
|
+
function fromQuotedPrintable(binary, header = false) {
|
|
57
|
+
let s = String(binary).replace(/[ \t]+(\r?\n)/g, '$1').replace(/=\r?\n/g, '');
|
|
58
|
+
if (header) s = s.replace(/_/g, ' ');
|
|
59
|
+
const out = [];
|
|
60
|
+
for (let i = 0; i < s.length; i++) {
|
|
61
|
+
if (s[i] === '=' && /^[0-9A-Fa-f]{2}$/.test(s.slice(i + 1, i + 3))) { out.push(parseInt(s.slice(i + 1, i + 3), 16)); i += 2; } else out.push(s.charCodeAt(i) & 255);
|
|
62
|
+
}
|
|
63
|
+
return Uint8Array.from(out);
|
|
64
|
+
}
|
|
65
|
+
/* RFC 2047: "=?UTF-8?Q?caf=C3=A9?=" -- words side by side are one; the rest, 8-bit, read as UTF-8. */
|
|
66
|
+
function words(value) {
|
|
67
|
+
const raw = String(value ?? '');
|
|
68
|
+
const re = /=\?([^?\s]+)\?([QqBb])\?([^?\s]*)\?=/g;
|
|
69
|
+
let out = ''; let last = 0; let wasWord = false; let m;
|
|
70
|
+
while ((m = re.exec(raw))) {
|
|
71
|
+
const between = raw.slice(last, m.index);
|
|
72
|
+
if (!(wasWord && /^\s*$/.test(between))) out += decode(bytesOf(between), 'utf-8');
|
|
73
|
+
const charset = m[1].split('*')[0];
|
|
74
|
+
const bytes = m[2].toUpperCase() === 'B' ? fromBase64(m[3]) : fromQuotedPrintable(m[3], true);
|
|
75
|
+
out += decode(bytes, charset);
|
|
76
|
+
last = re.lastIndex; wasWord = true;
|
|
77
|
+
}
|
|
78
|
+
out += decode(bytesOf(raw.slice(last)), 'utf-8');
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/* ---------- an entity: its headers, its body ---------- */
|
|
83
|
+
function split(binary) {
|
|
84
|
+
const m = /\r?\n\r?\n/.exec(binary);
|
|
85
|
+
const head = m ? binary.slice(0, m.index) : binary;
|
|
86
|
+
const body = m ? binary.slice(m.index + m[0].length) : '';
|
|
87
|
+
/* A message that starts with its body (no header at all) has no "name:" first. */
|
|
88
|
+
if (!/^[!-9;-~]+:/.test(head)) return { head: '', body: binary, headers: [] };
|
|
89
|
+
const headers = [];
|
|
90
|
+
for (const line of head.split(/\r?\n/)) {
|
|
91
|
+
if (/^[ \t]/.test(line) && headers.length) headers[headers.length - 1][1] += ` ${line.trim()}`;
|
|
92
|
+
else { const at = line.indexOf(':'); if (at > 0) headers.push([line.slice(0, at).trim(), line.slice(at + 1).trim()]); }
|
|
93
|
+
}
|
|
94
|
+
return { head, body, headers };
|
|
95
|
+
}
|
|
96
|
+
const first = (headers, name) => { const h = headers.find(([k]) => k.toLowerCase() === name); return h ? h[1] : ''; };
|
|
97
|
+
/* "text/html; charset=\"utf-8\"; name*=utf-8''r%C3%A9sum%C3%A9.pdf" -> { value, params } (RFC 2231 names and pieces). */
|
|
98
|
+
function params(value) {
|
|
99
|
+
const parts = []; let cur = ''; let quoted = false;
|
|
100
|
+
for (const ch of String(value ?? '')) {
|
|
101
|
+
if (ch === '"') quoted = !quoted;
|
|
102
|
+
if (ch === ';' && !quoted) { parts.push(cur); cur = ''; } else cur += ch;
|
|
103
|
+
}
|
|
104
|
+
parts.push(cur);
|
|
105
|
+
const out = {}; const pieces = {};
|
|
106
|
+
for (const p of parts.slice(1)) {
|
|
107
|
+
const at = p.indexOf('='); if (at < 0) continue;
|
|
108
|
+
const key = p.slice(0, at).trim().toLowerCase();
|
|
109
|
+
let val = p.slice(at + 1).trim();
|
|
110
|
+
if (val.startsWith('"')) val = val.replace(/^"|"$/g, '').replace(/\\(.)/g, '$1');
|
|
111
|
+
const piece = /^([^*]+)\*(\d+)?(\*)?$/.exec(key);
|
|
112
|
+
if (piece) { (pieces[piece[1]] ??= []).push({ n: Number(piece[2] ?? 0), val, enc: Boolean(piece[3]) || (piece[2] === undefined) }); } else out[key] = val;
|
|
113
|
+
}
|
|
114
|
+
for (const [key, list] of Object.entries(pieces)) {
|
|
115
|
+
list.sort((a, b) => a.n - b.n);
|
|
116
|
+
let charset = 'utf-8'; let bin = '';
|
|
117
|
+
list.forEach((p, i) => {
|
|
118
|
+
let v = p.val;
|
|
119
|
+
if (p.enc && i === 0) { const m = /^([^']*)'[^']*'(.*)$/.exec(v); if (m) { charset = m[1] || charset; v = m[2]; } }
|
|
120
|
+
bin += p.enc ? v.replace(/%([0-9A-Fa-f]{2})/g, (a, h) => String.fromCharCode(parseInt(h, 16))) : v;
|
|
121
|
+
});
|
|
122
|
+
out[key] = decode(bytesOf(bin), charset);
|
|
123
|
+
}
|
|
124
|
+
for (const k of Object.keys(out)) if (!(k in pieces)) out[k] = words(out[k]);
|
|
125
|
+
return { value: parts[0].trim().toLowerCase(), params: out };
|
|
126
|
+
}
|
|
127
|
+
function bodyBytes(binary, encoding) {
|
|
128
|
+
const e = String(encoding || '').trim().toLowerCase();
|
|
129
|
+
if (e === 'base64') return fromBase64(binary);
|
|
130
|
+
if (e === 'quoted-printable') return fromQuotedPrintable(binary);
|
|
131
|
+
return bytesOf(binary);
|
|
132
|
+
}
|
|
133
|
+
function entity(binary, depth = 0, parentType = '') {
|
|
134
|
+
const { head, body, headers } = split(binary);
|
|
135
|
+
const ct = params(first(headers, 'content-type') || (parentType === 'multipart/digest' ? 'message/rfc822' : 'text/plain; charset=us-ascii'));
|
|
136
|
+
const cd = params(first(headers, 'content-disposition'));
|
|
137
|
+
const node = {
|
|
138
|
+
head, headers, type: ct.value || 'text/plain', params: ct.params,
|
|
139
|
+
disposition: cd.value, filename: cd.params.filename || ct.params.name || '',
|
|
140
|
+
cid: first(headers, 'content-id').replace(/^\s*<|>\s*$/g, ''),
|
|
141
|
+
encoding: first(headers, 'content-transfer-encoding'), raw: body, parts: [],
|
|
142
|
+
};
|
|
143
|
+
const boundary = ct.params.boundary;
|
|
144
|
+
if (node.type.startsWith('multipart/') && boundary && depth < 20) {
|
|
145
|
+
const mark = `--${boundary}`;
|
|
146
|
+
const lines = body.split(/\r?\n/);
|
|
147
|
+
let cur = null;
|
|
148
|
+
for (const line of lines) {
|
|
149
|
+
const t = line.replace(/[ \t]+$/, '');
|
|
150
|
+
if (t === mark || t === `${mark}--`) {
|
|
151
|
+
if (cur) node.parts.push(entity(cur.join('\r\n'), depth + 1, node.type));
|
|
152
|
+
cur = t === mark ? [] : null;
|
|
153
|
+
if (t !== mark) break;
|
|
154
|
+
} else if (cur) cur.push(line);
|
|
155
|
+
}
|
|
156
|
+
if (cur && cur.length) node.parts.push(entity(cur.join('\r\n'), depth + 1, node.type));
|
|
157
|
+
}
|
|
158
|
+
return node;
|
|
159
|
+
}
|
|
160
|
+
const contentOf = (node) => bodyBytes(node.raw, node.encoding);
|
|
161
|
+
const textOf = (node) => decode(contentOf(node), node.params.charset);
|
|
162
|
+
|
|
163
|
+
/* "Ann Example <ann@example.com>, \"Doe, Bo\" <bo@example.org>" -> [{ name, address }]. */
|
|
164
|
+
function addresses(value) {
|
|
165
|
+
const text = words(value);
|
|
166
|
+
const out = []; let cur = ''; let quoted = false; let angle = false;
|
|
167
|
+
for (const ch of text) {
|
|
168
|
+
if (ch === '"') quoted = !quoted;
|
|
169
|
+
else if (ch === '<' && !quoted) angle = true;
|
|
170
|
+
else if (ch === '>' && !quoted) angle = false;
|
|
171
|
+
if (ch === ',' && !quoted && !angle) { out.push(cur); cur = ''; } else cur += ch;
|
|
172
|
+
}
|
|
173
|
+
out.push(cur);
|
|
174
|
+
return out.map((one) => {
|
|
175
|
+
const m = /^(.*?)<([^>]*)>\s*$/.exec(one.trim());
|
|
176
|
+
if (m) return { name: m[1].trim().replace(/^"|"$/g, '').replace(/\\(.)/g, '$1').trim(), address: m[2].trim() };
|
|
177
|
+
const bare = one.trim().replace(/\s*\(([^)]*)\)\s*$/, '');
|
|
178
|
+
const note = /\(([^)]*)\)\s*$/.exec(one.trim());
|
|
179
|
+
return { name: note ? note[1].trim() : '', address: bare };
|
|
180
|
+
}).filter((a) => a.address || a.name);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/* ---------- the mail ---------- */
|
|
184
|
+
function parse(input) {
|
|
185
|
+
const bytes = input instanceof Uint8Array ? input : new Uint8Array(input ?? []);
|
|
186
|
+
const top = entity(latin(bytes));
|
|
187
|
+
const mail = {
|
|
188
|
+
headers: top.headers.map(([k, v]) => [k, words(v)]), head: top.head,
|
|
189
|
+
subject: words(first(top.headers, 'subject')).trim(),
|
|
190
|
+
from: addresses(first(top.headers, 'from')), to: addresses(first(top.headers, 'to')), cc: addresses(first(top.headers, 'cc')),
|
|
191
|
+
replyTo: addresses(first(top.headers, 'reply-to')),
|
|
192
|
+
date: null, html: null, text: null, attachments: [], cids: {},
|
|
193
|
+
};
|
|
194
|
+
const d = Date.parse(first(top.headers, 'date').replace(/\s*\([^)]*\)\s*$/, ''));
|
|
195
|
+
mail.date = Number.isNaN(d) ? null : new Date(d);
|
|
196
|
+
const attach = (node, inline) => {
|
|
197
|
+
const content = contentOf(node);
|
|
198
|
+
let name = node.filename;
|
|
199
|
+
if (!name && node.type === 'message/rfc822') name = `${(words(first(split(node.raw).headers, 'subject')).trim() || 'message').replace(/[\\/:*?"<>|\u0000-\u001f]+/g, ' ').slice(0, 80)}.eml`;
|
|
200
|
+
if (!name) name = `part-${mail.attachments.length + 1}${EXT[node.type] ?? ''}`;
|
|
201
|
+
const one = { name: name.replace(/[\\/]+/g, '_'), type: node.type, size: content.length, bytes: content, cid: node.cid, inline: Boolean(inline) };
|
|
202
|
+
mail.attachments.push(one);
|
|
203
|
+
return one;
|
|
204
|
+
};
|
|
205
|
+
const isAttachment = (node) => node.disposition === 'attachment' || (Boolean(node.filename) && !/^text\/(plain|html)$/.test(node.type));
|
|
206
|
+
const hasHtml = (node) => node.type === 'text/html' || node.parts.some(hasHtml);
|
|
207
|
+
/* `body`: may this part be the mail's words, or only beside them. */
|
|
208
|
+
const walk = (node, body) => {
|
|
209
|
+
if (node.type === 'multipart/alternative') {
|
|
210
|
+
const best = [...node.parts].reverse().find((p) => hasHtml(p) && !isAttachment(p)) ?? [...node.parts].reverse().find((p) => p.type === 'text/plain') ?? node.parts[0];
|
|
211
|
+
if (best) walk(best, body);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (node.type === 'multipart/related') {
|
|
215
|
+
const start = node.params.start ? node.params.start.replace(/^<|>$/g, '') : '';
|
|
216
|
+
const main = node.parts.find((p) => start && p.cid === start) ?? node.parts[0];
|
|
217
|
+
for (const p of node.parts) {
|
|
218
|
+
if (p === main) continue;
|
|
219
|
+
if (p.cid && p.parts.length === 0) { const one = attach(p, true); mail.cids[p.cid] = one; } else walk(p, false);
|
|
220
|
+
}
|
|
221
|
+
if (main) walk(main, body);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (node.type.startsWith('multipart/')) { for (const p of node.parts) walk(p, body); return; }
|
|
225
|
+
if (!isAttachment(node) && (node.type === 'text/html' || node.type === 'text/plain') && body && mail.html === null && mail.text === null) {
|
|
226
|
+
if (node.type === 'text/html') mail.html = textOf(node); else mail.text = textOf(node);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const one = attach(node, false);
|
|
230
|
+
if (node.cid && node.type.startsWith('image/')) mail.cids[node.cid] = one;
|
|
231
|
+
};
|
|
232
|
+
walk(top, true);
|
|
233
|
+
/* A picture of the page drawn in it is not one more attachment; one it never shows is. */
|
|
234
|
+
if (mail.html !== null) {
|
|
235
|
+
const used = new Set([...mail.html.matchAll(/cid:([^"'\s)>]+)/gi)].map((m) => decodeURIComponentSafe(m[1])));
|
|
236
|
+
mail.attachments = mail.attachments.filter((a) => !(a.cid && used.has(a.cid)));
|
|
237
|
+
}
|
|
238
|
+
for (const a of mail.attachments) delete a.inline;
|
|
239
|
+
return mail;
|
|
240
|
+
}
|
|
241
|
+
const decodeURIComponentSafe = (s) => { try { return decodeURIComponent(s); } catch { return s; } };
|
|
242
|
+
const EXT = { 'text/plain': '.txt', 'text/html': '.html', 'image/png': '.png', 'image/jpeg': '.jpg', 'image/gif': '.gif', 'application/pdf': '.pdf', 'text/calendar': '.ics' };
|
|
243
|
+
|
|
244
|
+
/* ---------- its HTML, made harmless ---------- */
|
|
245
|
+
/* Tags kept (the page they draw); any other tag is dropped, its words kept. */
|
|
246
|
+
const KEEP = new Set(('a abbr address article aside b bdi bdo big blockquote br caption center cite code col colgroup dd del details dfn div dl dt em '
|
|
247
|
+
+ 'figcaption figure font footer h1 h2 h3 h4 h5 h6 header hr i img ins kbd li main mark nav ol p pre q s samp section small span strike strong '
|
|
248
|
+
+ 'style sub summary sup table tbody td tfoot th thead tr tt u ul var wbr').split(' '));
|
|
249
|
+
/* Dropped with all that is in them. */
|
|
250
|
+
const DROP = new Set('script noscript template iframe frame frameset object embed applet svg math title select textarea option button audio video canvas map xml'.split(' '));
|
|
251
|
+
const RAW = new Set(['script', 'style', 'textarea', 'title', 'xmp', 'iframe', 'noembed', 'noframes', 'noscript', 'plaintext']);
|
|
252
|
+
const VOID = new Set(['br', 'hr', 'img', 'col', 'wbr', 'area', 'base', 'link', 'meta', 'input', 'source', 'track', 'param', 'embed', 'keygen']);
|
|
253
|
+
const ATTRS = new Set(('href src alt title width height style class id align valign bgcolor color face size border cellpadding cellspacing colspan rowspan '
|
|
254
|
+
+ 'dir lang start type span background nowrap hspace vspace summary scope headers abbr reversed open cite datetime').split(' '));
|
|
255
|
+
const ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: '\u00a0', colon: ':', tab: '\t', newline: '\n', lpar: '(', rpar: ')', sol: '/', bsol: '\\', period: '.', comma: ',' };
|
|
256
|
+
const unescape = (s) => String(s).replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);?/gi, (all, e) => {
|
|
257
|
+
if (e[0] === '#') { const n = e[1] === 'x' || e[1] === 'X' ? parseInt(e.slice(2), 16) : parseInt(e.slice(1), 10); return n > 0 && n < 0x110000 ? String.fromCodePoint(n) : ''; }
|
|
258
|
+
return ENTITIES[e.toLowerCase()] ?? all;
|
|
259
|
+
});
|
|
260
|
+
const escape = (s) => String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
261
|
+
const SAFE_LINK = /^(https?:|mailto:|tel:|#)/i;
|
|
262
|
+
const REMOTE = /^(https?:)?\/\//i;
|
|
263
|
+
/* An address as a browser reads it: no blanks or controls anywhere in it ("java\tscript:"). */
|
|
264
|
+
const squeezed = (v) => unescape(v).replace(/[\u0000-\u0020\u007f-\u00a0\u00ad\u200b-\u200f\u2028\u2029\ufeff]+/g, '');
|
|
265
|
+
function sanitize(html, opts = {}) {
|
|
266
|
+
const remote = Boolean(opts.remote); const cids = opts.cids || {};
|
|
267
|
+
let blocked = 0;
|
|
268
|
+
const picture = (value) => {
|
|
269
|
+
const v = squeezed(value);
|
|
270
|
+
if (/^cid:/i.test(v)) { const one = cids[decodeURIComponentSafe(v.slice(4))]; return one && /^image\//.test(one.type) ? `data:${one.type};base64,${toBase64(one.bytes)}` : null; }
|
|
271
|
+
if (/^data:image\/(png|jpe?g|gif|webp|bmp);base64,[a-z0-9+/=\s]*$/i.test(v)) return v;
|
|
272
|
+
if (REMOTE.test(v)) { if (remote) return v.startsWith('//') ? `https:${v}` : v; blocked++; return null; }
|
|
273
|
+
return null;
|
|
274
|
+
};
|
|
275
|
+
/* CSS: nothing that runs or binds, no @import; a url() kept only as a picture is. */
|
|
276
|
+
const cssOnce = (text) => unescape(String(text)).replace(/\\/g, '')
|
|
277
|
+
.replace(/expression\s*\(|behaviou?r\s*:|-moz-binding|javascript:|vbscript:/gi, 'x-')
|
|
278
|
+
.replace(/@import[^;]*;?/gi, '')
|
|
279
|
+
.replace(/url\(\s*(['"]?)(.*?)\1\s*\)/gi, (all, q, v) => { const p = picture(v); return p ? `url("${p.replace(/"/g, '%22')}")` : 'none'; })
|
|
280
|
+
;
|
|
281
|
+
const css = (text) => { let t = cssOnce(text); for (let n = 0; n < 5 && /<\/?\s*style/i.test(t); n++) t = t.replace(/<\/?\s*style/gi, ''); return t.replace(/<\/?\s*style/gi, '').replace(/</g, ' '); };
|
|
282
|
+
let out = ''; let i = 0; const s = String(html ?? '');
|
|
283
|
+
let skip = null; let depth = 0; let bodyOpen = false;
|
|
284
|
+
while (i < s.length) {
|
|
285
|
+
const lt = s.indexOf('<', i);
|
|
286
|
+
if (lt < 0) { if (!skip) out += textOut(s.slice(i)); break; }
|
|
287
|
+
if (!skip) out += textOut(s.slice(i, lt));
|
|
288
|
+
i = lt;
|
|
289
|
+
if (s.startsWith('<!--', i)) { const end = s.indexOf('-->', i + 4); i = end < 0 ? s.length : end + 3; continue; }
|
|
290
|
+
if (s[i + 1] === '!' || s[i + 1] === '?') { const end = s.indexOf('>', i); i = end < 0 ? s.length : end + 1; continue; }
|
|
291
|
+
const closing = s[i + 1] === '/';
|
|
292
|
+
const nm = /^[a-zA-Z][a-zA-Z0-9:-]*/.exec(s.slice(i + (closing ? 2 : 1), i + 80));
|
|
293
|
+
if (!nm) { if (!skip) out += '<'; i += 1; continue; }
|
|
294
|
+
const name = nm[0].toLowerCase();
|
|
295
|
+
/* The attributes, quotes kept whole ("a>b" inside one does not end the tag). */
|
|
296
|
+
let j = i + (closing ? 2 : 1) + nm[0].length; const attrs = [];
|
|
297
|
+
while (j < s.length && s[j] !== '>') {
|
|
298
|
+
if (/[\s/]/.test(s[j])) { j++; continue; }
|
|
299
|
+
const an = /^[^\s/>=]+/.exec(s.slice(j)); if (!an) { j++; continue; }
|
|
300
|
+
j += an[0].length;
|
|
301
|
+
let k = j; while (/\s/.test(s[k] ?? '')) k++;
|
|
302
|
+
let value = '';
|
|
303
|
+
if (s[k] === '=') {
|
|
304
|
+
k++; while (/\s/.test(s[k] ?? '')) k++;
|
|
305
|
+
if (s[k] === '"' || s[k] === "'") { const end = s.indexOf(s[k], k + 1); value = s.slice(k + 1, end < 0 ? s.length : end); j = end < 0 ? s.length : end + 1; } else { const v = /^[^\s>]*/.exec(s.slice(k))[0]; value = v; j = k + v.length; }
|
|
306
|
+
}
|
|
307
|
+
attrs.push([an[0].toLowerCase(), value]);
|
|
308
|
+
}
|
|
309
|
+
i = j + 1;
|
|
310
|
+
if (skip) {
|
|
311
|
+
if (name === skip) { if (closing) { depth--; if (depth === 0) skip = null; } else if (!RAW.has(name)) depth++; }
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
if (RAW.has(name) && !closing && name !== 'style' && !KEEP.has(name)) {
|
|
315
|
+
/* Raw text (a script's, a textarea's): to its own end tag, nothing in it read as markup. */
|
|
316
|
+
const end = s.toLowerCase().indexOf(`</${name}`, i);
|
|
317
|
+
i = end < 0 ? s.length : (s.indexOf('>', end) < 0 ? s.length : s.indexOf('>', end) + 1);
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
if (name === 'style' && !closing) {
|
|
321
|
+
const end = s.toLowerCase().indexOf('</style', i);
|
|
322
|
+
const content = s.slice(i, end < 0 ? s.length : end);
|
|
323
|
+
i = end < 0 ? s.length : (s.indexOf('>', end) < 0 ? s.length : s.indexOf('>', end) + 1);
|
|
324
|
+
out += `<style>${css(content)}</style>`;
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
if (DROP.has(name)) { if (!closing && !VOID.has(name)) { skip = name; depth = 1; } continue; }
|
|
328
|
+
if (name === 'body' && !closing) {
|
|
329
|
+
/* The body's colour and its background colour, kept on a box of their own. */
|
|
330
|
+
const bg = attrs.find(([k]) => k === 'bgcolor'); const st = attrs.find(([k]) => k === 'style');
|
|
331
|
+
const style = [bg && /^#?[\w]+$/.test(bg[1]) ? `background-color:${bg[1]}` : '', st ? css(st[1]) : ''].filter(Boolean).join(';');
|
|
332
|
+
out += `<div class="mail-body"${style ? ` style="${escape(style)}"` : ''}>`; bodyOpen = true; continue;
|
|
333
|
+
}
|
|
334
|
+
if (name === 'body' && closing) { if (bodyOpen) { out += '</div>'; bodyOpen = false; } continue; }
|
|
335
|
+
if (!KEEP.has(name)) continue;
|
|
336
|
+
if (closing) { if (!VOID.has(name)) out += `</${name}>`; continue; }
|
|
337
|
+
let tag = `<${name}`;
|
|
338
|
+
for (const [k, raw] of attrs) {
|
|
339
|
+
if (k.startsWith('on') || !ATTRS.has(k)) continue;
|
|
340
|
+
let v = raw;
|
|
341
|
+
if (k === 'href') { const u = squeezed(v); if (!SAFE_LINK.test(u)) continue; v = u; }
|
|
342
|
+
else if (k === 'src') { if (name !== 'img') continue; const p = picture(v); if (!p) { tag += ' data-blocked=""'; continue; } v = p; }
|
|
343
|
+
else if (k === 'background') { const p = picture(v); if (!p) continue; v = p; }
|
|
344
|
+
else if (k === 'style') v = css(v);
|
|
345
|
+
else if (k === 'cite') continue;
|
|
346
|
+
else v = unescape(v);
|
|
347
|
+
tag += ` ${k}="${escape(v)}"`;
|
|
348
|
+
}
|
|
349
|
+
if (name === 'a') tag += ' target="_blank" rel="noopener noreferrer"';
|
|
350
|
+
out += `${tag}>`;
|
|
351
|
+
}
|
|
352
|
+
if (bodyOpen) out += '</div>';
|
|
353
|
+
return { html: out, blocked };
|
|
354
|
+
function textOut(t) { return t.replace(/</g, '<').replace(/>/g, '>'); }
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/* The frame's document: its own rules first (no script, nothing fetched but what `remote` allows),
|
|
358
|
+
links to a new tab; a mail is drawn on white as it was written for, whatever the page's theme. */
|
|
359
|
+
function pageOf(mail, opts = {}) {
|
|
360
|
+
const { html, blocked } = sanitize(mail.html ?? '', { remote: opts.remote, cids: mail.cids });
|
|
361
|
+
const img = opts.remote ? "data: https: http:" : 'data:';
|
|
362
|
+
const rules = `default-src 'none'; img-src ${img}; style-src 'unsafe-inline'; font-src data:; form-action 'none'; base-uri 'none'`;
|
|
363
|
+
const doc = `<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="${rules}">`
|
|
364
|
+
+ '<meta name="referrer" content="no-referrer"><base target="_blank">'
|
|
365
|
+
+ '<style>html{background:#fff;color:#17202b}body{margin:0;padding:16px;font:15px/1.5 system-ui,sans-serif;overflow-wrap:anywhere}img{max-width:100%;height:auto}img[data-blocked]{display:none}pre{white-space:pre-wrap}</style>'
|
|
366
|
+
+ `</head><body>${html}</body></html>`;
|
|
367
|
+
return { html: doc, blocked };
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/* Words and links, for the page to draw as text and <a> (never as markup). */
|
|
371
|
+
function linkify(text) {
|
|
372
|
+
const out = []; const re = /\b(https?:\/\/[^\s<>"']+|mailto:[^\s<>"']+|[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,})/g;
|
|
373
|
+
let last = 0; let m;
|
|
374
|
+
const t = String(text ?? '');
|
|
375
|
+
while ((m = re.exec(t))) {
|
|
376
|
+
let link = m[0]; const trail = /[.,;:!?)\]]+$/.exec(link); if (trail) link = link.slice(0, -trail[0].length);
|
|
377
|
+
if (m.index > last) out.push({ text: t.slice(last, m.index) });
|
|
378
|
+
out.push({ text: link, href: /^(https?|mailto):/i.test(link) ? link : `mailto:${link}` });
|
|
379
|
+
last = m.index + link.length; re.lastIndex = last;
|
|
380
|
+
}
|
|
381
|
+
if (last < t.length) out.push({ text: t.slice(last) });
|
|
382
|
+
return out;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
root.clavariumMail = { parse, sanitize, pageOf, linkify, words, decode, addresses };
|
|
386
|
+
})(typeof window !== 'undefined' ? window : globalThis);
|
package/web/style.css
CHANGED
|
@@ -453,7 +453,7 @@ footer button.careful { border-style: dashed; color: var(--ink2); }
|
|
|
453
453
|
#chat-off p { margin: 0 0 10px; font-size: 1rem; }
|
|
454
454
|
#chat-off p + p { color: var(--ink2); }
|
|
455
455
|
#simple[data-chat] { display: flex; flex-direction: column; overflow: hidden; padding: 10px 14px 12px; }
|
|
456
|
-
#simple-thread { flex: 1; min-height: 0; --parley-bg: var(--bg); --parley-text: var(--ink); --parley-dim: var(--ink2); --parley-line: var(--line); --parley-agent: var(--panel); --parley-person: var(--bar); --parley-ask: var(--brass-ink); --parley-wait: var(--wait); --parley-ok: var(--ok); --parley-action: var(--brass-ink); --parley-on-action: var(--on-brass); --parley-live: var(--danger); }
|
|
456
|
+
#simple-thread { flex: 1; min-height: 0; --parley-risk: var(--warn); --parley-bg: var(--bg); --parley-text: var(--ink); --parley-dim: var(--ink2); --parley-line: var(--line); --parley-agent: var(--panel); --parley-person: var(--bar); --parley-ask: var(--brass-ink); --parley-wait: var(--wait); --parley-ok: var(--ok); --parley-action: var(--brass-ink); --parley-on-action: var(--on-brass); --parley-live: var(--danger); }
|
|
457
457
|
|
|
458
458
|
|
|
459
459
|
/* Private repositories: how the server gets in, and the keys made here. */
|
|
@@ -2109,35 +2109,9 @@ details.commit > pre { margin: 6px 0 0 1.6em; white-space: pre-wrap; overflow-wr
|
|
|
2109
2109
|
.tool-exit-lines { max-height: 14rem; overflow: auto; font-size: .75rem; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bar); padding: .5rem .6rem; border-radius: 8px; margin: .3rem 0; }
|
|
2110
2110
|
.curve-legend-oom { color: var(--danger); }
|
|
2111
2111
|
|
|
2112
|
-
/* A request of the AI as a card (#190). */
|
|
2113
|
-
.
|
|
2114
|
-
.
|
|
2115
|
-
.dm-card > .dm-risk, .dm-card > .dm-acts { align-self: stretch; }
|
|
2116
|
-
.dm-top { display: flex; justify-content: flex-start; gap: 8px; align-items: center; font-size: .8125rem; color: var(--ink2); }
|
|
2117
|
-
.dm-ico { width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; background: var(--button); font-size: .8125rem; flex: none; }
|
|
2118
|
-
.dm-chev { margin-left: auto; font-size: 1.125rem; line-height: 1; transition: transform .15s; }
|
|
2119
|
-
.dm-card.open .dm-chev { transform: rotate(90deg); }
|
|
2120
|
-
.dm-head { display: flex; gap: 10px; align-items: center; min-width: 0; }
|
|
2121
|
-
.dm-hw { min-width: 0; }
|
|
2122
|
-
.dm-title { font-size: 1rem; line-height: 1.3; overflow-wrap: anywhere; }
|
|
2123
|
-
.dm-sub { color: var(--ink2); font-size: .875rem; }
|
|
2124
|
-
.dm-day { width: 46px; flex: none; text-align: center; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
|
|
2125
|
-
.dm-day-w { background: var(--brass); color: var(--on-brass); font-size: .6875rem; font-weight: 600; letter-spacing: .06em; padding: 1px 0; }
|
|
2126
|
-
.dm-day-n { font-size: 1.125rem; font-weight: 600; padding: 1px 0 3px; }
|
|
2127
|
-
.dm-risk { padding: 5px 9px; border-radius: 8px; background: color-mix(in srgb, var(--warn) 14%, transparent); color: inherit; font-size: .875rem; font-weight: 600; }
|
|
2128
|
-
.dm-facts { display: grid; justify-content: start; justify-items: start; grid-template-columns: 1.6em minmax(0, 1fr); gap: 3px 6px; font-size: .875rem; }
|
|
2129
|
-
.dm-k { color: var(--ink2); text-align: center; }
|
|
2130
|
-
.dm-v { min-width: 0; overflow-wrap: anywhere; }
|
|
2131
|
-
.dm-chips { display: inline-flex; flex-wrap: wrap; gap: 3px; }
|
|
2132
|
-
.dm-chip { border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; font-size: .8125rem; }
|
|
2133
|
-
.dm-chip.ext { border-color: color-mix(in srgb, var(--warn) 70%, transparent); }
|
|
2134
|
-
.dm-quote { border-left: 3px solid var(--line); padding: 1px 9px; font-size: .875rem; white-space: pre-line; max-height: 7.5em; overflow: hidden; }
|
|
2135
|
-
.dm-card.open .dm-quote { max-height: none; }
|
|
2136
|
-
.dm-why { color: var(--ink2); font-size: .875rem; }
|
|
2137
|
-
.dm-more { font-size: .8125rem; font-family: ui-monospace, monospace; overflow-wrap: anywhere; border-top: 1px dashed var(--line); padding-top: 6px; }
|
|
2138
|
-
.dm-acts { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
|
|
2139
|
-
.dm-acts .dm-dots { padding-inline: .7em; }
|
|
2140
|
-
.dm-undo { display: flex; gap: 10px; align-items: center; justify-content: space-between; font-size: .875rem; padding: 4px 0; }
|
|
2112
|
+
/* A request of the AI as a card (#190): Parley's own (requestCard), the same in the thread and here; its colours, this page's. */
|
|
2113
|
+
.demandes-box, body > .parley-request-shade { --parley-bg: var(--panel); --parley-text: var(--ink); --parley-dim: var(--ink2); --parley-line: var(--line); --parley-agent: var(--bar); --parley-ask: var(--brass-ink); --parley-ok: var(--ok); --parley-action: var(--brass-ink); --parley-risk: var(--warn); --parley-code-bg: var(--bar); }
|
|
2114
|
+
.demandes-box { display: flex; flex-direction: column; gap: 10px; }
|
|
2141
2115
|
.as-signature { display: flex; flex-direction: column; gap: 6px; margin: .6rem 0; }
|
|
2142
2116
|
.as-signature textarea { width: 100%; font: inherit; }
|
|
2143
2117
|
.as-drag-ghost { position: fixed; z-index: 90; pointer-events: none; opacity: .9; box-shadow: 0 12px 30px -10px rgba(0,0,0,.5); border-radius: 10px; background: var(--panel); }
|
|
@@ -2253,6 +2227,31 @@ body.as-dragging #assets-rows .as-row { touch-action: none; }
|
|
|
2253
2227
|
.sheet-table thead th { top: 0; z-index: 1; } .sheet-table tbody th { left: 0; }
|
|
2254
2228
|
.doc-frame { width: 100%; min-height: 70vh; border: 0; border-radius: 8px; background: transparent; }
|
|
2255
2229
|
|
|
2230
|
+
/* A MAIL FILE (.eml), as a mail program shows it (app.js showMail): its head, its words, its attachments. */
|
|
2231
|
+
.mail-view { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
|
|
2232
|
+
.mail-head { display: flex; flex-direction: column; gap: 4px; padding: 4px 2px 10px; border-bottom: 1px solid var(--line); min-width: 0; }
|
|
2233
|
+
.mail-subject { margin: 0 0 4px; font-size: 1.25rem; line-height: 1.3; color: var(--ink); overflow-wrap: anywhere; }
|
|
2234
|
+
.mail-from, .mail-line { font-size: .875rem; color: var(--ink); overflow-wrap: anywhere; }
|
|
2235
|
+
.mail-line { display: flex; gap: 8px; }
|
|
2236
|
+
.mail-label { flex: 0 0 3.2em; color: var(--ink2); }
|
|
2237
|
+
.mail-addr { font-size: .8125rem; }
|
|
2238
|
+
#viewer .mail-details { align-self: flex-start; min-height: 32px; padding: 0 2px; border: 0; font-size: .8125rem; text-decoration: underline; }
|
|
2239
|
+
#preview-body pre.mail-headers { padding: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; font-size: .75rem; max-height: 40vh; overflow: auto; }
|
|
2240
|
+
.mail-remote { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 4px 10px; font-size: .8125rem; color: var(--ink2); background: var(--bar); border: 1px solid var(--line); border-radius: 6px; }
|
|
2241
|
+
#viewer .mail-remote-show { min-height: 32px; padding: 0 4px; border: 0; color: var(--brass-ink); font-weight: 600; text-decoration: underline; }
|
|
2242
|
+
#preview-body iframe.mail-frame { flex: 0 0 auto; height: min(70vh, 900px); border: 1px solid var(--line); }
|
|
2243
|
+
.mail-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .9375rem; line-height: 1.5; color: var(--ink); padding: 4px 2px; }
|
|
2244
|
+
.mail-text a { color: var(--brass-ink); }
|
|
2245
|
+
.mail-files { list-style: none; margin: 0; padding: 8px 0 0; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 6px; }
|
|
2246
|
+
.mail-file { display: flex; align-items: stretch; min-width: 0; max-width: 100%; border: 1px solid var(--line); border-radius: 8px; }
|
|
2247
|
+
#viewer .mail-file-open { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 4px 10px; border: 0; color: var(--ink); text-align: left; }
|
|
2248
|
+
.mail-file-open b { font-weight: 600; font-size: .8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
|
|
2249
|
+
.mail-file-open small { color: var(--ink2); font-size: .75rem; white-space: nowrap; }
|
|
2250
|
+
.mail-file-open .kind { flex: 0 0 34px; font-size: .6875rem; font-weight: 600; text-align: center; padding: 3px 0; border: 1px solid var(--line); border-radius: 5px; color: var(--ink2); }
|
|
2251
|
+
.mail-file-get { display: flex; align-items: center; justify-content: center; width: 40px; border-left: 1px solid var(--line); color: var(--ink2); }
|
|
2252
|
+
.mail-file-get .ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
|
|
2253
|
+
@media (max-width: 560px) { .mail-file-open small { display: none; } .mail-file { flex: 1 1 100%; } }
|
|
2254
|
+
|
|
2256
2255
|
/* THE CONVERSATIONS AS CARDS (02-11): playing cards, one per conversation, and one to add. */
|
|
2257
2256
|
#list-title { cursor: pointer; }
|
|
2258
2257
|
#deck { overflow-y: auto; }
|
|
@@ -2303,7 +2302,7 @@ body.as-dragging #assets-rows .as-row { touch-action: none; }
|
|
|
2303
2302
|
.salon-members-row > .hint { width: 4.5rem; }
|
|
2304
2303
|
.salon-member { display: inline-flex; align-items: center; gap: 6px; font-size: .8125rem; }
|
|
2305
2304
|
.salon-host { font-size: .6875rem; color: var(--ink2); border: 1px solid var(--line); border-radius: 999px; padding: 0 6px; }
|
|
2306
|
-
#salon-thread { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0 14px 12px; --parley-bg: var(--bg); --parley-text: var(--ink); --parley-dim: var(--ink2); --parley-line: var(--line); --parley-agent: var(--panel); --parley-person: var(--bar); --parley-ask: var(--brass-ink); --parley-wait: var(--wait); --parley-ok: var(--ok); --parley-action: var(--brass-ink); --parley-on-action: var(--on-brass); --parley-live: var(--danger); }
|
|
2305
|
+
#salon-thread { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0 14px 12px; --parley-risk: var(--warn); --parley-bg: var(--bg); --parley-text: var(--ink); --parley-dim: var(--ink2); --parley-line: var(--line); --parley-agent: var(--panel); --parley-person: var(--bar); --parley-ask: var(--brass-ink); --parley-wait: var(--wait); --parley-ok: var(--ok); --parley-action: var(--brass-ink); --parley-on-action: var(--on-brass); --parley-live: var(--danger); }
|
|
2307
2306
|
|
|
2308
2307
|
.salon-thinking { display: flex; align-items: center; gap: 6px; margin: 0; padding: 0 14px 8px; font-size: .75rem; color: var(--ink2); order: 2; }
|
|
2309
2308
|
#salon-new { display: flex; flex-direction: column; }
|