emailengine-app 2.85.0 → 2.87.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.
- package/.ncurc.js +24 -6
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +97 -0
- package/DOCKER_DEPLOYMENT.md +2 -1
- package/Dockerfile +16 -3
- package/ENVIRONMENT.md +139 -0
- package/README.md +5 -1
- package/config/default.toml +2 -0
- package/copy-static-files.sh +4 -2
- package/data/google-crawlers.json +1 -1
- package/data/public_suffix_list.dat +4 -3
- package/lib/account-assignment.js +19 -0
- package/lib/account.js +285 -195
- package/lib/api-error-codes.js +49 -0
- package/lib/api-reference/model.js +6 -1
- package/lib/api-routes/account-routes.js +91 -32
- package/lib/api-routes/blocklist-routes.js +68 -2
- package/lib/api-routes/delivery-test-routes.js +1 -1
- package/lib/api-routes/gateway-routes.js +82 -10
- package/lib/api-routes/index.js +4 -0
- package/lib/api-routes/license-routes.js +2 -2
- package/lib/api-routes/mailbox-routes.js +3 -3
- package/lib/api-routes/message-routes.js +15 -7
- package/lib/api-routes/oauth2-app-routes.js +15 -8
- package/lib/api-routes/outbox-routes.js +77 -66
- package/lib/api-routes/permission-map.js +55 -6
- package/lib/api-routes/scoped-routes.js +74 -0
- package/lib/api-routes/settings-routes.js +11 -4
- package/lib/api-routes/stats-routes.js +5 -1
- package/lib/api-routes/submit-routes.js +25 -5
- package/lib/api-routes/template-routes.js +7 -6
- package/lib/api-routes/token-routes.js +11 -5
- package/lib/api-routes/webhook-delivery-routes.js +262 -0
- package/lib/api-routes/webhook-route-routes.js +119 -4
- package/lib/calendar-event.js +81 -1
- package/lib/consts.js +38 -46
- package/lib/db.js +14 -6
- package/lib/delivery-error.js +6 -0
- package/lib/deprecations.js +270 -0
- package/lib/email-client/base-client.js +134 -158
- package/lib/email-client/fallback-poll.js +62 -0
- package/lib/email-client/gmail-client.js +59 -11
- package/lib/email-client/imap/adaptive-idle-store.js +73 -0
- package/lib/email-client/imap/adaptive-idle.js +278 -0
- package/lib/email-client/imap/connection-errors.js +14 -1
- package/lib/email-client/imap/idle-settings.js +31 -5
- package/lib/email-client/imap/listing-diff.js +37 -0
- package/lib/email-client/imap/mailbox.js +380 -227
- package/lib/email-client/imap/subconnection.js +7 -29
- package/lib/email-client/imap/sync-operations.js +220 -127
- package/lib/email-client/imap-client.js +227 -163
- package/lib/email-client/message-builder.js +14 -79
- package/lib/email-client/outlook-client.js +378 -338
- package/lib/email-client/smtp-pool-manager.js +16 -13
- package/lib/email-client/sync-state-fields.js +19 -0
- package/lib/encrypt.js +157 -41
- package/lib/enum-descriptions.js +3 -1
- package/lib/env-setting-overrides.js +288 -0
- package/lib/export-worker.js +751 -0
- package/lib/export.js +64 -15
- package/lib/field-usage.js +1 -1
- package/lib/gateway.js +17 -1
- package/lib/get-raw-email.js +35 -108
- package/lib/health.js +75 -0
- package/lib/lock-run.js +119 -0
- package/lib/logger-consts.js +48 -0
- package/lib/logger.js +1 -1
- package/lib/lua/z-head-scores.lua +28 -0
- package/lib/network-errors.js +1 -1
- package/lib/node-version.js +24 -0
- package/lib/notify-attachments.js +20 -1
- package/lib/oauth/gmail.js +54 -29
- package/lib/oauth2-apps.js +630 -655
- package/lib/otp.js +66 -0
- package/lib/outbox.js +184 -54
- package/lib/parse-message.js +3 -3
- package/lib/privileged-settings.js +2 -2
- package/lib/queue-browser/definitions.js +11 -0
- package/lib/queue-browser/index.js +68 -19
- package/lib/queue-job-actions.js +18 -1
- package/lib/queue-retention.js +48 -12
- package/lib/queue-stats.js +11 -2
- package/lib/read-env-value.js +3 -0
- package/lib/redis-memory-warnings.js +99 -0
- package/lib/redis-reconnect.js +29 -0
- package/lib/request-timing.js +23 -0
- package/lib/respawn-backoff.js +35 -0
- package/lib/rewrite-text-nodes.js +19 -59
- package/lib/schemas.js +225 -41
- package/lib/settings.js +6 -2
- package/lib/smtp-auth.js +19 -1
- package/lib/swagger-options.js +2 -2
- package/lib/thread-diagnostics.js +18 -1
- package/lib/tls/provision.js +6 -3
- package/lib/token-audit-log.js +19 -20
- package/lib/token-permission-view.js +4 -3
- package/lib/tools.js +8 -41
- package/lib/ui-routes/admin-config-routes.js +64 -90
- package/lib/ui-routes/admin-entities-routes.js +2 -14
- package/lib/ui-routes/imap-idle-field.js +1 -1
- package/lib/ui-routes/outlook-subscription-view.js +1 -1
- package/lib/ui-routes/overridable-fields.js +84 -0
- package/lib/ui-routes/queue-routes.js +8 -5
- package/lib/ui-routes/settings-page.js +6 -0
- package/lib/utils/decode-headers.js +3 -12
- package/lib/utils/filter-empty.js +20 -0
- package/lib/utils/int-setting.js +48 -0
- package/lib/utils/tracking-settings.js +35 -0
- package/lib/web-safe-html.js +18 -105
- package/lib/webhook-delivery.js +461 -0
- package/lib/webhook-failures.js +132 -0
- package/lib/webhook-request.js +29 -1
- package/lib/webhook-routing.js +30 -1
- package/lib/webhook-test.js +88 -0
- package/lib/webhooks.js +59 -41
- package/lib/worker-rpc-error.js +2 -1
- package/package.json +28 -26
- package/sbom.json +600 -678
- package/server.js +149 -76
- package/static/css/flyonui.css +1 -1
- package/static/js/ace/ace.js +1 -1
- package/static/js/ee-client.js +650 -196
- package/static/licenses.html +49 -59
- package/translations/messages.pot +26 -26
- package/views/config/security.hbs +22 -0
- package/views/config/service.hbs +44 -0
- package/views/config/webhooks.hbs +36 -0
- package/views/layout/app.hbs +9 -6
- package/views/legal.hbs +8 -0
- package/views/partials/queue_retention_note.hbs +12 -8
- package/views/partials/ui/env-managed-alert.hbs +16 -7
- package/workers/api.js +112 -37
- package/workers/export.js +16 -631
- package/workers/imap.js +13 -0
- package/workers/smtp.js +9 -11
- package/workers/webhooks.js +18 -432
- package/lib/email-client/outlook-fallback-poll.js +0 -30
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Machine-readable `code` values for API error responses whose throw site did not set one.
|
|
4
|
+
// Dependency-free, so workers/api.js and the tests can share it.
|
|
5
|
+
//
|
|
6
|
+
// A 404 used to carry `code: 'NotFound'` only when it came from throwNotFound() or one of the
|
|
7
|
+
// lib-level update() methods. The others - an unknown export, queued message, blocklist entry,
|
|
8
|
+
// account log or account (lib/account.js throws a bare Boom 404) - came back without a code,
|
|
9
|
+
// because handleError() passes Boom errors through untouched, so a client could not branch on
|
|
10
|
+
// `code` for the most common error there is. Filled in once, where the JSON error body is built,
|
|
11
|
+
// so a 404 thrown by any route, now or later, carries it.
|
|
12
|
+
|
|
13
|
+
const DEFAULT_ERROR_CODES = {
|
|
14
|
+
404: 'NotFound'
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Sets the default `code` on an API error payload that has none
|
|
19
|
+
* @param {Object} payload - Boom output payload ({ statusCode, error, message, ... }), modified in place
|
|
20
|
+
* @returns {Object} The same payload
|
|
21
|
+
*/
|
|
22
|
+
function addDefaultErrorCode(payload) {
|
|
23
|
+
if (!payload || typeof payload !== 'object' || payload.code) {
|
|
24
|
+
return payload;
|
|
25
|
+
}
|
|
26
|
+
const code = DEFAULT_ERROR_CODES[payload.statusCode];
|
|
27
|
+
if (code) {
|
|
28
|
+
payload.code = code;
|
|
29
|
+
}
|
|
30
|
+
return payload;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Hapi onPreResponse step that fills in the default code of an error response. Registered by
|
|
35
|
+
* workers/api.js ahead of the handler that renders error pages and JSON errors, and by the route
|
|
36
|
+
* tests' bare servers, so a route test sees the same error body a client does
|
|
37
|
+
* @param {Object} request - Hapi request
|
|
38
|
+
* @param {Object} h - Hapi response toolkit
|
|
39
|
+
* @returns {Symbol} h.continue
|
|
40
|
+
*/
|
|
41
|
+
function errorCodeExt(request, h) {
|
|
42
|
+
const response = request.response;
|
|
43
|
+
if (response && response.isBoom) {
|
|
44
|
+
addDefaultErrorCode(response.output.payload);
|
|
45
|
+
}
|
|
46
|
+
return h.continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = { addDefaultErrorCode, errorCodeExt, DEFAULT_ERROR_CODES };
|
|
@@ -107,6 +107,7 @@ function buildParameter(spec, parameter, operationId) {
|
|
|
107
107
|
in: parameter.in,
|
|
108
108
|
required: !!parameter.required,
|
|
109
109
|
typeLabel: typeLabel(spec, schema),
|
|
110
|
+
description: parameter.description || schema.description,
|
|
110
111
|
descriptionHtml: formatDescription(parameter.description || schema.description),
|
|
111
112
|
usageHtml: formatDescription(schema['x-meta'] && schema['x-meta'].usage),
|
|
112
113
|
constraints: constraintList(schema),
|
|
@@ -156,6 +157,10 @@ function buildParameter(spec, parameter, operationId) {
|
|
|
156
157
|
// looser than that sentence would eventually match a group of undocumented strings and
|
|
157
158
|
// describe it wrongly, having also dropped each member's type, default and anchor. Predicate
|
|
158
159
|
// and prose have to mean the same thing.
|
|
160
|
+
// A description that says no more than the chip sentence does ("Include the `x` setting in the
|
|
161
|
+
// response"), which the settings flags carry for code generators and readers of the raw document
|
|
162
|
+
const INCLUDE_FLAG_DESCRIPTION = /^Include the .+ in the response$/;
|
|
163
|
+
|
|
159
164
|
function flagNames(parameters) {
|
|
160
165
|
if (parameters.length < FLAG_GROUP_MIN) {
|
|
161
166
|
return null;
|
|
@@ -165,7 +170,7 @@ function flagNames(parameters) {
|
|
|
165
170
|
parameter =>
|
|
166
171
|
parameter.typeLabel === 'boolean' &&
|
|
167
172
|
parameter.defaultValue === 'false' &&
|
|
168
|
-
!parameter.descriptionHtml &&
|
|
173
|
+
(!parameter.descriptionHtml || INCLUDE_FLAG_DESCRIPTION.test(parameter.description)) &&
|
|
169
174
|
!parameter.required &&
|
|
170
175
|
!parameter.deprecated &&
|
|
171
176
|
!parameter.enumValues
|
|
@@ -42,7 +42,9 @@ const {
|
|
|
42
42
|
ENUM_DESCRIPTIONS,
|
|
43
43
|
apiBoolean,
|
|
44
44
|
mailboxAddressSchema,
|
|
45
|
-
accountProxySchema
|
|
45
|
+
accountProxySchema,
|
|
46
|
+
verifyResultSchema,
|
|
47
|
+
accountRevocationSchema
|
|
46
48
|
} = require('../schemas');
|
|
47
49
|
|
|
48
50
|
const { REDIS_PREFIX, MAX_FORM_TTL, NONCE_BYTES, MCP_MAX_PAGE_SIZE, OUTLOOK_SYNC_MAX_LOOKBACK } = require('../consts');
|
|
@@ -57,28 +59,6 @@ const accountOauth2ScopesSchema = Joi.array()
|
|
|
57
59
|
.description('OAuth2 scopes granted for this account')
|
|
58
60
|
.label('AccountOauth2Scopes');
|
|
59
61
|
|
|
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
62
|
// The answer autodiscovery gives, shared by GET and POST /v1/autoconfig. One definition rather than
|
|
83
63
|
// two identical inline copies: the OpenAPI converter collapses structurally identical labelled
|
|
84
64
|
// schemas into a single component, so the two routes publish one `DiscoveredEmailSettings` type.
|
|
@@ -871,7 +851,9 @@ function registerDeleteAccount(server, args) {
|
|
|
871
851
|
account: request.params.account,
|
|
872
852
|
call,
|
|
873
853
|
secret: await getSecret(),
|
|
874
|
-
timeout: request.headers['x-ee-timeout']
|
|
854
|
+
timeout: request.headers['x-ee-timeout'],
|
|
855
|
+
// The revocation outcome is logged with this request's id and token
|
|
856
|
+
logger: request.logger
|
|
875
857
|
});
|
|
876
858
|
|
|
877
859
|
try {
|
|
@@ -883,7 +865,7 @@ function registerDeleteAccount(server, args) {
|
|
|
883
865
|
options: {
|
|
884
866
|
description: 'Remove account',
|
|
885
867
|
notes: [
|
|
886
|
-
"Stop processing and clear the account's cache. Pass revoke=true to also attempt revocation of the upstream OAuth2 grant at the provider before the account is removed.",
|
|
868
|
+
"Stop processing and clear the account's cache. Pass revoke=true to also attempt revocation of the upstream OAuth2 grant at the provider before the account is removed; the response then reports the outcome under `revocation`. Pass revoke=required to delete the account only when the grant is gone: when the provider does not confirm the revocation the request fails with code RevocationNotConfirmed (502 when the provider was asked, 409 when it could not be) and the account and its credentials are kept, so the request can be retried.",
|
|
887
869
|
BEHAVIOR.DELETION_SCOPE
|
|
888
870
|
],
|
|
889
871
|
|
|
@@ -894,7 +876,7 @@ function registerDeleteAccount(server, args) {
|
|
|
894
876
|
name: 'delete_account',
|
|
895
877
|
title: 'Delete account',
|
|
896
878
|
description:
|
|
897
|
-
'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.'
|
|
879
|
+
'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, or to "required" to keep the account unless the provider confirms the revocation. Confirm with the user before calling this.'
|
|
898
880
|
},
|
|
899
881
|
openapi: {
|
|
900
882
|
'x-ee-impact': IMPACT.DESTRUCTIVE,
|
|
@@ -930,9 +912,12 @@ function registerDeleteAccount(server, args) {
|
|
|
930
912
|
}),
|
|
931
913
|
|
|
932
914
|
query: Joi.object({
|
|
933
|
-
revoke:
|
|
915
|
+
revoke: Joi.alternatives()
|
|
916
|
+
.try(apiBoolean(), Joi.string().valid('required'))
|
|
934
917
|
.default(false)
|
|
935
|
-
.description(
|
|
918
|
+
.description(
|
|
919
|
+
'Revoke the upstream OAuth2 grant at the provider before deleting the account. `true` deletes the account whatever the outcome, `required` keeps it unless the grant is gone'
|
|
920
|
+
)
|
|
936
921
|
.meta({ usage: FIELD_USAGE.revokeGrant })
|
|
937
922
|
})
|
|
938
923
|
},
|
|
@@ -940,7 +925,8 @@ function registerDeleteAccount(server, args) {
|
|
|
940
925
|
response: {
|
|
941
926
|
schema: Joi.object({
|
|
942
927
|
account: accountIdSchema.required(),
|
|
943
|
-
deleted: apiBoolean().default(true).description('Was the account deleted')
|
|
928
|
+
deleted: apiBoolean().default(true).description('Was the account deleted'),
|
|
929
|
+
revocation: accountRevocationSchema
|
|
944
930
|
}).label('DeleteAccountResponse'),
|
|
945
931
|
failAction: 'log'
|
|
946
932
|
}
|
|
@@ -1073,7 +1059,7 @@ function registerListAccounts(server, args) {
|
|
|
1073
1059
|
|
|
1074
1060
|
options: {
|
|
1075
1061
|
description: 'List accounts',
|
|
1076
|
-
notes: 'Lists registered
|
|
1062
|
+
notes: 'Lists the email accounts registered on this instance, one page at a time, with their connection state.',
|
|
1077
1063
|
tags: ['api', 'Account'],
|
|
1078
1064
|
|
|
1079
1065
|
plugins: {
|
|
@@ -1548,7 +1534,8 @@ function registerGetAccount(server, args) {
|
|
|
1548
1534
|
state: Joi.string()
|
|
1549
1535
|
.valid('creating', 'created', 'renewing', 'error')
|
|
1550
1536
|
.description('Subscription state')
|
|
1551
|
-
.meta({ enumDescriptions: ENUM_DESCRIPTIONS.pubsubState })
|
|
1537
|
+
.meta({ enumDescriptions: ENUM_DESCRIPTIONS.pubsubState })
|
|
1538
|
+
.label('OutlookSubscriptionStateName'),
|
|
1552
1539
|
time: Joi.number().example(1625727994336).description('Timestamp of last state change'),
|
|
1553
1540
|
error: Joi.string()
|
|
1554
1541
|
.allow(null)
|
|
@@ -1559,9 +1546,11 @@ function registerGetAccount(server, args) {
|
|
|
1559
1546
|
})
|
|
1560
1547
|
.unknown()
|
|
1561
1548
|
.description('Current subscription state')
|
|
1549
|
+
.label('OutlookSubscriptionState')
|
|
1562
1550
|
})
|
|
1563
1551
|
.unknown()
|
|
1564
|
-
.description('Microsoft Graph subscription details (Outlook accounts only)')
|
|
1552
|
+
.description('Microsoft Graph subscription details (Outlook accounts only)')
|
|
1553
|
+
.label('OutlookSubscription'),
|
|
1565
1554
|
|
|
1566
1555
|
lastError: lastErrorSchema.allow(null)
|
|
1567
1556
|
}).label('AccountResponse'),
|
|
@@ -1730,6 +1719,12 @@ function registerGetServerSignatures(server, args) {
|
|
|
1730
1719
|
tags: ['api', 'Account'],
|
|
1731
1720
|
|
|
1732
1721
|
plugins: {
|
|
1722
|
+
mcp: {
|
|
1723
|
+
name: 'get_server_signatures',
|
|
1724
|
+
title: 'Get account signatures',
|
|
1725
|
+
description:
|
|
1726
|
+
'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.'
|
|
1727
|
+
},
|
|
1733
1728
|
openapi: {
|
|
1734
1729
|
responses: apiResponses('Returns the signatures configured on the account, as reported by the provider.', 400, 401, 403, 404, 429, 500)
|
|
1735
1730
|
}
|
|
@@ -2018,6 +2013,69 @@ function registerGetLogs(server, args) {
|
|
|
2018
2013
|
});
|
|
2019
2014
|
}
|
|
2020
2015
|
|
|
2016
|
+
function registerDeleteLogs(server, args) {
|
|
2017
|
+
const { CORS_CONFIG } = args;
|
|
2018
|
+
|
|
2019
|
+
server.route({
|
|
2020
|
+
method: 'DELETE',
|
|
2021
|
+
path: '/v1/logs/{account}',
|
|
2022
|
+
|
|
2023
|
+
async handler(request) {
|
|
2024
|
+
try {
|
|
2025
|
+
if (!(await accountExists(redis, request.params.account))) {
|
|
2026
|
+
throw Boom.notFound('Account record was not found for requested ID');
|
|
2027
|
+
}
|
|
2028
|
+
|
|
2029
|
+
const accountObject = new Account({ redis, account: request.params.account });
|
|
2030
|
+
const deleted = await redis.del(accountObject.getLogKey());
|
|
2031
|
+
request.logger.info({ msg: 'Cleared account logs', account: request.params.account });
|
|
2032
|
+
|
|
2033
|
+
return { deleted: !!deleted };
|
|
2034
|
+
} catch (err) {
|
|
2035
|
+
handleError(request, err);
|
|
2036
|
+
}
|
|
2037
|
+
},
|
|
2038
|
+
options: {
|
|
2039
|
+
description: 'Clear stored logs for an account',
|
|
2040
|
+
notes: 'Removes every stored log entry of the account. Logging continues if it is enabled for the account or the instance.',
|
|
2041
|
+
tags: ['api', 'Logs'],
|
|
2042
|
+
|
|
2043
|
+
auth: {
|
|
2044
|
+
strategy: 'api-token',
|
|
2045
|
+
mode: 'required'
|
|
2046
|
+
},
|
|
2047
|
+
cors: CORS_CONFIG,
|
|
2048
|
+
|
|
2049
|
+
plugins: {
|
|
2050
|
+
openapi: {
|
|
2051
|
+
'x-ee-impact': IMPACT.DESTRUCTIVE,
|
|
2052
|
+
responses: apiResponses('Returns a deletion marker.', 400, 401, 403, 404, 429, 500)
|
|
2053
|
+
}
|
|
2054
|
+
},
|
|
2055
|
+
|
|
2056
|
+
validate: {
|
|
2057
|
+
options: {
|
|
2058
|
+
stripUnknown: false,
|
|
2059
|
+
abortEarly: false,
|
|
2060
|
+
convert: true
|
|
2061
|
+
},
|
|
2062
|
+
failAction,
|
|
2063
|
+
|
|
2064
|
+
params: Joi.object({
|
|
2065
|
+
account: accountIdSchema.required()
|
|
2066
|
+
}).label('DeleteLogsRequest')
|
|
2067
|
+
},
|
|
2068
|
+
|
|
2069
|
+
response: {
|
|
2070
|
+
schema: Joi.object({
|
|
2071
|
+
deleted: apiBoolean().default(true).description('False when there were no stored log entries to remove')
|
|
2072
|
+
}).label('DeleteLogsResponse'),
|
|
2073
|
+
failAction: 'log'
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
});
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2021
2079
|
function registerVerifyAccount(server, args) {
|
|
2022
2080
|
const { CORS_CONFIG } = args;
|
|
2023
2081
|
|
|
@@ -2244,6 +2302,7 @@ async function init(args) {
|
|
|
2244
2302
|
registerGetServerSignatures(server, args);
|
|
2245
2303
|
registerAuthenticationForm(server, args);
|
|
2246
2304
|
registerGetLogs(server, args);
|
|
2305
|
+
registerDeleteLogs(server, args);
|
|
2247
2306
|
registerVerifyAccount(server, args);
|
|
2248
2307
|
registerGetAutoconfig(server, args);
|
|
2249
2308
|
registerPostAutoconfig(server, args);
|
|
@@ -7,7 +7,7 @@ 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');
|
|
@@ -109,7 +109,7 @@ function registerGetBlocklist(server, args) {
|
|
|
109
109
|
|
|
110
110
|
options: {
|
|
111
111
|
description: 'List blocklist entries',
|
|
112
|
-
notes: '
|
|
112
|
+
notes: 'Lists the addresses on a suppression list, one page at a time, with why and when each was added.',
|
|
113
113
|
tags: ['api', 'Blocklists'],
|
|
114
114
|
|
|
115
115
|
plugins: {
|
|
@@ -351,9 +351,75 @@ function registerRemoveFromBlocklist(server, args) {
|
|
|
351
351
|
});
|
|
352
352
|
}
|
|
353
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
|
+
|
|
354
418
|
async function init(args) {
|
|
355
419
|
const { server } = args;
|
|
356
420
|
|
|
421
|
+
registerDeleteBlocklist(server, args);
|
|
422
|
+
|
|
357
423
|
registerListBlocklists(server, args);
|
|
358
424
|
registerGetBlocklist(server, args);
|
|
359
425
|
registerAddToBlocklist(server, args);
|
|
@@ -290,7 +290,7 @@ function registerCheckDeliveryTest(server, args) {
|
|
|
290
290
|
},
|
|
291
291
|
options: {
|
|
292
292
|
description: 'Check test status',
|
|
293
|
-
notes: '
|
|
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.',
|
|
294
294
|
tags: ['api', 'Delivery Test'],
|
|
295
295
|
|
|
296
296
|
plugins: {
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const Joi = require('joi');
|
|
4
4
|
const { redis } = require('../db');
|
|
5
|
-
const { Gateway } = require('../gateway');
|
|
5
|
+
const { Gateway, gatewaySmtpConfig } = require('../gateway');
|
|
6
6
|
const getSecret = require('../get-secret');
|
|
7
|
-
const { failAction } = require('../tools');
|
|
7
|
+
const { failAction, verifyAccountInfo } = require('../tools');
|
|
8
8
|
const { handleError, maskSecrets, MASKED, MASK_NOTE } = require('./route-helpers');
|
|
9
|
-
const { apiResponses, apiBoolean, formBoolean, requireTlsSchema } = require('../schemas');
|
|
9
|
+
const { apiResponses, apiBoolean, formBoolean, requireTlsSchema, verifyResultSchema, listQuerySchema } = require('../schemas');
|
|
10
10
|
const { ENUM_DESCRIPTIONS } = require('../enum-descriptions');
|
|
11
11
|
const { IMPACT } = require('./operation-impact');
|
|
12
12
|
const { MCP_MAX_PAGE_SIZE } = require('../consts');
|
|
@@ -18,7 +18,7 @@ const gatewayRequireTlsSchema = requireTlsSchema('GatewayRequireTLS', formBoolea
|
|
|
18
18
|
|
|
19
19
|
const gatewayLastErrorSchema = Joi.object({
|
|
20
20
|
created: Joi.number().integer().example(1623868624153).description('Timestamp of the error as milliseconds from epoch'),
|
|
21
|
-
status: Joi.string().valid('error').example('error').description('Status of the last delivery attempt'),
|
|
21
|
+
status: Joi.string().valid('error').example('error').description('Status of the last delivery attempt').label('GatewayErrorStatus'),
|
|
22
22
|
response: Joi.string().example('535 Authentication failed').description('SMTP server response for the failed delivery'),
|
|
23
23
|
responseCode: Joi.number().integer().example(535).description('SMTP response code'),
|
|
24
24
|
code: Joi.string().example('EAUTH').description('Error type identifier'),
|
|
@@ -46,7 +46,7 @@ function registerListGateways(server, args) {
|
|
|
46
46
|
try {
|
|
47
47
|
let gatewayObject = new Gateway({ redis, gateway: request.params.gateway, call, secret: await getSecret() });
|
|
48
48
|
|
|
49
|
-
const listing = await gatewayObject.listGateways(request.query.page, request.query.pageSize);
|
|
49
|
+
const listing = await gatewayObject.listGateways(request.query.page, request.query.pageSize, request.query.query);
|
|
50
50
|
|
|
51
51
|
for (const entry of listing.gateways || []) {
|
|
52
52
|
maskSecrets(entry);
|
|
@@ -60,7 +60,7 @@ function registerListGateways(server, args) {
|
|
|
60
60
|
|
|
61
61
|
options: {
|
|
62
62
|
description: 'List gateways',
|
|
63
|
-
notes: 'Lists
|
|
63
|
+
notes: 'Lists the stored SMTP gateways, one page at a time, with their delivery counters and last error. Passwords are not included.',
|
|
64
64
|
tags: ['api', 'SMTP Gateway'],
|
|
65
65
|
|
|
66
66
|
plugins: {
|
|
@@ -99,7 +99,8 @@ function registerListGateways(server, args) {
|
|
|
99
99
|
.example(0)
|
|
100
100
|
.description('Page number (zero indexed, so use 0 for first page)')
|
|
101
101
|
.label('PageNumber'),
|
|
102
|
-
pageSize: Joi.number().integer().min(1).max(1000).default(20).example(20).description('How many entries per page').label('PageSize')
|
|
102
|
+
pageSize: Joi.number().integer().min(1).max(1000).default(20).example(20).description('How many entries per page').label('PageSize'),
|
|
103
|
+
query: listQuerySchema('gateway ID, name, host or username', 'GatewaysListQuery')
|
|
103
104
|
}).label('GatewaysFilter')
|
|
104
105
|
},
|
|
105
106
|
|
|
@@ -272,7 +273,7 @@ function registerCreateGateway(server, args) {
|
|
|
272
273
|
|
|
273
274
|
options: {
|
|
274
275
|
description: 'Register new gateway',
|
|
275
|
-
notes: '
|
|
276
|
+
notes: "Stores an SMTP relay that messages can be sent through instead of the account's own SMTP server, by naming it as `gateway` when submitting.",
|
|
276
277
|
tags: ['api', 'SMTP Gateway'],
|
|
277
278
|
|
|
278
279
|
plugins: {
|
|
@@ -378,7 +379,7 @@ function registerUpdateGateway(server, args) {
|
|
|
378
379
|
},
|
|
379
380
|
options: {
|
|
380
381
|
description: 'Update gateway info',
|
|
381
|
-
notes: '
|
|
382
|
+
notes: 'Changes the stored settings of an SMTP gateway. Fields left out of the request keep their stored values, the password included.',
|
|
382
383
|
tags: ['api', 'SMTP Gateway'],
|
|
383
384
|
|
|
384
385
|
plugins: {
|
|
@@ -471,7 +472,7 @@ function registerDeleteGateway(server, args) {
|
|
|
471
472
|
},
|
|
472
473
|
options: {
|
|
473
474
|
description: 'Remove SMTP gateway',
|
|
474
|
-
notes: '
|
|
475
|
+
notes: 'Deletes a stored SMTP gateway. Messages queued for it fail to deliver.',
|
|
475
476
|
tags: ['api', 'SMTP Gateway'],
|
|
476
477
|
|
|
477
478
|
plugins: {
|
|
@@ -516,6 +517,76 @@ function registerDeleteGateway(server, args) {
|
|
|
516
517
|
});
|
|
517
518
|
}
|
|
518
519
|
|
|
520
|
+
function registerVerifyGateway(server, args) {
|
|
521
|
+
const { CORS_CONFIG } = args;
|
|
522
|
+
|
|
523
|
+
server.route({
|
|
524
|
+
method: 'POST',
|
|
525
|
+
path: '/v1/gateway/{gateway}/verify',
|
|
526
|
+
|
|
527
|
+
async handler(request) {
|
|
528
|
+
try {
|
|
529
|
+
let gatewayObject = new Gateway({ redis, gateway: request.params.gateway, secret: await getSecret() });
|
|
530
|
+
let gatewayData = await gatewayObject.loadGatewayData();
|
|
531
|
+
|
|
532
|
+
// Only ever with the stored settings: the stored password goes to the host it was
|
|
533
|
+
// stored for, and nowhere a request could name
|
|
534
|
+
let verifyResult = await verifyAccountInfo(
|
|
535
|
+
redis,
|
|
536
|
+
{ smtp: gatewaySmtpConfig(gatewayData) },
|
|
537
|
+
request.logger.child({ gateway: request.params.gateway, action: 'verify-gateway' })
|
|
538
|
+
);
|
|
539
|
+
|
|
540
|
+
return verifyResult.smtp;
|
|
541
|
+
} catch (err) {
|
|
542
|
+
handleError(request, err);
|
|
543
|
+
}
|
|
544
|
+
},
|
|
545
|
+
options: {
|
|
546
|
+
description: 'Verify SMTP gateway',
|
|
547
|
+
notes: 'Connects to the SMTP server of a stored gateway with its stored settings and credentials, and reports whether the connection and the authentication succeeded. Nothing is sent and nothing is stored.',
|
|
548
|
+
tags: ['api', 'SMTP Gateway'],
|
|
549
|
+
|
|
550
|
+
plugins: {
|
|
551
|
+
mcp: {
|
|
552
|
+
name: 'verify_gateway',
|
|
553
|
+
title: 'Check SMTP gateway',
|
|
554
|
+
description:
|
|
555
|
+
'Check that a stored SMTP gateway still connects and authenticates, with its stored settings and credentials. Nothing is sent or changed. Use it when deliveries through the gateway fail.'
|
|
556
|
+
},
|
|
557
|
+
openapi: {
|
|
558
|
+
'x-ee-impact': IMPACT.READONLY,
|
|
559
|
+
responses: apiResponses('Returns the result of the connection check.', 400, 401, 403, 404, 429, 500)
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
|
|
563
|
+
auth: {
|
|
564
|
+
strategy: 'api-token',
|
|
565
|
+
mode: 'required'
|
|
566
|
+
},
|
|
567
|
+
cors: CORS_CONFIG,
|
|
568
|
+
|
|
569
|
+
validate: {
|
|
570
|
+
options: {
|
|
571
|
+
stripUnknown: false,
|
|
572
|
+
abortEarly: false,
|
|
573
|
+
convert: true
|
|
574
|
+
},
|
|
575
|
+
failAction,
|
|
576
|
+
|
|
577
|
+
params: Joi.object({
|
|
578
|
+
gateway: Joi.string().max(256).required().example('example').description('Gateway ID')
|
|
579
|
+
}).label('VerifyGatewayRequest')
|
|
580
|
+
},
|
|
581
|
+
|
|
582
|
+
response: {
|
|
583
|
+
schema: verifyResultSchema('Smtp', '535 Authentication failed'),
|
|
584
|
+
failAction: 'log'
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
|
|
519
590
|
async function init(args) {
|
|
520
591
|
const { server } = args;
|
|
521
592
|
|
|
@@ -524,6 +595,7 @@ async function init(args) {
|
|
|
524
595
|
registerCreateGateway(server, args);
|
|
525
596
|
registerUpdateGateway(server, args);
|
|
526
597
|
registerDeleteGateway(server, args);
|
|
598
|
+
registerVerifyGateway(server, args);
|
|
527
599
|
}
|
|
528
600
|
|
|
529
601
|
module.exports = init;
|
package/lib/api-routes/index.js
CHANGED
|
@@ -24,6 +24,7 @@ const statsRoutes = require('./stats-routes');
|
|
|
24
24
|
const licenseRoutes = require('./license-routes');
|
|
25
25
|
const outboxRoutes = require('./outbox-routes');
|
|
26
26
|
const webhookRouteRoutes = require('./webhook-route-routes');
|
|
27
|
+
const webhookDeliveryRoutes = require('./webhook-delivery-routes');
|
|
27
28
|
const oauth2AppRoutes = require('./oauth2-app-routes');
|
|
28
29
|
const gatewayRoutes = require('./gateway-routes');
|
|
29
30
|
const deliveryTestRoutes = require('./delivery-test-routes');
|
|
@@ -130,6 +131,9 @@ async function registerApiRoutes(args) {
|
|
|
130
131
|
// setup webhook route management routes
|
|
131
132
|
await webhookRouteRoutes({ server, CORS_CONFIG });
|
|
132
133
|
|
|
134
|
+
// setup failed webhook delivery routes
|
|
135
|
+
await webhookDeliveryRoutes({ server, CORS_CONFIG });
|
|
136
|
+
|
|
133
137
|
// setup OAuth2 application routes
|
|
134
138
|
await oauth2AppRoutes({ server, call, CORS_CONFIG, OAuth2ProviderSchema });
|
|
135
139
|
|
|
@@ -28,7 +28,7 @@ async function init(args) {
|
|
|
28
28
|
},
|
|
29
29
|
options: {
|
|
30
30
|
description: 'Request license info',
|
|
31
|
-
notes: '
|
|
31
|
+
notes: 'Returns the license this instance runs with: whether one is active, who it was issued to and when it expires.',
|
|
32
32
|
tags: ['api', 'License'],
|
|
33
33
|
|
|
34
34
|
plugins: {
|
|
@@ -74,7 +74,7 @@ async function init(args) {
|
|
|
74
74
|
},
|
|
75
75
|
options: {
|
|
76
76
|
description: 'Remove license',
|
|
77
|
-
notes: '
|
|
77
|
+
notes: 'Removes the active license. The instance continues without one.',
|
|
78
78
|
tags: ['api', 'License'],
|
|
79
79
|
|
|
80
80
|
plugins: {
|
|
@@ -75,7 +75,7 @@ function registerListMailboxes(server, args) {
|
|
|
75
75
|
|
|
76
76
|
options: {
|
|
77
77
|
description: 'List mailboxes',
|
|
78
|
-
notes: 'Lists
|
|
78
|
+
notes: 'Lists every folder of the account with its path, special-use flag and subscription state, and optionally its message counters.',
|
|
79
79
|
tags: ['api', 'Mailbox'],
|
|
80
80
|
|
|
81
81
|
plugins: {
|
|
@@ -157,7 +157,7 @@ function registerCreateMailbox(server, args) {
|
|
|
157
157
|
|
|
158
158
|
options: {
|
|
159
159
|
description: 'Create mailbox',
|
|
160
|
-
notes: '
|
|
160
|
+
notes: 'Creates a folder at the given path, a missing parent folder included. The path can be given as a list of names, which the server joins with its own separator.',
|
|
161
161
|
tags: ['api', 'Mailbox'],
|
|
162
162
|
|
|
163
163
|
plugins: {
|
|
@@ -333,7 +333,7 @@ function registerDeleteMailbox(server, args) {
|
|
|
333
333
|
|
|
334
334
|
options: {
|
|
335
335
|
description: 'Delete mailbox',
|
|
336
|
-
notes: '
|
|
336
|
+
notes: 'Deletes a folder together with every message in it.',
|
|
337
337
|
tags: ['api', 'Mailbox'],
|
|
338
338
|
|
|
339
339
|
plugins: {
|