emailengine-app 2.78.0 → 2.79.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.
Files changed (155) hide show
  1. package/.ncurc.js +23 -13
  2. package/.release-please-manifest.json +1 -1
  3. package/CHANGELOG.md +68 -0
  4. package/config/e2e.toml +2 -1
  5. package/config/test.toml +2 -1
  6. package/data/google-crawlers.json +1 -1
  7. package/lib/account.js +112 -36
  8. package/lib/api-reference/format.js +91 -4
  9. package/lib/api-reference/model.js +144 -19
  10. package/lib/api-reference/schema-tree.js +282 -28
  11. package/lib/api-routes/account-routes.js +80 -34
  12. package/lib/api-routes/blocklist-routes.js +21 -47
  13. package/lib/api-routes/chat-routes.js +10 -12
  14. package/lib/api-routes/delivery-test-routes.js +6 -26
  15. package/lib/api-routes/export-routes.js +2 -0
  16. package/lib/api-routes/gateway-routes.js +52 -11
  17. package/lib/api-routes/license-routes.js +2 -0
  18. package/lib/api-routes/mailbox-routes.js +29 -26
  19. package/lib/api-routes/message-routes.js +27 -21
  20. package/lib/api-routes/oauth2-app-routes.js +11 -29
  21. package/lib/api-routes/operation-impact.js +80 -0
  22. package/lib/api-routes/outbox-routes.js +15 -5
  23. package/lib/api-routes/permission-map.js +401 -0
  24. package/lib/api-routes/route-helpers.js +294 -9
  25. package/lib/api-routes/route-metadata.js +28 -0
  26. package/lib/api-routes/settings-routes.js +66 -38
  27. package/lib/api-routes/stats-routes.js +2 -2
  28. package/lib/api-routes/submit-routes.js +53 -31
  29. package/lib/api-routes/template-routes.js +3 -0
  30. package/lib/api-routes/token-routes.js +526 -72
  31. package/lib/api-routes/webhook-route-routes.js +14 -4
  32. package/lib/arf-detect.js +17 -4
  33. package/lib/auth-token.js +80 -8
  34. package/lib/bounce-detect.js +28 -17
  35. package/lib/consts.js +16 -0
  36. package/lib/db.js +26 -2
  37. package/lib/delivery-error.js +30 -1
  38. package/lib/email-client/base-client.js +27 -41
  39. package/lib/email-client/gmail-client.js +23 -17
  40. package/lib/email-client/imap/mailbox.js +58 -59
  41. package/lib/email-client/imap/subconnection.js +10 -7
  42. package/lib/email-client/imap/sync-operations.js +46 -46
  43. package/lib/email-client/imap-client.js +85 -28
  44. package/lib/email-client/message-builder.js +3 -3
  45. package/lib/email-client/notification-handler.js +1 -1
  46. package/lib/email-client/outlook/graph-api.js +10 -4
  47. package/lib/email-client/outlook-client.js +56 -64
  48. package/lib/email-client/smtp-pool-manager.js +1 -1
  49. package/lib/enum-descriptions.js +92 -2
  50. package/lib/export.js +1 -1
  51. package/lib/field-usage.js +133 -0
  52. package/lib/gateway.js +1 -1
  53. package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +3 -3
  54. package/lib/imapproxy/imap-core/lib/commands/id.js +2 -13
  55. package/lib/imapproxy/imap-core/lib/commands/starttls.js +1 -1
  56. package/lib/imapproxy/imap-core/lib/imap-command.js +21 -5
  57. package/lib/imapproxy/imap-core/lib/imap-connection.js +15 -5
  58. package/lib/imapproxy/imap-server.js +27 -7
  59. package/lib/license-beacon.js +4 -9
  60. package/lib/lists.js +49 -1
  61. package/lib/llm-pre-process.js +5 -5
  62. package/lib/logger.js +5 -1
  63. package/lib/lua/h-set-new-mark.lua +36 -0
  64. package/lib/message-port-stream.js +84 -1
  65. package/lib/metrics-collector.js +2 -2
  66. package/lib/oauth/gmail.js +9 -12
  67. package/lib/oauth/mail-ru.js +5 -7
  68. package/lib/oauth/outlook.js +9 -9
  69. package/lib/oauth/pubsub/google.js +25 -10
  70. package/lib/oauth/scope-checker.js +1 -1
  71. package/lib/oauth2-apps.js +290 -292
  72. package/lib/openapi/build-document.js +20 -8
  73. package/lib/openapi/joi-schema.js +20 -0
  74. package/lib/outbox.js +85 -17
  75. package/lib/pre-process.js +8 -8
  76. package/lib/queue-stats.js +49 -0
  77. package/lib/read-env-value.js +1 -1
  78. package/lib/reconnection-manager.js +2 -2
  79. package/lib/rewrite-text-nodes.js +4 -3
  80. package/lib/routes-ui.js +4 -0
  81. package/lib/schemas.js +218 -162
  82. package/lib/settings.js +98 -5
  83. package/lib/sub-script.js +2 -1
  84. package/lib/swagger-options.js +2 -1
  85. package/lib/templates.js +4 -4
  86. package/lib/threads.js +2 -2
  87. package/lib/token-audit-log.js +231 -0
  88. package/lib/token-permission-view.js +219 -0
  89. package/lib/token-permissions.js +172 -0
  90. package/lib/tokens.js +247 -66
  91. package/lib/tools.js +142 -37
  92. package/lib/ui-routes/account-routes.js +42 -15
  93. package/lib/ui-routes/admin-config-routes.js +18 -10
  94. package/lib/ui-routes/admin-entities-routes.js +117 -38
  95. package/lib/ui-routes/auth-routes.js +30 -24
  96. package/lib/ui-routes/export-routes.js +10 -4
  97. package/lib/ui-routes/oauth-config-routes.js +12 -12
  98. package/lib/ui-routes/reference-routes.js +3 -3
  99. package/lib/ui-routes/route-helpers.js +78 -2
  100. package/lib/ui-routes/settings-page.js +1 -1
  101. package/lib/ui-routes/smtp-test-routes.js +1 -1
  102. package/lib/ui-routes/suppression-list-routes.js +299 -0
  103. package/lib/ui-routes/unsubscribe-routes.js +19 -29
  104. package/lib/utils/decode-headers.js +42 -0
  105. package/lib/utils/header-map.js +48 -0
  106. package/lib/utils/network.js +2 -2
  107. package/lib/utils/unsafe-key.js +59 -0
  108. package/lib/web-safe-html.js +1 -1
  109. package/lib/webhook-routing.js +84 -0
  110. package/lib/webhooks.js +48 -14
  111. package/package.json +11 -10
  112. package/sbom.json +1 -1
  113. package/server.js +116 -55
  114. package/static/css/flyonui.css +1 -1
  115. package/static/css/src/app.tailwind.css +136 -9
  116. package/static/js/reference.js +456 -10
  117. package/static/js/ui.js +43 -0
  118. package/static/licenses.html +51 -41
  119. package/translations/messages.pot +59 -59
  120. package/views/accounts/account.hbs +75 -13
  121. package/views/accounts/browse.hbs +19 -36
  122. package/views/accounts/edit.hbs +2 -2
  123. package/views/config/logging.hbs +6 -0
  124. package/views/config/oauth/app.hbs +0 -2
  125. package/views/config/security.hbs +13 -0
  126. package/views/gateways/edit.hbs +1 -1
  127. package/views/gateways/gateway.hbs +2 -2
  128. package/views/gateways/index.hbs +7 -7
  129. package/views/partials/accounts_table.hbs +7 -7
  130. package/views/partials/oauth_form.hbs +0 -15
  131. package/views/partials/reference/disclosure.hbs +8 -2
  132. package/views/partials/reference/operation.hbs +47 -13
  133. package/views/partials/reference/params.hbs +17 -1
  134. package/views/partials/reference/schema-node.hbs +110 -52
  135. package/views/partials/reference/schema-tools.hbs +25 -0
  136. package/views/partials/reference/try-it.hbs +84 -11
  137. package/views/partials/side_menu.hbs +1 -0
  138. package/views/partials/ui/checkbox.hbs +2 -2
  139. package/views/partials/ui/tabs.hbs +7 -1
  140. package/views/reference/token.hbs +4 -0
  141. package/views/suppression-lists/index.hbs +85 -0
  142. package/views/suppression-lists/list.hbs +87 -0
  143. package/views/templates/index.hbs +10 -4
  144. package/views/templates/template.hbs +1 -1
  145. package/views/tokens/index.hbs +53 -6
  146. package/views/tokens/new.hbs +334 -5
  147. package/workers/api.js +185 -102
  148. package/workers/documents.js +46 -26
  149. package/workers/export.js +20 -8
  150. package/workers/imap-proxy.js +2 -2
  151. package/workers/imap.js +77 -78
  152. package/workers/smtp.js +13 -7
  153. package/workers/submit.js +40 -30
  154. package/workers/webhooks.js +80 -26
  155. package/lib/feature-flags.js +0 -48
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ const libmime = require('libmime');
4
+ const { UNSAFE_KEYS } = require('./unsafe-key');
5
+
6
+ /**
7
+ * Parses a header block into a map of lowercased header name to array of values.
8
+ *
9
+ * Wraps libmime.decodeHeaders() to drop names that collide with Object.prototype. Header names
10
+ * come from the message, so any sender can use one, and libmime returns them as real own
11
+ * properties. Neither names a real header, so there is nothing to preserve by keeping them:
12
+ *
13
+ * - an own "__proto__" key is the one thing lib/msgpack.js refuses to decode, so a map carrying it
14
+ * encodes into webhook logs and message payloads that can never be read back, and it hands
15
+ * anything that later copies the map with `obj[key] =` or Object.assign a prototype swap
16
+ * - "constructor" is inert on its own, but lib/utils/header-map.js cannot represent it, so keeping
17
+ * it would describe the same message differently depending on the transport that fetched it
18
+ *
19
+ * Dropping them here rather than at each consumer keeps every parsed header block on one
20
+ * contract: lib/email-client/imap/mailbox.js and lib/bounce-detect.js return these maps to callers
21
+ * verbatim, and lib/arf-detect.js copies them key by key into a published report. It is not the
22
+ * last word on either name though - a consumer that rebuilds a key from the name has to check
23
+ * again, see isUnsafeKey() in lib/utils/unsafe-key.js.
24
+ *
25
+ * @param {String|Buffer} headers - Raw header block
26
+ * @returns {Object} Map of lowercased header name to array of values
27
+ */
28
+ function decodeHeaders(headers) {
29
+ let parsed = libmime.decodeHeaders(headers);
30
+
31
+ for (let name of UNSAFE_KEYS) {
32
+ // Probing first is not needed for correctness, deleting a missing key is a no-op, but it is
33
+ // the cheaper no-op and almost every message takes this path
34
+ if (Object.hasOwn(parsed, name)) {
35
+ delete parsed[name];
36
+ }
37
+ }
38
+
39
+ return parsed;
40
+ }
41
+
42
+ module.exports = { decodeHeaders };
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ // Lives here rather than in lib/tools.js so that pure modules and tests can use it: tools.js
4
+ // opens Redis, which drags a connection into anything that only wants to collect header values.
5
+
6
+ /**
7
+ * Appends one value to a header map keyed by lowercased header name.
8
+ *
9
+ * Header names come from the remote server, so any sender can pick one that names an
10
+ * Object.prototype member. On a plain object `headers['__proto__']` reads back the prototype
11
+ * instead of an array, and assigning to it hands the value to the prototype setter rather than
12
+ * storing a key - so a bare `!headers[key]` probe pushes onto something that is not an array and
13
+ * throws. Lowercasing leaves exactly two such names, "__proto__" and "constructor", and both are
14
+ * dropped rather than collected: storing them would need an own "__proto__" key, which msgpack
15
+ * refuses to decode (test/msgpack-compat-test.js) and which hands webhook consumers a prototype
16
+ * pollution gadget of their own.
17
+ *
18
+ * Only the accumulate-by-assignment shape is guarded here. A header block parsed by libmime
19
+ * arrives with these names already set as own properties, which this cannot detect, so
20
+ * lib/utils/decode-headers.js drops them after the fact for the IMAP and bounce paths.
21
+ *
22
+ * The array is read before the `in` probe on purpose. `in` walks the prototype chain and has no
23
+ * fast path for the freshly lowercased (non-internalized) key, which made it roughly twice the
24
+ * cost of the whole loop; reading first keeps `in` on the miss path only.
25
+ *
26
+ * @param {Object} headers - Map of lowercased header name to array of values
27
+ * @param {String} key - Lowercased header name
28
+ * @param {String} value - Value to append
29
+ * @returns {Boolean} True when the value was stored, false when the name was skipped
30
+ */
31
+ function pushHeaderValue(headers, key, value) {
32
+ let values = headers[key];
33
+
34
+ if (Array.isArray(values)) {
35
+ values.push(value);
36
+ return true;
37
+ }
38
+
39
+ // Not an array: either the name is unused, or it resolves to a prototype member
40
+ if (key in headers) {
41
+ return false;
42
+ }
43
+
44
+ headers[key] = [value];
45
+ return true;
46
+ }
47
+
48
+ module.exports = { pushHeaderValue };
@@ -102,7 +102,7 @@ function matchIp(ip, addresses) {
102
102
  return true;
103
103
  }
104
104
  } catch (err) {
105
- logger.error({ msg: 'Failed to parse IP address', ip, addr, err });
105
+ logger.error({ msg: 'Failed to parse allowlist address', ip, addr, err });
106
106
  }
107
107
  }
108
108
 
@@ -339,7 +339,7 @@ async function getLocalAddress(redis, protocol, account, hint) {
339
339
  addressData.addressSelector = addressSelector;
340
340
  return addressData;
341
341
  } catch (err) {
342
- logger.error({ msg: 'Failed to load address data', localAddress, err });
342
+ logger.warn({ msg: 'Failed to load address data', localAddress, err });
343
343
  addressSelector = 'error';
344
344
  return { address: false, name: hostname, addressSelector };
345
345
  }
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ // Lives here rather than in lib/tools.js so that pure modules and tests can use it: tools.js opens
4
+ // Redis, which drags a connection into anything that only wants to parse a message.
5
+
6
+ // Names that resolve to an Object.prototype member. Header names come from the message, so any
7
+ // sender can pick one, and the maps built from them are plain objects:
8
+ //
9
+ // - assigning "__proto__" hands the value to the prototype setter and swaps the map's prototype
10
+ // instead of storing a key, and defining it as an own property instead leaves a key
11
+ // lib/msgpack.js refuses to decode - so a map carrying one encodes into webhook logs and message
12
+ // payloads that can never be read back
13
+ // - "constructor" is inert on its own, but lib/utils/header-map.js cannot represent it, so keeping
14
+ // it would describe the same message differently depending on the transport that fetched it
15
+ //
16
+ // The names a message supplies arrive lowercased, which leaves exactly these two. Kept as an
17
+ // explicit list rather than an `in {}` probe so that what gets dropped is readable at a glance, and
18
+ // so that names like "toString" - which cannot collide with a lowercased key, and which no real
19
+ // header or subtype uses either - are not dropped as a side effect.
20
+ const UNSAFE_KEYS = ['__proto__', 'constructor'];
21
+
22
+ /**
23
+ * Tells whether a key is one a plain-object map built from a message must not carry - header names,
24
+ * but also anything else the message names, such as the MIME subtype lib/email-client/imap/mailbox.js
25
+ * groups text parts by.
26
+ *
27
+ * Applied at the parse boundary (lib/utils/decode-headers.js), and again after any transform that
28
+ * rebuilds a key from a name. A transform can manufacture one of these out of an input the parse
29
+ * boundary had no reason to drop: toCamelCase() turns "_-_proto__" into "__proto__", so a guard
30
+ * that only ran before it never saw the name it exists to catch.
31
+ *
32
+ * @param {String} key - Key to test
33
+ * @returns {Boolean} True when the key must be dropped
34
+ */
35
+ function isUnsafeKey(key) {
36
+ return UNSAFE_KEYS.includes(key);
37
+ }
38
+
39
+ /**
40
+ * The stricter test for a key REBUILT from a name by a case-changing transform. After
41
+ * toCamelCase() a key is no longer lowercase-only: "to-string" camelCases into "toString" and
42
+ * "has-own-property" into "hasOwnProperty", so the transform can manufacture any Object.prototype
43
+ * member name out of an input the parse boundary had no reason to drop. Assigning one creates an
44
+ * own property that shadows the method on the published object, and the first consumer that
45
+ * string-coerces the report - or calls hasOwnProperty() on it - throws.
46
+ *
47
+ * Probed with `in` against Object.prototype itself (whose own chain ends at null, so this reads
48
+ * exactly its member set, __proto__ and constructor included) rather than extending the list
49
+ * above: the set tracks the runtime, and the parse-boundary check deliberately stays narrower -
50
+ * see the note on UNSAFE_KEYS about not dropping names a lowercased key cannot collide with.
51
+ *
52
+ * @param {String} key - Key to test, after the transform that rebuilt it
53
+ * @returns {Boolean} True when the key must be dropped
54
+ */
55
+ function isUnsafeTransformedKey(key) {
56
+ return key in Object.prototype;
57
+ }
58
+
59
+ module.exports = { UNSAFE_KEYS, isUnsafeKey, isUnsafeTransformedKey };
@@ -388,7 +388,7 @@ async function messageWebSafeHtml(messageData) {
388
388
  }
389
389
  } catch (err) {
390
390
  // A message that can not be folded is still a message. Render all of it.
391
- logger.error({ msg: 'Failed to mark quoted thread content', err });
391
+ logger.warn({ msg: 'Failed to mark quoted thread content', err });
392
392
  }
393
393
  }
394
394
 
@@ -0,0 +1,84 @@
1
+ 'use strict';
2
+
3
+ // Shared webhook routing rules. The notify pipeline (lib/webhooks.js, workers/webhooks.js)
4
+ // and the admin account page's routing card resolve targets and gates through the helpers
5
+ // here, so the debug view cannot drift from what the worker actually does.
6
+
7
+ // Precedence: custom route target, then the per-account webhooks override, then the global
8
+ // webhooks setting. Returns the winning URL and which configuration level provided it.
9
+ function resolveTargetUrl(customRouteTargetUrl, accountWebhooks, globalWebhooks) {
10
+ if (customRouteTargetUrl) {
11
+ return { url: customRouteTargetUrl, source: 'route' };
12
+ }
13
+ if (accountWebhooks) {
14
+ return { url: accountWebhooks, source: 'account' };
15
+ }
16
+ if (globalWebhooks) {
17
+ return { url: globalWebhooks, source: 'global' };
18
+ }
19
+ return { url: null, source: null };
20
+ }
21
+
22
+ // A custom route can only deliver when it is enabled and has a target URL
23
+ function isDeliverableRoute(route) {
24
+ return !!(route && route.enabled && route.targetUrl);
25
+ }
26
+
27
+ // The webhookEvents allowlist applies to the default route only; '*' allows everything
28
+ function eventAllowed(webhookEvents, eventName) {
29
+ let events = [].concat(webhookEvents || []);
30
+ return events.includes('*') || events.includes(eventName);
31
+ }
32
+
33
+ // Assembles a render-ready description of the webhook routing that applies to one account.
34
+ // All inputs are pre-fetched values; this function does not touch Redis or settings.
35
+ function describeEffectiveRouting(opts) {
36
+ opts = opts || {};
37
+
38
+ let events = [].concat(opts.webhookEvents || []);
39
+ let allEvents = events.includes('*');
40
+
41
+ let { url, source } = resolveTargetUrl(null, opts.accountWebhooks, opts.globalWebhooks);
42
+
43
+ let globalHeaders = [].concat(opts.globalCustomHeaders || []).length;
44
+ let accountHeaders = [].concat(opts.accountCustomHeaders || []).length;
45
+
46
+ let customHeadersLabel = null;
47
+ if (globalHeaders && accountHeaders) {
48
+ customHeadersLabel = `${globalHeaders} global, ${accountHeaders} account-specific`;
49
+ } else if (globalHeaders) {
50
+ customHeadersLabel = `${globalHeaders} global`;
51
+ } else if (accountHeaders) {
52
+ customHeadersLabel = `${accountHeaders} account-specific`;
53
+ }
54
+
55
+ return {
56
+ enabled: !!opts.webhooksEnabled,
57
+
58
+ defaultRoute: {
59
+ url,
60
+ source,
61
+ events: allEvents ? [] : events,
62
+ allEvents,
63
+ inboxNewOnly: !!opts.inboxNewOnly,
64
+ customHeadersLabel
65
+ },
66
+
67
+ // Enabled custom routes deliver independently of the default route, each gated by its
68
+ // own filter function instead of the webhookEvents allowlist. The worker requires that
69
+ // filter to exist (lib/webhooks.js pushToQueue skips a route without a compiled
70
+ // function), so a route whose `hasFilter` marker is false is flagged rather than
71
+ // presented as delivering - it never fires anything.
72
+ customRoutes: []
73
+ .concat(opts.routes || [])
74
+ .filter(isDeliverableRoute)
75
+ .map(route => ({
76
+ id: route.id,
77
+ name: route.name,
78
+ targetUrl: route.targetUrl,
79
+ missingFilter: route.hasFilter === false
80
+ }))
81
+ };
82
+ }
83
+
84
+ module.exports = { resolveTargetUrl, isDeliverableRoute, eventAllowed, describeEffectiveRouting };
package/lib/webhooks.js CHANGED
@@ -9,6 +9,7 @@ const { SubScript } = require('./sub-script');
9
9
  const settings = require('./settings');
10
10
  const { filterListPage } = require('./tools');
11
11
  const { buildRetentionPolicy } = require('./queue-retention');
12
+ const { isDeliverableRoute } = require('./webhook-routing');
12
13
 
13
14
  class WebhooksHandler {
14
15
  constructor(options) {
@@ -70,7 +71,12 @@ class WebhooksHandler {
70
71
  webhookErrorFlag = JSON.parse(list[i + 2].toString());
71
72
  }
72
73
  } catch (err) {
73
- logger.error({ msg: 'Failed to process webhook error', entry: list[i + 2] && list[i + 2].toString('base64') });
74
+ logger.error({
75
+ msg: 'Failed to parse webhook error flag',
76
+ webhook: selectedIds[i / 3],
77
+ entry: list[i + 2] && list[i + 2].toString('base64'),
78
+ err
79
+ });
74
80
  }
75
81
 
76
82
  try {
@@ -192,7 +198,7 @@ class WebhooksHandler {
192
198
  let entry = msgpack.decode(line);
193
199
  logEntries.unshift(entry);
194
200
  } catch (err) {
195
- logger.error({ msg: 'Failed to retrieve log line', webhook: id, entry: line && line.toString('base64') });
201
+ logger.error({ msg: 'Failed to decode log line', webhook: id, entry: line && line.toString('base64'), err });
196
202
  }
197
203
  }
198
204
 
@@ -212,7 +218,7 @@ class WebhooksHandler {
212
218
  meta = msgpack.decode(getResult[0]);
213
219
  }
214
220
  } catch (err) {
215
- logger.error({ msg: 'Failed to process webhook', entry: getResult[0].toString('base64') });
221
+ logger.error({ msg: 'Failed to process webhook', webhook: id, entry: getResult[0].toString('base64'), err });
216
222
  }
217
223
 
218
224
  return Object.assign({}, meta || {});
@@ -237,7 +243,7 @@ class WebhooksHandler {
237
243
  meta = msgpack.decode(getResult[0]);
238
244
  }
239
245
  } catch (err) {
240
- logger.error({ msg: 'Failed to process webhook', entry: getResult[0].toString('base64') });
246
+ logger.error({ msg: 'Failed to process webhook', webhook: id, entry: getResult[0].toString('base64'), err });
241
247
  }
242
248
 
243
249
  try {
@@ -245,7 +251,7 @@ class WebhooksHandler {
245
251
  content = msgpack.decode(getResult[1]);
246
252
  }
247
253
  } catch (err) {
248
- logger.error({ msg: 'Failed to process webhook', entry: getResult[1].toString('base64') });
254
+ logger.error({ msg: 'Failed to process webhook', webhook: id, entry: getResult[1].toString('base64'), err });
249
255
  }
250
256
 
251
257
  v = Number(getResult[2] && getResult[2].toString()) || 0;
@@ -255,7 +261,7 @@ class WebhooksHandler {
255
261
  webhookErrorFlag = JSON.parse(getResult[3].toString());
256
262
  }
257
263
  } catch (err) {
258
- logger.error({ msg: 'Failed to process webhook', entry: getResult[3].toString('base64') });
264
+ logger.error({ msg: 'Failed to process webhook', webhook: id, entry: getResult[3].toString('base64'), err });
259
265
  }
260
266
 
261
267
  tcount = Number(getResult[4] && getResult[4].toString()) || 0;
@@ -343,6 +349,34 @@ class WebhooksHandler {
343
349
  }
344
350
  }
345
351
 
352
+ // Filter-presence markers for the routes asked about, as a Map of id -> boolean. The
353
+ // delivery gate in pushToQueue() requires a compiled filter function, so anything
354
+ // describing routes to an operator (the account page's routing card) has to know which
355
+ // routes carry a script at all. Reads only the content entries of the given ids.
356
+ async getFilterInfo(ids) {
357
+ let result = new Map();
358
+ if (!ids || !ids.length) {
359
+ return result;
360
+ }
361
+
362
+ let entries = await this.redis.hmgetBuffer(
363
+ this.getWebhooksContentKey(),
364
+ ids.map(id => `${id}:content`)
365
+ );
366
+
367
+ for (let i = 0; i < ids.length; i++) {
368
+ let content = null;
369
+ try {
370
+ content = entries[i] ? msgpack.decode(entries[i]) : null;
371
+ } catch (err) {
372
+ logger.error({ msg: 'Failed to process webhook', webhook: ids[i], entry: entries[i] && entries[i].toString('base64'), err });
373
+ }
374
+ result.set(ids[i], !!(content && content.fn));
375
+ }
376
+
377
+ return result;
378
+ }
379
+
346
380
  async getHandler(id) {
347
381
  let webhookData = await this.get(id);
348
382
 
@@ -355,7 +389,7 @@ class WebhooksHandler {
355
389
  } catch (err) {
356
390
  await this.storeLog(id, 'filter', null, err.stack);
357
391
 
358
- logger.error({ msg: 'Compilation failed', type: 'filter', webhook: id, err });
392
+ logger.error({ msg: 'Failed to compile webhook script', type: 'filter', webhook: id, err });
359
393
  webhookData.compiledFn = null;
360
394
  webhookData.compiledMap = null;
361
395
  }
@@ -370,7 +404,7 @@ class WebhooksHandler {
370
404
  } catch (err) {
371
405
  await this.storeLog(id, 'map', null, err.stack);
372
406
 
373
- logger.error({ msg: 'Compilation failed', type: 'map', webhook: id, err });
407
+ logger.error({ msg: 'Failed to compile webhook script', type: 'map', webhook: id, err });
374
408
  webhookData.compiledFn = null;
375
409
  webhookData.compiledMap = null;
376
410
  }
@@ -383,7 +417,7 @@ class WebhooksHandler {
383
417
  } catch (err) {
384
418
  await this.storeLog(id, 'filter', payload, err.stack);
385
419
 
386
- logger.error({ msg: 'Exec failed', type: 'filter', webhook: webhookData.id, err });
420
+ logger.error({ msg: 'Failed to execute webhook script', type: 'filter', webhook: webhookData.id, err });
387
421
  return null;
388
422
  }
389
423
  };
@@ -396,7 +430,7 @@ class WebhooksHandler {
396
430
  } catch (err) {
397
431
  await this.storeLog(id, 'map', payload, err.stack);
398
432
 
399
- logger.error({ msg: 'Exec failed', type: 'map', webhook: webhookData.id, err });
433
+ logger.error({ msg: 'Failed to execute webhook script', type: 'map', webhook: webhookData.id, err });
400
434
  return null;
401
435
  }
402
436
  };
@@ -543,7 +577,7 @@ class WebhooksHandler {
543
577
  };
544
578
 
545
579
  for (let route of webhookRoutes) {
546
- if (route.enabled && route.targetUrl && typeof route.filterFn === 'function') {
580
+ if (isDeliverableRoute(route) && typeof route.filterFn === 'function') {
547
581
  let canSend;
548
582
  let payload = structuredClone(originalPayload);
549
583
 
@@ -556,7 +590,7 @@ class WebhooksHandler {
556
590
  } catch (err) {
557
591
  await this.storeLog(route.id, 'filter', payload, err.stack);
558
592
 
559
- logger.error({ msg: 'Exec failed', type: 'filter', webhook: route.id, err });
593
+ logger.error({ msg: 'Failed to execute webhook script', type: 'filter', webhook: route.id, err });
560
594
  }
561
595
 
562
596
  if (canSend) {
@@ -566,7 +600,7 @@ class WebhooksHandler {
566
600
  } catch (err) {
567
601
  await this.storeLog(route.id, 'map', payload, err.stack);
568
602
 
569
- logger.error({ msg: 'Exec failed', type: 'map', webhook: route.id, err });
603
+ logger.error({ msg: 'Failed to execute webhook script', type: 'map', webhook: route.id, err });
570
604
  canSend = false;
571
605
  }
572
606
  }
@@ -599,7 +633,7 @@ class WebhooksHandler {
599
633
  try {
600
634
  await this.redis.hincrby(this.getWebhooksContentKey(), `${route.id}:tcount`, 1);
601
635
  } catch (err) {
602
- logger.error({ msg: 'Failed to increment counter', event, webhook: route.id, err });
636
+ logger.warn({ msg: 'Failed to increment counter', event, webhook: route.id, err });
603
637
  }
604
638
  }
605
639
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emailengine-app",
3
- "version": "2.78.0",
3
+ "version": "2.79.1",
4
4
  "private": false,
5
5
  "productTitle": "EmailEngine",
6
6
  "description": "Email Sync Engine",
@@ -50,8 +50,8 @@
50
50
  },
51
51
  "homepage": "https://emailengine.app/",
52
52
  "dependencies": {
53
- "@bull-board/api": "8.6.0",
54
- "@bull-board/hapi": "8.6.0",
53
+ "@bull-board/api": "9.0.0",
54
+ "@bull-board/hapi": "9.0.0",
55
55
  "@elastic/elasticsearch": "8.15.3",
56
56
  "@hapi/accept": "6.0.3",
57
57
  "@hapi/bell": "13.1.0",
@@ -66,9 +66,9 @@
66
66
  "@postalsys/bounce-classifier": "3.0.0",
67
67
  "@postalsys/certs": "1.0.17",
68
68
  "@postalsys/ee-client": "1.7.0",
69
- "@postalsys/email-ai-tools": "1.13.17",
69
+ "@postalsys/email-ai-tools": "1.13.18",
70
70
  "@postalsys/email-content": "0.1.3",
71
- "@postalsys/email-text-tools": "2.4.12",
71
+ "@postalsys/email-text-tools": "2.4.13",
72
72
  "@postalsys/gettext": "4.1.1",
73
73
  "@postalsys/joi-messages": "1.0.5",
74
74
  "@postalsys/templates": "2.0.2",
@@ -78,12 +78,12 @@
78
78
  "@zone-eu/mailsplit": "5.4.15",
79
79
  "@zone-eu/wild-config": "1.7.6",
80
80
  "ace-builds": "1.44.0",
81
- "bullmq": "5.81.3",
81
+ "bullmq": "6.1.2",
82
82
  "compare-versions": "6.1.1",
83
83
  "dotenv": "17.4.2",
84
84
  "encoding-japanese": "2.2.0",
85
85
  "exponential-backoff": "3.1.3",
86
- "fast-xml-parser": "5.10.1",
86
+ "fast-xml-parser": "5.11.0",
87
87
  "gettext-parser": "7.0.1",
88
88
  "handlebars": "4.7.9",
89
89
  "hapi-auth-bearer-token": "8.0.0",
@@ -92,9 +92,9 @@
92
92
  "html-to-text": "10.0.0",
93
93
  "ical.js": "1.5.0",
94
94
  "iconv-lite": "0.7.3",
95
- "imapflow": "1.7.0",
95
+ "imapflow": "1.7.1",
96
96
  "ioredfour": "1.4.2",
97
- "ioredis": "5.11.1",
97
+ "ioredis": "6.0.0",
98
98
  "ipaddr.js": "2.5.0",
99
99
  "joi": "18.2.3",
100
100
  "libbase64": "1.3.0",
@@ -138,7 +138,8 @@
138
138
  "xgettext-template": "5.0.0"
139
139
  },
140
140
  "overrides": {
141
- "@asamuzakjp/css-color": "4.1.1"
141
+ "@asamuzakjp/css-color": "4.1.1",
142
+ "deepmerge-ts": "^8.0.1"
142
143
  },
143
144
  "engines": {
144
145
  "node": ">=20.x"