emailengine-app 2.72.0 → 2.72.2
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/CHANGELOG.md +16 -0
- package/data/google-crawlers.json +1 -1
- package/lib/account/account-state.js +5 -0
- package/lib/account.js +70 -6
- package/lib/api-routes/route-helpers.js +11 -5
- package/lib/autodetect-imap-settings.js +6 -0
- package/lib/email-client/gmail-client.js +41 -1
- package/lib/email-client/outlook-client.js +34 -6
- package/lib/email-client/smtp-pool-manager.js +2 -1
- package/package.json +14 -14
- package/sbom.json +1 -1
- package/static/licenses.html +139 -49
- package/translations/messages.pot +9 -9
- package/Fluid-Attacks-Results.csv +0 -1
- package/test-coverage-plan.md +0 -233
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.72.2](https://github.com/postalsys/emailengine/compare/v2.72.1...v2.72.2) (2026-06-26)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* reconnect error-state accounts after OAuth re-auth via create() ([77cee1e](https://github.com/postalsys/emailengine/commit/77cee1eb1916fbd6582cfcf931023d53f6cc8abf))
|
|
9
|
+
* resume sync after OAuth re-auth and enable Run sync for Gmail/Outlook ([f3bef82](https://github.com/postalsys/emailengine/commit/f3bef823ee90cd6fcf90b95fadcb6f2730657441))
|
|
10
|
+
* update dependencies (libmime 5.4.0, mailparser 3.9.12, imapflow 1.4.3, email-ai-tools 1.13.9) ([8c999d8](https://github.com/postalsys/emailengine/commit/8c999d8c5e6b550c6d3a28fd4ec118c48d095901))
|
|
11
|
+
|
|
12
|
+
## [2.72.1](https://github.com/postalsys/emailengine/compare/v2.72.0...v2.72.1) (2026-06-19)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* log expected API client errors (4xx) at warn instead of error ([c51e347](https://github.com/postalsys/emailengine/commit/c51e3476e346f321af845905a89141bf07a83421))
|
|
18
|
+
|
|
3
19
|
## [2.72.0](https://github.com/postalsys/emailengine/compare/v2.71.0...v2.72.0) (2026-06-18)
|
|
4
20
|
|
|
5
21
|
|
|
@@ -17,6 +17,10 @@ const ACCOUNT_STATES = {
|
|
|
17
17
|
// States that indicate the account is operational
|
|
18
18
|
const VALID_STATES = [ACCOUNT_STATES.CONNECTED, ACCOUNT_STATES.CONNECTING, ACCOUNT_STATES.SYNCING];
|
|
19
19
|
|
|
20
|
+
// Non-operational error states. Re-authorizing / re-saving credentials for an account in one of
|
|
21
|
+
// these states should trigger a full reconnect so syncing resumes.
|
|
22
|
+
const ERROR_STATES = [ACCOUNT_STATES.AUTHENTICATION_ERROR, ACCOUNT_STATES.CONNECT_ERROR];
|
|
23
|
+
|
|
20
24
|
// States that bypass runIndex checking
|
|
21
25
|
const BYPASS_RUN_INDEX_STATES = [ACCOUNT_STATES.INIT, ACCOUNT_STATES.UNSET];
|
|
22
26
|
|
|
@@ -225,6 +229,7 @@ module.exports = {
|
|
|
225
229
|
// Constants
|
|
226
230
|
ACCOUNT_STATES,
|
|
227
231
|
VALID_STATES,
|
|
232
|
+
ERROR_STATES,
|
|
228
233
|
BYPASS_RUN_INDEX_STATES,
|
|
229
234
|
|
|
230
235
|
// State calculation
|
package/lib/account.js
CHANGED
|
@@ -29,7 +29,7 @@ const nanoid = customAlphabet('0123456789abcdefghijklmnopqrstuvwxyz', 16);
|
|
|
29
29
|
const { REDIS_PREFIX, ACCOUNT_DELETED_NOTIFY, MAILBOX_HASH } = require('./consts');
|
|
30
30
|
const { mimeHtml } = require('@postalsys/email-text-tools');
|
|
31
31
|
const { checkAccountScopes: checkScopes } = require('./oauth/scope-checker');
|
|
32
|
-
const { ACCOUNT_STATES, calculateEffectiveState, validateAccountState, getDisplayState, formatLastError } = require('./account/account-state');
|
|
32
|
+
const { ACCOUNT_STATES, ERROR_STATES, calculateEffectiveState, validateAccountState, getDisplayState, formatLastError } = require('./account/account-state');
|
|
33
33
|
|
|
34
34
|
// Shared Lock instance to prevent Redis connection leak (one subscriber per Lock instance)
|
|
35
35
|
// Previously, each Account created its own Lock, causing ~30k connections with 30k accounts
|
|
@@ -848,6 +848,39 @@ class Account {
|
|
|
848
848
|
});
|
|
849
849
|
}
|
|
850
850
|
|
|
851
|
+
// When OAuth2 credentials are re-authorized for an account that is currently in a
|
|
852
|
+
// non-operational error state, trigger a full reconnect so syncing resumes without a
|
|
853
|
+
// manual "Reconnect". Gated on the error state and on the credentials actually
|
|
854
|
+
// changing, so routine token renewal - which runs while the account is connected and
|
|
855
|
+
// re-saves oauth2 hourly - never triggers a reconnect. During an actual reconnect the
|
|
856
|
+
// state is set to "connecting" before tokens are fetched, so this cannot loop.
|
|
857
|
+
if (
|
|
858
|
+
!reconnectRequested &&
|
|
859
|
+
'oauth2' in accountData &&
|
|
860
|
+
accountData.oauth2?.accessToken &&
|
|
861
|
+
(accountData.oauth2.accessToken !== oldAccountData.oauth2?.accessToken ||
|
|
862
|
+
accountData.oauth2.refreshToken !== oldAccountData.oauth2?.refreshToken) &&
|
|
863
|
+
ERROR_STATES.includes(oldAccountData.state)
|
|
864
|
+
) {
|
|
865
|
+
this.logger.info({
|
|
866
|
+
msg: 'OAuth2 credentials re-authorized for account in error state, requesting reconnect',
|
|
867
|
+
account: this.account,
|
|
868
|
+
state: oldAccountData.state
|
|
869
|
+
});
|
|
870
|
+
try {
|
|
871
|
+
await this.call({
|
|
872
|
+
cmd: 'reconnect',
|
|
873
|
+
account: this.account,
|
|
874
|
+
timeout: this.timeout
|
|
875
|
+
});
|
|
876
|
+
} catch (err) {
|
|
877
|
+
// Credentials are already persisted; a failed reconnect dispatch must not turn a
|
|
878
|
+
// saved credential update into an error response. The next periodic reconnect
|
|
879
|
+
// recovers. Log and continue.
|
|
880
|
+
this.logger.error({ msg: 'Failed to request reconnect after credential update', account: this.account, state: oldAccountData.state, err });
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
|
|
851
884
|
return {
|
|
852
885
|
account: this.account
|
|
853
886
|
};
|
|
@@ -961,11 +994,42 @@ class Account {
|
|
|
961
994
|
// ignore
|
|
962
995
|
}
|
|
963
996
|
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
account
|
|
967
|
-
|
|
968
|
-
|
|
997
|
+
const oldState = result[0][1].state;
|
|
998
|
+
if (ERROR_STATES.includes(oldState)) {
|
|
999
|
+
// Re-registration of an account that was in a non-operational error state (the
|
|
1000
|
+
// interactive OAuth re-auth redirect and the IMAP re-credentials form both land here).
|
|
1001
|
+
// cmd:'update' only calls reconnect() on the existing client instance, which cannot
|
|
1002
|
+
// switch client type (IMAP to API or back) and is a no-op against a torn-down
|
|
1003
|
+
// connection, so syncing would not resume without a manual "Reconnect". cmd:'reconnect'
|
|
1004
|
+
// closes and re-assigns a fresh client of the correct provider type. assignConnection
|
|
1005
|
+
// sets the state to "connecting" before any network work, so this cannot loop.
|
|
1006
|
+
// Gated on the error state alone (unlike update(), which also requires the oauth2
|
|
1007
|
+
// token to have changed): create() runs only on explicit re-registration, never on
|
|
1008
|
+
// routine token renewal, so there is no healthy-account churn to suppress here.
|
|
1009
|
+
this.logger.info({
|
|
1010
|
+
msg: 'Account re-created while in error state, requesting full reconnect',
|
|
1011
|
+
account: this.account,
|
|
1012
|
+
state: oldState
|
|
1013
|
+
});
|
|
1014
|
+
try {
|
|
1015
|
+
await this.call({
|
|
1016
|
+
cmd: 'reconnect',
|
|
1017
|
+
account: this.account,
|
|
1018
|
+
timeout: this.timeout
|
|
1019
|
+
});
|
|
1020
|
+
} catch (err) {
|
|
1021
|
+
// Credentials are already persisted (the hmset above returned OK). A failed
|
|
1022
|
+
// reconnect dispatch must not fail the re-auth or surface a 500; the next periodic
|
|
1023
|
+
// reconnect or a manual Reconnect will recover. Log and continue.
|
|
1024
|
+
this.logger.error({ msg: 'Failed to request reconnect after re-auth', account: this.account, state: oldState, err });
|
|
1025
|
+
}
|
|
1026
|
+
} else {
|
|
1027
|
+
await this.call({
|
|
1028
|
+
cmd: 'update',
|
|
1029
|
+
account: this.account,
|
|
1030
|
+
timeout: this.timeout
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
969
1033
|
} else {
|
|
970
1034
|
state = 'new';
|
|
971
1035
|
await this.call({
|
|
@@ -9,14 +9,20 @@ const Boom = require('@hapi/boom');
|
|
|
9
9
|
// machine-readable err.code. This function ALWAYS throws and never returns a value, so callers use it
|
|
10
10
|
// as the final statement inside a catch block: `catch (err) { handleError(request, err); }`.
|
|
11
11
|
function handleError(request, err) {
|
|
12
|
-
request.logger.error({ msg: 'API request failed', err });
|
|
13
|
-
if (Boom.isBoom(err)) {
|
|
14
|
-
throw err;
|
|
15
|
-
}
|
|
16
12
|
// Lower-level libraries (e.g. ImapFlow) flag "this server lacks the required capability" with a
|
|
17
13
|
// machine code but no HTTP status. Surface it as a 422 client error instead of a generic 500 - the
|
|
18
14
|
// request is well-formed, the account just cannot satisfy it (e.g. label search on non-Gmail IMAP).
|
|
19
|
-
let
|
|
15
|
+
let isBoom = Boom.isBoom(err);
|
|
16
|
+
let statusCode = isBoom ? err.output.statusCode : err.statusCode || (err.code === 'MissingServerExtension' ? 422 : 500);
|
|
17
|
+
|
|
18
|
+
// Log expected client errors (4xx, e.g. a 404 from an existence-check probe) at warn so they do not
|
|
19
|
+
// flood the error stream, while genuine server faults (5xx) stay at error.
|
|
20
|
+
let logLevel = statusCode >= 400 && statusCode < 500 ? 'warn' : 'error';
|
|
21
|
+
request.logger[logLevel]({ msg: 'API request failed', statusCode, err });
|
|
22
|
+
|
|
23
|
+
if (isBoom) {
|
|
24
|
+
throw err;
|
|
25
|
+
}
|
|
20
26
|
const error = Boom.boomify(err, { statusCode });
|
|
21
27
|
if (err.code) {
|
|
22
28
|
error.output.payload.code = err.code;
|
|
@@ -777,3 +777,9 @@ async function autodetectImapSettings(email, gt) {
|
|
|
777
777
|
}
|
|
778
778
|
|
|
779
779
|
module.exports.autodetectImapSettings = autodetectImapSettings;
|
|
780
|
+
|
|
781
|
+
// Exposed for unit testing of the pure parsing/matching helpers. These have no
|
|
782
|
+
// network side effects, so they can be exercised directly without mocking DNS or HTTP.
|
|
783
|
+
module.exports.processAutoconfigFile = processAutoconfigFile;
|
|
784
|
+
module.exports.getAppPassword = getAppPassword;
|
|
785
|
+
module.exports.escapeXml = escapeXml;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { Account } = require('../account');
|
|
4
4
|
const { oauth2Apps } = require('../oauth2-apps');
|
|
5
|
-
const { checkAccountScopes } = require('../oauth/scope-checker');
|
|
5
|
+
const { checkAccountScopes, isSendOnlyByScopes } = require('../oauth/scope-checker');
|
|
6
6
|
const getSecret = require('../get-secret');
|
|
7
7
|
const msgpack = require('msgpack5')();
|
|
8
8
|
const addressparser = require('nodemailer/lib/addressparser');
|
|
@@ -509,6 +509,46 @@ class GmailClient extends BaseClient {
|
|
|
509
509
|
return null;
|
|
510
510
|
}
|
|
511
511
|
|
|
512
|
+
/**
|
|
513
|
+
* Performs an on-demand catch-up sync. Triggered by the "Run sync" action
|
|
514
|
+
* (PUT /v1/account/{account}/sync). Gmail has no folder-walk sync like IMAP; instead it
|
|
515
|
+
* reads the current history checkpoint and processes anything that arrived since the last
|
|
516
|
+
* stored historyId, reusing the same code path as live Pub/Sub notifications.
|
|
517
|
+
*/
|
|
518
|
+
async syncMailboxes() {
|
|
519
|
+
if (this.closed) {
|
|
520
|
+
return null;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
let accountData = await this.accountObject.loadAccountData(this.account, false);
|
|
524
|
+
|
|
525
|
+
// Send-only accounts have no mailbox to sync
|
|
526
|
+
if (isSendOnlyByScopes('gmail', accountData)) {
|
|
527
|
+
return null;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
let profileRes;
|
|
531
|
+
try {
|
|
532
|
+
profileRes = await this.request(`${GMAIL_API_BASE}/gmail/v1/users/me/profile`);
|
|
533
|
+
} catch (err) {
|
|
534
|
+
this.logger.error({ msg: 'Failed to fetch profile for manual sync', account: this.account, err });
|
|
535
|
+
return null;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
let currentHistoryId = Number(profileRes?.historyId) || null;
|
|
539
|
+
// googleHistoryId is already loaded with the account data; reuse it (matches init())
|
|
540
|
+
let storedHistoryId = Number(accountData.googleHistoryId) || null;
|
|
541
|
+
|
|
542
|
+
if (currentHistoryId && storedHistoryId && currentHistoryId > storedHistoryId) {
|
|
543
|
+
// Reuse triggerSync so the processingHistory guard prevents overlap with a
|
|
544
|
+
// concurrent Pub/Sub-driven sync. triggerSync is fire-and-forget but catches its
|
|
545
|
+
// own errors, so it cannot produce an unhandled rejection.
|
|
546
|
+
this.triggerSync(storedHistoryId, currentHistoryId);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
return true;
|
|
550
|
+
}
|
|
551
|
+
|
|
512
552
|
async currentState() {
|
|
513
553
|
return (await this.redis.hget(this.getAccountKey(), 'state')) || 'disconnected';
|
|
514
554
|
}
|
|
@@ -409,6 +409,28 @@ class OutlookClient extends BaseClient {
|
|
|
409
409
|
return null;
|
|
410
410
|
}
|
|
411
411
|
|
|
412
|
+
/**
|
|
413
|
+
* Performs an on-demand catch-up sync. Triggered by the "Run sync" action
|
|
414
|
+
* (PUT /v1/account/{account}/sync). Outlook syncs via webhook subscriptions and delta
|
|
415
|
+
* queries rather than a folder walk, so a manual sync refreshes the folder cache and runs
|
|
416
|
+
* the missed-notification recovery (with the cooldown bypassed for this explicit action).
|
|
417
|
+
*/
|
|
418
|
+
async syncMailboxes() {
|
|
419
|
+
if (this.closed) {
|
|
420
|
+
return null;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
try {
|
|
424
|
+
await this.renewMailboxFolderCache();
|
|
425
|
+
} catch (err) {
|
|
426
|
+
this.logger.error({ msg: 'Failed to refresh folder cache for manual sync', account: this.account, err });
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
await this.syncMissedMessages({ force: true });
|
|
430
|
+
|
|
431
|
+
return true;
|
|
432
|
+
}
|
|
433
|
+
|
|
412
434
|
/**
|
|
413
435
|
* Get the current connection state from Redis
|
|
414
436
|
*/
|
|
@@ -3968,13 +3990,19 @@ class OutlookClient extends BaseClient {
|
|
|
3968
3990
|
* Queries recent messages and processes any not already seen via normal webhooks.
|
|
3969
3991
|
* @returns {boolean} Whether recovery ran (false if debounced)
|
|
3970
3992
|
*/
|
|
3971
|
-
async syncMissedMessages() {
|
|
3972
|
-
|
|
3993
|
+
async syncMissedMessages(opts) {
|
|
3994
|
+
let { force } = opts || {};
|
|
3995
|
+
|
|
3996
|
+
// Debounce: skip if recovery already ran recently. A manual "Run sync" passes
|
|
3997
|
+
// force:true to bypass the cooldown; duplicate suppression is still handled per
|
|
3998
|
+
// message by rollingBucketLock below, so forcing cannot re-emit seen messages.
|
|
3973
3999
|
const cooldownKey = `${REDIS_PREFIX}iam:${this.account}:missedRecovery`;
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
4000
|
+
if (!force) {
|
|
4001
|
+
const acquired = await this.redis.set(cooldownKey, '1', 'EX', 300, 'NX');
|
|
4002
|
+
if (!acquired) {
|
|
4003
|
+
this.logger.debug({ msg: 'Missed notification recovery skipped (cooldown active)', account: this.account });
|
|
4004
|
+
return false;
|
|
4005
|
+
}
|
|
3978
4006
|
}
|
|
3979
4007
|
|
|
3980
4008
|
// Determine lookback window
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "emailengine-app",
|
|
3
|
-
"version": "2.72.
|
|
3
|
+
"version": "2.72.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"productTitle": "EmailEngine",
|
|
6
6
|
"description": "Email Sync Engine",
|
|
@@ -62,19 +62,19 @@
|
|
|
62
62
|
"@postalsys/bounce-classifier": "3.0.0",
|
|
63
63
|
"@postalsys/certs": "1.0.15",
|
|
64
64
|
"@postalsys/ee-client": "1.3.0",
|
|
65
|
-
"@postalsys/email-ai-tools": "1.13.
|
|
66
|
-
"@postalsys/email-text-tools": "2.4.
|
|
65
|
+
"@postalsys/email-ai-tools": "1.13.9",
|
|
66
|
+
"@postalsys/email-text-tools": "2.4.9",
|
|
67
67
|
"@postalsys/gettext": "4.1.1",
|
|
68
68
|
"@postalsys/joi-messages": "1.0.5",
|
|
69
69
|
"@postalsys/templates": "2.0.1",
|
|
70
|
-
"@sentry/node": "10.
|
|
70
|
+
"@sentry/node": "10.61.0",
|
|
71
71
|
"@simplewebauthn/browser": "13.3.0",
|
|
72
|
-
"@simplewebauthn/server": "13.3.
|
|
73
|
-
"@zone-eu/mailsplit": "5.4.
|
|
72
|
+
"@simplewebauthn/server": "13.3.2",
|
|
73
|
+
"@zone-eu/mailsplit": "5.4.13",
|
|
74
74
|
"@zone-eu/wild-config": "1.7.5",
|
|
75
75
|
"ace-builds": "1.44.0",
|
|
76
76
|
"base32.js": "0.1.0",
|
|
77
|
-
"bullmq": "5.79.
|
|
77
|
+
"bullmq": "5.79.1",
|
|
78
78
|
"compare-versions": "6.1.1",
|
|
79
79
|
"dotenv": "17.4.2",
|
|
80
80
|
"encoding-japanese": "2.2.0",
|
|
@@ -88,31 +88,31 @@
|
|
|
88
88
|
"html-to-text": "10.0.0",
|
|
89
89
|
"ical.js": "1.5.0",
|
|
90
90
|
"iconv-lite": "0.7.2",
|
|
91
|
-
"imapflow": "1.4.
|
|
91
|
+
"imapflow": "1.4.3",
|
|
92
92
|
"ioredfour": "1.4.1",
|
|
93
93
|
"ioredis": "5.11.1",
|
|
94
94
|
"ipaddr.js": "2.4.0",
|
|
95
95
|
"joi": "17.13.4",
|
|
96
96
|
"jquery": "4.0.0",
|
|
97
97
|
"libbase64": "1.3.0",
|
|
98
|
-
"libmime": "5.
|
|
98
|
+
"libmime": "5.4.0",
|
|
99
99
|
"libqp": "2.1.1",
|
|
100
100
|
"license-checker": "25.0.1",
|
|
101
|
-
"mailparser": "3.9.
|
|
101
|
+
"mailparser": "3.9.12",
|
|
102
102
|
"marked": "15.0.12",
|
|
103
103
|
"minimist": "1.2.8",
|
|
104
104
|
"msgpack5": "6.0.2",
|
|
105
105
|
"murmurhash": "2.0.1",
|
|
106
|
-
"nanoid": "3.3.
|
|
106
|
+
"nanoid": "3.3.15",
|
|
107
107
|
"nodemailer": "9.0.1",
|
|
108
108
|
"pino": "10.3.1",
|
|
109
109
|
"popper.js": "1.16.1",
|
|
110
110
|
"prom-client": "15.1.3",
|
|
111
111
|
"psl": "1.15.0",
|
|
112
|
-
"pubface": "1.1.
|
|
112
|
+
"pubface": "1.1.4",
|
|
113
113
|
"punycode.js": "2.3.1",
|
|
114
114
|
"qrcode": "1.5.4",
|
|
115
|
-
"smtp-server": "3.19.
|
|
115
|
+
"smtp-server": "3.19.1",
|
|
116
116
|
"socks": "2.8.9",
|
|
117
117
|
"speakeasy": "2.0.0",
|
|
118
118
|
"startbootstrap-sb-admin-2": "3.3.7",
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
},
|
|
123
123
|
"devDependencies": {
|
|
124
124
|
"@eslint/js": "10.0.1",
|
|
125
|
-
"@playwright/test": "1.61.
|
|
125
|
+
"@playwright/test": "1.61.1",
|
|
126
126
|
"acorn": "8.17.0",
|
|
127
127
|
"acorn-walk": "8.3.5",
|
|
128
128
|
"chai": "4.5.0",
|