emailengine-app 2.83.2 → 2.84.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 (63) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +27 -0
  3. package/README.md +1 -1
  4. package/SECURITY.md +126 -47
  5. package/data/google-crawlers.json +1 -1
  6. package/lib/api-routes/outbox-routes.js +132 -9
  7. package/lib/api-routes/permission-map.js +11 -1
  8. package/lib/consts.js +0 -4
  9. package/lib/email-client/imap/idle-settings.js +44 -0
  10. package/lib/email-client/imap/mailbox.js +19 -7
  11. package/lib/email-client/imap-client.js +3 -21
  12. package/lib/enum-descriptions.js +7 -0
  13. package/lib/export.js +2 -6
  14. package/lib/field-usage.js +4 -0
  15. package/lib/handlebars-helpers.js +4 -0
  16. package/lib/outbox.js +338 -10
  17. package/lib/queue-browser/definitions.js +132 -0
  18. package/lib/queue-browser/format.js +387 -0
  19. package/lib/queue-browser/index.js +568 -0
  20. package/lib/queue-job-actions.js +75 -0
  21. package/lib/queue-retention.js +53 -1
  22. package/lib/routes-ui.js +5 -0
  23. package/lib/schemas.js +42 -2
  24. package/lib/security-headers.js +2 -24
  25. package/lib/token-permission-view.js +1 -1
  26. package/lib/ui-routes/account-routes.js +6 -0
  27. package/lib/ui-routes/imap-idle-field.js +42 -0
  28. package/lib/ui-routes/queue-routes.js +371 -0
  29. package/lib/utils/status-error.js +21 -0
  30. package/package.json +15 -17
  31. package/prepare-bundle-deps.sh +1 -1
  32. package/sbom.json +1 -1
  33. package/server.js +59 -24
  34. package/static/css/flyonui.css +1 -1
  35. package/static/css/src/app.tailwind.css +2 -0
  36. package/static/js/queues.js +117 -0
  37. package/static/licenses.html +122 -246
  38. package/translations/messages.pot +57 -42
  39. package/views/accounts/account.hbs +31 -0
  40. package/views/accounts/edit.hbs +2 -0
  41. package/views/config/service.hbs +1 -2
  42. package/views/dashboard.hbs +2 -2
  43. package/views/partials/queue_cell_account.hbs +20 -0
  44. package/views/partials/queue_cell_failure.hbs +6 -0
  45. package/views/partials/queue_clean_items.hbs +9 -0
  46. package/views/partials/queue_clean_modal.hbs +9 -0
  47. package/views/partials/queue_entry_actions.hbs +41 -0
  48. package/views/partials/queue_job_actions.hbs +15 -0
  49. package/views/partials/queue_pause_controls.hbs +18 -0
  50. package/views/partials/queue_retention_note.hbs +49 -0
  51. package/views/partials/queue_rows_export.hbs +58 -0
  52. package/views/partials/queue_rows_notify.hbs +73 -0
  53. package/views/partials/queue_rows_submit.hbs +70 -0
  54. package/views/partials/side_menu.hbs +1 -1
  55. package/views/partials/ui/tooltip.hbs +5 -3
  56. package/views/queues/index.hbs +104 -0
  57. package/views/queues/job.hbs +224 -0
  58. package/views/queues/queue.hbs +93 -0
  59. package/views/webhooks/webhook.hbs +3 -0
  60. package/workers/api.js +0 -4
  61. package/workers/submit.js +19 -5
  62. package/workers/webhooks.js +13 -0
  63. package/lib/api-routes/bull-board-routes.js +0 -56
package/server.js CHANGED
@@ -118,6 +118,7 @@ initSentry('main');
118
118
  const pathlib = require('path');
119
119
  const { redis, queueConf, notifyQueue, submitQueue, exportQueue, logBullErrors } = require('./lib/db');
120
120
  const { queueStats } = require('./lib/queue-stats');
121
+ const { pruneFailedContent } = require('./lib/outbox');
121
122
  const { packRpcError, unpackRpcError } = require('./lib/worker-rpc-error');
122
123
  const promClient = require('prom-client');
123
124
  const fs = require('fs').promises;
@@ -792,6 +793,7 @@ let workerAssigned = new WeakMap(); // Map of worker -> Set of accounts
792
793
  let onlineWorkers = new WeakSet(); // Set of workers that are online
793
794
  let reassignmentTimer = null; // Timer for failsafe reassignment
794
795
  let reassignmentPending = false; // Flag to track if reassignment is pending
796
+ const REASSIGNMENT_FAILSAFE_DELAY = 10 * 1000; // How long an exited IMAP worker gets to restart before its accounts move
795
797
  let assignRetryCount = 0; // Counter for safety-net retries in assignAccounts
796
798
  const MAX_ASSIGN_RETRIES = 3; // Max consecutive safety-net retries before giving up
797
799
 
@@ -1154,7 +1156,7 @@ let spawnWorker = async (type, opts, slot) => {
1154
1156
 
1155
1157
  // A fresh spawn opens its own slot. Counting the crash streak per type made every short-lived
1156
1158
  // exit of ANY IMAP worker double the next respawn delay of all of them, so unrelated exits
1157
- // pushed a restart past the 10s failsafe reassignment.
1159
+ // pushed a restart past the failsafe reassignment (REASSIGNMENT_FAILSAFE_DELAY).
1158
1160
  if (!slot) {
1159
1161
  slot = `${type}:${++spawnSlotCounter}`;
1160
1162
  }
@@ -1296,24 +1298,8 @@ let spawnWorker = async (type, opts, slot) => {
1296
1298
  if (unassigned && unassigned.size > 0) {
1297
1299
  reassignmentPending = true;
1298
1300
 
1299
- // Clear any existing timer
1300
- if (reassignmentTimer) {
1301
- clearTimeout(reassignmentTimer);
1302
- }
1303
-
1304
- // Set a failsafe timer - if worker doesn't restart in 10 seconds, reassign anyway
1305
- reassignmentTimer = setTimeout(() => {
1306
- if (reassignmentPending && unassigned && unassigned.size > 0) {
1307
- logger.warn({
1308
- msg: 'Failsafe reassignment triggered - worker restart timeout',
1309
- unassignedAccounts: unassigned.size,
1310
- currentWorkers: availableIMAPWorkers.size,
1311
- expectedWorkers: config.workers.imap
1312
- });
1313
- reassignmentPending = false;
1314
- assignAccounts().catch(err => logger.error({ msg: 'Unable to reassign accounts (failsafe)', err }));
1315
- }
1316
- }, 10000); // 10 second timeout
1301
+ // If the worker does not restart in time, its accounts go to the others anyway
1302
+ armReassignmentFailsafe();
1317
1303
 
1318
1304
  logger[exitLevel]({
1319
1305
  msg: 'Worker exited, waiting for restart before reassignment',
@@ -1657,6 +1643,11 @@ let spawnWorker = async (type, opts, slot) => {
1657
1643
  expectedWorkers: config.workers.imap,
1658
1644
  unassignedAccounts: unassigned.size
1659
1645
  });
1646
+ // The failsafe found no worker at all and stopped; give the rest
1647
+ // of the fleet the same time to come back from here
1648
+ if (!reassignmentTimer) {
1649
+ armReassignmentFailsafe();
1650
+ }
1660
1651
  }
1661
1652
  } else if (imapInitialWorkersLoaded) {
1662
1653
  // The failsafe timer already gave this worker's accounts to the
@@ -1790,6 +1781,43 @@ async function unassignFromWorker(worker, account) {
1790
1781
  }
1791
1782
  }
1792
1783
 
1784
+ /**
1785
+ * Starts (or restarts) the failsafe timer that gives the accounts an exited IMAP worker left behind
1786
+ * to the remaining workers when it does not come back in time
1787
+ */
1788
+ function armReassignmentFailsafe() {
1789
+ clearTimeout(reassignmentTimer);
1790
+
1791
+ reassignmentTimer = setTimeout(() => {
1792
+ reassignmentTimer = null;
1793
+ if (!reassignmentPending || !unassigned || !unassigned.size) {
1794
+ return;
1795
+ }
1796
+
1797
+ if (!availableIMAPWorkers.size) {
1798
+ // Every worker exited at once (the clean exit after a Redis reconnection) and none is
1799
+ // back yet. A pass now would find no worker and clear the pending flag that makes the
1800
+ // returning workers pick the accounts up, stranding them until a process restart. Keep
1801
+ // it pending instead; the first worker to come back arms this timer again
1802
+ logger.warn({
1803
+ msg: 'Failsafe reassignment postponed - no IMAP worker is available yet',
1804
+ unassignedAccounts: unassigned.size,
1805
+ expectedWorkers: config.workers.imap
1806
+ });
1807
+ return;
1808
+ }
1809
+
1810
+ logger.warn({
1811
+ msg: 'Failsafe reassignment triggered - worker restart timeout',
1812
+ unassignedAccounts: unassigned.size,
1813
+ currentWorkers: availableIMAPWorkers.size,
1814
+ expectedWorkers: config.workers.imap
1815
+ });
1816
+ reassignmentPending = false;
1817
+ assignAccounts().catch(err => logger.error({ msg: 'Unable to reassign accounts (failsafe)', err }));
1818
+ }, REASSIGNMENT_FAILSAFE_DELAY);
1819
+ }
1820
+
1793
1821
  /**
1794
1822
  * Moves a fair share of accounts onto an IMAP worker that became ready while the rest of the fleet
1795
1823
  * already served every account. That is the normal outcome of a restart slower than the failsafe
@@ -1808,9 +1836,6 @@ async function rebalanceOnto(worker) {
1808
1836
  }
1809
1837
 
1810
1838
  let moves = planRebalance({ workerAssigned, availableWorkers: availableIMAPWorkers }, worker);
1811
- if (!moves.length) {
1812
- return;
1813
- }
1814
1839
 
1815
1840
  assigning = true;
1816
1841
  let moved = 0;
@@ -1842,8 +1867,9 @@ async function rebalanceOnto(worker) {
1842
1867
  logger.info({ msg: 'Rebalancing accounts onto a restarted IMAP worker', threadId: worker.threadId, accounts: moved });
1843
1868
  }
1844
1869
  // Also run when nothing moved: an account added while this held the assignment lock found the
1845
- // pass refused and is waiting in unassigned. Every worker is available again, so the pass
1846
- // picks the least loaded one, which is the newcomer.
1870
+ // pass refused and is waiting in unassigned, or nothing was there to move because every worker
1871
+ // had exited and the accounts are all waiting. The pass picks the least loaded worker, which
1872
+ // is the newcomer.
1847
1873
  if (moved || unassigned.size) {
1848
1874
  await assignAccounts();
1849
1875
  }
@@ -3731,6 +3757,15 @@ startApplication()
3731
3757
  logger.error({ msg: 'Queue cleanup failed', queue: queue.name, err });
3732
3758
  }
3733
3759
  }
3760
+
3761
+ // The content kept for retrying failed messages follows the failed jobs it belongs
3762
+ // to: whatever the clean above removed, and whatever aged out, is dropped here
3763
+ try {
3764
+ const pruned = await pruneFailedContent({ logger });
3765
+ logger.trace({ msg: 'Failed message content pruned', ...pruned });
3766
+ } catch (err) {
3767
+ logger.error({ msg: 'Failed to prune the content of failed messages', err });
3768
+ }
3734
3769
  }
3735
3770
 
3736
3771
  const queueCleanupTimer = setInterval(cleanupQueues, QUEUE_CLEANUP_INTERVAL);