emailengine-app 2.85.0 → 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 +24 -6
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +74 -0
- package/Dockerfile +14 -1
- package/ENVIRONMENT.md +139 -0
- package/README.md +1 -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 +194 -165
- package/lib/api-error-codes.js +49 -0
- package/lib/api-reference/model.js +6 -1
- package/lib/api-routes/account-routes.js +78 -26
- 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 +4 -3
- 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 +130 -156
- package/lib/email-client/fallback-poll.js +62 -0
- package/lib/email-client/gmail-client.js +51 -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 +372 -226
- 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 +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 +17 -1
- package/lib/get-raw-email.js +25 -107
- 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/oauth2-apps.js +630 -655
- 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 +163 -39
- package/lib/settings.js +6 -2
- package/lib/smtp-auth.js +19 -1
- 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 +54 -41
- package/lib/worker-rpc-error.js +2 -1
- package/package.json +21 -20
- package/sbom.json +304 -382
- package/server.js +149 -76
- package/static/js/ace/ace.js +1 -1
- package/static/licenses.html +21 -31
- 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/partials/queue_retention_note.hbs +12 -8
- package/views/partials/ui/env-managed-alert.hbs +16 -7
- package/workers/api.js +102 -28
- 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,132 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// The webhook deliveries that failed for good, for the REST API: list them, put one back into the
|
|
4
|
+
// queue, or remove it. The admin queue browser (lib/queue-browser) offers the same over the whole
|
|
5
|
+
// notify queue; this is the failed set only, in the shape an integrator replaying the events a
|
|
6
|
+
// receiver outage cost it needs, and optionally held to one account so a token bound to that
|
|
7
|
+
// account reaches only its own deliveries.
|
|
8
|
+
//
|
|
9
|
+
// A listing carries what a delivery was about (event, account, folder, message, the route that
|
|
10
|
+
// sent it and why it failed), never the event payload itself, which can hold up to notifyTextSize
|
|
11
|
+
// of message text.
|
|
12
|
+
|
|
13
|
+
const { notifyQueue } = require('./db');
|
|
14
|
+
const { QUEUES_BY_NAME, listJobs } = require('./queue-browser');
|
|
15
|
+
const { retryFailedJob, assertJobState, getAccountJob } = require('./queue-job-actions');
|
|
16
|
+
const { statusError } = require('./utils/status-error');
|
|
17
|
+
|
|
18
|
+
const NOTIFY_QUEUE = QUEUES_BY_NAME.get('notify');
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The API form of a failed delivery, from the queue browser's formatted entry
|
|
22
|
+
* @param {Object} entry - Entry from listJobs()
|
|
23
|
+
* @returns {Object}
|
|
24
|
+
*/
|
|
25
|
+
function formatFailedDelivery(entry) {
|
|
26
|
+
return {
|
|
27
|
+
id: entry.id,
|
|
28
|
+
event: entry.event,
|
|
29
|
+
eventId: entry.eventId,
|
|
30
|
+
account: entry.account,
|
|
31
|
+
path: entry.path,
|
|
32
|
+
messageId: entry.messageId,
|
|
33
|
+
route: entry.routeId ? { id: entry.routeId, name: entry.routeName || null } : null,
|
|
34
|
+
created: entry.created,
|
|
35
|
+
failed: entry.finishedOn,
|
|
36
|
+
attemptsMade: entry.attemptsMade,
|
|
37
|
+
attempts: entry.attempts,
|
|
38
|
+
error: entry.failure
|
|
39
|
+
? {
|
|
40
|
+
message: entry.failure.reason,
|
|
41
|
+
code: entry.failure.code,
|
|
42
|
+
statusCode: entry.failure.statusCode,
|
|
43
|
+
permanent: entry.failure.permanent
|
|
44
|
+
}
|
|
45
|
+
: null
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* One page of failed deliveries, most recent first. With an account the failed set is scanned from
|
|
51
|
+
* its head for that account's deliveries, as far as the queue browser scans a filtered listing, and
|
|
52
|
+
* the result says when the scan stopped short of the end.
|
|
53
|
+
*
|
|
54
|
+
* @param {Object} options
|
|
55
|
+
* @param {string} [options.account] - Only deliveries of this account
|
|
56
|
+
* @param {number} [options.page] - Zero-based page
|
|
57
|
+
* @param {number} [options.pageSize] - Entries per page
|
|
58
|
+
* @param {Object} options.logger - Logger instance
|
|
59
|
+
* @returns {Promise<Object>} `{ total, page, pages, scanLimited, deliveries }`
|
|
60
|
+
*/
|
|
61
|
+
async function list(options) {
|
|
62
|
+
const result = await listJobs({
|
|
63
|
+
queue: NOTIFY_QUEUE,
|
|
64
|
+
state: 'failed',
|
|
65
|
+
page: options.page,
|
|
66
|
+
pageSize: options.pageSize,
|
|
67
|
+
account: options.account,
|
|
68
|
+
logger: options.logger
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
total: result.total,
|
|
73
|
+
page: result.page,
|
|
74
|
+
pages: result.total ? result.pages : 0,
|
|
75
|
+
scanLimited: result.scanLimited,
|
|
76
|
+
deliveries: result.entries.map(formatFailedDelivery)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Puts a failed delivery back into the queue with a fresh set of attempts.
|
|
82
|
+
*
|
|
83
|
+
* @param {Object} options
|
|
84
|
+
* @param {string} options.id - Job ID
|
|
85
|
+
* @param {string} [options.account] - Account the delivery has to belong to
|
|
86
|
+
* @param {Object} options.logger - Logger instance
|
|
87
|
+
* @returns {Promise<Object|false>} `{ retried: true, id }`, or false when there is no such delivery
|
|
88
|
+
* @throws {Error} 409 NotFailed when the delivery is not in the failed state
|
|
89
|
+
*/
|
|
90
|
+
async function retry(options) {
|
|
91
|
+
const job = await getAccountJob(notifyQueue, options.id, options.account);
|
|
92
|
+
if (!job) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
await assertJobState(job, 'failed', NOTIFY_QUEUE.noun, 'retried');
|
|
97
|
+
await retryFailedJob(job, NOTIFY_QUEUE.noun);
|
|
98
|
+
|
|
99
|
+
options.logger.info({ msg: 'Retrying failed webhook delivery', job: job.id, event: job.name, account: job.data && job.data.account });
|
|
100
|
+
return { retried: true, id: String(job.id) };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Removes a failed delivery from the queue.
|
|
105
|
+
*
|
|
106
|
+
* @param {Object} options
|
|
107
|
+
* @param {string} options.id - Job ID
|
|
108
|
+
* @param {string} [options.account] - Account the delivery has to belong to
|
|
109
|
+
* @param {Object} options.logger - Logger instance
|
|
110
|
+
* @returns {Promise<Object|false>} `{ deleted: true, id }`, or false when there is no such delivery
|
|
111
|
+
* @throws {Error} 409 NotFailed when the delivery is not in the failed state
|
|
112
|
+
*/
|
|
113
|
+
async function del(options) {
|
|
114
|
+
const job = await getAccountJob(notifyQueue, options.id, options.account);
|
|
115
|
+
if (!job) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
await assertJobState(job, 'failed', NOTIFY_QUEUE.noun, 'removed');
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
await job.remove();
|
|
123
|
+
} catch (err) {
|
|
124
|
+
// retried and picked up by a worker between the check and the removal
|
|
125
|
+
throw statusError('The webhook delivery is being processed and cannot be removed', 'Locked', 409);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
options.logger.info({ msg: 'Removed failed webhook delivery', job: job.id, event: job.name, account: job.data && job.data.account });
|
|
129
|
+
return { deleted: true, id: String(job.id) };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
module.exports = { list, retry, del, formatFailedDelivery };
|
package/lib/webhook-request.js
CHANGED
|
@@ -1,8 +1,36 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { createHmac } = require('crypto');
|
|
4
|
+
const packageData = require('../package.json');
|
|
3
5
|
const { DEFAULT_WEBHOOK_REQUEST_TIMEOUT } = require('./consts');
|
|
4
6
|
const { readBodyCapped } = require('./egress-fetch');
|
|
5
7
|
|
|
8
|
+
/**
|
|
9
|
+
* The headers every webhook request starts from, a real delivery and a test probe alike
|
|
10
|
+
* @param {string} [authorization] - Basic auth taken from the target URL
|
|
11
|
+
* @returns {Object}
|
|
12
|
+
*/
|
|
13
|
+
function baseDeliveryHeaders(authorization) {
|
|
14
|
+
const headers = {
|
|
15
|
+
'Content-Type': 'application/json',
|
|
16
|
+
'User-Agent': `${packageData.name}/${packageData.version} (+${packageData.homepage})`
|
|
17
|
+
};
|
|
18
|
+
if (authorization) {
|
|
19
|
+
headers.Authorization = authorization;
|
|
20
|
+
}
|
|
21
|
+
return headers;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Signs a request body into X-EE-Wh-Signature, the header a receiver verifies with the service secret
|
|
26
|
+
* @param {Object} headers - Request headers, modified in place
|
|
27
|
+
* @param {Buffer|string} body - The exact bytes that are sent
|
|
28
|
+
* @param {string} secret - The service secret
|
|
29
|
+
*/
|
|
30
|
+
function signDelivery(headers, body, secret) {
|
|
31
|
+
headers['X-EE-Wh-Signature'] = createHmac('sha256', secret).update(body).digest('base64url');
|
|
32
|
+
}
|
|
33
|
+
|
|
6
34
|
// How much of a response body is read before the connection is dropped instead. The body is never
|
|
7
35
|
// used, it is read only so the pooled socket can be reused, and undici inflates a compressed one,
|
|
8
36
|
// so a receiver answering a POST with an endless or a bomb body would otherwise be buffered in
|
|
@@ -121,4 +149,4 @@ function isUnrecoverableWebhookError(err) {
|
|
|
121
149
|
return !!err && (err.code === 'EEGRESSBLOCKED' || err.code === 'EREDIRECTNOTFOLLOWED');
|
|
122
150
|
}
|
|
123
151
|
|
|
124
|
-
module.exports = { sendWebhookRequest, isUnrecoverableWebhookError, MAX_DRAIN_BYTES };
|
|
152
|
+
module.exports = { sendWebhookRequest, isUnrecoverableWebhookError, baseDeliveryHeaders, signDelivery, MAX_DRAIN_BYTES };
|
package/lib/webhook-routing.js
CHANGED
|
@@ -4,7 +4,15 @@
|
|
|
4
4
|
// and the admin account page's routing card resolve targets and gates through the helpers
|
|
5
5
|
// here, so the debug view cannot drift from what the worker actually does.
|
|
6
6
|
|
|
7
|
-
const {
|
|
7
|
+
const {
|
|
8
|
+
MESSAGE_NEW_NOTIFY,
|
|
9
|
+
DEFAULT_WEBHOOK_ATTEMPTS,
|
|
10
|
+
MAX_WEBHOOK_ATTEMPTS,
|
|
11
|
+
DEFAULT_WEBHOOK_RETRY_DELAY,
|
|
12
|
+
MIN_WEBHOOK_RETRY_DELAY,
|
|
13
|
+
MAX_WEBHOOK_RETRY_DELAY
|
|
14
|
+
} = require('./consts');
|
|
15
|
+
const { boundedInt } = require('./utils/int-setting');
|
|
8
16
|
|
|
9
17
|
// Precedence: custom route target, then the per-account webhooks override, then the global
|
|
10
18
|
// webhooks setting. Returns the winning URL and which configuration level provided it.
|
|
@@ -167,7 +175,28 @@ function describeEffectiveRouting(opts) {
|
|
|
167
175
|
};
|
|
168
176
|
}
|
|
169
177
|
|
|
178
|
+
/**
|
|
179
|
+
* The attempts and backoff a webhook delivery job is queued with, from the webhooksDeliveryAttempts
|
|
180
|
+
* and webhooksRetryDelay settings. Read when an event is queued, so a change applies to the events
|
|
181
|
+
* queued after it, never to the deliveries already waiting.
|
|
182
|
+
*
|
|
183
|
+
* @param {Object} [values] - The two settings, as settings.getMulti() returns them
|
|
184
|
+
* @returns {{attempts: number, backoff: Object}} BullMQ job options
|
|
185
|
+
*/
|
|
186
|
+
function webhookRetryPolicy(values) {
|
|
187
|
+
values = values || {};
|
|
188
|
+
return {
|
|
189
|
+
attempts: boundedInt(values.webhooksDeliveryAttempts, DEFAULT_WEBHOOK_ATTEMPTS, 1, MAX_WEBHOOK_ATTEMPTS),
|
|
190
|
+
backoff: {
|
|
191
|
+
type: 'exponential',
|
|
192
|
+
delay: boundedInt(values.webhooksRetryDelay, DEFAULT_WEBHOOK_RETRY_DELAY, MIN_WEBHOOK_RETRY_DELAY, MAX_WEBHOOK_RETRY_DELAY),
|
|
193
|
+
jitter: 0.2 // 20% randomization to prevent thundering herd
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
170
198
|
module.exports = {
|
|
199
|
+
webhookRetryPolicy,
|
|
171
200
|
resolveTargetUrl,
|
|
172
201
|
isDeliverableRoute,
|
|
173
202
|
eventAllowed,
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// A one-off test delivery to a webhook target: the admin Webhooks page's "Test" button and
|
|
4
|
+
// POST /v1/webhooks/test. It goes out through the same request function, dispatcher and egress
|
|
5
|
+
// check as a real delivery, and is signed the way one is, so a receiver that verifies
|
|
6
|
+
// X-EE-Wh-Signature accepts the probe as it would accept the events.
|
|
7
|
+
|
|
8
|
+
const crypto = require('crypto');
|
|
9
|
+
const { fetch: fetchCmd } = require('undici');
|
|
10
|
+
const { splitUrlCredentials, httpAgent, getServiceSecret } = require('./tools');
|
|
11
|
+
const { validateWebhookTarget } = require('./webhook-egress');
|
|
12
|
+
const { sendWebhookRequest, baseDeliveryHeaders, signDelivery } = require('./webhook-request');
|
|
13
|
+
const { isReservedDeliveryHeader } = require('./webhook-routing');
|
|
14
|
+
const { NONCE_BYTES } = require('./consts');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The body of a test event, as the receiver gets it
|
|
18
|
+
* @param {string} serviceUrl - The instance's service URL
|
|
19
|
+
* @param {string} [account] - Account ID, when the test is for an account's target
|
|
20
|
+
* @returns {string} JSON
|
|
21
|
+
*/
|
|
22
|
+
function testEventBody(serviceUrl, account) {
|
|
23
|
+
return JSON.stringify({
|
|
24
|
+
serviceUrl,
|
|
25
|
+
account: account || null,
|
|
26
|
+
date: new Date().toISOString(),
|
|
27
|
+
event: 'test',
|
|
28
|
+
data: {
|
|
29
|
+
nonce: crypto.randomBytes(NONCE_BYTES).toString('base64url')
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Posts a test delivery and reports how it went. Never throws for a failed delivery: the result
|
|
36
|
+
* says why it failed, which is the point of a test.
|
|
37
|
+
*
|
|
38
|
+
* @param {Object} options
|
|
39
|
+
* @param {string} options.url - Target URL, credentials in it are sent as basic auth
|
|
40
|
+
* @param {Array} [options.customHeaders] - `{ key, value }` headers to add, the X-EE-Wh-* and
|
|
41
|
+
* framing headers excepted, as for a real delivery
|
|
42
|
+
* @param {string} options.body - Request body
|
|
43
|
+
* @param {Object} options.logger - Logger instance
|
|
44
|
+
* @returns {Promise<Object>} `{ success, duration }`, plus `error`, `code` and `statusCode` on failure
|
|
45
|
+
*/
|
|
46
|
+
async function sendTestWebhook(options) {
|
|
47
|
+
const { url, customHeaders, body, logger } = options;
|
|
48
|
+
|
|
49
|
+
const { url: parsed, authorization } = splitUrlCredentials(url);
|
|
50
|
+
const headers = baseDeliveryHeaders(authorization);
|
|
51
|
+
|
|
52
|
+
for (const header of [].concat(customHeaders || [])) {
|
|
53
|
+
if (header && header.key && !isReservedDeliveryHeader(header.key)) {
|
|
54
|
+
headers[header.key] = header.value;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
signDelivery(headers, body, await getServiceSecret());
|
|
59
|
+
|
|
60
|
+
const start = Date.now();
|
|
61
|
+
try {
|
|
62
|
+
await sendWebhookRequest(fetchCmd, parsed.toString(), {
|
|
63
|
+
method: 'post',
|
|
64
|
+
body,
|
|
65
|
+
headers,
|
|
66
|
+
dispatcher: httpAgent.webhook,
|
|
67
|
+
validateTarget: validateWebhookTarget
|
|
68
|
+
});
|
|
69
|
+
return { success: true, duration: Date.now() - start };
|
|
70
|
+
} catch (err) {
|
|
71
|
+
// undici wraps a connection failure in a generic "fetch failed"; the cause is the part
|
|
72
|
+
// worth reporting back
|
|
73
|
+
const failure = err.cause || err;
|
|
74
|
+
// the parsed URL, not the given one, so embedded basic-auth credentials stay out of the log
|
|
75
|
+
logger.warn({ msg: 'Failed to post test webhook', webhooks: parsed.toString(), event: 'test', err: failure });
|
|
76
|
+
return {
|
|
77
|
+
success: false,
|
|
78
|
+
duration: Date.now() - start,
|
|
79
|
+
error: failure.message,
|
|
80
|
+
code: failure.code,
|
|
81
|
+
// Same field the stored webhookErrorFlag carries, so a probe and a failed delivery are
|
|
82
|
+
// described the same way
|
|
83
|
+
statusCode: failure.statusCode
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports = { sendTestWebhook, testEventBody };
|
package/lib/webhooks.js
CHANGED
|
@@ -7,13 +7,14 @@ const logger = require('./logger');
|
|
|
7
7
|
const { REDIS_PREFIX, MESSAGE_NEW_NOTIFY } = require('./consts');
|
|
8
8
|
const { SubScript } = require('./sub-script');
|
|
9
9
|
const settings = require('./settings');
|
|
10
|
-
const { filterListPage, truncateTextContents } = require('./tools');
|
|
10
|
+
const { filterListPage, redactUrlCredentials, truncateTextContents } = require('./tools');
|
|
11
11
|
const { buildRetentionPolicy } = require('./queue-retention');
|
|
12
|
-
const {
|
|
12
|
+
const { getFailedJobRetention } = require('./env-setting-overrides');
|
|
13
|
+
const { isDeliverableRoute, defaultRouteTakes, webhookRetryPolicy } = require('./webhook-routing');
|
|
13
14
|
const { withinNotifyAttachmentSize } = require('./notify-attachments');
|
|
14
15
|
|
|
15
16
|
// Every setting pushToQueue() decides by, read in one round trip per event
|
|
16
|
-
const QUEUE_SETTINGS = ['webhooksEnabled', 'queueKeep', 'webhookEvents', 'inboxNewOnly'];
|
|
17
|
+
const QUEUE_SETTINGS = ['webhooksEnabled', 'queueKeep', 'webhookEvents', 'inboxNewOnly', 'webhooksDeliveryAttempts', 'webhooksRetryDelay'];
|
|
17
18
|
const { encryptField, decryptField } = require('./encrypt');
|
|
18
19
|
const getSecret = require('./get-secret');
|
|
19
20
|
|
|
@@ -168,8 +169,13 @@ class WebhooksHandler {
|
|
|
168
169
|
}
|
|
169
170
|
|
|
170
171
|
if (query) {
|
|
171
|
-
|
|
172
|
-
|
|
172
|
+
// Matched against the target URL as a reader of the listing sees it, credentials taken
|
|
173
|
+
// out: the decrypted URL can carry user:pass@, and matching on it would let a caller
|
|
174
|
+
// that only ever gets the masked value guess the credential one character at a time
|
|
175
|
+
// from whether an entry matches
|
|
176
|
+
let original = new Map(response.webhooks.map(entry => [Object.assign({}, entry, { targetUrl: redactUrlCredentials(entry.targetUrl) }), entry]));
|
|
177
|
+
let paged = filterListPage([...original.keys()], ['id', 'name', 'description', 'targetUrl'], query, startPos, pageSize);
|
|
178
|
+
response.webhooks = paged.entries.map(view => original.get(view));
|
|
173
179
|
response.total = paged.total;
|
|
174
180
|
response.pages = paged.pages;
|
|
175
181
|
}
|
|
@@ -594,58 +600,59 @@ class WebhooksHandler {
|
|
|
594
600
|
return this.handlerCache;
|
|
595
601
|
}
|
|
596
602
|
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
603
|
+
/**
|
|
604
|
+
* The messageNew normalizations: text, headers and attachment contents are kept only as far
|
|
605
|
+
* as the notify settings ask
|
|
606
|
+
* @param {Object} data - The event's data, changed in place
|
|
607
|
+
*/
|
|
608
|
+
async normalizeMessageNew(data) {
|
|
609
|
+
// one read for every setting these use
|
|
610
|
+
const { notifyText, notifyTextSize, notifyHeaders, notifyAttachments, notifyAttachmentSize } = await settings.getMulti(
|
|
611
|
+
'notifyText',
|
|
612
|
+
'notifyTextSize',
|
|
613
|
+
'notifyHeaders',
|
|
614
|
+
'notifyAttachments',
|
|
615
|
+
'notifyAttachmentSize'
|
|
616
|
+
);
|
|
602
617
|
|
|
603
|
-
if (
|
|
618
|
+
if (data.text) {
|
|
604
619
|
// normalize text content
|
|
605
|
-
let notifyText = await settings.get('notifyText');
|
|
606
620
|
if (!notifyText) {
|
|
607
621
|
// remove text content if any
|
|
608
|
-
for (let key of Object.keys(
|
|
622
|
+
for (let key of Object.keys(data.text)) {
|
|
609
623
|
if (!['id', 'encodedSize'].includes(key)) {
|
|
610
|
-
delete
|
|
624
|
+
delete data.text[key];
|
|
611
625
|
}
|
|
612
626
|
}
|
|
613
|
-
if (!Object.keys(
|
|
614
|
-
delete
|
|
615
|
-
}
|
|
616
|
-
} else {
|
|
617
|
-
let notifyTextSize = await settings.get('notifyTextSize');
|
|
618
|
-
if (payload.data.text && truncateTextContents(payload.data.text, notifyTextSize)) {
|
|
619
|
-
payload.data.text.hasMore = true;
|
|
627
|
+
if (!Object.keys(data.text).length) {
|
|
628
|
+
delete data.text;
|
|
620
629
|
}
|
|
630
|
+
} else if (data.text && truncateTextContents(data.text, notifyTextSize)) {
|
|
631
|
+
data.text.hasMore = true;
|
|
621
632
|
}
|
|
622
633
|
}
|
|
623
634
|
|
|
624
|
-
if (
|
|
635
|
+
if (data.headers) {
|
|
625
636
|
// normalize headers
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
delete payload.data.headers;
|
|
637
|
+
if (!notifyHeaders?.length) {
|
|
638
|
+
delete data.headers;
|
|
629
639
|
} else if (!notifyHeaders.includes('*')) {
|
|
630
640
|
// filter unneeded headers
|
|
631
|
-
for (let header of Object.keys(
|
|
641
|
+
for (let header of Object.keys(data.headers || {})) {
|
|
632
642
|
if (!notifyHeaders.includes(header.toLowerCase())) {
|
|
633
|
-
delete
|
|
643
|
+
delete data.headers[header];
|
|
634
644
|
}
|
|
635
645
|
}
|
|
636
646
|
}
|
|
637
647
|
|
|
638
|
-
if (
|
|
639
|
-
delete
|
|
648
|
+
if (data.headers && !Object.keys(data.headers).length) {
|
|
649
|
+
delete data.headers;
|
|
640
650
|
}
|
|
641
651
|
}
|
|
642
652
|
|
|
643
653
|
// remove attachment contents
|
|
644
|
-
if (
|
|
645
|
-
let
|
|
646
|
-
let notifyAttachmentSize = await settings.get('notifyAttachmentSize');
|
|
647
|
-
|
|
648
|
-
for (let attachment of payload.data.attachments) {
|
|
654
|
+
if (data.attachments) {
|
|
655
|
+
for (let attachment of data.attachments) {
|
|
649
656
|
if (attachment.content) {
|
|
650
657
|
if (notifyAttachments && withinNotifyAttachmentSize(attachment, notifyAttachmentSize)) {
|
|
651
658
|
// keep the attachment
|
|
@@ -655,6 +662,17 @@ class WebhooksHandler {
|
|
|
655
662
|
}
|
|
656
663
|
}
|
|
657
664
|
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
async formatPayload(event, originalPayload) {
|
|
668
|
+
// run all normalizations before sending the data
|
|
669
|
+
|
|
670
|
+
const payload = structuredClone(originalPayload);
|
|
671
|
+
payload.eventId = payload.eventId || uuid();
|
|
672
|
+
|
|
673
|
+
if (event === MESSAGE_NEW_NOTIFY && payload.data) {
|
|
674
|
+
await this.normalizeMessageNew(payload.data);
|
|
675
|
+
}
|
|
658
676
|
|
|
659
677
|
if (payload && payload.data && payload.data.text && payload.data.text._generatedHtml) {
|
|
660
678
|
payload.data.text.html = payload.data.text._generatedHtml;
|
|
@@ -699,13 +717,8 @@ class WebhooksHandler {
|
|
|
699
717
|
let queueKeep = queueSettings.queueKeep ?? true;
|
|
700
718
|
|
|
701
719
|
let jobOpts = {
|
|
702
|
-
...buildRetentionPolicy(queueKeep),
|
|
703
|
-
|
|
704
|
-
backoff: {
|
|
705
|
-
type: 'exponential',
|
|
706
|
-
delay: 5000,
|
|
707
|
-
jitter: 0.2 // 20% randomization to prevent thundering herd
|
|
708
|
-
}
|
|
720
|
+
...buildRetentionPolicy(queueKeep, await getFailedJobRetention()),
|
|
721
|
+
...webhookRetryPolicy(queueSettings)
|
|
709
722
|
};
|
|
710
723
|
|
|
711
724
|
for (let route of webhookRoutes) {
|
package/lib/worker-rpc-error.js
CHANGED
|
@@ -12,12 +12,13 @@
|
|
|
12
12
|
// to tell a transient 4xx rejection (e.g. greylisting) from a permanent 5xx one. It used to be
|
|
13
13
|
// dropped, so the predicate's SMTP-reply branch never fired in production; keeping the field list in
|
|
14
14
|
// one place makes that dependency explicit and unit-testable (see test/worker-rpc-error-test.js).
|
|
15
|
+
// `permanent` is nodemailer's own verdict on that reply, which the predicate prefers when present.
|
|
15
16
|
//
|
|
16
17
|
// These helpers are used at the delivery-error RPC path - the imap/submit workers and the main-thread
|
|
17
18
|
// hub (server.js) that relays between them. The other workers (webhooks/export/smtp/api)
|
|
18
19
|
// keep their own inline resp-handler copies: they never carry a delivery error, so `responseCode`
|
|
19
20
|
// does not apply to them. Route a delivery error through a new worker and it must switch to these too.
|
|
20
|
-
const RPC_ERROR_FIELDS = ['code', 'statusCode', 'responseCode', 'info'];
|
|
21
|
+
const RPC_ERROR_FIELDS = ['code', 'statusCode', 'responseCode', 'permanent', 'info'];
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* Serializes an Error into the plain payload sent over postMessage.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "emailengine-app",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.86.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"productTitle": "EmailEngine",
|
|
6
6
|
"description": "Email Sync Engine",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"test:unit": "NODE_ENV=test node test/run-tests.js unit",
|
|
16
16
|
"test:cjs": "NODE_ENV=test NODE_OPTIONS=--no-experimental-require-module node test/run-tests.js unit",
|
|
17
17
|
"test:integration": "NODE_ENV=test node test/run-tests.js integration",
|
|
18
|
+
"test:mutation": "NODE_ENV=test node scripts/mutation-test.js",
|
|
18
19
|
"test:dovecot": "./test/dovecot/run-dovecot-tests.sh",
|
|
19
20
|
"test:e2e": "playwright test",
|
|
20
21
|
"test:e2e:install": "playwright install --with-deps chromium",
|
|
@@ -58,49 +59,48 @@
|
|
|
58
59
|
"@hapi/boom": "10.0.1",
|
|
59
60
|
"@hapi/cookie": "12.0.1",
|
|
60
61
|
"@hapi/crumb": "9.0.1",
|
|
61
|
-
"@hapi/hapi": "21.4.
|
|
62
|
-
"@hapi/inert": "7.1.
|
|
62
|
+
"@hapi/hapi": "21.4.11",
|
|
63
|
+
"@hapi/inert": "7.1.3",
|
|
63
64
|
"@hapi/vision": "7.0.3",
|
|
64
65
|
"@msgpack/msgpack": "3.1.3",
|
|
65
66
|
"@postalsys/bounce-classifier": "3.1.0",
|
|
66
|
-
"@postalsys/certs": "2.0.
|
|
67
|
-
"@postalsys/email-ai-tools": "2.3.
|
|
68
|
-
"@postalsys/email-content": "0.1.
|
|
69
|
-
"@postalsys/email-text-tools": "2.
|
|
67
|
+
"@postalsys/certs": "2.0.2",
|
|
68
|
+
"@postalsys/email-ai-tools": "2.3.2",
|
|
69
|
+
"@postalsys/email-content": "0.1.18",
|
|
70
|
+
"@postalsys/email-text-tools": "2.6.1",
|
|
70
71
|
"@postalsys/gettext": "4.3.0",
|
|
71
72
|
"@postalsys/joi-messages": "1.4.1",
|
|
72
73
|
"@postalsys/templates": "2.1.1",
|
|
73
74
|
"@sentry/node-core": "10.76.2",
|
|
74
75
|
"@simplewebauthn/server": "14.0.3",
|
|
75
|
-
"@zone-eu/mailsplit": "5.4.
|
|
76
|
+
"@zone-eu/mailsplit": "5.4.29",
|
|
76
77
|
"@zone-eu/wild-config": "1.7.10",
|
|
77
|
-
"bullmq": "6.
|
|
78
|
-
"dotenv": "18.0.
|
|
79
|
-
"encoding-japanese": "2.4.0",
|
|
78
|
+
"bullmq": "6.4.0",
|
|
79
|
+
"dotenv": "18.0.9",
|
|
80
80
|
"fast-xml-parser": "5.11.2",
|
|
81
81
|
"handlebars": "4.7.10",
|
|
82
82
|
"he": "1.2.0",
|
|
83
83
|
"html-to-text": "10.0.1",
|
|
84
84
|
"ical.js": "2.2.1",
|
|
85
85
|
"iconv-lite": "0.7.3",
|
|
86
|
-
"imapflow": "2.
|
|
87
|
-
"ioredfour": "2.
|
|
86
|
+
"imapflow": "2.9.1",
|
|
87
|
+
"ioredfour": "2.2.0",
|
|
88
88
|
"ioredis": "6.0.0",
|
|
89
89
|
"ipaddr.js": "2.5.0",
|
|
90
90
|
"joi": "18.3.0",
|
|
91
91
|
"libbase64": "1.4.1",
|
|
92
|
-
"libmime": "5.
|
|
92
|
+
"libmime": "5.6.3",
|
|
93
93
|
"libqp": "3.0.1",
|
|
94
|
-
"mailparser": "3.
|
|
94
|
+
"mailparser": "3.12.4",
|
|
95
95
|
"marked": "15.0.12",
|
|
96
96
|
"minimist": "1.2.8",
|
|
97
|
-
"nodemailer": "10.1
|
|
97
|
+
"nodemailer": "10.2.1",
|
|
98
98
|
"pino": "10.3.1",
|
|
99
99
|
"prom-client": "15.1.3",
|
|
100
100
|
"pubface": "1.2.0",
|
|
101
101
|
"punycode.js": "2.3.1",
|
|
102
102
|
"qrcode-generator": "2.0.4",
|
|
103
|
-
"smtp-server": "3.
|
|
103
|
+
"smtp-server": "3.21.1",
|
|
104
104
|
"socks": "2.8.10",
|
|
105
105
|
"undici": "7.30.1"
|
|
106
106
|
},
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
"@postalsys/ee-client": "1.8.2",
|
|
113
113
|
"@simplewebauthn/browser": "14.0.0",
|
|
114
114
|
"@tailwindcss/cli": "4.3.3",
|
|
115
|
-
"ace-builds": "1.45.
|
|
115
|
+
"ace-builds": "1.45.2",
|
|
116
116
|
"acorn": "8.19.0",
|
|
117
117
|
"acorn-walk": "8.3.5",
|
|
118
118
|
"eerawlog": "1.5.5",
|
|
@@ -130,10 +130,11 @@
|
|
|
130
130
|
"xgettext-template": "5.0.0"
|
|
131
131
|
},
|
|
132
132
|
"overrides": {
|
|
133
|
-
"@asamuzakjp/css-color": "4.1.1"
|
|
133
|
+
"@asamuzakjp/css-color": "4.1.1",
|
|
134
|
+
"cheerio": "1.2.0"
|
|
134
135
|
},
|
|
135
136
|
"engines": {
|
|
136
|
-
"node": ">=20.
|
|
137
|
+
"node": ">=20.19.0"
|
|
137
138
|
},
|
|
138
139
|
"pkg": {
|
|
139
140
|
"scripts": [
|