emailengine-app 2.81.1 → 2.82.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 +12 -6
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +52 -0
- package/Dockerfile +4 -2
- package/bin/emailengine.js +28 -18
- package/config/default.toml +0 -5
- package/config/test.toml +0 -5
- package/data/google-crawlers.json +1 -1
- package/encrypt.js +70 -42
- package/getswagger.sh +0 -4
- package/lib/account/account-state.js +2 -110
- package/lib/account/bounce-store-sweep.js +63 -0
- package/lib/account/expected-identity.js +1 -1
- package/lib/account-assignment.js +207 -0
- package/lib/account.js +374 -878
- package/lib/api-reference/index.js +2 -3
- package/lib/api-reference/schema-tree.js +53 -3
- package/lib/api-routes/account-routes.js +18 -29
- package/lib/api-routes/blocklist-routes.js +2 -2
- package/lib/api-routes/bull-board-routes.js +1 -6
- package/lib/api-routes/export-routes.js +2 -22
- package/lib/api-routes/gateway-routes.js +5 -14
- package/lib/api-routes/index.js +1 -13
- package/lib/api-routes/mailbox-routes.js +2 -7
- package/lib/api-routes/mcp-oauth-routes.js +2 -1
- package/lib/api-routes/mcp-routes.js +7 -7
- package/lib/api-routes/message-routes.js +44 -236
- package/lib/api-routes/mint-bounds.js +110 -0
- package/lib/api-routes/oauth2-app-routes.js +23 -32
- package/lib/api-routes/operation-impact.js +1 -1
- package/lib/api-routes/outbox-routes.js +2 -2
- package/lib/api-routes/permission-map.js +1 -7
- package/lib/api-routes/route-helpers.js +11 -5
- package/lib/api-routes/settings-routes.js +19 -19
- package/lib/api-routes/stats-routes.js +1 -1
- package/lib/api-routes/submit-routes.js +17 -18
- package/lib/api-routes/template-routes.js +4 -9
- package/lib/api-routes/token-routes.js +27 -5
- package/lib/api-token-scheme.js +71 -0
- package/lib/arf-detect.js +41 -7
- package/lib/auth-token.js +44 -24
- package/lib/autodetect-imap-settings.js +163 -123
- package/lib/bounce-detect.js +25 -16
- package/lib/calendar-event.js +78 -0
- package/lib/consts.js +51 -5
- package/lib/create-imap-client.js +24 -0
- package/lib/db.js +76 -17
- package/lib/delivery-error.js +2 -1
- package/lib/egress-fetch.js +54 -3
- package/lib/egress-filter.js +11 -0
- package/lib/email-client/api-retry.js +147 -0
- package/lib/email-client/base-client.js +628 -615
- package/lib/email-client/gmail/gmail-api.js +38 -125
- package/lib/email-client/gmail/send-request.js +1 -1
- package/lib/email-client/gmail-client.js +170 -84
- package/lib/email-client/imap/mailbox.js +244 -535
- package/lib/email-client/imap/stale-view.js +109 -0
- package/lib/email-client/imap/subconnection.js +46 -9
- package/lib/email-client/imap/sync-operations.js +5 -37
- package/lib/email-client/imap-client.js +188 -64
- package/lib/email-client/message-builder.js +9 -14
- package/lib/email-client/notification-handler.js +5 -219
- package/lib/email-client/outlook/graph-api.js +147 -126
- package/lib/email-client/outlook/send-request.js +10 -4
- package/lib/email-client/outlook-client.js +519 -617
- package/lib/email-client/smtp-pool-manager.js +3 -2
- package/lib/encrypt.js +184 -19
- package/lib/enum-descriptions.js +1 -2
- package/lib/export.js +144 -41
- package/lib/gateway.js +20 -6
- package/lib/get-raw-email.js +26 -44
- package/lib/handlebars-helpers.js +31 -10
- package/lib/imap-proxy-auth.js +13 -29
- package/lib/imapproxy/imap-core/README.md +1 -0
- package/lib/imapproxy/imap-core/lib/handler/imap-parser.js +12 -0
- package/lib/imapproxy/imap-core/lib/imap-command.js +74 -10
- package/lib/imapproxy/imap-core/lib/imap-connection.js +9 -1
- package/lib/imapproxy/imap-core/lib/imap-server.js +112 -26
- package/lib/imapproxy/imap-core/lib/imap-stream.js +41 -1
- package/lib/imapproxy/imap-core/lib/imap-tools.js +10 -2
- package/lib/imapproxy/imap-core/lib/indexer/indexer.js +4 -2
- package/lib/imapproxy/imap-server.js +17 -177
- package/lib/imapproxy/proxy-handoff.js +235 -0
- package/lib/imapproxy/response-error.js +33 -0
- package/lib/imapproxy/upstream-client.js +2 -2
- package/lib/license-beacon.js +3 -9
- package/lib/llm-pre-process.js +182 -43
- package/lib/logger.js +1 -1
- package/lib/lua/ee-export-queue-add.lua +39 -0
- package/lib/lua/ee-get-idempotency.lua +15 -3
- package/lib/lua/ee-release-attempts.lua +23 -0
- package/lib/lua/ee-reserve-attempts.lua +42 -0
- package/lib/lua/h-set-bigger.lua +12 -2
- package/lib/lua/s-list-accounts.lua +6 -3
- package/lib/mcp/index.js +1 -2
- package/lib/mcp/listen.js +221 -18
- package/lib/mcp/oauth.js +44 -5
- package/lib/mcp/resources.js +8 -2
- package/lib/mcp/tools.js +13 -0
- package/lib/message-port-stream.js +64 -6
- package/lib/msgpack.js +1 -6
- package/lib/oauth/external-account-signer.js +16 -13
- package/lib/oauth/gmail.js +22 -20
- package/lib/oauth/outlook.js +19 -16
- package/lib/oauth/pubsub/google.js +38 -2
- package/lib/oauth/scope-checker.js +4 -7
- package/lib/oauth/verify-app.js +2 -2
- package/lib/oauth2-apps.js +139 -44
- package/lib/openapi/build-document.js +1 -1
- package/lib/openapi/joi-schema.js +78 -9
- package/lib/parse-message.js +21 -0
- package/lib/payload-examples-webhooks.json +4 -7
- package/lib/pbkdf2-phc.js +101 -0
- package/lib/privileged-settings.js +0 -14
- package/lib/rate-limit.js +54 -15
- package/lib/redis-scan-delete.js +56 -29
- package/lib/redis-url.js +3 -1
- package/lib/respawn-backoff.js +5 -4
- package/lib/response-stream.js +25 -4
- package/lib/rewrite-text-nodes.js +27 -40
- package/lib/routes-ui.js +0 -5
- package/lib/schemas.js +129 -262
- package/lib/sentry.js +21 -5
- package/lib/settings.js +58 -59
- package/lib/smtp-auth.js +6 -2
- package/lib/smtp-message-processor.js +28 -7
- package/lib/sso.js +7 -3
- package/lib/stream-encrypt.js +14 -13
- package/lib/swagger-options.js +3 -1
- package/lib/tls/provision.js +69 -3
- package/lib/tls/store.js +14 -1
- package/lib/tools.js +113 -52
- package/lib/totp.js +16 -1
- package/lib/ui-routes/account-routes.js +27 -63
- package/lib/ui-routes/admin-config-routes.js +111 -134
- package/lib/ui-routes/admin-entities-routes.js +101 -191
- package/lib/ui-routes/ai-options.js +104 -0
- package/lib/ui-routes/auth-routes.js +98 -18
- package/lib/ui-routes/export-routes.js +3 -23
- package/lib/ui-routes/internals-routes.js +12 -9
- package/lib/ui-routes/network-config-routes.js +8 -18
- package/lib/ui-routes/oauth-config-routes.js +80 -214
- package/lib/ui-routes/route-helpers.js +40 -44
- package/lib/ui-routes/unsubscribe-routes.js +2 -2
- package/lib/utils/decode-headers.js +32 -5
- package/lib/utils/header-map.js +62 -1
- package/lib/utils/network.js +2 -0
- package/lib/web-safe-html.js +77 -4
- package/lib/webhook-request.js +9 -1
- package/lib/webhook-routing.js +27 -1
- package/lib/webhooks.js +120 -43
- package/lib/worker-rpc-error.js +43 -2
- package/list-generate.js +13 -2
- package/package.json +38 -46
- package/sbom.json +1 -1
- package/scripts/refresh-test-tokens.js +42 -14
- package/server.js +340 -336
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +7 -8
- package/static/js/ee-client.js +145 -70
- package/static/js/ui.js +350 -154
- package/static/licenses.html +460 -1861
- package/translations/messages.pot +99 -99
- package/views/accounts/browse.hbs +10 -4
- package/views/config/ai.hbs +49 -41
- package/views/config/oauth/app.hbs +2 -1
- package/views/dashboard.hbs +18 -16
- package/views/layout/app.hbs +0 -22
- package/views/layout/login.hbs +2 -1
- package/views/partials/filter_editor_js.hbs +4 -3
- package/views/partials/side_menu.hbs +0 -4
- package/views/partials/ui/account-picker.hbs +6 -32
- package/views/partials/ui/model-picker.hbs +31 -0
- package/views/partials/ui/pagination.hbs +6 -1
- package/views/partials/ui/picker.hbs +47 -0
- package/views/unsubscribe.hbs +1 -1
- package/workers/api.js +33 -23
- package/workers/export.js +55 -60
- package/workers/imap.js +134 -47
- package/workers/submit.js +3 -1
- package/workers/webhooks.js +46 -27
- package/.githooks/pre-commit +0 -80
- package/.github/CODE_OF_CONDUCT.md +0 -76
- package/.github/contributing.md +0 -17
- package/.github/dependabot.yml +0 -22
- package/.github/docker-smoke-test.sh +0 -61
- package/.github/workflows/deploy.yml +0 -215
- package/.github/workflows/e2e.yml +0 -55
- package/.github/workflows/release.yaml +0 -217
- package/.github/workflows/test.yml +0 -307
- package/lib/api-routes/chat-routes.js +0 -535
- package/lib/append-list.js +0 -63
- package/lib/document-store.js +0 -75
- package/lib/es.js +0 -757
- package/lib/generate-text-preview.js +0 -61
- package/lib/imapproxy/imap-core/memory-notifier.js +0 -129
- package/lib/lua/h-push.lua +0 -32
- package/lib/pre-process.js +0 -196
- package/lib/threads.js +0 -155
- package/lib/ui-routes/document-store-routes.js +0 -806
- package/playwright.config.js +0 -47
- package/views/config/document-store/chat.hbs +0 -286
- package/views/config/document-store/index.hbs +0 -146
- package/views/config/document-store/mappings/index.hbs +0 -108
- package/views/config/document-store/mappings/new.hbs +0 -68
- package/views/config/document-store/pre-processing/index.hbs +0 -103
- package/views/partials/document_store_header.hbs +0 -30
- package/workers/documents.js +0 -1128
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
// in lib/sso.js because workers/api.js needs them too.
|
|
10
10
|
|
|
11
11
|
const Joi = require('joi');
|
|
12
|
+
const { formBoolean } = require('../schemas');
|
|
12
13
|
const crypto = require('crypto');
|
|
13
14
|
const { parentPort } = require('worker_threads');
|
|
14
|
-
const pbkdf2 = require('
|
|
15
|
-
const
|
|
16
|
-
const { generateTotpSeed, verifyTotp, generateTotpUrl } = require('../totp');
|
|
15
|
+
const pbkdf2 = require('../pbkdf2-phc');
|
|
16
|
+
const { generateTotpSeed, verifyTotp, generateTotpUrl, generateTotpQrDataUrl } = require('../totp');
|
|
17
17
|
const {
|
|
18
18
|
generateRegistrationOptions,
|
|
19
19
|
verifyRegistrationResponse,
|
|
@@ -21,13 +21,41 @@ const {
|
|
|
21
21
|
verifyAuthenticationResponse
|
|
22
22
|
} = require('@simplewebauthn/server');
|
|
23
23
|
|
|
24
|
+
// The public key algorithms a passkey may be registered with: ES256 and RS256, which every
|
|
25
|
+
// authenticator offers. The library's own list starts with EdDSA, and an Ed25519 passkey fails at
|
|
26
|
+
// every login once the instance runs on a host whose OpenSSL is in FIPS mode, where Ed25519 is not
|
|
27
|
+
// available. Sign-in verifies against the stored key, so the list affects registration only
|
|
28
|
+
const PASSKEY_ALGORITHMS = [-7, -257];
|
|
29
|
+
|
|
24
30
|
const settings = require('../settings');
|
|
25
31
|
const consts = require('../consts');
|
|
26
32
|
const { readEnvValue, setAdminSession } = require('../tools');
|
|
27
33
|
const passkeys = require('../passkeys');
|
|
28
34
|
const sso = require('../sso');
|
|
29
|
-
|
|
30
|
-
const {
|
|
35
|
+
const { redis } = require('../db');
|
|
36
|
+
const { windowBudget, reserveAttempts, releaseAttempts, incrementCounter } = require('../rate-limit');
|
|
37
|
+
|
|
38
|
+
const { LOGIN_PERIOD_TTL, TOTP_WINDOW_SIZE, REDIS_PREFIX } = consts;
|
|
39
|
+
|
|
40
|
+
// Failed second-factor codes a user may spend, per window. The per-minute attempt limit alone
|
|
41
|
+
// allowed some 14,000 guesses a day at three valid codes each (the verification window), which
|
|
42
|
+
// finds a six-digit code within weeks. The budgets escalate: an hour's worth of failures locks
|
|
43
|
+
// the second factor for the rest of that hour, a day's worth for the rest of the day. Keyed on
|
|
44
|
+
// the user, not the session, so logging in again does not buy a fresh budget.
|
|
45
|
+
const TOTP_FAILURE_BUDGETS = [
|
|
46
|
+
{ windowSize: 60 * 60, allowed: 20 },
|
|
47
|
+
{ windowSize: 24 * 60 * 60, allowed: 60 }
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
// Failed codes one password-stage session may submit before it is ended and the password has to
|
|
51
|
+
// be entered again
|
|
52
|
+
const TOTP_SESSION_FAILURES = 5;
|
|
53
|
+
// Seconds a session's failure count is kept; a password-stage session is not meant to live long
|
|
54
|
+
const TOTP_SESSION_FAILURE_TTL = 24 * 60 * 60;
|
|
55
|
+
|
|
56
|
+
// How long a code that verified stays spent: longer than the span in which any code verifies
|
|
57
|
+
// (TOTP_WINDOW_SIZE steps either side of the current 30 second one)
|
|
58
|
+
const TOTP_USED_CODE_TTL = 12 * 60;
|
|
31
59
|
|
|
32
60
|
const OKTA_OAUTH2_ISSUER = readEnvValue('OKTA_OAUTH2_ISSUER');
|
|
33
61
|
const OKTA_OAUTH2_CLIENT_ID = readEnvValue('OKTA_OAUTH2_CLIENT_ID');
|
|
@@ -124,6 +152,17 @@ async function verifyCurrentPassword(request, h, authData, password) {
|
|
|
124
152
|
return { ok: true };
|
|
125
153
|
}
|
|
126
154
|
|
|
155
|
+
// Counts a failed second-factor code against the password-stage session that submitted it, keyed
|
|
156
|
+
// on the session's random sid. An exact counter rather than a rate-limit bucket, because the
|
|
157
|
+
// session is ended on a count, not throttled over a window. Returns the failures so far.
|
|
158
|
+
async function countSessionTotpFailure(request) {
|
|
159
|
+
let sid = request.auth && request.auth.artifacts && request.auth.artifacts.sid;
|
|
160
|
+
if (!sid) {
|
|
161
|
+
return 0;
|
|
162
|
+
}
|
|
163
|
+
return await incrementCounter(`${REDIS_PREFIX}totp:session:${sid}`, 1, TOTP_SESSION_FAILURE_TTL);
|
|
164
|
+
}
|
|
165
|
+
|
|
127
166
|
// View model for the security page's passkey list. Only the fields the list renders are
|
|
128
167
|
// exposed - the stored credential also carries the public key, the signature counter and
|
|
129
168
|
// the owning user, none of which belong in a template context.
|
|
@@ -422,7 +461,7 @@ function init(args) {
|
|
|
422
461
|
payload: Joi.object({
|
|
423
462
|
username: Joi.string().max(256).example('user').label('Username').description('Your account username'),
|
|
424
463
|
password: Joi.string().max(256).min(8).required().example('secret').label('Password').description('Your account password'),
|
|
425
|
-
remember:
|
|
464
|
+
remember: formBoolean().default(false).description('Remember me'),
|
|
426
465
|
next: Joi.string()
|
|
427
466
|
.empty('')
|
|
428
467
|
.uri({ relativeOnly: true })
|
|
@@ -525,18 +564,61 @@ function init(args) {
|
|
|
525
564
|
return h.redirect(`/admin/login`);
|
|
526
565
|
}
|
|
527
566
|
|
|
567
|
+
let user = (request.auth.credentials && request.auth.credentials.user) || 'admin';
|
|
568
|
+
|
|
569
|
+
// One attempt reserved in the hour and the day budget together, given back when
|
|
570
|
+
// the code verifies, so only a failure stays counted and parallel guesses cannot
|
|
571
|
+
// all slip past a nearly spent budget the way a look-then-record check let them
|
|
572
|
+
const now = Date.now();
|
|
573
|
+
const failureBudgets = TOTP_FAILURE_BUDGETS.map(budget => windowBudget(`totp:fail:${user}`, budget.allowed, budget.windowSize, now));
|
|
574
|
+
const reservation = await reserveAttempts(failureBudgets);
|
|
575
|
+
if (!reservation.admitted) {
|
|
576
|
+
request.logger.warn({
|
|
577
|
+
msg: 'Second factor locked after too many failed codes',
|
|
578
|
+
user,
|
|
579
|
+
counts: reservation.counts,
|
|
580
|
+
remoteAddress: request.app.ip
|
|
581
|
+
});
|
|
582
|
+
let err = new Error('Too many failed codes, please try again later');
|
|
583
|
+
err.responseText = err.message;
|
|
584
|
+
throw err;
|
|
585
|
+
}
|
|
586
|
+
|
|
528
587
|
let verified = verifyTotp(totpSeed, request.payload.code, { window: TOTP_WINDOW_SIZE });
|
|
529
588
|
|
|
530
589
|
if (!verified) {
|
|
590
|
+
// The reservation stays: that is the recorded failure
|
|
591
|
+
if ((await countSessionTotpFailure(request)) >= TOTP_SESSION_FAILURES) {
|
|
592
|
+
// End the half-logged-in session: further guesses need the password again,
|
|
593
|
+
// which the login form rate limits on its own
|
|
594
|
+
request.logger.warn({ msg: 'Password-stage session ended after failed codes', user, remoteAddress: request.app.ip });
|
|
595
|
+
request.cookieAuth.clear();
|
|
596
|
+
await request.flash({ type: 'danger', message: `Too many failed codes. Sign in again.` });
|
|
597
|
+
|
|
598
|
+
let url = new URL(`admin/login`, 'http://localhost');
|
|
599
|
+
if (request.payload.next) {
|
|
600
|
+
url.searchParams.append('next', request.payload.next);
|
|
601
|
+
}
|
|
602
|
+
return h.redirect(url.pathname + url.search);
|
|
603
|
+
}
|
|
604
|
+
|
|
531
605
|
let err = new Error('Failed to verify login');
|
|
532
606
|
err.details = { code: 'Invalid or expired code' };
|
|
533
607
|
throw err;
|
|
534
608
|
}
|
|
535
609
|
|
|
536
|
-
// code
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
request.logger.
|
|
610
|
+
// Not awaited: a verified code is not held up by giving its reservation back, and a
|
|
611
|
+
// release that fails only costs this user one attempt of the budget
|
|
612
|
+
releaseAttempts(failureBudgets.map(budget => budget.key)).catch(err => {
|
|
613
|
+
request.logger.error({ msg: 'Failed to release second factor attempt', user, err });
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
// Single use: a code that verified cannot verify again for as long as it is valid.
|
|
617
|
+
// A marker per code rather than a fixed-bucket counter, whose bucket boundary let a
|
|
618
|
+
// code used just before it be replayed just after.
|
|
619
|
+
let firstUse = await redis.set(`${REDIS_PREFIX}totp:used:${user}:${request.payload.code}`, '1', 'EX', TOTP_USED_CODE_TTL, 'NX');
|
|
620
|
+
if (!firstUse) {
|
|
621
|
+
request.logger.warn({ msg: 'TOTP code recently used', user, remoteAddress: request.app.ip });
|
|
540
622
|
let err = new Error('This code has been already used, please wait and try another code');
|
|
541
623
|
err.responseText = err.message;
|
|
542
624
|
throw err;
|
|
@@ -683,7 +765,7 @@ function init(args) {
|
|
|
683
765
|
});
|
|
684
766
|
|
|
685
767
|
try {
|
|
686
|
-
totp.dataUrl =
|
|
768
|
+
totp.dataUrl = generateTotpQrDataUrl(otpauth_url);
|
|
687
769
|
} catch (err) {
|
|
688
770
|
request.logger.error({ msg: 'Failed to generate QR code', err });
|
|
689
771
|
}
|
|
@@ -1017,6 +1099,7 @@ function init(args) {
|
|
|
1017
1099
|
userName: user,
|
|
1018
1100
|
userID: Buffer.from(crypto.createHash('sha256').update(user).digest()),
|
|
1019
1101
|
attestationType: 'none',
|
|
1102
|
+
supportedAlgorithmIDs: PASSKEY_ALGORITHMS,
|
|
1020
1103
|
excludeCredentials: existingCredentials.map(c => ({
|
|
1021
1104
|
id: c.id,
|
|
1022
1105
|
transports: c.transports
|
|
@@ -1090,7 +1173,8 @@ function init(args) {
|
|
|
1090
1173
|
response: request.payload.credential,
|
|
1091
1174
|
expectedChallenge: challenge,
|
|
1092
1175
|
expectedOrigin: origin,
|
|
1093
|
-
expectedRPID: rpId
|
|
1176
|
+
expectedRPID: rpId,
|
|
1177
|
+
supportedAlgorithmIDs: PASSKEY_ALGORITHMS
|
|
1094
1178
|
});
|
|
1095
1179
|
|
|
1096
1180
|
if (!verification.verified || !verification.registrationInfo) {
|
|
@@ -1370,7 +1454,7 @@ function init(args) {
|
|
|
1370
1454
|
.uri({ relativeOnly: true })
|
|
1371
1455
|
.pattern(/^\/(?!\/)/)
|
|
1372
1456
|
.label('NextUrl'),
|
|
1373
|
-
remember:
|
|
1457
|
+
remember: formBoolean().default(false)
|
|
1374
1458
|
})
|
|
1375
1459
|
}
|
|
1376
1460
|
}
|
|
@@ -1429,11 +1513,7 @@ function init(args) {
|
|
|
1429
1513
|
}
|
|
1430
1514
|
}
|
|
1431
1515
|
|
|
1432
|
-
const passwordHash = await pbkdf2.hash(request.payload.password
|
|
1433
|
-
iterations: PDKDF2_ITERATIONS,
|
|
1434
|
-
saltSize: PDKDF2_SALT_SIZE,
|
|
1435
|
-
digest: PDKDF2_DIGEST
|
|
1436
|
-
});
|
|
1516
|
+
const passwordHash = await pbkdf2.hash(request.payload.password);
|
|
1437
1517
|
|
|
1438
1518
|
authData = authData || {};
|
|
1439
1519
|
authData.user = authData.user || 'admin';
|
|
@@ -6,10 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
const Joi = require('joi');
|
|
8
8
|
const Boom = require('@hapi/boom');
|
|
9
|
-
const fs = require('fs');
|
|
10
9
|
|
|
11
|
-
const { Export } = require('../export');
|
|
12
|
-
const getSecret = require('../get-secret');
|
|
10
|
+
const { Export, openExportReadStream } = require('../export');
|
|
13
11
|
const { failAction } = require('../tools');
|
|
14
12
|
const { exportIdSchema } = require('../schemas');
|
|
15
13
|
const { throwAsBoom, isClientError } = require('./route-helpers');
|
|
@@ -172,29 +170,11 @@ function init(args) {
|
|
|
172
170
|
throw Boom.notFound('Export not found');
|
|
173
171
|
}
|
|
174
172
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
stream.on('error', err => {
|
|
173
|
+
// Decrypted on the way out when the export is encrypted
|
|
174
|
+
const stream = await openExportReadStream(fileInfo, err => {
|
|
179
175
|
request.logger.error({ msg: 'Export download stream error', exportId, err });
|
|
180
176
|
});
|
|
181
177
|
|
|
182
|
-
// Decrypt file if encrypted
|
|
183
|
-
if (fileInfo.isEncrypted) {
|
|
184
|
-
const secret = await getSecret();
|
|
185
|
-
if (!secret) {
|
|
186
|
-
fileReadStream.destroy();
|
|
187
|
-
throw Boom.serverUnavailable('Encryption secret not available for decryption');
|
|
188
|
-
}
|
|
189
|
-
const { createDecryptStream } = require('../stream-encrypt');
|
|
190
|
-
const decryptStream = await createDecryptStream(secret);
|
|
191
|
-
decryptStream.on('error', err => {
|
|
192
|
-
request.logger.error({ msg: 'Export decryption error', exportId, err });
|
|
193
|
-
fileReadStream.destroy();
|
|
194
|
-
});
|
|
195
|
-
stream = fileReadStream.pipe(decryptStream);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
178
|
return h
|
|
199
179
|
.response(stream)
|
|
200
180
|
.type('application/gzip')
|
|
@@ -11,12 +11,12 @@ const settings = require('../settings');
|
|
|
11
11
|
const { Account } = require('../account');
|
|
12
12
|
const { redis } = require('../db');
|
|
13
13
|
const { DEFAULT_PAGE_SIZE } = require('../consts');
|
|
14
|
-
const { formatAccountData } = require('./route-helpers');
|
|
14
|
+
const { formatAccountData, windowedPageLinks } = require('./route-helpers');
|
|
15
15
|
const { severityRank } = require('../utils/severity');
|
|
16
16
|
|
|
17
17
|
// Worker kinds in the order they are shown on the internals page (known kinds first; any
|
|
18
18
|
// unrecognized kind is appended so nothing is dropped).
|
|
19
|
-
const THREAD_TYPE_ORDER = ['main', 'api', 'imap', 'webhooks', 'submit', 'export', 'smtp', 'imapProxy'
|
|
19
|
+
const THREAD_TYPE_ORDER = ['main', 'api', 'imap', 'webhooks', 'submit', 'export', 'smtp', 'imapProxy'];
|
|
20
20
|
|
|
21
21
|
// "Recently restarted" detection. Workers normally come online within seconds of the main
|
|
22
22
|
// process; one that came online much later was respawned after a crash (uncaught exception).
|
|
@@ -34,7 +34,6 @@ const THREAD_PURPOSE = {
|
|
|
34
34
|
webhooks: 'Delivers webhook notifications for email and account events over HTTP, with automatic retries and optional per-route filtering and transforms.',
|
|
35
35
|
submit: 'Sends queued outbound email through SMTP or a provider API (Gmail, Outlook), with retries and delivery, bounce and complaint tracking.',
|
|
36
36
|
export: 'Runs bulk account export jobs, extracting matching messages into compressed files for download.',
|
|
37
|
-
documents: 'Indexes emails into the Document Store (ElasticSearch) for search and processing. This is a deprecated feature.',
|
|
38
37
|
smtp: 'Accepts SMTP submissions from legacy applications and queues them for delivery through the associated account.',
|
|
39
38
|
imapProxy: 'Lets standard IMAP clients reach EmailEngine-managed accounts, hiding the OAuth2 complexity of providers like Gmail and Microsoft 365.'
|
|
40
39
|
};
|
|
@@ -357,7 +356,14 @@ function init(args) {
|
|
|
357
356
|
const accountsWithData = [];
|
|
358
357
|
for (const accountId of result.accounts) {
|
|
359
358
|
const accountObject = new Account({ redis, account: accountId });
|
|
360
|
-
|
|
359
|
+
// loadAccountData() throws (a 404 for an account deleted since it was assigned)
|
|
360
|
+
// rather than returning nothing, and one bad row must not take the page down
|
|
361
|
+
let accountData;
|
|
362
|
+
try {
|
|
363
|
+
accountData = await accountObject.loadAccountData(null, null, runIndex);
|
|
364
|
+
} catch (err) {
|
|
365
|
+
request.logger.warn({ msg: 'Failed to load assigned account', account: accountId, threadId, err });
|
|
366
|
+
}
|
|
361
367
|
if (accountData) {
|
|
362
368
|
accountsWithData.push(formatAccountData(accountData, request.app.gt));
|
|
363
369
|
} else {
|
|
@@ -414,11 +420,8 @@ function init(args) {
|
|
|
414
420
|
showPaging: result.pages > 1,
|
|
415
421
|
nextPage,
|
|
416
422
|
prevPage,
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
title: i + 1,
|
|
420
|
-
active: i + 1 === result.page
|
|
421
|
-
}))
|
|
423
|
+
// result.page is one-based here
|
|
424
|
+
pageLinks: windowedPageLinks(result.pages, result.page - 1, getPagingUrl)
|
|
422
425
|
},
|
|
423
426
|
{
|
|
424
427
|
layout: 'app'
|
|
@@ -12,7 +12,7 @@ const { parentPort } = require('worker_threads');
|
|
|
12
12
|
|
|
13
13
|
const settings = require('../settings');
|
|
14
14
|
const { redis } = require('../db');
|
|
15
|
-
const { REDIS_PREFIX } = require('../consts');
|
|
15
|
+
const { REDIS_PREFIX, LISTENER_RELOADS } = require('../consts');
|
|
16
16
|
const { failAction, getServiceHostname, maybeReloadTlsCertificates } = require('../tools');
|
|
17
17
|
const { ADDRESS_STRATEGIES, settingsSchema } = require('../schemas');
|
|
18
18
|
const { updatePublicInterfaces } = require('../utils/network');
|
|
@@ -319,18 +319,18 @@ function init(args) {
|
|
|
319
319
|
|
|
320
320
|
// Persist a server-settings payload and request a server restart when a key
|
|
321
321
|
// that affects the listener (enabled/port/host/TLS) actually changed
|
|
322
|
-
const applyServerSettings = async (request,
|
|
323
|
-
const existingSetup = await settings.getMulti(...
|
|
324
|
-
const hasServerChanges =
|
|
322
|
+
const applyServerSettings = async (request, listener) => {
|
|
323
|
+
const existingSetup = await settings.getMulti(...listener.keys);
|
|
324
|
+
const hasServerChanges = listener.keys.some(key => request.payload[key] !== existingSetup[key]);
|
|
325
325
|
|
|
326
326
|
await settings.setMulti(request.payload);
|
|
327
327
|
|
|
328
328
|
if (hasServerChanges) {
|
|
329
329
|
// request server restart
|
|
330
330
|
try {
|
|
331
|
-
await call({ cmd:
|
|
331
|
+
await call({ cmd: listener.cmd });
|
|
332
332
|
} catch (err) {
|
|
333
|
-
request.logger.error({ msg: 'Reload request failed', action:
|
|
333
|
+
request.logger.error({ msg: 'Reload request failed', action: listener.action, err });
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
};
|
|
@@ -356,12 +356,7 @@ function init(args) {
|
|
|
356
356
|
viewContext: async (request, values, h) => await serverPageContext(h, 'imapProxy'),
|
|
357
357
|
|
|
358
358
|
async applySettings(request) {
|
|
359
|
-
await applyServerSettings(
|
|
360
|
-
request,
|
|
361
|
-
['imapProxyServerEnabled', 'imapProxyServerPort', 'imapProxyServerHost', 'imapProxyServerTLSEnabled'],
|
|
362
|
-
'imapProxyReload',
|
|
363
|
-
'request_reload_imap_proxy'
|
|
364
|
-
);
|
|
359
|
+
await applyServerSettings(request, LISTENER_RELOADS.imapProxy);
|
|
365
360
|
}
|
|
366
361
|
});
|
|
367
362
|
|
|
@@ -387,12 +382,7 @@ function init(args) {
|
|
|
387
382
|
viewContext: async (request, values, h) => await serverPageContext(h, 'smtp'),
|
|
388
383
|
|
|
389
384
|
async applySettings(request) {
|
|
390
|
-
await applyServerSettings(
|
|
391
|
-
request,
|
|
392
|
-
['smtpServerEnabled', 'smtpServerPort', 'smtpServerHost', 'smtpServerTLSEnabled'],
|
|
393
|
-
'smtpReload',
|
|
394
|
-
'request_reload_smtp'
|
|
395
|
-
);
|
|
385
|
+
await applyServerSettings(request, LISTENER_RELOADS.smtp);
|
|
396
386
|
}
|
|
397
387
|
});
|
|
398
388
|
|