emailengine-app 2.87.0 → 2.87.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/.ncurc.js +2 -4
  2. package/.release-please-manifest.json +1 -1
  3. package/CHANGELOG.md +27 -0
  4. package/Dockerfile +3 -4
  5. package/bin/emailengine.js +2 -4
  6. package/bin/healthcheck.js +20 -0
  7. package/data/google-crawlers.json +1 -1
  8. package/data/public_suffix_list.dat +3 -7
  9. package/lib/account/auth-failure-backfill.js +3 -2
  10. package/lib/account/expected-identity.js +2 -2
  11. package/lib/account.js +9 -8
  12. package/lib/api-listener.js +40 -0
  13. package/lib/api-token-auth.js +406 -0
  14. package/lib/autodetect-imap-settings.js +36 -3
  15. package/lib/consts.js +5 -0
  16. package/lib/dbsc/index.js +292 -0
  17. package/lib/dbsc/jwt.js +157 -0
  18. package/lib/dbsc/protocol.js +132 -0
  19. package/lib/dbsc/store.js +136 -0
  20. package/lib/email-client/base-client.js +23 -107
  21. package/lib/email-client/gmail-client.js +7 -4
  22. package/lib/email-client/imap/mailbox.js +89 -96
  23. package/lib/email-client/imap/sync-operations.js +13 -6
  24. package/lib/email-client/imap-client.js +28 -7
  25. package/lib/email-client/new-message-steps.js +162 -0
  26. package/lib/email-client/outlook-client.js +4 -2
  27. package/lib/env-setting-overrides.js +6 -2
  28. package/lib/export-worker.js +3 -2
  29. package/lib/export.js +43 -4
  30. package/lib/get-boolean.js +38 -0
  31. package/lib/health-probe.js +71 -0
  32. package/lib/imapproxy/imap-server.js +4 -55
  33. package/lib/net-tos-guard.js +42 -0
  34. package/lib/oauth2-apps.js +2 -1
  35. package/lib/privileged-settings.js +6 -0
  36. package/lib/read-env-value.js +19 -7
  37. package/lib/redis-keys.js +19 -0
  38. package/lib/redis-operations.js +7 -3
  39. package/lib/routes-ui.js +4 -1
  40. package/lib/schemas.js +8 -0
  41. package/lib/security-headers.js +18 -0
  42. package/lib/session-default.js +60 -0
  43. package/lib/settings.js +2 -1
  44. package/lib/stream-encrypt.js +71 -20
  45. package/lib/sub-script.js +8 -2
  46. package/lib/submit-lock.js +84 -0
  47. package/lib/submit-processor.js +283 -0
  48. package/lib/templates.js +6 -3
  49. package/lib/tls/context.js +2 -16
  50. package/lib/tools.js +8 -30
  51. package/lib/ui-routes/admin-config-routes.js +27 -5
  52. package/lib/ui-routes/auth-routes.js +4 -0
  53. package/lib/ui-routes/dbsc-routes.js +43 -0
  54. package/lib/utils/redis-errors.js +44 -0
  55. package/lib/webhook-delivery.js +3 -4
  56. package/lib/worker-rpc-error.js +10 -5
  57. package/lib/worker-rpc.js +138 -0
  58. package/package.json +17 -19
  59. package/sbom.json +370 -1446
  60. package/server.js +6 -5
  61. package/static/css/flyonui.css +2 -2
  62. package/static/licenses.html +253 -1366
  63. package/translations/messages.pot +16 -16
  64. package/views/config/security.hbs +37 -0
  65. package/workers/api.js +61 -467
  66. package/workers/export.js +14 -55
  67. package/workers/imap-proxy.js +5 -18
  68. package/workers/imap.js +27 -49
  69. package/workers/smtp.js +7 -69
  70. package/workers/submit.js +21 -279
  71. package/workers/webhooks.js +7 -72
package/.ncurc.js CHANGED
@@ -53,7 +53,8 @@ module.exports = {
53
53
  // from the CommonJS rule); the Node requirement does, since the tooling has to
54
54
  // run on the Node 20 floor too.
55
55
  // undici - 8.x requires Node >=22.19 and crashes at require() on Node 20. Permanent while the
56
- // Node 20 floor above stands.
56
+ // Node 20 floor above stands. lib/net-tos-guard.js covers a 7.x crash 8.x fixed
57
+ // itself (unguarded setTypeOfService); remove it with the upgrade.
57
58
  // marked - 16.x dropped the CommonJS build (ESM-only, needs require(esm)/Node >=20.19); 15.x is the
58
59
  // last require()-compatible line. 15.0.12 verified on Node 20-24 and in a yao/pkg node24 build.
59
60
  // Permanent: an ESM-only release cannot be bundled by pkg, whatever the Node floor.
@@ -91,9 +92,6 @@ module.exports = {
91
92
  // bump still needs a look at the generated document: test/openapi-golden-test.js fails if joi's
92
93
  // describe() output changes shape.
93
94
  reject: [
94
- // @asamuzakjp/css-color >=4.1.2 pulls in @csstools/* v4 which are pure ESM and break pkg bundling
95
- // (transitive via @postalsys/email-text-tools -> jsdom -> cssstyle; also pinned in package.json "overrides").
96
- '@asamuzakjp/css-color'
97
95
  // Not a direct dependency, so nothing here moves it: the "overrides" entry in package.json
98
96
  // lifts cheerio from the 1.0.0 that juice 11 (via @postalsys/email-text-tools) pins exactly,
99
97
  // which drags in a second copy of undici (6.x) next to ours. cheerio 1.2.0 shares our undici
@@ -1,3 +1,3 @@
1
1
  {
2
- ".": "2.87.0"
2
+ ".": "2.87.2"
3
3
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.87.2](https://github.com/postalsys/emailengine/compare/v2.87.1...v2.87.2) (2026-11-05)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * bind admin sessions to the signing-in device (beta, off by default) ([a62a421](https://github.com/postalsys/emailengine/commit/a62a421eb26ada313c5f556d49477082c5f639b4))
9
+ * bind admin sessions to the signing-in device (beta, off by default) ([da02403](https://github.com/postalsys/emailengine/commit/da02403b4f386af47324cfdcf9d505fe5a91ccf7))
10
+
11
+ ## [2.87.1](https://github.com/postalsys/emailengine/compare/v2.87.0...v2.87.1) (2026-11-05)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * bind export encryption chunks to their position in the file ([c138b61](https://github.com/postalsys/emailengine/commit/c138b6145ad0dab33b92d8d5f1571ffd32fc96c3))
17
+ * export recovery ownership and sent-marker durability (2.87.1 review) ([5c24113](https://github.com/postalsys/emailengine/commit/5c2411311ee1652ed4580fd53d40f0fdc81bd7f4))
18
+ * keep the sent marker until the submit job is recorded as completed ([aecf19f](https://github.com/postalsys/emailengine/commit/aecf19f6ac7a431f87441102e3302228ab1728ad))
19
+ * make the Docker health check follow the API's TLS setting, port and bind address ([957dec0](https://github.com/postalsys/emailengine/commit/957dec0923ab359355761bd531d6d08003a3dd05))
20
+ * never fail an export another export worker is still running ([74d1755](https://github.com/postalsys/emailengine/commit/74d1755aa2fec63565bae64fcad55153e5294c5d))
21
+ * read the TLS mode from <Encryption> in Exchange autodiscover answers ([5a1b7e9](https://github.com/postalsys/emailengine/commit/5a1b7e9e3df33a38b65b80447e6628a8e908223e))
22
+ * report a template id with an out-of-range timestamp as not found ([ac043db](https://github.com/postalsys/emailengine/commit/ac043db8d1540a025d8143d1d261cf3d2f1400cb))
23
+ * set text.hasMore when an IMAP text part is cut at maxBytes ([f070b5e](https://github.com/postalsys/emailengine/commit/f070b5ea91ad3763936c975a302a23d20d768e69))
24
+ * share the worker RPC, token check and new-message steps instead of copies ([ac4cf28](https://github.com/postalsys/emailengine/commit/ac4cf28ae3925bcf4a01373f3c05d51a5c4da8f3))
25
+ * standalone fixes for new-folder ids, Redis-refused work, duplicate sends, CLI password and queued exports ([#685](https://github.com/postalsys/emailengine/issues/685)) ([8e934c0](https://github.com/postalsys/emailengine/commit/8e934c0cf9cda2e33cfbdb7a42cfe2a77172523d))
26
+ * update dependencies ([56df020](https://github.com/postalsys/emailengine/commit/56df02073fb6a76e984531710fd97fee0163e58b))
27
+ * update dependencies ([25ee28f](https://github.com/postalsys/emailengine/commit/25ee28fc5bd5623c4b73b55e0890c027832825cf))
28
+ * update dependencies (bullmq 6.5.4, fast-xml-parser 5.12.0) ([5624ee1](https://github.com/postalsys/emailengine/commit/5624ee1844c6ed2f377bbbe7161f21f035d7c943))
29
+
3
30
  ## [2.87.0](https://github.com/postalsys/emailengine/compare/v2.86.0...v2.87.0) (2026-10-29)
4
31
 
5
32
 
package/Dockerfile CHANGED
@@ -114,11 +114,10 @@ EXPOSE 3000
114
114
 
115
115
  # The liveness check: answers while the process can serve HTTP, without waiting on Redis or the
116
116
  # workers, so an orchestrator restarts the container only when restarting can help. Readiness
117
- # (workers and Redis) is /health/ready, for whatever routes traffic to it. 127.0.0.1 rather than
118
- # localhost for the reason docker-compose.yml gives: BusyBox wget on musl tries ::1 only, and
119
- # EmailEngine listens on IPv4. Shell form so a changed EENGINE_PORT (or PORT) is followed.
117
+ # (workers and Redis) is /health/ready, for whatever routes traffic to it. A Node script rather than
118
+ # wget so the probe follows the API's own port, bind address and TLS switch (lib/health-probe.js).
120
119
  HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
121
- CMD wget --no-verbose --tries=1 --spider "http://127.0.0.1:${EENGINE_PORT:-${PORT:-3000}}/health/live" || exit 1
120
+ CMD ["node", "/emailengine/bin/healthcheck.js"]
122
121
 
123
122
  ENTRYPOINT ["/usr/bin/dumb-init", "--"]
124
123
  CMD ["node", "/emailengine/server.js"]
@@ -412,10 +412,8 @@ function runPassword() {
412
412
  let returnValue = argv.hash || argv.r ? Buffer.from(res.passwordHash).toString('base64url') : res.password;
413
413
  process.stdout.write(returnValue);
414
414
  // The password is stored, and every existing session is ended by the
415
- // version bump; the login requirement itself is installed by each API
416
- // worker at startup, so an instance that was running without a password
417
- // keeps serving the admin pages without one until it is restarted
418
- process.stderr.write('\nRestart running EmailEngine instances for the new password to take effect\n');
415
+ // version bump; a running instance that had no password asks for a login
416
+ // from its next admin request on (lib/session-default.js)
419
417
  return process.exit(0);
420
418
  })
421
419
  .catch(err => {
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // The Docker image's HEALTHCHECK: exits 0 when the API answers /health/live, 1 otherwise. See
5
+ // lib/health-probe.js.
6
+
7
+ // Resolve `.env` and `config/` against the application root, in the same order as server.js
8
+ process.chdir(require('path').join(__dirname, '..'));
9
+ require('dotenv').config({ quiet: true });
10
+
11
+ const config = require('@zone-eu/wild-config');
12
+ const { probeTarget, probe } = require('../lib/health-probe');
13
+
14
+ const target = probeTarget(config.api || {});
15
+
16
+ probe(target).then(result => {
17
+ const url = `${target.protocol}://${target.host}:${target.port}`;
18
+ process.stdout.write(result.ok ? `${url} is live\n` : `${url} is not live: ${result.error || `HTTP ${result.statusCode}`}\n`);
19
+ process.exit(result.ok ? 0 : 1);
20
+ });
@@ -1,5 +1,5 @@
1
1
  {
2
- "creationTime": "2026-10-28T15:45:59.000000",
2
+ "creationTime": "2026-11-04T15:46:00.000000",
3
3
  "prefixes": [
4
4
  {
5
5
  "ipv6Prefix": "2001:4860:4801:2008::/64"
@@ -5,8 +5,8 @@
5
5
  // Please pull this list from, and only from https://publicsuffix.org/list/public_suffix_list.dat,
6
6
  // rather than any other VCS sites. Pulling from any other URL is not guaranteed to be supported.
7
7
 
8
- // VERSION: 2026-10-28_13-15-55_UTC
9
- // COMMIT: 9dfbe81931367b3f0af21035c36ae7eeb830dd88
8
+ // VERSION: 2026-10-31_14-17-28_UTC
9
+ // COMMIT: 73f8cc701c084fe07d888ec552b2f0b53281a674
10
10
 
11
11
  // Instructions on pulling and using this list can be found at https://publicsuffix.org/list/.
12
12
 
@@ -6812,7 +6812,7 @@ org.zw
6812
6812
 
6813
6813
  // newGTLDs
6814
6814
 
6815
- // List of new gTLDs imported from https://www.icann.org/resources/registries/gtlds/v2/gtlds.json on 2026-10-16T18:37:24Z
6815
+ // List of new gTLDs imported from https://www.icann.org/resources/registries/gtlds/v2/gtlds.json on 2026-10-30T19:51:02Z
6816
6816
  // This list is auto-generated, don't edit it manually.
6817
6817
  // aaa : American Automobile Association, Inc.
6818
6818
  // https://www.iana.org/domains/root/db/aaa.html
@@ -8498,10 +8498,6 @@ healthcare
8498
8498
  // https://www.iana.org/domains/root/db/help.html
8499
8499
  help
8500
8500
 
8501
- // helsinki : City of Helsinki
8502
- // https://www.iana.org/domains/root/db/helsinki.html
8503
- helsinki
8504
-
8505
8501
  // here : Charleston Road Registry Inc.
8506
8502
  // https://www.iana.org/domains/root/db/here.html
8507
8503
  here
@@ -39,6 +39,7 @@
39
39
  // rolling upgrade, would leave a second batch that the key then hides; re-arming means deleting
40
40
  // BACKFILL_KEY and restarting.
41
41
 
42
+ const { accountDataKey } = require('../redis-keys');
42
43
  const { redis } = require('../db');
43
44
  const logger = require('../logger');
44
45
  const { parseImapData } = require('./imap-data');
@@ -130,7 +131,7 @@ async function backfillAuthFailureDisabled(opts = {}) {
130
131
 
131
132
  const readReq = client.pipeline();
132
133
  for (const account of chunk) {
133
- readReq.hmget(`${REDIS_PREFIX}iad:${account}`, ...SCAN_FIELDS);
134
+ readReq.hmget(accountDataKey(account), ...SCAN_FIELDS);
134
135
  }
135
136
  const rows = await readReq.exec();
136
137
 
@@ -142,7 +143,7 @@ async function backfillAuthFailureDisabled(opts = {}) {
142
143
  // hSetExists rather than hset, for the same reason the safety net writes it that way: an
143
144
  // account deleted between the read above and this write must not come back as a hash
144
145
  // holding nothing but a marker.
145
- writeReq.hSetExists(`${REDIS_PREFIX}iad:${chunk[j]}`, AUTH_FAILURE_DISABLED_FIELD, stamp);
146
+ writeReq.hSetExists(accountDataKey(chunk[j]), AUTH_FAILURE_DISABLED_FIELD, stamp);
146
147
  queued++;
147
148
  }
148
149
  }
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const { REDIS_PREFIX } = require('../consts');
3
+ const { accountDataKey } = require('../redis-keys');
4
4
 
5
5
  // An account can carry an expected identity: the address that must own it, set by an authenticated API
6
6
  // caller through `expectedEmail` on POST /v1/authentication/form, POST /v1/account or
@@ -82,7 +82,7 @@ async function resolveExpectedIdentity(redis, opts) {
82
82
  return null;
83
83
  }
84
84
 
85
- return normalizeEmail(await redis.hget(`${REDIS_PREFIX}iad:${account}`, 'expectedEmail')) || null;
85
+ return normalizeEmail(await redis.hget(accountDataKey(account), 'expectedEmail')) || null;
86
86
  }
87
87
 
88
88
  module.exports = { normalizeEmail, matchesExpectedIdentity, pendingSetupExpectation, resolveExpectedIdentity };
package/lib/account.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const { accountDataKey } = require('./redis-keys');
3
4
  const logger = require('./logger');
4
5
  const Boom = require('@hapi/boom');
5
6
  const msgpack = require('./msgpack');
@@ -368,7 +369,7 @@ class Account {
368
369
  let delegatedAccount = await resolveDelegatedAccount(this.redis, accountData.account);
369
370
  if (delegatedAccount) {
370
371
  accountData.delegatedAccount = delegatedAccount;
371
- let delegatedAccountRow = await this.redis.hgetall(`${REDIS_PREFIX}iad:${delegatedAccount}`);
372
+ let delegatedAccountRow = await this.redis.hgetall(accountDataKey(delegatedAccount));
372
373
  let delegatedAccountData = this.unserializeAccountData(delegatedAccountRow, { skipDecrypt: true });
373
374
  if (delegatedAccountData.oauth2 && delegatedAccountData.oauth2.provider) {
374
375
  let app;
@@ -443,7 +444,7 @@ class Account {
443
444
  }
444
445
 
445
446
  getAccountKey() {
446
- return `${REDIS_PREFIX}iad:${this.account}`;
447
+ return accountDataKey(this.account);
447
448
  }
448
449
 
449
450
  getMailboxListKey() {
@@ -1024,7 +1025,7 @@ class Account {
1024
1025
  let delegatedAccount = await resolveDelegatedAccount(this.redis, accountData.account);
1025
1026
  if (delegatedAccount) {
1026
1027
  accountData.delegatedAccount = delegatedAccount;
1027
- let delegatedAccountRow = await this.redis.hgetall(`${REDIS_PREFIX}iad:${delegatedAccount}`);
1028
+ let delegatedAccountRow = await this.redis.hgetall(accountDataKey(delegatedAccount));
1028
1029
  let delegatedAccountData = this.unserializeAccountData(delegatedAccountRow, { skipDecrypt: true });
1029
1030
  if (delegatedAccountData.oauth2 && delegatedAccountData.oauth2.provider) {
1030
1031
  let app = await oauth2Apps.get(delegatedAccountData.oauth2.provider);
@@ -1396,7 +1397,7 @@ class Account {
1396
1397
  let retries = 0;
1397
1398
  while (retries++ < 20) {
1398
1399
  id = randomId();
1399
- let alreadyExists = await this.redis.hexists(`${REDIS_PREFIX}iad:${id}`, 'account');
1400
+ let alreadyExists = await this.redis.hexists(accountDataKey(id), 'account');
1400
1401
  if (alreadyExists) {
1401
1402
  id = false;
1402
1403
  } else {
@@ -2802,7 +2803,7 @@ class Account {
2802
2803
  let delegatedAccount = await resolveDelegatedAccount(this.redis, accountData.account);
2803
2804
  if (delegatedAccount) {
2804
2805
  accountData.delegatedAccount = delegatedAccount;
2805
- let delegatedAccountRow = await this.redis.hgetall(`${REDIS_PREFIX}iad:${delegatedAccount}`);
2806
+ let delegatedAccountRow = await this.redis.hgetall(accountDataKey(delegatedAccount));
2806
2807
  let delegatedAccountData = this.unserializeAccountData(delegatedAccountRow, { skipDecrypt: true });
2807
2808
  if (delegatedAccountData?.oauth2?.provider) {
2808
2809
  let app = await oauth2Apps.get(delegatedAccountData.oauth2.provider);
@@ -3011,7 +3012,7 @@ const DEFERRED_CHANGE_BATCH = 100;
3011
3012
  // the mandatory marker field of the account hash (the same idiom the notify worker and
3012
3013
  // genId() rely on), so its presence is the canonical "this account exists" signal.
3013
3014
  async function accountExists(redis, account) {
3014
- return (await redis.hexists(`${REDIS_PREFIX}iad:${account}`, 'account')) === 1;
3015
+ return (await redis.hexists(accountDataKey(account), 'account')) === 1;
3015
3016
  }
3016
3017
 
3017
3018
  /**
@@ -3031,7 +3032,7 @@ async function accountsExist(redis, accounts) {
3031
3032
 
3032
3033
  let pipeline = redis.pipeline();
3033
3034
  for (let account of accounts) {
3034
- pipeline = pipeline.hexists(`${REDIS_PREFIX}iad:${account}`, 'account');
3035
+ pipeline = pipeline.hexists(accountDataKey(account), 'account');
3035
3036
  }
3036
3037
 
3037
3038
  // A pipeline reports a per-command failure in its results rather than rejecting, and
@@ -3060,7 +3061,7 @@ async function accountSummary(redis, account) {
3060
3061
  }
3061
3062
 
3062
3063
  // `account` is the existence marker (see accountExists); the rest are optional on a record
3063
- let [exists, name, email, state] = await redis.hmget(`${REDIS_PREFIX}iad:${account}`, 'account', 'name', 'email', 'state');
3064
+ let [exists, name, email, state] = await redis.hmget(accountDataKey(account), 'account', 'name', 'email', 'state');
3064
3065
  if (!exists) {
3065
3066
  return null;
3066
3067
  }
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ // Where and how the API listens, resolved from the environment and the config file. One copy for
4
+ // every process that needs the answer: the main thread and the API worker build the listener from
5
+ // it, the certificate reconciler asks whether it serves TLS, and the Docker health check
6
+ // (lib/health-probe.js) probes it. Kept to leaf modules so the health check can load it without
7
+ // reaching Redis, which lib/tools.js and lib/settings.js do as they load.
8
+
9
+ const config = require('@zone-eu/wild-config');
10
+ const { readEnvValue, hasEnvValue } = require('./read-env-value');
11
+ const { getBoolean } = require('./get-boolean');
12
+
13
+ /**
14
+ * @param {Object} [api] - The `[api]` section of the configuration
15
+ * @returns {number|undefined} EENGINE_PORT, then PORT, then `[api] port`
16
+ */
17
+ function apiPort(api = config.api || {}) {
18
+ return (hasEnvValue('EENGINE_PORT') && Number(readEnvValue('EENGINE_PORT'))) || (hasEnvValue('PORT') && Number(readEnvValue('PORT'))) || api.port;
19
+ }
20
+
21
+ /**
22
+ * @param {Object} [api] - The `[api]` section of the configuration
23
+ * @returns {string|undefined} EENGINE_HOST, then `[api] host`
24
+ */
25
+ function apiHost(api = config.api || {}) {
26
+ return readEnvValue('EENGINE_HOST') || api.host;
27
+ }
28
+
29
+ /**
30
+ * Whether, and how, the API listener serves TLS: EENGINE_API_TLS and `[api.tls]`.
31
+ *
32
+ * @param {Object} [api] - The `[api]` section of the configuration
33
+ * @returns {Object|false} The `[api.tls]` options to build the listener from, or false when the
34
+ * API serves plain HTTP
35
+ */
36
+ function apiTlsConfig(api = config.api || {}) {
37
+ return hasEnvValue('EENGINE_API_TLS') ? getBoolean(readEnvValue('EENGINE_API_TLS')) && (api.tls || {}) : api.tls || false;
38
+ }
39
+
40
+ module.exports = { apiPort, apiHost, apiTlsConfig };