emailengine-app 2.84.2 → 2.85.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 (86) hide show
  1. package/.ncurc.js +5 -3
  2. package/.prettierignore +5 -1
  3. package/.prettierrc.js +2 -0
  4. package/.release-please-manifest.json +1 -1
  5. package/CHANGELOG.md +33 -0
  6. package/Dockerfile +6 -0
  7. package/README.md +1 -1
  8. package/bin/emailengine.js +434 -408
  9. package/copy-static-files.sh +39 -14
  10. package/data/google-crawlers.json +1 -1
  11. package/data/public_suffix_list.dat +16562 -0
  12. package/eslint.config.js +81 -99
  13. package/lib/account.js +36 -5
  14. package/lib/api-reference/format.js +4 -3
  15. package/lib/api-routes/account-routes.js +177 -12
  16. package/lib/api-routes/blocklist-routes.js +23 -2
  17. package/lib/api-routes/delivery-test-routes.js +26 -3
  18. package/lib/api-routes/export-routes.js +28 -2
  19. package/lib/api-routes/gateway-routes.js +28 -2
  20. package/lib/api-routes/mailbox-routes.js +41 -2
  21. package/lib/api-routes/message-routes.js +97 -3
  22. package/lib/api-routes/oauth2-app-routes.js +48 -15
  23. package/lib/api-routes/outbox-routes.js +45 -11
  24. package/lib/api-routes/permission-map.js +12 -1
  25. package/lib/api-routes/settings-routes.js +23 -2
  26. package/lib/api-routes/submit-routes.js +336 -309
  27. package/lib/api-routes/template-routes.js +38 -2
  28. package/lib/api-routes/token-routes.js +142 -96
  29. package/lib/api-routes/webhook-route-routes.js +13 -2
  30. package/lib/bounce-detect.js +397 -205
  31. package/lib/consts.js +5 -4
  32. package/lib/email-client/base-client.js +10 -31
  33. package/lib/email-client/gmail-client.js +9 -11
  34. package/lib/email-client/imap/mailbox.js +3 -19
  35. package/lib/email-client/imap/subconnection.js +1 -1
  36. package/lib/email-client/imap-client.js +1 -1
  37. package/lib/email-client/notification-handler.js +1 -2
  38. package/lib/gateway.js +2 -3
  39. package/lib/hapi-request-logger.js +107 -0
  40. package/lib/imapproxy/imap-core/README.md +6 -5
  41. package/lib/mcp/tools.js +37 -8
  42. package/lib/notify-attachments.js +17 -0
  43. package/lib/oauth/outlook-mailbox.js +35 -0
  44. package/lib/oauth/state.js +24 -0
  45. package/lib/oauth2-apps.js +1 -1
  46. package/lib/pbkdf2-phc.js +1 -1
  47. package/lib/schemas.js +1 -1
  48. package/lib/sso.js +1 -1
  49. package/lib/swagger-options.js +1 -1
  50. package/lib/thread-diagnostics.js +46 -0
  51. package/lib/timezones.js +109 -0
  52. package/lib/token-permission-view.js +3 -3
  53. package/lib/tools.js +40 -10
  54. package/lib/totp.js +2 -5
  55. package/lib/translations.js +1 -2
  56. package/lib/ui-routes/account-routes.js +475 -454
  57. package/lib/ui-routes/account-setup.js +99 -0
  58. package/lib/ui-routes/admin-config-routes.js +88 -10
  59. package/lib/ui-routes/admin-entities-routes.js +91 -7
  60. package/lib/ui-routes/auth-routes.js +90 -38
  61. package/lib/ui-routes/internals-routes.js +5 -0
  62. package/lib/ui-routes/oauth-config-routes.js +124 -82
  63. package/lib/ui-routes/route-helpers.js +19 -3
  64. package/lib/ui-routes/tls-config-routes.js +58 -15
  65. package/lib/utils/back-off.js +82 -0
  66. package/lib/utils/murmurhash3.js +66 -0
  67. package/lib/utils/public-suffix.js +122 -0
  68. package/lib/utils/random-id.js +26 -0
  69. package/lib/utils/version.js +74 -0
  70. package/lib/webhook-routing.js +27 -0
  71. package/lib/webhooks.js +41 -6
  72. package/package.json +27 -29
  73. package/sbom.json +7980 -1
  74. package/server.js +634 -441
  75. package/static/licenses.html +181 -1006
  76. package/translations/messages.pot +62 -63
  77. package/views/config/ai.hbs +1 -1
  78. package/views/config/security.hbs +2 -2
  79. package/views/config/service.hbs +3 -0
  80. package/views/internals/index.hbs +8 -0
  81. package/views/partials/webhook_form.hbs +1 -1
  82. package/views/suppression-lists/index.hbs +1 -1
  83. package/workers/api.js +738 -583
  84. package/workers/export.js +1 -1
  85. package/workers/submit.js +1 -1
  86. package/workers/webhooks.js +16 -32
@@ -190,9 +190,32 @@ async function listPasskeysForView(username) {
190
190
  });
191
191
  }
192
192
 
193
- function init(args) {
194
- const { server } = args;
195
-
193
+ // --- Passkey (WebAuthn) routes ---
194
+
195
+ const passkeyCredentialSchema = Joi.object({
196
+ id: Joi.string()
197
+ .max(512)
198
+ .pattern(/^[A-Za-z0-9_-]+$/)
199
+ .required(),
200
+ rawId: Joi.string()
201
+ .max(512)
202
+ .pattern(/^[A-Za-z0-9_-]+$/)
203
+ .required(),
204
+ response: Joi.object({
205
+ clientDataJSON: Joi.string().max(16384).required(),
206
+ attestationObject: Joi.string().max(65536),
207
+ authenticatorData: Joi.string().max(8192),
208
+ signature: Joi.string().max(2048),
209
+ userHandle: Joi.string().max(512).allow(''),
210
+ publicKey: Joi.string().max(4096),
211
+ publicKeyAlgorithm: Joi.number().integer()
212
+ }).required(),
213
+ type: Joi.string().valid('public-key').required(),
214
+ authenticatorAttachment: Joi.string().optional(),
215
+ clientExtensionResults: Joi.object().optional()
216
+ }).required();
217
+
218
+ function registerGetLogin(server) {
196
219
  server.route({
197
220
  method: 'GET',
198
221
  path: '/admin/login',
@@ -290,7 +313,9 @@ function init(args) {
290
313
  }
291
314
  }
292
315
  });
316
+ }
293
317
 
318
+ function registerGetLogout(server) {
294
319
  server.route({
295
320
  method: 'GET',
296
321
  path: '/admin/logout',
@@ -320,7 +345,9 @@ function init(args) {
320
345
  return h.redirect('/');
321
346
  }
322
347
  });
348
+ }
323
349
 
350
+ function registerPostLogin(server) {
324
351
  server.route({
325
352
  method: 'POST',
326
353
  path: '/admin/login',
@@ -499,7 +526,9 @@ function init(args) {
499
526
  }
500
527
  }
501
528
  });
529
+ }
502
530
 
531
+ function registerGetTotp(server) {
503
532
  server.route({
504
533
  method: 'GET',
505
534
  path: '/admin/totp',
@@ -548,7 +577,9 @@ function init(args) {
548
577
  }
549
578
  }
550
579
  });
580
+ }
551
581
 
582
+ function registerPostTotp(server) {
552
583
  server.route({
553
584
  method: 'POST',
554
585
  path: '/admin/totp',
@@ -751,7 +782,9 @@ function init(args) {
751
782
  }
752
783
  }
753
784
  });
785
+ }
754
786
 
787
+ function registerGetAccountSecurity(server) {
755
788
  server.route({
756
789
  method: 'GET',
757
790
  path: '/admin/account/security',
@@ -831,11 +864,13 @@ function init(args) {
831
864
  );
832
865
  }
833
866
  });
867
+ }
834
868
 
835
- // Passkeys get a page of their own, the way the password does: the security page above is an
836
- // inventory of ways into the account, and a credential list that grows to MAX_PASSKEYS_PER_USER
837
- // rows would take it over. Registering needs an account password, so an instance without one
838
- // has nothing to show here.
869
+ // Passkeys get a page of their own, the way the password does: the security page above is an
870
+ // inventory of ways into the account, and a credential list that grows to MAX_PASSKEYS_PER_USER
871
+ // rows would take it over. Registering needs an account password, so an instance without one
872
+ // has nothing to show here.
873
+ function registerGetAccountPasskeys(server) {
839
874
  server.route({
840
875
  method: 'GET',
841
876
  path: '/admin/account/passkeys',
@@ -884,7 +919,9 @@ function init(args) {
884
919
  );
885
920
  }
886
921
  });
922
+ }
887
923
 
924
+ function registerPostAccountTfaEnable(server) {
888
925
  server.route({
889
926
  method: 'POST',
890
927
  path: '/admin/account/tfa/enable',
@@ -961,7 +998,9 @@ function init(args) {
961
998
  }
962
999
  }
963
1000
  });
1001
+ }
964
1002
 
1003
+ function registerPostAccountTfaDisable(server) {
965
1004
  server.route({
966
1005
  method: 'POST',
967
1006
  path: '/admin/account/tfa/disable',
@@ -1016,7 +1055,9 @@ function init(args) {
1016
1055
  }
1017
1056
  }
1018
1057
  });
1058
+ }
1019
1059
 
1060
+ function registerPostAccountLogoutAll(server) {
1020
1061
  server.route({
1021
1062
  method: 'POST',
1022
1063
  path: '/admin/account/logout-all',
@@ -1059,33 +1100,10 @@ function init(args) {
1059
1100
  }
1060
1101
  }
1061
1102
  });
1103
+ }
1062
1104
 
1063
- // --- Passkey (WebAuthn) routes ---
1064
-
1065
- const passkeyCredentialSchema = Joi.object({
1066
- id: Joi.string()
1067
- .max(512)
1068
- .pattern(/^[A-Za-z0-9_-]+$/)
1069
- .required(),
1070
- rawId: Joi.string()
1071
- .max(512)
1072
- .pattern(/^[A-Za-z0-9_-]+$/)
1073
- .required(),
1074
- response: Joi.object({
1075
- clientDataJSON: Joi.string().max(16384).required(),
1076
- attestationObject: Joi.string().max(65536),
1077
- authenticatorData: Joi.string().max(8192),
1078
- signature: Joi.string().max(2048),
1079
- userHandle: Joi.string().max(512).allow(''),
1080
- publicKey: Joi.string().max(4096),
1081
- publicKeyAlgorithm: Joi.number().integer()
1082
- }).required(),
1083
- type: Joi.string().valid('public-key').required(),
1084
- authenticatorAttachment: Joi.string().optional(),
1085
- clientExtensionResults: Joi.object().optional()
1086
- }).required();
1087
-
1088
- // Registration: generate options (authenticated)
1105
+ // Registration: generate options (authenticated)
1106
+ function registerPostAccountPasskeysRegisterOptions(server) {
1089
1107
  server.route({
1090
1108
  method: 'POST',
1091
1109
  path: '/admin/account/passkeys/register/options',
@@ -1157,8 +1175,10 @@ function init(args) {
1157
1175
  }
1158
1176
  }
1159
1177
  });
1178
+ }
1160
1179
 
1161
- // Registration: verify response (authenticated)
1180
+ // Registration: verify response (authenticated)
1181
+ function registerPostAccountPasskeysRegisterVerify(server) {
1162
1182
  server.route({
1163
1183
  method: 'POST',
1164
1184
  path: '/admin/account/passkeys/register/verify',
@@ -1258,8 +1278,10 @@ function init(args) {
1258
1278
  }
1259
1279
  }
1260
1280
  });
1281
+ }
1261
1282
 
1262
- // Delete passkey (authenticated)
1283
+ // Delete passkey (authenticated)
1284
+ function registerPostAccountPasskeysDelete(server) {
1263
1285
  server.route({
1264
1286
  method: 'POST',
1265
1287
  path: '/admin/account/passkeys/delete',
@@ -1313,8 +1335,10 @@ function init(args) {
1313
1335
  }
1314
1336
  }
1315
1337
  });
1338
+ }
1316
1339
 
1317
- // Authentication: generate options (unauthenticated)
1340
+ // Authentication: generate options (unauthenticated)
1341
+ function registerPostPasskeyAuthOptions(server) {
1318
1342
  server.route({
1319
1343
  method: 'POST',
1320
1344
  path: '/admin/passkey/auth/options',
@@ -1376,8 +1400,10 @@ function init(args) {
1376
1400
  }
1377
1401
  }
1378
1402
  });
1403
+ }
1379
1404
 
1380
- // Authentication: verify response (unauthenticated)
1405
+ // Authentication: verify response (unauthenticated)
1406
+ function registerPostPasskeyAuthVerify(server) {
1381
1407
  server.route({
1382
1408
  method: 'POST',
1383
1409
  path: '/admin/passkey/auth/verify',
@@ -1487,9 +1513,11 @@ function init(args) {
1487
1513
  }
1488
1514
  }
1489
1515
  });
1516
+ }
1490
1517
 
1491
- // --- End of Passkey routes ---
1518
+ // --- End of Passkey routes ---
1492
1519
 
1520
+ function registerGetAccountPassword(server) {
1493
1521
  server.route({
1494
1522
  method: 'GET',
1495
1523
  path: '/admin/account/password',
@@ -1518,7 +1546,9 @@ function init(args) {
1518
1546
  );
1519
1547
  }
1520
1548
  });
1549
+ }
1521
1550
 
1551
+ function registerPostAccountPassword(server) {
1522
1552
  server.route({
1523
1553
  method: 'POST',
1524
1554
  path: '/admin/account/password',
@@ -1681,4 +1711,26 @@ function init(args) {
1681
1711
  });
1682
1712
  }
1683
1713
 
1714
+ function init(args) {
1715
+ const { server } = args;
1716
+
1717
+ registerGetLogin(server);
1718
+ registerGetLogout(server);
1719
+ registerPostLogin(server);
1720
+ registerGetTotp(server);
1721
+ registerPostTotp(server);
1722
+ registerGetAccountSecurity(server);
1723
+ registerGetAccountPasskeys(server);
1724
+ registerPostAccountTfaEnable(server);
1725
+ registerPostAccountTfaDisable(server);
1726
+ registerPostAccountLogoutAll(server);
1727
+ registerPostAccountPasskeysRegisterOptions(server);
1728
+ registerPostAccountPasskeysRegisterVerify(server);
1729
+ registerPostAccountPasskeysDelete(server);
1730
+ registerPostPasskeyAuthOptions(server);
1731
+ registerPostPasskeyAuthVerify(server);
1732
+ registerGetAccountPassword(server);
1733
+ registerPostAccountPassword(server);
1734
+ }
1735
+
1684
1736
  module.exports = init;
@@ -145,6 +145,11 @@ function init(args) {
145
145
  threadInfo.heapUsed = bytesFormatter.format(threadInfo.heapUsed).replace(/BB$/, 'GB');
146
146
  }
147
147
 
148
+ // Longest delay over the collector's last window; a thread's first reading has none yet
149
+ if (!threadInfo.isUnresponsive && typeof threadInfo.eventLoopDelay?.max === 'number') {
150
+ threadInfo.eventLoopDelayMax = Math.round(threadInfo.eventLoopDelay.max);
151
+ }
152
+
148
153
  // Email (sync) workers own account assignment, but the count field is absent
149
154
  // when a worker currently syncs none - show an explicit 0 instead of a blank.
150
155
  if (threadInfo.type === 'imap' && typeof threadInfo.accounts !== 'number') {
@@ -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;
@@ -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,