emailengine-app 2.84.2 → 2.86.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.
Files changed (164) hide show
  1. package/.ncurc.js +29 -9
  2. package/.prettierignore +5 -1
  3. package/.prettierrc.js +2 -0
  4. package/.release-please-manifest.json +1 -1
  5. package/CHANGELOG.md +107 -0
  6. package/Dockerfile +20 -1
  7. package/ENVIRONMENT.md +139 -0
  8. package/README.md +2 -2
  9. package/bin/emailengine.js +434 -408
  10. package/config/default.toml +2 -0
  11. package/copy-static-files.sh +41 -14
  12. package/data/google-crawlers.json +1 -1
  13. package/data/public_suffix_list.dat +16563 -0
  14. package/eslint.config.js +81 -99
  15. package/lib/account-assignment.js +19 -0
  16. package/lib/account.js +230 -170
  17. package/lib/api-error-codes.js +49 -0
  18. package/lib/api-reference/format.js +4 -3
  19. package/lib/api-reference/model.js +6 -1
  20. package/lib/api-routes/account-routes.js +255 -38
  21. package/lib/api-routes/blocklist-routes.js +91 -4
  22. package/lib/api-routes/delivery-test-routes.js +27 -4
  23. package/lib/api-routes/export-routes.js +28 -2
  24. package/lib/api-routes/gateway-routes.js +110 -12
  25. package/lib/api-routes/index.js +4 -0
  26. package/lib/api-routes/license-routes.js +2 -2
  27. package/lib/api-routes/mailbox-routes.js +44 -5
  28. package/lib/api-routes/message-routes.js +112 -10
  29. package/lib/api-routes/oauth2-app-routes.js +63 -23
  30. package/lib/api-routes/outbox-routes.js +97 -52
  31. package/lib/api-routes/permission-map.js +67 -7
  32. package/lib/api-routes/scoped-routes.js +74 -0
  33. package/lib/api-routes/settings-routes.js +34 -6
  34. package/lib/api-routes/stats-routes.js +5 -1
  35. package/lib/api-routes/submit-routes.js +337 -309
  36. package/lib/api-routes/template-routes.js +45 -8
  37. package/lib/api-routes/token-routes.js +152 -100
  38. package/lib/api-routes/webhook-delivery-routes.js +262 -0
  39. package/lib/api-routes/webhook-route-routes.js +132 -6
  40. package/lib/bounce-detect.js +397 -205
  41. package/lib/calendar-event.js +81 -1
  42. package/lib/consts.js +38 -45
  43. package/lib/db.js +14 -6
  44. package/lib/delivery-error.js +6 -0
  45. package/lib/deprecations.js +270 -0
  46. package/lib/email-client/base-client.js +137 -184
  47. package/lib/email-client/fallback-poll.js +62 -0
  48. package/lib/email-client/gmail-client.js +60 -22
  49. package/lib/email-client/imap/adaptive-idle-store.js +73 -0
  50. package/lib/email-client/imap/adaptive-idle.js +278 -0
  51. package/lib/email-client/imap/connection-errors.js +14 -1
  52. package/lib/email-client/imap/idle-settings.js +31 -5
  53. package/lib/email-client/imap/listing-diff.js +37 -0
  54. package/lib/email-client/imap/mailbox.js +372 -242
  55. package/lib/email-client/imap/subconnection.js +8 -30
  56. package/lib/email-client/imap/sync-operations.js +220 -127
  57. package/lib/email-client/imap-client.js +228 -164
  58. package/lib/email-client/message-builder.js +14 -79
  59. package/lib/email-client/notification-handler.js +1 -2
  60. package/lib/email-client/outlook-client.js +372 -338
  61. package/lib/email-client/smtp-pool-manager.js +16 -13
  62. package/lib/email-client/sync-state-fields.js +19 -0
  63. package/lib/encrypt.js +157 -41
  64. package/lib/enum-descriptions.js +3 -1
  65. package/lib/env-setting-overrides.js +288 -0
  66. package/lib/export-worker.js +751 -0
  67. package/lib/export.js +64 -15
  68. package/lib/gateway.js +19 -4
  69. package/lib/get-raw-email.js +25 -107
  70. package/lib/hapi-request-logger.js +107 -0
  71. package/lib/health.js +75 -0
  72. package/lib/imapproxy/imap-core/README.md +6 -5
  73. package/lib/lock-run.js +119 -0
  74. package/lib/logger-consts.js +48 -0
  75. package/lib/logger.js +1 -1
  76. package/lib/lua/z-head-scores.lua +28 -0
  77. package/lib/mcp/tools.js +37 -8
  78. package/lib/network-errors.js +1 -1
  79. package/lib/node-version.js +24 -0
  80. package/lib/notify-attachments.js +36 -0
  81. package/lib/oauth/outlook-mailbox.js +35 -0
  82. package/lib/oauth/state.js +24 -0
  83. package/lib/oauth2-apps.js +631 -656
  84. package/lib/outbox.js +184 -54
  85. package/lib/parse-message.js +3 -3
  86. package/lib/pbkdf2-phc.js +1 -1
  87. package/lib/privileged-settings.js +2 -2
  88. package/lib/queue-browser/definitions.js +11 -0
  89. package/lib/queue-browser/index.js +68 -19
  90. package/lib/queue-job-actions.js +18 -1
  91. package/lib/queue-retention.js +48 -12
  92. package/lib/queue-stats.js +11 -2
  93. package/lib/read-env-value.js +3 -0
  94. package/lib/redis-memory-warnings.js +99 -0
  95. package/lib/redis-reconnect.js +29 -0
  96. package/lib/request-timing.js +23 -0
  97. package/lib/respawn-backoff.js +35 -0
  98. package/lib/rewrite-text-nodes.js +19 -59
  99. package/lib/schemas.js +164 -40
  100. package/lib/settings.js +6 -2
  101. package/lib/smtp-auth.js +19 -1
  102. package/lib/sso.js +1 -1
  103. package/lib/swagger-options.js +1 -1
  104. package/lib/thread-diagnostics.js +63 -0
  105. package/lib/timezones.js +109 -0
  106. package/lib/tls/provision.js +6 -3
  107. package/lib/token-audit-log.js +19 -20
  108. package/lib/token-permission-view.js +7 -6
  109. package/lib/tools.js +48 -51
  110. package/lib/totp.js +2 -5
  111. package/lib/translations.js +1 -2
  112. package/lib/ui-routes/account-routes.js +475 -454
  113. package/lib/ui-routes/account-setup.js +99 -0
  114. package/lib/ui-routes/admin-config-routes.js +152 -100
  115. package/lib/ui-routes/admin-entities-routes.js +93 -21
  116. package/lib/ui-routes/auth-routes.js +90 -38
  117. package/lib/ui-routes/imap-idle-field.js +1 -1
  118. package/lib/ui-routes/internals-routes.js +5 -0
  119. package/lib/ui-routes/oauth-config-routes.js +124 -82
  120. package/lib/ui-routes/outlook-subscription-view.js +1 -1
  121. package/lib/ui-routes/overridable-fields.js +84 -0
  122. package/lib/ui-routes/queue-routes.js +8 -5
  123. package/lib/ui-routes/route-helpers.js +19 -3
  124. package/lib/ui-routes/settings-page.js +6 -0
  125. package/lib/ui-routes/tls-config-routes.js +58 -15
  126. package/lib/utils/back-off.js +82 -0
  127. package/lib/utils/decode-headers.js +3 -12
  128. package/lib/utils/filter-empty.js +20 -0
  129. package/lib/utils/int-setting.js +48 -0
  130. package/lib/utils/murmurhash3.js +66 -0
  131. package/lib/utils/public-suffix.js +122 -0
  132. package/lib/utils/random-id.js +26 -0
  133. package/lib/utils/tracking-settings.js +35 -0
  134. package/lib/utils/version.js +74 -0
  135. package/lib/web-safe-html.js +18 -105
  136. package/lib/webhook-delivery.js +461 -0
  137. package/lib/webhook-failures.js +132 -0
  138. package/lib/webhook-request.js +29 -1
  139. package/lib/webhook-routing.js +56 -0
  140. package/lib/webhook-test.js +88 -0
  141. package/lib/webhooks.js +93 -45
  142. package/lib/worker-rpc-error.js +2 -1
  143. package/package.json +37 -38
  144. package/sbom.json +7902 -1
  145. package/server.js +784 -518
  146. package/static/js/ace/ace.js +1 -1
  147. package/static/licenses.html +225 -1060
  148. package/translations/messages.pot +62 -63
  149. package/views/config/ai.hbs +1 -1
  150. package/views/config/security.hbs +24 -2
  151. package/views/config/service.hbs +47 -0
  152. package/views/config/webhooks.hbs +36 -0
  153. package/views/internals/index.hbs +8 -0
  154. package/views/partials/queue_retention_note.hbs +12 -8
  155. package/views/partials/ui/env-managed-alert.hbs +16 -7
  156. package/views/partials/webhook_form.hbs +1 -1
  157. package/views/suppression-lists/index.hbs +1 -1
  158. package/workers/api.js +840 -611
  159. package/workers/export.js +17 -632
  160. package/workers/imap.js +13 -0
  161. package/workers/smtp.js +9 -11
  162. package/workers/submit.js +1 -1
  163. package/workers/webhooks.js +18 -448
  164. package/lib/email-client/outlook-fallback-poll.js +0 -30
@@ -4,6 +4,16 @@
4
4
  // and the admin account page's routing card resolve targets and gates through the helpers
5
5
  // here, so the debug view cannot drift from what the worker actually does.
6
6
 
7
+ const {
8
+ MESSAGE_NEW_NOTIFY,
9
+ DEFAULT_WEBHOOK_ATTEMPTS,
10
+ MAX_WEBHOOK_ATTEMPTS,
11
+ DEFAULT_WEBHOOK_RETRY_DELAY,
12
+ MIN_WEBHOOK_RETRY_DELAY,
13
+ MAX_WEBHOOK_RETRY_DELAY
14
+ } = require('./consts');
15
+ const { boundedInt } = require('./utils/int-setting');
16
+
7
17
  // Precedence: custom route target, then the per-account webhooks override, then the global
8
18
  // webhooks setting. Returns the winning URL and which configuration level provided it.
9
19
  function resolveTargetUrl(customRouteTargetUrl, accountWebhooks, globalWebhooks) {
@@ -30,6 +40,30 @@ function eventAllowed(webhookEvents, eventName) {
30
40
  return events.includes('*') || events.includes(eventName);
31
41
  }
32
42
 
43
+ // A messageNew counts as an Inbox message when any of the ways the clients report the folder says so:
44
+ // the IMAP path, the folder's special use, or the message's own special use or Gmail label
45
+ function isInboxPayload(payload) {
46
+ return !!(
47
+ (payload.account && payload.path === 'INBOX') ||
48
+ payload.specialUse === '\\Inbox' ||
49
+ (payload.data && payload.data.messageSpecialUse === '\\Inbox') ||
50
+ (payload.data && payload.data.labels && payload.data.labels.includes('\\Inbox'))
51
+ );
52
+ }
53
+
54
+ // Whether the default route takes an event: the webhookEvents allowlist, then inboxNewOnly for
55
+ // messageNew. The worker asks this at delivery, and lib/webhooks.js asks it before queueing so an
56
+ // event the default route would drop is not written to Redis only for the worker to drop it.
57
+ function defaultRouteTakes(eventName, payload, { webhookEvents, inboxNewOnly }) {
58
+ if (!eventAllowed(webhookEvents, eventName)) {
59
+ return false;
60
+ }
61
+ if (eventName === MESSAGE_NEW_NOTIFY && inboxNewOnly && !isInboxPayload(payload)) {
62
+ return false;
63
+ }
64
+ return true;
65
+ }
66
+
33
67
  // Which custom header lists travel with a delivery, by the configuration level whose target won
34
68
  // (`source`, from resolveTargetUrl), in the order they are merged (later lists override earlier):
35
69
  //
@@ -141,10 +175,32 @@ function describeEffectiveRouting(opts) {
141
175
  };
142
176
  }
143
177
 
178
+ /**
179
+ * The attempts and backoff a webhook delivery job is queued with, from the webhooksDeliveryAttempts
180
+ * and webhooksRetryDelay settings. Read when an event is queued, so a change applies to the events
181
+ * queued after it, never to the deliveries already waiting.
182
+ *
183
+ * @param {Object} [values] - The two settings, as settings.getMulti() returns them
184
+ * @returns {{attempts: number, backoff: Object}} BullMQ job options
185
+ */
186
+ function webhookRetryPolicy(values) {
187
+ values = values || {};
188
+ return {
189
+ attempts: boundedInt(values.webhooksDeliveryAttempts, DEFAULT_WEBHOOK_ATTEMPTS, 1, MAX_WEBHOOK_ATTEMPTS),
190
+ backoff: {
191
+ type: 'exponential',
192
+ delay: boundedInt(values.webhooksRetryDelay, DEFAULT_WEBHOOK_RETRY_DELAY, MIN_WEBHOOK_RETRY_DELAY, MAX_WEBHOOK_RETRY_DELAY),
193
+ jitter: 0.2 // 20% randomization to prevent thundering herd
194
+ }
195
+ };
196
+ }
197
+
144
198
  module.exports = {
199
+ webhookRetryPolicy,
145
200
  resolveTargetUrl,
146
201
  isDeliverableRoute,
147
202
  eventAllowed,
203
+ defaultRouteTakes,
148
204
  describeEffectiveRouting,
149
205
  headerLevels,
150
206
  deliveryCustomHeaders,
@@ -0,0 +1,88 @@
1
+ 'use strict';
2
+
3
+ // A one-off test delivery to a webhook target: the admin Webhooks page's "Test" button and
4
+ // POST /v1/webhooks/test. It goes out through the same request function, dispatcher and egress
5
+ // check as a real delivery, and is signed the way one is, so a receiver that verifies
6
+ // X-EE-Wh-Signature accepts the probe as it would accept the events.
7
+
8
+ const crypto = require('crypto');
9
+ const { fetch: fetchCmd } = require('undici');
10
+ const { splitUrlCredentials, httpAgent, getServiceSecret } = require('./tools');
11
+ const { validateWebhookTarget } = require('./webhook-egress');
12
+ const { sendWebhookRequest, baseDeliveryHeaders, signDelivery } = require('./webhook-request');
13
+ const { isReservedDeliveryHeader } = require('./webhook-routing');
14
+ const { NONCE_BYTES } = require('./consts');
15
+
16
+ /**
17
+ * The body of a test event, as the receiver gets it
18
+ * @param {string} serviceUrl - The instance's service URL
19
+ * @param {string} [account] - Account ID, when the test is for an account's target
20
+ * @returns {string} JSON
21
+ */
22
+ function testEventBody(serviceUrl, account) {
23
+ return JSON.stringify({
24
+ serviceUrl,
25
+ account: account || null,
26
+ date: new Date().toISOString(),
27
+ event: 'test',
28
+ data: {
29
+ nonce: crypto.randomBytes(NONCE_BYTES).toString('base64url')
30
+ }
31
+ });
32
+ }
33
+
34
+ /**
35
+ * Posts a test delivery and reports how it went. Never throws for a failed delivery: the result
36
+ * says why it failed, which is the point of a test.
37
+ *
38
+ * @param {Object} options
39
+ * @param {string} options.url - Target URL, credentials in it are sent as basic auth
40
+ * @param {Array} [options.customHeaders] - `{ key, value }` headers to add, the X-EE-Wh-* and
41
+ * framing headers excepted, as for a real delivery
42
+ * @param {string} options.body - Request body
43
+ * @param {Object} options.logger - Logger instance
44
+ * @returns {Promise<Object>} `{ success, duration }`, plus `error`, `code` and `statusCode` on failure
45
+ */
46
+ async function sendTestWebhook(options) {
47
+ const { url, customHeaders, body, logger } = options;
48
+
49
+ const { url: parsed, authorization } = splitUrlCredentials(url);
50
+ const headers = baseDeliveryHeaders(authorization);
51
+
52
+ for (const header of [].concat(customHeaders || [])) {
53
+ if (header && header.key && !isReservedDeliveryHeader(header.key)) {
54
+ headers[header.key] = header.value;
55
+ }
56
+ }
57
+
58
+ signDelivery(headers, body, await getServiceSecret());
59
+
60
+ const start = Date.now();
61
+ try {
62
+ await sendWebhookRequest(fetchCmd, parsed.toString(), {
63
+ method: 'post',
64
+ body,
65
+ headers,
66
+ dispatcher: httpAgent.webhook,
67
+ validateTarget: validateWebhookTarget
68
+ });
69
+ return { success: true, duration: Date.now() - start };
70
+ } catch (err) {
71
+ // undici wraps a connection failure in a generic "fetch failed"; the cause is the part
72
+ // worth reporting back
73
+ const failure = err.cause || err;
74
+ // the parsed URL, not the given one, so embedded basic-auth credentials stay out of the log
75
+ logger.warn({ msg: 'Failed to post test webhook', webhooks: parsed.toString(), event: 'test', err: failure });
76
+ return {
77
+ success: false,
78
+ duration: Date.now() - start,
79
+ error: failure.message,
80
+ code: failure.code,
81
+ // Same field the stored webhookErrorFlag carries, so a probe and a failed delivery are
82
+ // described the same way
83
+ statusCode: failure.statusCode
84
+ };
85
+ }
86
+ }
87
+
88
+ module.exports = { sendTestWebhook, testEventBody };
package/lib/webhooks.js CHANGED
@@ -7,9 +7,14 @@ const logger = require('./logger');
7
7
  const { REDIS_PREFIX, MESSAGE_NEW_NOTIFY } = require('./consts');
8
8
  const { SubScript } = require('./sub-script');
9
9
  const settings = require('./settings');
10
- const { filterListPage, truncateTextContents } = require('./tools');
10
+ const { filterListPage, redactUrlCredentials, truncateTextContents } = require('./tools');
11
11
  const { buildRetentionPolicy } = require('./queue-retention');
12
- const { isDeliverableRoute } = require('./webhook-routing');
12
+ const { getFailedJobRetention } = require('./env-setting-overrides');
13
+ const { isDeliverableRoute, defaultRouteTakes, webhookRetryPolicy } = require('./webhook-routing');
14
+ const { withinNotifyAttachmentSize } = require('./notify-attachments');
15
+
16
+ // Every setting pushToQueue() decides by, read in one round trip per event
17
+ const QUEUE_SETTINGS = ['webhooksEnabled', 'queueKeep', 'webhookEvents', 'inboxNewOnly', 'webhooksDeliveryAttempts', 'webhooksRetryDelay'];
13
18
  const { encryptField, decryptField } = require('./encrypt');
14
19
  const getSecret = require('./get-secret');
15
20
 
@@ -164,8 +169,13 @@ class WebhooksHandler {
164
169
  }
165
170
 
166
171
  if (query) {
167
- let paged = filterListPage(response.webhooks, ['id', 'name', 'description', 'targetUrl'], query, startPos, pageSize);
168
- response.webhooks = paged.entries;
172
+ // Matched against the target URL as a reader of the listing sees it, credentials taken
173
+ // out: the decrypted URL can carry user:pass@, and matching on it would let a caller
174
+ // that only ever gets the masked value guess the credential one character at a time
175
+ // from whether an entry matches
176
+ let original = new Map(response.webhooks.map(entry => [Object.assign({}, entry, { targetUrl: redactUrlCredentials(entry.targetUrl) }), entry]));
177
+ let paged = filterListPage([...original.keys()], ['id', 'name', 'description', 'targetUrl'], query, startPos, pageSize);
178
+ response.webhooks = paged.entries.map(view => original.get(view));
169
179
  response.total = paged.total;
170
180
  response.pages = paged.pages;
171
181
  }
@@ -590,60 +600,61 @@ class WebhooksHandler {
590
600
  return this.handlerCache;
591
601
  }
592
602
 
593
- async formatPayload(event, originalPayload) {
594
- // run all normalizations before sending the data
595
-
596
- const payload = structuredClone(originalPayload);
597
- payload.eventId = payload.eventId || uuid();
603
+ /**
604
+ * The messageNew normalizations: text, headers and attachment contents are kept only as far
605
+ * as the notify settings ask
606
+ * @param {Object} data - The event's data, changed in place
607
+ */
608
+ async normalizeMessageNew(data) {
609
+ // one read for every setting these use
610
+ const { notifyText, notifyTextSize, notifyHeaders, notifyAttachments, notifyAttachmentSize } = await settings.getMulti(
611
+ 'notifyText',
612
+ 'notifyTextSize',
613
+ 'notifyHeaders',
614
+ 'notifyAttachments',
615
+ 'notifyAttachmentSize'
616
+ );
598
617
 
599
- if (event === MESSAGE_NEW_NOTIFY && payload && payload.data && payload.data.text) {
618
+ if (data.text) {
600
619
  // normalize text content
601
- let notifyText = await settings.get('notifyText');
602
620
  if (!notifyText) {
603
621
  // remove text content if any
604
- for (let key of Object.keys(payload.data.text)) {
622
+ for (let key of Object.keys(data.text)) {
605
623
  if (!['id', 'encodedSize'].includes(key)) {
606
- delete payload.data.text[key];
624
+ delete data.text[key];
607
625
  }
608
626
  }
609
- if (!Object.keys(payload.data.text).length) {
610
- delete payload.data.text;
611
- }
612
- } else {
613
- let notifyTextSize = await settings.get('notifyTextSize');
614
- if (payload.data.text && truncateTextContents(payload.data.text, notifyTextSize)) {
615
- payload.data.text.hasMore = true;
627
+ if (!Object.keys(data.text).length) {
628
+ delete data.text;
616
629
  }
630
+ } else if (data.text && truncateTextContents(data.text, notifyTextSize)) {
631
+ data.text.hasMore = true;
617
632
  }
618
633
  }
619
634
 
620
- if (event === MESSAGE_NEW_NOTIFY && payload && payload.data && payload.data.headers) {
635
+ if (data.headers) {
621
636
  // normalize headers
622
- let notifyHeaders = (await settings.get('notifyHeaders')) || [];
623
- if (!notifyHeaders.length) {
624
- delete payload.data.headers;
637
+ if (!notifyHeaders?.length) {
638
+ delete data.headers;
625
639
  } else if (!notifyHeaders.includes('*')) {
626
640
  // filter unneeded headers
627
- for (let header of Object.keys(payload.data.headers || {})) {
641
+ for (let header of Object.keys(data.headers || {})) {
628
642
  if (!notifyHeaders.includes(header.toLowerCase())) {
629
- delete payload.data.headers[header];
643
+ delete data.headers[header];
630
644
  }
631
645
  }
632
646
  }
633
647
 
634
- if (payload.data.headers && !Object.keys(payload.data.headers).length) {
635
- delete payload.data.headers;
648
+ if (data.headers && !Object.keys(data.headers).length) {
649
+ delete data.headers;
636
650
  }
637
651
  }
638
652
 
639
653
  // remove attachment contents
640
- if (event === MESSAGE_NEW_NOTIFY && payload && payload.data && payload.data.attachments) {
641
- let notifyAttachments = await settings.get('notifyAttachments');
642
- let notifyAttachmentSize = await settings.get('notifyAttachmentSize');
643
-
644
- for (let attachment of payload.data.attachments) {
654
+ if (data.attachments) {
655
+ for (let attachment of data.attachments) {
645
656
  if (attachment.content) {
646
- if (notifyAttachments && (!notifyAttachmentSize || notifyAttachmentSize > (attachment.content.length / 4) * 3)) {
657
+ if (notifyAttachments && withinNotifyAttachmentSize(attachment, notifyAttachmentSize)) {
647
658
  // keep the attachment
648
659
  continue;
649
660
  }
@@ -651,6 +662,17 @@ class WebhooksHandler {
651
662
  }
652
663
  }
653
664
  }
665
+ }
666
+
667
+ async formatPayload(event, originalPayload) {
668
+ // run all normalizations before sending the data
669
+
670
+ const payload = structuredClone(originalPayload);
671
+ payload.eventId = payload.eventId || uuid();
672
+
673
+ if (event === MESSAGE_NEW_NOTIFY && payload.data) {
674
+ await this.normalizeMessageNew(payload.data);
675
+ }
654
676
 
655
677
  if (payload && payload.data && payload.data.text && payload.data.text._generatedHtml) {
656
678
  payload.data.text.html = payload.data.text._generatedHtml;
@@ -661,19 +683,42 @@ class WebhooksHandler {
661
683
  return payload;
662
684
  }
663
685
 
664
- async pushToQueue(event, originalPayload) {
686
+ /**
687
+ * Formats an event and queues it for delivery. The entry point for every producer of webhook
688
+ * events: with delivery switched off it returns before the payload is cloned and formatted.
689
+ * @param {string} event - Event name
690
+ * @param {Object} payload - Unformatted event payload
691
+ */
692
+ async enqueue(event, payload) {
693
+ let queueSettings = await settings.getMulti(...QUEUE_SETTINGS);
694
+ if (!queueSettings.webhooksEnabled) {
695
+ return;
696
+ }
697
+ await this.pushToQueue(event, await this.formatPayload(event, payload), queueSettings);
698
+ }
699
+
700
+ /**
701
+ * Queues a formatted event for the custom routes that take it and for the default route.
702
+ * @param {string} event - Event name
703
+ * @param {Object} originalPayload - Payload as formatPayload() returned it
704
+ * @param {Object} [queueSettings] - QUEUE_SETTINGS values when the caller has read them already
705
+ */
706
+ async pushToQueue(event, originalPayload, queueSettings) {
707
+ queueSettings = queueSettings || (await settings.getMulti(...QUEUE_SETTINGS));
708
+
709
+ // With delivery switched off the worker drops every job before looking at its target,
710
+ // custom routes included, so nothing is queued and no route script runs
711
+ if (!queueSettings.webhooksEnabled) {
712
+ return;
713
+ }
714
+
665
715
  // custom webhook routes
666
716
  let webhookRoutes = await this.getWebhookHandlers();
667
- let queueKeep = (await settings.get('queueKeep')) ?? true;
717
+ let queueKeep = queueSettings.queueKeep ?? true;
668
718
 
669
719
  let jobOpts = {
670
- ...buildRetentionPolicy(queueKeep),
671
- attempts: 10,
672
- backoff: {
673
- type: 'exponential',
674
- delay: 5000,
675
- jitter: 0.2 // 20% randomization to prevent thundering herd
676
- }
720
+ ...buildRetentionPolicy(queueKeep, await getFailedJobRetention()),
721
+ ...webhookRetryPolicy(queueSettings)
677
722
  };
678
723
 
679
724
  for (let route of webhookRoutes) {
@@ -724,8 +769,11 @@ class WebhooksHandler {
724
769
  }
725
770
  }
726
771
 
727
- // MAIN webhook
728
- await notifyQueue.add(event, originalPayload, jobOpts);
772
+ // MAIN webhook, unless its allowlist or inboxNewOnly already rules the event out. The worker
773
+ // asks the same again at delivery, since either setting can change while a job waits
774
+ if (defaultRouteTakes(event, originalPayload, queueSettings)) {
775
+ await notifyQueue.add(event, originalPayload, jobOpts);
776
+ }
729
777
  }
730
778
  }
731
779
 
@@ -12,12 +12,13 @@
12
12
  // to tell a transient 4xx rejection (e.g. greylisting) from a permanent 5xx one. It used to be
13
13
  // dropped, so the predicate's SMTP-reply branch never fired in production; keeping the field list in
14
14
  // one place makes that dependency explicit and unit-testable (see test/worker-rpc-error-test.js).
15
+ // `permanent` is nodemailer's own verdict on that reply, which the predicate prefers when present.
15
16
  //
16
17
  // These helpers are used at the delivery-error RPC path - the imap/submit workers and the main-thread
17
18
  // hub (server.js) that relays between them. The other workers (webhooks/export/smtp/api)
18
19
  // keep their own inline resp-handler copies: they never carry a delivery error, so `responseCode`
19
20
  // does not apply to them. Route a delivery error through a new worker and it must switch to these too.
20
- const RPC_ERROR_FIELDS = ['code', 'statusCode', 'responseCode', 'info'];
21
+ const RPC_ERROR_FIELDS = ['code', 'statusCode', 'responseCode', 'permanent', 'info'];
21
22
 
22
23
  /**
23
24
  * Serializes an Error into the plain payload sent over postMessage.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emailengine-app",
3
- "version": "2.84.2",
3
+ "version": "2.86.0",
4
4
  "private": false,
5
5
  "productTitle": "EmailEngine",
6
6
  "description": "Email Sync Engine",
@@ -13,11 +13,14 @@
13
13
  "gmail": "EE_OPENAPI_VERBOSE=true EENGINE_LOG_RAW=true EENGINE_SECRET=your-encryption-key EENGINE_WORKERS=2 EENGINE_CORS_ORIGIN='*' node --inspect server --dbs.redis='redis://127.0.0.1:6379/11' --api.port=7003 --api.host=0.0.0.0 | tee $HOME/ee.log.gmail.txt | pino-pretty",
14
14
  "test": "npm run lint:src && npm run test:unit && npm run test:integration",
15
15
  "test:unit": "NODE_ENV=test node test/run-tests.js unit",
16
+ "test:cjs": "NODE_ENV=test NODE_OPTIONS=--no-experimental-require-module node test/run-tests.js unit",
16
17
  "test:integration": "NODE_ENV=test node test/run-tests.js integration",
18
+ "test:mutation": "NODE_ENV=test node scripts/mutation-test.js",
17
19
  "test:dovecot": "./test/dovecot/run-dovecot-tests.sh",
18
20
  "test:e2e": "playwright test",
19
21
  "test:e2e:install": "playwright install --with-deps chromium",
20
- "lint": "npx eslint 'lib/**/*.js' 'workers/**/*.js' 'test/**/*.js' server.js",
22
+ "lint": "eslint .",
23
+ "lint:fix": "eslint . --fix",
21
24
  "lint:src": "npx eslint 'lib/**/*.js' 'workers/**/*.js' server.js",
22
25
  "swagger": "./getswagger.sh",
23
26
  "build:css": "tailwindcss -i static/css/src/app.tailwind.css -o static/css/flyonui.css --minify",
@@ -56,58 +59,49 @@
56
59
  "@hapi/boom": "10.0.1",
57
60
  "@hapi/cookie": "12.0.1",
58
61
  "@hapi/crumb": "9.0.1",
59
- "@hapi/hapi": "21.4.10",
60
- "@hapi/inert": "7.1.2",
62
+ "@hapi/hapi": "21.4.11",
63
+ "@hapi/inert": "7.1.3",
61
64
  "@hapi/vision": "7.0.3",
62
65
  "@msgpack/msgpack": "3.1.3",
63
- "@postalsys/bounce-classifier": "3.0.1",
64
- "@postalsys/certs": "1.4.6",
65
- "@postalsys/email-ai-tools": "2.2.7",
66
- "@postalsys/email-content": "0.1.16",
67
- "@postalsys/email-text-tools": "2.4.25",
68
- "@postalsys/gettext": "4.1.1",
69
- "@postalsys/joi-messages": "1.3.1",
70
- "@postalsys/templates": "2.0.4",
66
+ "@postalsys/bounce-classifier": "3.1.0",
67
+ "@postalsys/certs": "2.0.2",
68
+ "@postalsys/email-ai-tools": "2.3.2",
69
+ "@postalsys/email-content": "0.1.18",
70
+ "@postalsys/email-text-tools": "2.6.1",
71
+ "@postalsys/gettext": "4.3.0",
72
+ "@postalsys/joi-messages": "1.4.1",
73
+ "@postalsys/templates": "2.1.1",
71
74
  "@sentry/node-core": "10.76.2",
72
75
  "@simplewebauthn/server": "14.0.3",
73
- "@zone-eu/mailsplit": "5.4.26",
74
- "@zone-eu/wild-config": "1.7.9",
75
- "bullmq": "6.3.16",
76
- "compare-versions": "6.1.1",
77
- "dotenv": "18.0.8",
78
- "encoding-japanese": "2.4.0",
79
- "exponential-backoff": "3.1.3",
76
+ "@zone-eu/mailsplit": "5.4.29",
77
+ "@zone-eu/wild-config": "1.7.10",
78
+ "bullmq": "6.4.0",
79
+ "dotenv": "18.0.9",
80
80
  "fast-xml-parser": "5.11.2",
81
- "gettext-parser": "7.0.1",
82
81
  "handlebars": "4.7.10",
83
- "hapi-pino": "13.0.0",
84
82
  "he": "1.2.0",
85
83
  "html-to-text": "10.0.1",
86
84
  "ical.js": "2.2.1",
87
85
  "iconv-lite": "0.7.3",
88
- "imapflow": "2.5.5",
89
- "ioredfour": "1.4.4",
86
+ "imapflow": "2.9.1",
87
+ "ioredfour": "2.2.0",
90
88
  "ioredis": "6.0.0",
91
89
  "ipaddr.js": "2.5.0",
92
90
  "joi": "18.3.0",
93
91
  "libbase64": "1.4.1",
94
- "libmime": "5.5.1",
92
+ "libmime": "5.6.3",
95
93
  "libqp": "3.0.1",
96
- "mailparser": "3.9.46",
94
+ "mailparser": "3.12.4",
97
95
  "marked": "15.0.12",
98
96
  "minimist": "1.2.8",
99
- "murmurhash": "2.0.1",
100
- "nanoid": "3.3.20",
101
- "nodemailer": "10.1.7",
97
+ "nodemailer": "10.2.1",
102
98
  "pino": "10.3.1",
103
99
  "prom-client": "15.1.3",
104
- "psl": "1.15.0",
105
- "pubface": "1.1.18",
100
+ "pubface": "1.2.0",
106
101
  "punycode.js": "2.3.1",
107
102
  "qrcode-generator": "2.0.4",
108
- "smtp-server": "3.20.2",
103
+ "smtp-server": "3.21.1",
109
104
  "socks": "2.8.10",
110
- "timezones-list": "3.1.0",
111
105
  "undici": "7.30.1"
112
106
  },
113
107
  "devDependencies": {
@@ -118,13 +112,15 @@
118
112
  "@postalsys/ee-client": "1.8.2",
119
113
  "@simplewebauthn/browser": "14.0.0",
120
114
  "@tailwindcss/cli": "4.3.3",
121
- "ace-builds": "1.45.0",
115
+ "ace-builds": "1.45.2",
122
116
  "acorn": "8.19.0",
123
117
  "acorn-walk": "8.3.5",
124
- "chai": "4.5.0",
125
118
  "eerawlog": "1.5.5",
126
119
  "eslint": "10.13.0",
120
+ "eslint-config-prettier": "10.1.8",
127
121
  "flyonui": "2.4.1",
122
+ "gettext-parser": "7.0.1",
123
+ "globals": "17.13.0",
128
124
  "pino-pretty": "13.2.0",
129
125
  "prettier": "3.9.10",
130
126
  "resedit": "3.1.0",
@@ -134,10 +130,11 @@
134
130
  "xgettext-template": "5.0.0"
135
131
  },
136
132
  "overrides": {
137
- "@asamuzakjp/css-color": "4.1.1"
133
+ "@asamuzakjp/css-color": "4.1.1",
134
+ "cheerio": "1.2.0"
138
135
  },
139
136
  "engines": {
140
- "node": ">=20.0.0"
137
+ "node": ">=20.19.0"
141
138
  },
142
139
  "pkg": {
143
140
  "scripts": [
@@ -154,7 +151,8 @@
154
151
  "node_modules/jsdom/lib/jsdom/browser/default-stylesheet.css",
155
152
  "LICENSE_EMAILENGINE.txt",
156
153
  "version-info.json",
157
- "sbom.json"
154
+ "sbom.json",
155
+ "data/public_suffix_list.dat"
158
156
  ],
159
157
  "targets": [
160
158
  "node24-linux-x64",
@@ -164,7 +162,8 @@
164
162
  ],
165
163
  "outputPath": "ee-dist",
166
164
  "options": [
167
- "max_old_space_size=4096"
165
+ "max_old_space_size=4096",
166
+ "max_semi_space_size=16"
168
167
  ]
169
168
  }
170
169
  }