domma-cms 1.28.3 → 1.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/admin/js/lib/contacts-arrange.js +1 -1
- package/docs/DommaFeatures.md +5 -3
- package/package.json +4 -1
- package/plugins/_lib/admin/mail/body-menu.js +2 -0
- package/plugins/_lib/admin/mail/cms-host.js +22 -0
- package/plugins/_lib/admin/mail/compose-window.js +1027 -1021
- package/plugins/_lib/admin/mail/contacts.js +10 -8
- package/plugins/_lib/admin/mail/diagnostics-section.js +2 -0
- package/plugins/_lib/admin/mail/drag-drop.js +46 -0
- package/plugins/_lib/admin/mail/folder-tree.js +2 -0
- package/plugins/_lib/admin/mail/font-controls.js +6 -4
- package/plugins/_lib/admin/mail/fonts.js +1 -1
- package/plugins/_lib/admin/mail/host-context.js +87 -0
- package/plugins/_lib/admin/mail/identity.js +2 -0
- package/plugins/_lib/admin/mail/image-senders-section.js +2 -0
- package/plugins/_lib/admin/mail/keyboard.js +2 -0
- package/plugins/_lib/admin/mail/mail.css +1 -1
- package/plugins/_lib/admin/mail/mail.html +4 -0
- package/plugins/_lib/admin/mail/message-actions.js +2 -0
- package/plugins/_lib/admin/mail/oauth-panel.js +2 -0
- package/plugins/_lib/admin/mail/panes.js +2 -0
- package/plugins/_lib/admin/mail/reader-kit.js +2 -0
- package/plugins/_lib/admin/mail/reader-runtime.js +6534 -0
- package/plugins/_lib/admin/mail/reader-view.js +9 -6380
- package/plugins/_lib/admin/mail/resizable.js +2 -0
- package/plugins/_lib/admin/mail/restore-spam.js +13 -0
- package/plugins/_lib/admin/mail/rules.js +14 -0
- package/plugins/_lib/admin/mail/scheduling.js +4 -1
- package/plugins/_lib/admin/mail/section-kit.js +4 -1
- package/plugins/_lib/admin/mail/security-note.js +2 -0
- package/plugins/_lib/admin/mail/settings-section.js +11 -10
- package/plugins/_lib/admin/mail/templates.js +5 -2
- package/plugins/_lib/admin/mail/threads.js +2 -0
- package/plugins/_lib/admin/mail/vacation.js +16 -2
- package/plugins/_lib/admin/mail/when-closed.js +24 -2
- package/plugins/_lib/admin/ui/dates.js +2 -0
- package/plugins/_lib/admin/ui/resizable.js +7 -5
- package/plugins/_lib/contacts/mailContact.js +69 -0
- package/plugins/_lib/contacts/model.js +199 -0
- package/plugins/_lib/domma-mail-contacts.lock.json +10 -0
- package/plugins/_lib/domma-mail.lock.json +85 -0
- package/plugins/_lib/games/plays.js +15 -3
- package/plugins/_lib/mail/accountFileStore.js +66 -0
- package/plugins/_lib/mail/accountRepository.js +617 -0
- package/plugins/_lib/mail/accountRoutes.js +130 -0
- package/plugins/_lib/mail/accounts.js +66 -940
- package/plugins/_lib/mail/automationLock.js +10 -0
- package/plugins/_lib/mail/bodyTokenProvider.js +36 -0
- package/plugins/_lib/mail/bodyTokens.js +5 -99
- package/plugins/_lib/mail/compose.js +5 -3
- package/plugins/_lib/mail/defaults.js +2 -0
- package/plugins/_lib/mail/envelope.js +3 -1
- package/plugins/_lib/mail/folderActions.js +83 -0
- package/plugins/_lib/mail/folderRuntime.js +109 -0
- package/plugins/_lib/mail/folders.js +4 -9
- package/plugins/_lib/mail/imapPool.js +11 -389
- package/plugins/_lib/mail/imapPoolRuntime.js +396 -0
- package/plugins/_lib/mail/mbox.js +2 -0
- package/plugins/_lib/mail/message-action.js +2 -0
- package/plugins/_lib/mail/messageSecurity.js +4 -111
- package/plugins/_lib/mail/messageSecurityProvider.js +116 -0
- package/plugins/_lib/mail/networkAddresses.js +77 -0
- package/plugins/_lib/mail/networkPolicy.js +62 -0
- package/plugins/_lib/mail/oauth.js +3 -451
- package/plugins/_lib/mail/oauthAccounts.js +178 -0
- package/plugins/_lib/mail/oauthRouteRuntime.js +282 -0
- package/plugins/_lib/mail/oauthRoutes.js +7 -289
- package/plugins/_lib/mail/oauthRuntime.js +456 -0
- package/plugins/_lib/mail/pollSchedule.js +2 -0
- package/plugins/_lib/mail/poller.js +4 -136
- package/plugins/_lib/mail/pollerRuntime.js +150 -0
- package/plugins/_lib/mail/priority.js +2 -0
- package/plugins/_lib/mail/publicMailbox.js +27 -0
- package/plugins/_lib/mail/readRoutes.js +14 -827
- package/plugins/_lib/mail/readRuntime.js +701 -0
- package/plugins/_lib/mail/render.js +2 -0
- package/plugins/_lib/mail/ruleRunner.js +27 -10
- package/plugins/_lib/mail/scheduler.js +11 -279
- package/plugins/_lib/mail/schedulerRuntime.js +259 -0
- package/plugins/_lib/mail/secretProvider.js +112 -0
- package/plugins/_lib/mail/secretbox.js +12 -225
- package/plugins/_lib/mail/send.js +21 -537
- package/plugins/_lib/mail/sieve.js +211 -0
- package/plugins/_lib/mail/sieveHost.js +24 -0
- package/plugins/_lib/mail/smtpService.js +553 -0
- package/plugins/_lib/mail/snoozeRuntime.js +60 -0
- package/plugins/_lib/mail/store.js +122 -64
- package/plugins/_lib/mail/subscriptions.js +11 -0
- package/plugins/_lib/mail/sync.js +64 -290
- package/plugins/_lib/mail/syncPlan.js +2 -0
- package/plugins/_lib/mail/syncRuntime.js +255 -0
- package/plugins/_lib/mail/syncSelection.js +2 -0
- package/plugins/_lib/mail/unreadBadge.js +2 -0
- package/plugins/_lib/mail/unsubscribe.js +2 -0
- package/plugins/_lib/mail/vacationRunner.js +3 -116
- package/plugins/_lib/mail/vacationRuntime.js +70 -0
- package/plugins/_lib/mail/write.js +44 -13
- package/server/routes/api/contacts.js +2 -196
|
@@ -1,393 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* connection per request would mean a TLS handshake and a LOGIN for every
|
|
7
|
-
* click, and most mail servers rate-limit that fairly aggressively.
|
|
8
|
-
*
|
|
9
|
-
* So connections are cached per user and reaped when idle. All mailbox access
|
|
10
|
-
* goes through `withMailbox()`, which takes ImapFlow's own mailbox lock, so
|
|
11
|
-
* two overlapping requests from the same user queue rather than corrupting
|
|
12
|
-
* each other's command stream.
|
|
13
|
-
*
|
|
14
|
-
* ## Read-only, twice over
|
|
15
|
-
*
|
|
16
|
-
* Every mailbox is opened `{readOnly: true}` and ImapFlow fetches with
|
|
17
|
-
* `BODY.PEEK[]` (see its commands/fetch.js). Either alone would stop the
|
|
18
|
-
* server setting `\Seen` as a side effect of reading a message; phase 1 has
|
|
19
|
-
* both, because a reader that silently marks a user's mail as read on their
|
|
20
|
-
* phone is worse than no reader at all. Do not relax this without making
|
|
21
|
-
* mark-as-read a deliberate, user-visible action.
|
|
22
|
-
*
|
|
23
|
-
* **Single-process only.** The pool is module state, exactly like the messages
|
|
24
|
-
* plugin's SSE registry. Running the site across workers would give each
|
|
25
|
-
* worker its own connections and blow through per-user connection limits.
|
|
26
|
-
*
|
|
27
|
-
* @module mail-reader/services/imapPool
|
|
28
|
-
*/
|
|
29
|
-
import {ImapFlow} from 'imapflow';
|
|
30
|
-
import {pinMailHost} from './hostGuard.js';
|
|
1
|
+
/** Shared IMAP runtime with this host's existing connection policy. */
|
|
2
|
+
import {getConfig} from '../../../server/config.js';
|
|
3
|
+
import * as hostGuard from './hostGuard.js';
|
|
4
|
+
import {createMailHostPolicy} from './networkPolicy.js';
|
|
5
|
+
import {createImapPool} from './imapPoolRuntime.js';
|
|
31
6
|
|
|
32
|
-
|
|
33
|
-
* Identify a connection's target. A change to any of these means the cached
|
|
34
|
-
* connection is for a different account and must be thrown away.
|
|
35
|
-
*
|
|
36
|
-
* @param {object} connection
|
|
37
|
-
* @returns {string}
|
|
38
|
-
*/
|
|
39
|
-
function fingerprint(connection) {
|
|
40
|
-
return [connection.host, connection.port, connection.secure, connection.auth.user].join('|');
|
|
41
|
-
}
|
|
7
|
+
export {describeError} from './imapPoolRuntime.js';
|
|
42
8
|
|
|
43
|
-
/**
|
|
44
|
-
* Create an IMAP connection pool.
|
|
45
|
-
*
|
|
46
|
-
* @param {{connectionIdleMs: number, maxConnections: number, connectionTimeoutMs: number, allowInsecureTLS: boolean}} config
|
|
47
|
-
* @returns {object} pool API
|
|
48
|
-
*/
|
|
49
9
|
export function createPool(config) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Build the ImapFlow options for a connection.
|
|
58
|
-
*
|
|
59
|
-
* @param {object} connection
|
|
60
|
-
* @returns {object}
|
|
61
|
-
*/
|
|
62
|
-
function clientOptions(connection) {
|
|
63
|
-
return {
|
|
64
|
-
host: connection.host,
|
|
65
|
-
port: connection.port,
|
|
66
|
-
secure: connection.secure,
|
|
67
|
-
auth: connection.auth,
|
|
68
|
-
logger: false,
|
|
69
|
-
// A dead mail server should fail the request, not hang the admin.
|
|
70
|
-
greetingTimeout: config.connectionTimeoutMs,
|
|
71
|
-
socketTimeout: config.connectionTimeoutMs,
|
|
72
|
-
connectionTimeout: config.connectionTimeoutMs,
|
|
73
|
-
tls: {rejectUnauthorized: !config.allowInsecureTLS}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Open and sign in one client, renewing an OAuth2 token on the way.
|
|
79
|
-
*
|
|
80
|
-
* A password connection is a single attempt, as it always was. A signed-in
|
|
81
|
-
* (OAuth2) one carries `refresh` from `toConnection()`: the stored token is
|
|
82
|
-
* taken (renewed first when under a minute is left), and renewed once more -
|
|
83
|
-
* forced - when the server refuses it anyway (revoked early, a clock out
|
|
84
|
-
* of step). Never more than once: a second refusal is the answer.
|
|
85
|
-
*
|
|
86
|
-
* @param {object} connection
|
|
87
|
-
* @param {(client: ImapFlow) => void} [prepare] - listeners to add before connect
|
|
88
|
-
* @returns {Promise<ImapFlow>}
|
|
89
|
-
*/
|
|
90
|
-
async function connectClient(connection, prepare = () => {}) {
|
|
91
|
-
let auth = connection.auth;
|
|
92
|
-
const canRenew = typeof connection.refresh === 'function';
|
|
93
|
-
if (canRenew) {
|
|
94
|
-
// Asked every time, not only near expiry: it reads the STORED
|
|
95
|
-
// sign-in (no network while the token is good), so a connection
|
|
96
|
-
// object built a while ago neither presents a token another
|
|
97
|
-
// request has since replaced, nor tries one already known dead.
|
|
98
|
-
const r = await connection.refresh(false);
|
|
99
|
-
auth = {user: auth.user, accessToken: r.accessToken};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Checked here, at every connect, and connected to the checked address
|
|
103
|
-
// (the name kept for TLS) - see hostGuard.js pinMailHost.
|
|
104
|
-
const pinned = await pinMailHost(connection.host, connection.port, {kind: 'imap', allowPrivate: config.allowPrivateMailHosts === true});
|
|
105
|
-
|
|
106
|
-
const attempt = async (withAuth) => {
|
|
107
|
-
const client = new ImapFlow({
|
|
108
|
-
...clientOptions({...connection, auth: withAuth}),
|
|
109
|
-
host: pinned.address,
|
|
110
|
-
...(pinned.servername && {servername: pinned.servername})
|
|
111
|
-
});
|
|
112
|
-
prepare(client);
|
|
113
|
-
try {
|
|
114
|
-
await client.connect();
|
|
115
|
-
return client;
|
|
116
|
-
} catch (err) {
|
|
117
|
-
try { client.close(); } catch { /* already down */ }
|
|
118
|
-
throw err;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
try {
|
|
123
|
-
return await attempt(auth);
|
|
124
|
-
} catch (err) {
|
|
125
|
-
if (!canRenew || !err?.authenticationFailed) throw err;
|
|
126
|
-
const r = await connection.refresh(true);
|
|
127
|
-
return attempt({user: auth.user, accessToken: r.accessToken});
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Drop a pooled connection, closing it best-effort.
|
|
133
|
-
*
|
|
134
|
-
* @param {string} userId
|
|
135
|
-
* @returns {void}
|
|
136
|
-
*/
|
|
137
|
-
function evict(userId) {
|
|
138
|
-
const entry = pool.get(userId);
|
|
139
|
-
if (!entry) return;
|
|
140
|
-
pool.delete(userId);
|
|
141
|
-
entry.client.logout().catch(() => entry.client.close());
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Get a live, authenticated client for a user.
|
|
146
|
-
*
|
|
147
|
-
* @param {string} userId
|
|
148
|
-
* @param {object} connection
|
|
149
|
-
* @returns {Promise<ImapFlow>}
|
|
150
|
-
*/
|
|
151
|
-
async function acquire(userId, connection) {
|
|
152
|
-
const fp = fingerprint(connection);
|
|
153
|
-
const existing = pool.get(userId);
|
|
154
|
-
|
|
155
|
-
if (existing && existing.fingerprint === fp && existing.client.usable) {
|
|
156
|
-
existing.lastUsed = Date.now();
|
|
157
|
-
return existing.client;
|
|
158
|
-
}
|
|
159
|
-
// Stale, or the account details changed under it.
|
|
160
|
-
if (existing) evict(userId);
|
|
161
|
-
|
|
162
|
-
const inFlight = pending.get(userId);
|
|
163
|
-
if (inFlight) return inFlight;
|
|
164
|
-
|
|
165
|
-
if (pool.size >= config.maxConnections) {
|
|
166
|
-
// Evict the least recently used rather than refusing the request -
|
|
167
|
-
// the cap exists to bound resource use, not to lock people out.
|
|
168
|
-
const oldest = [...pool.entries()].sort((a, b) => a[1].lastUsed - b[1].lastUsed)[0];
|
|
169
|
-
if (oldest) evict(oldest[0]);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const connect = (async () => {
|
|
173
|
-
const client = await connectClient(connection, (c) => {
|
|
174
|
-
// ImapFlow emits 'error' on an already-failed connection; without a
|
|
175
|
-
// listener that becomes an unhandled event and takes the process out.
|
|
176
|
-
c.on('error', () => evict(userId));
|
|
177
|
-
c.on('close', () => {
|
|
178
|
-
if (pool.get(userId)?.client === c) pool.delete(userId);
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
pool.set(userId, {client, fingerprint: fp, lastUsed: Date.now()});
|
|
182
|
-
return client;
|
|
183
|
-
})();
|
|
184
|
-
|
|
185
|
-
pending.set(userId, connect);
|
|
186
|
-
try {
|
|
187
|
-
return await connect;
|
|
188
|
-
} finally {
|
|
189
|
-
pending.delete(userId);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Run a function against a user's connection, no mailbox selected.
|
|
195
|
-
*
|
|
196
|
-
* @param {string} userId
|
|
197
|
-
* @param {object} connection
|
|
198
|
-
* @param {(client: ImapFlow) => Promise<any>} fn
|
|
199
|
-
* @returns {Promise<any>}
|
|
200
|
-
*/
|
|
201
|
-
async function withClient(userId, connection, fn) {
|
|
202
|
-
const client = await acquire(userId, connection);
|
|
203
|
-
try {
|
|
204
|
-
const result = await fn(client);
|
|
205
|
-
const entry = pool.get(userId);
|
|
206
|
-
if (entry) entry.lastUsed = Date.now();
|
|
207
|
-
return result;
|
|
208
|
-
} catch (err) {
|
|
209
|
-
evict(userId);
|
|
210
|
-
throw err;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Run a function with a mailbox open and locked.
|
|
216
|
-
*
|
|
217
|
-
* Read-only unless asked otherwise, and the asking is deliberate: the free
|
|
218
|
-
* reader's entire guarantee is that looking at mail never changes it, and
|
|
219
|
-
* a default of read-write would quietly break that the first time a shared
|
|
220
|
-
* helper forgot the option. Only the Pro edition's write operations pass
|
|
221
|
-
* `writable`, and only for the one call that needs it.
|
|
222
|
-
*
|
|
223
|
-
* @param {string} userId
|
|
224
|
-
* @param {object} connection
|
|
225
|
-
* @param {string} mailbox
|
|
226
|
-
* @param {(client: ImapFlow, mailbox: object) => Promise<any>} fn
|
|
227
|
-
* @param {{writable?: boolean}} [options]
|
|
228
|
-
* @returns {Promise<any>}
|
|
229
|
-
*/
|
|
230
|
-
async function withMailbox(userId, connection, mailbox, fn, {writable = false} = {}) {
|
|
231
|
-
return withClient(userId, connection, async (client) => {
|
|
232
|
-
const lock = await client.getMailboxLock(mailbox, {readOnly: !writable});
|
|
233
|
-
try {
|
|
234
|
-
return await fn(client, client.mailbox);
|
|
235
|
-
} finally {
|
|
236
|
-
lock.release();
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* One-shot connect used by the "Test connection" button.
|
|
243
|
-
*
|
|
244
|
-
* Deliberately not pooled: it runs against details that have not been
|
|
245
|
-
* saved yet, and a failed attempt should leave nothing behind.
|
|
246
|
-
*
|
|
247
|
-
* @param {object} connection
|
|
248
|
-
* @returns {Promise<{ok: true, greeting: string|null} | {ok: false, error: string}>}
|
|
249
|
-
*/
|
|
250
|
-
async function test(connection) {
|
|
251
|
-
let client = null;
|
|
252
|
-
try {
|
|
253
|
-
client = await connectClient(connection, c => c.on('error', () => {}));
|
|
254
|
-
const greeting = client.serverInfo?.greeting ?? null;
|
|
255
|
-
await client.logout();
|
|
256
|
-
return {ok: true, greeting};
|
|
257
|
-
} catch (err) {
|
|
258
|
-
try {
|
|
259
|
-
client?.close();
|
|
260
|
-
} catch {
|
|
261
|
-
// Already down - nothing to close.
|
|
262
|
-
}
|
|
263
|
-
return {ok: false, error: err?.needsReconnect ? err.message : describeError(err, connection)};
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Close a specific user's connection - used when their account changes or
|
|
269
|
-
* is deleted, so the next request does not reuse the old credentials.
|
|
270
|
-
*
|
|
271
|
-
* @param {string} userId
|
|
272
|
-
* @returns {void}
|
|
273
|
-
*/
|
|
274
|
-
function release(userId) {
|
|
275
|
-
evict(userId);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Close every connection a user holds, whatever mailbox it belongs to.
|
|
280
|
-
*
|
|
281
|
-
* Keys are `userId:accountId`, so this is a prefix sweep. Used when a user
|
|
282
|
-
* is deleted - their sockets should not outlive their account either.
|
|
283
|
-
*
|
|
284
|
-
* @param {string} userId
|
|
285
|
-
* @returns {void}
|
|
286
|
-
*/
|
|
287
|
-
function releaseUser(userId) {
|
|
288
|
-
const prefix = `${userId}:`;
|
|
289
|
-
for (const key of [...pool.keys()]) {
|
|
290
|
-
if (key === userId || key.startsWith(prefix)) evict(key);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Close everything. Called on plugin disable and server shutdown.
|
|
296
|
-
*
|
|
297
|
-
* @returns {void}
|
|
298
|
-
*/
|
|
299
|
-
function closeAll() {
|
|
300
|
-
for (const userId of [...pool.keys()]) evict(userId);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const reaper = setInterval(() => {
|
|
304
|
-
const cutoff = Date.now() - config.connectionIdleMs;
|
|
305
|
-
for (const [userId, entry] of pool) {
|
|
306
|
-
if (entry.lastUsed < cutoff) evict(userId);
|
|
307
|
-
}
|
|
308
|
-
}, Math.max(30_000, Math.floor(config.connectionIdleMs / 2)));
|
|
309
|
-
// Never hold the process open on account of an idle mail connection.
|
|
310
|
-
reaper.unref?.();
|
|
311
|
-
|
|
312
|
-
return {withClient, withMailbox, test, release, releaseUser, closeAll, connectClient,
|
|
313
|
-
// What send.js passes to hostGuard.js pinMailHost for this plugin's outgoing servers.
|
|
314
|
-
mailHostOptions: {allowPrivate: config.allowPrivateMailHosts === true},
|
|
315
|
-
get size() {
|
|
316
|
-
return pool.size;
|
|
317
|
-
}};
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Turn an IMAP/SMTP/network error into something worth showing a user.
|
|
322
|
-
*
|
|
323
|
-
* ImapFlow's own messages are decent but its auth failures surface as raw
|
|
324
|
-
* server responses, which vary by server and read like a stack trace. TLS
|
|
325
|
-
* failures are worse: OpenSSL's text ("…:tls_validate_record_header:wrong
|
|
326
|
-
* version number:…") names nothing the user can change. nodemailer also wraps
|
|
327
|
-
* every socket error as `ESOCKET`, dropping the TLS code, so those are
|
|
328
|
-
* recognised by `reason`/message as well as by code.
|
|
329
|
-
*
|
|
330
|
-
* @param {Error & {code?: string, reason?: string, authenticationFailed?: boolean}} err
|
|
331
|
-
* @param {{host?: string, port?: number, secure?: boolean}} [connection] - what was tried, so the message can name it
|
|
332
|
-
* @returns {string}
|
|
333
|
-
*/
|
|
334
|
-
export function describeError(err, connection = {}) {
|
|
335
|
-
if (!err) return 'Unknown error.';
|
|
336
|
-
if (err.needsReconnect || err.mailHostRefused) return err.message;
|
|
337
|
-
// A signed-in (OAuth2) mailbox has no password to blame.
|
|
338
|
-
if ((err.authenticationFailed || err.code === 'EAUTH' || err.code === 'EOAUTH2') && (connection.auth?.accessToken !== undefined || connection.auth?.type === 'OAuth2')) {
|
|
339
|
-
return 'The mail server refused the sign-in. If it keeps happening, Reconnect the mailbox.';
|
|
340
|
-
}
|
|
341
|
-
if (err.authenticationFailed || err.code === 'EAUTH') return 'The mail server rejected that username and password.';
|
|
342
|
-
|
|
343
|
-
const host = connection.host || 'The mail server';
|
|
344
|
-
const port = connection.port ? `Port ${connection.port}` : 'That port';
|
|
345
|
-
const text = `${err.reason || ''} ${err.message || ''}`;
|
|
346
|
-
|
|
347
|
-
// Implicit TLS against a port that starts in plain text (587, 143, 25):
|
|
348
|
-
// the "server hello" is a greeting line, which OpenSSL reads as a bad version.
|
|
349
|
-
if (err.code === 'ERR_SSL_WRONG_VERSION_NUMBER' || /wrong version number/i.test(text)) {
|
|
350
|
-
return connection.secure
|
|
351
|
-
? `${port} does not start with TLS, so Implicit TLS must be off for it - ports 587 and 143 switch to TLS with STARTTLS. Untick Implicit TLS, or use the implicit-TLS port (465 to send, 993 to read).`
|
|
352
|
-
: `${port} answered in a different TLS mode from the one chosen. Check the port and the Implicit TLS setting.`;
|
|
353
|
-
}
|
|
354
|
-
if (['DEPTH_ZERO_SELF_SIGNED_CERT', 'SELF_SIGNED_CERT_IN_CHAIN'].includes(err.code) || /self[- ]signed certificate/i.test(text)) {
|
|
355
|
-
return `${host === 'The mail server' ? 'The mail server’s' : `${host}’s`} TLS certificate is self-signed, so the server cannot prove who it is. `
|
|
356
|
-
+ `Install a trusted certificate (Let’s Encrypt, for example) that covers this hostname on the mail server. `
|
|
357
|
-
+ `For a server you control, the plugin’s allowInsecureTLS setting accepts it instead.`;
|
|
358
|
-
}
|
|
359
|
-
if (err.code === 'ERR_TLS_CERT_ALTNAME_INVALID' || /altnames|does not match certificate/i.test(text)) {
|
|
360
|
-
return `The mail server’s TLS certificate does not cover ${connection.host || 'that hostname'}. Use the hostname the certificate was issued for, or reissue it to include this one.`;
|
|
361
|
-
}
|
|
362
|
-
if (err.code === 'CERT_HAS_EXPIRED' || /certificate has expired/i.test(text)) {
|
|
363
|
-
return 'The mail server’s TLS certificate has expired. It needs renewing on the server.';
|
|
364
|
-
}
|
|
365
|
-
if (['UNABLE_TO_VERIFY_LEAF_SIGNATURE', 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY'].includes(err.code) || /unable to (verify the first certificate|get local issuer)/i.test(text)) {
|
|
366
|
-
return 'The mail server’s TLS certificate could not be verified - it is missing its intermediate certificate, or was issued by an authority this server does not trust.';
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
// nodemailer reports these as ESOCKET/EDNS; the system code survives only in the message.
|
|
370
|
-
const netCode = text.match(/\b(ENOTFOUND|EAI_AGAIN|ECONNREFUSED|ETIMEDOUT|ECONNRESET)\b/)?.[1] ?? err.code;
|
|
371
|
-
switch (netCode) {
|
|
372
|
-
case 'ENOTFOUND':
|
|
373
|
-
case 'EAI_AGAIN':
|
|
374
|
-
return 'That mail server hostname could not be resolved.';
|
|
375
|
-
case 'ECONNREFUSED':
|
|
376
|
-
return 'The mail server refused the connection on that port.';
|
|
377
|
-
case 'ETIMEDOUT':
|
|
378
|
-
case 'ECONNRESET':
|
|
379
|
-
return 'The mail server did not respond in time.';
|
|
380
|
-
default:
|
|
381
|
-
// Words that are ours, or a mail server's answer to a command after
|
|
382
|
-
// it greeted and (for IMAP) signed us in - those say nothing about
|
|
383
|
-
// what else listens on a host and port.
|
|
384
|
-
if (err.name === 'MailKeyError' || err.responseStatus === 'NO' || err.responseStatus === 'BAD'
|
|
385
|
-
|| err.code === 'EENVELOPE' || err.code === 'EMESSAGE') {
|
|
386
|
-
return err.message || 'The mail server connection failed.';
|
|
387
|
-
}
|
|
388
|
-
// Anything else stays out of the browser: a greeting, a banner or a
|
|
389
|
-
// socket error is exactly what a port scan reads. The log has it.
|
|
390
|
-
console.warn(`[mail] connection to ${connection.host || 'the mail server'}:${connection.port || '?'} failed${err.code ? ` (${err.code})` : ''}: ${err.message || err}`);
|
|
391
|
-
return 'The mail server connection failed. Check the server settings.';
|
|
392
|
-
}
|
|
10
|
+
const policy = createMailHostPolicy({getPolicy: () => ({
|
|
11
|
+
allowPrivate: config.allowPrivateMailHosts === true,
|
|
12
|
+
ownSmtpHost: hostGuard.siteSmtpHost(getConfig)
|
|
13
|
+
})});
|
|
14
|
+
return createImapPool(config, {pinMailHost: hostGuard.pinMailHost ?? policy.pinMailHost});
|
|
393
15
|
}
|