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
package/.ncurc.js
CHANGED
|
@@ -11,9 +11,8 @@ module.exports = {
|
|
|
11
11
|
// is a major we are deliberately soaking. Using 'minor' instead of a blanket reject so these
|
|
12
12
|
// still receive security/patch updates within the safe major instead of being frozen at one
|
|
13
13
|
// exact version. Verified against Node 20 (Docker) 2026-06-17.
|
|
14
|
-
target: name => (['nanoid', '
|
|
14
|
+
target: name => (['nanoid', 'gettext-parser', 'xgettext-template', 'chai', 'undici', 'marked', '@sentry/node-core'].includes(name) ? 'minor' : 'latest'),
|
|
15
15
|
// nanoid - 4.x dropped the CommonJS require export (ESM-only)
|
|
16
|
-
// ical.js - 2.x is ESM-only
|
|
17
16
|
// gettext-parser - 8.x is ESM-only
|
|
18
17
|
// xgettext-template - 6.x is ESM-only (translation build tool)
|
|
19
18
|
// chai - 5.x is ESM-only (only used by the vendored imap-core tests)
|
|
@@ -22,6 +21,17 @@ module.exports = {
|
|
|
22
21
|
// marked - 16.x dropped the CommonJS build (ESM-only, needs require(esm)/Node >=20.19); 15.x is the
|
|
23
22
|
// last require()-compatible line. 15.0.12 verified on Node 20-24 and in a yao/pkg node24 build.
|
|
24
23
|
// Permanent while the Node 20 floor above stands.
|
|
24
|
+
// @sentry/node-core - held on the 10.x line for the reasons @sentry/node (which it replaced, through its
|
|
25
|
+
// `light` entry) was held there: @sentry/node 11.x requires Node >=20.19 (the DigitalOcean
|
|
26
|
+
// images are not guaranteed to be on a 20.x that new), and it depends on
|
|
27
|
+
// @sentry/bundler-plugins, which pulls the 16 MB Sentry CLI (package `sentry`, licensed
|
|
28
|
+
// FSL-1.1-Apache-2.0, not an OSI license) into the runtime tree and the pkg bundle. The
|
|
29
|
+
// node-core line is versioned in step with @sentry/node, so lift this only once an 11.x
|
|
30
|
+
// of node-core exists and has been checked against both points.
|
|
31
|
+
//
|
|
32
|
+
// ical.js was capped at 1.x here as "2.x is ESM-only", which was never true: every 2.x ships a CommonJS
|
|
33
|
+
// build behind exports.require. Moved to 2.x on 2026-09-28; it is also what resolves a DTSTART against
|
|
34
|
+
// the VTIMEZONE embedded in the same invite (1.x read such a value in the server's own zone).
|
|
25
35
|
//
|
|
26
36
|
// bullmq was capped at 5.x until 2026-08-17, when both stated reasons had expired. Now on 6.x, which
|
|
27
37
|
// moves cron-parser off the deprecated 4.9.0 onto 5.x - but not off luxon, which cron-parser depends
|
|
@@ -37,10 +47,6 @@ module.exports = {
|
|
|
37
47
|
// bump still needs a look at the generated document: test/openapi-golden-test.js fails if joi's
|
|
38
48
|
// describe() output changes shape.
|
|
39
49
|
reject: [
|
|
40
|
-
// 8.16+ pulls apache-arrow (ESM) into the pkg bundle; 9.x drops it but is a major bump for
|
|
41
|
-
// the deprecated, default-off Document Store. Even the 8.19 minor is unsafe to bundle.
|
|
42
|
-
'@elastic/elasticsearch',
|
|
43
|
-
|
|
44
50
|
// @asamuzakjp/css-color >=4.1.2 pulls in @csstools/* v4 which are pure ESM and break pkg bundling
|
|
45
51
|
// (transitive via @postalsys/email-text-tools -> jsdom -> cssstyle; also pinned in package.json "overrides").
|
|
46
52
|
'@asamuzakjp/css-color'
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,57 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.82.0](https://github.com/postalsys/emailengine/compare/v2.81.2...v2.82.0) (2026-10-01)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* check incoming mail in code before the AI reads it, and pick the model from a list that says what each is for ([cf6f3a6](https://github.com/postalsys/emailengine/commit/cf6f3a6fda2d7c67a7f178b9c10e5014fc497e48))
|
|
9
|
+
* deliver the AI summary as the model returned it, and count its usage ([854ef18](https://github.com/postalsys/emailengine/commit/854ef18f1f8969bdcabe34b5a3a99c6ee2fc71e8))
|
|
10
|
+
* remove embeddings generation ([f4ddd90](https://github.com/postalsys/emailengine/commit/f4ddd908326bf6489ebbbdbf3421a291043ce8f0))
|
|
11
|
+
* remove the Document Store ([56df159](https://github.com/postalsys/emailengine/commit/56df159e4838d7b3052dadb8c30d8ac1e85f4e12))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* assert the literal cap on the continuations sent before the refusal ([1aa24dc](https://github.com/postalsys/emailengine/commit/1aa24dc9d6cbd2a2b8b33b4dc8f5fd328ab435bb))
|
|
17
|
+
* close the findings of the 2026-09-28 codebase audit ([2db748f](https://github.com/postalsys/emailengine/commit/2db748fc9879d577d3a9634fd6676149c91c1219))
|
|
18
|
+
* count announced literals against the IMAP proxy cap at continuation time ([51b73d2](https://github.com/postalsys/emailengine/commit/51b73d2f498e2d1fcd85861104ad89f65f184879))
|
|
19
|
+
* **deps:** update libmime, mailsplit, imapflow, mailparser and email-ai-tools ([943d2f5](https://github.com/postalsys/emailengine/commit/943d2f5891a88ff040fc2b7b3eb590c16cc498c6))
|
|
20
|
+
* **deps:** update nodemailer, smtp-server, mailparser, email-content and email-ai-tools ([af7aa9f](https://github.com/postalsys/emailengine/commit/af7aa9f5a46fb20409c9d8a3bd64be63c6593700))
|
|
21
|
+
* drop the trusted authentication servers setting from the AI page ([0b01c7e](https://github.com/postalsys/emailengine/commit/0b01c7e04c80e4dc60bf3bcf6b11e3114e9bd9ff))
|
|
22
|
+
* **imap:** measure the stale view quiet period from the UIDNEXT the primary knows ([a3044a1](https://github.com/postalsys/emailengine/commit/a3044a1ddbdae50298ebc3f61a909102360548dd))
|
|
23
|
+
* **imap:** reconnect a primary connection whose view of the main mailbox stopped moving ([442955c](https://github.com/postalsys/emailengine/commit/442955c41ef2f0fa4898e089056d2ee9fa7a2fdd))
|
|
24
|
+
* match the model picker's search term by term and rank the answers ([632754e](https://github.com/postalsys/emailengine/commit/632754e3e2110431caedb6f6ba391a3367b58df9))
|
|
25
|
+
* **outlook:** keep draft replies threaded on MS Graph accounts ([1ec3c6a](https://github.com/postalsys/emailengine/commit/1ec3c6a1485ee4fd649060e6fd2f137b01d87975))
|
|
26
|
+
* read the browse page session token from its hidden input in the e2e spec ([eea4a58](https://github.com/postalsys/emailengine/commit/eea4a58d5d15779c322fa52b9cc03b14284f2104))
|
|
27
|
+
* update ImapFlow to 2.2.1 ([a007b46](https://github.com/postalsys/emailengine/commit/a007b46ab68add12486ad11e6bef84db53777974))
|
|
28
|
+
* use only FIPS-approved primitives, so an instance runs on a host whose OpenSSL is in FIPS mode ([5070de0](https://github.com/postalsys/emailengine/commit/5070de07d5ac4c64bfa252766b965e9602407497))
|
|
29
|
+
|
|
30
|
+
## [2.81.2](https://github.com/postalsys/emailengine/compare/v2.81.1...v2.81.2) (2026-09-27)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Bug Fixes
|
|
34
|
+
|
|
35
|
+
* **api:** check isBounce for messages in the Inbox only ([de05eff](https://github.com/postalsys/emailengine/commit/de05eff7d684cd7beeb227a912afa6aa0988b421))
|
|
36
|
+
* **api:** decide isBounce at fetch time instead of storing a marker ([2c81311](https://github.com/postalsys/emailengine/commit/2c813117f95757c6cf656ae3f904042c3b458a7a))
|
|
37
|
+
* **api:** remove the bounces field and the store behind it ([b67acb9](https://github.com/postalsys/emailengine/commit/b67acb9618754a108e32e4bafbef0b05d4773ade))
|
|
38
|
+
* **api:** report isBounce and relatedMessageId in message responses ([b551bfd](https://github.com/postalsys/emailengine/commit/b551bfd7457466e8f51ff77540d0bb4afd59eb21))
|
|
39
|
+
* **deps:** update dependencies, hold @sentry/node at 10.x ([6c74381](https://github.com/postalsys/emailengine/commit/6c7438108559fa5eef36a022756515f623ac965f))
|
|
40
|
+
* **deps:** update imapflow to 2.0.6 ([07d5ea7](https://github.com/postalsys/emailengine/commit/07d5ea7eb42cdb01fd9a091db043837ecd8e58d3))
|
|
41
|
+
* **deps:** update imapflow to 2.1.0, dedupe nodemailer and undici ([13da944](https://github.com/postalsys/emailengine/commit/13da944e7ffee2943a91bfd4a0ade21b60c8f2b1))
|
|
42
|
+
* **docker:** bump the node:24-alpine base image digest ([0cb6d23](https://github.com/postalsys/emailengine/commit/0cb6d23a8e975e09bce10158434332b3f1131e89))
|
|
43
|
+
* **gmail:** retry new messages that fail on a transient API error ([f7d45f9](https://github.com/postalsys/emailengine/commit/f7d45f9edc1afaaf44b0d145caddb13aef0e76c1))
|
|
44
|
+
* **imap:** run the shared arrival checks instead of IMAP wrappers ([26cd53c](https://github.com/postalsys/emailengine/commit/26cd53c771ed8f6abbd740c22ef62319b54401a8))
|
|
45
|
+
* **imap:** share the bounce shape check with the API clients ([a0302a2](https://github.com/postalsys/emailengine/commit/a0302a2ff40ab62f8fd5dfc68f26cbc9175d0059))
|
|
46
|
+
* **imap:** share the complaint shape check with the API clients ([90a9825](https://github.com/postalsys/emailengine/commit/90a9825044fc024cf5977c5c56ccf5a484973cd4))
|
|
47
|
+
* **imap:** share the delivery-report shape check with the API clients ([aa777df](https://github.com/postalsys/emailengine/commit/aa777dfefbe8047f7b7a6df7000fb95b89189a2c))
|
|
48
|
+
* keep assigning accounts when an IMAP worker exits mid-assignment ([ed87eee](https://github.com/postalsys/emailengine/commit/ed87eee43ff6eba3b53d6556d7fc33e6ebfca0dc))
|
|
49
|
+
* keep throttled IMAP arrivals and harden the deferred change retries ([4830bb4](https://github.com/postalsys/emailengine/commit/4830bb451c5ee166c2ee0e6beef9cc759424341a))
|
|
50
|
+
* **outlook:** recover missed Graph notifications durably ([ff0eca6](https://github.com/postalsys/emailengine/commit/ff0eca6dbdfdbda34776b0b5c92b9c07cfbe5d04))
|
|
51
|
+
* **outlook:** retry change notifications that fail on a transient Graph error ([9d1301c](https://github.com/postalsys/emailengine/commit/9d1301cff3bd2b505e0d3402c40c2eefaf1c44ed))
|
|
52
|
+
* **submit:** warn when the sent copy is skipped for lack of a Sent mailbox ([47fd10b](https://github.com/postalsys/emailengine/commit/47fd10bdef5dc732265b10619122456d574942de))
|
|
53
|
+
* **sync:** defer Gmail and Graph changes that fail on a transient error ([b778adf](https://github.com/postalsys/emailengine/commit/b778adfab637ce7b2afc801e7eedd4f31f3a50a9))
|
|
54
|
+
|
|
3
55
|
## [2.81.1](https://github.com/postalsys/emailengine/compare/v2.81.0...v2.81.1) (2026-09-15)
|
|
4
56
|
|
|
5
57
|
|
package/Dockerfile
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
# here; the runtime stage below copies out only the finished tree, so npm and its dependencies never
|
|
12
12
|
# reach the published image. npm accounted for 38 of the 59 HIGH/CRITICAL findings in the old image
|
|
13
13
|
# (a vendored tar, pacote, sigstore, minimatch) and nothing at runtime ever invokes it.
|
|
14
|
-
FROM node:24-alpine@sha256:
|
|
14
|
+
FROM node:24-alpine@sha256:ebfe2f90462722a7a4de65e91990e97fe0d401c70e0e762c5b53302f905ec1c1 AS builder
|
|
15
15
|
|
|
16
16
|
ARG BUILDPLATFORM
|
|
17
17
|
ARG TARGETPLATFORM
|
|
@@ -74,7 +74,7 @@ RUN : "${EE_COMMIT_HASH:?EE_COMMIT_HASH build arg is required, e.g. --build-arg
|
|
|
74
74
|
&& rm -f update-info.sh
|
|
75
75
|
|
|
76
76
|
# Runtime stage.
|
|
77
|
-
FROM node:24-alpine@sha256:
|
|
77
|
+
FROM node:24-alpine@sha256:ebfe2f90462722a7a4de65e91990e97fe0d401c70e0e762c5b53302f905ec1c1
|
|
78
78
|
|
|
79
79
|
# `apk upgrade` patches the Alpine packages that the base image itself lags on - at the time of
|
|
80
80
|
# writing node:24-alpine still carries an openssl below 3.5.8-r0. dumb-init reaps zombies as PID 1.
|
|
@@ -98,6 +98,8 @@ USER emailengineuser
|
|
|
98
98
|
|
|
99
99
|
ENV EENGINE_HOST=0.0.0.0
|
|
100
100
|
ENV EENGINE_API_PROXY=true
|
|
101
|
+
# The pure JavaScript msgpackr decoder is what the pkg binary uses, so npm and Docker installs decode the same way and no native addon is loaded
|
|
102
|
+
ENV MSGPACKR_NATIVE_ACCELERATION_DISABLED=true
|
|
101
103
|
|
|
102
104
|
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
|
|
103
105
|
CMD ["node", "/emailengine/server.js"]
|
package/bin/emailengine.js
CHANGED
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
/* eslint global-require: 0 */
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
+
// No native addons (CLAUDE.md "Pure JavaScript only"): keep msgpackr, loaded through bullmq by
|
|
6
|
+
// lib/db below, off its optional node-gyp decoder. server.js sets the same for a direct start.
|
|
7
|
+
process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED = 'true';
|
|
8
|
+
|
|
5
9
|
const packageData = require('../package.json');
|
|
6
10
|
const fs = require('fs');
|
|
7
11
|
const pathlib = require('path');
|
|
8
12
|
const settings = require('../lib/settings');
|
|
9
13
|
const { checkLicense } = require('../lib/tools');
|
|
10
|
-
const pbkdf2 = require('
|
|
11
|
-
const {
|
|
14
|
+
const pbkdf2 = require('../lib/pbkdf2-phc');
|
|
15
|
+
const { generateWebhookTable } = require('../lib/consts');
|
|
12
16
|
const { Account } = require('../lib/account');
|
|
13
17
|
const getSecret = require('../lib/get-secret');
|
|
14
18
|
const { redis } = require('../lib/db');
|
|
@@ -133,13 +137,6 @@ const GLOBAL_OPTIONS = [
|
|
|
133
137
|
{ name: '--smtp.port', description: 'SMTP server port', type: 'number', default: 2525, group: 'SMTP server' },
|
|
134
138
|
{ name: '--smtp.proxy', description: 'Enable HAProxy PROXY protocol', type: 'boolean', default: false, group: 'SMTP server' },
|
|
135
139
|
{ name: '--smtp.maxMessageSize', description: 'Maximum email size', type: 'number/string', default: '25M', group: 'SMTP server' },
|
|
136
|
-
{
|
|
137
|
-
name: '--documentStore.enabled',
|
|
138
|
-
description: 'Enable the deprecated Document Store (ElasticSearch) feature',
|
|
139
|
-
type: 'boolean',
|
|
140
|
-
default: false,
|
|
141
|
-
group: 'Document Store (deprecated)'
|
|
142
|
-
},
|
|
143
140
|
{
|
|
144
141
|
name: '--mcp.enabled',
|
|
145
142
|
description: 'Register the MCP endpoint at /mcp (the mcpEnabled runtime setting still has to be turned on)',
|
|
@@ -386,11 +383,7 @@ function run() {
|
|
|
386
383
|
}
|
|
387
384
|
|
|
388
385
|
let updatePassword = async () => {
|
|
389
|
-
let passwordHash = await pbkdf2.hash(password
|
|
390
|
-
iterations: PDKDF2_ITERATIONS,
|
|
391
|
-
saltSize: PDKDF2_SALT_SIZE,
|
|
392
|
-
digest: PDKDF2_DIGEST
|
|
393
|
-
});
|
|
386
|
+
let passwordHash = await pbkdf2.hash(password);
|
|
394
387
|
|
|
395
388
|
let authData = await settings.get('authData');
|
|
396
389
|
|
|
@@ -581,7 +574,13 @@ function run() {
|
|
|
581
574
|
case 'import':
|
|
582
575
|
{
|
|
583
576
|
let rawToken = (argv.token || argv.t || '').toString();
|
|
584
|
-
let tokenData
|
|
577
|
+
let tokenData;
|
|
578
|
+
try {
|
|
579
|
+
tokenData = msgpack.decode(Buffer.from(rawToken, 'base64url'));
|
|
580
|
+
} catch (err) {
|
|
581
|
+
console.error(`Unable to decode token data: ${err.message}`);
|
|
582
|
+
return process.exit(1);
|
|
583
|
+
}
|
|
585
584
|
tokens
|
|
586
585
|
.setRawData(tokenData)
|
|
587
586
|
.then(result => {
|
|
@@ -600,8 +599,12 @@ function run() {
|
|
|
600
599
|
break;
|
|
601
600
|
|
|
602
601
|
default:
|
|
603
|
-
|
|
604
|
-
|
|
602
|
+
// Nothing else would end the process: the Redis connection opened on load
|
|
603
|
+
// kept it running with no output
|
|
604
|
+
console.error(tokensCmd ? `Unknown tokens command: ${tokensCmd}` : 'A tokens command is required');
|
|
605
|
+
console.error('');
|
|
606
|
+
console.error(generateCommandHelp('tokens'));
|
|
607
|
+
return process.exit(1);
|
|
605
608
|
}
|
|
606
609
|
}
|
|
607
610
|
break;
|
|
@@ -703,10 +706,17 @@ function run() {
|
|
|
703
706
|
}
|
|
704
707
|
break;
|
|
705
708
|
|
|
706
|
-
|
|
709
|
+
case '':
|
|
707
710
|
// run normally
|
|
708
711
|
require('../server');
|
|
709
712
|
break;
|
|
713
|
+
|
|
714
|
+
default:
|
|
715
|
+
// A mistyped command used to start the server instead
|
|
716
|
+
console.error(`Unknown command: ${cmd}`);
|
|
717
|
+
console.error('');
|
|
718
|
+
console.error('Run "emailengine help" to see available commands.');
|
|
719
|
+
return process.exit(1);
|
|
710
720
|
}
|
|
711
721
|
}
|
|
712
722
|
|
package/config/default.toml
CHANGED
|
@@ -46,11 +46,6 @@ proxy = false # Set to true if using HAProxy with send-proxy option
|
|
|
46
46
|
#maxMessageSize = "25M" # maximum message size accepted by SMTP server (default: 25MB)
|
|
47
47
|
#maxClients = 100 # concurrent SMTP server connections; excess connections are refused with a 421 (default: 100)
|
|
48
48
|
|
|
49
|
-
[documentStore]
|
|
50
|
-
# Deprecated Document Store (ElasticSearch) feature. Disabled by default; the worker and
|
|
51
|
-
# all document-store API/UI endpoints are only available when this is enabled.
|
|
52
|
-
enabled = false
|
|
53
|
-
|
|
54
49
|
[mcp]
|
|
55
50
|
# MCP (Model Context Protocol) endpoint at /mcp. This deployment-level gate controls whether
|
|
56
51
|
# the endpoint exists in the route table at all; the runtime on/off switch is the mcpEnabled
|
package/config/test.toml
CHANGED
package/encrypt.js
CHANGED
|
@@ -13,8 +13,10 @@ try {
|
|
|
13
13
|
|
|
14
14
|
const { redis } = require('./lib/db');
|
|
15
15
|
const config = require('@zone-eu/wild-config');
|
|
16
|
-
const {
|
|
16
|
+
const { reencrypt } = require('./lib/encrypt');
|
|
17
17
|
const { encryptedKeys } = require('./lib/settings');
|
|
18
|
+
const { ENCRYPTED_ACCOUNT_FIELDS } = require('./lib/account');
|
|
19
|
+
const { ENCRYPTED_ROUTE_FIELDS } = require('./lib/webhooks');
|
|
18
20
|
const getSecret = require('./lib/get-secret');
|
|
19
21
|
const msgpack = require('./lib/msgpack');
|
|
20
22
|
|
|
@@ -24,47 +26,7 @@ const { TLS_KEY } = require('./lib/tls/store');
|
|
|
24
26
|
|
|
25
27
|
const DECRYPT_PASSWORDS = [].concat(config.decrypt || []);
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
let lastErr = false;
|
|
29
|
-
let decrypted = value;
|
|
30
|
-
|
|
31
|
-
for (let password of DECRYPT_PASSWORDS) {
|
|
32
|
-
try {
|
|
33
|
-
decrypted = decrypt(value, password);
|
|
34
|
-
if (password === encryptSecret) {
|
|
35
|
-
// nothing was changed
|
|
36
|
-
return value;
|
|
37
|
-
}
|
|
38
|
-
break;
|
|
39
|
-
} catch (err) {
|
|
40
|
-
lastErr = err;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
let parsed = parseEncryptedData(decrypted);
|
|
45
|
-
if (parsed.format !== 'cleartext') {
|
|
46
|
-
// was not able to decrypt
|
|
47
|
-
if (encryptSecret) {
|
|
48
|
-
try {
|
|
49
|
-
decrypted = decrypt(value, encryptSecret);
|
|
50
|
-
// did not throw, so the value is already encrypted with the new password
|
|
51
|
-
return value;
|
|
52
|
-
} catch (err) {
|
|
53
|
-
// ignore
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
throw lastErr || new Error('Could not decrypt encrypted password');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (encryptSecret) {
|
|
61
|
-
// encrypt
|
|
62
|
-
return encrypt(decrypted, encryptSecret);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// return plaintext
|
|
66
|
-
return decrypted;
|
|
67
|
-
}
|
|
29
|
+
const processSecret = (value, encryptSecret) => reencrypt(value, DECRYPT_PASSWORDS, encryptSecret);
|
|
68
30
|
|
|
69
31
|
async function main() {
|
|
70
32
|
console.error('EmailEngine account encryption tool');
|
|
@@ -163,6 +125,23 @@ async function main() {
|
|
|
163
125
|
}
|
|
164
126
|
}
|
|
165
127
|
|
|
128
|
+
// The credential-bearing fields stored as plain strings (webhooksCustomHeaders is its JSON
|
|
129
|
+
// encoding); '' is a cleared marker and stays as it is
|
|
130
|
+
for (let key of ENCRYPTED_ACCOUNT_FIELDS) {
|
|
131
|
+
if (!accountData[key] || typeof accountData[key] !== 'string') {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
let value = await processSecret(accountData[key], encryptSecret);
|
|
136
|
+
if (value !== accountData[key]) {
|
|
137
|
+
updates[key] = value;
|
|
138
|
+
updated = true;
|
|
139
|
+
}
|
|
140
|
+
} catch (err) {
|
|
141
|
+
console.error(`Could not process "${key}" for ${account}. Check decryption secrets.`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
166
145
|
if (updated) {
|
|
167
146
|
let result = await redis.hmset(`${REDIS_PREFIX}iad:${account}`, updates);
|
|
168
147
|
if (result === 'OK') {
|
|
@@ -249,6 +228,55 @@ async function main() {
|
|
|
249
228
|
|
|
250
229
|
console.log(`Updated ${updatedApps}/${apps.length} OAuth2 apps`);
|
|
251
230
|
|
|
231
|
+
// Custom webhook routes: the target URL and the custom header list inside each route's msgpack
|
|
232
|
+
// meta entry. A route written before these were encrypted holds the headers as an array, which
|
|
233
|
+
// is converted to the JSON string form lib/webhooks.js stores.
|
|
234
|
+
let updatedRoutes = 0;
|
|
235
|
+
let routes = await redis.smembers(`${REDIS_PREFIX}wh:i`);
|
|
236
|
+
for (let route of routes) {
|
|
237
|
+
let metaBuf = await redis.hgetBuffer(`${REDIS_PREFIX}wh:c`, `${route}:meta`);
|
|
238
|
+
if (!metaBuf) {
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
let meta;
|
|
243
|
+
try {
|
|
244
|
+
meta = msgpack.decode(metaBuf);
|
|
245
|
+
} catch (err) {
|
|
246
|
+
console.log(`Webhook route ${route}: failed to parse`);
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
try {
|
|
251
|
+
let routeUpdated = false;
|
|
252
|
+
for (let key of ENCRYPTED_ROUTE_FIELDS) {
|
|
253
|
+
let stored = Array.isArray(meta[key]) ? JSON.stringify(meta[key]) : meta[key];
|
|
254
|
+
if (!stored || typeof stored !== 'string') {
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
let value = await processSecret(stored, encryptSecret);
|
|
258
|
+
if (value !== meta[key]) {
|
|
259
|
+
meta[key] = value;
|
|
260
|
+
routeUpdated = true;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (routeUpdated) {
|
|
265
|
+
let result = await redis.hmset(`${REDIS_PREFIX}wh:c`, { [`${route}:meta`]: msgpack.encode(meta) });
|
|
266
|
+
if (result === 'OK') {
|
|
267
|
+
console.log(`Webhook route ${route}: updated`);
|
|
268
|
+
} else {
|
|
269
|
+
console.log(`Webhook route ${route}: Unexpected response from DB: ${result}`);
|
|
270
|
+
}
|
|
271
|
+
updatedRoutes++;
|
|
272
|
+
}
|
|
273
|
+
} catch (err) {
|
|
274
|
+
console.error(`Could not process encrypted values for webhook route ${route}. Check decryption secrets.`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
console.log(`Updated ${updatedRoutes}/${routes.length} webhook routes`);
|
|
279
|
+
|
|
252
280
|
// TLS private keys managed by @postalsys/certs. These live in the module's own hash, not in the
|
|
253
281
|
// EmailEngine settings hash, so they need their own pass - without it a rotation leaves the ACME
|
|
254
282
|
// account key and every domain key readable only with the old secret, and TLS fails on the next
|
package/getswagger.sh
CHANGED
|
@@ -4,10 +4,6 @@ set -e
|
|
|
4
4
|
|
|
5
5
|
export EENGINE_PORT=5678
|
|
6
6
|
|
|
7
|
-
# Keep the deprecated Document Store endpoints in the generated spec; they are only
|
|
8
|
-
# registered when the feature is enabled.
|
|
9
|
-
export EENGINE_DOCUMENT_STORE_ENABLED=true
|
|
10
|
-
|
|
11
7
|
# refuse to run if something is already listening on the port, otherwise the
|
|
12
8
|
# polling loop below would silently fetch swagger.json from a stale instance
|
|
13
9
|
if (exec 3<>"/dev/tcp/127.0.0.1/${EENGINE_PORT}") 2>/dev/null; then
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const Boom = require('@hapi/boom');
|
|
4
|
-
const { REDIS_PREFIX } = require('../consts');
|
|
5
4
|
|
|
6
5
|
// Account state constants
|
|
7
6
|
const ACCOUNT_STATES = {
|
|
@@ -92,102 +91,6 @@ function validateAccountState(accountData) {
|
|
|
92
91
|
throw error;
|
|
93
92
|
}
|
|
94
93
|
|
|
95
|
-
/**
|
|
96
|
-
* Gets the account state from Redis
|
|
97
|
-
* @param {Object} redis - Redis client
|
|
98
|
-
* @param {string} account - Account ID
|
|
99
|
-
* @returns {Promise<string|null>} The current state value
|
|
100
|
-
*/
|
|
101
|
-
async function getAccountState(redis, account) {
|
|
102
|
-
const accountKey = `${REDIS_PREFIX}iad:${account}`;
|
|
103
|
-
return await redis.hget(accountKey, 'state');
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Sets the account state in Redis
|
|
108
|
-
* Only updates if the account exists
|
|
109
|
-
* @param {Object} redis - Redis client
|
|
110
|
-
* @param {string} account - Account ID
|
|
111
|
-
* @param {string} state - New state value
|
|
112
|
-
* @returns {Promise<boolean>} True if state was set
|
|
113
|
-
*/
|
|
114
|
-
async function setAccountState(redis, account, state) {
|
|
115
|
-
const accountKey = `${REDIS_PREFIX}iad:${account}`;
|
|
116
|
-
const result = await redis.hSetExists(accountKey, 'state', state);
|
|
117
|
-
return result === 1;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Gets the last error state for an account
|
|
122
|
-
* @param {Object} redis - Redis client
|
|
123
|
-
* @param {string} account - Account ID
|
|
124
|
-
* @returns {Promise<Object|null>} Parsed error state object or null
|
|
125
|
-
*/
|
|
126
|
-
async function getLastErrorState(redis, account) {
|
|
127
|
-
const accountKey = `${REDIS_PREFIX}iad:${account}`;
|
|
128
|
-
const errorState = await redis.hget(accountKey, 'lastErrorState');
|
|
129
|
-
|
|
130
|
-
if (!errorState) {
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
return JSON.parse(errorState);
|
|
136
|
-
} catch (err) {
|
|
137
|
-
return null;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Sets the last error state for an account
|
|
143
|
-
* @param {Object} redis - Redis client
|
|
144
|
-
* @param {string} account - Account ID
|
|
145
|
-
* @param {Object} errorData - Error state data
|
|
146
|
-
* @returns {Promise<boolean>} True if error state was set
|
|
147
|
-
*/
|
|
148
|
-
async function setLastErrorState(redis, account, errorData) {
|
|
149
|
-
const accountKey = `${REDIS_PREFIX}iad:${account}`;
|
|
150
|
-
const result = await redis.hSetExists(accountKey, 'lastErrorState', JSON.stringify(errorData));
|
|
151
|
-
return result === 1;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Clears the last error state for an account
|
|
156
|
-
* @param {Object} redis - Redis client
|
|
157
|
-
* @param {string} account - Account ID
|
|
158
|
-
* @returns {Promise<number>} Number of fields removed
|
|
159
|
-
*/
|
|
160
|
-
async function clearLastErrorState(redis, account) {
|
|
161
|
-
const accountKey = `${REDIS_PREFIX}iad:${account}`;
|
|
162
|
-
return await redis.hdel(accountKey, 'lastErrorState');
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Gets the connection count for a specific state
|
|
167
|
-
* @param {Object} redis - Redis client
|
|
168
|
-
* @param {string} account - Account ID
|
|
169
|
-
* @param {string} state - State to get count for
|
|
170
|
-
* @returns {Promise<number>} Connection count
|
|
171
|
-
*/
|
|
172
|
-
async function getStateCount(redis, account, state) {
|
|
173
|
-
const accountKey = `${REDIS_PREFIX}iad:${account}`;
|
|
174
|
-
const count = await redis.hget(accountKey, `state:count:${state}`);
|
|
175
|
-
return parseInt(count, 10) || 0;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Resets the connection count for a specific state
|
|
180
|
-
* @param {Object} redis - Redis client
|
|
181
|
-
* @param {string} account - Account ID
|
|
182
|
-
* @param {string} state - State to reset count for
|
|
183
|
-
* @returns {Promise<boolean>} True if count was reset
|
|
184
|
-
*/
|
|
185
|
-
async function resetStateCount(redis, account, state) {
|
|
186
|
-
const accountKey = `${REDIS_PREFIX}iad:${account}`;
|
|
187
|
-
const result = await redis.hset(accountKey, `state:count:${state}`, '0');
|
|
188
|
-
return result >= 0;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
94
|
// A stored timestamp is only as good as whatever wrote it: a corrupt or hand-edited record must
|
|
192
95
|
// degrade to null rather than fail the response schema and 500 the endpoint
|
|
193
96
|
function isoOrNull(date) {
|
|
@@ -298,18 +201,7 @@ module.exports = {
|
|
|
298
201
|
validateAccountState,
|
|
299
202
|
getDisplayState,
|
|
300
203
|
|
|
301
|
-
//
|
|
302
|
-
getAccountState,
|
|
303
|
-
setAccountState,
|
|
304
|
-
|
|
305
|
-
// Error state management
|
|
306
|
-
getLastErrorState,
|
|
307
|
-
setLastErrorState,
|
|
308
|
-
clearLastErrorState,
|
|
204
|
+
// Error state formatting
|
|
309
205
|
formatLastError,
|
|
310
|
-
formatGmailWatch
|
|
311
|
-
|
|
312
|
-
// State counters
|
|
313
|
-
getStateCount,
|
|
314
|
-
resetStateCount
|
|
206
|
+
formatGmailWatch
|
|
315
207
|
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// One-time sweep of the store behind the retired `bounces` response field: the per-account hash
|
|
4
|
+
// `iar:b:<account>` every detected bounce used to append to, which nothing trimmed and nothing reads
|
|
5
|
+
// or writes any more. The accounts are walked rather than the keyspace scanned, because the store
|
|
6
|
+
// only ever existed for an account in the set (deleting the account unlinked it). A completion key
|
|
7
|
+
// makes the sweep run once; delete SWEEP_KEY and restart to re-arm it.
|
|
8
|
+
|
|
9
|
+
const { redis } = require('../db');
|
|
10
|
+
const logger = require('../logger');
|
|
11
|
+
const { REDIS_PREFIX } = require('../consts');
|
|
12
|
+
|
|
13
|
+
// Marks the sweep as done for this Redis. Value is the ISO time of the run.
|
|
14
|
+
const SWEEP_KEY = `${REDIS_PREFIX}migration:bounceStoreRemoved`;
|
|
15
|
+
|
|
16
|
+
// Accounts unlinked per pipeline, matching the chunking of the auth-failure backfill
|
|
17
|
+
const CHUNK_SIZE = 500;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Deletes every account's bounce store, once.
|
|
21
|
+
*
|
|
22
|
+
* @param {Object} [opts] - Overrides for tests; the defaults are the shared clients
|
|
23
|
+
* @param {Object} [opts.redis] - ioredis client
|
|
24
|
+
* @param {Object} [opts.logger] - Logger
|
|
25
|
+
* @returns {Promise<Number>} How many stores were deleted
|
|
26
|
+
*/
|
|
27
|
+
async function sweepBounceStore(opts = {}) {
|
|
28
|
+
const { redis: client = redis, logger: log = logger } = opts;
|
|
29
|
+
|
|
30
|
+
// The common case is an instance that has already swept, and this is the whole cost for it
|
|
31
|
+
if (await client.exists(SWEEP_KEY)) {
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const accounts = await client.smembers(`${REDIS_PREFIX}ia:accounts`);
|
|
36
|
+
|
|
37
|
+
// Counted from the replies: UNLINK answers 1 only for a key that existed. A failed reply throws
|
|
38
|
+
// before the completion key is written, so the next startup runs the sweep again
|
|
39
|
+
let deleted = 0;
|
|
40
|
+
for (let i = 0; i < accounts.length; i += CHUNK_SIZE) {
|
|
41
|
+
const req = client.pipeline();
|
|
42
|
+
for (const account of accounts.slice(i, i + CHUNK_SIZE)) {
|
|
43
|
+
req.unlink(`${REDIS_PREFIX}iar:b:${account}`);
|
|
44
|
+
}
|
|
45
|
+
for (const [err, count] of await req.exec()) {
|
|
46
|
+
if (err) {
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
deleted += count ? 1 : 0;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Written last, so a crash mid-sweep re-enters and finishes it
|
|
54
|
+
await client.set(SWEEP_KEY, new Date().toISOString());
|
|
55
|
+
|
|
56
|
+
if (deleted) {
|
|
57
|
+
log.info({ msg: 'Deleted the bounce store of earlier versions', accounts: deleted });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return deleted;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = { sweepBounceStore, SWEEP_KEY };
|
|
@@ -54,7 +54,7 @@ function matchesExpectedIdentity(expectedEmail, identities) {
|
|
|
54
54
|
//
|
|
55
55
|
// Redis is read lazily, only on that fallback: a pinned link would otherwise pay a round trip for a value
|
|
56
56
|
// it always discards. Reads the field directly rather than through Account.loadAccountData(), which
|
|
57
|
-
// hgetalls and decrypts the whole record
|
|
57
|
+
// hgetalls and decrypts the whole record.
|
|
58
58
|
// The expectation carried by a pending OAuth2 setup, whichever of the two shapes it arrives in.
|
|
59
59
|
//
|
|
60
60
|
// Both are written by the server for an authenticated caller and stored under a random nonce, so they are
|