domma-cms 1.7.0 → 1.7.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/CHANGELOG.md +5 -0
- package/admin/js/lib/mail-compose.js +1 -0
- package/admin/js/templates/call-new.html +1 -1
- package/admin/js/views/call-new.js +1 -1
- package/admin/js/views/contacts.js +15 -15
- package/admin/js/views/form-submissions.js +2 -2
- package/package.json +1 -1
- package/plugins/_lib/admin/mail/compose-window.js +3 -1
- package/plugins/_lib/admin/mail/identity.js +18 -3
- package/plugins/_lib/admin/mail/reader-view.js +32 -3
- package/plugins/blog/CLAUDE.md +4 -0
- package/plugins/blog/admin/lib/email.js +191 -0
- package/plugins/blog/admin/views/comments.js +3 -1
- package/plugins/blog/plugin.json +2 -2
- package/plugins/blog/plugin.public.js +1 -1
- package/plugins/blog/tests/email.test.js +69 -0
- package/plugins/booking/CLAUDE.md +4 -0
- package/plugins/booking/admin/lib/email.js +191 -0
- package/plugins/booking/admin/views/panels.js +7 -3
- package/plugins/booking/plugin.json +1 -1
- package/plugins/booking/tests/email.test.js +69 -0
- package/plugins/free-tier.lock.json +27 -19
- package/plugins/shopping-cart/CLAUDE.md +4 -0
- package/plugins/shopping-cart/admin/lib/email.js +191 -0
- package/plugins/shopping-cart/admin/views/orders.js +11 -3
- package/plugins/shopping-cart/plugin.json +2 -2
- package/plugins/shopping-cart/tests/email.test.js +69 -0
- package/plugins/support/CLAUDE.md +4 -0
- package/plugins/support/admin/lib/email.js +191 -0
- package/plugins/support/admin/views/desk.js +4 -1
- package/plugins/support/admin/views/inbox.js +6 -2
- package/plugins/support/plugin.json +2 -2
- package/plugins/support/tests/email.test.js +69 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Email someone from this Tool: Email Pro's compose window when the user can
|
|
3
|
+
* send from it, otherwise the device's mail program through `mailto:`.
|
|
4
|
+
*
|
|
5
|
+
* Core makes the choice (`/admin/js/lib/mail-compose.js`, CMS 1.6.61+). It is
|
|
6
|
+
* imported at RUN time, never statically, so this Tool still loads on an older
|
|
7
|
+
* core - where every action keeps the plain `mailto:` it always had.
|
|
8
|
+
*
|
|
9
|
+
* `emailTo()` is for menu actions; `routeMailLinks()` is for a visible
|
|
10
|
+
* `<a href="mailto:…">` - the link stays a link (copy, hover, middle-click all
|
|
11
|
+
* still work) and a plain click goes the same way as the menu action.
|
|
12
|
+
*
|
|
13
|
+
* @module support/admin/lib/email
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const CORE = '/admin/js/lib/mail-compose.js';
|
|
17
|
+
let core = null;
|
|
18
|
+
|
|
19
|
+
/** The core module, or null on a core without it. Asked once. */
|
|
20
|
+
const loadCore = () => (core ??= import(CORE).catch(() => null));
|
|
21
|
+
|
|
22
|
+
/** Longest subject or body carried (as core's). */
|
|
23
|
+
const MAX_TEXT = 2000;
|
|
24
|
+
/** Longest mailto: handed to the device - mail programs cut or refuse longer ones. */
|
|
25
|
+
const MAX_MAILTO = 1800;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Something that can only be an email address: one @, no spaces or line
|
|
29
|
+
* breaks, nothing that would start another recipient or a query.
|
|
30
|
+
*
|
|
31
|
+
* @param {*} value
|
|
32
|
+
* @returns {boolean}
|
|
33
|
+
*/
|
|
34
|
+
export function looksLikeAddress(value) {
|
|
35
|
+
return typeof value === 'string' && /^[^\s@<>,;"?&]+@[^\s@<>,;"?&]+$/.test(value);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Valid addresses only, once each (ignoring case), from a string, `{address}`/`{email}`, or a list. */
|
|
39
|
+
function addressesOf(list) {
|
|
40
|
+
const seen = new Set();
|
|
41
|
+
return (Array.isArray(list) ? list : list == null ? [] : [list])
|
|
42
|
+
.map(x => String(typeof x === 'string' ? x : (x?.address ?? x?.email ?? '')).trim())
|
|
43
|
+
.filter(a => looksLikeAddress(a) && !seen.has(a.toLowerCase()) && seen.add(a.toLowerCase()));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Trim and cap; a subject loses its line breaks (they would be a header). */
|
|
47
|
+
function cleanText(value, {oneLine = false} = {}) {
|
|
48
|
+
let text = String(value ?? '');
|
|
49
|
+
if (oneLine) text = text.replace(/[\r\n]+/g, ' ');
|
|
50
|
+
return text.slice(0, MAX_TEXT).trim();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The request as a `mailto:` link (the fallback on an older core).
|
|
55
|
+
*
|
|
56
|
+
* @param {{to?: *, cc?: *, bcc?: *, subject?: string, body?: string}} request
|
|
57
|
+
* @returns {string}
|
|
58
|
+
*/
|
|
59
|
+
export function mailtoHref({to, cc, bcc, subject, body} = {}) {
|
|
60
|
+
const enc = (list) => addressesOf(list).map(a => encodeURIComponent(a).replace(/%40/g, '@')).join(',');
|
|
61
|
+
const s = cleanText(subject, {oneLine: true});
|
|
62
|
+
const b = cleanText(body);
|
|
63
|
+
const query = [];
|
|
64
|
+
if (enc(cc)) query.push(`cc=${enc(cc)}`);
|
|
65
|
+
if (enc(bcc)) query.push(`bcc=${enc(bcc)}`);
|
|
66
|
+
if (s) query.push(`subject=${encodeURIComponent(s)}`);
|
|
67
|
+
if (b) query.push(`body=${encodeURIComponent(b)}`);
|
|
68
|
+
return `mailto:${enc(to)}${query.length ? `?${query.join('&')}` : ''}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Copy text: the clipboard, else the old copy command, else a box to copy it from by hand. */
|
|
72
|
+
async function copyText(text) {
|
|
73
|
+
try {
|
|
74
|
+
await navigator.clipboard.writeText(text);
|
|
75
|
+
return true;
|
|
76
|
+
} catch { /* next */ }
|
|
77
|
+
const box = document.createElement('textarea');
|
|
78
|
+
box.className = 'form-input';
|
|
79
|
+
box.readOnly = true;
|
|
80
|
+
box.rows = 6;
|
|
81
|
+
box.value = text;
|
|
82
|
+
try {
|
|
83
|
+
box.style.position = 'fixed';
|
|
84
|
+
box.style.opacity = '0';
|
|
85
|
+
document.body.appendChild(box);
|
|
86
|
+
box.select();
|
|
87
|
+
if (document.execCommand('copy')) return true;
|
|
88
|
+
} catch { /* next */ } finally {
|
|
89
|
+
box.remove();
|
|
90
|
+
box.style.position = '';
|
|
91
|
+
box.style.opacity = '';
|
|
92
|
+
}
|
|
93
|
+
const modal = E.modal({title: 'Copy the addresses', size: 'medium', buttons: [{id: 'close', text: 'Close', variant: 'secondary'}]});
|
|
94
|
+
modal.element.appendChild(box); // light DOM: setContent would strip the textarea
|
|
95
|
+
modal.open();
|
|
96
|
+
box.select();
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Hand the request to the device's mail program - unless the link would be
|
|
102
|
+
* too long for it, when the addresses are copied instead and the toast says
|
|
103
|
+
* what did not go.
|
|
104
|
+
*/
|
|
105
|
+
async function openMailto(request) {
|
|
106
|
+
const href = mailtoHref(request);
|
|
107
|
+
if (href.length <= MAX_MAILTO) {
|
|
108
|
+
location.href = href;
|
|
109
|
+
return 'mailto';
|
|
110
|
+
}
|
|
111
|
+
const all = addressesOf([...addressesOf(request.to), ...addressesOf(request.cc), ...addressesOf(request.bcc)]);
|
|
112
|
+
const copied = all.length ? await copyText(all.join(', ')) : false;
|
|
113
|
+
const lost = [cleanText(request.subject) && 'the subject', cleanText(request.body) && 'the message'].filter(Boolean);
|
|
114
|
+
E.toast(`Too long for your mail program to open. ${all.length
|
|
115
|
+
? `${copied ? 'The' : 'Copy the'} ${all.length} address${all.length === 1 ? '' : 'es'}${copied ? ' are copied' : ''} - paste them into Bcc of a new email.` : ''}${lost.length ? ` Not carried over: ${lost.join(' and ')}.` : ''}`,
|
|
116
|
+
{type: 'warning', duration: 9000});
|
|
117
|
+
return 'copied';
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const decode = (s) => { try { return decodeURIComponent(s); } catch { return s; } };
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A `mailto:` link read back into a request (what a visible link carries).
|
|
124
|
+
* When the address part holds anything that is not an address, the query
|
|
125
|
+
* is ignored: an address stored as `me@x.com?body=…` must not prefill a message.
|
|
126
|
+
*
|
|
127
|
+
* @param {string} href
|
|
128
|
+
* @returns {null|{to: string[], cc: string[], bcc: string[], subject: string, body: string}}
|
|
129
|
+
*/
|
|
130
|
+
export function parseMailto(href) {
|
|
131
|
+
const m = String(href ?? '').match(/^mailto:([^?]*)(?:\?(.*))?$/i);
|
|
132
|
+
if (!m) return null;
|
|
133
|
+
const split = (s) => decode(s || '').split(/[,;]/).map(x => x.trim()).filter(Boolean);
|
|
134
|
+
const named = split(m[1]);
|
|
135
|
+
const out = {to: addressesOf(named), cc: [], bcc: [], subject: '', body: ''};
|
|
136
|
+
if (named.some(a => !looksLikeAddress(a))) return out;
|
|
137
|
+
for (const pair of (m[2] || '').split('&')) {
|
|
138
|
+
const i = pair.indexOf('=');
|
|
139
|
+
if (i < 1) continue;
|
|
140
|
+
const key = pair.slice(0, i).toLowerCase();
|
|
141
|
+
const value = pair.slice(i + 1);
|
|
142
|
+
if (key === 'to') out.to = addressesOf([...out.to, ...split(value)]);
|
|
143
|
+
else if (key === 'cc' || key === 'bcc') out[key] = addressesOf([...out[key], ...split(value)]);
|
|
144
|
+
else if (key === 'subject') out.subject = cleanText(decode(value), {oneLine: true});
|
|
145
|
+
else if (key === 'body') out.body = cleanText(decode(value));
|
|
146
|
+
}
|
|
147
|
+
return out;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Email someone. Recipients are `{name, address}`, `{name, email}` or bare
|
|
152
|
+
* addresses; several people belong in `bcc`, so nobody sees the others.
|
|
153
|
+
* With nobody to address (a link to pass on) compose still opens, To empty.
|
|
154
|
+
*
|
|
155
|
+
* @param {{to?: *, cc?: *, bcc?: *, subject?: string, body?: string}} request
|
|
156
|
+
* @returns {Promise<'compose'|'mailto'|'copied'|'none'>}
|
|
157
|
+
*/
|
|
158
|
+
export async function emailTo(request = {}) {
|
|
159
|
+
const mail = await loadCore();
|
|
160
|
+
if (!mail) return openMailto(request);
|
|
161
|
+
const r = mail.composeRequest(request);
|
|
162
|
+
if (r.to.length || r.cc.length || r.bcc.length) return mail.openEmail(r);
|
|
163
|
+
if (await mail.emailReady()) {
|
|
164
|
+
location.hash = mail.composeHash(r);
|
|
165
|
+
return 'compose';
|
|
166
|
+
}
|
|
167
|
+
location.href = mail.mailtoHref(r);
|
|
168
|
+
return 'mailto';
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Send plain clicks on the `mailto:` links inside `root` through `emailTo()`.
|
|
173
|
+
* A modified click (new tab/window) or one already handled is left alone.
|
|
174
|
+
*
|
|
175
|
+
* @param {Element} root
|
|
176
|
+
* @returns {() => void} removes the listener
|
|
177
|
+
*/
|
|
178
|
+
export function routeMailLinks(root) {
|
|
179
|
+
if (!root) return () => {};
|
|
180
|
+
const onClick = (e) => {
|
|
181
|
+
if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
|
|
182
|
+
const a = e.target?.closest?.('a[href^="mailto:" i]');
|
|
183
|
+
if (!a || !root.contains(a)) return;
|
|
184
|
+
const request = parseMailto(a.getAttribute('href'));
|
|
185
|
+
if (!request) return;
|
|
186
|
+
e.preventDefault();
|
|
187
|
+
emailTo(request);
|
|
188
|
+
};
|
|
189
|
+
root.addEventListener('click', onClick);
|
|
190
|
+
return () => root.removeEventListener('click', onClick);
|
|
191
|
+
}
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
refreshBadge, rowKeys, stamp, store, telHref, threadFiles, threadRows, when
|
|
19
19
|
} from '../lib/kit.js';
|
|
20
20
|
import {DRAFT_KEYS, afterSend, draftQuestion, draftText, draftValues, newDraftQuestion, ticketPrint} from '../lib/drafts.js';
|
|
21
|
+
import {looksLikeAddress, routeMailLinks} from '../lib/email.js';
|
|
21
22
|
|
|
22
23
|
const ROW = `
|
|
23
24
|
<div class="sp-row" data-id="{{key}}" tabindex="0" role="button" aria-haspopup="menu">
|
|
@@ -154,9 +155,11 @@ export async function mount(root, ctx) {
|
|
|
154
155
|
const tel = view.querySelector('[data-ref="tel"]');
|
|
155
156
|
scope(M.effect(() => {
|
|
156
157
|
const c = contact.value || {};
|
|
157
|
-
if (c.email) mailLink.setAttribute('href', `mailto:${c.email}`);
|
|
158
|
+
if (looksLikeAddress(c.email)) mailLink.setAttribute('href', `mailto:${encodeURIComponent(c.email)}`);
|
|
158
159
|
if (c.phone) tel.setAttribute('href', telHref(c.phone));
|
|
159
160
|
}));
|
|
161
|
+
// Domma's address stays a link; a click goes to Email Pro's compose when this user can send from it.
|
|
162
|
+
scope(routeMailLinks(view));
|
|
160
163
|
|
|
161
164
|
// The first load shows a skeleton in the slot; a reload keeps the list on screen.
|
|
162
165
|
let loaded = false;
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
threadFiles, threadRows, when
|
|
14
14
|
} from '../lib/kit.js';
|
|
15
15
|
import {DRAFT_KEYS, afterSend, draftQuestion, draftText, draftValues, ticketPrint} from '../lib/drafts.js';
|
|
16
|
+
import {looksLikeAddress, routeMailLinks} from '../lib/email.js';
|
|
16
17
|
|
|
17
18
|
const ROW = `
|
|
18
19
|
<div class="sp-row" data-id="{{key}}" tabindex="0" role="button" aria-haspopup="menu">
|
|
@@ -234,6 +235,7 @@ export async function mount(root, ctx) {
|
|
|
234
235
|
let guard = null;
|
|
235
236
|
let savedNotes = saved.notes;
|
|
236
237
|
let stopScroll = () => {};
|
|
238
|
+
let stopMail = () => {};
|
|
237
239
|
let menu = null;
|
|
238
240
|
|
|
239
241
|
const run = async (fn) => {
|
|
@@ -249,7 +251,7 @@ export async function mount(root, ctx) {
|
|
|
249
251
|
size: 'lg',
|
|
250
252
|
model: {thread, status, statusLabel, tone, urgent, archived, draft, hasDraft, after, notes, busy},
|
|
251
253
|
cleanup: () => {
|
|
252
|
-
stopScroll(); stopFiles(); shown.dispose(); menu?.destroy?.();
|
|
254
|
+
stopScroll(); stopMail(); stopFiles(); shown.dispose(); menu?.destroy?.();
|
|
253
255
|
[cur, thread, status, statusLabel, tone, urgent, archived, hasDraft].forEach(c => c.dispose?.());
|
|
254
256
|
panels.release('detail');
|
|
255
257
|
},
|
|
@@ -258,7 +260,7 @@ export async function mount(root, ctx) {
|
|
|
258
260
|
<div><dt>Status</dt><dd><span class="sp-chip" data-bind-class="tone.value" data-bind-text="statusLabel.value"></span>
|
|
259
261
|
<span class="sp-chip is-muted" data-bind-hidden="!archived.value">Archived</span></dd></div>
|
|
260
262
|
<div><dt>Site</dt><dd>${siteUrl ? `<a href="${esc(siteUrl)}" target="_blank" rel="noopener">${esc(t.siteName)}</a>` : esc(t.siteName)}</dd></div>
|
|
261
|
-
<div><dt>From</dt><dd>${esc(t.userName)}${t.userEmail ? ` ·
|
|
263
|
+
<div><dt>From</dt><dd>${esc(t.userName)}${t.userEmail ? ` · ${looksLikeAddress(t.userEmail) ? `<a href="mailto:${esc(encodeURIComponent(t.userEmail))}">${esc(t.userEmail)}</a>` : esc(t.userEmail)}` : ''}</dd></div>
|
|
262
264
|
<div><dt>About</dt><dd>${esc(labelOf(t.category))}</dd></div>
|
|
263
265
|
<div><dt>Opened</dt><dd>${esc(stamp(t.createdAt))}</dd></div>
|
|
264
266
|
${t.where ? `<div><dt>Where</dt><dd>${esc(t.where)}</dd></div>` : ''}
|
|
@@ -329,6 +331,8 @@ export async function mount(root, ctx) {
|
|
|
329
331
|
was: offer.state === 'keep' ? offer.draft.was : ticketPrint(t, {notes: true})
|
|
330
332
|
});
|
|
331
333
|
panels.set('detail', {key: tid, close: (how) => guard.close(how)});
|
|
334
|
+
// The customer's address stays a link; a click goes to Email Pro's compose when it can.
|
|
335
|
+
stopMail = routeMailLinks(panel.panel);
|
|
332
336
|
// Keep the newest message in view as the thread grows.
|
|
333
337
|
const box = panel.panel.querySelector('.sp-thread-host');
|
|
334
338
|
stopScroll = M.effect(() => { thread.value; Promise.resolve().then(() => { M.flush?.(); box.scrollTop = box.scrollHeight; }); });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "support",
|
|
3
3
|
"displayName": "Support",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.1",
|
|
5
5
|
"tier": "free",
|
|
6
6
|
"description": "Get help from Domma straight from your admin: our email, phone and hours always to hand, and a conversation with the Domma team for anything you need - urgent requests first. Right-click a request to archive, resolve or remove it.",
|
|
7
7
|
"author": "Domma CMS",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
],
|
|
62
62
|
"views": {
|
|
63
63
|
"plugin-support": {
|
|
64
|
-
"entry": "support/admin/views/support.js?v=1.2.
|
|
64
|
+
"entry": "support/admin/views/support.js?v=1.2.1",
|
|
65
65
|
"exportName": "supportView"
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/lib/email.js - the mailto: fallback and link reading (node has no
|
|
3
|
+
* /admin/js/lib/mail-compose.js, so emailTo() here is the older-core path).
|
|
4
|
+
*/
|
|
5
|
+
import {test} from 'node:test';
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import {emailTo, looksLikeAddress, mailtoHref, parseMailto} from '../admin/lib/email.js';
|
|
8
|
+
|
|
9
|
+
test('mailtoHref: one person in To, subject and body encoded, @ readable', () => {
|
|
10
|
+
assert.equal(mailtoHref({to: [{name: 'Ann', address: 'ann+x@example.test'}], subject: 'Hi & bye', body: 'Line 1\nLine 2'}),
|
|
11
|
+
'mailto:ann%2Bx@example.test?subject=Hi%20%26%20bye&body=Line%201%0ALine%202');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('mailtoHref: several people in Bcc, strings and contacts alike', () => {
|
|
15
|
+
assert.equal(mailtoHref({bcc: ['a@x.test', {email: 'b@x.test'}], subject: 'S'}), 'mailto:?bcc=a@x.test,b@x.test&subject=S');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('parseMailto reads back what mailtoHref writes, and plain links', () => {
|
|
19
|
+
const r = parseMailto(mailtoHref({to: 'a@x.test', cc: ['c@x.test'], bcc: ['b@x.test', 'd@x.test'], subject: 'Hi + there', body: 'Join: https://x.test/?a=1&b=2'}));
|
|
20
|
+
assert.deepEqual(r, {to: ['a@x.test'], cc: ['c@x.test'], bcc: ['b@x.test', 'd@x.test'], subject: 'Hi + there', body: 'Join: https://x.test/?a=1&b=2'});
|
|
21
|
+
assert.deepEqual(parseMailto('mailto:ann@example.test'), {to: ['ann@example.test'], cc: [], bcc: [], subject: '', body: ''});
|
|
22
|
+
assert.equal(parseMailto('https://example.test'), null);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('emailTo on a core without mail-compose.js keeps the old mailto:', async () => {
|
|
26
|
+
const saved = globalThis.location;
|
|
27
|
+
globalThis.location = {href: '', hash: ''};
|
|
28
|
+
try {
|
|
29
|
+
assert.equal(await emailTo({to: [{name: 'Ann', address: 'ann@example.test'}], subject: 'Hello'}), 'mailto');
|
|
30
|
+
assert.equal(globalThis.location.href, 'mailto:ann@example.test?subject=Hello');
|
|
31
|
+
assert.equal(globalThis.location.hash, '');
|
|
32
|
+
} finally {
|
|
33
|
+
globalThis.location = saved;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('fallback hardening: bad addresses dropped, repeats once, subject one line, text capped', () => {
|
|
38
|
+
for (const bad of ['a b@x.test', 'a@x.test\r\nBcc: c@x.test', '<a@x.test>', 'a@x.test,b@x.test', 'a@x.test?body=hi', 'nobody']) assert.equal(looksLikeAddress(bad), false, bad);
|
|
39
|
+
const href = mailtoHref({to: ['A@x.test', 'a@x.test', 'a b@x.test', 'me@x.test?body=evil'], subject: 'Hi\r\nBcc: c@x.test', body: 'x'.repeat(3000)});
|
|
40
|
+
assert.ok(href.startsWith('mailto:A@x.test?subject=Hi%20Bcc%3A%20c%40x.test&body='), href);
|
|
41
|
+
assert.equal(decodeURIComponent(href.split('body=')[1]).length, 2000);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('parseMailto ignores the query when the address part is not an address', () => {
|
|
45
|
+
// An address stored as "me@x.com?body=..." and encoded into a link.
|
|
46
|
+
assert.deepEqual(parseMailto(`mailto:${encodeURIComponent('me@x.test?body=Pay now')}`), {to: [], cc: [], bcc: [], subject: '', body: ''});
|
|
47
|
+
assert.deepEqual(parseMailto('mailto:me@x.test%0D%0Abcc:z@x.test?subject=Hi&bcc=y@x.test'), {to: [], cc: [], bcc: [], subject: '', body: ''});
|
|
48
|
+
assert.deepEqual(parseMailto('mailto:?subject=Join&body=link').subject, 'Join');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('emailTo on an old core: a mailto over 1800 characters is not opened - the addresses are copied', async () => {
|
|
52
|
+
const saved = {location: globalThis.location, E: globalThis.E, nav: Object.getOwnPropertyDescriptor(globalThis, 'navigator')};
|
|
53
|
+
let copied = '';
|
|
54
|
+
const toasts = [];
|
|
55
|
+
globalThis.location = {href: '', hash: ''};
|
|
56
|
+
globalThis.E = {toast: (m) => toasts.push(m)};
|
|
57
|
+
Object.defineProperty(globalThis, 'navigator', {value: {clipboard: {writeText: async (t) => { copied = t; }}}, configurable: true});
|
|
58
|
+
try {
|
|
59
|
+
const bcc = Array.from({length: 120}, (_, i) => `person${i}@example.test`);
|
|
60
|
+
assert.equal(await emailTo({bcc, subject: 'News'}), 'copied');
|
|
61
|
+
assert.equal(globalThis.location.href, '');
|
|
62
|
+
assert.equal(copied, bcc.join(', '));
|
|
63
|
+
assert.match(toasts[0], /120 addresses are copied.*Not carried over: the subject/);
|
|
64
|
+
} finally {
|
|
65
|
+
globalThis.location = saved.location;
|
|
66
|
+
globalThis.E = saved.E;
|
|
67
|
+
if (saved.nav) Object.defineProperty(globalThis, 'navigator', saved.nav); else delete globalThis.navigator;
|
|
68
|
+
}
|
|
69
|
+
});
|