emailengine-app 2.86.0 → 2.87.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/.ncurc.js +2 -4
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +42 -0
- package/DOCKER_DEPLOYMENT.md +2 -1
- package/Dockerfile +5 -6
- package/README.md +4 -0
- package/bin/emailengine.js +2 -4
- package/bin/healthcheck.js +20 -0
- package/data/google-crawlers.json +1 -1
- package/data/public_suffix_list.dat +3 -7
- package/lib/account/auth-failure-backfill.js +3 -2
- package/lib/account/expected-identity.js +2 -2
- package/lib/account.js +101 -39
- package/lib/api-listener.js +40 -0
- package/lib/api-routes/account-routes.js +14 -7
- package/lib/api-routes/submit-routes.js +21 -2
- package/lib/api-token-auth.js +406 -0
- package/lib/autodetect-imap-settings.js +36 -3
- package/lib/consts.js +5 -0
- package/lib/email-client/base-client.js +27 -109
- package/lib/email-client/gmail-client.js +15 -4
- package/lib/email-client/imap/mailbox.js +97 -97
- package/lib/email-client/imap/sync-operations.js +13 -6
- package/lib/email-client/imap-client.js +28 -7
- package/lib/email-client/new-message-steps.js +162 -0
- package/lib/email-client/outlook-client.js +10 -2
- package/lib/env-setting-overrides.js +6 -2
- package/lib/export-worker.js +3 -2
- package/lib/export.js +43 -4
- package/lib/field-usage.js +1 -1
- package/lib/get-boolean.js +38 -0
- package/lib/get-raw-email.js +10 -1
- package/lib/health-probe.js +71 -0
- package/lib/imapproxy/imap-server.js +4 -55
- package/lib/net-tos-guard.js +42 -0
- package/lib/oauth/gmail.js +54 -29
- package/lib/oauth2-apps.js +2 -1
- package/lib/otp.js +66 -0
- package/lib/read-env-value.js +19 -7
- package/lib/redis-keys.js +19 -0
- package/lib/redis-operations.js +7 -3
- package/lib/schemas.js +62 -2
- package/lib/security-headers.js +18 -0
- package/lib/session-default.js +50 -0
- package/lib/settings.js +2 -1
- package/lib/stream-encrypt.js +71 -20
- package/lib/sub-script.js +8 -2
- package/lib/submit-lock.js +84 -0
- package/lib/submit-processor.js +283 -0
- package/lib/swagger-options.js +2 -2
- package/lib/templates.js +6 -3
- package/lib/tls/context.js +2 -16
- package/lib/tools.js +8 -30
- package/lib/utils/redis-errors.js +44 -0
- package/lib/webhook-delivery.js +3 -4
- package/lib/webhooks.js +5 -0
- package/lib/worker-rpc-error.js +10 -5
- package/lib/worker-rpc.js +138 -0
- package/package.json +25 -26
- package/sbom.json +660 -1736
- package/server.js +6 -5
- package/static/css/flyonui.css +2 -2
- package/static/js/ee-client.js +650 -196
- package/static/licenses.html +280 -1393
- package/translations/messages.pot +16 -16
- package/views/layout/app.hbs +9 -6
- package/views/legal.hbs +8 -0
- package/workers/api.js +51 -474
- package/workers/export.js +14 -55
- package/workers/imap-proxy.js +5 -18
- package/workers/imap.js +27 -49
- package/workers/smtp.js +7 -69
- package/workers/submit.js +21 -279
- package/workers/webhooks.js +7 -72
package/workers/export.js
CHANGED
|
@@ -6,7 +6,7 @@ const packageData = require('../package.json');
|
|
|
6
6
|
const config = require('@zone-eu/wild-config');
|
|
7
7
|
const logger = require('../lib/logger');
|
|
8
8
|
|
|
9
|
-
const { REDIS_PREFIX, EXPORT_COMPLETED_NOTIFY, EXPORT_FAILED_NOTIFY } = require('../lib/consts');
|
|
9
|
+
const { REDIS_PREFIX, EXPORT_COMPLETED_NOTIFY, EXPORT_FAILED_NOTIFY, EXPORT_LOCK_DURATION, EXPORT_STALLED_INTERVAL } = require('../lib/consts');
|
|
10
10
|
const { getDuration, readEnvValue, threadStats } = require('../lib/tools');
|
|
11
11
|
const { webhooks: Webhooks } = require('../lib/webhooks');
|
|
12
12
|
const settings = require('../lib/settings');
|
|
@@ -35,41 +35,9 @@ const EXPORT_TIMEOUT = getDuration(readEnvValue('EENGINE_EXPORT_TIMEOUT')) || DE
|
|
|
35
35
|
|
|
36
36
|
const EXPORT_QC = (readEnvValue('EENGINE_EXPORT_QC') && Number(readEnvValue('EENGINE_EXPORT_QC'))) || config.queues.export || 1;
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
async function call(message, transferList) {
|
|
42
|
-
return new Promise((resolve, reject) => {
|
|
43
|
-
let mid = `${Date.now()}:${++mids}`;
|
|
44
|
-
|
|
45
|
-
let ttl = Math.max(message.timeout || 0, EENGINE_TIMEOUT || 0);
|
|
46
|
-
let timer = setTimeout(() => {
|
|
47
|
-
callQueue.delete(mid);
|
|
48
|
-
let err = new Error('Timeout waiting for command response [T6]');
|
|
49
|
-
err.statusCode = 504;
|
|
50
|
-
err.code = 'Timeout';
|
|
51
|
-
err.ttl = ttl;
|
|
52
|
-
reject(err);
|
|
53
|
-
}, ttl);
|
|
54
|
-
|
|
55
|
-
callQueue.set(mid, { resolve, reject, timer });
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
parentPort.postMessage(
|
|
59
|
-
{
|
|
60
|
-
cmd: 'call',
|
|
61
|
-
mid,
|
|
62
|
-
message
|
|
63
|
-
},
|
|
64
|
-
transferList
|
|
65
|
-
);
|
|
66
|
-
} catch (err) {
|
|
67
|
-
clearTimeout(timer);
|
|
68
|
-
callQueue.delete(mid);
|
|
69
|
-
return reject(err);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|
|
38
|
+
const { createRpcClient, respond, isCall } = require('../lib/worker-rpc');
|
|
39
|
+
const rpc = createRpcClient({ port: parentPort, defaultTimeout: EENGINE_TIMEOUT, timeoutTag: 'T6' });
|
|
40
|
+
const call = rpc.call;
|
|
73
41
|
|
|
74
42
|
async function metrics(logger, key, method, ...args) {
|
|
75
43
|
try {
|
|
@@ -199,8 +167,12 @@ const exportWorker = new Worker(
|
|
|
199
167
|
},
|
|
200
168
|
{
|
|
201
169
|
concurrency: EXPORT_QC,
|
|
202
|
-
lockDuration
|
|
203
|
-
|
|
170
|
+
// BullMQ renews the lock every lockDuration / 2 while the job runs. The lock is also what
|
|
171
|
+
// keeps a sibling worker's startup recovery off a running export (removeAbandonedJob() in
|
|
172
|
+
// lib/export.js), and how long an export of a worker that died waits before the stalled
|
|
173
|
+
// check runs it again, so it is kept short: about three minutes from a crash to a restart
|
|
174
|
+
lockDuration: EXPORT_LOCK_DURATION,
|
|
175
|
+
stalledInterval: EXPORT_STALLED_INTERVAL,
|
|
204
176
|
maxStalledCount: 5,
|
|
205
177
|
// Do not start consuming jobs at construction. Startup recovery (markInterruptedAsFailed +
|
|
206
178
|
// cleanup) must finish first, otherwise the worker can pick up a queued export and start
|
|
@@ -335,25 +307,12 @@ async function onCommand(command) {
|
|
|
335
307
|
})();
|
|
336
308
|
|
|
337
309
|
parentPort.on('message', message => {
|
|
338
|
-
if (
|
|
339
|
-
|
|
340
|
-
clearTimeout(timer);
|
|
341
|
-
callQueue.delete(message.mid);
|
|
342
|
-
|
|
343
|
-
if (message.error) {
|
|
344
|
-
const err = new Error(message.error);
|
|
345
|
-
if (message.code) err.code = message.code;
|
|
346
|
-
if (message.statusCode) err.statusCode = message.statusCode;
|
|
347
|
-
if (message.info) err.info = message.info;
|
|
348
|
-
return reject(err);
|
|
349
|
-
}
|
|
350
|
-
return resolve(message.response);
|
|
310
|
+
if (rpc.handleResponse(message)) {
|
|
311
|
+
return;
|
|
351
312
|
}
|
|
352
313
|
|
|
353
|
-
if (message
|
|
354
|
-
|
|
355
|
-
.then(response => parentPort.postMessage({ cmd: 'resp', mid: message.mid, response }))
|
|
356
|
-
.catch(err => parentPort.postMessage({ cmd: 'resp', mid: message.mid, error: err.message, code: err.code, statusCode: err.statusCode }));
|
|
314
|
+
if (isCall(message)) {
|
|
315
|
+
return respond(parentPort, message, onCommand, { logger });
|
|
357
316
|
}
|
|
358
317
|
});
|
|
359
318
|
|
package/workers/imap-proxy.js
CHANGED
|
@@ -8,6 +8,7 @@ const logger = require('../lib/logger');
|
|
|
8
8
|
const { threadStats } = require('../lib/tools');
|
|
9
9
|
|
|
10
10
|
const { run, reloadCertificates } = require('../lib/imapproxy/imap-server');
|
|
11
|
+
const { respond, isCall } = require('../lib/worker-rpc');
|
|
11
12
|
|
|
12
13
|
const { initSentry } = require('../lib/sentry');
|
|
13
14
|
initSentry('imapProxy');
|
|
@@ -37,25 +38,11 @@ setInterval(() => {
|
|
|
37
38
|
// Send initial ready signal
|
|
38
39
|
parentPort.postMessage({ cmd: 'ready' });
|
|
39
40
|
|
|
41
|
+
// Responses to this worker's own calls are settled by lib/imapproxy/imap-server.js, which owns the
|
|
42
|
+
// calling half
|
|
40
43
|
parentPort.on('message', message => {
|
|
41
|
-
if (message
|
|
42
|
-
return
|
|
43
|
-
.then(response => {
|
|
44
|
-
parentPort.postMessage({
|
|
45
|
-
cmd: 'resp',
|
|
46
|
-
mid: message.mid,
|
|
47
|
-
response
|
|
48
|
-
});
|
|
49
|
-
})
|
|
50
|
-
.catch(err => {
|
|
51
|
-
parentPort.postMessage({
|
|
52
|
-
cmd: 'resp',
|
|
53
|
-
mid: message.mid,
|
|
54
|
-
error: err.message,
|
|
55
|
-
code: err.code,
|
|
56
|
-
statusCode: err.statusCode
|
|
57
|
-
});
|
|
58
|
-
});
|
|
44
|
+
if (isCall(message)) {
|
|
45
|
+
return respond(parentPort, message, onCommand, { logger });
|
|
59
46
|
}
|
|
60
47
|
});
|
|
61
48
|
|
package/workers/imap.js
CHANGED
|
@@ -20,12 +20,15 @@ const { Account } = require('../lib/account');
|
|
|
20
20
|
const { oauth2Apps, isApiBasedApp } = require('../lib/oauth2-apps');
|
|
21
21
|
const { redis, notifyQueue, submitQueue, watchRedisReconnect } = require('../lib/db');
|
|
22
22
|
const { sendToMessagePort, MessagePortWritable } = require('../lib/message-port-stream');
|
|
23
|
-
const {
|
|
23
|
+
const { describeRpcCommand } = require('../lib/worker-rpc-error');
|
|
24
|
+
const { createRpcClient, respond, isCall } = require('../lib/worker-rpc');
|
|
24
25
|
const { ImapFlowErrorCode } = require('imapflow');
|
|
25
26
|
const settings = require('../lib/settings');
|
|
26
27
|
const msgpack = require('../lib/msgpack');
|
|
27
28
|
|
|
28
29
|
const getSecret = require('../lib/get-secret');
|
|
30
|
+
const { getSharedLock } = require('../lib/lock-run');
|
|
31
|
+
const { sendQueuedOnce } = require('../lib/submit-lock');
|
|
29
32
|
|
|
30
33
|
config.service = config.service || {};
|
|
31
34
|
|
|
@@ -56,8 +59,7 @@ NO_ACTIVE_HANDLER_RESP_ERR.code = 'WorkerNotAvailable';
|
|
|
56
59
|
|
|
57
60
|
class ConnectionHandler {
|
|
58
61
|
constructor() {
|
|
59
|
-
this.
|
|
60
|
-
this.mids = 0;
|
|
62
|
+
this.rpc = createRpcClient({ port: parentPort, defaultTimeout: EENGINE_TIMEOUT, timeoutTag: 'T3' });
|
|
61
63
|
|
|
62
64
|
this.accounts = new Map();
|
|
63
65
|
|
|
@@ -727,7 +729,16 @@ class ConnectionHandler {
|
|
|
727
729
|
throw NO_ACTIVE_HANDLER_RESP_ERR;
|
|
728
730
|
}
|
|
729
731
|
|
|
730
|
-
|
|
732
|
+
// A queued message is sent under a lock, so a retry never runs next to a send still in
|
|
733
|
+
// progress (lib/submit-lock.js)
|
|
734
|
+
return await sendQueuedOnce({
|
|
735
|
+
lock: getSharedLock(),
|
|
736
|
+
redis,
|
|
737
|
+
logger,
|
|
738
|
+
account: message.account,
|
|
739
|
+
queueId: message.data && message.data.queueId,
|
|
740
|
+
send: () => accountData.connection.submitMessage(message.data)
|
|
741
|
+
});
|
|
731
742
|
}
|
|
732
743
|
|
|
733
744
|
async queueMessage(message) {
|
|
@@ -1090,27 +1101,8 @@ class ConnectionHandler {
|
|
|
1090
1101
|
}
|
|
1091
1102
|
}
|
|
1092
1103
|
|
|
1093
|
-
|
|
1094
|
-
return
|
|
1095
|
-
let mid = `${Date.now()}:${++this.mids}`;
|
|
1096
|
-
|
|
1097
|
-
let ttl = Math.max(message.timeout || 0, EENGINE_TIMEOUT || 0);
|
|
1098
|
-
let timer = setTimeout(() => {
|
|
1099
|
-
let err = new Error('Timeout waiting for command response [T3]');
|
|
1100
|
-
err.statusCode = 504;
|
|
1101
|
-
err.code = 'Timeout';
|
|
1102
|
-
err.ttl = ttl;
|
|
1103
|
-
this.callQueue.delete(mid);
|
|
1104
|
-
reject(err);
|
|
1105
|
-
}, ttl);
|
|
1106
|
-
|
|
1107
|
-
this.callQueue.set(mid, { resolve, reject, timer });
|
|
1108
|
-
parentPort.postMessage({
|
|
1109
|
-
cmd: 'call',
|
|
1110
|
-
mid,
|
|
1111
|
-
message
|
|
1112
|
-
});
|
|
1113
|
-
});
|
|
1104
|
+
call(message) {
|
|
1105
|
+
return this.rpc.call(message);
|
|
1114
1106
|
}
|
|
1115
1107
|
|
|
1116
1108
|
metrics(key, method, ...args) {
|
|
@@ -1134,42 +1126,28 @@ async function main() {
|
|
|
1134
1126
|
}
|
|
1135
1127
|
|
|
1136
1128
|
parentPort.on('message', message => {
|
|
1137
|
-
if (
|
|
1138
|
-
|
|
1139
|
-
clearTimeout(timer);
|
|
1140
|
-
connectionHandler.callQueue.delete(message.mid);
|
|
1141
|
-
if (message.error) {
|
|
1142
|
-
return reject(unpackRpcError(message));
|
|
1143
|
-
} else {
|
|
1144
|
-
return resolve(message.response);
|
|
1145
|
-
}
|
|
1129
|
+
if (connectionHandler.rpc.handleResponse(message)) {
|
|
1130
|
+
return;
|
|
1146
1131
|
}
|
|
1147
1132
|
|
|
1148
|
-
if (message
|
|
1149
|
-
return connectionHandler
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
parentPort.postMessage({
|
|
1153
|
-
cmd: 'resp',
|
|
1154
|
-
mid: message.mid,
|
|
1155
|
-
response
|
|
1156
|
-
});
|
|
1157
|
-
})
|
|
1158
|
-
.catch(err => {
|
|
1133
|
+
if (isCall(message)) {
|
|
1134
|
+
return respond(parentPort, message, command => connectionHandler.onCommand(command), {
|
|
1135
|
+
logger,
|
|
1136
|
+
onError(err) {
|
|
1159
1137
|
// Anything with a client-facing status (404 not found, 503 no active handler) is
|
|
1160
1138
|
// reported back to the caller as the command response, so it is not a server fault.
|
|
1161
1139
|
// 503 is excluded from the error branch on purpose: both "no active handler" and
|
|
1162
1140
|
// IMAPConnectionClosing carry it, and a worker taking over accounts answers every
|
|
1163
1141
|
// in-flight command with one until the reassignment settles.
|
|
1164
|
-
if (err.code === ImapFlowErrorCode.ETHROTTLE && !err.statusCode) {
|
|
1142
|
+
if (err && err.code === ImapFlowErrorCode.ETHROTTLE && !err.statusCode) {
|
|
1165
1143
|
// ImapFlow gave up after the server throttled every retry: the caller should
|
|
1166
1144
|
// back off, the same answer a throttled Gmail or Graph request gets
|
|
1167
1145
|
err.statusCode = 429;
|
|
1168
1146
|
}
|
|
1169
|
-
let isServerFault = !err.statusCode || (err.statusCode >= 500 && err.statusCode !== 503);
|
|
1147
|
+
let isServerFault = !err || !err.statusCode || (err.statusCode >= 500 && err.statusCode !== 503);
|
|
1170
1148
|
logger[isServerFault ? 'error' : 'debug'](Object.assign(describeRpcCommand(message), { msg: 'Command failed', err }));
|
|
1171
|
-
|
|
1172
|
-
|
|
1149
|
+
}
|
|
1150
|
+
});
|
|
1173
1151
|
}
|
|
1174
1152
|
|
|
1175
1153
|
connectionHandler.onMessage(message).catch(err => logger.error({ msg: 'Failed to process IPC message', err }));
|
package/workers/smtp.js
CHANGED
|
@@ -55,41 +55,9 @@ const ACCOUNT_CACHE = new WeakMap();
|
|
|
55
55
|
let smtpServer = null;
|
|
56
56
|
let tlsContext = null;
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
async function call(message, transferList) {
|
|
62
|
-
return new Promise((resolve, reject) => {
|
|
63
|
-
let mid = `${Date.now()}:${++mids}`;
|
|
64
|
-
|
|
65
|
-
let ttl = Math.max(message.timeout || 0, EENGINE_TIMEOUT || 0);
|
|
66
|
-
let timer = setTimeout(() => {
|
|
67
|
-
let err = new Error('Timeout waiting for command response [T4]');
|
|
68
|
-
err.statusCode = 504;
|
|
69
|
-
err.code = 'Timeout';
|
|
70
|
-
err.ttl = ttl;
|
|
71
|
-
callQueue.delete(mid);
|
|
72
|
-
reject(err);
|
|
73
|
-
}, ttl);
|
|
74
|
-
|
|
75
|
-
callQueue.set(mid, { resolve, reject, timer });
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
parentPort.postMessage(
|
|
79
|
-
{
|
|
80
|
-
cmd: 'call',
|
|
81
|
-
mid,
|
|
82
|
-
message
|
|
83
|
-
},
|
|
84
|
-
transferList
|
|
85
|
-
);
|
|
86
|
-
} catch (err) {
|
|
87
|
-
clearTimeout(timer);
|
|
88
|
-
callQueue.delete(mid);
|
|
89
|
-
return reject(err);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
58
|
+
const { createRpcClient, respond, isCall } = require('../lib/worker-rpc');
|
|
59
|
+
const rpc = createRpcClient({ port: parentPort, defaultTimeout: EENGINE_TIMEOUT, timeoutTag: 'T4' });
|
|
60
|
+
const call = rpc.call;
|
|
93
61
|
|
|
94
62
|
async function metrics(logger, key, method, ...args) {
|
|
95
63
|
try {
|
|
@@ -358,42 +326,12 @@ setInterval(() => {
|
|
|
358
326
|
parentPort.postMessage({ cmd: 'ready' });
|
|
359
327
|
|
|
360
328
|
parentPort.on('message', message => {
|
|
361
|
-
if (
|
|
362
|
-
|
|
363
|
-
clearTimeout(timer);
|
|
364
|
-
callQueue.delete(message.mid);
|
|
365
|
-
if (message.error) {
|
|
366
|
-
let err = new Error(message.error);
|
|
367
|
-
if (message.code) {
|
|
368
|
-
err.code = message.code;
|
|
369
|
-
}
|
|
370
|
-
if (message.statusCode) {
|
|
371
|
-
err.statusCode = message.statusCode;
|
|
372
|
-
}
|
|
373
|
-
return reject(err);
|
|
374
|
-
} else {
|
|
375
|
-
return resolve(message.response);
|
|
376
|
-
}
|
|
329
|
+
if (rpc.handleResponse(message)) {
|
|
330
|
+
return;
|
|
377
331
|
}
|
|
378
332
|
|
|
379
|
-
if (message
|
|
380
|
-
return
|
|
381
|
-
.then(response => {
|
|
382
|
-
parentPort.postMessage({
|
|
383
|
-
cmd: 'resp',
|
|
384
|
-
mid: message.mid,
|
|
385
|
-
response
|
|
386
|
-
});
|
|
387
|
-
})
|
|
388
|
-
.catch(err => {
|
|
389
|
-
parentPort.postMessage({
|
|
390
|
-
cmd: 'resp',
|
|
391
|
-
mid: message.mid,
|
|
392
|
-
error: err.message,
|
|
393
|
-
code: err.code,
|
|
394
|
-
statusCode: err.statusCode
|
|
395
|
-
});
|
|
396
|
-
});
|
|
333
|
+
if (isCall(message)) {
|
|
334
|
+
return respond(parentPort, message, onCommand, { logger });
|
|
397
335
|
}
|
|
398
336
|
});
|
|
399
337
|
|