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.
- package/.ncurc.js +29 -9
- package/.prettierignore +5 -1
- package/.prettierrc.js +2 -0
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +107 -0
- package/Dockerfile +20 -1
- package/ENVIRONMENT.md +139 -0
- package/README.md +2 -2
- package/bin/emailengine.js +434 -408
- package/config/default.toml +2 -0
- package/copy-static-files.sh +41 -14
- package/data/google-crawlers.json +1 -1
- package/data/public_suffix_list.dat +16563 -0
- package/eslint.config.js +81 -99
- package/lib/account-assignment.js +19 -0
- package/lib/account.js +230 -170
- package/lib/api-error-codes.js +49 -0
- package/lib/api-reference/format.js +4 -3
- package/lib/api-reference/model.js +6 -1
- package/lib/api-routes/account-routes.js +255 -38
- package/lib/api-routes/blocklist-routes.js +91 -4
- package/lib/api-routes/delivery-test-routes.js +27 -4
- package/lib/api-routes/export-routes.js +28 -2
- package/lib/api-routes/gateway-routes.js +110 -12
- package/lib/api-routes/index.js +4 -0
- package/lib/api-routes/license-routes.js +2 -2
- package/lib/api-routes/mailbox-routes.js +44 -5
- package/lib/api-routes/message-routes.js +112 -10
- package/lib/api-routes/oauth2-app-routes.js +63 -23
- package/lib/api-routes/outbox-routes.js +97 -52
- package/lib/api-routes/permission-map.js +67 -7
- package/lib/api-routes/scoped-routes.js +74 -0
- package/lib/api-routes/settings-routes.js +34 -6
- package/lib/api-routes/stats-routes.js +5 -1
- package/lib/api-routes/submit-routes.js +337 -309
- package/lib/api-routes/template-routes.js +45 -8
- package/lib/api-routes/token-routes.js +152 -100
- package/lib/api-routes/webhook-delivery-routes.js +262 -0
- package/lib/api-routes/webhook-route-routes.js +132 -6
- package/lib/bounce-detect.js +397 -205
- package/lib/calendar-event.js +81 -1
- package/lib/consts.js +38 -45
- 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 +137 -184
- package/lib/email-client/fallback-poll.js +62 -0
- package/lib/email-client/gmail-client.js +60 -22
- 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 +372 -242
- package/lib/email-client/imap/subconnection.js +8 -30
- package/lib/email-client/imap/sync-operations.js +220 -127
- package/lib/email-client/imap-client.js +228 -164
- package/lib/email-client/message-builder.js +14 -79
- package/lib/email-client/notification-handler.js +1 -2
- package/lib/email-client/outlook-client.js +372 -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/gateway.js +19 -4
- package/lib/get-raw-email.js +25 -107
- package/lib/hapi-request-logger.js +107 -0
- package/lib/health.js +75 -0
- package/lib/imapproxy/imap-core/README.md +6 -5
- 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/mcp/tools.js +37 -8
- package/lib/network-errors.js +1 -1
- package/lib/node-version.js +24 -0
- package/lib/notify-attachments.js +36 -0
- package/lib/oauth/outlook-mailbox.js +35 -0
- package/lib/oauth/state.js +24 -0
- package/lib/oauth2-apps.js +631 -656
- package/lib/outbox.js +184 -54
- package/lib/parse-message.js +3 -3
- package/lib/pbkdf2-phc.js +1 -1
- 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 +164 -40
- package/lib/settings.js +6 -2
- package/lib/smtp-auth.js +19 -1
- package/lib/sso.js +1 -1
- package/lib/swagger-options.js +1 -1
- package/lib/thread-diagnostics.js +63 -0
- package/lib/timezones.js +109 -0
- package/lib/tls/provision.js +6 -3
- package/lib/token-audit-log.js +19 -20
- package/lib/token-permission-view.js +7 -6
- package/lib/tools.js +48 -51
- package/lib/totp.js +2 -5
- package/lib/translations.js +1 -2
- package/lib/ui-routes/account-routes.js +475 -454
- package/lib/ui-routes/account-setup.js +99 -0
- package/lib/ui-routes/admin-config-routes.js +152 -100
- package/lib/ui-routes/admin-entities-routes.js +93 -21
- package/lib/ui-routes/auth-routes.js +90 -38
- package/lib/ui-routes/imap-idle-field.js +1 -1
- package/lib/ui-routes/internals-routes.js +5 -0
- package/lib/ui-routes/oauth-config-routes.js +124 -82
- 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/route-helpers.js +19 -3
- package/lib/ui-routes/settings-page.js +6 -0
- package/lib/ui-routes/tls-config-routes.js +58 -15
- package/lib/utils/back-off.js +82 -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/murmurhash3.js +66 -0
- package/lib/utils/public-suffix.js +122 -0
- package/lib/utils/random-id.js +26 -0
- package/lib/utils/tracking-settings.js +35 -0
- package/lib/utils/version.js +74 -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 +56 -0
- package/lib/webhook-test.js +88 -0
- package/lib/webhooks.js +93 -45
- package/lib/worker-rpc-error.js +2 -1
- package/package.json +37 -38
- package/sbom.json +7902 -1
- package/server.js +784 -518
- package/static/js/ace/ace.js +1 -1
- package/static/licenses.html +225 -1060
- package/translations/messages.pot +62 -63
- package/views/config/ai.hbs +1 -1
- package/views/config/security.hbs +24 -2
- package/views/config/service.hbs +47 -0
- package/views/config/webhooks.hbs +36 -0
- package/views/internals/index.hbs +8 -0
- package/views/partials/queue_retention_note.hbs +12 -8
- package/views/partials/ui/env-managed-alert.hbs +16 -7
- package/views/partials/webhook_form.hbs +1 -1
- package/views/suppression-lists/index.hbs +1 -1
- package/workers/api.js +840 -611
- package/workers/export.js +17 -632
- package/workers/imap.js +13 -0
- package/workers/smtp.js +9 -11
- package/workers/submit.js +1 -1
- package/workers/webhooks.js +18 -448
- package/lib/email-client/outlook-fallback-poll.js +0 -30
|
@@ -1,34 +1,45 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const Boom = require('@hapi/boom');
|
|
4
3
|
const Joi = require('joi');
|
|
5
4
|
const logger = require('../logger');
|
|
6
5
|
const outbox = require('../outbox');
|
|
7
6
|
const { failAction } = require('../tools');
|
|
8
|
-
const { handleError, maskSecrets, MASK_NOTE } = require('./route-helpers');
|
|
9
|
-
|
|
7
|
+
const { handleError, maskSecrets, MASK_NOTE, throwNotFound } = require('./route-helpers');
|
|
8
|
+
|
|
9
|
+
// What every per-message route answers for an unknown queue ID, and on the account routes for the
|
|
10
|
+
// queue ID of another account's message. The state refusals the outbox module throws (code
|
|
11
|
+
// NotFailed, ContentGone, NotDelayed) carry a 409 of their own
|
|
12
|
+
const QUEUE_ENTRY_NOT_FOUND = 'Requested queue entry was not found';
|
|
13
|
+
const { outboxEntrySchema, accountIdSchema, apiResponses, apiBoolean } = require('../schemas');
|
|
14
|
+
const { routeScopes, routeParams, scopedLabel, mcpFor, pagingQuery } = require('./scoped-routes');
|
|
10
15
|
const { IMPACT } = require('./operation-impact');
|
|
11
16
|
const { MCP_MAX_PAGE_SIZE } = require('../consts');
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
// Every outbox route exists twice, for the instance and for one account (see scoped-routes.js), so
|
|
19
|
+
// a bound credential cannot act on another account's message by its queue ID
|
|
20
|
+
const SCOPES = routeScopes({ instance: '/v1/outbox', account: '/v1/account/{account}/outbox' });
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
const outboxStateSchema = Joi.string()
|
|
23
|
+
.valid(...outbox.JOB_STATES)
|
|
24
|
+
.example('failed')
|
|
25
|
+
.description('List only messages in this state')
|
|
26
|
+
.label('OutboxStateFilter');
|
|
20
27
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
function registerListOutbox(server, ctx, scope) {
|
|
29
|
+
const { CORS_CONFIG } = ctx;
|
|
30
|
+
|
|
31
|
+
const query = Object.assign(pagingQuery(), { state: outboxStateSchema });
|
|
32
|
+
if (scope.isInstance) {
|
|
33
|
+
query.account = accountIdSchema.description('List only messages queued by this account');
|
|
34
|
+
}
|
|
24
35
|
|
|
25
36
|
server.route({
|
|
26
37
|
method: 'GET',
|
|
27
|
-
path:
|
|
38
|
+
path: scope.prefix,
|
|
28
39
|
|
|
29
40
|
async handler(request) {
|
|
30
41
|
try {
|
|
31
|
-
const listing = await outbox.list(Object.assign({ logger }, request.query));
|
|
42
|
+
const listing = await outbox.list(Object.assign({ logger }, request.query, request.params.account ? { account: request.params.account } : {}));
|
|
32
43
|
|
|
33
44
|
// A queue entry carries the proxy the submission was told to use, and a failed one
|
|
34
45
|
// also records the route it took under progress.networkRouting
|
|
@@ -43,17 +54,19 @@ async function init(args) {
|
|
|
43
54
|
},
|
|
44
55
|
|
|
45
56
|
options: {
|
|
46
|
-
description: 'List queued messages',
|
|
47
|
-
notes:
|
|
57
|
+
description: scope.isInstance ? 'List queued messages' : 'List queued messages of an account',
|
|
58
|
+
notes: scope.isInstance
|
|
59
|
+
? `Lists messages in the Outbox. With \`account\` set, only the messages that account has queued are listed, the same as the account outbox endpoint. ${MASK_NOTE}`
|
|
60
|
+
: `Lists the messages an account has in the Outbox: scheduled and waiting messages, those being delivered, and failed messages whose content is still stored for a retry. Reachable with an access token bound to the account. ${MASK_NOTE}`,
|
|
48
61
|
tags: ['api', 'Outbox'],
|
|
49
62
|
|
|
50
63
|
plugins: {
|
|
51
|
-
mcp: {
|
|
64
|
+
mcp: mcpFor(scope, {
|
|
52
65
|
name: 'get_outbox',
|
|
53
66
|
title: 'List outbox',
|
|
54
67
|
description: 'List messages queued for delivery, paged, including scheduled sends and their delivery progress.',
|
|
55
68
|
bounds: { pageSize: MCP_MAX_PAGE_SIZE }
|
|
56
|
-
},
|
|
69
|
+
}),
|
|
57
70
|
openapi: {
|
|
58
71
|
responses: apiResponses('Returns the messages currently queued for delivery.', 400, 401, 403, 429, 500)
|
|
59
72
|
}
|
|
@@ -73,17 +86,8 @@ async function init(args) {
|
|
|
73
86
|
},
|
|
74
87
|
failAction,
|
|
75
88
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
.integer()
|
|
79
|
-
.min(0)
|
|
80
|
-
.max(1024 * 1024)
|
|
81
|
-
.default(0)
|
|
82
|
-
.example(0)
|
|
83
|
-
.description('Page number (zero indexed, so use 0 for first page)')
|
|
84
|
-
.label('PageNumber'),
|
|
85
|
-
pageSize: Joi.number().integer().min(1).max(1000).default(20).example(20).description('How many entries per page').label('PageSize')
|
|
86
|
-
}).label('OutbixListFilter')
|
|
89
|
+
params: routeParams(scope),
|
|
90
|
+
query: Joi.object(query).label(scopedLabel(scope, 'OutboxListFilter'))
|
|
87
91
|
},
|
|
88
92
|
|
|
89
93
|
response: {
|
|
@@ -98,16 +102,20 @@ async function init(args) {
|
|
|
98
102
|
}
|
|
99
103
|
}
|
|
100
104
|
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function registerGetOutboxEntry(server, ctx, scope) {
|
|
108
|
+
const { CORS_CONFIG, queueIdParam } = ctx;
|
|
101
109
|
|
|
102
110
|
server.route({
|
|
103
111
|
method: 'GET',
|
|
104
|
-
path:
|
|
112
|
+
path: `${scope.prefix}/{queueId}`,
|
|
105
113
|
|
|
106
114
|
async handler(request) {
|
|
107
115
|
try {
|
|
108
|
-
let outboxEntry = await outbox.get({ queueId: request.params.queueId, logger });
|
|
116
|
+
let outboxEntry = await outbox.get({ queueId: request.params.queueId, account: request.params.account, logger });
|
|
109
117
|
if (!outboxEntry) {
|
|
110
|
-
|
|
118
|
+
throwNotFound(QUEUE_ENTRY_NOT_FOUND);
|
|
111
119
|
}
|
|
112
120
|
return maskSecrets(outboxEntry);
|
|
113
121
|
} catch (err) {
|
|
@@ -121,6 +129,12 @@ async function init(args) {
|
|
|
121
129
|
tags: ['api', 'Outbox'],
|
|
122
130
|
|
|
123
131
|
plugins: {
|
|
132
|
+
mcp: mcpFor(scope, {
|
|
133
|
+
name: 'get_queued_message',
|
|
134
|
+
title: 'Get queued message',
|
|
135
|
+
description:
|
|
136
|
+
'Get one message in the sending queue by the queue id that send_message, send_draft or get_outbox returned: its recipients, scheduled time, delivery attempts and the last delivery error.'
|
|
137
|
+
}),
|
|
124
138
|
openapi: {
|
|
125
139
|
responses: apiResponses('Returns the queued message, including its delivery attempts and last error.', 400, 401, 403, 404, 429, 500)
|
|
126
140
|
}
|
|
@@ -140,7 +154,7 @@ async function init(args) {
|
|
|
140
154
|
},
|
|
141
155
|
failAction,
|
|
142
156
|
|
|
143
|
-
params:
|
|
157
|
+
params: routeParams(scope, queueIdParam).label(scopedLabel(scope, 'OutboxEntryParams'))
|
|
144
158
|
},
|
|
145
159
|
|
|
146
160
|
response: {
|
|
@@ -149,16 +163,20 @@ async function init(args) {
|
|
|
149
163
|
}
|
|
150
164
|
}
|
|
151
165
|
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function registerRetryOutboxEntry(server, ctx, scope) {
|
|
169
|
+
const { CORS_CONFIG, queueIdParam } = ctx;
|
|
152
170
|
|
|
153
171
|
server.route({
|
|
154
172
|
method: 'POST',
|
|
155
|
-
path:
|
|
173
|
+
path: `${scope.prefix}/{queueId}/retry`,
|
|
156
174
|
|
|
157
175
|
async handler(request) {
|
|
158
176
|
try {
|
|
159
|
-
let result = await outbox.retry({ queueId: request.params.queueId, logger });
|
|
177
|
+
let result = await outbox.retry({ queueId: request.params.queueId, account: request.params.account, logger });
|
|
160
178
|
if (!result) {
|
|
161
|
-
|
|
179
|
+
throwNotFound(QUEUE_ENTRY_NOT_FOUND);
|
|
162
180
|
}
|
|
163
181
|
return result;
|
|
164
182
|
} catch (err) {
|
|
@@ -167,16 +185,16 @@ async function init(args) {
|
|
|
167
185
|
},
|
|
168
186
|
options: {
|
|
169
187
|
description: 'Retry a failed message',
|
|
170
|
-
notes: 'Puts a message whose delivery failed for good back into the queue with a fresh set of delivery attempts. Only a failed message whose content is still stored can be retried: the content of the most recent failures is kept for this, within the bounds set by EENGINE_QUEUE_KEEP_FAILED_CONTENT and EENGINE_QUEUE_KEEP_FAILED_CONTENT_SIZE. A message that cannot be retried answers 409 with `code` NotFailed (the message is not in the failed state) or ContentGone (its content is no longer stored).',
|
|
188
|
+
notes: 'Puts a message whose delivery failed for good back into the queue with a fresh set of delivery attempts. Only a failed message whose content is still stored can be retried: the content of the most recent failures is kept for this, within the bounds set by the queueKeepFailedContent and queueKeepFailedContentSize settings (or EENGINE_QUEUE_KEEP_FAILED_CONTENT and EENGINE_QUEUE_KEEP_FAILED_CONTENT_SIZE, which win when set). A message that cannot be retried answers 409 with `code` NotFailed (the message is not in the failed state) or ContentGone (its content is no longer stored).',
|
|
171
189
|
tags: ['api', 'Outbox'],
|
|
172
190
|
|
|
173
191
|
plugins: {
|
|
174
|
-
mcp: {
|
|
192
|
+
mcp: mcpFor(scope, {
|
|
175
193
|
name: 'retry_queued_message',
|
|
176
194
|
title: 'Retry failed message',
|
|
177
195
|
description:
|
|
178
196
|
'Retry a message whose delivery failed for good, by the queue id from get_outbox. Only a message in the failed state whose content is still stored can be retried; the error says when it cannot. A retried message starts over with a full set of delivery attempts.'
|
|
179
|
-
},
|
|
197
|
+
}),
|
|
180
198
|
openapi: {
|
|
181
199
|
responses: apiResponses('Returns a retry marker. The message is waiting for a delivery attempt again.', 400, 401, 403, 404, 409, 429, 500)
|
|
182
200
|
}
|
|
@@ -196,7 +214,7 @@ async function init(args) {
|
|
|
196
214
|
},
|
|
197
215
|
failAction,
|
|
198
216
|
|
|
199
|
-
params:
|
|
217
|
+
params: routeParams(scope, queueIdParam).label(scopedLabel(scope, 'OutboxEntryParams'))
|
|
200
218
|
},
|
|
201
219
|
|
|
202
220
|
response: {
|
|
@@ -209,16 +227,20 @@ async function init(args) {
|
|
|
209
227
|
}
|
|
210
228
|
}
|
|
211
229
|
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function registerPromoteOutboxEntry(server, ctx, scope) {
|
|
233
|
+
const { CORS_CONFIG, queueIdParam } = ctx;
|
|
212
234
|
|
|
213
235
|
server.route({
|
|
214
236
|
method: 'POST',
|
|
215
|
-
path:
|
|
237
|
+
path: `${scope.prefix}/{queueId}/promote`,
|
|
216
238
|
|
|
217
239
|
async handler(request) {
|
|
218
240
|
try {
|
|
219
|
-
let result = await outbox.promote({ queueId: request.params.queueId, logger });
|
|
241
|
+
let result = await outbox.promote({ queueId: request.params.queueId, account: request.params.account, logger });
|
|
220
242
|
if (!result) {
|
|
221
|
-
|
|
243
|
+
throwNotFound(QUEUE_ENTRY_NOT_FOUND);
|
|
222
244
|
}
|
|
223
245
|
return result;
|
|
224
246
|
} catch (err) {
|
|
@@ -231,12 +253,12 @@ async function init(args) {
|
|
|
231
253
|
tags: ['api', 'Outbox'],
|
|
232
254
|
|
|
233
255
|
plugins: {
|
|
234
|
-
mcp: {
|
|
256
|
+
mcp: mcpFor(scope, {
|
|
235
257
|
name: 'send_queued_message_now',
|
|
236
258
|
title: 'Send queued message now',
|
|
237
259
|
description:
|
|
238
260
|
'Deliver a queued message at the next opportunity instead of waiting for its scheduled time or for the backoff before its next attempt, by the queue id from get_outbox. Only a message in the delayed state can be promoted.'
|
|
239
|
-
},
|
|
261
|
+
}),
|
|
240
262
|
openapi: {
|
|
241
263
|
responses: apiResponses('Returns a promotion marker. The message is waiting for a delivery attempt.', 400, 401, 403, 404, 409, 429, 500)
|
|
242
264
|
}
|
|
@@ -256,7 +278,7 @@ async function init(args) {
|
|
|
256
278
|
},
|
|
257
279
|
failAction,
|
|
258
280
|
|
|
259
|
-
params:
|
|
281
|
+
params: routeParams(scope, queueIdParam).label(scopedLabel(scope, 'OutboxEntryParams'))
|
|
260
282
|
},
|
|
261
283
|
|
|
262
284
|
response: {
|
|
@@ -269,30 +291,34 @@ async function init(args) {
|
|
|
269
291
|
}
|
|
270
292
|
}
|
|
271
293
|
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function registerDeleteOutboxEntry(server, ctx, scope) {
|
|
297
|
+
const { CORS_CONFIG, queueIdParam } = ctx;
|
|
272
298
|
|
|
273
299
|
server.route({
|
|
274
300
|
method: 'DELETE',
|
|
275
|
-
path:
|
|
301
|
+
path: `${scope.prefix}/{queueId}`,
|
|
276
302
|
|
|
277
303
|
async handler(request) {
|
|
278
304
|
try {
|
|
279
|
-
return await outbox.del({ queueId: request.params.queueId, logger });
|
|
305
|
+
return await outbox.del({ queueId: request.params.queueId, account: request.params.account, logger });
|
|
280
306
|
} catch (err) {
|
|
281
307
|
handleError(request, err);
|
|
282
308
|
}
|
|
283
309
|
},
|
|
284
310
|
options: {
|
|
285
311
|
description: 'Remove a message',
|
|
286
|
-
notes: '
|
|
312
|
+
notes: 'Removes a queued message together with its stored content, so it is not sent. A message whose delivery attempt is running right now is not removed and is reported as locked.',
|
|
287
313
|
tags: ['api', 'Outbox'],
|
|
288
314
|
|
|
289
315
|
plugins: {
|
|
290
|
-
mcp: {
|
|
316
|
+
mcp: mcpFor(scope, {
|
|
291
317
|
name: 'cancel_queued_message',
|
|
292
318
|
title: 'Cancel queued message',
|
|
293
319
|
description:
|
|
294
320
|
'Cancel a message waiting in the sending queue, by the queue id from get_outbox. A message already handed to the mail server cannot be cancelled.'
|
|
295
|
-
},
|
|
321
|
+
}),
|
|
296
322
|
openapi: {
|
|
297
323
|
'x-ee-impact': IMPACT.DESTRUCTIVE,
|
|
298
324
|
responses: apiResponses('Returns a deletion marker. A message already being delivered cannot be removed.', 400, 401, 403, 429, 500)
|
|
@@ -313,7 +339,7 @@ async function init(args) {
|
|
|
313
339
|
},
|
|
314
340
|
failAction,
|
|
315
341
|
|
|
316
|
-
params:
|
|
342
|
+
params: routeParams(scope, queueIdParam).label(scopedLabel(scope, 'OutboxEntryParams'))
|
|
317
343
|
},
|
|
318
344
|
|
|
319
345
|
response: {
|
|
@@ -331,4 +357,23 @@ async function init(args) {
|
|
|
331
357
|
});
|
|
332
358
|
}
|
|
333
359
|
|
|
360
|
+
async function init(args) {
|
|
361
|
+
const { server, CORS_CONFIG } = args;
|
|
362
|
+
|
|
363
|
+
// The queue ID of a message, as every per-message outbox route takes it
|
|
364
|
+
const queueIdParam = {
|
|
365
|
+
queueId: Joi.string().max(100).example('d41f0423195f271f').description('Queue identifier for scheduled email').required()
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
const ctx = { CORS_CONFIG, queueIdParam };
|
|
369
|
+
|
|
370
|
+
for (const scope of SCOPES.all) {
|
|
371
|
+
registerListOutbox(server, ctx, scope);
|
|
372
|
+
registerGetOutboxEntry(server, ctx, scope);
|
|
373
|
+
registerRetryOutboxEntry(server, ctx, scope);
|
|
374
|
+
registerPromoteOutboxEntry(server, ctx, scope);
|
|
375
|
+
registerDeleteOutboxEntry(server, ctx, scope);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
334
379
|
module.exports = init;
|
|
@@ -126,6 +126,13 @@ const GROUP = {
|
|
|
126
126
|
// in ADMIN, because a token that can mint tokens can widen itself.
|
|
127
127
|
TOKEN: 'token',
|
|
128
128
|
|
|
129
|
+
// The webhook deliveries that failed for good: list, retry, remove. Its own group rather than
|
|
130
|
+
// part of `webhook` because a listing names what each failed event was about (the account, the
|
|
131
|
+
// folder, the message) across every account, which no `webhook` grant ever exposed: that group
|
|
132
|
+
// covered reading the route definitions and nothing more. A new group, so it is reachable only
|
|
133
|
+
// by a record that names it, never through IMPLICIT_GROUPS.
|
|
134
|
+
WEBHOOK_DELIVERIES: 'webhook-deliveries',
|
|
135
|
+
|
|
129
136
|
// Adding accounts and gateways, and reconfiguring them, including where they connect. Its own
|
|
130
137
|
// group rather than a write on `account` or `gateway` because both records keep their stored
|
|
131
138
|
// credential across a partial update, so a change to nothing but `host` makes the next
|
|
@@ -215,7 +222,14 @@ const SURFACE_GRANTS = {
|
|
|
215
222
|
{ action: ACTION.DESTRUCTIVE, group: GROUP.MESSAGE },
|
|
216
223
|
{ action: ACTION.SEND, group: GROUP.SUBMIT },
|
|
217
224
|
{ action: ACTION.READ, group: GROUP.OUTBOX },
|
|
218
|
-
{ action: ACTION.READ, group: GROUP.TEMPLATE }
|
|
225
|
+
{ action: ACTION.READ, group: GROUP.TEMPLATE },
|
|
226
|
+
// Folder create and rename (the Mail agent level) and folder delete (Full access), added
|
|
227
|
+
// 2026-10-20 by explicit operator decision. Unlike the pairs above, these widened tokens
|
|
228
|
+
// already issued: an mcp-scoped token without a permissions record is bounded by this
|
|
229
|
+
// table alone, and those - including every one minted from the "Full access" consent in
|
|
230
|
+
// 2.79.2 to 2.80.0 - gained folder create, rename and delete with them
|
|
231
|
+
{ action: ACTION.WRITE, group: GROUP.MAILBOX },
|
|
232
|
+
{ action: ACTION.DESTRUCTIVE, group: GROUP.MAILBOX }
|
|
219
233
|
],
|
|
220
234
|
|
|
221
235
|
// The management half of the MCP endpoint: the same door, checked per request the same way,
|
|
@@ -261,7 +275,12 @@ const SURFACE_GRANTS = {
|
|
|
261
275
|
{ action: ACTION.WRITE, group: GROUP.OUTBOX },
|
|
262
276
|
{ action: ACTION.DESTRUCTIVE, group: GROUP.OUTBOX },
|
|
263
277
|
{ action: ACTION.READ, group: GROUP.DIAGNOSTICS },
|
|
264
|
-
{ action: ACTION.READ, group: GROUP.LOGS }
|
|
278
|
+
{ action: ACTION.READ, group: GROUP.LOGS },
|
|
279
|
+
// The webhook deliveries that failed for good: listing them is observing the queues, a
|
|
280
|
+
// retry operates them, a removal is a deletion, the same three steps as the outbox above
|
|
281
|
+
{ action: ACTION.READ, group: GROUP.WEBHOOK_DELIVERIES },
|
|
282
|
+
{ action: ACTION.WRITE, group: GROUP.WEBHOOK_DELIVERIES },
|
|
283
|
+
{ action: ACTION.DESTRUCTIVE, group: GROUP.WEBHOOK_DELIVERIES }
|
|
265
284
|
]
|
|
266
285
|
};
|
|
267
286
|
|
|
@@ -428,6 +447,10 @@ const GROUP_ROUTES = {
|
|
|
428
447
|
'DELETE /v1/account/{account}',
|
|
429
448
|
'PUT /v1/account/{account}/flush',
|
|
430
449
|
'PUT /v1/account/{account}/reconnect',
|
|
450
|
+
// Lifts the auth-failure park and reconnects: operating the connection like the reconnect
|
|
451
|
+
// above, and no more than that - it never touches the stored credentials or where they
|
|
452
|
+
// are sent, and an operator's own send-only switch is not lifted by it
|
|
453
|
+
'PUT /v1/account/{account}/resume',
|
|
431
454
|
'PUT /v1/account/{account}/sync',
|
|
432
455
|
'GET /v1/account/{account}/server-signatures'
|
|
433
456
|
],
|
|
@@ -468,7 +491,14 @@ const GROUP_ROUTES = {
|
|
|
468
491
|
'GET /v1/outbox/{queueId}',
|
|
469
492
|
'POST /v1/outbox/{queueId}/retry',
|
|
470
493
|
'POST /v1/outbox/{queueId}/promote',
|
|
471
|
-
'DELETE /v1/outbox/{queueId}'
|
|
494
|
+
'DELETE /v1/outbox/{queueId}',
|
|
495
|
+
// The same five for one account, reachable with a token bound to it. Each queue ID has to
|
|
496
|
+
// belong to the account in the path, so they reach a subset of what the five above do
|
|
497
|
+
'GET /v1/account/{account}/outbox',
|
|
498
|
+
'GET /v1/account/{account}/outbox/{queueId}',
|
|
499
|
+
'POST /v1/account/{account}/outbox/{queueId}/retry',
|
|
500
|
+
'POST /v1/account/{account}/outbox/{queueId}/promote',
|
|
501
|
+
'DELETE /v1/account/{account}/outbox/{queueId}'
|
|
472
502
|
],
|
|
473
503
|
|
|
474
504
|
[GROUP.EXPORT]: [
|
|
@@ -488,14 +518,34 @@ const GROUP_ROUTES = {
|
|
|
488
518
|
'DELETE /v1/templates/account/{account}'
|
|
489
519
|
],
|
|
490
520
|
|
|
491
|
-
[GROUP.BLOCKLIST]: [
|
|
521
|
+
[GROUP.BLOCKLIST]: [
|
|
522
|
+
'GET /v1/blocklists',
|
|
523
|
+
'GET /v1/blocklist/{listId}',
|
|
524
|
+
'POST /v1/blocklist/{listId}',
|
|
525
|
+
'DELETE /v1/blocklist/{listId}',
|
|
526
|
+
// The whole list at once, which the entry removal above already reaches one address at a time
|
|
527
|
+
'DELETE /v1/blocklists/{listId}'
|
|
528
|
+
],
|
|
492
529
|
|
|
493
|
-
[GROUP.WEBHOOK]: [
|
|
530
|
+
[GROUP.WEBHOOK]: [
|
|
531
|
+
'GET /v1/webhookRoutes',
|
|
532
|
+
'GET /v1/webhookRoutes/webhookRoute/{webhookRoute}',
|
|
533
|
+
// Posts a test event to a configured target. The target is never taken from the request
|
|
534
|
+
// and never echoed back, so it reveals and redirects nothing
|
|
535
|
+
'POST /v1/webhooks/test'
|
|
536
|
+
],
|
|
494
537
|
|
|
495
538
|
// Reading a gateway and removing one. The two WRITES are in PROVISIONING below, because they
|
|
496
539
|
// can redirect where the stored relay credentials are sent - so they are deliberately absent
|
|
497
540
|
// here rather than listed in both places.
|
|
498
|
-
[GROUP.GATEWAY]: [
|
|
541
|
+
[GROUP.GATEWAY]: [
|
|
542
|
+
'GET /v1/gateways',
|
|
543
|
+
'GET /v1/gateway/{gateway}',
|
|
544
|
+
'DELETE /v1/gateway/{gateway}',
|
|
545
|
+
// A connection check with the stored settings only, a read: it sends the stored credential
|
|
546
|
+
// to the host it was stored for and nowhere the request could name
|
|
547
|
+
'POST /v1/gateway/{gateway}/verify'
|
|
548
|
+
],
|
|
499
549
|
|
|
500
550
|
[GROUP.EVENTS]: ['GET /v1/changes'],
|
|
501
551
|
|
|
@@ -512,7 +562,7 @@ const GROUP_ROUTES = {
|
|
|
512
562
|
'GET /metrics'
|
|
513
563
|
],
|
|
514
564
|
|
|
515
|
-
[GROUP.LOGS]: ['GET /v1/logs/{account}'],
|
|
565
|
+
[GROUP.LOGS]: ['GET /v1/logs/{account}', 'DELETE /v1/logs/{account}'],
|
|
516
566
|
|
|
517
567
|
// The five groups below used to be the admin block. They were split out so an agent that
|
|
518
568
|
// manages the instance can hold them, and each went to a NEW group rather than into one that
|
|
@@ -534,6 +584,16 @@ const GROUP_ROUTES = {
|
|
|
534
584
|
|
|
535
585
|
[GROUP.LICENSE]: ['GET /v1/license', 'POST /v1/license', 'DELETE /v1/license'],
|
|
536
586
|
|
|
587
|
+
[GROUP.WEBHOOK_DELIVERIES]: [
|
|
588
|
+
'GET /v1/webhooks/failed',
|
|
589
|
+
'POST /v1/webhooks/failed/{delivery}/retry',
|
|
590
|
+
'DELETE /v1/webhooks/failed/{delivery}',
|
|
591
|
+
// The same three for one account, reachable with a token bound to it
|
|
592
|
+
'GET /v1/account/{account}/webhooks/failed',
|
|
593
|
+
'POST /v1/account/{account}/webhooks/failed/{delivery}/retry',
|
|
594
|
+
'DELETE /v1/account/{account}/webhooks/failed/{delivery}'
|
|
595
|
+
],
|
|
596
|
+
|
|
537
597
|
// Everything about tokens except minting one, which is under ADMIN
|
|
538
598
|
[GROUP.TOKEN]: [
|
|
539
599
|
'GET /v1/tokens',
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Routes that exist twice: once for the whole instance, and once for one account under
|
|
4
|
+
// /v1/account/{account}/... The account form is what an account-bound access token can reach - its
|
|
5
|
+
// path names the account, which is what the api-token strategy checks the binding against - and
|
|
6
|
+
// every ID it is given has to belong to that account. The MCP tools stay on the instance form: the
|
|
7
|
+
// account form does the same thing for a narrower caller. Shared by the outbox and the failed
|
|
8
|
+
// webhook delivery routes, so a third pair does not start from a copy of either.
|
|
9
|
+
|
|
10
|
+
const Joi = require('joi');
|
|
11
|
+
const { accountIdSchema } = require('../schemas');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {Object} prefixes
|
|
15
|
+
* @param {string} prefixes.instance - Path prefix of the instance form
|
|
16
|
+
* @param {string} prefixes.account - Path prefix of the account form, with an {account} parameter
|
|
17
|
+
* @returns {{ instance: Object, account: Object, all: Object[] }} The two scopes
|
|
18
|
+
*/
|
|
19
|
+
function routeScopes(prefixes) {
|
|
20
|
+
const instance = { prefix: prefixes.instance, params: {}, mcp: true, isInstance: true, labelPrefix: '' };
|
|
21
|
+
const account = { prefix: prefixes.account, params: { account: accountIdSchema.required() }, mcp: false, isInstance: false, labelPrefix: 'Account' };
|
|
22
|
+
return { instance, account, all: [instance, account] };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Path parameter schema of a scoped route
|
|
27
|
+
* @param {Object} scope - From routeScopes()
|
|
28
|
+
* @param {Object} [extra] - Parameters of the route itself
|
|
29
|
+
* @returns {Object|undefined} A joi object, or undefined for a route without parameters
|
|
30
|
+
*/
|
|
31
|
+
function routeParams(scope, extra) {
|
|
32
|
+
const keys = Object.assign({}, scope.params, extra || {});
|
|
33
|
+
return Object.keys(keys).length ? Joi.object(keys) : undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A schema label, prefixed with Account on the account form so the two forms name distinct types
|
|
38
|
+
* @param {Object} scope - From routeScopes()
|
|
39
|
+
* @param {string} label - The instance form's label
|
|
40
|
+
* @returns {string}
|
|
41
|
+
*/
|
|
42
|
+
function scopedLabel(scope, label) {
|
|
43
|
+
return scope.labelPrefix + label;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The route's MCP tool block, on the instance form only
|
|
48
|
+
* @param {Object} scope - From routeScopes()
|
|
49
|
+
* @param {Object} definition - The plugins.mcp block
|
|
50
|
+
* @returns {Object|undefined}
|
|
51
|
+
*/
|
|
52
|
+
function mcpFor(scope, definition) {
|
|
53
|
+
return scope.mcp ? definition : undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The page and pageSize query parameters of a paged listing
|
|
58
|
+
* @returns {Object} joi keys
|
|
59
|
+
*/
|
|
60
|
+
function pagingQuery() {
|
|
61
|
+
return {
|
|
62
|
+
page: Joi.number()
|
|
63
|
+
.integer()
|
|
64
|
+
.min(0)
|
|
65
|
+
.max(1024 * 1024)
|
|
66
|
+
.default(0)
|
|
67
|
+
.example(0)
|
|
68
|
+
.description('Page number (zero indexed, so use 0 for first page)')
|
|
69
|
+
.label('PageNumber'),
|
|
70
|
+
pageSize: Joi.number().integer().min(1).max(1000).default(20).example(20).description('How many entries per page').label('PageSize')
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = { routeScopes, routeParams, scopedLabel, mcpFor, pagingQuery };
|
|
@@ -8,6 +8,7 @@ const consts = require('../consts');
|
|
|
8
8
|
const { failAction, maybeReloadTlsCertificates, TLS_MATERIAL_SETTINGS } = require('../tools');
|
|
9
9
|
const { tlsSettingChanged } = require('../tls/store');
|
|
10
10
|
const { queueStats } = require('../queue-stats');
|
|
11
|
+
const { isOverridableSetting, storeOverridableSetting } = require('../env-setting-overrides');
|
|
11
12
|
const Boom = require('@hapi/boom');
|
|
12
13
|
const { handleError, maskSecrets, containsMaskedSecret, isMaskedRoundTrip, assertNoPrivilegedSettings, MASKED } = require('./route-helpers');
|
|
13
14
|
const { settingsSchema, settingsQuerySchema, isHiddenSetting, apiResponses, ENUM_DESCRIPTIONS } = require('../schemas');
|
|
@@ -25,7 +26,7 @@ for (let key of Object.keys(settingsSchema)) {
|
|
|
25
26
|
} else {
|
|
26
27
|
// Use a distinct label for the nullable response variant, otherwise the generated
|
|
27
28
|
// OpenAPI spec would contain suffixed duplicates of the request-side components
|
|
28
|
-
settingsOutputSchema[key] = settingsSchema[key].allow(null).label(
|
|
29
|
+
settingsOutputSchema[key] = settingsSchema[key].allow(null).label(`Setting${key.charAt(0).toUpperCase()}${key.slice(1)}`);
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
settingsOutputSchema.eventTypes = Joi.array()
|
|
@@ -43,8 +44,8 @@ settingsOutputSchema.eventTypes = Joi.array()
|
|
|
43
44
|
// agree.
|
|
44
45
|
const MCP_SETTINGS_KEYS = Object.keys(settingsSchema).filter(key => !settings.privilegedKeys.includes(key) && !isHiddenSetting(key));
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
const {
|
|
47
|
+
function registerGetSettings(server, args) {
|
|
48
|
+
const { CORS_CONFIG } = args;
|
|
48
49
|
|
|
49
50
|
server.route({
|
|
50
51
|
method: 'GET',
|
|
@@ -135,6 +136,10 @@ async function init(args) {
|
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
138
|
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function registerUpdateSettings(server, args) {
|
|
142
|
+
const { call, notify, CORS_CONFIG } = args;
|
|
138
143
|
|
|
139
144
|
server.route({
|
|
140
145
|
method: 'POST',
|
|
@@ -175,7 +180,13 @@ async function init(args) {
|
|
|
175
180
|
tlsChanged.push(key);
|
|
176
181
|
}
|
|
177
182
|
|
|
178
|
-
|
|
183
|
+
if (isOverridableSetting(key)) {
|
|
184
|
+
// null clears the setting so its environment variable or default applies
|
|
185
|
+
// again; settings.set() would have stored the null
|
|
186
|
+
await storeOverridableSetting(key, value);
|
|
187
|
+
} else {
|
|
188
|
+
await settings.set(key, value);
|
|
189
|
+
}
|
|
179
190
|
applied[key] = value;
|
|
180
191
|
}
|
|
181
192
|
} catch (err) {
|
|
@@ -256,6 +267,10 @@ async function init(args) {
|
|
|
256
267
|
}
|
|
257
268
|
}
|
|
258
269
|
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function registerGetQueueSettings(server, args) {
|
|
273
|
+
const { CORS_CONFIG } = args;
|
|
259
274
|
|
|
260
275
|
server.route({
|
|
261
276
|
method: 'GET',
|
|
@@ -295,7 +310,7 @@ async function init(args) {
|
|
|
295
310
|
},
|
|
296
311
|
options: {
|
|
297
312
|
description: 'Show queue information',
|
|
298
|
-
notes: '
|
|
313
|
+
notes: 'Returns how many jobs a queue holds in each state and whether it is paused.',
|
|
299
314
|
tags: ['api', 'Settings'],
|
|
300
315
|
|
|
301
316
|
plugins: {
|
|
@@ -360,6 +375,10 @@ async function init(args) {
|
|
|
360
375
|
}
|
|
361
376
|
}
|
|
362
377
|
});
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function registerUpdateQueueSettings(server, args) {
|
|
381
|
+
const { CORS_CONFIG } = args;
|
|
363
382
|
|
|
364
383
|
server.route({
|
|
365
384
|
method: 'PUT',
|
|
@@ -396,7 +415,7 @@ async function init(args) {
|
|
|
396
415
|
},
|
|
397
416
|
options: {
|
|
398
417
|
description: 'Set queue settings',
|
|
399
|
-
notes: '
|
|
418
|
+
notes: 'Pauses or resumes a queue. A paused queue keeps accepting jobs, the workers stop taking them until it is resumed.',
|
|
400
419
|
tags: ['api', 'Settings'],
|
|
401
420
|
|
|
402
421
|
plugins: {
|
|
@@ -452,4 +471,13 @@ async function init(args) {
|
|
|
452
471
|
});
|
|
453
472
|
}
|
|
454
473
|
|
|
474
|
+
async function init(args) {
|
|
475
|
+
const { server } = args;
|
|
476
|
+
|
|
477
|
+
registerGetSettings(server, args);
|
|
478
|
+
registerUpdateSettings(server, args);
|
|
479
|
+
registerGetQueueSettings(server, args);
|
|
480
|
+
registerUpdateQueueSettings(server, args);
|
|
481
|
+
}
|
|
482
|
+
|
|
455
483
|
module.exports = init;
|
|
@@ -27,6 +27,7 @@ async function init(args) {
|
|
|
27
27
|
|
|
28
28
|
options: {
|
|
29
29
|
description: 'Return server stats',
|
|
30
|
+
notes: 'Returns the running version and license, how many accounts are in each connection state, message and webhook counters for the last `seconds`, and the Redis server details with any warnings about how Redis is configured.',
|
|
30
31
|
tags: ['api', 'Stats'],
|
|
31
32
|
|
|
32
33
|
plugins: {
|
|
@@ -85,7 +86,10 @@ async function init(args) {
|
|
|
85
86
|
key: Joi.string().example('maxmemory-policy').description('Warning identifier'),
|
|
86
87
|
color: Joi.string().example('warning').description('Severity indicator'),
|
|
87
88
|
title: Joi.string().example('Unsafe Redis eviction policy').description('Warning title'),
|
|
88
|
-
details: Joi.array()
|
|
89
|
+
details: Joi.array()
|
|
90
|
+
.items(Joi.string().example('maxmemory-policy is allkeys-lru'))
|
|
91
|
+
.description('Warning details')
|
|
92
|
+
.label('RedisWarningDetails')
|
|
89
93
|
})
|
|
90
94
|
.unknown()
|
|
91
95
|
.label('RedisWarningEntry')
|