emailengine-app 2.84.2 → 2.86.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/.ncurc.js +29 -9
  2. package/.prettierignore +5 -1
  3. package/.prettierrc.js +2 -0
  4. package/.release-please-manifest.json +1 -1
  5. package/CHANGELOG.md +107 -0
  6. package/Dockerfile +20 -1
  7. package/ENVIRONMENT.md +139 -0
  8. package/README.md +2 -2
  9. package/bin/emailengine.js +434 -408
  10. package/config/default.toml +2 -0
  11. package/copy-static-files.sh +41 -14
  12. package/data/google-crawlers.json +1 -1
  13. package/data/public_suffix_list.dat +16563 -0
  14. package/eslint.config.js +81 -99
  15. package/lib/account-assignment.js +19 -0
  16. package/lib/account.js +230 -170
  17. package/lib/api-error-codes.js +49 -0
  18. package/lib/api-reference/format.js +4 -3
  19. package/lib/api-reference/model.js +6 -1
  20. package/lib/api-routes/account-routes.js +255 -38
  21. package/lib/api-routes/blocklist-routes.js +91 -4
  22. package/lib/api-routes/delivery-test-routes.js +27 -4
  23. package/lib/api-routes/export-routes.js +28 -2
  24. package/lib/api-routes/gateway-routes.js +110 -12
  25. package/lib/api-routes/index.js +4 -0
  26. package/lib/api-routes/license-routes.js +2 -2
  27. package/lib/api-routes/mailbox-routes.js +44 -5
  28. package/lib/api-routes/message-routes.js +112 -10
  29. package/lib/api-routes/oauth2-app-routes.js +63 -23
  30. package/lib/api-routes/outbox-routes.js +97 -52
  31. package/lib/api-routes/permission-map.js +67 -7
  32. package/lib/api-routes/scoped-routes.js +74 -0
  33. package/lib/api-routes/settings-routes.js +34 -6
  34. package/lib/api-routes/stats-routes.js +5 -1
  35. package/lib/api-routes/submit-routes.js +337 -309
  36. package/lib/api-routes/template-routes.js +45 -8
  37. package/lib/api-routes/token-routes.js +152 -100
  38. package/lib/api-routes/webhook-delivery-routes.js +262 -0
  39. package/lib/api-routes/webhook-route-routes.js +132 -6
  40. package/lib/bounce-detect.js +397 -205
  41. package/lib/calendar-event.js +81 -1
  42. package/lib/consts.js +38 -45
  43. package/lib/db.js +14 -6
  44. package/lib/delivery-error.js +6 -0
  45. package/lib/deprecations.js +270 -0
  46. package/lib/email-client/base-client.js +137 -184
  47. package/lib/email-client/fallback-poll.js +62 -0
  48. package/lib/email-client/gmail-client.js +60 -22
  49. package/lib/email-client/imap/adaptive-idle-store.js +73 -0
  50. package/lib/email-client/imap/adaptive-idle.js +278 -0
  51. package/lib/email-client/imap/connection-errors.js +14 -1
  52. package/lib/email-client/imap/idle-settings.js +31 -5
  53. package/lib/email-client/imap/listing-diff.js +37 -0
  54. package/lib/email-client/imap/mailbox.js +372 -242
  55. package/lib/email-client/imap/subconnection.js +8 -30
  56. package/lib/email-client/imap/sync-operations.js +220 -127
  57. package/lib/email-client/imap-client.js +228 -164
  58. package/lib/email-client/message-builder.js +14 -79
  59. package/lib/email-client/notification-handler.js +1 -2
  60. package/lib/email-client/outlook-client.js +372 -338
  61. package/lib/email-client/smtp-pool-manager.js +16 -13
  62. package/lib/email-client/sync-state-fields.js +19 -0
  63. package/lib/encrypt.js +157 -41
  64. package/lib/enum-descriptions.js +3 -1
  65. package/lib/env-setting-overrides.js +288 -0
  66. package/lib/export-worker.js +751 -0
  67. package/lib/export.js +64 -15
  68. package/lib/gateway.js +19 -4
  69. package/lib/get-raw-email.js +25 -107
  70. package/lib/hapi-request-logger.js +107 -0
  71. package/lib/health.js +75 -0
  72. package/lib/imapproxy/imap-core/README.md +6 -5
  73. package/lib/lock-run.js +119 -0
  74. package/lib/logger-consts.js +48 -0
  75. package/lib/logger.js +1 -1
  76. package/lib/lua/z-head-scores.lua +28 -0
  77. package/lib/mcp/tools.js +37 -8
  78. package/lib/network-errors.js +1 -1
  79. package/lib/node-version.js +24 -0
  80. package/lib/notify-attachments.js +36 -0
  81. package/lib/oauth/outlook-mailbox.js +35 -0
  82. package/lib/oauth/state.js +24 -0
  83. package/lib/oauth2-apps.js +631 -656
  84. package/lib/outbox.js +184 -54
  85. package/lib/parse-message.js +3 -3
  86. package/lib/pbkdf2-phc.js +1 -1
  87. package/lib/privileged-settings.js +2 -2
  88. package/lib/queue-browser/definitions.js +11 -0
  89. package/lib/queue-browser/index.js +68 -19
  90. package/lib/queue-job-actions.js +18 -1
  91. package/lib/queue-retention.js +48 -12
  92. package/lib/queue-stats.js +11 -2
  93. package/lib/read-env-value.js +3 -0
  94. package/lib/redis-memory-warnings.js +99 -0
  95. package/lib/redis-reconnect.js +29 -0
  96. package/lib/request-timing.js +23 -0
  97. package/lib/respawn-backoff.js +35 -0
  98. package/lib/rewrite-text-nodes.js +19 -59
  99. package/lib/schemas.js +164 -40
  100. package/lib/settings.js +6 -2
  101. package/lib/smtp-auth.js +19 -1
  102. package/lib/sso.js +1 -1
  103. package/lib/swagger-options.js +1 -1
  104. package/lib/thread-diagnostics.js +63 -0
  105. package/lib/timezones.js +109 -0
  106. package/lib/tls/provision.js +6 -3
  107. package/lib/token-audit-log.js +19 -20
  108. package/lib/token-permission-view.js +7 -6
  109. package/lib/tools.js +48 -51
  110. package/lib/totp.js +2 -5
  111. package/lib/translations.js +1 -2
  112. package/lib/ui-routes/account-routes.js +475 -454
  113. package/lib/ui-routes/account-setup.js +99 -0
  114. package/lib/ui-routes/admin-config-routes.js +152 -100
  115. package/lib/ui-routes/admin-entities-routes.js +93 -21
  116. package/lib/ui-routes/auth-routes.js +90 -38
  117. package/lib/ui-routes/imap-idle-field.js +1 -1
  118. package/lib/ui-routes/internals-routes.js +5 -0
  119. package/lib/ui-routes/oauth-config-routes.js +124 -82
  120. package/lib/ui-routes/outlook-subscription-view.js +1 -1
  121. package/lib/ui-routes/overridable-fields.js +84 -0
  122. package/lib/ui-routes/queue-routes.js +8 -5
  123. package/lib/ui-routes/route-helpers.js +19 -3
  124. package/lib/ui-routes/settings-page.js +6 -0
  125. package/lib/ui-routes/tls-config-routes.js +58 -15
  126. package/lib/utils/back-off.js +82 -0
  127. package/lib/utils/decode-headers.js +3 -12
  128. package/lib/utils/filter-empty.js +20 -0
  129. package/lib/utils/int-setting.js +48 -0
  130. package/lib/utils/murmurhash3.js +66 -0
  131. package/lib/utils/public-suffix.js +122 -0
  132. package/lib/utils/random-id.js +26 -0
  133. package/lib/utils/tracking-settings.js +35 -0
  134. package/lib/utils/version.js +74 -0
  135. package/lib/web-safe-html.js +18 -105
  136. package/lib/webhook-delivery.js +461 -0
  137. package/lib/webhook-failures.js +132 -0
  138. package/lib/webhook-request.js +29 -1
  139. package/lib/webhook-routing.js +56 -0
  140. package/lib/webhook-test.js +88 -0
  141. package/lib/webhooks.js +93 -45
  142. package/lib/worker-rpc-error.js +2 -1
  143. package/package.json +37 -38
  144. package/sbom.json +7902 -1
  145. package/server.js +784 -518
  146. package/static/js/ace/ace.js +1 -1
  147. package/static/licenses.html +225 -1060
  148. package/translations/messages.pot +62 -63
  149. package/views/config/ai.hbs +1 -1
  150. package/views/config/security.hbs +24 -2
  151. package/views/config/service.hbs +47 -0
  152. package/views/config/webhooks.hbs +36 -0
  153. package/views/internals/index.hbs +8 -0
  154. package/views/partials/queue_retention_note.hbs +12 -8
  155. package/views/partials/ui/env-managed-alert.hbs +16 -7
  156. package/views/partials/webhook_form.hbs +1 -1
  157. package/views/suppression-lists/index.hbs +1 -1
  158. package/workers/api.js +840 -611
  159. package/workers/export.js +17 -632
  160. package/workers/imap.js +13 -0
  161. package/workers/smtp.js +9 -11
  162. package/workers/submit.js +1 -1
  163. package/workers/webhooks.js +18 -448
  164. package/lib/email-client/outlook-fallback-poll.js +0 -30
@@ -42,7 +42,8 @@ const {
42
42
  ENUM_DESCRIPTIONS,
43
43
  apiBoolean,
44
44
  mailboxAddressSchema,
45
- accountProxySchema
45
+ accountProxySchema,
46
+ verifyResultSchema
46
47
  } = require('../schemas');
47
48
 
48
49
  const { REDIS_PREFIX, MAX_FORM_TTL, NONCE_BYTES, MCP_MAX_PAGE_SIZE, OUTLOOK_SYNC_MAX_LOOKBACK } = require('../consts');
@@ -57,28 +58,6 @@ const accountOauth2ScopesSchema = Joi.array()
57
58
  .description('OAuth2 scopes granted for this account')
58
59
  .label('AccountOauth2Scopes');
59
60
 
60
- // Per-protocol result block for the account verification response - the IMAP and SMTP results
61
- // carry the same fields built by verifyAccountInfo, only labels, wording, and the server
62
- // response example differ
63
- const verifyResultSchema = (proto, responseTextExample) =>
64
- Joi.object({
65
- success: Joi.boolean().example(true).description(`Was ${proto.toUpperCase()} account verified`).label(`Verify${proto}Success`),
66
- error: Joi.string()
67
- .example('Something went wrong')
68
- .description(`Error messages for ${proto.toUpperCase()} verification. Only present if success=false`)
69
- .label(`Verify${proto}Error`),
70
- code: Joi.string().example('ERR_SSL_WRONG_VERSION_NUMBER').description('Error code. Only present if success=false').label(`Verify${proto}Code`),
71
- statusCode: Joi.number()
72
- .integer()
73
- .example(500)
74
- .description('HTTP-style status code for the error. Only present if success=false')
75
- .label(`Verify${proto}StatusCode`),
76
- responseText: Joi.string()
77
- .example(responseTextExample)
78
- .description('Server response for the failed verification. Only present if success=false')
79
- .label(`Verify${proto}ResponseText`)
80
- }).label(`Verify${proto}Result`);
81
-
82
61
  // The answer autodiscovery gives, shared by GET and POST /v1/autoconfig. One definition rather than
83
62
  // two identical inline copies: the OpenAPI converter collapses structurally identical labelled
84
63
  // schemas into a single component, so the two routes publish one `DiscoveredEmailSettings` type.
@@ -166,18 +145,8 @@ function validateDelegationFields(payload) {
166
145
  }
167
146
  }
168
147
 
169
- async function init(args) {
170
- const {
171
- server,
172
- call,
173
- oauth2Schema: oauth2SchemaArg,
174
- imapSchema: imapSchemaArg,
175
- smtpSchema: smtpSchemaArg,
176
- CORS_CONFIG,
177
- AccountTypeSchema,
178
- OAuth2ProviderSchema,
179
- metrics
180
- } = args;
148
+ function registerCreateAccount(server, args) {
149
+ const { call, oauth2Schema: oauth2SchemaArg, imapSchema: imapSchemaArg, smtpSchema: smtpSchemaArg, CORS_CONFIG } = args;
181
150
 
182
151
  // POST /v1/account - Create account
183
152
  server.route({
@@ -429,6 +398,10 @@ async function init(args) {
429
398
  }
430
399
  }
431
400
  });
401
+ }
402
+
403
+ function registerUpdateAccount(server, args) {
404
+ const { call, CORS_CONFIG } = args;
432
405
 
433
406
  // PUT /v1/account/{account} - Update account
434
407
  server.route({
@@ -586,6 +559,10 @@ async function init(args) {
586
559
  }
587
560
  }
588
561
  });
562
+ }
563
+
564
+ function registerAccountReconnect(server, args) {
565
+ const { call, CORS_CONFIG } = args;
589
566
 
590
567
  // PUT /v1/account/{account}/reconnect - Request reconnect
591
568
  server.route({
@@ -666,6 +643,108 @@ async function init(args) {
666
643
  }
667
644
  }
668
645
  });
646
+ }
647
+
648
+ function registerAccountResume(server, args) {
649
+ const { call, CORS_CONFIG } = args;
650
+
651
+ // PUT /v1/account/{account}/resume - Resume an account switched off after authentication failures
652
+ server.route({
653
+ method: 'PUT',
654
+ path: '/v1/account/{account}/resume',
655
+
656
+ async handler(request) {
657
+ let accountObject = new Account({
658
+ redis,
659
+ account: request.params.account,
660
+ call,
661
+ secret: await getSecret(),
662
+ timeout: request.headers['x-ee-timeout']
663
+ });
664
+
665
+ try {
666
+ // 404 for an unknown account rather than the 409 below, which would read as "this
667
+ // account exists and is running"
668
+ await accountObject.loadAccountData(request.params.account, false);
669
+
670
+ if (!(await accountObject.resumeAfterAuthFailure())) {
671
+ // The same answer the admin UI gives, as a state refusal: an account that was
672
+ // never parked, or that an operator already re-enabled, has nothing to resume,
673
+ // and an operator's own send-only switch is not lifted from here
674
+ let err = new Error('This account was not switched off by EmailEngine after authentication failures, so there is nothing to resume');
675
+ err.code = 'NotSwitchedOff';
676
+ err.statusCode = 409;
677
+ throw err;
678
+ }
679
+
680
+ return { resumed: true };
681
+ } catch (err) {
682
+ handleError(request, err);
683
+ }
684
+ },
685
+ options: {
686
+ description: 'Resume syncing',
687
+ notes: [
688
+ 'Turns an account back on after EmailEngine switched it off following repeated authentication failures (`authFailureDisabledAt` on the account), and requests a reconnect. The same action as "Resume syncing" in the admin UI. Only lifts that automatic switch: an account that was not switched off by EmailEngine, including one an operator set to send-only, answers 409 with `code` NotSwitchedOff. If the stored credentials are still refused, the account is switched off again after the next run of failures, so fix the credentials first.',
689
+ BEHAVIOR.SCHEDULED_ON_WORKER
690
+ ],
691
+ tags: ['api', 'Account'],
692
+
693
+ plugins: {
694
+ mcp: {
695
+ name: 'resume_account',
696
+ title: 'Resume account',
697
+ description:
698
+ 'Turn an account back on after EmailEngine switched it off following repeated authentication failures, and reconnect it. list_accounts and get_account show such an account with authFailureDisabledAt set. ' +
699
+ 'Use once the cause is fixed (a changed password, a revoked or expired authorization): with the same credentials still refused, the account is switched off again after the next run of failures. ' +
700
+ 'An account that EmailEngine did not switch off has nothing to resume, and the call fails saying so.'
701
+ },
702
+ openapi: {
703
+ 'x-ee-behavior': [BEHAVIOR.SCHEDULED_ON_WORKER],
704
+ responses: apiResponses(
705
+ 'Returns an acknowledgement. The account is switched back on and a reconnect is requested, not completed - watch the account state for the result.',
706
+ 400,
707
+ 401,
708
+ 403,
709
+ 404,
710
+ 409,
711
+ 429,
712
+ 500
713
+ )
714
+ }
715
+ },
716
+
717
+ auth: {
718
+ strategy: 'api-token',
719
+ mode: 'required'
720
+ },
721
+ cors: CORS_CONFIG,
722
+
723
+ validate: {
724
+ options: {
725
+ stripUnknown: false,
726
+ abortEarly: false,
727
+ convert: true
728
+ },
729
+ failAction,
730
+
731
+ params: Joi.object({
732
+ account: accountIdSchema.required()
733
+ })
734
+ },
735
+
736
+ response: {
737
+ schema: Joi.object({
738
+ resumed: Joi.boolean().example(true).description('The account was switched back on and a reconnect was requested')
739
+ }).label('AccountResumeResponse'),
740
+ failAction: 'log'
741
+ }
742
+ }
743
+ });
744
+ }
745
+
746
+ function registerAccountSync(server, args) {
747
+ const { call, CORS_CONFIG } = args;
669
748
 
670
749
  // PUT /v1/account/{account}/sync - Request syncing
671
750
  server.route({
@@ -755,6 +834,10 @@ async function init(args) {
755
834
  }
756
835
  }
757
836
  });
837
+ }
838
+
839
+ function registerDeleteAccount(server, args) {
840
+ const { call, CORS_CONFIG } = args;
758
841
 
759
842
  // DELETE /v1/account/{account} - Remove account
760
843
  server.route({
@@ -842,6 +925,10 @@ async function init(args) {
842
925
  }
843
926
  }
844
927
  });
928
+ }
929
+
930
+ function registerAccountFlush(server, args) {
931
+ const { call, CORS_CONFIG } = args;
845
932
 
846
933
  // PUT /v1/account/{account}/flush - Request account flush
847
934
  server.route({
@@ -929,6 +1016,10 @@ async function init(args) {
929
1016
  }
930
1017
  }
931
1018
  });
1019
+ }
1020
+
1021
+ function registerListAccounts(server, args) {
1022
+ const { call, CORS_CONFIG, AccountTypeSchema } = args;
932
1023
 
933
1024
  // GET /v1/accounts - List accounts
934
1025
  server.route({
@@ -961,7 +1052,7 @@ async function init(args) {
961
1052
 
962
1053
  options: {
963
1054
  description: 'List accounts',
964
- notes: 'Lists registered accounts',
1055
+ notes: 'Lists the email accounts registered on this instance, one page at a time, with their connection state.',
965
1056
  tags: ['api', 'Account'],
966
1057
 
967
1058
  plugins: {
@@ -1068,6 +1159,10 @@ async function init(args) {
1068
1159
  }
1069
1160
  }
1070
1161
  });
1162
+ }
1163
+
1164
+ function registerGetAccount(server, args) {
1165
+ const { call, CORS_CONFIG, AccountTypeSchema } = args;
1071
1166
 
1072
1167
  // GET /v1/account/{account} - Get account info
1073
1168
  server.route({
@@ -1432,7 +1527,8 @@ async function init(args) {
1432
1527
  state: Joi.string()
1433
1528
  .valid('creating', 'created', 'renewing', 'error')
1434
1529
  .description('Subscription state')
1435
- .meta({ enumDescriptions: ENUM_DESCRIPTIONS.pubsubState }),
1530
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.pubsubState })
1531
+ .label('OutlookSubscriptionStateName'),
1436
1532
  time: Joi.number().example(1625727994336).description('Timestamp of last state change'),
1437
1533
  error: Joi.string()
1438
1534
  .allow(null)
@@ -1443,9 +1539,11 @@ async function init(args) {
1443
1539
  })
1444
1540
  .unknown()
1445
1541
  .description('Current subscription state')
1542
+ .label('OutlookSubscriptionState')
1446
1543
  })
1447
1544
  .unknown()
1448
- .description('Microsoft Graph subscription details (Outlook accounts only)'),
1545
+ .description('Microsoft Graph subscription details (Outlook accounts only)')
1546
+ .label('OutlookSubscription'),
1449
1547
 
1450
1548
  lastError: lastErrorSchema.allow(null)
1451
1549
  }).label('AccountResponse'),
@@ -1453,6 +1551,10 @@ async function init(args) {
1453
1551
  }
1454
1552
  }
1455
1553
  });
1554
+ }
1555
+
1556
+ function registerGetAccountOAuthToken(server, args) {
1557
+ const { call, CORS_CONFIG, OAuth2ProviderSchema, metrics } = args;
1456
1558
 
1457
1559
  server.route({
1458
1560
  method: 'GET',
@@ -1580,6 +1682,10 @@ async function init(args) {
1580
1682
  }
1581
1683
  }
1582
1684
  });
1685
+ }
1686
+
1687
+ function registerGetServerSignatures(server, args) {
1688
+ const { call, CORS_CONFIG } = args;
1583
1689
 
1584
1690
  server.route({
1585
1691
  method: 'GET',
@@ -1606,6 +1712,12 @@ async function init(args) {
1606
1712
  tags: ['api', 'Account'],
1607
1713
 
1608
1714
  plugins: {
1715
+ mcp: {
1716
+ name: 'get_server_signatures',
1717
+ title: 'Get account signatures',
1718
+ description:
1719
+ 'List the email signatures configured on the account at the provider, to append to a message composed for it. Only Gmail API accounts report signatures; for other accounts the list is empty.'
1720
+ },
1609
1721
  openapi: {
1610
1722
  responses: apiResponses('Returns the signatures configured on the account, as reported by the provider.', 400, 401, 403, 404, 429, 500)
1611
1723
  }
@@ -1651,6 +1763,10 @@ async function init(args) {
1651
1763
  }
1652
1764
  }
1653
1765
  });
1766
+ }
1767
+
1768
+ function registerAuthenticationForm(server, args) {
1769
+ const { CORS_CONFIG } = args;
1654
1770
 
1655
1771
  server.route({
1656
1772
  method: 'POST',
@@ -1819,6 +1935,10 @@ async function init(args) {
1819
1935
  }
1820
1936
  }
1821
1937
  });
1938
+ }
1939
+
1940
+ function registerGetLogs(server, args) {
1941
+ const { CORS_CONFIG } = args;
1822
1942
 
1823
1943
  server.route({
1824
1944
  method: 'GET',
@@ -1884,6 +2004,73 @@ async function init(args) {
1884
2004
  }
1885
2005
  }
1886
2006
  });
2007
+ }
2008
+
2009
+ function registerDeleteLogs(server, args) {
2010
+ const { CORS_CONFIG } = args;
2011
+
2012
+ server.route({
2013
+ method: 'DELETE',
2014
+ path: '/v1/logs/{account}',
2015
+
2016
+ async handler(request) {
2017
+ try {
2018
+ if (!(await accountExists(redis, request.params.account))) {
2019
+ throw Boom.notFound('Account record was not found for requested ID');
2020
+ }
2021
+
2022
+ const accountObject = new Account({ redis, account: request.params.account });
2023
+ const deleted = await redis.del(accountObject.getLogKey());
2024
+ request.logger.info({ msg: 'Cleared account logs', account: request.params.account });
2025
+
2026
+ return { deleted: !!deleted };
2027
+ } catch (err) {
2028
+ handleError(request, err);
2029
+ }
2030
+ },
2031
+ options: {
2032
+ description: 'Clear stored logs for an account',
2033
+ notes: 'Removes every stored log entry of the account. Logging continues if it is enabled for the account or the instance.',
2034
+ tags: ['api', 'Logs'],
2035
+
2036
+ auth: {
2037
+ strategy: 'api-token',
2038
+ mode: 'required'
2039
+ },
2040
+ cors: CORS_CONFIG,
2041
+
2042
+ plugins: {
2043
+ openapi: {
2044
+ 'x-ee-impact': IMPACT.DESTRUCTIVE,
2045
+ responses: apiResponses('Returns a deletion marker.', 400, 401, 403, 404, 429, 500)
2046
+ }
2047
+ },
2048
+
2049
+ validate: {
2050
+ options: {
2051
+ stripUnknown: false,
2052
+ abortEarly: false,
2053
+ convert: true
2054
+ },
2055
+ failAction,
2056
+
2057
+ params: Joi.object({
2058
+ account: accountIdSchema.required()
2059
+ }).label('DeleteLogsRequest')
2060
+ },
2061
+
2062
+ response: {
2063
+ schema: Joi.object({
2064
+ deleted: apiBoolean().default(true).description('False when there were no stored log entries to remove')
2065
+ }).label('DeleteLogsResponse'),
2066
+ failAction: 'log'
2067
+ }
2068
+ }
2069
+ });
2070
+ }
2071
+
2072
+ function registerVerifyAccount(server, args) {
2073
+ const { CORS_CONFIG } = args;
1887
2074
 
1888
2075
  server.route({
1889
2076
  method: 'POST',
@@ -1962,6 +2149,10 @@ async function init(args) {
1962
2149
  }
1963
2150
  }
1964
2151
  });
2152
+ }
2153
+
2154
+ function registerGetAutoconfig(server, args) {
2155
+ const { CORS_CONFIG } = args;
1965
2156
 
1966
2157
  server.route({
1967
2158
  method: 'GET',
@@ -2014,6 +2205,10 @@ async function init(args) {
2014
2205
  }
2015
2206
  }
2016
2207
  });
2208
+ }
2209
+
2210
+ function registerPostAutoconfig(server, args) {
2211
+ const { CORS_CONFIG } = args;
2017
2212
 
2018
2213
  server.route({
2019
2214
  method: 'POST',
@@ -2084,4 +2279,26 @@ async function init(args) {
2084
2279
  });
2085
2280
  }
2086
2281
 
2282
+ async function init(args) {
2283
+ const { server } = args;
2284
+
2285
+ registerCreateAccount(server, args);
2286
+ registerUpdateAccount(server, args);
2287
+ registerAccountReconnect(server, args);
2288
+ registerAccountResume(server, args);
2289
+ registerAccountSync(server, args);
2290
+ registerDeleteAccount(server, args);
2291
+ registerAccountFlush(server, args);
2292
+ registerListAccounts(server, args);
2293
+ registerGetAccount(server, args);
2294
+ registerGetAccountOAuthToken(server, args);
2295
+ registerGetServerSignatures(server, args);
2296
+ registerAuthenticationForm(server, args);
2297
+ registerGetLogs(server, args);
2298
+ registerDeleteLogs(server, args);
2299
+ registerVerifyAccount(server, args);
2300
+ registerGetAutoconfig(server, args);
2301
+ registerPostAutoconfig(server, args);
2302
+ }
2303
+
2087
2304
  module.exports = init;
@@ -7,13 +7,13 @@ const { Account } = require('../account');
7
7
  const getSecret = require('../get-secret');
8
8
  const { lists } = require('../lists');
9
9
  const { failAction } = require('../tools');
10
- const { handleError } = require('./route-helpers');
10
+ const { handleError, throwNotFound } = require('./route-helpers');
11
11
  const { accountIdSchema, blocklistListIdSchema, apiResponses, apiBoolean, mailboxAddressSchema } = require('../schemas');
12
12
  const { IMPACT } = require('./operation-impact');
13
13
  const { MCP_MAX_PAGE_SIZE } = require('../consts');
14
14
 
15
- async function init(args) {
16
- const { server, call, CORS_CONFIG } = args;
15
+ function registerListBlocklists(server, args) {
16
+ const { CORS_CONFIG } = args;
17
17
 
18
18
  server.route({
19
19
  method: 'GET',
@@ -90,6 +90,10 @@ async function init(args) {
90
90
  }
91
91
  }
92
92
  });
93
+ }
94
+
95
+ function registerGetBlocklist(server, args) {
96
+ const { CORS_CONFIG } = args;
93
97
 
94
98
  server.route({
95
99
  method: 'GET',
@@ -105,7 +109,7 @@ async function init(args) {
105
109
 
106
110
  options: {
107
111
  description: 'List blocklist entries',
108
- notes: 'List suppressed addresses for a list',
112
+ notes: 'Lists the addresses on a suppression list, one page at a time, with why and when each was added.',
109
113
  tags: ['api', 'Blocklists'],
110
114
 
111
115
  plugins: {
@@ -182,6 +186,10 @@ async function init(args) {
182
186
  }
183
187
  }
184
188
  });
189
+ }
190
+
191
+ function registerAddToBlocklist(server, args) {
192
+ const { call, CORS_CONFIG } = args;
185
193
 
186
194
  server.route({
187
195
  method: 'POST',
@@ -266,6 +274,10 @@ async function init(args) {
266
274
  }
267
275
  }
268
276
  });
277
+ }
278
+
279
+ function registerRemoveFromBlocklist(server, args) {
280
+ const { CORS_CONFIG } = args;
269
281
 
270
282
  server.route({
271
283
  method: 'DELETE',
@@ -339,4 +351,79 @@ async function init(args) {
339
351
  });
340
352
  }
341
353
 
354
+ function registerDeleteBlocklist(server, args) {
355
+ const { CORS_CONFIG } = args;
356
+
357
+ server.route({
358
+ method: 'DELETE',
359
+ path: '/v1/blocklists/{listId}',
360
+
361
+ async handler(request) {
362
+ try {
363
+ if (!(await lists.deleteList(request.params.listId))) {
364
+ throwNotFound('Requested blocklist was not found');
365
+ }
366
+ return { deleted: true };
367
+ } catch (err) {
368
+ handleError(request, err);
369
+ }
370
+ },
371
+ options: {
372
+ description: 'Delete a blocklist',
373
+ notes: 'Deletes a whole suppression list with every address on it. Messages sent with this list ID are delivered to all recipients again.',
374
+ tags: ['api', 'Blocklists'],
375
+
376
+ plugins: {
377
+ mcp: {
378
+ name: 'delete_blocklist',
379
+ title: 'Delete suppression list',
380
+ description:
381
+ 'Delete a whole suppression list with every address on it, so messages sent with that list id reach all recipients again. Confirm with the user before calling this.'
382
+ },
383
+ openapi: {
384
+ 'x-ee-impact': IMPACT.DESTRUCTIVE,
385
+ responses: apiResponses('Returns a deletion marker.', 400, 401, 403, 404, 429, 500)
386
+ }
387
+ },
388
+
389
+ auth: {
390
+ strategy: 'api-token',
391
+ mode: 'required'
392
+ },
393
+ cors: CORS_CONFIG,
394
+
395
+ validate: {
396
+ options: {
397
+ stripUnknown: false,
398
+ abortEarly: false,
399
+ convert: true
400
+ },
401
+ failAction,
402
+
403
+ params: Joi.object({
404
+ listId: blocklistListIdSchema
405
+ }).label('BlocklistListRequest')
406
+ },
407
+
408
+ response: {
409
+ schema: Joi.object({
410
+ deleted: apiBoolean().default(true).description('Was the list deleted')
411
+ }).label('DeleteBlocklistListResponse'),
412
+ failAction: 'log'
413
+ }
414
+ }
415
+ });
416
+ }
417
+
418
+ async function init(args) {
419
+ const { server } = args;
420
+
421
+ registerDeleteBlocklist(server, args);
422
+
423
+ registerListBlocklists(server, args);
424
+ registerGetBlocklist(server, args);
425
+ registerAddToBlocklist(server, args);
426
+ registerRemoveFromBlocklist(server, args);
427
+ }
428
+
342
429
  module.exports = init;
@@ -14,8 +14,8 @@ const BEHAVIOR = require('./behavior-notes');
14
14
  const { handleError } = require('./route-helpers');
15
15
  const { IMPACT } = require('./operation-impact');
16
16
 
17
- async function init(args) {
18
- const { server, call, CORS_CONFIG, SMTP_TEST_HOST } = args;
17
+ function registerCreateDeliveryTest(server, args) {
18
+ const { call, CORS_CONFIG, SMTP_TEST_HOST } = args;
19
19
 
20
20
  server.route({
21
21
  method: 'POST',
@@ -129,6 +129,18 @@ ${now}`,
129
129
  tags: ['api', 'Delivery Test'],
130
130
 
131
131
  plugins: {
132
+ mcp: {
133
+ name: 'create_delivery_test',
134
+ title: 'Start delivery test',
135
+ description:
136
+ "Send a test message from the account to a probe address of EmailEngine's delivery test service, to see how its mail is received: whether it arrives and its SPF, DKIM and DMARC results. " +
137
+ 'Returns a deliveryTest id; check_delivery_test reads the result from it, which takes a minute or so to be ready. check_delivery_test is a management tool, so a credential with mail access alone can start a test but not read it.',
138
+ // Picking an SMTP gateway is left to the REST API, as it is for send_message.
139
+ // Pinned to none rather than just hidden: the handler reads the field off a
140
+ // payload, so the call has to carry one
141
+ omit: ['gateway'],
142
+ force: { gateway: null }
143
+ },
132
144
  openapi: {
133
145
  'x-ee-impact': IMPACT.SENDS,
134
146
  'x-ee-behavior': [BEHAVIOR.BACKGROUND_JOB],
@@ -188,6 +200,10 @@ ${now}`,
188
200
  }
189
201
  }
190
202
  });
203
+ }
204
+
205
+ function registerCheckDeliveryTest(server, args) {
206
+ const { CORS_CONFIG, SMTP_TEST_HOST } = args;
191
207
 
192
208
  server.route({
193
209
  method: 'GET',
@@ -274,7 +290,7 @@ ${now}`,
274
290
  },
275
291
  options: {
276
292
  description: 'Check test status',
277
- notes: 'Check delivery test status',
293
+ notes: 'Returns the result of a delivery test started with the delivery test endpoint: whether the test message arrived, and the authentication results it arrived with.',
278
294
  tags: ['api', 'Delivery Test'],
279
295
 
280
296
  plugins: {
@@ -282,7 +298,7 @@ ${now}`,
282
298
  name: 'check_delivery_test',
283
299
  title: 'Check delivery test',
284
300
  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.'
301
+ 'Check the result of a delivery test started by create_delivery_test or over the REST API: whether the probe message arrived, and its SPF, DKIM and DMARC results.'
286
302
  },
287
303
  openapi: {
288
304
  responses: apiResponses(
@@ -347,4 +363,11 @@ ${now}`,
347
363
  });
348
364
  }
349
365
 
366
+ async function init(args) {
367
+ const { server } = args;
368
+
369
+ registerCreateDeliveryTest(server, args);
370
+ registerCheckDeliveryTest(server, args);
371
+ }
372
+
350
373
  module.exports = init;