emailengine-app 2.79.9 → 2.80.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 (146) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +73 -0
  3. package/README.md +6 -0
  4. package/config/default.toml +5 -1
  5. package/data/google-crawlers.json +1 -1
  6. package/encrypt.js +43 -0
  7. package/lib/account/account-state.js +62 -0
  8. package/lib/account.js +34 -2
  9. package/lib/api-routes/account-routes.js +101 -1
  10. package/lib/api-routes/blocklist-routes.js +24 -0
  11. package/lib/api-routes/delivery-test-routes.js +6 -0
  12. package/lib/api-routes/gateway-routes.js +30 -0
  13. package/lib/api-routes/index.js +1 -1
  14. package/lib/api-routes/license-routes.js +10 -0
  15. package/lib/api-routes/mcp-oauth-routes.js +3 -3
  16. package/lib/api-routes/mcp-routes.js +39 -21
  17. package/lib/api-routes/oauth2-app-routes.js +38 -1
  18. package/lib/api-routes/outbox-routes.js +6 -0
  19. package/lib/api-routes/permission-map.js +208 -43
  20. package/lib/api-routes/pubsub-routes.js +8 -0
  21. package/lib/api-routes/route-helpers.js +58 -11
  22. package/lib/api-routes/settings-routes.js +67 -6
  23. package/lib/api-routes/stats-routes.js +6 -0
  24. package/lib/api-routes/template-routes.js +21 -0
  25. package/lib/api-routes/token-routes.js +34 -2
  26. package/lib/api-routes/webhook-route-routes.js +13 -0
  27. package/lib/autodetect-imap-settings.js +349 -47
  28. package/lib/cert-handler.js +62 -0
  29. package/lib/consts.js +50 -6
  30. package/lib/db.js +12 -0
  31. package/lib/egress-fetch.js +21 -9
  32. package/lib/email-client/base-client.js +238 -67
  33. package/lib/email-client/credential-errors.js +122 -0
  34. package/lib/email-client/gmail/gmail-api.js +2 -1
  35. package/lib/email-client/gmail-client.js +70 -64
  36. package/lib/email-client/imap/connection-errors.js +52 -0
  37. package/lib/email-client/imap/listing-diff.js +47 -6
  38. package/lib/email-client/imap/login-failure.js +52 -0
  39. package/lib/email-client/imap/mailbox.js +457 -379
  40. package/lib/email-client/imap/subconnection.js +17 -12
  41. package/lib/email-client/imap/sync-operations.js +46 -59
  42. package/lib/email-client/imap-client.js +139 -101
  43. package/lib/email-client/message-builder.js +11 -11
  44. package/lib/email-client/outlook/graph-api.js +2 -1
  45. package/lib/email-client/outlook-client.js +219 -106
  46. package/lib/enum-descriptions.js +12 -2
  47. package/lib/imap-proxy-auth.js +58 -3
  48. package/lib/imapproxy/imap-server.js +53 -62
  49. package/lib/lua/h-del-if-equals.lua +39 -0
  50. package/lib/lua/h-set-if-equals.lua +39 -0
  51. package/lib/mcp/oauth.js +46 -8
  52. package/lib/mcp/protocol.js +78 -35
  53. package/lib/mcp/tools.js +53 -17
  54. package/lib/privileged-settings.js +147 -0
  55. package/lib/routes-ui.js +4 -34
  56. package/lib/schemas.js +92 -16
  57. package/lib/security-headers.js +15 -0
  58. package/lib/settings.js +13 -0
  59. package/lib/tls/catalog.js +428 -0
  60. package/lib/tls/context.js +302 -0
  61. package/lib/tls/der.js +223 -0
  62. package/lib/tls/listeners.js +62 -0
  63. package/lib/tls/provision.js +555 -0
  64. package/lib/tls/self-signed.js +282 -0
  65. package/lib/tls/status.js +480 -0
  66. package/lib/tls/store.js +667 -0
  67. package/lib/token-permission-view.js +252 -102
  68. package/lib/token-permissions.js +176 -26
  69. package/lib/tokens.js +7 -6
  70. package/lib/tools.js +73 -27
  71. package/lib/ui-routes/account-routes.js +43 -30
  72. package/lib/ui-routes/admin-config-routes.js +63 -22
  73. package/lib/ui-routes/admin-entities-routes.js +23 -13
  74. package/lib/ui-routes/auth-routes.js +16 -1
  75. package/lib/ui-routes/internals-routes.js +3 -5
  76. package/lib/ui-routes/mcp-consent-routes.js +72 -31
  77. package/lib/ui-routes/network-config-routes.js +54 -45
  78. package/lib/ui-routes/tls-config-routes.js +628 -0
  79. package/lib/utils/mailbox-path.js +51 -0
  80. package/lib/utils/severity.js +31 -0
  81. package/package.json +12 -12
  82. package/sbom.json +1 -1
  83. package/server.js +23 -1
  84. package/static/css/flyonui.css +1 -1
  85. package/static/css/src/app.tailwind.css +11 -0
  86. package/static/js/app.js +34 -0
  87. package/static/js/public.js +6 -2
  88. package/static/js/ui.js +97 -61
  89. package/static/licenses.html +341 -1252
  90. package/translations/messages.pot +62 -56
  91. package/views/account/login-redirect.hbs +22 -0
  92. package/views/account/passkeys.hbs +2 -2
  93. package/views/accounts/account.hbs +2 -2
  94. package/views/accounts/browse.hbs +1 -1
  95. package/views/accounts/edit.hbs +1 -1
  96. package/views/accounts/register/imap-server.hbs +1 -1
  97. package/views/config/ai.hbs +1 -1
  98. package/views/config/branding.hbs +2 -2
  99. package/views/config/document-store/chat.hbs +1 -1
  100. package/views/config/document-store/index.hbs +1 -1
  101. package/views/config/imap-proxy.hbs +1 -4
  102. package/views/config/license.hbs +1 -1
  103. package/views/config/mcp.hbs +88 -52
  104. package/views/config/network.hbs +1 -1
  105. package/views/config/oauth/app.hbs +2 -2
  106. package/views/config/service.hbs +1 -1
  107. package/views/config/smtp.hbs +1 -4
  108. package/views/config/tls-upload.hbs +81 -0
  109. package/views/config/tls.hbs +593 -0
  110. package/views/config/webhooks.hbs +2 -2
  111. package/views/internals/index.hbs +1 -1
  112. package/views/layout/app.hbs +6 -6
  113. package/views/layout/login.hbs +5 -5
  114. package/views/layout/main.hbs +2 -2
  115. package/views/layout/prompt.hbs +3 -3
  116. package/views/layout/public.hbs +1 -1
  117. package/views/mcp/authorize.hbs +47 -45
  118. package/views/partials/ace_assets.hbs +1 -1
  119. package/views/partials/add_account_modal.hbs +1 -1
  120. package/views/partials/filter_editor_js.hbs +2 -2
  121. package/views/partials/gateway_js.hbs +1 -1
  122. package/views/partials/mcp_access_levels.hbs +16 -9
  123. package/views/partials/mcp_tool_count.hbs +15 -14
  124. package/views/partials/oauth_form.hbs +1 -1
  125. package/views/partials/public_theme_init.hbs +1 -1
  126. package/views/partials/side_menu.hbs +1 -0
  127. package/views/partials/template_form.hbs +1 -1
  128. package/views/partials/theme_init.hbs +1 -1
  129. package/views/partials/tls_security_card.hbs +25 -53
  130. package/views/partials/ui/alert-banner.hbs +3 -2
  131. package/views/partials/ui/badge.hbs +6 -2
  132. package/views/partials/ui/btn.hbs +5 -2
  133. package/views/partials/webhooks_editor_functions.hbs +1 -1
  134. package/views/reference/index.hbs +1 -1
  135. package/views/reference/redirect.hbs +1 -1
  136. package/views/reference/tag.hbs +1 -1
  137. package/views/reference/token.hbs +1 -1
  138. package/views/templates/template.hbs +1 -1
  139. package/views/tokens/new.hbs +175 -74
  140. package/views/unsubscribe.hbs +1 -1
  141. package/views/webhooks/webhook.hbs +1 -1
  142. package/workers/api.js +102 -142
  143. package/workers/imap-proxy.js +4 -1
  144. package/workers/smtp.js +51 -44
  145. package/views/partials/tls_security_js.hbs +0 -64
  146. package/views/partials/tls_security_modal.hbs +0 -22
@@ -1,10 +1,10 @@
1
1
  msgid ""
2
2
  msgstr ""
3
3
  "Content-Type: text/plain; charset=ascii\n"
4
- "POT-Creation-Date: 2026-09-07 13:17+0000\n"
4
+ "POT-Creation-Date: 2026-09-10 17:19+0000\n"
5
5
 
6
6
  #: views/error.hbs:6
7
- #: workers/api.js:3153
7
+ #: workers/api.js:3130
8
8
  msgid "Something went wrong"
9
9
  msgstr ""
10
10
 
@@ -27,6 +27,12 @@ msgid_plural "%d days"
27
27
  msgstr[0] ""
28
28
  msgstr[1] ""
29
29
 
30
+ #: views/config/tls.hbs:418
31
+ msgid "%d certificate"
32
+ msgid_plural "%d certificates"
33
+ msgstr[0] ""
34
+ msgstr[1] ""
35
+
30
36
  #: views/redirect.hbs:1
31
37
  msgid "Click <a href=\"%s\">here</a> to continue&mldr;"
32
38
  msgstr ""
@@ -287,7 +293,7 @@ msgid ""
287
293
  "contact the service that sent you this link."
288
294
  msgstr ""
289
295
 
290
- #: lib/autodetect-imap-settings.js:111
296
+ #: lib/autodetect-imap-settings.js:151
291
297
  msgid ""
292
298
  "Microsoft has disabled password-based sign-ins (including app passwords) "
293
299
  "for Outlook.com, Hotmail.com, and Microsoft 365 email accounts. To "
@@ -295,103 +301,103 @@ msgid ""
295
301
  "connect your account."
296
302
  msgstr ""
297
303
 
298
- #: lib/tools.js:1480
304
+ #: lib/tools.js:1526
299
305
  #: lib/ui-routes/unsubscribe-routes.js:31
300
306
  #: lib/ui-routes/unsubscribe-routes.js:99
301
307
  msgid "Invalid input"
302
308
  msgstr ""
303
309
 
304
- #: lib/tools.js:2345
310
+ #: lib/tools.js:2391
305
311
  msgid "Signature validation failed"
306
312
  msgstr ""
307
313
 
308
- #: lib/tools.js:2368
309
- #: lib/tools.js:2374
310
- #: lib/tools.js:2379
311
- #: lib/ui-routes/account-routes.js:1149
314
+ #: lib/tools.js:2414
315
+ #: lib/tools.js:2420
316
+ #: lib/tools.js:2425
317
+ #: lib/ui-routes/account-routes.js:1157
312
318
  msgid "Invalid or expired account setup URL"
313
319
  msgstr ""
314
320
 
315
- #: lib/ui-routes/account-routes.js:479
316
- #: lib/ui-routes/account-routes.js:523
317
- #: lib/ui-routes/account-routes.js:767
318
- #: lib/ui-routes/account-routes.js:818
319
- #: lib/ui-routes/account-routes.js:875
320
- #: lib/ui-routes/account-routes.js:1262
321
+ #: lib/ui-routes/account-routes.js:481
322
+ #: lib/ui-routes/account-routes.js:525
323
+ #: lib/ui-routes/account-routes.js:769
324
+ #: lib/ui-routes/account-routes.js:826
325
+ #: lib/ui-routes/account-routes.js:883
326
+ #: lib/ui-routes/account-routes.js:1270
321
327
  #: lib/ui-routes/route-helpers.js:403
322
- #: workers/api.js:2325
323
- #: workers/api.js:2395
328
+ #: workers/api.js:2302
329
+ #: workers/api.js:2372
324
330
  msgid "Email Account Setup"
325
331
  msgstr ""
326
332
 
327
- #: lib/ui-routes/account-routes.js:548
328
- #: lib/ui-routes/account-routes.js:580
333
+ #: lib/ui-routes/account-routes.js:550
334
+ #: lib/ui-routes/account-routes.js:582
329
335
  #: lib/ui-routes/unsubscribe-routes.js:71
330
336
  msgid "Invalid request. Check your input and try again."
331
337
  msgstr ""
332
338
 
333
- #: lib/ui-routes/account-routes.js:713
339
+ #: lib/ui-routes/account-routes.js:715
334
340
  msgid "Too many attempts for this setup link. Request a new setup link to continue."
335
341
  msgstr ""
336
342
 
337
- #: lib/ui-routes/account-routes.js:862
338
- #: lib/ui-routes/account-routes.js:1199
343
+ #: lib/ui-routes/account-routes.js:870
344
+ #: lib/ui-routes/account-routes.js:1207
339
345
  msgid "Couldn't set up account. Try again."
340
346
  msgstr ""
341
347
 
342
- #: lib/ui-routes/account-routes.js:950
343
- #: lib/ui-routes/account-routes.js:990
344
- #: lib/ui-routes/admin-entities-routes.js:2077
348
+ #: lib/ui-routes/account-routes.js:958
349
+ #: lib/ui-routes/account-routes.js:998
350
+ #: lib/ui-routes/admin-entities-routes.js:2078
345
351
  msgid "Server hostname was not found"
346
352
  msgstr ""
347
353
 
348
- #: lib/ui-routes/account-routes.js:953
349
- #: lib/ui-routes/account-routes.js:993
350
- #: lib/ui-routes/admin-entities-routes.js:2080
354
+ #: lib/ui-routes/account-routes.js:961
355
+ #: lib/ui-routes/account-routes.js:1001
356
+ #: lib/ui-routes/admin-entities-routes.js:2081
351
357
  msgid "Invalid username or password"
352
358
  msgstr ""
353
359
 
354
- #: lib/ui-routes/account-routes.js:958
355
- #: lib/ui-routes/account-routes.js:1010
356
- #: lib/ui-routes/admin-entities-routes.js:2097
360
+ #: lib/ui-routes/account-routes.js:966
361
+ #: lib/ui-routes/account-routes.js:1018
362
+ #: lib/ui-routes/admin-entities-routes.js:2098
357
363
  msgid "Connection timed out"
358
364
  msgstr ""
359
365
 
360
- #: lib/ui-routes/account-routes.js:964
361
- #: lib/ui-routes/account-routes.js:1013
362
- #: lib/ui-routes/admin-entities-routes.js:2100
366
+ #: lib/ui-routes/account-routes.js:972
367
+ #: lib/ui-routes/account-routes.js:1021
368
+ #: lib/ui-routes/admin-entities-routes.js:2101
363
369
  msgid "Could not connect to server"
364
370
  msgstr ""
365
371
 
366
- #: lib/ui-routes/account-routes.js:977
367
- #: lib/ui-routes/account-routes.js:981
368
- #: lib/ui-routes/account-routes.js:1002
369
- #: lib/ui-routes/account-routes.js:1006
370
- #: lib/ui-routes/admin-entities-routes.js:2089
371
- #: lib/ui-routes/admin-entities-routes.js:2093
372
+ #: lib/ui-routes/account-routes.js:985
373
+ #: lib/ui-routes/account-routes.js:989
374
+ #: lib/ui-routes/account-routes.js:1010
375
+ #: lib/ui-routes/account-routes.js:1014
376
+ #: lib/ui-routes/admin-entities-routes.js:2090
377
+ #: lib/ui-routes/admin-entities-routes.js:2094
372
378
  msgid "TLS protocol error"
373
379
  msgstr ""
374
380
 
375
- #: lib/ui-routes/account-routes.js:996
376
- #: lib/ui-routes/admin-entities-routes.js:2083
381
+ #: lib/ui-routes/account-routes.js:1004
382
+ #: lib/ui-routes/admin-entities-routes.js:2084
377
383
  msgid "Authentication credentials were not provided"
378
384
  msgstr ""
379
385
 
380
- #: lib/ui-routes/account-routes.js:999
381
- #: lib/ui-routes/admin-entities-routes.js:2086
386
+ #: lib/ui-routes/account-routes.js:1007
387
+ #: lib/ui-routes/admin-entities-routes.js:2087
382
388
  msgid "OAuth2 authentication failed"
383
389
  msgstr ""
384
390
 
385
- #: lib/ui-routes/account-routes.js:1016
386
- #: lib/ui-routes/admin-entities-routes.js:2103
391
+ #: lib/ui-routes/account-routes.js:1024
392
+ #: lib/ui-routes/admin-entities-routes.js:2104
387
393
  msgid "Unexpected server response"
388
394
  msgstr ""
389
395
 
390
- #: lib/ui-routes/account-routes.js:1137
396
+ #: lib/ui-routes/account-routes.js:1145
391
397
  msgid "Temporary error, please try again"
392
398
  msgstr ""
393
399
 
394
- #: lib/ui-routes/admin-config-routes.js:172
400
+ #: lib/ui-routes/admin-config-routes.js:193
395
401
  msgid "Invalid API key for OpenAI"
396
402
  msgstr ""
397
403
 
@@ -445,37 +451,37 @@ msgstr ""
445
451
  msgid "Couldn't process request. Try again."
446
452
  msgstr ""
447
453
 
448
- #: workers/api.js:2254
454
+ #: workers/api.js:2231
449
455
  msgid ""
450
456
  "The sign-in was cancelled or the requested access was not granted. Open the "
451
457
  "account setup link again to retry."
452
458
  msgstr ""
453
459
 
454
- #: workers/api.js:2263
460
+ #: workers/api.js:2240
455
461
  msgid "Sign-in with the email provider failed: %s"
456
462
  msgstr ""
457
463
 
458
- #: workers/api.js:2267
464
+ #: workers/api.js:2244
459
465
  msgid "Sign-in with the email provider failed: no authorization code was received"
460
466
  msgstr ""
461
467
 
462
- #: workers/api.js:2273
468
+ #: workers/api.js:2250
463
469
  msgid "Sign-in with the email provider failed: the request state is not valid"
464
470
  msgstr ""
465
471
 
466
- #: workers/api.js:2279
472
+ #: workers/api.js:2256
467
473
  msgid ""
468
474
  "The account setup session has expired or was already used. Open the account "
469
475
  "setup link again to retry."
470
476
  msgstr ""
471
477
 
472
- #: workers/api.js:2286
478
+ #: workers/api.js:2263
473
479
  msgid ""
474
480
  "Sign-in with the email provider failed: the stored setup session is not "
475
481
  "valid"
476
482
  msgstr ""
477
483
 
478
- #: workers/api.js:3152
479
- #: workers/api.js:3267
484
+ #: workers/api.js:3129
485
+ #: workers/api.js:3244
480
486
  msgid "Requested page not found"
481
487
  msgstr ""
@@ -0,0 +1,22 @@
1
+ {{!-- Forced-SSO hand-off. This page exists instead of an HTTP redirect because Chrome checks a
2
+ form submission's redirect target against the SUBMITTING page's form-action: when a session expires
3
+ mid-form, the browser follows POST /admin/x -> /admin/login -> the provider as one submission, and
4
+ the admin policy's `form-action 'self'` kills that last hop, so the form silently does nothing. A
5
+ navigation this page starts is not part of that submission, so the policy no longer applies to it.
6
+
7
+ The per-route relaxation that lets the account page's Re-authenticate button redirect to a provider
8
+ (OAUTH_REDIRECT_FORM_DIRECTIVES) cannot help here: the policy being enforced belongs to whichever
9
+ admin page held the form, which is any of them.
10
+
11
+ location.replace() rather than a meta refresh: it leaves no history entry, so Back does not land
12
+ here and bounce the user straight out again, which is how the HTTP redirect behaved. The link is
13
+ what a browser that did not run the script gets. --}}
14
+ <h1 class="text-base-content mb-2 text-xl font-semibold">Signing in&mldr;</h1>
15
+
16
+ <p class="text-base-content/60 mb-6 text-sm">Taking you to {{providers.oidc.name}} to sign in.</p>
17
+
18
+ {{> ui/btn label="Continue" href=ssoRedirectUrl id="sso-continue" icon="icon-[tabler--login-2]" class="btn-block"}}
19
+
20
+ <script data-cfasync="false" nonce="{{cspNonce}}">
21
+ window.location.replace(document.getElementById('sso-continue').href);
22
+ </script>
@@ -137,5 +137,5 @@ Are you sure you want to remove <strong class="delete-target-name"></strong>? Yo
137
137
  </div>
138
138
  {{/ui/modal}}
139
139
 
140
- <script src="/static/vendor/simplewebauthn/browser.min.js"></script>
141
- <script src="/static/js/passkey-register.js"></script>
140
+ <script data-cfasync="false" src="/static/vendor/simplewebauthn/browser.min.js"></script>
141
+ <script data-cfasync="false" src="/static/js/passkey-register.js"></script>
@@ -951,7 +951,7 @@ submitLabel="Delete account"}}
951
951
  {{!-- no #crumb input: the layout already renders the element the script reads --}}
952
952
  <input type="hidden" id="account-id" value="{{account.account}}">
953
953
 
954
- <script nonce="{{cspNonce}}">
954
+ <script data-cfasync="false" nonce="{{cspNonce}}">
955
955
  document.addEventListener('DOMContentLoaded', () => {
956
956
 
957
957
  const reconnectAccount = async () => {
@@ -1365,7 +1365,7 @@ submitLabel="Delete account"}}
1365
1365
  });
1366
1366
  </script>
1367
1367
 
1368
- <script nonce="{{cspNonce}}">
1368
+ <script data-cfasync="false" nonce="{{cspNonce}}">
1369
1369
  document.addEventListener('DOMContentLoaded', () => {
1370
1370
  let aborted = false;
1371
1371
 
@@ -26,7 +26,7 @@
26
26
  </div>
27
27
  {{/ui/modal}}
28
28
 
29
- <script type="module" nonce="{{cspNonce}}">
29
+ <script data-cfasync="false" type="module" nonce="{{cspNonce}}">
30
30
  import { EmailEngineClient } from '/static/js/ee-client.js';
31
31
 
32
32
  // Create client with UI container. The embed follows the admin theme -
@@ -140,7 +140,7 @@
140
140
 
141
141
  <input type="hidden" id="availablePaths" value="{{availablePaths}}">
142
142
 
143
- <script nonce="{{cspNonce}}">
143
+ <script data-cfasync="false" nonce="{{cspNonce}}">
144
144
  document.addEventListener('DOMContentLoaded', () => {
145
145
  let availablePaths = JSON.parse(document.getElementById('availablePaths').value);
146
146
  // native datalist suggestions for the Sent Mail folder input (the
@@ -290,7 +290,7 @@ focus ring on) the corner close button --}}
290
290
 
291
291
  <input type="hidden" id="autoTest" value="{{#if autoTest}}true{{/if}}">
292
292
 
293
- <script nonce="{{cspNonce}}">
293
+ <script data-cfasync="false" nonce="{{cspNonce}}">
294
294
  document.addEventListener('DOMContentLoaded', () => {
295
295
 
296
296
  let formTested = false;
@@ -311,7 +311,7 @@ defaultTestPayload='{"account":"test","path":"INBOX","subject":"test email"}'}}
311
311
 
312
312
  <input type="hidden" id="defaultPromptJson" value="{{defaultPromptJson}}">
313
313
 
314
- <script nonce="{{cspNonce}}">
314
+ <script data-cfasync="false" nonce="{{cspNonce}}">
315
315
  document.addEventListener('DOMContentLoaded', () => {
316
316
 
317
317
  const editorPrompt = uiAceEditor("editor-prompt", "markdown", document.getElementById('openAiPromptElement').value, {
@@ -79,9 +79,9 @@
79
79
 
80
80
 
81
81
  {{> ace_assets}}
82
- <script src="/static/js/ace/ext-language_tools.js"></script>
82
+ <script data-cfasync="false" src="/static/js/ace/ext-language_tools.js"></script>
83
83
 
84
- <script nonce="{{cspNonce}}">
84
+ <script data-cfasync="false" nonce="{{cspNonce}}">
85
85
  document.addEventListener('DOMContentLoaded', () => {
86
86
 
87
87
  const editors = new Map();
@@ -171,7 +171,7 @@
171
171
  </form>
172
172
  {{/ui/modal}}
173
173
 
174
- <script nonce="{{cspNonce}}">
174
+ <script data-cfasync="false" nonce="{{cspNonce}}">
175
175
  document.addEventListener('DOMContentLoaded', () => {
176
176
 
177
177
  const sendQuestionPayload = async () => {
@@ -116,7 +116,7 @@
116
116
 
117
117
  </form>
118
118
 
119
- <script nonce="{{cspNonce}}">
119
+ <script data-cfasync="false" nonce="{{cspNonce}}">
120
120
  document.addEventListener('DOMContentLoaded', () => {
121
121
 
122
122
  const sendTestPayload = async () => {
@@ -136,11 +136,10 @@
136
136
 
137
137
  </form>
138
138
 
139
- {{> tls_security_modal}}
140
139
 
141
140
  <input type="hidden" id="availableAddresses" value="{{availableAddresses}}">
142
141
 
143
- <script nonce="{{cspNonce}}">
142
+ <script data-cfasync="false" nonce="{{cspNonce}}">
144
143
  document.addEventListener('DOMContentLoaded', () => {
145
144
 
146
145
  let availableAddresses = document.getElementById('availableAddresses').value.split(',').map(e => e.trim()).filter(e => e);
@@ -185,7 +184,5 @@ $client = $cm->make([
185
184
  ]);`}
186
185
  }
187
186
  });
188
-
189
- {{> tls_security_js field="imapProxyServerTLSEnabled"}}
190
187
  });
191
188
  </script>
@@ -122,7 +122,7 @@ submitLabel="Remove License"}}
122
122
  Remove the current license key from this EmailEngine instance?
123
123
  {{/ui/confirm-modal}}
124
124
 
125
- <script nonce="{{cspNonce}}">
125
+ <script data-cfasync="false" nonce="{{cspNonce}}">
126
126
  document.addEventListener('DOMContentLoaded', () => {
127
127
  let licenseTextElm = document.getElementById('licenseTextElement')
128
128
  let fileSelectElm = document.getElementById('licenseFile');
@@ -1,9 +1,11 @@
1
1
  {{> ui/page-header title="MCP" icon="icon-[tabler--plug-connected]" badgeLabel="Beta" badgeVariant="info" class="mb-1"}}
2
2
 
3
3
  <p class="mb-6">
4
- Let AI agents work with the connected email accounts over the Model Context Protocol. The MCP endpoint exposes a
5
- curated tool set (list and search messages, read content, organize and delete messages, create drafts, send mail)
6
- and accepts the same access tokens as the REST API.
4
+ Let AI agents manage this EmailEngine instance over the Model Context Protocol, and optionally work with the
5
+ connected mailboxes. The MCP endpoint exposes two tool sets behind two scopes: management (accounts, settings,
6
+ OAuth2 applications, gateways, tokens, the license, queues and logs) and mail (list and search messages, read
7
+ content, organize and delete messages, create drafts, send mail). It accepts the same access tokens as the REST
8
+ API.
7
9
  </p>
8
10
 
9
11
  <div class="mb-6 alert alert-soft alert-info">
@@ -46,8 +48,8 @@
46
48
  checked=values.mcpEnabled error=errors.mcpEnabled}}
47
49
  <span class="helper-text">Serves the Model Context Protocol at <code>/mcp</code>. The
48
50
  <button type="button" class="link cursor-pointer" data-goto-tab="mcp-connect">Connect an agent</button> tab
49
- generates access tokens and ready-to-paste setup for clients; a token with the <code>mcp</code> scope works
50
- only here and not against the REST API.</span>
51
+ generates access tokens and ready-to-paste setup for clients; a token with the <code>mcp-manage</code> or
52
+ <code>mcp</code> scope works only here and not against the REST API.</span>
51
53
  </div>
52
54
 
53
55
  {{!-- Nested rather than a peer: OAuth is a sub-option of an endpoint that is already on,
@@ -105,8 +107,9 @@
105
107
 
106
108
  {{#> ui/card bodyClass="space-y-4"}}
107
109
 
108
- <p class="text-sm">Generate an access token and ready-to-paste client configuration in one step. The token gets the
109
- <code>mcp</code> scope, so it works against the MCP endpoint and nothing else.</p>
110
+ <p class="text-sm">Generate an access token and ready-to-paste client configuration in one step. The token gets the MCP
111
+ scopes you choose below (<code>mcp-manage</code> for the instance, <code>mcp</code> for mail), so it works against
112
+ the MCP endpoint and nothing else.</p>
110
113
 
111
114
  {{#unless canProvision}}
112
115
  <div class="alert alert-soft alert-warning text-sm">
@@ -115,28 +118,33 @@
115
118
  </div>
116
119
  {{/unless}}
117
120
 
118
- <div id="mcpTokenGen" data-presets="{{json mcpAccessPresets}}" data-mcp-url="{{mcpUrl}}" class="space-y-4">
121
+ <div id="mcpTokenGen" data-mcp-url="{{mcpUrl}}" class="space-y-4">
119
122
  {{!-- One column on purpose: two-up put the account field a full screen away from its
120
123
  label-mate on wide displays, and the form reads as one top-to-bottom flow --}}
121
124
  {{> ui/form-field id="mcpGenLabel" label="What is this token for?" placeholder="for example Cursor or Claude"
122
125
  hint="Shows up as the token description, so you can tell agents apart on the Access Tokens page."}}
123
126
 
124
- {{> mcp_account_limit id="mcpGenAccount"}}
125
-
127
+ {{!-- The same two sections, in the same order and from the same table, as the OAuth consent
128
+ prompt: management first, mail declined unless picked. The radio group of a section is
129
+ named mcpGen_<key>, which is what ui.js reads the selection back from. --}}
130
+ {{#each mcpSections}}
126
131
  <fieldset class="space-y-2">
127
- <legend class="label-text mb-1">Access level</legend>
128
- {{> mcp_access_levels name="mcpGenAccess" idPrefix="mcpGenAccess" selected="read"}}
129
-
130
- {{!-- What the selected level actually leaves the client able to call, which the level
131
- names alone cannot say: the count follows both the level and the account limit
132
- above, exactly as tools/list will --}}
133
- {{> mcp_tool_count id="mcpGenToolCount" levelName="mcpGenAccess" accountId="mcpGenAccount" class="pt-1"}}
134
-
135
- {{!-- At the decision point rather than only in the collapsed manual-config block: the
136
- level chosen here is what decides whether injected instructions can act --}}
137
- <p class="text-base-content/60 text-sm">Email content flows into whatever model the connected client runs, and
138
- instructions inside received mail can steer it - grant sending and deleting rights deliberately.</p>
132
+ <legend class="label-text mb-1">{{label}}</legend>
133
+ {{> mcp_access_levels section=this name=(concat "mcpGen_" @key) idPrefix=(concat "mcpGen_" @key) selected=defaultLevel includeNone=true}}
139
134
  </fieldset>
135
+ {{/each}}
136
+
137
+ {{!-- At the decision point rather than only in the collapsed manual-config block: the
138
+ level chosen here is what decides whether injected instructions can act --}}
139
+ <p class="text-base-content/60 text-sm">Email content flows into whatever model the connected client runs, and
140
+ instructions inside received mail can steer it - grant sending and deleting rights deliberately.</p>
141
+
142
+ {{> mcp_account_limit id="mcpGenAccount"}}
143
+
144
+ {{!-- What the selected levels actually leave the client able to call, which the level names
145
+ alone cannot say: the count follows both sections and the account limit, exactly as
146
+ tools/list will --}}
147
+ {{> mcp_tool_count id="mcpGenToolCount" autoWire=true levelPrefix="mcpGen_" accountId="mcpGenAccount" class="pt-1"}}
140
148
 
141
149
  <div class="flex items-center gap-3">
142
150
  {{#if canProvision}}
@@ -166,8 +174,9 @@
166
174
  </div>
167
175
 
168
176
  <div class="text-sm text-base-content/60">
169
- Every connected agent is an ordinary access token with the <code>mcp</code> scope - review or revoke them on
170
- the <a href="/admin/tokens?scope=mcp" class="link">Access Tokens</a> page.
177
+ Every connected agent is an ordinary access token with the <code>mcp-manage</code> or <code>mcp</code> scope -
178
+ review or revoke them on the <a href="/admin/tokens?scope=mcp-manage&amp;scope=mcp" class="link">Access
179
+ Tokens</a> page.
171
180
  </div>
172
181
  </div>
173
182
 
@@ -256,10 +265,10 @@
256
265
  <ol class="text-base-content/80 ms-4 mt-1 list-decimal space-y-1 text-sm">
257
266
  <li>When you connect, the client opens this instance's authorization prompt in the browser. Sign in with the
258
267
  admin credentials if asked.</li>
259
- <li>On the prompt, pick the access level (read-only is the default) and optionally limit the connector to a
260
- single account, then approve.</li>
261
- <li>The connector receives its own access token with the <code>mcp</code> scope - review or revoke it at any
262
- time on the <a href="/admin/tokens?scope=mcp" class="link">Access Tokens</a> page.</li>
268
+ <li>On the prompt, pick what the connector may manage (observing the instance is the default), switch on mail
269
+ access if it should read mail, optionally limit it to a single account, then approve.</li>
270
+ <li>The connector receives its own access token with the MCP scopes you chose - review or revoke it at any
271
+ time on the <a href="/admin/tokens?scope=mcp-manage&amp;scope=mcp" class="link">Access Tokens</a> page.</li>
263
272
  </ol>
264
273
  </div>
265
274
 
@@ -272,29 +281,50 @@
272
281
  </div>
273
282
 
274
283
  {{!-- Outside the method panels: what a connected agent receives is the same either way --}}
275
- {{#> ui/details summary="Exposed tools" summarySmall=(concat toolCatalog.length " tools") class="card bg-base-100 shadow-md mb-6"}}
276
- <div>
277
- <p class="text-sm text-base-content/60 mb-4">This is exactly what a connected agent receives from
278
- <code>tools/list</code>. Whether a given token can call a tool also depends on its account binding and
279
- permission restrictions.</p>
280
- <div class="space-y-3">
281
- {{#each toolCatalog}}
282
- <div class="flex flex-wrap items-baseline gap-2">
283
- <code>{{name}}</code>
284
- {{> ui/badge label=badge.label variant=badge.variant soft=true}}
285
- <span class="text-sm text-base-content/60 basis-full sm:basis-auto sm:grow">{{description}}</span>
284
+ {{#> ui/details summary="Exposed tools" summarySmall=(concat toolCatalog.total " tools") class="card bg-base-100 shadow-md mb-6"}}
285
+ <div class="space-y-6">
286
+ <p class="text-sm text-base-content/60">This is exactly what a connected agent receives from
287
+ <code>tools/list</code>, grouped by the scope that reaches each tool. Whether a given token can call a tool
288
+ also depends on its access level and account binding.</p>
289
+ {{#each toolCatalog.sections}}
290
+ <div>
291
+ <h6 class="mb-2 font-bold">{{label}} <span class="text-base-content/60 font-normal">({{tools.length}} tools,
292
+ <code>{{scope}}</code>)</span></h6>
293
+ <div class="space-y-3">
294
+ {{#each tools}}
295
+ <div class="flex flex-wrap items-baseline gap-2">
296
+ <code>{{name}}</code>
297
+ {{> ui/badge label=badge.label variant=badge.variant soft=true}}
298
+ {{#if shared}}{{> ui/badge label="both scopes" variant="neutral" soft=true}}{{/if}}
299
+ <span class="text-sm text-base-content/60 basis-full sm:basis-auto sm:grow">{{description}}</span>
300
+ </div>
301
+ {{/each}}
302
+ </div>
303
+ </div>
304
+ {{/each}}
305
+ {{#if toolCatalog.unreached.length}}
306
+ <div>
307
+ <h6 class="mb-2 font-bold">Not offered by any MCP scope</h6>
308
+ <div class="space-y-3">
309
+ {{#each toolCatalog.unreached}}
310
+ <div class="flex flex-wrap items-baseline gap-2">
311
+ <code>{{name}}</code>
312
+ <span class="text-sm text-base-content/60 basis-full sm:basis-auto sm:grow">{{description}}</span>
313
+ </div>
314
+ {{/each}}
286
315
  </div>
287
- {{/each}}
288
316
  </div>
317
+ {{/if}}
289
318
  </div>
290
319
  {{/ui/details}}
291
320
 
292
321
  </div>
293
322
 
294
- <script nonce="{{cspNonce}}">
323
+ <script data-cfasync="false" nonce="{{cspNonce}}">
295
324
  (() => {
296
325
  let container = document.getElementById('mcpTokenGen');
297
- let presets = JSON.parse(container.dataset.presets || '{}');
326
+ // The section table is embedded once, on the tool count element ui.js wires
327
+ let sections = JSON.parse(document.getElementById('mcpGenToolCount').dataset.mcpSections || '{}');
298
328
  let mcpUrl = container.dataset.mcpUrl;
299
329
 
300
330
  // The one place each artifact is written; the manual block shows them with a
@@ -323,25 +353,31 @@
323
353
 
324
354
  let label = (document.getElementById('mcpGenLabel').value || '').trim() || 'MCP agent';
325
355
  let account = (document.getElementById('mcpGenAccount').value || '').trim();
326
- let accessElm = document.querySelector('input[name="mcpGenAccess"]:checked');
327
- let access = (accessElm && accessElm.value) || 'read';
356
+ let choice = uiMcpLevelChoice(sections, 'mcpGen_');
328
357
 
329
358
  try {
330
- if (!Object.prototype.hasOwnProperty.call(presets, access)) {
331
- // A missing preset must not silently mint a wider credential than the
332
- // selected level promises
333
- throw new Error('The access preset failed to load. Reload the page and try again.');
359
+ if (!sections.manage || !sections.mail) {
360
+ // A missing table must not silently mint a wider credential than the
361
+ // selected levels promise
362
+ throw new Error('The access levels failed to load. Reload the page and try again.');
363
+ }
364
+
365
+ // The same union the consent prompt mints, computed by the shared helper: the
366
+ // scopes of the sections that were not declined and the grant pairs of their
367
+ // levels. A token always carries its grants explicitly, so what the operator saw
368
+ // is exactly what the credential holds.
369
+ let record = uiMcpLevelRecord(sections, choice);
370
+ if (!record.surfaces.length) {
371
+ throw new Error('Choose at least one kind of access.');
334
372
  }
335
373
 
336
374
  let data = await uiPostJson('/admin/tokens/new', {
337
375
  description: 'MCP: ' + label,
338
- scopes: ['mcp'],
376
+ scopes: record.surfaces,
339
377
  // The empty string, not null: accountIdSchema is `Joi.string().empty('')`,
340
378
  // which converts '' to the schema default and refuses an explicit null
341
379
  account: account,
342
- // The access-level table maps 'full' to null: the absence of a permissions
343
- // record, because the mcp scope already bounds the token to the MCP surface
344
- permissions: presets[access]
380
+ permissions: { grants: record.grants }
345
381
  });
346
382
 
347
383
  if (!data.success) {
@@ -184,7 +184,7 @@ Remove this IP from the list? It will be re-added if found during the next scan.
184
184
  {{/ui/confirm-modal}}
185
185
 
186
186
 
187
- <script nonce="{{cspNonce}}">
187
+ <script data-cfasync="false" nonce="{{cspNonce}}">
188
188
  document.addEventListener('DOMContentLoaded', () => {
189
189
  let reloadBtn = document.getElementById('reload-btn');
190
190
 
@@ -355,7 +355,7 @@ fieldName="app" fieldValue=app.id submitLabel="Delete app" submitIcon="icon-[tab
355
355
  </form>
356
356
  {{/ui/modal}}
357
357
 
358
- <script nonce="{{cspNonce}}">
358
+ <script data-cfasync="false" nonce="{{cspNonce}}">
359
359
  document.addEventListener('DOMContentLoaded', () => {
360
360
  document.getElementById('addServiceAccountModal').addEventListener('open.overlay', () => {
361
361
  document.getElementById('service-account-name').focus();
@@ -364,7 +364,7 @@ fieldName="app" fieldValue=app.id submitLabel="Delete app" submitIcon="icon-[tab
364
364
  </script>
365
365
  {{/if}}
366
366
 
367
- <script nonce="{{cspNonce}}">
367
+ <script data-cfasync="false" nonce="{{cspNonce}}">
368
368
  document.addEventListener('DOMContentLoaded', () => {
369
369
  const appId = "{{app.id}}";
370
370
  const stepsElm = document.getElementById('verify-steps');