emailengine-app 2.84.2 → 2.86.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 (164) hide show
  1. package/.ncurc.js +29 -9
  2. package/.prettierignore +5 -1
  3. package/.prettierrc.js +2 -0
  4. package/.release-please-manifest.json +1 -1
  5. package/CHANGELOG.md +107 -0
  6. package/Dockerfile +20 -1
  7. package/ENVIRONMENT.md +139 -0
  8. package/README.md +2 -2
  9. package/bin/emailengine.js +434 -408
  10. package/config/default.toml +2 -0
  11. package/copy-static-files.sh +41 -14
  12. package/data/google-crawlers.json +1 -1
  13. package/data/public_suffix_list.dat +16563 -0
  14. package/eslint.config.js +81 -99
  15. package/lib/account-assignment.js +19 -0
  16. package/lib/account.js +230 -170
  17. package/lib/api-error-codes.js +49 -0
  18. package/lib/api-reference/format.js +4 -3
  19. package/lib/api-reference/model.js +6 -1
  20. package/lib/api-routes/account-routes.js +255 -38
  21. package/lib/api-routes/blocklist-routes.js +91 -4
  22. package/lib/api-routes/delivery-test-routes.js +27 -4
  23. package/lib/api-routes/export-routes.js +28 -2
  24. package/lib/api-routes/gateway-routes.js +110 -12
  25. package/lib/api-routes/index.js +4 -0
  26. package/lib/api-routes/license-routes.js +2 -2
  27. package/lib/api-routes/mailbox-routes.js +44 -5
  28. package/lib/api-routes/message-routes.js +112 -10
  29. package/lib/api-routes/oauth2-app-routes.js +63 -23
  30. package/lib/api-routes/outbox-routes.js +97 -52
  31. package/lib/api-routes/permission-map.js +67 -7
  32. package/lib/api-routes/scoped-routes.js +74 -0
  33. package/lib/api-routes/settings-routes.js +34 -6
  34. package/lib/api-routes/stats-routes.js +5 -1
  35. package/lib/api-routes/submit-routes.js +337 -309
  36. package/lib/api-routes/template-routes.js +45 -8
  37. package/lib/api-routes/token-routes.js +152 -100
  38. package/lib/api-routes/webhook-delivery-routes.js +262 -0
  39. package/lib/api-routes/webhook-route-routes.js +132 -6
  40. package/lib/bounce-detect.js +397 -205
  41. package/lib/calendar-event.js +81 -1
  42. package/lib/consts.js +38 -45
  43. package/lib/db.js +14 -6
  44. package/lib/delivery-error.js +6 -0
  45. package/lib/deprecations.js +270 -0
  46. package/lib/email-client/base-client.js +137 -184
  47. package/lib/email-client/fallback-poll.js +62 -0
  48. package/lib/email-client/gmail-client.js +60 -22
  49. package/lib/email-client/imap/adaptive-idle-store.js +73 -0
  50. package/lib/email-client/imap/adaptive-idle.js +278 -0
  51. package/lib/email-client/imap/connection-errors.js +14 -1
  52. package/lib/email-client/imap/idle-settings.js +31 -5
  53. package/lib/email-client/imap/listing-diff.js +37 -0
  54. package/lib/email-client/imap/mailbox.js +372 -242
  55. package/lib/email-client/imap/subconnection.js +8 -30
  56. package/lib/email-client/imap/sync-operations.js +220 -127
  57. package/lib/email-client/imap-client.js +228 -164
  58. package/lib/email-client/message-builder.js +14 -79
  59. package/lib/email-client/notification-handler.js +1 -2
  60. package/lib/email-client/outlook-client.js +372 -338
  61. package/lib/email-client/smtp-pool-manager.js +16 -13
  62. package/lib/email-client/sync-state-fields.js +19 -0
  63. package/lib/encrypt.js +157 -41
  64. package/lib/enum-descriptions.js +3 -1
  65. package/lib/env-setting-overrides.js +288 -0
  66. package/lib/export-worker.js +751 -0
  67. package/lib/export.js +64 -15
  68. package/lib/gateway.js +19 -4
  69. package/lib/get-raw-email.js +25 -107
  70. package/lib/hapi-request-logger.js +107 -0
  71. package/lib/health.js +75 -0
  72. package/lib/imapproxy/imap-core/README.md +6 -5
  73. package/lib/lock-run.js +119 -0
  74. package/lib/logger-consts.js +48 -0
  75. package/lib/logger.js +1 -1
  76. package/lib/lua/z-head-scores.lua +28 -0
  77. package/lib/mcp/tools.js +37 -8
  78. package/lib/network-errors.js +1 -1
  79. package/lib/node-version.js +24 -0
  80. package/lib/notify-attachments.js +36 -0
  81. package/lib/oauth/outlook-mailbox.js +35 -0
  82. package/lib/oauth/state.js +24 -0
  83. package/lib/oauth2-apps.js +631 -656
  84. package/lib/outbox.js +184 -54
  85. package/lib/parse-message.js +3 -3
  86. package/lib/pbkdf2-phc.js +1 -1
  87. package/lib/privileged-settings.js +2 -2
  88. package/lib/queue-browser/definitions.js +11 -0
  89. package/lib/queue-browser/index.js +68 -19
  90. package/lib/queue-job-actions.js +18 -1
  91. package/lib/queue-retention.js +48 -12
  92. package/lib/queue-stats.js +11 -2
  93. package/lib/read-env-value.js +3 -0
  94. package/lib/redis-memory-warnings.js +99 -0
  95. package/lib/redis-reconnect.js +29 -0
  96. package/lib/request-timing.js +23 -0
  97. package/lib/respawn-backoff.js +35 -0
  98. package/lib/rewrite-text-nodes.js +19 -59
  99. package/lib/schemas.js +164 -40
  100. package/lib/settings.js +6 -2
  101. package/lib/smtp-auth.js +19 -1
  102. package/lib/sso.js +1 -1
  103. package/lib/swagger-options.js +1 -1
  104. package/lib/thread-diagnostics.js +63 -0
  105. package/lib/timezones.js +109 -0
  106. package/lib/tls/provision.js +6 -3
  107. package/lib/token-audit-log.js +19 -20
  108. package/lib/token-permission-view.js +7 -6
  109. package/lib/tools.js +48 -51
  110. package/lib/totp.js +2 -5
  111. package/lib/translations.js +1 -2
  112. package/lib/ui-routes/account-routes.js +475 -454
  113. package/lib/ui-routes/account-setup.js +99 -0
  114. package/lib/ui-routes/admin-config-routes.js +152 -100
  115. package/lib/ui-routes/admin-entities-routes.js +93 -21
  116. package/lib/ui-routes/auth-routes.js +90 -38
  117. package/lib/ui-routes/imap-idle-field.js +1 -1
  118. package/lib/ui-routes/internals-routes.js +5 -0
  119. package/lib/ui-routes/oauth-config-routes.js +124 -82
  120. package/lib/ui-routes/outlook-subscription-view.js +1 -1
  121. package/lib/ui-routes/overridable-fields.js +84 -0
  122. package/lib/ui-routes/queue-routes.js +8 -5
  123. package/lib/ui-routes/route-helpers.js +19 -3
  124. package/lib/ui-routes/settings-page.js +6 -0
  125. package/lib/ui-routes/tls-config-routes.js +58 -15
  126. package/lib/utils/back-off.js +82 -0
  127. package/lib/utils/decode-headers.js +3 -12
  128. package/lib/utils/filter-empty.js +20 -0
  129. package/lib/utils/int-setting.js +48 -0
  130. package/lib/utils/murmurhash3.js +66 -0
  131. package/lib/utils/public-suffix.js +122 -0
  132. package/lib/utils/random-id.js +26 -0
  133. package/lib/utils/tracking-settings.js +35 -0
  134. package/lib/utils/version.js +74 -0
  135. package/lib/web-safe-html.js +18 -105
  136. package/lib/webhook-delivery.js +461 -0
  137. package/lib/webhook-failures.js +132 -0
  138. package/lib/webhook-request.js +29 -1
  139. package/lib/webhook-routing.js +56 -0
  140. package/lib/webhook-test.js +88 -0
  141. package/lib/webhooks.js +93 -45
  142. package/lib/worker-rpc-error.js +2 -1
  143. package/package.json +37 -38
  144. package/sbom.json +7902 -1
  145. package/server.js +784 -518
  146. package/static/js/ace/ace.js +1 -1
  147. package/static/licenses.html +225 -1060
  148. package/translations/messages.pot +62 -63
  149. package/views/config/ai.hbs +1 -1
  150. package/views/config/security.hbs +24 -2
  151. package/views/config/service.hbs +47 -0
  152. package/views/config/webhooks.hbs +36 -0
  153. package/views/internals/index.hbs +8 -0
  154. package/views/partials/queue_retention_note.hbs +12 -8
  155. package/views/partials/ui/env-managed-alert.hbs +16 -7
  156. package/views/partials/webhook_form.hbs +1 -1
  157. package/views/suppression-lists/index.hbs +1 -1
  158. package/workers/api.js +840 -611
  159. package/workers/export.js +17 -632
  160. package/workers/imap.js +13 -0
  161. package/workers/smtp.js +9 -11
  162. package/workers/submit.js +1 -1
  163. package/workers/webhooks.js +18 -448
  164. package/lib/email-client/outlook-fallback-poll.js +0 -30
@@ -52,93 +52,89 @@ const AZURE_CLOUDS = [
52
52
  }
53
53
  ];
54
54
 
55
- function init(args) {
56
- const { server, call } = args;
57
-
58
- gmailServiceAuthRoutes({ server });
59
-
60
- /**
61
- * View context for re-rendering the new or edit OAuth2 app form after a failed save, from the
62
- * submitted fields. One function for the handler's catch and the validation failAction of both
63
- * forms, so the four copies cannot drift again: the secret fields are blanked (the edit page
64
- * never echoes a stored secret, and the API masks them), and on the edit form the
65
- * authentication method stays locked once the app has one.
66
- *
67
- * @param {Object} request - the Hapi request carrying the submitted payload
68
- * @param {Object} [appData] - the stored app when editing, absent when creating
69
- * @param {Object} [errors] - field errors to show
70
- * @returns {Promise<Object>}
71
- */
72
- async function appFormErrorContext(request, appData, errors) {
73
- const payload = request.payload;
74
- const provider = appData ? appData.provider : payload.provider;
75
- const providerData = appData ? oauth2ProviderData(appData.provider, appData.cloud) : oauth2ProviderData(provider);
76
-
77
- const serviceUrl = await settings.get('serviceUrl');
78
- let defaultRedirectUrl = `${serviceUrl}/oauth`;
79
- if (provider === 'outlook') {
80
- defaultRedirectUrl = defaultRedirectUrl.replace(/^http:\/\/127\.0\.0\.1\b/i, 'http://localhost');
81
- }
82
-
83
- const context = {
84
- pageTitle: 'OAuth2 Apps',
85
- menuOauthApps: true,
86
-
87
- [`active${providerData.caseName}`]: true,
88
- providerData,
89
- defaultRedirectUrl,
90
-
91
- pubSubApps: await getPubSubAppsForSelect(payload.pubSubApp),
92
-
93
- ...baseScopesContext(payload.baseScopes),
94
-
95
- azureClouds: structuredClone(AZURE_CLOUDS).map(entry => {
96
- entry.selected = payload.cloud === entry.id;
97
- return entry;
98
- }),
99
-
100
- // The submitted fields, not the stored app: without them the new-app form loses its
101
- // provider on a validation error and the next submit is bounced to /admin
102
- values: submittedValues(request, 'clientSecret', 'serviceKey', 'externalAccount'),
103
-
104
- authorityCommon: payload.authority === 'common',
105
- authorityOrganizations: payload.authority === 'organizations',
106
- authorityConsumers: payload.authority === 'consumers',
107
- authorityTenant: payload.authority === 'tenant',
108
-
109
- errors
110
- };
111
-
112
- if (appData) {
113
- Object.assign(context, {
114
- appData,
115
- hasClientSecret: !!appData.clientSecret,
116
- hasServiceKey: !!appData.serviceKey,
117
- hasExternalAccount: !!appData.externalAccount,
118
- ...authMethodContext(appData.authMethod, isAuthMethodLocked(appData))
119
- });
120
- } else {
121
- Object.assign(context, { actionCreate: true, ...authMethodContext(payload.authMethod) });
122
- }
55
+ /**
56
+ * View context for re-rendering the new or edit OAuth2 app form after a failed save, from the
57
+ * submitted fields. One function for the handler's catch and the validation failAction of both
58
+ * forms, so the four copies cannot drift again: the secret fields are blanked (the edit page
59
+ * never echoes a stored secret, and the API masks them), and on the edit form the
60
+ * authentication method stays locked once the app has one.
61
+ *
62
+ * @param {Object} request - the Hapi request carrying the submitted payload
63
+ * @param {Object} [appData] - the stored app when editing, absent when creating
64
+ * @param {Object} [errors] - field errors to show
65
+ * @returns {Promise<Object>}
66
+ */
67
+ async function appFormErrorContext(request, appData, errors) {
68
+ const payload = request.payload;
69
+ const provider = appData ? appData.provider : payload.provider;
70
+ const providerData = appData ? oauth2ProviderData(appData.provider, appData.cloud) : oauth2ProviderData(provider);
71
+
72
+ const serviceUrl = await settings.get('serviceUrl');
73
+ let defaultRedirectUrl = `${serviceUrl}/oauth`;
74
+ if (provider === 'outlook') {
75
+ defaultRedirectUrl = defaultRedirectUrl.replace(/^http:\/\/127\.0\.0\.1\b/i, 'http://localhost');
76
+ }
123
77
 
124
- return context;
78
+ const context = {
79
+ pageTitle: 'OAuth2 Apps',
80
+ menuOauthApps: true,
81
+
82
+ [`active${providerData.caseName}`]: true,
83
+ providerData,
84
+ defaultRedirectUrl,
85
+
86
+ pubSubApps: await getPubSubAppsForSelect(payload.pubSubApp),
87
+
88
+ ...baseScopesContext(payload.baseScopes),
89
+
90
+ azureClouds: structuredClone(AZURE_CLOUDS).map(entry => {
91
+ entry.selected = payload.cloud === entry.id;
92
+ return entry;
93
+ }),
94
+
95
+ // The submitted fields, not the stored app: without them the new-app form loses its
96
+ // provider on a validation error and the next submit is bounced to /admin
97
+ values: submittedValues(request, 'clientSecret', 'serviceKey', 'externalAccount'),
98
+
99
+ authorityCommon: payload.authority === 'common',
100
+ authorityOrganizations: payload.authority === 'organizations',
101
+ authorityConsumers: payload.authority === 'consumers',
102
+ authorityTenant: payload.authority === 'tenant',
103
+
104
+ errors
105
+ };
106
+
107
+ if (appData) {
108
+ Object.assign(context, {
109
+ appData,
110
+ hasClientSecret: !!appData.clientSecret,
111
+ hasServiceKey: !!appData.serviceKey,
112
+ hasExternalAccount: !!appData.externalAccount,
113
+ ...authMethodContext(appData.authMethod, isAuthMethodLocked(appData))
114
+ });
115
+ } else {
116
+ Object.assign(context, { actionCreate: true, ...authMethodContext(payload.authMethod) });
125
117
  }
126
118
 
127
- /**
128
- * Fetch the list of Pub/Sub apps and mark the one matching selectedId as selected.
129
- * Returns the apps array ready for template rendering.
130
- */
131
- async function getPubSubAppsForSelect(selectedId) {
132
- let result = await oauth2Apps.list(0, 1000, { pubsub: true });
133
- let apps = (result && result.apps) || [];
134
- for (let app of apps) {
135
- if (app.id === selectedId) {
136
- app.selected = true;
137
- }
119
+ return context;
120
+ }
121
+
122
+ /**
123
+ * Fetch the list of Pub/Sub apps and mark the one matching selectedId as selected.
124
+ * Returns the apps array ready for template rendering.
125
+ */
126
+ async function getPubSubAppsForSelect(selectedId) {
127
+ let result = await oauth2Apps.list(0, 1000, { pubsub: true });
128
+ let apps = (result && result.apps) || [];
129
+ for (let app of apps) {
130
+ if (app.id === selectedId) {
131
+ app.selected = true;
138
132
  }
139
- return apps;
140
133
  }
134
+ return apps;
135
+ }
141
136
 
137
+ function registerGetConfigOauth(server) {
142
138
  server.route({
143
139
  method: 'GET',
144
140
  path: '/admin/config/oauth',
@@ -240,8 +236,10 @@ function init(args) {
240
236
  }
241
237
  }
242
238
  });
239
+ }
243
240
 
244
- // GET /admin/config/oauth/subscriptions - Gmail Pub/Sub subscriptions list
241
+ // GET /admin/config/oauth/subscriptions - Gmail Pub/Sub subscriptions list
242
+ function registerGetConfigOauthSubscriptions(server) {
245
243
  server.route({
246
244
  method: 'GET',
247
245
  path: '/admin/config/oauth/subscriptions',
@@ -353,7 +351,9 @@ function init(args) {
353
351
  }
354
352
  }
355
353
  });
354
+ }
356
355
 
356
+ function registerPostConfigOauthSubscriptions(server) {
357
357
  server.route({
358
358
  method: 'POST',
359
359
  path: '/admin/config/oauth/subscriptions',
@@ -391,7 +391,9 @@ function init(args) {
391
391
  }
392
392
  }
393
393
  });
394
+ }
394
395
 
396
+ function registerGetConfigOauthApp(server) {
395
397
  server.route({
396
398
  method: 'GET',
397
399
  path: '/admin/config/oauth/app/{app}',
@@ -489,6 +491,10 @@ function init(args) {
489
491
  }
490
492
  }
491
493
  });
494
+ }
495
+
496
+ function registerPostConfigOauthDelete(server, args) {
497
+ const { call } = args;
492
498
 
493
499
  server.route({
494
500
  method: 'POST',
@@ -533,6 +539,10 @@ function init(args) {
533
539
  }
534
540
  }
535
541
  });
542
+ }
543
+
544
+ function registerPostConfigOauthAppAddAccount(server, args) {
545
+ const { call } = args;
536
546
 
537
547
  server.route({
538
548
  method: 'POST',
@@ -606,7 +616,9 @@ function init(args) {
606
616
  }
607
617
  }
608
618
  });
619
+ }
609
620
 
621
+ function registerPostConfigOauthVerify(server) {
610
622
  server.route({
611
623
  method: 'POST',
612
624
  path: '/admin/config/oauth/verify/{app}',
@@ -646,7 +658,9 @@ function init(args) {
646
658
  }
647
659
  }
648
660
  });
661
+ }
649
662
 
663
+ function registerGetConfigOauthNew(server) {
650
664
  server.route({
651
665
  method: 'GET',
652
666
  path: '/admin/config/oauth/new',
@@ -727,6 +741,10 @@ function init(args) {
727
741
  }
728
742
  }
729
743
  });
744
+ }
745
+
746
+ function registerPostConfigOauthNew(server, args) {
747
+ const { call } = args;
730
748
 
731
749
  server.route({
732
750
  method: 'POST',
@@ -799,7 +817,9 @@ function init(args) {
799
817
  }
800
818
  }
801
819
  });
820
+ }
802
821
 
822
+ function registerGetConfigOauthEdit(server) {
803
823
  server.route({
804
824
  method: 'GET',
805
825
  path: '/admin/config/oauth/edit/{app}',
@@ -885,6 +905,10 @@ function init(args) {
885
905
  }
886
906
  }
887
907
  });
908
+ }
909
+
910
+ function registerPostConfigOauthEdit(server, args) {
911
+ const { call } = args;
888
912
 
889
913
  server.route({
890
914
  method: 'POST',
@@ -966,4 +990,22 @@ function init(args) {
966
990
  });
967
991
  }
968
992
 
993
+ function init(args) {
994
+ const { server } = args;
995
+
996
+ gmailServiceAuthRoutes({ server });
997
+
998
+ registerGetConfigOauth(server);
999
+ registerGetConfigOauthSubscriptions(server);
1000
+ registerPostConfigOauthSubscriptions(server);
1001
+ registerGetConfigOauthApp(server);
1002
+ registerPostConfigOauthDelete(server, args);
1003
+ registerPostConfigOauthAppAddAccount(server, args);
1004
+ registerPostConfigOauthVerify(server);
1005
+ registerGetConfigOauthNew(server);
1006
+ registerPostConfigOauthNew(server, args);
1007
+ registerGetConfigOauthEdit(server);
1008
+ registerPostConfigOauthEdit(server, args);
1009
+ }
1010
+
969
1011
  module.exports = init;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const { FALLBACK_POLL_INTERVAL } = require('../email-client/outlook-fallback-poll');
3
+ const { OUTLOOK_FALLBACK_POLL_INTERVAL: FALLBACK_POLL_INTERVAL } = require('../email-client/fallback-poll');
4
4
 
5
5
  /**
6
6
  * Adds the fields the account page renders for a Graph change subscription, in place
@@ -0,0 +1,84 @@
1
+ 'use strict';
2
+
3
+ // Form fields for the settings that an environment variable can override
4
+ // (lib/env-setting-overrides.js). Some are shown in a friendlier unit than the one stored - days
5
+ // for a setting kept in seconds, megabytes for one kept in bytes - so the conversion lives here,
6
+ // next to the values the pages read and write. A blank field arrives as null and stays null,
7
+ // which writeOverridableSettings() reads as "clear this setting".
8
+
9
+ const { getOverridableSettings } = require('../env-setting-overrides');
10
+
11
+ const DAY = 24 * 3600;
12
+ const MEGABYTE = 1024 * 1024;
13
+
14
+ const isNumber = value => typeof value === 'number' && Number.isFinite(value);
15
+
16
+ // Rounded to two decimals so an age set through the API in odd seconds still shows something a
17
+ // form can submit back unchanged in meaning
18
+ const secondsToDays = seconds => (isNumber(seconds) ? Math.round((seconds / DAY) * 100) / 100 : null);
19
+ const daysToSeconds = days => (isNumber(days) ? Math.round(days * DAY) : null);
20
+
21
+ const bytesToMegabytes = bytes => (isNumber(bytes) ? Math.round((bytes / MEGABYTE) * 100) / 100 : null);
22
+ const megabytesToBytes = megabytes => (isNumber(megabytes) ? Math.round(megabytes * MEGABYTE) : null);
23
+
24
+ const msToSeconds = ms => (isNumber(ms) ? Math.round(ms / 10) / 100 : null);
25
+ const secondsToMs = seconds => (isNumber(seconds) ? Math.round(seconds * 1000) : null);
26
+
27
+ // key -> [stored to form, form to stored]; keys not listed are shown as stored. Not limited to the
28
+ // overridable settings: any settings form field kept in a unit other than the one it shows is here
29
+ const FORM_UNITS = {
30
+ queueKeepFailedAge: [secondsToDays, daysToSeconds],
31
+ queueKeepFailedContentSize: [bytesToMegabytes, megabytesToBytes],
32
+ tokenLogAge: [secondsToDays, daysToSeconds],
33
+ webhooksRetryDelay: [msToSeconds, secondsToMs]
34
+ };
35
+
36
+ /**
37
+ * A stored value in the unit its form field shows
38
+ * @param {string} key - Setting key
39
+ * @param {*} value - Stored value
40
+ * @returns {*}
41
+ */
42
+ const toFormValue = (key, value) => (FORM_UNITS[key] ? FORM_UNITS[key][0](value) : value);
43
+
44
+ /**
45
+ * A form value in the unit the setting is stored in
46
+ * @param {string} key - Setting key
47
+ * @param {*} value - Validated form value, null for a blank field
48
+ * @returns {*}
49
+ */
50
+ const fromFormValue = (key, value) => (FORM_UNITS[key] ? FORM_UNITS[key][1](value) : value);
51
+
52
+ /**
53
+ * The values in effect for the given keys, in the units their form fields show. The page shows
54
+ * what applies whichever source set it, the environment included.
55
+ * @param {...string} keys - Overridable setting keys
56
+ * @returns {Promise<Object>} field name -> value
57
+ */
58
+ async function overridableFormValues(...keys) {
59
+ const values = await getOverridableSettings(...keys);
60
+ return Object.fromEntries(keys.map(key => [key, toFormValue(key, values[key])]));
61
+ }
62
+
63
+ /**
64
+ * The settings to write for the given keys from a validated form payload, in stored units.
65
+ * @param {Object} payload - Validated request payload
66
+ * @param {...string} keys - Overridable setting keys
67
+ * @returns {Object} key -> value (null to clear)
68
+ */
69
+ function overridableSettingsFromForm(payload, ...keys) {
70
+ return Object.fromEntries(keys.map(key => [key, fromFormValue(key, payload[key] === undefined ? null : payload[key])]));
71
+ }
72
+
73
+ module.exports = {
74
+ overridableFormValues,
75
+ overridableSettingsFromForm,
76
+ toFormValue,
77
+ fromFormValue,
78
+ secondsToDays,
79
+ daysToSeconds,
80
+ bytesToMegabytes,
81
+ megabytesToBytes,
82
+ msToSeconds,
83
+ secondsToMs
84
+ };
@@ -12,7 +12,7 @@ const Boom = require('@hapi/boom');
12
12
 
13
13
  const { buildPagingView } = require('./route-helpers');
14
14
  const queueBrowser = require('../queue-browser');
15
- const { QUEUE_NAMES, STATE_NAMES, DEFAULT_STATE, SCAN_LIMIT } = require('../queue-browser/definitions');
15
+ const { QUEUE_NAMES, STATE_NAMES, DEFAULT_STATE, SCAN_LIMIT, BULL_BOARD_DEPRECATION } = require('../queue-browser/definitions');
16
16
  const { DEFAULT_PAGE_SIZE } = require('../consts');
17
17
 
18
18
  const QUEUE_PARAM = Joi.string()
@@ -194,7 +194,7 @@ function init(args) {
194
194
  listing,
195
195
  scanLimit: SCAN_LIMIT,
196
196
  retention,
197
- failedContent: { limits: queueBrowser.failedContentLimits() },
197
+ failedContent: { limits: await queueBrowser.failedContentLimits() },
198
198
 
199
199
  filter: Object.assign({ active: listing.filtered, label: filterLabel }, filterParams),
200
200
  clearHref: listUrl(queueDef.name, { state }),
@@ -348,13 +348,15 @@ function init(args) {
348
348
 
349
349
  // Compatibility for the retired bull-board page: its own URL and the queue deep links
350
350
  // written against it (the docs, the dashboard of older releases, bookmarks) land on the
351
- // matching page here.
351
+ // matching page here. Deprecated, removed after REMOVAL_DATE (lib/deprecations.js)
352
+
352
353
  server.route({
353
354
  method: 'GET',
354
355
  path: '/admin/bull-board',
355
356
  handler(request, h) {
356
357
  return h.redirect('/admin/queues');
357
- }
358
+ },
359
+ options: { plugins: { deprecation: BULL_BOARD_DEPRECATION } }
358
360
  });
359
361
 
360
362
  server.route({
@@ -364,7 +366,8 @@ function init(args) {
364
366
  const path = decodeURIComponent(request.params.path || '');
365
367
  const queueName = QUEUE_NAMES.find(name => path.includes(name));
366
368
  return h.redirect(queueName ? `/admin/queues/${queueName}` : '/admin/queues');
367
- }
369
+ },
370
+ options: { plugins: { deprecation: BULL_BOARD_DEPRECATION } }
368
371
  });
369
372
  }
370
373
 
@@ -13,7 +13,7 @@ const Boom = require('@hapi/boom');
13
13
  const util = require('util');
14
14
  const fs = require('fs');
15
15
  const pathlib = require('path');
16
- const psl = require('psl');
16
+ const { getRegistrableDomain } = require('../utils/public-suffix');
17
17
  const handlebars = require('handlebars');
18
18
 
19
19
  const { redis } = require('../db');
@@ -177,11 +177,11 @@ function formatAccountData(account, gt) {
177
177
  } else if (account.imap && !account.imap.disabled) {
178
178
  account.type.icon = 'icon-[tabler--mail]';
179
179
  account.type.name = 'IMAP';
180
- account.type.comment = psl.get(account.imap.host) || account.imap.host;
180
+ account.type.comment = getRegistrableDomain(account.imap.host) || account.imap.host;
181
181
  } else if (account.smtp) {
182
182
  account.type.icon = 'icon-[tabler--send]';
183
183
  account.type.name = 'SMTP';
184
- account.type.comment = psl.get(account.smtp.host) || account.smtp.host;
184
+ account.type.comment = getRegistrableDomain(account.smtp.host) || account.smtp.host;
185
185
  } else if (account.oauth2 && account.oauth2.auth && account.oauth2.auth.delegatedAccount) {
186
186
  account.type.icon = 'icon-[tabler--arrow-right-circle]';
187
187
  account.type.name = gt.gettext('Delegated');
@@ -364,6 +364,21 @@ function workspaceErrorView(request, h, { actualEmail, retryUrl }) {
364
364
  return setupRefusalView(request, h, 'account-workspace-error', { actualEmail, retryUrl });
365
365
  }
366
366
 
367
+ // The page a successful setup ends on, from both arms of the form. An HTML redirect rather than an
368
+ // HTTP one, otherwise samesite=strict cookies are not passed on.
369
+ function renderRedirect(request, h, httpRedirectUrl) {
370
+ return h.view(
371
+ 'redirect',
372
+ {
373
+ pageTitleFull: request.app.gt.gettext('Email Account Setup'),
374
+ httpRedirectUrl
375
+ },
376
+ {
377
+ layout: 'public'
378
+ }
379
+ );
380
+ }
381
+
367
382
  // View-model for the ui/pagination partial: prev/next URLs plus the numbered page links.
368
383
  // basePath is the URL path without a query string (leading slash optional, matching the
369
384
  // `new URL(path, base)` convention the route modules already use); data is a listing
@@ -593,6 +608,7 @@ module.exports = {
593
608
  accountPickerSelection,
594
609
  identityErrorView,
595
610
  workspaceErrorView,
611
+ renderRedirect,
596
612
  compiledFragments,
597
613
  closedAfterConnectMessage,
598
614
  accountStateLabel,
@@ -29,9 +29,14 @@
29
29
  // so - the way the logging page flags the SENTRY_DSN pinned fields. Field names are matched to
30
30
  // settings keys as-is, which holds for every page except the logging form, whose
31
31
  // `all`/`maxLogLines` fields fold into the `logs` setting.
32
+ //
33
+ // Renders also carry `envOverriddenSettings`, the fields whose own environment variable is set
34
+ // (lib/env-setting-overrides.js): the variable wins over the setting, so the page shows the value
35
+ // in effect and a value typed into such a field is not saved.
32
36
 
33
37
  const Joi = require('joi');
34
38
  const settings = require('../settings');
39
+ const { envOverriddenSettings } = require('../env-setting-overrides');
35
40
 
36
41
  function registerSettingsPage(server, page) {
37
42
  const { path, view, pageTitle, menuKey, schema, loadValues, applySettings, errorValues, viewContext } = page;
@@ -45,6 +50,7 @@ function registerSettingsPage(server, page) {
45
50
  }
46
51
  const preparedKeys = (await settings.get('preparedSettingsKeys')) || [];
47
52
  context.envManagedKeys = preparedKeys.filter(key => Object.hasOwn(schema, key));
53
+ context.envOverriddenSettings = envOverriddenSettings(Object.keys(schema));
48
54
  return context;
49
55
  };
50
56
 
@@ -110,12 +110,10 @@ async function assertConfiguredHostname(hostname) {
110
110
  return name;
111
111
  }
112
112
 
113
- function init(args) {
114
- const { server, call } = args;
115
-
116
- // The path Let's Encrypt fetches to validate a domain, and the only unauthenticated route on
117
- // this module. It lives here rather than in the routes-ui monolith because it is part of the
118
- // certificate story, and because the preflight probe below shares its token store.
113
+ // The path Let's Encrypt fetches to validate a domain, and the only unauthenticated route on
114
+ // this module. It lives here rather than in the routes-ui monolith because it is part of the
115
+ // certificate story, and because the preflight probe below shares its token store.
116
+ function registerAcmeChallenge(server) {
119
117
  server.route({
120
118
  method: 'GET',
121
119
  path: '/.well-known/acme-challenge/{token}',
@@ -157,6 +155,10 @@ Token: ${JSON.stringify(request.params.token)}`
157
155
  auth: false
158
156
  }
159
157
  });
158
+ }
159
+
160
+ function registerTlsSettingsPage(server, args) {
161
+ const { call } = args;
160
162
 
161
163
  registerSettingsPage(server, {
162
164
  path: TLS_PAGE,
@@ -185,12 +187,16 @@ Token: ${JSON.stringify(request.params.token)}`
185
187
  await maybeReloadTlsCertificates(call, request.logger, changed ? ['tlsProvisioning'] : [], { action: 'settings' });
186
188
  }
187
189
  });
190
+ }
191
+
192
+ // Hostnames are rows of the certificate table, added and removed one at a time. Each write
193
+ // reloads the listeners: they resolve their material against the hostname list, and the
194
+ // self-signed fallback is regenerated when that list no longer matches what it covers. Without
195
+ // the reload a name added here is served the previous certificate until something else restarts
196
+ // the worker, and the page would report a certificate the listener is not using.
197
+ function registerPostConfigTlsHostnames(server, args) {
198
+ const { call } = args;
188
199
 
189
- // Hostnames are rows of the certificate table, added and removed one at a time. Each write
190
- // reloads the listeners: they resolve their material against the hostname list, and the
191
- // self-signed fallback is regenerated when that list no longer matches what it covers. Without
192
- // the reload a name added here is served the previous certificate until something else restarts
193
- // the worker, and the page would report a certificate the listener is not using.
194
200
  server.route({
195
201
  method: 'POST',
196
202
  path: '/admin/config/tls/hostnames',
@@ -235,6 +241,10 @@ Token: ${JSON.stringify(request.params.token)}`
235
241
  }
236
242
  }
237
243
  });
244
+ }
245
+
246
+ function registerPostConfigTlsHostnamesDelete(server, args) {
247
+ const { call } = args;
238
248
 
239
249
  server.route({
240
250
  method: 'POST',
@@ -290,11 +300,15 @@ Token: ${JSON.stringify(request.params.token)}`
290
300
  }
291
301
  }
292
302
  });
303
+ }
304
+
305
+ // Which certificate each listener presents by default. One form for the three listeners,
306
+ // posted with a Save button rather than on change: a wrong default is what a client sees on
307
+ // its next handshake, and three dropdowns that each reload every listener the moment they are
308
+ // touched is three chances to do that by accident.
309
+ function registerPostConfigTlsListeners(server, args) {
310
+ const { call } = args;
293
311
 
294
- // Which certificate each listener presents by default. One form for the three listeners,
295
- // posted with a Save button rather than on change: a wrong default is what a client sees on
296
- // its next handshake, and three dropdowns that each reload every listener the moment they are
297
- // touched is three chances to do that by accident.
298
312
  server.route({
299
313
  method: 'POST',
300
314
  path: '/admin/config/tls/listeners',
@@ -358,7 +372,9 @@ Token: ${JSON.stringify(request.params.token)}`
358
372
  }
359
373
  }
360
374
  });
375
+ }
361
376
 
377
+ function registerGetUploadPage(server) {
362
378
  server.route({
363
379
  method: 'GET',
364
380
  path: UPLOAD_PAGE,
@@ -375,7 +391,9 @@ Token: ${JSON.stringify(request.params.token)}`
375
391
  );
376
392
  }
377
393
  });
394
+ }
378
395
 
396
+ function registerPostConfigTlsRequest(server) {
379
397
  server.route({
380
398
  method: 'POST',
381
399
  path: '/admin/config/tls/request',
@@ -410,7 +428,9 @@ Token: ${JSON.stringify(request.params.token)}`
410
428
  }
411
429
  }
412
430
  });
431
+ }
413
432
 
433
+ function registerPostConfigTlsPreflight(server) {
414
434
  server.route({
415
435
  method: 'POST',
416
436
  path: '/admin/config/tls/preflight',
@@ -434,6 +454,10 @@ Token: ${JSON.stringify(request.params.token)}`
434
454
  }
435
455
  }
436
456
  });
457
+ }
458
+
459
+ function registerPostConfigTlsUpload(server, args) {
460
+ const { call } = args;
437
461
 
438
462
  server.route({
439
463
  method: 'POST',
@@ -488,6 +512,10 @@ Token: ${JSON.stringify(request.params.token)}`
488
512
  }
489
513
  }
490
514
  });
515
+ }
516
+
517
+ function registerPostConfigTlsDelete(server, args) {
518
+ const { call } = args;
491
519
 
492
520
  server.route({
493
521
  method: 'POST',
@@ -549,6 +577,21 @@ Token: ${JSON.stringify(request.params.token)}`
549
577
  });
550
578
  }
551
579
 
580
+ function init(args) {
581
+ const { server } = args;
582
+
583
+ registerAcmeChallenge(server);
584
+ registerTlsSettingsPage(server, args);
585
+ registerPostConfigTlsHostnames(server, args);
586
+ registerPostConfigTlsHostnamesDelete(server, args);
587
+ registerPostConfigTlsListeners(server, args);
588
+ registerGetUploadPage(server);
589
+ registerPostConfigTlsRequest(server);
590
+ registerPostConfigTlsPreflight(server);
591
+ registerPostConfigTlsUpload(server, args);
592
+ registerPostConfigTlsDelete(server, args);
593
+ }
594
+
552
595
  /**
553
596
  * The whole page model: the certificate for every configured name, every certificate the instance
554
597
  * holds, and the listeners with the default each is set to and what each is serving right now.