emailengine-app 2.79.7 → 2.79.8

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 (94) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +17 -0
  3. package/DOCKER_DEPLOYMENT.md +2 -0
  4. package/bin/emailengine.js +29 -13
  5. package/config/default.toml +13 -3
  6. package/data/google-crawlers.json +7 -1
  7. package/docker-compose.yml +12 -3
  8. package/install.sh +2 -0
  9. package/lib/api-routes/account-routes.js +14 -3
  10. package/lib/api-routes/mailbox-routes.js +4 -1
  11. package/lib/api-routes/message-routes.js +6 -5
  12. package/lib/api-routes/outbox-routes.js +7 -4
  13. package/lib/api-routes/settings-routes.js +34 -25
  14. package/lib/api-routes/stats-routes.js +8 -1
  15. package/lib/api-routes/submit-routes.js +2 -1
  16. package/lib/api-routes/template-routes.js +3 -2
  17. package/lib/bounce-detect.js +45 -0
  18. package/lib/consts.js +5 -1
  19. package/lib/egress-filter.js +39 -4
  20. package/lib/email-client/base-client.js +274 -24
  21. package/lib/email-client/gmail/gmail-api.js +15 -7
  22. package/lib/email-client/gmail-client.js +121 -64
  23. package/lib/email-client/imap/mailbox.js +18 -59
  24. package/lib/email-client/imap-client.js +53 -29
  25. package/lib/email-client/notification-handler.js +11 -2
  26. package/lib/email-client/outlook/graph-api.js +106 -90
  27. package/lib/email-client/outlook-client.js +222 -106
  28. package/lib/generate-text-preview.js +10 -5
  29. package/lib/headers-rewriter.js +1 -1
  30. package/lib/llm-pre-process.js +4 -1
  31. package/lib/mcp/json-schema.js +50 -2
  32. package/lib/outbox.js +22 -5
  33. package/lib/pre-process.js +4 -1
  34. package/lib/rewrite-text-nodes.js +12 -1
  35. package/lib/schemas.js +27 -5
  36. package/lib/settings.js +19 -1
  37. package/lib/sso.js +13 -3
  38. package/lib/submit-progress.js +29 -0
  39. package/lib/templates.js +11 -0
  40. package/lib/tools.js +96 -53
  41. package/lib/ui-routes/account-routes.js +70 -11
  42. package/lib/ui-routes/admin-config-routes.js +7 -21
  43. package/lib/ui-routes/admin-entities-routes.js +42 -12
  44. package/lib/ui-routes/auth-routes.js +87 -28
  45. package/lib/ui-routes/dashboard-routes.js +1 -1
  46. package/lib/ui-routes/internals-routes.js +2 -0
  47. package/lib/ui-routes/mcp-consent-routes.js +5 -2
  48. package/lib/ui-routes/network-config-routes.js +2 -2
  49. package/lib/ui-routes/oauth-config-routes.js +12 -1
  50. package/lib/ui-routes/route-helpers.js +41 -6
  51. package/lib/ui-routes/settings-page.js +10 -0
  52. package/lib/ui-routes/suppression-list-routes.js +16 -5
  53. package/lib/ui-routes/unsubscribe-routes.js +22 -3
  54. package/lib/webhooks.js +14 -2
  55. package/package.json +11 -11
  56. package/sbom.json +1 -1
  57. package/server.js +63 -35
  58. package/static/css/flyonui.css +1 -1
  59. package/static/licenses.html +17 -17
  60. package/translations/messages.pot +49 -49
  61. package/views/account/passkeys.hbs +8 -0
  62. package/views/account/password.hbs +11 -0
  63. package/views/account/security.hbs +18 -7
  64. package/views/accounts/account.hbs +6 -1
  65. package/views/accounts/register/imap-server.hbs +10 -2
  66. package/views/config/ai.hbs +2 -0
  67. package/views/config/branding.hbs +2 -0
  68. package/views/config/email-processing.hbs +2 -0
  69. package/views/config/imap-proxy.hbs +2 -0
  70. package/views/config/logging.hbs +3 -1
  71. package/views/config/mcp.hbs +2 -0
  72. package/views/config/network.hbs +2 -0
  73. package/views/config/oauth/app.hbs +2 -2
  74. package/views/config/security.hbs +2 -0
  75. package/views/config/service.hbs +2 -0
  76. package/views/config/smtp.hbs +2 -0
  77. package/views/config/webhooks.hbs +2 -0
  78. package/views/error.hbs +6 -0
  79. package/views/layout/app.hbs +6 -3
  80. package/views/layout/login.hbs +1 -1
  81. package/views/layout/prompt.hbs +1 -1
  82. package/views/layout/public.hbs +1 -1
  83. package/views/legal.hbs +1 -1
  84. package/views/partials/filter_editor_js.hbs +1 -1
  85. package/views/partials/oauth_form.hbs +5 -5
  86. package/views/partials/ui/env-managed-alert.hbs +19 -0
  87. package/views/partials/webhook_form.hbs +1 -1
  88. package/views/unsubscribe.hbs +6 -0
  89. package/workers/api.js +137 -63
  90. package/workers/imap.js +32 -3
  91. package/workers/smtp.js +7 -0
  92. package/workers/submit.js +25 -1
  93. package/workers/webhooks.js +13 -17
  94. package/lib/reconnection-manager.js +0 -106
package/server.js CHANGED
@@ -3175,6 +3175,44 @@ process.on('SIGINT', () => {
3175
3175
 
3176
3176
  // START APPLICATION
3177
3177
 
3178
+ /**
3179
+ * Waits for a fleet of spawned workers and tolerates a partial start: proceeds as long as at
3180
+ * least one worker reached 'ready' (the spawnWorker exit handler respawns any that failed;
3181
+ * letting such a rejection abort startup would exit the process while the respawn is pending).
3182
+ * Only a fleet that failed entirely is fatal - the thrown error rejects startApplication(), which
3183
+ * logs fatal and exits the process, preserving the original single-worker "no worker => exit"
3184
+ * behavior.
3185
+ *
3186
+ * @param {string} label - Worker type as it appears in the log lines ('API', 'IMAP')
3187
+ * @param {Promise[]} promises - spawnWorker() promises of the fleet
3188
+ * @param {Object} logFields - extra fields for the partial-failure log line (requested count etc.)
3189
+ * @returns {Promise<Array>} Thread IDs of the workers that reached 'ready'
3190
+ */
3191
+ const settleWorkerFleet = async (label, promises, logFields) => {
3192
+ let results = await Promise.allSettled(promises);
3193
+ let threadIds = results.filter(result => result.status === 'fulfilled').map(result => result.value);
3194
+ let failed = results.length - threadIds.length;
3195
+ if (failed) {
3196
+ logger.error(
3197
+ Object.assign({ msg: `Some ${label} workers failed to start; they will be respawned` }, logFields, {
3198
+ ready: threadIds.length,
3199
+ failed,
3200
+ errors: results
3201
+ .filter(result => result.status === 'rejected')
3202
+ .map(result => ({
3203
+ message: result.reason && result.reason.message,
3204
+ exitCode: result.reason && result.reason.exitCode,
3205
+ threadId: result.reason && result.reason.threadId
3206
+ }))
3207
+ })
3208
+ );
3209
+ }
3210
+ if (results.length && !threadIds.length) {
3211
+ throw new Error(`No ${label} worker thread could be started`);
3212
+ }
3213
+ return threadIds;
3214
+ };
3215
+
3178
3216
  /**
3179
3217
  * Main application startup
3180
3218
  * @returns {Promise<void>}
@@ -3271,6 +3309,13 @@ const startApplication = async () => {
3271
3309
  for (let key of Object.keys(preparedSettings)) {
3272
3310
  await settings.set(key, preparedSettings[key]);
3273
3311
  }
3312
+
3313
+ // These keys are re-applied on every boot, so a value saved for one of them in the admin
3314
+ // UI reverts at the next restart. The list is recorded for the settings pages
3315
+ // (lib/ui-routes/settings-page.js) to flag those fields as managed by EENGINE_SETTINGS
3316
+ await settings.set('preparedSettingsKeys', Object.keys(preparedSettings));
3317
+ } else {
3318
+ await settings.clear('preparedSettingsKeys');
3274
3319
  }
3275
3320
 
3276
3321
  // Initialize required settings
@@ -3403,13 +3448,20 @@ const startApplication = async () => {
3403
3448
  try {
3404
3449
  let authData = await settings.get('authData');
3405
3450
 
3406
- authData = authData || {};
3407
- authData.user = authData.user || 'admin';
3408
- authData.password = preparedPassword;
3409
- authData.passwordVersion = Date.now();
3410
-
3411
- await settings.set('authData', authData);
3412
- logger.debug({ msg: 'Password imported' });
3451
+ // Written only when the stored hash differs: passwordVersion is what every admin
3452
+ // session and message-browser token is checked against, so rewriting the same hash
3453
+ // on each boot would log every operator out at every restart
3454
+ if (!authData || authData.password !== preparedPassword) {
3455
+ authData = authData || {};
3456
+ authData.user = authData.user || 'admin';
3457
+ authData.password = preparedPassword;
3458
+ authData.passwordVersion = Date.now();
3459
+
3460
+ await settings.set('authData', authData);
3461
+ logger.debug({ msg: 'Password imported' });
3462
+ } else {
3463
+ logger.debug({ msg: 'Password already imported' });
3464
+ }
3413
3465
  } catch (err) {
3414
3466
  logger.error({ msg: 'Password import failed', err });
3415
3467
  }
@@ -3481,33 +3533,8 @@ const startApplication = async () => {
3481
3533
  apiPromises.push(spawnWorker('api', workerSpawnOpts('api', i)));
3482
3534
  }
3483
3535
 
3484
- // Tolerate partial API-worker startup: proceed as long as at least one worker reached 'ready'
3485
- // (the spawnWorker exit handler respawns any that failed). Only abort startup if EVERY API
3486
- // worker failed, preserving the original single-worker "no API worker => exit" behavior.
3487
- let apiResults = await Promise.allSettled(apiPromises);
3488
- let apiReady = apiResults.filter(result => result.status === 'fulfilled').length;
3489
- let apiFailed = apiResults.length - apiReady;
3490
- if (apiFailed) {
3491
- logger.error({
3492
- msg: 'Some API workers failed to start; they will be respawned',
3493
- requested: apiWorkersRequested,
3494
- attempted: apiResults.length,
3495
- ready: apiReady,
3496
- failed: apiFailed,
3497
- errors: apiResults
3498
- .filter(result => result.status === 'rejected')
3499
- .map(result => ({
3500
- message: result.reason && result.reason.message,
3501
- exitCode: result.reason && result.reason.exitCode,
3502
- threadId: result.reason && result.reason.threadId
3503
- }))
3504
- });
3505
- }
3506
- if (!apiReady) {
3507
- // No API worker came up at all - fatal, same as the original single-worker behavior. This
3508
- // rejects startApplication(), which logs fatal and exits the process.
3509
- throw new Error('No API worker thread could be started');
3510
- }
3536
+ // `attempted` can be below `requested` after the SO_REUSEPORT fallback above
3537
+ let apiReady = (await settleWorkerFleet('API', apiPromises, { requested: apiWorkersRequested, attempted: apiPromises.length })).length;
3511
3538
  logger.info({ msg: 'API workers started', requested: apiWorkersRequested, ready: apiReady });
3512
3539
 
3513
3540
  // Small delay to allow API to start
@@ -3518,7 +3545,8 @@ const startApplication = async () => {
3518
3545
  for (let i = 0; i < config.workers.imap; i++) {
3519
3546
  workerPromises.push(spawnWorker('imap'));
3520
3547
  }
3521
- let threadIds = await Promise.all(workerPromises);
3548
+
3549
+ let threadIds = await settleWorkerFleet('IMAP', workerPromises, { requested: config.workers.imap });
3522
3550
  logger.info({ msg: 'IMAP workers started', workers: config.workers.imap, threadIds });
3523
3551
 
3524
3552
  // Mark that initial workers are loaded BEFORE assignment