emailengine-app 2.90.0 → 2.91.0

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 (64) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +29 -0
  3. package/Dockerfile +2 -2
  4. package/ENVIRONMENT.md +24 -23
  5. package/README.md +1 -1
  6. package/data/google-crawlers.json +1 -1
  7. package/lib/account-assignment.js +26 -9
  8. package/lib/account.js +38 -9
  9. package/lib/api-routes/account-routes.js +7 -0
  10. package/lib/autodetect-imap-settings.js +401 -64
  11. package/lib/consts.js +4 -0
  12. package/lib/email-client/imap-client.js +5 -5
  13. package/lib/email-client/message-builder.js +4 -5
  14. package/lib/imapproxy/imap-server.js +5 -5
  15. package/lib/logger-consts.js +37 -1
  16. package/lib/mail-probe.js +157 -0
  17. package/lib/oauth/mail-ru.js +9 -2
  18. package/lib/read-env-value.js +30 -6
  19. package/lib/redis-backend-warnings.js +70 -0
  20. package/lib/tools.js +17 -28
  21. package/lib/ui-routes/account-routes.js +34 -31
  22. package/lib/ui-routes/account-setup.js +1 -1
  23. package/lib/ui-routes/provider-signin.js +187 -0
  24. package/lib/ui-routes/route-helpers.js +1 -1
  25. package/lib/ui-routes/unsubscribe-routes.js +2 -2
  26. package/package.json +13 -13
  27. package/sbom.json +231 -260
  28. package/server.js +80 -1
  29. package/static/css/public.css +55 -1
  30. package/static/licenses.html +126 -148
  31. package/translations/de.mo +0 -0
  32. package/translations/de.po +429 -390
  33. package/translations/en.mo +0 -0
  34. package/translations/en.po +342 -257
  35. package/translations/es.mo +0 -0
  36. package/translations/es.po +440 -395
  37. package/translations/et.mo +0 -0
  38. package/translations/et.po +425 -375
  39. package/translations/fr.mo +0 -0
  40. package/translations/fr.po +425 -383
  41. package/translations/it.mo +0 -0
  42. package/translations/it.po +441 -394
  43. package/translations/ja.mo +0 -0
  44. package/translations/ja.po +408 -335
  45. package/translations/messages.pot +136 -89
  46. package/translations/nl.mo +0 -0
  47. package/translations/nl.po +419 -382
  48. package/translations/pl.mo +0 -0
  49. package/translations/pl.po +425 -379
  50. package/translations/sv.mo +0 -0
  51. package/translations/sv.po +440 -388
  52. package/translations/tr.mo +0 -0
  53. package/translations/tr.po +441 -387
  54. package/views/account-identity-error.hbs +1 -1
  55. package/views/account-workspace-error.hbs +2 -2
  56. package/views/accounts/register/imap-server.hbs +22 -7
  57. package/views/accounts/register/imap.hbs +3 -0
  58. package/views/accounts/register/index.hbs +1 -27
  59. package/views/accounts/register/provider-signin.hbs +58 -0
  60. package/views/oauth-scope-error.hbs +1 -1
  61. package/views/partials/provider_signin_button.hbs +30 -0
  62. package/views/queues/index.hbs +1 -1
  63. package/views/redirect.hbs +1 -1
  64. package/views/unsubscribe.hbs +6 -6
package/server.js CHANGED
@@ -62,6 +62,15 @@ if (nodeSupportLevel === 'outside-range') {
62
62
  console.error(`Node.js ${process.version} is outside the range EmailEngine supports (${SUPPORTED_RANGE_LABEL}). It runs, but please upgrade Node.js.`);
63
63
  }
64
64
 
65
+ // Validates EENGINE_LOG_REDACT_HEADERS before the logger loads, so a bad entry stops the boot with a
66
+ // one-line message instead of a stack trace
67
+ try {
68
+ require('./lib/logger-consts');
69
+ } catch (err) {
70
+ console.error(err.message);
71
+ process.exit(1);
72
+ }
73
+
65
74
  const { accountDataKey } = require('./lib/redis-keys');
66
75
  const { resolveMetricKeys, statBuckets } = require('./lib/worker-metrics');
67
76
  const { importPreparedPassword } = require('./lib/prepared-password');
@@ -180,6 +189,7 @@ const {
180
189
  requeueFailedAccounts,
181
190
  forgetAccount,
182
191
  shouldRequeueFailedAssignment,
192
+ findUntrackedAccounts,
183
193
  planRebalance
184
194
  } = require('./lib/account-assignment');
185
195
  const { mapConcurrent } = require('./lib/utils/map-concurrent');
@@ -587,6 +597,10 @@ let reassignmentPending = false; // Flag to track if reassignment is pending
587
597
  const REASSIGNMENT_FAILSAFE_DELAY = 10 * 1000; // How long an exited IMAP worker gets to restart before its accounts move
588
598
  let assignRetryCount = 0; // Counter for safety-net retries in assignAccounts
589
599
  let assignRetryTimer = null; // The pending safety-net retry, so passes do not stack them
600
+ // Accounts the orphan sweep adopted, announced with accountAdded once a pass actually assigns them
601
+ // (which may be a later retry pass, not the one the sweep started)
602
+ let announceOnAssign = new Set();
603
+ const ORPHAN_SWEEP_INTERVAL = 60 * 60 * 1000;
590
604
 
591
605
  // Worker management
592
606
  let imapInitialWorkersLoaded = false; // Have all initial IMAP workers started?
@@ -1793,14 +1807,19 @@ async function assignAccounts() {
1793
1807
 
1794
1808
  logger.error({ msg: 'Failed to assign account to worker', account, threadId: worker.threadId, err });
1795
1809
 
1796
- if (await shouldRequeueFailedAssignment(err, account, isRegisteredAccount)) {
1810
+ if (await shouldRequeueFailedAssignment(account, isRegisteredAccount)) {
1797
1811
  failedAccounts.push(account);
1798
1812
  } else {
1813
+ announceOnAssign.delete(account);
1799
1814
  logger.info({ msg: 'Dropped assignment of an account that no longer exists', account });
1800
1815
  }
1801
1816
  continue;
1802
1817
  }
1803
1818
 
1819
+ if (announceOnAssign.delete(account)) {
1820
+ sendWebhook(account, ACCOUNT_ADDED_NOTIFY, { account }).catch(err => logger.error({ msg: 'Account added webhook failed', account, err }));
1821
+ }
1822
+
1804
1823
  // Add delay between assignments to avoid overwhelming the system
1805
1824
  if (CONNECTION_SETUP_DELAY) {
1806
1825
  await new Promise(r => setTimeout(r, CONNECTION_SETUP_DELAY));
@@ -1849,6 +1868,47 @@ async function assignAccounts() {
1849
1868
  }
1850
1869
  }
1851
1870
 
1871
+ /**
1872
+ * Safety net for registered accounts the assignment state lost track of. assignAccounts() reads the
1873
+ * registered set only on its first run, so an account whose `new` dispatch never reached the main
1874
+ * thread (Account.notifyWorker() logs that failure rather than failing the saved create) stayed
1875
+ * unsynced until a restart. Queues such accounts and announces each with accountAdded once a pass
1876
+ * assigns it, since the lost dispatch was what would have announced it
1877
+ * @returns {Promise<void>}
1878
+ */
1879
+ async function sweepOrphanedAccounts() {
1880
+ if (isClosing || assigning || !unassigned || !availableIMAPWorkers.size) {
1881
+ return;
1882
+ }
1883
+
1884
+ // SSCAN in batches rather than SMEMBERS, so a large account set does not stall the main thread
1885
+ let candidates = new Set();
1886
+ let cursor = '0';
1887
+ do {
1888
+ let [nextCursor, batch] = await redis.sscan(`${REDIS_PREFIX}ia:accounts`, cursor, 'COUNT', 1000);
1889
+ cursor = nextCursor;
1890
+ for (let account of findUntrackedAccounts(batch, { assigned, unassigned })) {
1891
+ candidates.add(account);
1892
+ }
1893
+ } while (cursor !== '0' && !isClosing);
1894
+
1895
+ // Settled after the scan: a create has queued the account and an assignment pass may have
1896
+ // picked some up. An account deleted during the scan is dropped by the pass's membership check
1897
+ // after its assign fails, before anything is announced
1898
+ let orphaned = findUntrackedAccounts(candidates, { assigned, unassigned });
1899
+ if (!orphaned.length || isClosing) {
1900
+ return;
1901
+ }
1902
+
1903
+ logger.warn({ msg: 'Queueing registered accounts that were never assigned', count: orphaned.length, accounts: orphaned.slice(0, 20) });
1904
+ for (let account of orphaned) {
1905
+ unassigned.add(account);
1906
+ announceOnAssign.add(account);
1907
+ }
1908
+ // When a pass is already running this returns at once; that pass's retry picks the accounts up
1909
+ await assignAccounts();
1910
+ }
1911
+
1852
1912
  // License checking state
1853
1913
  let licenseCheckTimer = false;
1854
1914
  let checkingLicense = false;
@@ -2805,6 +2865,20 @@ async function commandNewAccount(worker, message) {
2805
2865
  // before that used to throw here and fail the request with a 500. Skipping the add is
2806
2866
  // safe rather than merely quiet: the account is already in `ia:accounts` by the time
2807
2867
  // this message is sent, so the first load picks it up.
2868
+ //
2869
+ // This dispatch announces the account itself, so the orphan sweep must not announce it again
2870
+ announceOnAssign.delete(message.account);
2871
+ if (assigned.has(message.account)) {
2872
+ // Still assigned: a `delete` for an earlier account with the same id never arrived, or the
2873
+ // orphan sweep adopted this one first. Queueing it again would let the next pass assign it to
2874
+ // a second worker, two connections for one account. The worker holding it reconnects instead,
2875
+ // which reloads the stored record
2876
+ commandForwardToAccountWorker(worker, { cmd: 'reconnect', account: message.account });
2877
+ sendWebhook(message.account, ACCOUNT_ADDED_NOTIFY, { account: message.account }).catch(err =>
2878
+ logger.error({ msg: 'Account added webhook failed', account: message.account, err })
2879
+ );
2880
+ return;
2881
+ }
2808
2882
  if (unassigned) {
2809
2883
  unassigned.add(message.account);
2810
2884
  }
@@ -2820,6 +2894,7 @@ async function commandDeleteAccount(worker, message) {
2820
2894
  // answered with a 500 for a deletion that had in fact succeeded: the account was
2821
2895
  // already gone from Redis by the time this message was sent.
2822
2896
  let assignedWorker = forgetAccount({ workerAssigned, assigned, unassigned }, message.account);
2897
+ announceOnAssign.delete(message.account);
2823
2898
  if (assignedWorker) {
2824
2899
  // Notify worker to clean up
2825
2900
  call(assignedWorker, message)
@@ -3817,6 +3892,10 @@ startApplication()
3817
3892
  collectMetrics().catch(err => logger.error({ msg: 'Metrics collection failed', err }));
3818
3893
  }, 1000).unref();
3819
3894
 
3895
+ setInterval(() => {
3896
+ sweepOrphanedAccounts().catch(err => logger.error({ msg: 'Orphaned account sweep failed', err }));
3897
+ }, ORPHAN_SWEEP_INTERVAL).unref();
3898
+
3820
3899
  // Schedule periodic checks. A monthly-plan license, or one that is not in good standing, is
3821
3900
  // checked right away (unless an hour has not passed since the last check, so a restart
3822
3901
  // loop costs one call an hour); everything else after the usual first delay
@@ -191,6 +191,7 @@ body.ee-page {
191
191
  font-size: 1.25rem;
192
192
  font-weight: 600;
193
193
  margin: 0 0 1.5rem;
194
+ text-wrap: balance;
194
195
  }
195
196
 
196
197
  :where(.ee-card-body h2) {
@@ -627,10 +628,18 @@ a.ee-link:hover::before {
627
628
  padding: 1rem;
628
629
  border-radius: var(--ee-radius-box);
629
630
  background-color: color-mix(in oklab, var(--ee-alert-color) 10%, var(--ee-surface));
630
- color: var(--ee-alert-color);
631
+ /* the text is pulled toward the body color: the status colors themselves (amber and cyan
632
+ * especially) are too light to read as text on their own tinted background */
633
+ color: color-mix(in oklab, var(--ee-alert-color) 45%, var(--ee-text));
631
634
  text-align: start;
632
635
  }
633
636
 
637
+ /* the icon keeps the full status color, which is what tells the alerts apart at a glance */
638
+ .ee-alert > .ee-icon {
639
+ flex: none;
640
+ color: var(--ee-alert-color);
641
+ }
642
+
634
643
  .ee-alert-info {
635
644
  --ee-alert-color: var(--ee-info);
636
645
  }
@@ -918,6 +927,51 @@ dialog.ee-modal.ee-modal-wide {
918
927
  cursor: default;
919
928
  }
920
929
 
930
+ /* OAuth2 sign-in offered on the IMAP path (accounts/register/provider-signin):
931
+ * the address and the reason above the provider buttons, and the IMAP way out
932
+ * below them, set apart so it reads as the exception */
933
+ .ee-provider-lead {
934
+ max-width: 30rem;
935
+ margin: 0 auto 1.5rem;
936
+ text-align: center;
937
+ }
938
+
939
+ .ee-provider-lead p {
940
+ margin: 0 0 0.5rem;
941
+ }
942
+
943
+ /* short centered copy: even out the lines instead of leaving a word, or in Japanese a few
944
+ * characters, on a line of its own */
945
+ .ee-provider-lead p,
946
+ .ee-provider-alt .ee-hint {
947
+ text-wrap: balance;
948
+ }
949
+
950
+ .ee-provider-email {
951
+ overflow-wrap: anywhere;
952
+ }
953
+
954
+ .ee-provider-alt {
955
+ display: flex;
956
+ flex-direction: column;
957
+ align-items: center;
958
+ gap: 0.25rem;
959
+ max-width: 30rem;
960
+ margin: 1.5rem auto 0;
961
+ padding-top: 1.25rem;
962
+ border-top: 1px solid color-mix(in oklab, var(--ee-text) 15%, transparent);
963
+ text-align: center;
964
+ }
965
+
966
+ /* Translated labels can wrap without extending beyond the text column. */
967
+ .ee-provider-alt > .ee-btn {
968
+ max-width: 100%;
969
+ height: auto;
970
+ min-height: 1.875rem;
971
+ padding-block: 0.25rem;
972
+ white-space: normal;
973
+ }
974
+
921
975
  /* provider sign-in images (e.g. the Google / Microsoft branded buttons) */
922
976
  .ee-provider-image {
923
977
  display: block;