emailengine-app 2.84.1 → 2.84.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 (93) hide show
  1. package/.dockerignore +6 -0
  2. package/.release-please-manifest.json +1 -1
  3. package/CHANGELOG.md +28 -0
  4. package/Dockerfile +2 -2
  5. package/bin/emailengine.js +15 -0
  6. package/data/google-crawlers.json +1 -1
  7. package/docker-compose.yml +1 -1
  8. package/lib/account/own-account-key.js +42 -0
  9. package/lib/account-assignment.js +1 -33
  10. package/lib/account.js +32 -19
  11. package/lib/add-trackers.js +11 -4
  12. package/lib/api-routes/account-routes.js +67 -14
  13. package/lib/api-routes/gateway-routes.js +9 -3
  14. package/lib/api-routes/message-routes.js +7 -1
  15. package/lib/api-routes/mint-bounds.js +11 -0
  16. package/lib/api-routes/route-helpers.js +125 -3
  17. package/lib/api-routes/submit-routes.js +4 -2
  18. package/lib/auth-token.js +23 -10
  19. package/lib/bounce-detect.js +17 -5
  20. package/lib/consts.js +34 -0
  21. package/lib/create-imap-client.js +41 -2
  22. package/lib/email-client/base-client.js +20 -10
  23. package/lib/email-client/gmail-client.js +21 -7
  24. package/lib/email-client/imap/mailbox.js +10 -4
  25. package/lib/email-client/imap/response-metrics.js +75 -0
  26. package/lib/email-client/imap-client.js +5 -2
  27. package/lib/email-client/message-builder.js +7 -2
  28. package/lib/email-client/outlook/graph-api.js +17 -2
  29. package/lib/email-client/outlook-client.js +6 -3
  30. package/lib/email-client/smtp-pool-manager.js +6 -0
  31. package/lib/encrypt.js +9 -0
  32. package/lib/export.js +3 -1
  33. package/lib/get-raw-email.js +4 -2
  34. package/lib/imap-proxy-auth.js +14 -1
  35. package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +1 -0
  36. package/lib/imapproxy/imap-core/lib/commands/login.js +1 -0
  37. package/lib/imapproxy/imap-core/lib/imap-command.js +86 -43
  38. package/lib/imapproxy/imap-core/lib/imap-stream.js +58 -13
  39. package/lib/imapproxy/imap-core/lib/indexer/indexer.js +3 -1
  40. package/lib/mcp/listen.js +10 -1
  41. package/lib/oauth/external-account-config.js +3 -1
  42. package/lib/oauth/gmail.js +21 -48
  43. package/lib/oauth/mail-ru.js +5 -38
  44. package/lib/oauth/outlook.js +26 -44
  45. package/lib/pbkdf2-phc.js +18 -1
  46. package/lib/privileged-settings.js +6 -3
  47. package/lib/redis-scan-delete.js +15 -1
  48. package/lib/schemas.js +78 -32
  49. package/lib/settings.js +13 -1
  50. package/lib/smtp-auth.js +23 -0
  51. package/lib/tools.js +245 -56
  52. package/lib/ui-routes/account-routes.js +16 -37
  53. package/lib/ui-routes/admin-config-routes.js +10 -38
  54. package/lib/ui-routes/admin-entities-routes.js +22 -24
  55. package/lib/ui-routes/auth-routes.js +47 -24
  56. package/lib/ui-routes/connection-security-form.js +74 -0
  57. package/lib/ui-routes/form-lists.js +46 -0
  58. package/lib/ui-routes/mcp-consent-routes.js +5 -1
  59. package/lib/ui-routes/oauth-config-routes.js +9 -18
  60. package/lib/ui-routes/sign-in-helpers.js +59 -0
  61. package/lib/ui-routes/unsubscribe-routes.js +6 -3
  62. package/lib/utils/map-concurrent.js +36 -0
  63. package/lib/utils/network.js +28 -0
  64. package/lib/utils/provider-id.js +27 -0
  65. package/lib/utils/require-tls.js +33 -0
  66. package/lib/web-safe-html.js +5 -6
  67. package/lib/webhook-penalty.js +75 -0
  68. package/lib/webhook-routing.js +22 -2
  69. package/package.json +21 -21
  70. package/sbom.json +1 -1
  71. package/server.js +25 -14
  72. package/static/js/ace/ace.js +1 -1
  73. package/static/js/ace/mode-handlebars.js +1 -1
  74. package/static/js/ace/mode-html.js +1 -1
  75. package/static/js/ace/mode-javascript.js +1 -1
  76. package/static/js/ace/mode-markdown.js +1 -1
  77. package/static/js/ace/worker-html.js +1 -1
  78. package/static/js/ace/worker-javascript.js +1 -1
  79. package/static/js/ace/worker-json.js +1 -1
  80. package/static/js/ee-client.js +5 -0
  81. package/static/licenses.html +23 -23
  82. package/translations/messages.pot +66 -66
  83. package/views/account/security.hbs +10 -0
  84. package/views/accounts/account.hbs +11 -11
  85. package/views/accounts/edit.hbs +6 -2
  86. package/views/partials/gateway_form.hbs +3 -1
  87. package/workers/api.js +43 -3
  88. package/workers/webhooks.js +39 -3
  89. package/config/test.toml +0 -46
  90. package/install.sh +0 -428
  91. package/setup-production.sh +0 -215
  92. package/systemd/emailengine.service +0 -97
  93. package/systemd/nginx-proxy.conf +0 -77
package/server.js CHANGED
@@ -20,19 +20,23 @@
20
20
  // same way. Set before anything can require bullmq; worker threads share this environment.
21
21
  process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED = 'true';
22
22
 
23
- // Load environment variables if not already loaded
24
- if (!process.env.EE_ENV_LOADED) {
25
- require('dotenv').config({ quiet: true });
26
- process.env.EE_ENV_LOADED = 'true';
27
- }
28
-
29
- // Attempt to change working directory to script location
23
+ // Attempt to change working directory to script location. Before anything reads a file by a
24
+ // relative path: `.env` below and the `config/` directory wild-config loads (including executable
25
+ // `.js` configuration files, run with the real require) are both resolved against the working
26
+ // directory, and the directory the operator happened to start from is not where this instance's
27
+ // configuration lives
30
28
  try {
31
29
  process.chdir(__dirname);
32
30
  } catch (err) {
33
31
  // ignore - may fail in some containerized environments
34
32
  }
35
33
 
34
+ // Load environment variables if not already loaded
35
+ if (!process.env.EE_ENV_LOADED) {
36
+ require('dotenv').config({ quiet: true });
37
+ process.env.EE_ENV_LOADED = 'true';
38
+ }
39
+
36
40
  // Set process title for easier identification in process lists
37
41
  process.title = 'emailengine';
38
42
 
@@ -146,10 +150,10 @@ const {
146
150
  releaseWorkerAccounts,
147
151
  requeueFailedAccounts,
148
152
  forgetAccount,
149
- mapConcurrent,
150
153
  shouldRequeueFailedAssignment,
151
154
  planRebalance
152
155
  } = require('./lib/account-assignment');
156
+ const { mapConcurrent } = require('./lib/utils/map-concurrent');
153
157
  const { RespawnTracker } = require('./lib/respawn-backoff');
154
158
 
155
159
  const msgpack = require('./lib/msgpack');
@@ -2548,10 +2552,15 @@ const openAiRequestOpts = () => ({
2548
2552
 
2549
2553
  const aiValueSet = value => value !== undefined && value !== null && value !== '';
2550
2554
 
2555
+ const aiUrlValue = value => (value === undefined || value === null ? '' : String(value).trim());
2556
+
2551
2557
  /**
2552
2558
  * Options for one request to the AI provider. The configuration page's test sends every field as
2553
2559
  * its form shows it, so the test runs with what the page shows; the sync path sends none and gets
2554
- * the stored settings. The key is the exception: the form leaves it blank to keep the stored one
2560
+ * the stored settings. The key is the exception: the form leaves it blank to keep the stored one,
2561
+ * and a request made with the stored key goes to the stored URL, since a write-only secret must
2562
+ * not be extractable by pointing a request that falls back to it at a server of one's own. The
2563
+ * rule is here rather than on the page's routes so every request the form can make is under it
2555
2564
  * @param {Object} data - The command's data
2556
2565
  * @returns {Promise<{openAiAPIKey: string, requestOpts: Object}>}
2557
2566
  */
@@ -2563,6 +2572,9 @@ async function aiRequestOptions(data) {
2563
2572
  if (!openAiAPIKey) {
2564
2573
  throw new Error(`OpenAI API key is not configured`);
2565
2574
  }
2575
+ if (data.options && !data.options.openAiAPIKey && aiUrlValue(data.options.openAiAPIUrl) !== aiUrlValue(stored.openAiAPIUrl)) {
2576
+ throw new Error('Enter the API key to use a different API URL');
2577
+ }
2566
2578
 
2567
2579
  const requestOpts = openAiRequestOpts();
2568
2580
  requestOpts.gptModel = aiValueSet(values.openAiModel) ? values.openAiModel : openAiDefaultModel;
@@ -3454,11 +3466,10 @@ const startApplication = async () => {
3454
3466
  await settings.set('enableApiProxy', HAS_API_PROXY_SET ? API_PROXY : true);
3455
3467
  }
3456
3468
 
3457
- // Service settings
3458
- let existingServiceSecret = await settings.get('serviceSecret');
3459
- if (existingServiceSecret === null) {
3460
- await settings.set('serviceSecret', crypto.randomBytes(16).toString('hex'));
3461
- }
3469
+ // Service settings. HSETNX rather than read-then-write: a stored secret that does not decrypt
3470
+ // (the wrong EENGINE_SECRET) reads as null, and overwriting it would destroy a value the
3471
+ // rotation CLI can still recover once the right secret is back
3472
+ await settings.setIfMissing('serviceSecret', crypto.randomBytes(16).toString('hex'));
3462
3473
 
3463
3474
  let existingQueueKeep = await settings.get('queueKeep');
3464
3475
  if (existingQueueKeep === null) {