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
@@ -764,3 +764,14 @@
764
764
  background-color: var(--color-base-200);
765
765
  }
766
766
  }
767
+
768
+ /* A table whose cells hold sentences. FlyonUI's .table sets every cell nowrap from the
769
+ * utilities layer, which is right for ids and badges and wrong for a status line under a
770
+ * hostname. A utility of our own is the only thing that can outrank it: same layer, and
771
+ * :is() carries the element's specificity where the library's :where() carries none. A cell
772
+ * that must stay on one line puts whitespace-nowrap on a wrapper inside the cell. */
773
+ @utility ee-table-wrap {
774
+ & :is(th, td) {
775
+ white-space: normal;
776
+ }
777
+ }
package/static/js/app.js CHANGED
@@ -379,6 +379,14 @@ document.addEventListener('DOMContentLoaded', () => {
379
379
  updateServerStateIndicators('imapProxy', data);
380
380
  break;
381
381
  }
382
+
383
+ // Page-scoped listeners (the TLS page follows certificate provisioning this way) get
384
+ // every event, including the ones this switch does not paint a badge for. One stream
385
+ // per page: a second EventSource would be a second authenticated connection for the
386
+ // same feed.
387
+ if (data) {
388
+ document.dispatchEvent(new CustomEvent('ee:change', { detail: data }));
389
+ }
382
390
  };
383
391
 
384
392
  evtSource.onerror = function (e) {
@@ -412,3 +420,29 @@ document.addEventListener('DOMContentLoaded', () => {
412
420
  }
413
421
 
414
422
  });
423
+
424
+ // "Choose file" buttons: a .file-picker-btn with data-file-target="#selector" reads the picked
425
+ // file as text into that control (a PEM certificate into its textarea). Delegated, so a page
426
+ // needs no script of its own for it; the .droptxt class on the same control adds drag and drop.
427
+ document.addEventListener('click', e => {
428
+ let btn = e.target.closest('.file-picker-btn');
429
+ if (!btn) {
430
+ return;
431
+ }
432
+ e.preventDefault();
433
+
434
+ let target = btn.dataset.fileTarget ? document.querySelector(btn.dataset.fileTarget) : null;
435
+ if (!target) {
436
+ return;
437
+ }
438
+
439
+ window
440
+ .browseFileContents('text')
441
+ .then(contents => {
442
+ if (contents) {
443
+ target.value = contents.toString().trim();
444
+ target.focus();
445
+ }
446
+ })
447
+ .catch(err => window.showToast('Could not read the file\n' + err.message, 'alert-triangle'));
448
+ });
@@ -153,11 +153,15 @@ window.eeButtonBusy = (btn, busy) => {
153
153
  // the event by the time this sees it.
154
154
  document.addEventListener('submit', e => {
155
155
  let form = e.target;
156
- if (e.defaultPrevented || !form || form.method !== 'post') {
156
+ // Attributes rather than properties: a control named `method` or `target` shadows the
157
+ // same-named property on HTMLFormElement
158
+ if (e.defaultPrevented || !form || (form.getAttribute('method') || 'get').toLowerCase() !== 'post') {
157
159
  return;
158
160
  }
159
161
 
160
- let target = form.target.trim().toLowerCase();
162
+ // The attribute, not the property: a form control named `target` shadows
163
+ // HTMLFormElement.target, and reading the property would throw on such a form
164
+ let target = (form.getAttribute('target') || '').trim().toLowerCase();
161
165
  if (target && target !== '_self') {
162
166
  return;
163
167
  }
package/static/js/ui.js CHANGED
@@ -293,29 +293,6 @@ window.uiEditorFullscreen = editors => {
293
293
  }
294
294
  };
295
295
 
296
- // Repaint the #tls-label certificate badge (config/smtp and config/imap-proxy
297
- // pages) from a certificate-check response: badge color, label text and the
298
- // FlyonUI tooltip body that carries the status details
299
- window.paintCertData = certData => {
300
- let tlsLabelElm = document.getElementById('tls-label');
301
-
302
- if (!certData || !certData.label || !tlsLabelElm) {
303
- return;
304
- }
305
-
306
- tlsLabelElm.classList.remove(`badge-${tlsLabelElm.dataset.labeltype}`);
307
- tlsLabelElm.classList.add(`badge-${certData.label.type}`);
308
- tlsLabelElm.dataset.labeltype = certData.label.type;
309
-
310
- tlsLabelElm.textContent = certData.label.text;
311
-
312
- let tooltipBodyElm = tlsLabelElm.closest('.tooltip');
313
- tooltipBodyElm = tooltipBodyElm && tooltipBodyElm.querySelector('.tooltip-body');
314
- if (tooltipBodyElm) {
315
- tooltipBodyElm.textContent = certData.label.title;
316
- }
317
- };
318
-
319
296
  // Keyboard hints that spell a modifier differently on macOS (ui/search-input
320
297
  // renders `shortcut` with an optional `shortcutMac`). The server cannot know
321
298
  // the platform, so it emits the Ctrl form and the Mac spelling rides along in
@@ -620,13 +597,19 @@ const uiFormBusy = new Map();
620
597
  // this guard by not being POST forms.)
621
598
  document.addEventListener('submit', event => {
622
599
  const form = event.target;
623
- if (event.defaultPrevented || !form || form.method !== 'post') {
600
+ // Attributes rather than properties throughout: a form control named `method` or `target`
601
+ // shadows the same-named property on HTMLFormElement, and this handler runs on every form.
602
+ if (event.defaultPrevented || !form || (form.getAttribute('method') || 'get').toLowerCase() !== 'post') {
624
603
  return;
625
604
  }
626
605
 
627
606
  // A form aimed at another browsing context leaves this page in place, so
628
607
  // there is no navigation to end the busy state and nothing to latch.
629
- const target = form.target.trim().toLowerCase();
608
+ //
609
+ // Read the attribute, not the property: a form control named `target` shadows
610
+ // HTMLFormElement.target, so form.target can be an <input> element. That threw here and took
611
+ // every busy button on the page down with it.
612
+ const target = (form.getAttribute('target') || '').trim().toLowerCase();
630
613
  if (target && target !== '_self') {
631
614
  return;
632
615
  }
@@ -857,22 +840,43 @@ window.uiCodeExamples = config => {
857
840
 
858
841
  // The MCP tool count: how many of the endpoint's tools a credential would actually be offered.
859
842
  //
860
- // Shared by the three places an mcp-scoped token is minted - the access-token form, the MCP config
861
- // page's generator and the OAuth consent prompt - because all three ask the same question, and the
862
- // count is the one thing a permission record does not tell a reader: the MCP surface reaches six of
863
- // the thirteen sections, so a record that looks generous can still leave an agent holding one tool.
843
+ // Shared by the three places an MCP token is minted - the access-token form, the MCP config page's
844
+ // generator and the OAuth consent prompt - because all three ask the same question, and the count
845
+ // is the one thing a permission record does not tell a reader: a record that looks generous can
846
+ // still leave an agent holding one tool.
864
847
  //
865
- // Two filters, the same two lib/mcp/tools.js toolVisibleTo() applies to tools/list: the permission
866
- // record, and the account binding - a credential bound to one account is never offered the tools
867
- // that take no account argument, because there is nothing to bind them to. This is the browser's
868
- // copy of that rule, and test/mcp-tools-test.js asserts the two agree over the whole catalog.
848
+ // Three filters, the same three lib/mcp/tools.js toolVisibleTo() applies to tools/list: the scopes
849
+ // (a tool is offered only through a surface scope whose table covers it), the permission record,
850
+ // and the account binding - a credential bound to one account is never offered the tools that take
851
+ // no account argument, because there is nothing to bind them to. This is the browser's copy of
852
+ // that rule, and test/mcp-tools-test.js asserts the two agree over the whole catalog.
869
853
  //
870
- // `record` is { actions, groups, unrestricted, account }. `unrestricted` is the absence of a
871
- // permissions record, which is a different answer from an empty one: the scopes are the only bound.
872
- // A null record clears the element - the question does not apply to this credential at all, which
873
- // is not the same as it having no tools.
854
+ // `record` is { surfaces, grants | actions + groups, unrestricted, account }. `surfaces` lists the
855
+ // MCP scopes the token holds (absent: no scope bound). `grants` is a list of {action, group} pairs,
856
+ // the pair-list form; `actions` and `groups` are the two-axis form. `unrestricted` is the absence
857
+ // of a permissions record, which is a different answer from an empty one: the scopes are the only
858
+ // bound. A null record clears the element - the question does not apply to this credential at
859
+ // all, which is not the same as it having no tools.
860
+
861
+ // Whether a record allows one (action, group) pair, in whichever form it is written. The one
862
+ // reading of the record shape in the browser: the count and the token form's scope warning both
863
+ // ask this.
864
+ window.uiMcpRecordAllows = (record, action, group) => {
865
+ if (record.unrestricted) {
866
+ return true;
867
+ }
868
+ if (record.grants) {
869
+ return record.grants.some(grant => grant.action === action && grant.group === group);
870
+ }
871
+ return record.actions.includes(action) && record.groups.includes(group);
872
+ };
873
+
874
874
  window.uiMcpToolCount = (elm, record) => {
875
- let tools = JSON.parse(elm.dataset.mcpTools || '[]');
875
+ // Parsed once per element: the account field repaints this per keystroke
876
+ if (!elm.mcpTools) {
877
+ elm.mcpTools = JSON.parse(elm.dataset.mcpTools || '[]');
878
+ }
879
+ let tools = elm.mcpTools;
876
880
 
877
881
  elm.replaceChildren();
878
882
  if (!tools.length || !record) {
@@ -880,8 +884,9 @@ window.uiMcpToolCount = (elm, record) => {
880
884
  }
881
885
 
882
886
  let bound = !!(record.account || '').trim();
883
- let offered = bound ? tools.filter(tool => tool.accountScoped) : tools;
884
- let available = record.unrestricted ? offered : offered.filter(tool => record.actions.includes(tool.action) && record.groups.includes(tool.group));
887
+ let reachable = record.surfaces ? tools.filter(tool => (tool.surfaces || []).some(scope => record.surfaces.includes(scope))) : tools;
888
+ let offered = bound ? reachable.filter(tool => tool.accountScoped) : reachable;
889
+ let available = offered.filter(tool => window.uiMcpRecordAllows(record, tool.action, tool.group));
885
890
 
886
891
  let count = document.createElement('div');
887
892
  let countLabel = document.createElement('strong');
@@ -896,7 +901,7 @@ window.uiMcpToolCount = (elm, record) => {
896
901
 
897
902
  // Said out loud rather than left as a smaller total: the tools a binding takes away are the
898
903
  // ones an agent would otherwise use to discover what it is connected to.
899
- let instanceWide = tools.filter(tool => !tool.accountScoped);
904
+ let instanceWide = reachable.filter(tool => !tool.accountScoped);
900
905
  if (bound && instanceWide.length) {
901
906
  let note = document.createElement('div');
902
907
  note.className = 'text-base-content/60';
@@ -905,32 +910,63 @@ window.uiMcpToolCount = (elm, record) => {
905
910
  }
906
911
  };
907
912
 
908
- // Auto-wiring for the pages whose whole answer is a named access level (the MCP config generator
909
- // and the consent prompt). The access-token form drives its own count instead, because its fourth
910
- // option is a hand-built record rather than a level, and it carries no data-mcp-level-name.
913
+ // The level a page has selected per section, read off the radio groups. Every page renders one
914
+ // radio group per section, named `<prefix><section key>` by the mcp_access_levels partial; a
915
+ // section with no radio checked (the token form leaves a section out entirely while its scope is
916
+ // unticked) is declined.
917
+ window.uiMcpLevelChoice = (sections, prefix) => {
918
+ let choice = {};
919
+ for (let key of Object.keys(sections)) {
920
+ let radio = document.querySelector('input[name="' + (prefix || '') + key + '"]:checked');
921
+ choice[key] = radio ? radio.value : 'none';
922
+ }
923
+ return choice;
924
+ };
925
+
926
+ // The record a choice of section levels mints, as the count reads it and as the mint posts it:
927
+ // the scopes of the sections that were not declined and the union of their pairs. The browser's
928
+ // copy of mcpGrantsFor() in lib/token-permission-view.js, over the same table.
929
+ window.uiMcpLevelRecord = (sections, choice) => {
930
+ let surfaces = [];
931
+ let grants = [];
932
+ for (let key of Object.keys(sections)) {
933
+ let level = sections[key].levels.find(entry => entry.value === choice[key]);
934
+ if (!level) {
935
+ // Declined, or a level the table does not know - which counts as nothing rather than
936
+ // as everything, the same direction every other reader of this table fails in
937
+ continue;
938
+ }
939
+ surfaces.push(sections[key].scope);
940
+ for (let pair of level.pairs) {
941
+ if (!grants.some(grant => grant.action === pair.action && grant.group === pair.group)) {
942
+ grants.push({ action: pair.action, group: pair.group });
943
+ }
944
+ }
945
+ }
946
+ return { surfaces, grants, unrestricted: false };
947
+ };
948
+
949
+ // Auto-wiring for the pages whose whole answer is a level per section (the MCP config generator
950
+ // and the consent prompt): the count element carries the section table and the radio name prefix,
951
+ // and repaints whenever a level or the account binding changes. The access-token form drives its
952
+ // own count instead, because its custom option is a hand-built record rather than a level.
911
953
  document.addEventListener('DOMContentLoaded', () => {
912
- for (let elm of document.querySelectorAll('[data-mcp-level-name]')) {
913
- let presets = JSON.parse(elm.dataset.mcpPresets || '{}');
954
+ for (let elm of document.querySelectorAll('[data-mcp-auto-wire]')) {
955
+ let sections = JSON.parse(elm.dataset.mcpSections || '{}');
956
+ let prefix = elm.dataset.mcpLevelPrefix || '';
914
957
  let accountElm = elm.dataset.mcpAccountId ? document.getElementById(elm.dataset.mcpAccountId) : null;
915
- let radios = Array.from(document.querySelectorAll('input[name="' + elm.dataset.mcpLevelName + '"]'));
916
958
 
917
959
  let paint = () => {
918
- let selected = radios.find(radio => radio.checked);
919
- let level = (selected && selected.value) || 'read';
920
- let preset = presets[level];
921
-
922
- window.uiMcpToolCount(elm, {
923
- actions: preset ? preset.actions : [],
924
- groups: preset ? preset.groups : [],
925
- // A level the table stores as null is the unrestricted one. A level missing from
926
- // the table entirely is not, and counts as nothing rather than as everything -
927
- // the same direction every other reader of this table fails in.
928
- unrestricted: !preset && Object.prototype.hasOwnProperty.call(presets, level),
929
- account: accountElm ? accountElm.value : ''
930
- });
960
+ let record = window.uiMcpLevelRecord(sections, window.uiMcpLevelChoice(sections, prefix));
961
+ record.account = accountElm ? accountElm.value : '';
962
+ window.uiMcpToolCount(elm, record);
931
963
  };
932
964
 
933
- radios.forEach(radio => radio.addEventListener('change', paint));
965
+ for (let key of Object.keys(sections)) {
966
+ for (let radio of document.querySelectorAll('input[name="' + prefix + key + '"]')) {
967
+ radio.addEventListener('change', paint);
968
+ }
969
+ }
934
970
  if (accountElm) {
935
971
  // Per keystroke, so what the binding costs is visible while the field is being filled
936
972
  // in rather than only after it loses focus