emailengine-app 2.80.0 → 2.81.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 (178) hide show
  1. package/.dockerignore +44 -0
  2. package/.github/docker-smoke-test.sh +16 -0
  3. package/.github/workflows/deploy.yml +4 -0
  4. package/.github/workflows/release.yaml +4 -0
  5. package/.github/workflows/test.yml +2 -0
  6. package/.release-please-manifest.json +1 -1
  7. package/CHANGELOG.md +56 -0
  8. package/Dockerfile +17 -9
  9. package/README.md +6 -0
  10. package/data/google-crawlers.json +1 -1
  11. package/docker-compose.yml +7 -1
  12. package/lib/api-routes/account-routes.js +239 -73
  13. package/lib/api-routes/blocklist-routes.js +24 -0
  14. package/lib/api-routes/delivery-test-routes.js +6 -0
  15. package/lib/api-routes/gateway-routes.js +30 -0
  16. package/lib/api-routes/license-routes.js +10 -0
  17. package/lib/api-routes/mcp-oauth-routes.js +3 -3
  18. package/lib/api-routes/mcp-routes.js +39 -21
  19. package/lib/api-routes/oauth2-app-routes.js +38 -1
  20. package/lib/api-routes/outbox-routes.js +6 -0
  21. package/lib/api-routes/permission-map.js +212 -42
  22. package/lib/api-routes/pubsub-routes.js +8 -0
  23. package/lib/api-routes/route-helpers.js +58 -11
  24. package/lib/api-routes/settings-routes.js +50 -4
  25. package/lib/api-routes/stats-routes.js +6 -0
  26. package/lib/api-routes/template-routes.js +21 -0
  27. package/lib/api-routes/token-routes.js +34 -2
  28. package/lib/api-routes/webhook-route-routes.js +13 -0
  29. package/lib/autodetect-imap-settings.js +4 -4
  30. package/lib/email-client/base-client.js +6 -3
  31. package/lib/email-client/credential-errors.js +4 -0
  32. package/lib/email-client/imap/login-failure.js +52 -0
  33. package/lib/email-client/imap/subconnection.js +2 -1
  34. package/lib/email-client/imap-client.js +3 -6
  35. package/lib/enum-descriptions.js +12 -2
  36. package/lib/imapproxy/imap-server.js +1 -1
  37. package/lib/mcp/oauth.js +46 -8
  38. package/lib/mcp/protocol.js +78 -35
  39. package/lib/mcp/tools.js +53 -17
  40. package/lib/privileged-settings.js +147 -0
  41. package/lib/schemas.js +60 -16
  42. package/lib/sentry.js +13 -2
  43. package/lib/settings.js +13 -0
  44. package/lib/tls/catalog.js +428 -0
  45. package/lib/tls/context.js +87 -161
  46. package/lib/tls/listeners.js +62 -0
  47. package/lib/tls/provision.js +1 -1
  48. package/lib/tls/status.js +128 -79
  49. package/lib/tls/store.js +3 -2
  50. package/lib/token-permission-view.js +253 -102
  51. package/lib/token-permissions.js +176 -26
  52. package/lib/tokens.js +7 -6
  53. package/lib/tools.js +5 -3
  54. package/lib/ui-routes/account-routes.js +195 -61
  55. package/lib/ui-routes/admin-config-routes.js +41 -21
  56. package/lib/ui-routes/admin-entities-routes.js +32 -22
  57. package/lib/ui-routes/mcp-consent-routes.js +72 -31
  58. package/lib/ui-routes/tls-config-routes.js +121 -74
  59. package/package.json +16 -16
  60. package/sbom.json +1 -1
  61. package/server.js +7 -1
  62. package/static/css/flyonui.css +1 -1
  63. package/static/css/public.css +41 -0
  64. package/static/css/src/app.tailwind.css +135 -4
  65. package/static/js/public.js +218 -0
  66. package/static/js/ui.js +89 -36
  67. package/static/licenses.html +55 -37
  68. package/translations/README.md +4 -3
  69. package/translations/de.mo +0 -0
  70. package/translations/de.po +296 -185
  71. package/translations/en.po +220 -128
  72. package/translations/es.mo +0 -0
  73. package/translations/es.po +558 -0
  74. package/translations/et.mo +0 -0
  75. package/translations/et.po +288 -181
  76. package/translations/fr.mo +0 -0
  77. package/translations/fr.po +295 -183
  78. package/translations/it.mo +0 -0
  79. package/translations/it.po +558 -0
  80. package/translations/ja.mo +0 -0
  81. package/translations/ja.po +268 -192
  82. package/translations/locales.json +24 -0
  83. package/translations/messages.pot +179 -127
  84. package/translations/nl.mo +0 -0
  85. package/translations/nl.po +288 -175
  86. package/translations/pl.mo +0 -0
  87. package/translations/pl.po +294 -181
  88. package/translations/sv.mo +0 -0
  89. package/translations/sv.po +555 -0
  90. package/translations/tr.mo +0 -0
  91. package/translations/tr.po +555 -0
  92. package/update-info.sh +12 -6
  93. package/views/account/login-redirect.hbs +6 -5
  94. package/views/account/passkeys.hbs +8 -8
  95. package/views/account/security.hbs +2 -2
  96. package/views/accounts/account.hbs +19 -21
  97. package/views/accounts/browse.hbs +1 -1
  98. package/views/accounts/edit.hbs +15 -15
  99. package/views/accounts/index.hbs +3 -3
  100. package/views/accounts/register/imap-server.hbs +27 -173
  101. package/views/accounts/register/validating.hbs +139 -0
  102. package/views/config/ai.hbs +15 -17
  103. package/views/config/branding.hbs +7 -7
  104. package/views/config/document-store/chat.hbs +9 -8
  105. package/views/config/document-store/index.hbs +14 -15
  106. package/views/config/document-store/mappings/index.hbs +5 -6
  107. package/views/config/document-store/mappings/new.hbs +1 -2
  108. package/views/config/document-store/pre-processing/index.hbs +4 -4
  109. package/views/config/email-processing.hbs +6 -6
  110. package/views/config/imap-proxy.hbs +7 -8
  111. package/views/config/license.hbs +9 -9
  112. package/views/config/logging.hbs +5 -7
  113. package/views/config/mcp.hbs +90 -58
  114. package/views/config/network.hbs +4 -4
  115. package/views/config/oauth/app.hbs +12 -12
  116. package/views/config/oauth/index.hbs +6 -6
  117. package/views/config/oauth/subscriptions.hbs +9 -9
  118. package/views/config/security.hbs +5 -7
  119. package/views/config/service.hbs +11 -10
  120. package/views/config/smtp.hbs +9 -12
  121. package/views/config/tls-upload.hbs +3 -3
  122. package/views/config/tls.hbs +281 -182
  123. package/views/config/webhooks.hbs +12 -15
  124. package/views/dashboard.hbs +9 -8
  125. package/views/gateways/edit.hbs +3 -3
  126. package/views/gateways/gateway.hbs +3 -3
  127. package/views/gateways/index.hbs +6 -6
  128. package/views/gateways/new.hbs +3 -3
  129. package/views/internals/index.hbs +15 -13
  130. package/views/layout/app.hbs +6 -6
  131. package/views/layout/login.hbs +32 -19
  132. package/views/layout/main.hbs +2 -2
  133. package/views/layout/prompt.hbs +15 -18
  134. package/views/layout/public.hbs +1 -1
  135. package/views/mcp/authorize.hbs +47 -45
  136. package/views/partials/accounts_table.hbs +5 -5
  137. package/views/partials/ace_assets.hbs +1 -1
  138. package/views/partials/add_account_modal.hbs +4 -4
  139. package/views/partials/address_list.hbs +4 -4
  140. package/views/partials/filter_editor_js.hbs +2 -2
  141. package/views/partials/gateway_form.hbs +5 -5
  142. package/views/partials/gateway_js.hbs +1 -1
  143. package/views/partials/mcp_access_levels.hbs +16 -9
  144. package/views/partials/mcp_account_limit.hbs +2 -2
  145. package/views/partials/mcp_tool_count.hbs +15 -14
  146. package/views/partials/oauth_config_header.hbs +2 -2
  147. package/views/partials/oauth_form.hbs +37 -42
  148. package/views/partials/public_alerts.hbs +1 -1
  149. package/views/partials/public_test_labels.hbs +15 -0
  150. package/views/partials/public_theme_init.hbs +1 -1
  151. package/views/partials/security_header.hbs +2 -2
  152. package/views/partials/template_form.hbs +4 -4
  153. package/views/partials/theme_init.hbs +1 -1
  154. package/views/partials/tls_security_card.hbs +4 -1
  155. package/views/partials/ui/form-field.hbs +6 -1
  156. package/views/partials/ui/setting-ref.hbs +12 -7
  157. package/views/partials/ui/stat-card.hbs +4 -1
  158. package/views/partials/ui/tabs.hbs +3 -7
  159. package/views/partials/webhook_form.hbs +9 -12
  160. package/views/partials/webhooks_editor_functions.hbs +1 -1
  161. package/views/reference/index.hbs +3 -3
  162. package/views/reference/redirect.hbs +1 -1
  163. package/views/reference/tag.hbs +1 -1
  164. package/views/reference/token.hbs +4 -4
  165. package/views/suppression-lists/index.hbs +8 -6
  166. package/views/suppression-lists/list.hbs +13 -8
  167. package/views/templates/edit.hbs +1 -1
  168. package/views/templates/index.hbs +10 -11
  169. package/views/templates/template.hbs +5 -5
  170. package/views/tokens/index.hbs +17 -17
  171. package/views/tokens/new.hbs +190 -93
  172. package/views/unsubscribe.hbs +1 -1
  173. package/views/webhooks/edit.hbs +1 -1
  174. package/views/webhooks/index.hbs +10 -11
  175. package/views/webhooks/new.hbs +1 -1
  176. package/views/webhooks/webhook.hbs +5 -6
  177. package/workers/api.js +9 -8
  178. package/workers/smtp.js +1 -1
@@ -11,7 +11,7 @@ const { autodetectImapSettings } = require('../autodetect-imap-settings');
11
11
  const Boom = require('@hapi/boom');
12
12
  const Joi = require('joi');
13
13
  const { failAction, getSignedFormData, getLogs, verifyAccountInfo } = require('../tools');
14
- const { handleError, maskSecrets, MASKED, MASK_NOTE } = require('./route-helpers');
14
+ const { handleError, maskSecrets, assertNoNetworkOverride, MASKED, MASK_NOTE } = require('./route-helpers');
15
15
 
16
16
  const {
17
17
  settingsSchema,
@@ -67,6 +67,82 @@ const verifyResultSchema = (proto, responseTextExample) =>
67
67
  .label(`Verify${proto}ResponseText`)
68
68
  }).label(`Verify${proto}Result`);
69
69
 
70
+ // The answer autodiscovery gives, shared by GET and POST /v1/autoconfig. One definition rather than
71
+ // two identical inline copies: the OpenAPI converter collapses structurally identical labelled
72
+ // schemas into a single component, so the two routes publish one `DiscoveredEmailSettings` type.
73
+ // One discovered server block. The IMAP and SMTP halves carry the same fields and differ only in
74
+ // their examples and their (historically inconsistent) label, so they are built rather than written
75
+ // out twice - the same reason verifyResultSchema above is a factory.
76
+ const discoveredServerSchema = (proto, label, hostExample, portExample) =>
77
+ Joi.object({
78
+ auth: Joi.object({
79
+ user: Joi.string().max(256).example('myuser@gmail.com').description('Account username')
80
+ }).label('DetectedAuthenticationInfo'),
81
+
82
+ host: Joi.string().hostname().example(hostExample).description('Hostname to connect to'),
83
+ port: Joi.number()
84
+ .integer()
85
+ .min(1)
86
+ .max(64 * 1024)
87
+ .example(portExample)
88
+ .description('Service port number'),
89
+ secure: Joi.boolean().default(false).example(true).description(`Should connection use TLS. Usually true for port ${portExample}`)
90
+ })
91
+ .allow(false)
92
+ .description(`Discovered ${proto} settings. False if ${proto} settings were not found`)
93
+ .label(label);
94
+
95
+ const discoveredEmailSettingsSchema = Joi.object({
96
+ imap: discoveredServerSchema('IMAP', 'ResolvedServerSettings', 'imap.gmail.com', 993),
97
+ smtp: discoveredServerSchema('SMTP', 'DiscoveredServerSettings', 'smtp.gmail.com', 465),
98
+ appPassword: Joi.object({
99
+ required: Joi.boolean().example(true).description('Whether the provider requires an app password'),
100
+ provider: Joi.string().example('Gmail').description('Provider name'),
101
+ instructions: Joi.string()
102
+ .example('Use an app password instead of the regular account password')
103
+ .description('Instructions for setting up an app password')
104
+ })
105
+ .unknown()
106
+ .description('App password requirements for the provider, if known')
107
+ .label('DiscoveredAppPasswordInfo'),
108
+ _source: Joi.string().example('srv').description('Source for the detected info')
109
+ }).label('DiscoveredEmailSettings');
110
+
111
+ // Address to discover settings for. Same field on the GET query and the POST payload.
112
+ const autodiscoverEmailSchema = Joi.string()
113
+ .email()
114
+ .required()
115
+ .example('sender@example.com')
116
+ .description('Email address to discover email settings for')
117
+ .label('EmailAddress');
118
+
119
+ // Shared by both autoconfig routes, which answer the same question and publish the same contract -
120
+ // including the empty result, which is the normal answer for an address whose domain describes no
121
+ // mail server anywhere. Credentials are optional and only ever reach an autodiscovery endpoint that
122
+ // refuses to answer anonymously (lib/autodetect-imap-settings.js).
123
+ const runAutoconfig = async (request, email, credentials) => {
124
+ try {
125
+ return await autodetectImapSettings(email, request.app.gt, credentials);
126
+ } catch (err) {
127
+ // autodiscovery fails routinely for unknown domains and the handler answers with a
128
+ // regular "not found" response, so this is not an operator-visible failure
129
+ request.logger.debug({ msg: 'API request failed', err });
130
+ if (Boom.isBoom(err)) {
131
+ throw err;
132
+ }
133
+ return { imap: false, smtp: false, _source: 'unknown' };
134
+ }
135
+ };
136
+
137
+ const AUTOCONFIG_RESPONSES = apiResponses(
138
+ 'Returns the discovered IMAP and SMTP settings for the address, or empty values when nothing could be resolved.',
139
+ 400,
140
+ 401,
141
+ 403,
142
+ 429,
143
+ 500
144
+ );
145
+
70
146
  /**
71
147
  * Validates that delegation fields are only used with OAuth2 accounts.
72
148
  */
@@ -106,6 +182,10 @@ async function init(args) {
106
182
  });
107
183
 
108
184
  try {
185
+ // A narrowed provisioning token may add an account, but not route its connection
186
+ // through a host of its own choosing - the same rule the submit routes apply
187
+ assertNoNetworkOverride(request);
188
+
109
189
  if (request.payload.oauth2 && request.payload.oauth2.authorize) {
110
190
  // redirect to OAuth2 consent screen
111
191
 
@@ -186,6 +266,13 @@ async function init(args) {
186
266
  tags: ['api', 'Account'],
187
267
 
188
268
  plugins: {
269
+ mcp: {
270
+ name: 'create_account',
271
+ title: 'Create account',
272
+ description:
273
+ 'Register an email account. For an OAuth2 provider set oauth2.provider to the application id (from list_oauth2_apps) and oauth2.authorize to true: the response carries a redirect URL for the user to open and sign in, and no credentials are needed. For IMAP set imap and smtp with the host, port and auth the user supplied (autodiscover_settings finds the servers). Prefer create_account_setup_link when the user can open a link themselves, so no password passes through this conversation.',
274
+ omit: ['proxy', 'smtpEhloName', 'webhooksCustomHeaders', 'copy', 'locale', 'tz']
275
+ },
189
276
  openapi: {
190
277
  'x-ee-behavior': [BEHAVIOR.CREDENTIALS_VERIFIED_LATER],
191
278
  responses: apiResponses(
@@ -341,6 +428,10 @@ async function init(args) {
341
428
  });
342
429
 
343
430
  try {
431
+ // The stored credential survives a partial update, so where the connection goes is
432
+ // the one thing a narrowed token must not decide (see the provisioning group)
433
+ assertNoNetworkOverride(request);
434
+
344
435
  // Validate delegation fields are only used with OAuth2 provider
345
436
  validateDelegationFields(request.payload);
346
437
 
@@ -358,6 +449,13 @@ async function init(args) {
358
449
  tags: ['api', 'Account'],
359
450
 
360
451
  plugins: {
452
+ mcp: {
453
+ name: 'update_account',
454
+ title: 'Update account',
455
+ description:
456
+ "Change an account's configuration: name, email, sync and notification settings, special folders, the webhook target, and the IMAP, SMTP or OAuth2 connection settings. Send only the fields to change. Changing a host makes the next connection authenticate to the new host with the stored credential, so confirm connection changes with the user.",
457
+ omit: ['proxy', 'smtpEhloName', 'webhooksCustomHeaders', 'copy', 'locale', 'tz']
458
+ },
361
459
  openapi: {
362
460
  'x-ee-behavior': [BEHAVIOR.CREDENTIALS_VERIFIED_LATER],
363
461
  responses: apiResponses('Returns the account ID. Changed credentials take effect on the next connection.', 400, 401, 403, 404, 429, 500)
@@ -482,6 +580,14 @@ async function init(args) {
482
580
  tags: ['api', 'Account'],
483
581
 
484
582
  plugins: {
583
+ mcp: {
584
+ name: 'reconnect_account',
585
+ title: 'Reconnect account',
586
+ description:
587
+ "Ask the account's worker to close and re-open its connection. Use after fixing credentials or server settings, or when an account is stuck connecting.",
588
+ omit: ['reconnect'],
589
+ force: { reconnect: true }
590
+ },
485
591
  openapi: {
486
592
  'x-ee-behavior': [BEHAVIOR.SCHEDULED_ON_WORKER],
487
593
  responses: apiResponses(
@@ -554,6 +660,13 @@ async function init(args) {
554
660
  tags: ['api', 'Account'],
555
661
 
556
662
  plugins: {
663
+ mcp: {
664
+ name: 'sync_account',
665
+ title: 'Sync account now',
666
+ description: "Ask the account's worker to run a sync now instead of waiting for the next scheduled one.",
667
+ omit: ['sync'],
668
+ force: { sync: true }
669
+ },
557
670
  openapi: {
558
671
  'x-ee-behavior': [BEHAVIOR.SCHEDULED_ON_WORKER],
559
672
  responses: apiResponses(
@@ -631,6 +744,12 @@ async function init(args) {
631
744
  tags: ['api', 'Account'],
632
745
 
633
746
  plugins: {
747
+ mcp: {
748
+ name: 'delete_account',
749
+ title: 'Delete account',
750
+ description:
751
+ 'Remove an account from this instance, with its synced index and the tokens bound to it. The mailbox at the provider is untouched. Set revoke to true to also revoke the OAuth2 grant at the provider. Confirm with the user before calling this.'
752
+ },
634
753
  openapi: {
635
754
  'x-ee-impact': IMPACT.DESTRUCTIVE,
636
755
  'x-ee-behavior': [BEHAVIOR.DELETION_SCOPE],
@@ -714,6 +833,14 @@ async function init(args) {
714
833
  tags: ['api', 'Account'],
715
834
 
716
835
  plugins: {
836
+ mcp: {
837
+ name: 'flush_account',
838
+ title: 'Flush and re-sync account',
839
+ description:
840
+ "Discard the account's local index and sync it again from scratch. Every existing message counts as new again, so webhooks fire for all of them; use only when the index is broken or the sync settings changed. Confirm with the user before calling this.",
841
+ omit: ['flush'],
842
+ force: { flush: true }
843
+ },
717
844
  openapi: {
718
845
  'x-ee-impact': IMPACT.DESTRUCTIVE,
719
846
  'x-ee-behavior': [BEHAVIOR.SCHEDULED_ON_WORKER],
@@ -1461,6 +1588,7 @@ async function init(args) {
1461
1588
  subconnections: request.payload.subconnections,
1462
1589
  redirectUrl: request.payload.redirectUrl,
1463
1590
  delegated: request.payload.delegated,
1591
+ skipServerSettings: request.payload.skipServerSettings,
1464
1592
  path: request.payload.path && !request.payload.path.includes('*') ? request.payload.path : null,
1465
1593
  // identify request
1466
1594
  n: crypto.randomBytes(NONCE_BYTES).toString('base64url'),
@@ -1513,11 +1641,19 @@ async function init(args) {
1513
1641
  description: 'Generate authentication link',
1514
1642
  notes: [
1515
1643
  'Generates a redirect link to the hosted authentication form',
1644
+ 'An IMAP setup completes without asking the user for mail server settings whenever EmailEngine can discover and verify them from the address and password alone. Set `skipServerSettings` to false to always show that step.',
1516
1645
  'If `expectedEmail` is set and the user completes the form as a different identity, the setup is rejected before any credentials are stored. The user stays on EmailEngine, which names both addresses and offers to restart the setup, so the browser is never redirected to `redirectUrl`.'
1517
1646
  ],
1518
1647
  tags: ['api', 'Account'],
1519
1648
 
1520
1649
  plugins: {
1650
+ mcp: {
1651
+ name: 'create_account_setup_link',
1652
+ title: 'Create account setup link',
1653
+ description:
1654
+ 'Create a one-time link to the hosted setup form, where the user signs in to their mailbox themselves, so no password passes through this conversation. Give the link to the user. Set redirectUrl to where they should land afterwards; optionally account (the id to assign), name, email, expectedEmail (the setup is refused if they sign in as someone else) and type (an OAuth2 application id, or imap).',
1655
+ keep: ['account', 'name', 'email', 'expectedEmail', 'redirectUrl', 'type']
1656
+ },
1521
1657
  openapi: {
1522
1658
  responses: apiResponses('Returns a single-use URL for the hosted authentication form.', 400, 401, 403, 404, 429, 500)
1523
1659
  }
@@ -1565,6 +1701,15 @@ async function init(args) {
1565
1701
  .default(false)
1566
1702
  .description('If true, configures this account as a shared mailbox. Currently supported by MS365 OAuth2 accounts'),
1567
1703
 
1704
+ skipServerSettings: Joi.boolean()
1705
+ .empty('')
1706
+ .truthy('Y', 'true', '1')
1707
+ .falsy('N', 'false', 0)
1708
+ .default(true)
1709
+ .description(
1710
+ 'If true, the mail server settings step is skipped whenever the IMAP and SMTP settings for the address can both be discovered and verified with the password the user enters. The step is still shown if discovery or verification does not fully succeed. Set to false to always ask the user for the server settings. Applies to the IMAP setup path only.'
1711
+ ),
1712
+
1568
1713
  syncFrom: accountSchemas.syncFrom,
1569
1714
  notifyFrom: accountSchemas.notifyFrom,
1570
1715
 
@@ -1629,6 +1774,12 @@ async function init(args) {
1629
1774
  cors: CORS_CONFIG,
1630
1775
 
1631
1776
  plugins: {
1777
+ mcp: {
1778
+ name: 'get_account_logs',
1779
+ title: 'Get account connection log',
1780
+ description:
1781
+ 'Read the stored connection log of an account: the raw IMAP or provider API trace, which names folders, message ids and subjects. Use it to find out why an account fails to connect or sync. Only kept while logging is enabled for the account or for the whole instance.'
1782
+ },
1632
1783
  openapi: {
1633
1784
  'x-ee-behavior': [BEHAVIOR.ACCOUNT_LOG_SCOPE],
1634
1785
  produces: ['text/plain'],
@@ -1657,6 +1808,7 @@ async function init(args) {
1657
1808
 
1658
1809
  async handler(request) {
1659
1810
  try {
1811
+ assertNoNetworkOverride(request);
1660
1812
  return await verifyAccountInfo(redis, request.payload, request.logger.child({ action: 'verify-account' }));
1661
1813
  } catch (err) {
1662
1814
  handleError(request, err);
@@ -1668,6 +1820,14 @@ async function init(args) {
1668
1820
  tags: ['api', 'Account'],
1669
1821
 
1670
1822
  plugins: {
1823
+ mcp: {
1824
+ name: 'verify_account_settings',
1825
+ title: 'Verify account settings',
1826
+ description:
1827
+ 'Test IMAP and SMTP settings without saving them: connects and authenticates with the supplied host, port and credentials and reports what failed. Set mailboxes to true to also list the folders. Useful before create_account or update_account.',
1828
+ omit: ['proxy', 'smtpEhloName'],
1829
+ openWorld: true
1830
+ },
1671
1831
  openapi: {
1672
1832
  'x-ee-impact': IMPACT.READONLY,
1673
1833
  responses: apiResponses(
@@ -1725,18 +1885,7 @@ async function init(args) {
1725
1885
  path: '/v1/autoconfig',
1726
1886
 
1727
1887
  async handler(request) {
1728
- try {
1729
- let serverSettings = await autodetectImapSettings(request.query.email, request.app.gt);
1730
- return serverSettings;
1731
- } catch (err) {
1732
- // autodiscovery fails routinely for unknown domains and the handler answers with a
1733
- // regular "not found" response, so this is not an operator-visible failure
1734
- request.logger.debug({ msg: 'API request failed', err });
1735
- if (Boom.isBoom(err)) {
1736
- throw err;
1737
- }
1738
- return { imap: false, smtp: false, _source: 'unknown' };
1739
- }
1888
+ return await runAutoconfig(request, request.query.email);
1740
1889
  },
1741
1890
 
1742
1891
  options: {
@@ -1745,15 +1894,15 @@ async function init(args) {
1745
1894
  tags: ['api', 'Settings'],
1746
1895
 
1747
1896
  plugins: {
1897
+ mcp: {
1898
+ name: 'autodiscover_settings',
1899
+ title: 'Discover mail server settings',
1900
+ description:
1901
+ "Discover the IMAP and SMTP server settings for an email address from DNS and the provider's autoconfiguration. The natural first step before create_account or verify_account_settings for a mailbox that does not use an OAuth2 application.",
1902
+ openWorld: true
1903
+ },
1748
1904
  openapi: {
1749
- responses: apiResponses(
1750
- 'Returns the discovered IMAP and SMTP settings for the address, or empty values when nothing could be resolved.',
1751
- 400,
1752
- 401,
1753
- 403,
1754
- 429,
1755
- 500
1756
- )
1905
+ responses: AUTOCONFIG_RESPONSES
1757
1906
  }
1758
1907
  },
1759
1908
 
@@ -1772,63 +1921,80 @@ async function init(args) {
1772
1921
  failAction,
1773
1922
 
1774
1923
  query: Joi.object({
1775
- email: Joi.string()
1776
- .email()
1777
- .required()
1778
- .example('sender@example.com')
1779
- .description('Email address to discover email settings for')
1780
- .label('EmailAddress')
1924
+ email: autodiscoverEmailSchema
1781
1925
  }).label('AutodiscoverQuery')
1782
1926
  },
1783
1927
 
1784
1928
  response: {
1785
- schema: Joi.object({
1786
- imap: Joi.object({
1787
- auth: Joi.object({
1788
- user: Joi.string().max(256).example('myuser@gmail.com').description('Account username')
1789
- }).label('DetectedAuthenticationInfo'),
1790
-
1791
- host: Joi.string().hostname().example('imap.gmail.com').description('Hostname to connect to'),
1792
- port: Joi.number()
1793
- .integer()
1794
- .min(1)
1795
- .max(64 * 1024)
1796
- .example(993)
1797
- .description('Service port number'),
1798
- secure: Joi.boolean().default(false).example(true).description('Should connection use TLS. Usually true for port 993')
1799
- })
1800
- .allow(false)
1801
- .description('Discovered IMAP settings. False if IMAP settings were not found')
1802
- .label('ResolvedServerSettings'),
1803
- smtp: Joi.object({
1804
- auth: Joi.object({
1805
- user: Joi.string().max(256).example('myuser@gmail.com').description('Account username')
1806
- }).label('DetectedAuthenticationInfo'),
1807
-
1808
- host: Joi.string().hostname().example('smtp.gmail.com').description('Hostname to connect to'),
1809
- port: Joi.number()
1810
- .integer()
1811
- .min(1)
1812
- .max(64 * 1024)
1813
- .example(465)
1814
- .description('Service port number'),
1815
- secure: Joi.boolean().default(false).example(true).description('Should connection use TLS. Usually true for port 465')
1816
- })
1817
- .allow(false)
1818
- .description('Discovered SMTP settings. False if SMTP settings were not found')
1819
- .label('DiscoveredServerSettings'),
1820
- appPassword: Joi.object({
1821
- required: Joi.boolean().example(true).description('Whether the provider requires an app password'),
1822
- provider: Joi.string().example('Gmail').description('Provider name'),
1823
- instructions: Joi.string()
1824
- .example('Use an app password instead of the regular account password')
1825
- .description('Instructions for setting up an app password')
1929
+ schema: discoveredEmailSettingsSchema,
1930
+ failAction: 'log'
1931
+ }
1932
+ }
1933
+ });
1934
+
1935
+ server.route({
1936
+ method: 'POST',
1937
+ path: '/v1/autoconfig',
1938
+
1939
+ async handler(request) {
1940
+ // The credentials are offered to the autodiscovery host only after that host has refused
1941
+ // an anonymous request with a Basic challenge over https, and only to the origin that
1942
+ // issued it (lib/autodetect-imap-settings.js runAutodiscovery). Every other resolver
1943
+ // stays anonymous, so an address that resolves without a password answers the same here
1944
+ // as it does on the GET.
1945
+ return await runAutoconfig(request, request.payload.email, request.payload.auth);
1946
+ },
1947
+
1948
+ options: {
1949
+ description: 'Discover Email settings with credentials',
1950
+ notes: [
1951
+ 'Try to discover IMAP and SMTP settings for an email account, optionally authenticating against an autodiscovery server that refuses to answer anonymously',
1952
+ "Hosted Exchange answers autodiscovery only for an authenticated request, which is why this endpoint exists alongside `GET /v1/autoconfig`. The password is sent to the autodiscovery host named by the address domain's own DNS records, and only after that host has asked for it with a Basic challenge over HTTPS."
1953
+ ],
1954
+ tags: ['api', 'Settings'],
1955
+
1956
+ // Deliberately not exposed as an MCP tool. `autodiscover_settings` (the GET) covers
1957
+ // discovery for an agent; this one takes a mailbox password as an argument, which is not
1958
+ // something to put in a tool manifest for a model to fill in.
1959
+ plugins: {
1960
+ openapi: {
1961
+ 'x-ee-impact': IMPACT.READONLY,
1962
+ responses: AUTOCONFIG_RESPONSES
1963
+ }
1964
+ },
1965
+
1966
+ auth: {
1967
+ strategy: 'api-token',
1968
+ mode: 'required'
1969
+ },
1970
+ cors: CORS_CONFIG,
1971
+
1972
+ validate: {
1973
+ options: {
1974
+ stripUnknown: false,
1975
+ abortEarly: false,
1976
+ convert: true
1977
+ },
1978
+ failAction,
1979
+
1980
+ payload: Joi.object({
1981
+ email: autodiscoverEmailSchema,
1982
+ auth: Joi.object({
1983
+ user: Joi.string()
1984
+ .empty('')
1985
+ .trim()
1986
+ .max(1024)
1987
+ .example('myuser@gmail.com')
1988
+ .description('Username for the autodiscovery request. Defaults to the email address.'),
1989
+ pass: Joi.string().max(1024).required().example('verysecret').description('Password for the mailbox')
1826
1990
  })
1827
- .unknown()
1828
- .description('App password requirements for the provider, if known')
1829
- .label('DiscoveredAppPasswordInfo'),
1830
- _source: Joi.string().example('srv').description('Source for the detected info')
1831
- }).label('DiscoveredEmailSettings'),
1991
+ .description('Credentials to offer if the autodiscovery server refuses to answer anonymously')
1992
+ .label('AutodiscoverCredentials')
1993
+ }).label('AutodiscoverRequest')
1994
+ },
1995
+
1996
+ response: {
1997
+ schema: discoveredEmailSettingsSchema,
1832
1998
  failAction: 'log'
1833
1999
  }
1834
2000
  }
@@ -10,6 +10,7 @@ const { failAction } = require('../tools');
10
10
  const { handleError } = require('./route-helpers');
11
11
  const { accountIdSchema, blocklistListIdSchema, apiResponses } = require('../schemas');
12
12
  const { IMPACT } = require('./operation-impact');
13
+ const { MCP_MAX_PAGE_SIZE } = require('../consts');
13
14
 
14
15
  async function init(args) {
15
16
  const { server, call, CORS_CONFIG } = args;
@@ -32,6 +33,12 @@ async function init(args) {
32
33
  tags: ['api', 'Blocklists'],
33
34
 
34
35
  plugins: {
36
+ mcp: {
37
+ name: 'list_blocklists',
38
+ title: 'List suppression lists',
39
+ description: 'List the suppression lists (blocklists) and how many addresses each holds, paged.',
40
+ bounds: { pageSize: MCP_MAX_PAGE_SIZE }
41
+ },
35
42
  openapi: {
36
43
  responses: apiResponses('Returns every blocklist with its entry count.', 400, 401, 403, 429, 500)
37
44
  }
@@ -102,6 +109,12 @@ async function init(args) {
102
109
  tags: ['api', 'Blocklists'],
103
110
 
104
111
  plugins: {
112
+ mcp: {
113
+ name: 'get_blocklist',
114
+ title: 'Get suppression list',
115
+ description: 'List the addresses on one suppression list, paged, with the reason and source of each entry.',
116
+ bounds: { pageSize: MCP_MAX_PAGE_SIZE }
117
+ },
105
118
  openapi: {
106
119
  responses: apiResponses('Returns a page of entries on the blocklist.', 400, 401, 403, 404, 429, 500)
107
120
  }
@@ -208,6 +221,12 @@ async function init(args) {
208
221
  tags: ['api', 'Blocklists'],
209
222
 
210
223
  plugins: {
224
+ mcp: {
225
+ name: 'add_to_blocklist',
226
+ title: 'Add to suppression list',
227
+ description:
228
+ 'Add a recipient address to a suppression list, so messages sent with that list id are not delivered to it. Needs the account the block was raised for.'
229
+ },
211
230
  openapi: {
212
231
  responses: apiResponses('Returns whether the address was added or was already listed.', 400, 401, 403, 404, 429, 500)
213
232
  }
@@ -276,6 +295,11 @@ async function init(args) {
276
295
  tags: ['api', 'Blocklists'],
277
296
 
278
297
  plugins: {
298
+ mcp: {
299
+ name: 'remove_from_blocklist',
300
+ title: 'Remove from suppression list',
301
+ description: 'Remove a recipient address from a suppression list, so messages to it are delivered again.'
302
+ },
279
303
  openapi: {
280
304
  'x-ee-impact': IMPACT.DESTRUCTIVE,
281
305
  responses: apiResponses('Returns a deletion marker.', 400, 401, 403, 404, 429, 500)
@@ -278,6 +278,12 @@ ${now}`,
278
278
  tags: ['api', 'Delivery Test'],
279
279
 
280
280
  plugins: {
281
+ mcp: {
282
+ name: 'check_delivery_test',
283
+ title: 'Check delivery test',
284
+ description:
285
+ 'Check the result of a delivery test started over the REST API: whether the probe message arrived, and its SPF, DKIM and DMARC results.'
286
+ },
281
287
  openapi: {
282
288
  responses: apiResponses(
283
289
  'Returns the test result once it has completed, including SPF, DKIM and DMARC outcomes.',
@@ -9,6 +9,7 @@ const { handleError, maskSecrets, MASKED, MASK_NOTE } = require('./route-helpers
9
9
  const { apiResponses } = require('../schemas');
10
10
  const { ENUM_DESCRIPTIONS } = require('../enum-descriptions');
11
11
  const { IMPACT } = require('./operation-impact');
12
+ const { MCP_MAX_PAGE_SIZE } = require('../consts');
12
13
 
13
14
  // Gateways store SMTP delivery errors, not OAuth2 errors, so the error shape differs from the
14
15
  // account-level lastErrorSchema
@@ -60,6 +61,13 @@ async function init(args) {
60
61
  tags: ['api', 'SMTP Gateway'],
61
62
 
62
63
  plugins: {
64
+ mcp: {
65
+ name: 'list_gateways',
66
+ title: 'List SMTP gateways',
67
+ description:
68
+ "List the SMTP gateways (relay servers messages can be sent through instead of the account's own SMTP server), paged. Passwords are masked.",
69
+ bounds: { pageSize: MCP_MAX_PAGE_SIZE }
70
+ },
63
71
  openapi: {
64
72
  responses: apiResponses('Returns a page of configured SMTP gateways.', 400, 401, 403, 429, 500)
65
73
  }
@@ -156,6 +164,11 @@ async function init(args) {
156
164
  tags: ['api', 'SMTP Gateway'],
157
165
 
158
166
  plugins: {
167
+ mcp: {
168
+ name: 'get_gateway',
169
+ title: 'Get SMTP gateway',
170
+ description: 'Get one SMTP gateway: host, port, TLS mode, username and the last delivery error. The password is masked.'
171
+ },
159
172
  openapi: {
160
173
  responses: apiResponses('Returns the gateway configuration. The password is masked.', 400, 401, 403, 404, 429, 500)
161
174
  }
@@ -253,6 +266,12 @@ async function init(args) {
253
266
  tags: ['api', 'SMTP Gateway'],
254
267
 
255
268
  plugins: {
269
+ mcp: {
270
+ name: 'create_gateway',
271
+ title: 'Create SMTP gateway',
272
+ description:
273
+ 'Register an SMTP gateway, a relay server messages can be sent through. Needs an id, a name, the host and the port; a password can be written but never read back.'
274
+ },
256
275
  openapi: {
257
276
  responses: apiResponses('Returns the registered gateway.', 400, 401, 403, 429, 500)
258
277
  }
@@ -342,6 +361,12 @@ async function init(args) {
342
361
  tags: ['api', 'SMTP Gateway'],
343
362
 
344
363
  plugins: {
364
+ mcp: {
365
+ name: 'update_gateway',
366
+ title: 'Update SMTP gateway',
367
+ description:
368
+ 'Update an SMTP gateway. Send only the fields to change. Changing the host makes the next delivery authenticate to the new host with the stored password, so confirm host changes with the user.'
369
+ },
345
370
  openapi: {
346
371
  responses: apiResponses('Returns the updated gateway.', 400, 401, 403, 404, 429, 500)
347
372
  }
@@ -429,6 +454,11 @@ async function init(args) {
429
454
  tags: ['api', 'SMTP Gateway'],
430
455
 
431
456
  plugins: {
457
+ mcp: {
458
+ name: 'delete_gateway',
459
+ title: 'Delete SMTP gateway',
460
+ description: 'Remove an SMTP gateway. Messages queued through it fail to deliver. Confirm with the user before calling this.'
461
+ },
432
462
  openapi: {
433
463
  'x-ee-impact': IMPACT.DESTRUCTIVE,
434
464
  responses: apiResponses('Returns a deletion marker.', 400, 401, 403, 404, 429, 500)
@@ -32,6 +32,11 @@ async function init(args) {
32
32
  tags: ['api', 'License'],
33
33
 
34
34
  plugins: {
35
+ mcp: {
36
+ name: 'get_license',
37
+ title: 'Get license',
38
+ description: 'Get the active license: who it is issued to and when it expires, or an empty object when the instance runs unlicensed.'
39
+ },
35
40
  openapi: {
36
41
  responses: apiResponses('Returns the active license and its expiry, or an empty object when unlicensed.', 401, 403, 429, 500)
37
42
  }
@@ -119,6 +124,11 @@ async function init(args) {
119
124
  tags: ['api', 'License'],
120
125
 
121
126
  plugins: {
127
+ mcp: {
128
+ name: 'set_license',
129
+ title: 'Apply license',
130
+ description: 'Apply a license key to this instance. Takes the full license text as issued, including its BEGIN and END lines.'
131
+ },
122
132
  openapi: {
123
133
  responses: apiResponses('Returns the registered license.', 400, 401, 403, 429, 500)
124
134
  }
@@ -19,7 +19,7 @@ const Boom = require('@hapi/boom');
19
19
  const Joi = require('joi');
20
20
 
21
21
  const { checkRateLimit } = require('../rate-limit');
22
- const { oauthOrigin, mcpResource, registerClient, redeemAuthorizationCode, MAX_REDIRECT_URIS } = require('../mcp/oauth');
22
+ const { oauthOrigin, mcpResource, registerClient, redeemAuthorizationCode, MAX_REDIRECT_URIS, MCP_OAUTH_SCOPES } = require('../mcp/oauth');
23
23
 
24
24
  const OPEN_CORS = { origin: ['*'] };
25
25
 
@@ -95,7 +95,7 @@ async function init(args) {
95
95
  return {
96
96
  resource: mcpResource(origin),
97
97
  authorization_servers: [origin],
98
- scopes_supported: ['mcp'],
98
+ scopes_supported: MCP_OAUTH_SCOPES,
99
99
  bearer_methods_supported: ['header'],
100
100
  resource_name: 'EmailEngine MCP'
101
101
  };
@@ -128,7 +128,7 @@ async function init(args) {
128
128
  grant_types_supported: ['authorization_code'],
129
129
  code_challenge_methods_supported: ['S256'],
130
130
  token_endpoint_auth_methods_supported: ['none'],
131
- scopes_supported: ['mcp'],
131
+ scopes_supported: MCP_OAUTH_SCOPES,
132
132
  authorization_response_iss_parameter_supported: true
133
133
  };
134
134
  },