emailengine-app 2.87.0 → 2.87.2

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.
Files changed (71) hide show
  1. package/.ncurc.js +2 -4
  2. package/.release-please-manifest.json +1 -1
  3. package/CHANGELOG.md +27 -0
  4. package/Dockerfile +3 -4
  5. package/bin/emailengine.js +2 -4
  6. package/bin/healthcheck.js +20 -0
  7. package/data/google-crawlers.json +1 -1
  8. package/data/public_suffix_list.dat +3 -7
  9. package/lib/account/auth-failure-backfill.js +3 -2
  10. package/lib/account/expected-identity.js +2 -2
  11. package/lib/account.js +9 -8
  12. package/lib/api-listener.js +40 -0
  13. package/lib/api-token-auth.js +406 -0
  14. package/lib/autodetect-imap-settings.js +36 -3
  15. package/lib/consts.js +5 -0
  16. package/lib/dbsc/index.js +292 -0
  17. package/lib/dbsc/jwt.js +157 -0
  18. package/lib/dbsc/protocol.js +132 -0
  19. package/lib/dbsc/store.js +136 -0
  20. package/lib/email-client/base-client.js +23 -107
  21. package/lib/email-client/gmail-client.js +7 -4
  22. package/lib/email-client/imap/mailbox.js +89 -96
  23. package/lib/email-client/imap/sync-operations.js +13 -6
  24. package/lib/email-client/imap-client.js +28 -7
  25. package/lib/email-client/new-message-steps.js +162 -0
  26. package/lib/email-client/outlook-client.js +4 -2
  27. package/lib/env-setting-overrides.js +6 -2
  28. package/lib/export-worker.js +3 -2
  29. package/lib/export.js +43 -4
  30. package/lib/get-boolean.js +38 -0
  31. package/lib/health-probe.js +71 -0
  32. package/lib/imapproxy/imap-server.js +4 -55
  33. package/lib/net-tos-guard.js +42 -0
  34. package/lib/oauth2-apps.js +2 -1
  35. package/lib/privileged-settings.js +6 -0
  36. package/lib/read-env-value.js +19 -7
  37. package/lib/redis-keys.js +19 -0
  38. package/lib/redis-operations.js +7 -3
  39. package/lib/routes-ui.js +4 -1
  40. package/lib/schemas.js +8 -0
  41. package/lib/security-headers.js +18 -0
  42. package/lib/session-default.js +60 -0
  43. package/lib/settings.js +2 -1
  44. package/lib/stream-encrypt.js +71 -20
  45. package/lib/sub-script.js +8 -2
  46. package/lib/submit-lock.js +84 -0
  47. package/lib/submit-processor.js +283 -0
  48. package/lib/templates.js +6 -3
  49. package/lib/tls/context.js +2 -16
  50. package/lib/tools.js +8 -30
  51. package/lib/ui-routes/admin-config-routes.js +27 -5
  52. package/lib/ui-routes/auth-routes.js +4 -0
  53. package/lib/ui-routes/dbsc-routes.js +43 -0
  54. package/lib/utils/redis-errors.js +44 -0
  55. package/lib/webhook-delivery.js +3 -4
  56. package/lib/worker-rpc-error.js +10 -5
  57. package/lib/worker-rpc.js +138 -0
  58. package/package.json +17 -19
  59. package/sbom.json +370 -1446
  60. package/server.js +6 -5
  61. package/static/css/flyonui.css +2 -2
  62. package/static/licenses.html +253 -1366
  63. package/translations/messages.pot +16 -16
  64. package/views/config/security.hbs +37 -0
  65. package/workers/api.js +61 -467
  66. package/workers/export.js +14 -55
  67. package/workers/imap-proxy.js +5 -18
  68. package/workers/imap.js +27 -49
  69. package/workers/smtp.js +7 -69
  70. package/workers/submit.js +21 -279
  71. package/workers/webhooks.js +7 -72
package/lib/tools.js CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  'use strict';
4
4
 
5
+ // Before anything that makes an HTTP request, see the module
6
+ require('./net-tos-guard');
7
+ const { accountDataKey } = require('./redis-keys');
5
8
  const { filterEmptyObjectValues } = require('./utils/filter-empty');
6
9
 
7
10
  const msgpack = require('./msgpack');
@@ -71,7 +74,8 @@ const tls = require('tls');
71
74
  const net = require('net');
72
75
  const { SocksClient } = require('socks');
73
76
  const { createWebhookLookup, WEBHOOK_EGRESS_POLICY } = require('./webhook-egress');
74
- const { readEnvValue } = require('./read-env-value');
77
+ const { readEnvValue, hasEnvValue } = require('./read-env-value');
78
+ const { getBoolean } = require('./get-boolean');
75
79
 
76
80
  const AGENT_OPTS = {
77
81
  strictContentLength: false,
@@ -1587,31 +1591,7 @@ module.exports = {
1587
1591
  return scoredAddresses[0].address;
1588
1592
  },
1589
1593
 
1590
- getBoolean(value) {
1591
- if (typeof value === 'boolean') {
1592
- return value;
1593
- }
1594
-
1595
- if (typeof value === 'string') {
1596
- value = value.trim();
1597
- }
1598
-
1599
- if (typeof value === 'string' && !isNaN(value) && /^[0-9]+$/.test(value)) {
1600
- value = Number(value);
1601
- }
1602
-
1603
- if (typeof value === 'number') {
1604
- return !!value;
1605
- }
1606
-
1607
- if (typeof value === 'string') {
1608
- // `on` and `enabled` are what several operators write in env files, and joi and
1609
- // resolveHttpProxy() already read `on` as true
1610
- return /^(y|true|on$|enabled$)/i.test(value);
1611
- }
1612
-
1613
- return false; // ????
1614
- },
1594
+ getBoolean,
1615
1595
 
1616
1596
  async checkLicense(license) {
1617
1597
  let verifyKeys = [
@@ -2826,9 +2806,7 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
2826
2806
  return false;
2827
2807
  },
2828
2808
 
2829
- hasEnvValue(key) {
2830
- return key in process.env || `${key}_FILE` in process.env;
2831
- },
2809
+ hasEnvValue,
2832
2810
 
2833
2811
  /**
2834
2812
  * Reads a comma-separated environment value as a trimmed, blank-free array.
@@ -3001,7 +2979,7 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
3001
2979
  let hopsAllowed = 20;
3002
2980
 
3003
2981
  while (redirect++ < hopsAllowed) {
3004
- let oauth2DataStr = await redis.hget(`${REDIS_PREFIX}iad:${account}`, 'oauth2');
2982
+ let oauth2DataStr = await redis.hget(accountDataKey(account), 'oauth2');
3005
2983
  if (!oauth2DataStr) {
3006
2984
  let error = new Error(`Missing account data for delegated account "${account}"`);
3007
2985
  throw error;
@@ -22,6 +22,7 @@ const { getByteSize, formatByteSize, getDuration, failAction, readEnvValue, read
22
22
  const { sendTestWebhook, testEventBody } = require('../webhook-test');
23
23
  const { llmPreProcess, buildSummaryInput, authenticationTrust } = require('../llm-pre-process');
24
24
  const { decodeHeaders } = require('../utils/decode-headers');
25
+ const { isSecureOrigin } = require('../security-headers');
25
26
  const { mcpFeatureEnabled } = require('../mcp');
26
27
  const { mcpResource } = require('../mcp/oauth');
27
28
  const { getToolRegistry } = require('../mcp/tools');
@@ -426,6 +427,15 @@ function registerConfigServicePage(server, args) {
426
427
  });
427
428
  }
428
429
 
430
+ // What the Security page says about device-bound sessions: whether the setting can take effect on
431
+ // this instance (an https Service URL, which browsers require), and whether the browser looking at
432
+ // the page is bound right now, which is the one way an operator can see it working
433
+ async function dbscStatus(request) {
434
+ const dbsc = request.server.app.dbsc;
435
+ const [serviceUrl, currentBound] = await Promise.all([settings.get('serviceUrl'), !!dbsc && dbsc.isBound(request)]);
436
+ return { active: isSecureOrigin(serviceUrl), currentBound };
437
+ }
438
+
429
439
  function registerConfigSecurityPage(server) {
430
440
  registerSettingsPage(server, {
431
441
  path: '/admin/config/security',
@@ -436,6 +446,7 @@ function registerConfigSecurityPage(server) {
436
446
  serviceSecret: settingsSchema.serviceSecret,
437
447
  ignoreMailCertErrors: settingsSchema.ignoreMailCertErrors.default(false),
438
448
  tokenAuditLog: settingsSchema.tokenAuditLog.default(false),
449
+ dbscEnabled: settingsSchema.dbscEnabled.default(false),
439
450
  tokenLogEntries: settingsSchema.tokenLogEntries.allow(null).default(null),
440
451
  // days on the form, seconds in the setting
441
452
  tokenLogAge: Joi.number().empty('').positive().precision(2).allow(null).default(null),
@@ -446,7 +457,14 @@ function registerConfigSecurityPage(server) {
446
457
  },
447
458
 
448
459
  async loadValues() {
449
- const storedValues = await settings.getMulti('serviceSecret', 'disableTokens', 'enableOAuthTokensApi', 'ignoreMailCertErrors', 'tokenAuditLog');
460
+ const storedValues = await settings.getMulti(
461
+ 'serviceSecret',
462
+ 'disableTokens',
463
+ 'enableOAuthTokensApi',
464
+ 'ignoreMailCertErrors',
465
+ 'tokenAuditLog',
466
+ 'dbscEnabled'
467
+ );
450
468
 
451
469
  return {
452
470
  ...(await overridableFormValues('tokenLogEntries', 'tokenLogAge')),
@@ -454,14 +472,17 @@ function registerConfigSecurityPage(server) {
454
472
  enableTokens: !storedValues.disableTokens,
455
473
  enableOAuthTokensApi: storedValues.enableOAuthTokensApi || false,
456
474
  ignoreMailCertErrors: storedValues.ignoreMailCertErrors || false,
457
- tokenAuditLog: storedValues.tokenAuditLog || false
475
+ tokenAuditLog: storedValues.tokenAuditLog || false,
476
+ dbscEnabled: storedValues.dbscEnabled || false
458
477
  };
459
478
  },
460
479
 
461
- async viewContext() {
480
+ async viewContext(request) {
481
+ const [encryption, dbsc] = await Promise.all([getSecret(), dbscStatus(request)]);
462
482
  return {
463
- encryption: await getSecret(),
464
- adminAccessLimit: ADMIN_ACCESS_ADDRESSES && ADMIN_ACCESS_ADDRESSES.length
483
+ encryption,
484
+ adminAccessLimit: ADMIN_ACCESS_ADDRESSES && ADMIN_ACCESS_ADDRESSES.length,
485
+ dbsc
465
486
  };
466
487
  },
467
488
 
@@ -471,6 +492,7 @@ function registerConfigSecurityPage(server) {
471
492
  enableOAuthTokensApi: request.payload.enableOAuthTokensApi,
472
493
  ignoreMailCertErrors: request.payload.ignoreMailCertErrors,
473
494
  tokenAuditLog: request.payload.tokenAuditLog,
495
+ dbscEnabled: request.payload.dbscEnabled,
474
496
  ...overridableSettingsFromForm(request.payload, 'tokenLogEntries', 'tokenLogAge')
475
497
  };
476
498
 
@@ -30,6 +30,7 @@ const PASSKEY_ALGORITHMS = [-7, -257];
30
30
  const settings = require('../settings');
31
31
  const consts = require('../consts');
32
32
  const { readEnvValue, setAdminSession } = require('../tools');
33
+ const { endDeviceBinding } = require('../dbsc');
33
34
  const passkeys = require('../passkeys');
34
35
  const sso = require('../sso');
35
36
  const { redis } = require('../db');
@@ -333,6 +334,9 @@ function registerGetLogout(server) {
333
334
  logoutUrl = await h.oidcLogoutUrl(artifacts.idToken);
334
335
  }
335
336
 
337
+ // Before the cookie is cleared: the binding is found by the session's sid
338
+ await endDeviceBinding(request, h);
339
+
336
340
  if (request.cookieAuth) {
337
341
  request.cookieAuth.clear();
338
342
  }
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ // The two endpoints of device-bound admin sessions (lib/dbsc/). The browser calls both on its own,
4
+ // not a page, which is why neither carries a crumb: what stands in for one is a signature over a
5
+ // challenge only this server issued, to this session, minutes ago.
6
+
7
+ const { REGISTRATION_PATH, REFRESH_PATH } = require('../dbsc/protocol');
8
+
9
+ /**
10
+ * The handlers find the DBSC instance on server.app, where workers/api.js publishes it with the
11
+ * session strategy (setupDbsc() in lib/dbsc), so registration needs nothing but the server
12
+ * @param {Object} args
13
+ * @param {Object} args.server - hapi server
14
+ */
15
+ function init(args) {
16
+ const { server } = args;
17
+
18
+ server.route({
19
+ method: 'POST',
20
+ path: REGISTRATION_PATH,
21
+ // The default session strategy: only a signed-in admin session can bind itself
22
+ handler: (request, h) => request.server.app.dbsc.register(request, h),
23
+ options: {
24
+ plugins: { crumb: false }
25
+ }
26
+ });
27
+
28
+ server.route({
29
+ method: 'POST',
30
+ path: REFRESH_PATH,
31
+ // Reads the session without requiring it. The browser acts on the status of this answer, and
32
+ // the redirect to the login page a required session would produce is one it ignores, so an
33
+ // ended session has to be told so in a body it understands instead
34
+ handler: (request, h) => request.server.app.dbsc.refresh(request, h),
35
+ options: {
36
+ auth: { strategy: 'session', mode: 'try' },
37
+ // dbsc.enforce: false - a missing bound cookie is what this route renews
38
+ plugins: { crumb: false, dbsc: { enforce: false } }
39
+ }
40
+ });
41
+ }
42
+
43
+ module.exports = init;
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ // Which Redis reply errors say "not now" rather than "never". Dependency-free, so pure modules and
4
+ // their tests can ask.
5
+ //
6
+ // A cut connection never reaches the code as an error (ioredis runs with maxRetriesPerRequest null
7
+ // and sends the command again once it has reconnected), so these replies are how a Redis problem
8
+ // does reach it: OOM for every write and script while used memory is over maxmemory, LOADING while a
9
+ // restarted Redis loads its dataset, BUSY while a script runs past its time limit, READONLY and
10
+ // MASTERDOWN around a failover, MISCONF while snapshots fail, the cluster ones while slots move. All
11
+ // of them clear up without anything changing on our side, so a caller that holds work durably (a
12
+ // queued arrival, a retried job) keeps it rather than drop it.
13
+
14
+ const TRANSIENT_REPLY = /^(OOM|LOADING|BUSY|READONLY|MASTERDOWN|MISCONF|TRYAGAIN|CLUSTERDOWN|NOREPLICAS)\b/;
15
+
16
+ /**
17
+ * Whether an error is a Redis reply that a later attempt can get past. EXECABORT counts when every
18
+ * command that failed inside the transaction did so for such a reason (ioredis collects them in
19
+ * `previousErrors`); a transaction refused for a syntax error fails the same way every time. An
20
+ * error that wraps one (its `cause`) counts as well
21
+ * @param {Error} err
22
+ * @returns {boolean}
23
+ */
24
+ function isTransientRedisError(err, depth = 0) {
25
+ if (!err || depth > 5) {
26
+ return false;
27
+ }
28
+ if (err.name !== 'ReplyError' || typeof err.message !== 'string') {
29
+ return isTransientRedisError(err.cause, depth + 1);
30
+ }
31
+ if (TRANSIENT_REPLY.test(err.message)) {
32
+ return true;
33
+ }
34
+ return (
35
+ /^EXECABORT\b/.test(err.message) &&
36
+ Array.isArray(err.previousErrors) &&
37
+ err.previousErrors.length > 0 &&
38
+ // An explicit callback: every() would hand in the index as the depth, so the seventh
39
+ // failed command of a transaction read as past the depth limit, a permanent error
40
+ err.previousErrors.every(previous => isTransientRedisError(previous, depth + 1))
41
+ );
42
+ }
43
+
44
+ module.exports = { isTransientRedisError };
@@ -6,6 +6,7 @@
6
6
  // decisions were only tested through the helpers it calls. Everything with a side effect is passed
7
7
  // in, see createWebhookProcessor().
8
8
 
9
+ const { accountDataKey } = require('./redis-keys');
9
10
  const { UnrecoverableError, DelayedError } = require('bullmq');
10
11
 
11
12
  const { redactUrlCredentials, splitUrlCredentials } = require('./tools');
@@ -21,13 +22,11 @@ const {
21
22
  deliveryCustomHeaders,
22
23
  isRouteMappingMissing
23
24
  } = require('./webhook-routing');
24
- const { REDIS_PREFIX, ACCOUNT_DELETED_NOTIFY, DEFAULT_WEBHOOK_REQUEST_TIMEOUT } = require('./consts');
25
+ const { ACCOUNT_DELETED_NOTIFY, DEFAULT_WEBHOOK_REQUEST_TIMEOUT } = require('./consts');
25
26
 
26
27
  // The payload fields of `data` that are logged as they are; anything else only marks it partial
27
28
  const LOGGED_DATA_KEYS = new Set(['id', 'uid', 'path', 'messageId']);
28
29
 
29
- const getAccountKey = account => `${REDIS_PREFIX}iad:${account}`;
30
-
31
30
  /**
32
31
  * Log context shared by every line about one job
33
32
  * @param {Object} job - BullMQ job
@@ -152,7 +151,7 @@ async function waitOutPenalty(job, token, webhooks, deps) {
152
151
  */
153
152
  async function planDelivery(job, token, deps) {
154
153
  const { redis, settings, logger, openAccountField } = deps;
155
- let accountKey = getAccountKey(job.data.account);
154
+ let accountKey = accountDataKey(job.data.account);
156
155
 
157
156
  // Keep the route id reachable for the completed/failed event handlers, which see this same
158
157
  // job instance after _route has been deleted from the payload. Stashed before the early
@@ -14,10 +14,8 @@
14
14
  // one place makes that dependency explicit and unit-testable (see test/worker-rpc-error-test.js).
15
15
  // `permanent` is nodemailer's own verdict on that reply, which the predicate prefers when present.
16
16
  //
17
- // These helpers are used at the delivery-error RPC path - the imap/submit workers and the main-thread
18
- // hub (server.js) that relays between them. The other workers (webhooks/export/smtp/api)
19
- // keep their own inline resp-handler copies: they never carry a delivery error, so `responseCode`
20
- // does not apply to them. Route a delivery error through a new worker and it must switch to these too.
17
+ // Every worker's RPC goes through these helpers (lib/worker-rpc.js on the worker side, server.js as
18
+ // the hub that relays between workers), so a field added here reaches every hop.
21
19
  const RPC_ERROR_FIELDS = ['code', 'statusCode', 'responseCode', 'permanent', 'info'];
22
20
 
23
21
  /**
@@ -27,7 +25,14 @@ const RPC_ERROR_FIELDS = ['code', 'statusCode', 'responseCode', 'permanent', 'in
27
25
  * @returns {Object} Payload with `error` (the message) plus every present RPC_ERROR_FIELD
28
26
  */
29
27
  function packRpcError(err) {
30
- let payload = { error: err.message };
28
+ // A command may reject with something that is not an Error (a string, undefined). Reading
29
+ // .message off that used to throw inside the reply handler, a rejection nothing caught
30
+ if (!err || typeof err !== 'object') {
31
+ return { error: String(err) };
32
+ }
33
+ // Never empty: the receiving side tells an error reply from a result by this field being set,
34
+ // so an Error with no message would otherwise arrive as a successful, empty response
35
+ let payload = { error: err.message || err.name || 'Error' };
31
36
  for (let field of RPC_ERROR_FIELDS) {
32
37
  if (err[field] != null) {
33
38
  payload[field] = err[field];
@@ -0,0 +1,138 @@
1
+ 'use strict';
2
+
3
+ // The worker side of the RPC protocol between a worker thread and the main thread (server.js).
4
+ //
5
+ // A worker calls the main thread with `{ cmd: 'call', mid, message }` and gets back
6
+ // `{ cmd: 'resp', mid, response }` or `{ cmd: 'resp', mid, error, ...fields }`; the main thread
7
+ // calls a worker the same way. Every worker used to carry its own copy of both halves, and the
8
+ // copies had drifted: some rebuilt errors without `responseCode` and `permanent`, one call() did
9
+ // not guard postMessage, and no reply guarded against a response that cannot be cloned, which
10
+ // would surface as a rejection nothing handles and end the worker. Errors cross the hop through
11
+ // lib/worker-rpc-error.js, the same field list everywhere.
12
+ //
13
+ // The main thread's hub (server.js) routes calls between workers and keeps its own bookkeeping
14
+ // (the worker each call went to, rejecting them when it exits), so it does not use this module.
15
+
16
+ const { packRpcError, unpackRpcError } = require('./worker-rpc-error');
17
+
18
+ /**
19
+ * Creates the calling half: call() sends a command to the main thread and settles when its
20
+ * response arrives or the timeout passes, handleResponse() settles a call from a received message.
21
+ *
22
+ * @param {Object} opts
23
+ * @param {Object} opts.port - the MessagePort to talk over (parentPort)
24
+ * @param {Number} opts.defaultTimeout - lowest timeout in ms, a command may ask for longer
25
+ * @param {String} opts.timeoutTag - short marker in the timeout message that names the worker
26
+ * @returns {{ call: Function, handleResponse: Function, pendingCount: Function }}
27
+ */
28
+ function createRpcClient({ port, defaultTimeout, timeoutTag }) {
29
+ const pending = new Map();
30
+ let mids = 0;
31
+
32
+ function call(message, transferList) {
33
+ return new Promise((resolve, reject) => {
34
+ const mid = `${Date.now()}:${++mids}`;
35
+
36
+ const ttl = Math.max(message.timeout || 0, defaultTimeout || 0);
37
+ const timer = setTimeout(() => {
38
+ pending.delete(mid);
39
+ const err = new Error(`Timeout waiting for command response [${timeoutTag}]`);
40
+ err.statusCode = 504;
41
+ err.code = 'Timeout';
42
+ err.ttl = ttl;
43
+ reject(err);
44
+ }, ttl);
45
+
46
+ pending.set(mid, { resolve, reject, timer });
47
+
48
+ try {
49
+ port.postMessage({ cmd: 'call', mid, message }, transferList);
50
+ } catch (err) {
51
+ clearTimeout(timer);
52
+ pending.delete(mid);
53
+ reject(err);
54
+ }
55
+ });
56
+ }
57
+
58
+ /**
59
+ * Settles the call a response belongs to
60
+ * @param {Object} message - a received message
61
+ * @returns {Boolean} true when the message was the response to a pending call
62
+ */
63
+ function handleResponse(message) {
64
+ if (!message || message.cmd !== 'resp' || !message.mid || !pending.has(message.mid)) {
65
+ return false;
66
+ }
67
+
68
+ const { resolve, reject, timer } = pending.get(message.mid);
69
+ clearTimeout(timer);
70
+ pending.delete(message.mid);
71
+
72
+ if (message.error) {
73
+ reject(unpackRpcError(message));
74
+ } else {
75
+ resolve(message.response);
76
+ }
77
+ return true;
78
+ }
79
+
80
+ return { call, handleResponse, pendingCount: () => pending.size };
81
+ }
82
+
83
+ /**
84
+ * Runs a command the main thread sent and posts its result back. Never rejects: a response that
85
+ * cannot be sent (a value postMessage cannot clone, a closed port) is answered with an error
86
+ * instead, and a failure to send even that is logged rather than left to the global handler.
87
+ *
88
+ * @param {Object} port - the MessagePort to answer over (parentPort)
89
+ * @param {Object} message - the received `{ cmd: 'call', mid, message }`
90
+ * @param {Function} handler - async (command) => response
91
+ * @param {Object} opts
92
+ * @param {Object} opts.logger - where an undeliverable response is reported
93
+ * @param {Function} [opts.onError] - (err, message) => void, sees a command's error before it is sent
94
+ * @returns {Promise<void>}
95
+ */
96
+ async function respond(port, message, handler, { logger, onError }) {
97
+ const mid = message.mid;
98
+
99
+ const send = payload => {
100
+ try {
101
+ port.postMessage(payload);
102
+ } catch (err) {
103
+ try {
104
+ port.postMessage(Object.assign({ cmd: 'resp', mid }, packRpcError(err)));
105
+ } catch (fallbackErr) {
106
+ logger.error({ msg: 'Failed to send a command response', mid, err: fallbackErr });
107
+ }
108
+ }
109
+ };
110
+
111
+ let response;
112
+ try {
113
+ response = await handler(message.message);
114
+ } catch (err) {
115
+ if (onError) {
116
+ try {
117
+ onError(err, message);
118
+ } catch (hookErr) {
119
+ logger.error({ msg: 'Failed to process a command error', mid, err: hookErr });
120
+ }
121
+ }
122
+ send(Object.assign({ cmd: 'resp', mid }, packRpcError(err)));
123
+ return;
124
+ }
125
+
126
+ send({ cmd: 'resp', mid, response });
127
+ }
128
+
129
+ /**
130
+ * Whether a received message is a command for this worker to run
131
+ * @param {Object} message
132
+ * @returns {Boolean}
133
+ */
134
+ function isCall(message) {
135
+ return !!(message && message.cmd === 'call' && message.mid);
136
+ }
137
+
138
+ module.exports = { createRpcClient, respond, isCall };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emailengine-app",
3
- "version": "2.87.0",
3
+ "version": "2.87.2",
4
4
  "private": false,
5
5
  "productTitle": "EmailEngine",
6
6
  "description": "Email Sync Engine",
@@ -60,39 +60,39 @@
60
60
  "@hapi/boom": "10.0.1",
61
61
  "@hapi/cookie": "12.0.1",
62
62
  "@hapi/crumb": "9.0.1",
63
- "@hapi/hapi": "21.4.12",
63
+ "@hapi/hapi": "21.4.13",
64
64
  "@hapi/inert": "7.1.3",
65
65
  "@hapi/vision": "7.0.3",
66
66
  "@msgpack/msgpack": "3.1.3",
67
67
  "@postalsys/bounce-classifier": "3.1.0",
68
- "@postalsys/certs": "2.0.3",
69
- "@postalsys/email-ai-tools": "2.4.0",
70
- "@postalsys/email-content": "0.1.18",
71
- "@postalsys/email-text-tools": "2.6.1",
68
+ "@postalsys/certs": "2.0.4",
69
+ "@postalsys/email-ai-tools": "2.4.2",
70
+ "@postalsys/email-content": "0.1.20",
71
+ "@postalsys/email-text-tools": "2.6.3",
72
72
  "@postalsys/gettext": "4.3.0",
73
73
  "@postalsys/joi-messages": "1.4.1",
74
74
  "@postalsys/templates": "2.1.1",
75
75
  "@sentry/node-core": "10.78.0",
76
76
  "@simplewebauthn/server": "14.0.3",
77
- "@zone-eu/mailsplit": "5.4.29",
77
+ "@zone-eu/mailsplit": "5.4.30",
78
78
  "@zone-eu/wild-config": "1.7.10",
79
- "bullmq": "6.5.1",
79
+ "bullmq": "6.7.0",
80
80
  "dotenv": "18.0.9",
81
- "fast-xml-parser": "5.11.2",
81
+ "fast-xml-parser": "5.12.0",
82
82
  "handlebars": "4.7.10",
83
83
  "he": "1.2.0",
84
84
  "html-to-text": "10.0.1",
85
85
  "ical.js": "2.2.1",
86
86
  "iconv-lite": "0.7.3",
87
- "imapflow": "2.10.0",
87
+ "imapflow": "2.10.2",
88
88
  "ioredfour": "2.2.0",
89
89
  "ioredis": "6.0.0",
90
90
  "ipaddr.js": "2.5.0",
91
- "joi": "18.3.1",
91
+ "joi": "18.3.2",
92
92
  "libbase64": "1.4.1",
93
- "libmime": "5.6.3",
93
+ "libmime": "5.6.4",
94
94
  "libqp": "3.0.1",
95
- "mailparser": "3.14.1",
95
+ "mailparser": "3.14.2",
96
96
  "marked": "15.0.12",
97
97
  "minimist": "1.2.8",
98
98
  "nodemailer": "10.3.1",
@@ -112,26 +112,25 @@
112
112
  "@playwright/test": "1.63.0",
113
113
  "@postalsys/ee-client": "1.10.0",
114
114
  "@simplewebauthn/browser": "14.0.0",
115
- "@tailwindcss/cli": "4.3.3",
115
+ "@tailwindcss/cli": "4.3.4",
116
116
  "ace-builds": "1.45.2",
117
117
  "acorn": "8.19.0",
118
118
  "acorn-walk": "8.3.5",
119
119
  "eerawlog": "1.5.5",
120
- "eslint": "10.13.0",
120
+ "eslint": "10.14.0",
121
121
  "eslint-config-prettier": "10.1.8",
122
122
  "flyonui": "2.4.1",
123
123
  "gettext-parser": "7.0.1",
124
- "globals": "17.13.0",
124
+ "globals": "17.14.0",
125
125
  "pino-pretty": "13.2.0",
126
126
  "prettier": "3.9.10",
127
127
  "resedit": "3.1.0",
128
128
  "spdx-satisfies": "6.0.0",
129
129
  "supertest": "7.3.1",
130
- "tailwindcss": "4.3.3",
130
+ "tailwindcss": "4.3.4",
131
131
  "xgettext-template": "5.0.0"
132
132
  },
133
133
  "overrides": {
134
- "@asamuzakjp/css-color": "4.1.1",
135
134
  "cheerio": "1.2.0"
136
135
  },
137
136
  "engines": {
@@ -149,7 +148,6 @@
149
148
  "node_modules/@postalsys/joi-messages/translations/*",
150
149
  "node_modules/@postalsys/bounce-classifier/model/**/*",
151
150
  "node_modules/@postalsys/email-content/dist/detect/patterns/*.json",
152
- "node_modules/jsdom/lib/jsdom/browser/default-stylesheet.css",
153
151
  "LICENSE_EMAILENGINE.txt",
154
152
  "version-info.json",
155
153
  "sbom.json",