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
package/.ncurc.js CHANGED
@@ -1,26 +1,36 @@
1
1
  module.exports = {
2
2
  upgrade: true,
3
+ // Node 20 is a hard runtime floor, not a preference. The DigitalOcean one-click images run
4
+ // EmailEngine on Node 20 and ship an upgrade script for EmailEngine but none for Node, so those
5
+ // installs keep self-updating on a runtime that never moves; raising the floor breaks them on
6
+ // their next upgrade. Node 20 being EOL upstream, and CI and the pkg targets being on Node 24,
7
+ // do not lift this. Treat "needs Node >20" as a permanent reject.
8
+ //
3
9
  // Packages capped inside their current major: the next major is ESM-only (this codebase is
4
- // CommonJS and is bundled into a binary with pkg) or it breaks a peer dependency. Using 'minor'
5
- // instead of a blanket reject so these still receive security/patch updates within the safe
6
- // major instead of being frozen at one exact version. Verified against Node 20 (Docker) 2026-06-17.
7
- target: name =>
8
- ['nanoid', 'ical.js', 'gettext-parser', 'xgettext-template', 'chai', 'undici', 'marked', 'bullmq', 'ioredis'].includes(name) ? 'minor' : 'latest',
10
+ // CommonJS and is bundled into a binary with pkg), needs a Node newer than the floor above, or
11
+ // is a major we are deliberately soaking. Using 'minor' instead of a blanket reject so these
12
+ // still receive security/patch updates within the safe major instead of being frozen at one
13
+ // exact version. Verified against Node 20 (Docker) 2026-06-17.
14
+ target: name => (['nanoid', 'ical.js', 'gettext-parser', 'xgettext-template', 'chai', 'undici', 'marked'].includes(name) ? 'minor' : 'latest'),
9
15
  // nanoid - 4.x dropped the CommonJS require export (ESM-only)
10
16
  // ical.js - 2.x is ESM-only
11
17
  // gettext-parser - 8.x is ESM-only
12
18
  // xgettext-template - 6.x is ESM-only (translation build tool)
13
19
  // chai - 5.x is ESM-only (only used by the vendored imap-core tests)
14
- // undici - 8.x requires Node >=22.19 and crashes at require() on Node 20; EmailEngine supports Node 20+
20
+ // undici - 8.x requires Node >=22.19 and crashes at require() on Node 20. Permanent while the
21
+ // Node 20 floor above stands.
15
22
  // marked - 16.x dropped the CommonJS build (ESM-only, needs require(esm)/Node >=20.19); 15.x is the
16
23
  // last require()-compatible line. 15.0.12 verified on Node 20-24 and in a yao/pkg node24 build.
17
- // bullmq - 6.x drops ioredis entirely, and @bull-board/api still peer-requires bullmq ^5.79.2, so the
18
- // install fails outright (ERESOLVE) on the queue browser we mount at /admin/bull-board.
19
- // Lift when bull-board ships bullmq 6 support.
20
- // ioredis - 6.x is held back BY the bullmq cap above, not on its own merits. lib/db.js creates the
21
- // client and hands it to bullmq as `connection` for all four queues, while bullmq 5 pins
22
- // ioredis 5.11.1 as a direct dependency - so bumping ours to 6 would drive bullmq 5's
23
- // internals with a client it was not written against. These two move together.
24
+ // Permanent while the Node 20 floor above stands.
25
+ //
26
+ // bullmq was capped at 5.x until 2026-08-17, when both stated reasons had expired. Now on 6.x, which
27
+ // moves cron-parser off the deprecated 4.9.0 onto 5.x - but not off luxon, which cron-parser depends
28
+ // on in both majors.
29
+ //
30
+ // ioredis was capped at 5.x for the same span, held there BY the bullmq cap (bullmq 5 carried ioredis
31
+ // as a direct dependency; 6.x demoted it to an optional peer, which dissolved the coupling). Now on
32
+ // 6.x, whose one breaking change is that it speaks RESP3 by default - taken as-is, since RESP3 was
33
+ // verified against everything here that could plausibly differ (see the commit that made the move).
24
34
  //
25
35
  // joi used to be capped here because hapi-swagger peer-required 17.x. That dependency is gone
26
36
  // (the OpenAPI document is generated by lib/openapi/ now), so joi may move majors again. A major
@@ -1,3 +1,3 @@
1
1
  {
2
- ".": "2.78.0"
2
+ ".": "2.79.1"
3
3
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,73 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.79.1](https://github.com/postalsys/emailengine/compare/v2.79.0...v2.79.1) (2026-08-19)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **admin:** flag webhook routes that can never deliver on the account page ([416f612](https://github.com/postalsys/emailengine/commit/416f612b616380371f825d673c0b80ad0f975924))
9
+ * **admin:** percent-encode an account or gateway ID interpolated into a link ([522d267](https://github.com/postalsys/emailengine/commit/522d2673eeb33c2f9cc85e7faf78550b99afe361))
10
+ * **admin:** percent-encode every ID a redirect interpolates ([d21c2ab](https://github.com/postalsys/emailengine/commit/d21c2ab5d5892fb94e85a2962a2a252fc865a03d))
11
+ * **admin:** probe a listing's accounts in one round trip ([a9a4c8a](https://github.com/postalsys/emailengine/commit/a9a4c8aeeb30b16b09f22e62847bb93671e8e46d))
12
+ * **admin:** stop reporting a suppression-list read failure as a missing list ([bd414a9](https://github.com/postalsys/emailengine/commit/bd414a94e7ff51f3c6cd68241ff3b94c8996ed2d))
13
+ * **downloads:** end a cross-thread transfer when the peer closes the channel ([8875e79](https://github.com/postalsys/emailengine/commit/8875e799b7d2d365822f3666160450e137130673))
14
+ * **downloads:** notice a consumer that closed the channel before the transfer began ([ce295e6](https://github.com/postalsys/emailengine/commit/ce295e6060c556a0223bbc7bce11078513cbd0ae))
15
+ * **downloads:** stop an aborted attachment download from killing the IMAP worker ([f937993](https://github.com/postalsys/emailengine/commit/f937993b47c518683da3137eebcc7188c8bd9f3e))
16
+ * **gmail:** keep prototype-shaped header names from breaking message formatting ([a494f13](https://github.com/postalsys/emailengine/commit/a494f1308f04fd24dc1ce9bceb27a46ca326fa71))
17
+ * **headers:** drop a __proto__ field name when parsing a header block ([fae64fd](https://github.com/postalsys/emailengine/commit/fae64fd5754f8236b51c26f6095df5c81f299a90))
18
+ * **headers:** drop a constructor field name too, and guard the bounced-message map ([b5fcf32](https://github.com/postalsys/emailengine/commit/b5fcf32003d99254e8288ad2c7d330d14d138637))
19
+ * **headers:** drop a prototype-shaped field name the camelCase step re-creates ([77a3beb](https://github.com/postalsys/emailengine/commit/77a3bebaff9ca61de2ebff875cd50cd9648533c6))
20
+ * **imap:** keep a prototype-shaped content subtype from breaking a text fetch ([d90e013](https://github.com/postalsys/emailengine/commit/d90e0131f236a085bf10537f567b267de0a25481))
21
+ * **imap:** release the mailbox lock when a download resolves without a stream ([8513432](https://github.com/postalsys/emailengine/commit/8513432f9968061eb01fef8e90654904ebdce3cf))
22
+ * **imap:** return the connection to its mailbox after a download or text fetch ([33db6a2](https://github.com/postalsys/emailengine/commit/33db6a20ed64112d9f5c446f89abb82fb9f33101))
23
+ * **imap:** return the connection to its mailbox after deleting one ([0cac841](https://github.com/postalsys/emailengine/commit/0cac8418a296b0bea41c646bcaa539b2862eed69))
24
+ * **imap:** return the connection to its mailbox after renaming one ([6014093](https://github.com/postalsys/emailengine/commit/601409377c19f7f16eb9d8d60d88b5b906ecf1b1))
25
+ * **imap:** stop a secondary connection's task from re-selecting the primary mailbox ([d12a046](https://github.com/postalsys/emailengine/commit/d12a046eaa5d9ef584bc8c88778fcfedc3e3d533))
26
+ * **metrics:** derive the Prometheus queue gauges from BullMQ itself ([7968678](https://github.com/postalsys/emailengine/commit/796867886a2d8ba9ad0e8fee8e9d53dea1af5b3d))
27
+ * **oauth2:** harden the legacy app migration and restore the auth-failure alert ([50710be](https://github.com/postalsys/emailengine/commit/50710bebe5b4c108313add39beabe74e6c0dd0f8))
28
+ * **reference:** leave the deprecated token aliases out of the published document ([1ff4697](https://github.com/postalsys/emailengine/commit/1ff46975d47f130289d2cb2702d11cedbf16a6b6))
29
+ * **reports:** drop every prototype-shaped name a camelCased report can carry ([77abf0e](https://github.com/postalsys/emailengine/commit/77abf0ee7b3266de92885e66ae48824598dc822f))
30
+ * **settings:** refuse masked credential values posted back to the settings API ([7e51155](https://github.com/postalsys/emailengine/commit/7e51155641b72f2622d0d6f7c31d94e2b01ef9fa))
31
+ * **settings:** seed the trial Sentry default atomically ([1e276f8](https://github.com/postalsys/emailengine/commit/1e276f8ef0dac49a6c4fe3470fff572f57cfab94))
32
+ * **startup:** name the prepared-settings keys that get ignored ([9e23ceb](https://github.com/postalsys/emailengine/commit/9e23ceb9d20dff5f7c64690f71f307bf427bac59))
33
+ * **tokens:** bind an access token to an account from the create form ([6f4fc93](https://github.com/postalsys/emailengine/commit/6f4fc936ef254710b7bc99582776c6d1700d7195))
34
+ * **tokens:** keep the audit log page size default inside its own range ([c688756](https://github.com/postalsys/emailengine/commit/c6887564e0ef20e9e5c2b4ec4a5560d3eec3fc8d))
35
+ * **tokens:** raise the audit log retention cap and bound the account it stores ([6c8039a](https://github.com/postalsys/emailengine/commit/6c8039a1fb2bc5325a8b815a79b51d4f318a059f))
36
+ * **tokens:** register the pre-2.79 token endpoints as deprecated aliases ([5cb2887](https://github.com/postalsys/emailengine/commit/5cb2887c6c6c94e7b3dd9686f5223ae6b7dafb29))
37
+ * **tokens:** revoke an account's access tokens when the account is deleted ([61c9a17](https://github.com/postalsys/emailengine/commit/61c9a178c8a55b4f869fc8d204755519f48a3e48))
38
+ * **tokens:** show account-bound tokens on the Access Tokens page ([716ca0d](https://github.com/postalsys/emailengine/commit/716ca0dc5a56a9d853c5064f4c059fbefd8b0551))
39
+ * **tokens:** stop a whitespace-only search from reading every record ([eb1f398](https://github.com/postalsys/emailengine/commit/eb1f398f5a99c613e4fe30d5e91a93cd80399603))
40
+ * **webhooks:** log the reason a delivery is skipped ([c34df7d](https://github.com/postalsys/emailengine/commit/c34df7d0fbe1724e2bea8baa1d66ce3e7a3e3f40))
41
+
42
+ ## [2.79.0](https://github.com/postalsys/emailengine/compare/v2.78.0...v2.79.0) (2026-08-18)
43
+
44
+
45
+ ### Features
46
+
47
+ * **lists:** add suppression list management to the admin UI ([d684030](https://github.com/postalsys/emailengine/commit/d6840305a3dc0940f248c12e650e068aed866e28))
48
+ * **lists:** link suppression entries to the subscription management page ([b4e1d49](https://github.com/postalsys/emailengine/commit/b4e1d49ff105d95f24462b8ceb0f80b453378cc9))
49
+ * **oauth2:** migrate legacy settings-based OAuth2 apps into the app registry ([4aeb7f5](https://github.com/postalsys/emailengine/commit/4aeb7f5bee45d0ec32ab17d72252bf8d13b57018))
50
+ * **reference:** confirm irreversible Try it requests before running them ([546c32e](https://github.com/postalsys/emailengine/commit/546c32e352a70061ae188c59f54b78933d2bde20))
51
+ * **reference:** edit Try it request bodies in a JSON editor ([dbd38e8](https://github.com/postalsys/emailengine/commit/dbd38e857f16a1ce28c86a32a9105b0e5cb36ca6))
52
+ * **reference:** make large schemas readable in the API reference ([9874821](https://github.com/postalsys/emailengine/commit/9874821288f543d531af757366eced663b738705))
53
+ * **reference:** show an example value and usage guidance for every field ([c974f19](https://github.com/postalsys/emailengine/commit/c974f19e393c6d7519c3599b772a58a898f7c4ce))
54
+ * **reference:** warn in Try it only where running the request has a consequence ([4f53d02](https://github.com/postalsys/emailengine/commit/4f53d02d068f88707419aaffecee6618b2f0bd71))
55
+ * **sentry:** enable error reporting by default for trial licenses ([9c918bc](https://github.com/postalsys/emailengine/commit/9c918bcb9cbb45113c1006db649a6fbf871c6c81))
56
+ * **tokens:** granular access token permissions ([#633](https://github.com/postalsys/emailengine/issues/633)) ([f30bf0a](https://github.com/postalsys/emailengine/commit/f30bf0a838958f64a057afe8f44767a0b3de306a))
57
+ * **webhooks:** show the effective webhook routing on the account page ([0cdbbff](https://github.com/postalsys/emailengine/commit/0cdbbffacfc19ed7af2ef200061edd7e06930b26))
58
+
59
+
60
+ ### Bug Fixes
61
+
62
+ * **deps:** move to ioredis 6 ([da4904a](https://github.com/postalsys/emailengine/commit/da4904aba141f7fffeef2200a726254994ae3f9b))
63
+ * **deps:** override deepmerge-ts to clear GHSA-ggr8-5vv4-36mx ([#635](https://github.com/postalsys/emailengine/issues/635)) ([6d68432](https://github.com/postalsys/emailengine/commit/6d6843217ee5246e150e66307e2c2bae94fbc89b))
64
+ * **deps:** refresh dependencies and dedupe node-html-parser ([5502c04](https://github.com/postalsys/emailengine/commit/5502c0467da52eb2d285c1a057818d6c0eb7694e))
65
+ * **logging:** standardize log levels and keep credentials out of error logs ([a229bdc](https://github.com/postalsys/emailengine/commit/a229bdca3b8662338db889568fa132503c5e89c9))
66
+ * **queues:** move to BullMQ 6 and fix outbox paging ([eba0761](https://github.com/postalsys/emailengine/commit/eba0761f162c2561bab81460b481743e42ab4608))
67
+ * **reference:** count the minted token's expiry down while the page is open ([356dfd0](https://github.com/postalsys/emailengine/commit/356dfd0ac9178bcd2ad007f351c2ded3af0936ce))
68
+ * **ui:** share the confirm dialog helper and stop the reference page scrolling sideways ([994ddec](https://github.com/postalsys/emailengine/commit/994ddec7d42c91c1a7ea5167cfe5ee6df689b4d2))
69
+ * **ui:** stop partial blocks from losing content wrapped in a bare condition ([0887172](https://github.com/postalsys/emailengine/commit/0887172c4fe18d23c8a3bd9f9d26249fc7551a9a))
70
+
3
71
  ## [2.78.0](https://github.com/postalsys/emailengine/compare/v2.77.0...v2.78.0) (2026-08-12)
4
72
 
5
73
 
package/config/e2e.toml CHANGED
@@ -12,7 +12,8 @@
12
12
  settings = '''
13
13
  {
14
14
  "serviceUrl": "https://e2e.emailengine.app/",
15
- "ignoreMailCertErrors": true
15
+ "ignoreMailCertErrors": true,
16
+ "sentryEnabled": false
16
17
  }
17
18
  '''
18
19
 
package/config/test.toml CHANGED
@@ -14,7 +14,8 @@ settings = '''
14
14
  ],
15
15
  "serviceUrl": "http://127.0.0.1:7077",
16
16
  "ignoreMailCertErrors": true,
17
- "serviceSecret": "a cat"
17
+ "serviceSecret": "a cat",
18
+ "sentryEnabled": false
18
19
  }
19
20
  '''
20
21
 
@@ -1,5 +1,5 @@
1
1
  {
2
- "creationTime": "2026-08-11T14:47:00.000000",
2
+ "creationTime": "2026-08-14T14:46:51.000000",
3
3
  "prefixes": [
4
4
  {
5
5
  "ipv6Prefix": "2001:4860:4801:2008::/64"
package/lib/account.js CHANGED
@@ -20,12 +20,14 @@ const { MessageChannel } = require('worker_threads');
20
20
  const { MessagePortReadable } = require('./message-port-stream');
21
21
  const { deepStrictEqual, strictEqual } = require('assert');
22
22
  const { encrypt, decrypt } = require('./encrypt');
23
- const { oauth2Apps, LEGACY_KEYS, isApiBasedApp } = require('./oauth2-apps');
23
+ const { oauth2Apps, isApiBasedApp } = require('./oauth2-apps');
24
24
  const settings = require('./settings');
25
25
  const { buildRetentionPolicy } = require('./queue-retention');
26
26
  const { isDocumentStoreEnabled, documentStoreFeatureEnabled } = require('./document-store');
27
27
  const redisScanDelete = require('./redis-scan-delete');
28
+ const { extractMultiValues } = require('./redis-operations');
28
29
  const outbox = require('./outbox');
30
+ const tokens = require('./tokens');
29
31
  const { customAlphabet } = require('nanoid');
30
32
  const Lock = require('ioredfour');
31
33
  const { redis } = require('./db');
@@ -301,6 +303,20 @@ class Account {
301
303
  return `${REDIS_PREFIX}iap:${this.account}`;
302
304
  }
303
305
 
306
+ // Shared log entry for unserializeAccountData() failures. The raw value is withheld on
307
+ // purpose: imap/smtp/oauth2 payloads may carry cleartext credentials when no EENGINE_SECRET is
308
+ // set, so only its length is logged. `ownerAccount` is the row's own marker when available -
309
+ // listAccounts() unserializes other accounts' rows on an instance whose own account id is false.
310
+ logUnserializeFailure(msg, key, rawValue, ownerAccount, err) {
311
+ this.logger.error({
312
+ msg,
313
+ key,
314
+ valueLength: (rawValue || '').toString().length,
315
+ account: ownerAccount || this.account || undefined,
316
+ err
317
+ });
318
+ }
319
+
304
320
  unserializeAccountData(accountData) {
305
321
  const result = {};
306
322
 
@@ -371,7 +387,7 @@ class Account {
371
387
  }
372
388
  result[key] = value;
373
389
  } catch (err) {
374
- this.logger.error({ msg: 'Failed to parse input from Redis', key, value: accountData[key], err });
390
+ this.logUnserializeFailure('Failed to parse input from Redis', key, accountData[key], accountData.account, err);
375
391
  }
376
392
  } else {
377
393
  // regular string
@@ -391,7 +407,7 @@ class Account {
391
407
  }
392
408
  result[key] = value;
393
409
  } catch (err) {
394
- this.logger.error({ msg: 'Failed to parse input from Redis', key, value: accountData[key], err });
410
+ this.logUnserializeFailure('Failed to parse input from Redis', key, accountData[key], accountData.account, err);
395
411
  }
396
412
  break;
397
413
 
@@ -412,7 +428,7 @@ class Account {
412
428
 
413
429
  result[key] = value;
414
430
  } catch (err) {
415
- this.logger.error({ msg: 'Failed to parse input from Redis', key, value: accountData[key], err });
431
+ this.logUnserializeFailure('Failed to parse input from Redis', key, accountData[key], accountData.account, err);
416
432
  }
417
433
  break;
418
434
 
@@ -446,7 +462,7 @@ class Account {
446
462
  }
447
463
  }
448
464
  } catch (err) {
449
- this.logger.error({ msg: 'Failed to parse input from Redis', key, value: accountData[key], err });
465
+ this.logUnserializeFailure('Failed to parse input from Redis', key, accountData[key], accountData.account, err);
450
466
  }
451
467
  break;
452
468
 
@@ -473,14 +489,14 @@ class Account {
473
489
  result[type].auth[key] = decrypt(result[type].auth[key], this.secret);
474
490
  } catch (err) {
475
491
  // ignore??
476
- this.logger.error({ msg: 'Failed to decrypt value', encrypted: result[type].auth[key], err });
492
+ this.logUnserializeFailure('Failed to decrypt value', key, result[type].auth[key], result.account, err);
477
493
  }
478
494
  } else if (key in result[type]) {
479
495
  try {
480
496
  result[type][key] = decrypt(result[type][key], this.secret);
481
497
  } catch (err) {
482
498
  // ignore??
483
- this.logger.error({ msg: 'Failed to decrypt value', encrypted: result[type][key], err });
499
+ this.logUnserializeFailure('Failed to decrypt value', key, result[type][key], result.account, err);
484
500
  }
485
501
  }
486
502
  }
@@ -550,7 +566,7 @@ class Account {
550
566
  try {
551
567
  result[key] = JSON.stringify(accountData[key]);
552
568
  } catch (err) {
553
- this.logger.error({ msg: 'Failed to stringify input for Redis', key, err });
569
+ this.logger.error({ msg: 'Failed to stringify input for Redis', key, account: this.account, err });
554
570
  }
555
571
  }
556
572
  break;
@@ -565,7 +581,7 @@ class Account {
565
581
 
566
582
  result[key] = value;
567
583
  } catch (err) {
568
- this.logger.error({ msg: 'Failed to stringify input for Redis', key, err });
584
+ this.logger.error({ msg: 'Failed to stringify input for Redis', key, account: this.account, err });
569
585
  }
570
586
 
571
587
  break;
@@ -593,7 +609,7 @@ class Account {
593
609
 
594
610
  result[key] = value;
595
611
  } catch (err) {
596
- this.logger.error({ msg: 'Failed to stringify input for Redis', key, err });
612
+ this.logger.error({ msg: 'Failed to stringify input for Redis', key, account: this.account, err });
597
613
  }
598
614
 
599
615
  break;
@@ -612,13 +628,13 @@ class Account {
612
628
  try {
613
629
  connectData.auth[key] = encrypt(connectData.auth[key], this.secret);
614
630
  } catch (err) {
615
- this.logger.error({ msg: 'Failed to encrypt value', err });
631
+ this.logger.error({ msg: 'Failed to encrypt value', key, account: this.account, err });
616
632
  }
617
633
  } else if (key in connectData) {
618
634
  try {
619
635
  connectData[key] = encrypt(connectData[key], this.secret);
620
636
  } catch (err) {
621
- this.logger.error({ msg: 'Failed to encrypt value', err });
637
+ this.logger.error({ msg: 'Failed to encrypt value', key, account: this.account, err });
622
638
  }
623
639
  }
624
640
  }
@@ -636,7 +652,7 @@ class Account {
636
652
 
637
653
  result[key] = JSON.stringify(connectData);
638
654
  } catch (err) {
639
- this.logger.error({ msg: 'Failed to stringify input for Redis', key, err });
655
+ this.logger.error({ msg: 'Failed to stringify input for Redis', key, account: this.account, err });
640
656
  }
641
657
  break;
642
658
 
@@ -799,7 +815,7 @@ class Account {
799
815
  await lock.releaseLock(updateLock);
800
816
  } catch (err) {
801
817
  // The lock expires on its own, so a failed release must not mask the result
802
- this.logger.error({ msg: 'Failed to release account update lock', account: accountData.account, lockKey, err });
818
+ this.logger.warn({ msg: 'Failed to release account update lock', account: accountData.account, lockKey, err });
803
819
  }
804
820
  }
805
821
  }
@@ -870,7 +886,7 @@ class Account {
870
886
  pipeline = pipeline.hmset(this.getAccountKey(), updatedFields);
871
887
  }
872
888
 
873
- if (addProvider && !LEGACY_KEYS.includes(addProvider)) {
889
+ if (addProvider) {
874
890
  pipeline = pipeline.sadd(`${REDIS_PREFIX}oapp:a:${addProvider}`, this.account);
875
891
  if (accountData._oldOAuth2User && accountData._oldOAuth2User.toLowerCase() !== accountData.oauth2.auth?.user?.toLowerCase()) {
876
892
  pipeline = pipeline.hdel(`${REDIS_PREFIX}oapp:h:${addProvider}`, accountData._oldOAuth2User.toLowerCase());
@@ -1235,7 +1251,6 @@ class Account {
1235
1251
  .unlink(`${REDIS_PREFIX}iar:b:${this.account}`) // bounce list
1236
1252
  .unlink(`${REDIS_PREFIX}iar:s:${this.account}`) // seen messages list
1237
1253
  .unlink(`${REDIS_PREFIX}iaq:${this.account}`) // delayed message queue
1238
- .unlink(`${REDIS_PREFIX}iat:${this.account}`) // access tokens
1239
1254
  .unlink(`${REDIS_PREFIX}iac:${this.account}`) // cache hash
1240
1255
  .unlink(`${REDIS_PREFIX}iap:${this.account}`) // external event notification queue
1241
1256
 
@@ -1254,6 +1269,18 @@ class Account {
1254
1269
 
1255
1270
  let result = await pipeline.exec();
1256
1271
 
1272
+ // The account's access tokens go with it - see tokens.deleteForAccount(), which owns the
1273
+ // account's token index too. Deliberately on this side of the transaction: while the account
1274
+ // record exists a token can still be minted against it, and both mint paths check that
1275
+ // record first, so revoking once it is unlinked closes all but a vanishing window. Best
1276
+ // effort, like the queued messages below - the account still has to go, and anything left
1277
+ // behind stays on the access token listing, marked as bound to a deleted account.
1278
+ try {
1279
+ await tokens.deleteForAccount(this.account);
1280
+ } catch (err) {
1281
+ this.logger.error({ msg: 'Failed to delete the access tokens of an account', account: this.account, err });
1282
+ }
1283
+
1257
1284
  // Results are positional: [0] is the outbox HKEYS, [1] the account key UNLINK. Both indexes
1258
1285
  // move if a command is inserted ahead of them.
1259
1286
  let queuedMessageIds = (result && result[0] && result[0][1]) || [];
@@ -1303,7 +1330,7 @@ class Account {
1303
1330
  }
1304
1331
  });
1305
1332
  } catch (err) {
1306
- this.logger.error({ msg: 'Failed to add entry to documents queue', err });
1333
+ this.logger.error({ msg: 'Failed to add entry to documents queue', account: this.account, err });
1307
1334
  }
1308
1335
  }
1309
1336
 
@@ -1478,7 +1505,7 @@ class Account {
1478
1505
  // its own state against this endpoint reads as a deletion.
1479
1506
  let decoded = decodeStoredMailboxEntry(storedListing[path]);
1480
1507
  if (!decoded) {
1481
- this.logger.error({ msg: 'Skipping corrupt stored mailbox listing entry', path, account: this.account });
1508
+ this.logger.warn({ msg: 'Skipping corrupt stored mailbox listing entry', path, account: this.account });
1482
1509
  continue;
1483
1510
  }
1484
1511
 
@@ -1899,7 +1926,7 @@ class Account {
1899
1926
  messageData.flags.push('\\Seen');
1900
1927
  // do not wait until the update is completed, return immediately
1901
1928
  this.updateMessage(message, { flags: { add: ['\\Seen'] } }).catch(err => {
1902
- this.logger.error({ msg: 'Failed to mark message as Seen', message, err });
1929
+ this.logger.error({ msg: 'Failed to mark message as Seen', account: this.account, message, err });
1903
1930
  });
1904
1931
  }
1905
1932
 
@@ -2379,7 +2406,14 @@ class Account {
2379
2406
 
2380
2407
  this.logger.trace({
2381
2408
  msg: 'Executed ES query',
2382
- query: { type: 'search', index, size: pageSize, from: pageSize * page, query: searchQuery, sort: { uid: 'desc' } },
2409
+ query: {
2410
+ type: 'search',
2411
+ index,
2412
+ size: pageSize,
2413
+ from: pageSize * page,
2414
+ query: searchQuery,
2415
+ sort: { [!searchOpts.unified ? 'uid' : 'date']: 'desc' }
2416
+ },
2383
2417
  results: searchResult.hits.total.value
2384
2418
  });
2385
2419
 
@@ -2545,17 +2579,19 @@ class Account {
2545
2579
  try {
2546
2580
  flushLock = await lock.acquireLock(lockKey, 30 * 60 * 1000);
2547
2581
  if (!flushLock.success) {
2548
- this.logger.error({ msg: 'Failed to get lock', lockKey });
2582
+ // contention: another flush already holds the lock
2583
+ this.logger.warn({ msg: 'Failed to get flush lock, another flush is already running', account: this.account, lockKey });
2549
2584
 
2550
2585
  let error = Boom.boomify(new Error('One flush operation at a time allowed, try again later'), { statusCode: 429 });
2551
2586
  error.output.payload.code = 'LockFail';
2552
2587
  throw error;
2553
2588
  }
2554
2589
  } catch (err) {
2555
- this.logger.error({ msg: 'Failed to get lock', lockKey, err });
2556
2590
  if (Boom.isBoom(err)) {
2591
+ // contention was already logged above
2557
2592
  throw err;
2558
2593
  }
2594
+ this.logger.error({ msg: 'Failed to get flush lock', account: this.account, lockKey, err });
2559
2595
  let error = Boom.boomify(new Error('Failed to get flush lock, try again later'), { statusCode: 500 });
2560
2596
  if (err.code) {
2561
2597
  error.output.payload.code = err.code || 'LockFail';
@@ -2634,7 +2670,7 @@ class Account {
2634
2670
  });
2635
2671
  deletedCount += deleteResult[indexName].deleted || 0;
2636
2672
  } catch (err) {
2637
- logger.error({
2673
+ this.logger.error({
2638
2674
  msg: 'Failed to delete account emails from index',
2639
2675
  action: 'flush',
2640
2676
  code: 'document_delete_account_error',
@@ -2648,10 +2684,11 @@ class Account {
2648
2684
  }
2649
2685
  }
2650
2686
 
2651
- logger.trace({
2687
+ this.logger.trace({
2652
2688
  msg: 'Deleted account emails from index',
2653
2689
  action: 'flush',
2654
2690
  code: 'document_delete_account',
2691
+ account: this.account,
2655
2692
  deletedCount,
2656
2693
  deleteResult
2657
2694
  });
@@ -2693,11 +2730,15 @@ class Account {
2693
2730
  try {
2694
2731
  renewLock = await lock.waitAcquireLock(lockKey, 5 * 60 * 1000, 1 * 60 * 1000);
2695
2732
  if (!renewLock.success) {
2696
- this.logger.error({ msg: 'Failed to get lock', lockKey });
2733
+ // contention: timed out waiting for the current lock holder
2734
+ this.logger.warn({ msg: 'Failed to get renewal lock, timed out waiting for the current holder', account: this.account, lockKey });
2697
2735
  throw new Error('Failed to get renewal lock');
2698
2736
  }
2699
2737
  } catch (err) {
2700
- this.logger.error({ msg: 'Failed to get lock', lockKey, err });
2738
+ if (!renewLock) {
2739
+ // unexpected lock-layer error; contention was already logged above
2740
+ this.logger.error({ msg: 'Failed to get renewal lock', account: this.account, lockKey, err });
2741
+ }
2701
2742
  let error = Boom.boomify(new Error('Failed to get renewal lock'), { statusCode: 500 });
2702
2743
  if (err.code) {
2703
2744
  error.output.payload.code = err.code || 'LockFail';
@@ -2718,7 +2759,7 @@ class Account {
2718
2759
  this.logger.info({
2719
2760
  msg: 'OAuth2 access token renewed while locked',
2720
2761
  action: 'ensureAccessToken',
2721
- error: null,
2762
+ account: this.account,
2722
2763
  user: accountData.oauth2.auth.user,
2723
2764
  expires: accountData.oauth2.expires,
2724
2765
  scopes: accountData.oauth2.scope,
@@ -2766,7 +2807,7 @@ class Account {
2766
2807
  this.logger.info({
2767
2808
  msg: 'Renewed OAuth2 access token',
2768
2809
  action: 'ensureAccessToken',
2769
- error: null,
2810
+ account: this.account,
2770
2811
  user: accountData.oauth2.auth.user,
2771
2812
  expires: updates.expires,
2772
2813
  scopes: updates.scope,
@@ -2777,12 +2818,11 @@ class Account {
2777
2818
 
2778
2819
  return accountData;
2779
2820
  } catch (err) {
2780
- this.logger.info({
2821
+ this.logger.warn({
2781
2822
  msg: 'Failed to renew OAuth2 access token',
2782
2823
  action: 'ensureAccessToken',
2783
- error: err,
2784
- response: err.tokenRequest && err.tokenRequest.response,
2785
- flag: err.tokenRequest && err.tokenRequest.flag
2824
+ account: this.account,
2825
+ err
2786
2826
  });
2787
2827
 
2788
2828
  if (err.tokenRequest?.userFlag) {
@@ -2802,7 +2842,7 @@ class Account {
2802
2842
  if (accountData.oauth2) {
2803
2843
  accountData.oauth2.expires = new Date(Date.now() - 24 * 3600 * 1000).toISOString();
2804
2844
  await this.update({ account: accountData.account, oauth2: accountData.oauth2 });
2805
- this.logger.info({ msg: 'Invalidated the OAuth2 access token', expires: accountData.oauth2.expires });
2845
+ this.logger.info({ msg: 'Invalidated the OAuth2 access token', account: this.account, expires: accountData.oauth2.expires });
2806
2846
  }
2807
2847
  return accountData;
2808
2848
  }
@@ -2935,17 +2975,18 @@ class Account {
2935
2975
  this.logger.debug({
2936
2976
  msg: 'MS Graph subscription event',
2937
2977
  type: 'event',
2978
+ account: this.account,
2938
2979
  event,
2939
2980
  res
2940
2981
  });
2941
2982
  } catch (err) {
2942
- this.logger.error({ msg: 'Failed to insert event to account queue', event, err });
2983
+ this.logger.error({ msg: 'Failed to insert event to account queue', account: this.account, event, err });
2943
2984
  }
2944
2985
 
2945
2986
  try {
2946
2987
  await this.call({ cmd: 'externalNotify', accounts: [this.account] });
2947
2988
  } catch (err) {
2948
- logger.error({ msg: 'Failed to notify about queue changes', err });
2989
+ this.logger.error({ msg: 'Failed to notify about queue changes', account: this.account, err });
2949
2990
  }
2950
2991
  }
2951
2992
 
@@ -2966,4 +3007,39 @@ class Account {
2966
3007
  }
2967
3008
  }
2968
3009
 
2969
- module.exports = { Account };
3010
+ // Cheap existence probe that does not load or decrypt account data. The `account` field is
3011
+ // the mandatory marker field of the account hash (the same idiom the notify worker and
3012
+ // genId() rely on), so its presence is the canonical "this account exists" signal.
3013
+ async function accountExists(redis, account) {
3014
+ return (await redis.hexists(`${REDIS_PREFIX}iad:${account}`, 'account')) === 1;
3015
+ }
3016
+
3017
+ /**
3018
+ * Same question as accountExists(), asked about a list of accounts in one round trip.
3019
+ *
3020
+ * lib/db.js enables no auto-pipelining, so probing a listing page's accounts one at a time is a
3021
+ * socket write each - up to 250 on the admin listings that call this.
3022
+ *
3023
+ * @param {Object} redis - Redis client
3024
+ * @param {Array} accounts - Account IDs to probe
3025
+ * @returns {Promise<Map<String, Boolean>>} keyed by account ID, in the order given
3026
+ */
3027
+ async function accountsExist(redis, accounts) {
3028
+ if (!accounts || !accounts.length) {
3029
+ return new Map();
3030
+ }
3031
+
3032
+ let pipeline = redis.pipeline();
3033
+ for (let account of accounts) {
3034
+ pipeline = pipeline.hexists(`${REDIS_PREFIX}iad:${account}`, 'account');
3035
+ }
3036
+
3037
+ // A pipeline reports a per-command failure in its results rather than rejecting, and
3038
+ // extractMultiValues() reads such an entry as undefined - an account that could not be probed is
3039
+ // not an account that is known to exist
3040
+ let values = extractMultiValues(await pipeline.exec());
3041
+
3042
+ return new Map(accounts.map((account, i) => [account, values[i] === 1]));
3043
+ }
3044
+
3045
+ module.exports = { Account, accountExists, accountsExist };