emailengine-app 2.81.2 → 2.82.1
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 +33 -10
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +71 -0
- package/DOCKER_DEPLOYMENT.md +13 -12
- package/Dockerfile +2 -0
- package/bin/emailengine.js +105 -25
- 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/expected-identity.js +1 -1
- package/lib/account-assignment.js +138 -1
- package/lib/account.js +289 -869
- package/lib/api-reference/index.js +2 -3
- package/lib/api-reference/schema-tree.js +53 -3
- package/lib/api-routes/account-binding.js +58 -0
- package/lib/api-routes/account-routes.js +65 -37
- package/lib/api-routes/behavior-notes.js +4 -0
- 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 +15 -16
- 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 +50 -238
- 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 +3 -3
- 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 +20 -21
- 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 +28 -6
- package/lib/api-token-scheme.js +71 -0
- package/lib/arf-detect.js +33 -6
- package/lib/auth-token.js +44 -24
- package/lib/autodetect-imap-settings.js +305 -123
- package/lib/bounce-detect.js +25 -16
- package/lib/calendar-event.js +78 -0
- package/lib/consts.js +54 -5
- package/lib/create-imap-client.js +24 -0
- package/lib/db.js +77 -30
- package/lib/delivery-error.js +70 -2
- 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 +383 -536
- package/lib/email-client/credential-errors.js +21 -5
- 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 +77 -51
- package/lib/email-client/imap/mailbox.js +158 -324
- 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 +190 -65
- package/lib/email-client/message-builder.js +50 -25
- 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 +389 -463
- package/lib/email-client/smtp-pool-manager.js +3 -2
- package/lib/encrypt.js +184 -19
- package/lib/enum-descriptions.js +6 -3
- package/lib/export.js +141 -41
- package/lib/gateway.js +25 -6
- package/lib/get-raw-email.js +26 -44
- package/lib/get-secret.js +1 -21
- 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 +108 -36
- package/lib/message-port-stream.js +64 -6
- package/lib/oauth/external-account-signer.js +16 -13
- package/lib/oauth/gmail.js +64 -32
- package/lib/oauth/mail-ru.js +24 -17
- package/lib/oauth/outlook.js +53 -40
- package/lib/oauth/pubsub/google.js +38 -2
- package/lib/oauth/scope-checker.js +39 -8
- package/lib/oauth/scope-list.js +55 -0
- package/lib/oauth/token-fetch.js +47 -0
- package/lib/oauth/verify-app.js +2 -2
- package/lib/oauth2-apps.js +154 -90
- package/lib/openapi/build-document.js +1 -1
- package/lib/openapi/joi-schema.js +78 -9
- package/lib/outbox.js +2 -7
- 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/queue-retention.js +4 -2
- package/lib/rate-limit.js +54 -15
- package/lib/read-env-value.js +33 -2
- 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 +180 -253
- 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/token-audit-log.js +3 -2
- package/lib/tools.js +114 -53
- package/lib/totp.js +16 -1
- package/lib/ui-routes/account-routes.js +67 -70
- 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 +83 -228
- package/lib/ui-routes/route-helpers.js +63 -67
- package/lib/ui-routes/special-use-paths.js +33 -0
- 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 +11 -17
- 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 +338 -292
- package/setup-production.sh +16 -7
- 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 +349 -1740
- package/translations/messages.pot +129 -111
- package/views/account-workspace-error.hbs +30 -0
- package/views/accounts/account.hbs +9 -4
- package/views/accounts/browse.hbs +10 -4
- package/views/accounts/edit.hbs +11 -2
- package/views/config/ai.hbs +49 -41
- package/views/config/oauth/app.hbs +2 -1
- package/views/dashboard.hbs +18 -16
- package/views/internals/index.hbs +1 -1
- 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/gmail_api_scopes.hbs +16 -0
- package/views/partials/oauth_form.hbs +67 -94
- package/views/partials/oauth_pubsub_app_select.hbs +43 -0
- package/views/partials/scope_info.hbs +14 -23
- 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 +82 -47
- package/workers/export.js +55 -60
- package/workers/imap.js +132 -49
- package/workers/submit.js +5 -6
- 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/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/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
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Decisions for the stale view check of the main mailbox (EENGINE_IMAP_STALE_CHECK_INTERVAL).
|
|
5
|
+
*
|
|
6
|
+
* Some servers keep a long-lived session healthy on the wire - IDLE, NOOP, LIST and STATUS of
|
|
7
|
+
* other folders all answer OK - while the session's view of the selected mailbox stops moving.
|
|
8
|
+
* No EXISTS arrives, and a FETCH or SEARCH on that connection answers from the frozen view, so
|
|
9
|
+
* nothing the primary connection can do reveals it. A new session sees the messages, which is
|
|
10
|
+
* why the check asks a second connection and why the only remedy is reconnecting.
|
|
11
|
+
*
|
|
12
|
+
* Kept free of connection and Redis code so the rules can be tested on their own.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// A probe that finds the server ahead has to be confirmed by the next one before the primary
|
|
16
|
+
// connection is dropped. A message that landed just before the probe is normally still on its
|
|
17
|
+
// way through EXISTS and the partial sync it triggers, and the next probe no longer sees it
|
|
18
|
+
const STALE_CONFIRMATIONS = 2;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* What the primary connection knows of the main mailbox's UIDNEXT: the higher of the stored value
|
|
22
|
+
* and the one its session reports. Neither is enough alone. A partial sync stores the snapshot it
|
|
23
|
+
* took before fetching, while ImapFlow moves the session's UIDNEXT once a FETCH returns a newer
|
|
24
|
+
* UID, so the stored value trails a healthy session by one fetch. And a message delivered and
|
|
25
|
+
* expunged before the primary fetched it leaves the stored value behind the server's for good on
|
|
26
|
+
* a CONDSTORE server whose HIGHESTMODSEQ did not move, while the SELECT of the next session reports
|
|
27
|
+
* the server's value. A frozen session's UIDNEXT is as frozen as the rest of its view
|
|
28
|
+
* @param {Number|false} storedUidNext - uidNext the sync state machine last stored
|
|
29
|
+
* @param {Number|false} sessionUidNext - UIDNEXT the primary connection's session reports
|
|
30
|
+
* @returns {Number|false} The known UIDNEXT, false when neither is available
|
|
31
|
+
*/
|
|
32
|
+
function knownUidNext(storedUidNext, sessionUidNext) {
|
|
33
|
+
const values = [storedUidNext, sessionUidNext].filter(value => typeof value === 'number' && value > 0);
|
|
34
|
+
return values.length ? Math.max(...values) : false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Fresh state: the quiet period starts at `now` from this UIDNEXT
|
|
38
|
+
const baseline = (now, uidNext) => ({ checkedAt: now, uidNext, confirmations: 0 });
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Decides whether this resync pass should look at the main mailbox over a second connection.
|
|
42
|
+
* Only a connection whose known UIDNEXT has not moved for a whole interval is probed, so an
|
|
43
|
+
* account that keeps receiving mail never pays for the extra login
|
|
44
|
+
* @param {Object|null} state - State returned by the previous call on this connection, or null
|
|
45
|
+
* @param {Number|false} uidNext - Known UIDNEXT of the main mailbox, see knownUidNext()
|
|
46
|
+
* @param {Number} now - Current time in milliseconds
|
|
47
|
+
* @param {Number} interval - Quiet period before probing, in milliseconds. Falsy disables the check
|
|
48
|
+
* @returns {{ probe: Boolean, state: Object|null }} Whether to probe, and the state to keep
|
|
49
|
+
*/
|
|
50
|
+
function planStaleViewProbe(state, uidNext, now, interval) {
|
|
51
|
+
if (!interval || !uidNext) {
|
|
52
|
+
// Disabled, or a server that reports no UIDNEXT - there is nothing to compare against
|
|
53
|
+
return { probe: false, state: null };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!state || state.uidNext !== uidNext) {
|
|
57
|
+
// First pass on this connection, or something arrived since the last look. Either way
|
|
58
|
+
// it is not stale, and the quiet period starts over
|
|
59
|
+
return { probe: false, state: baseline(now, uidNext) };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (now - state.checkedAt < interval) {
|
|
63
|
+
return { probe: false, state };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// The clock restarts as the probe is decided, not when it answers: a probe that fails (the
|
|
67
|
+
// second login refused, another folder open on the primary) must wait out a whole interval
|
|
68
|
+
// like any other, not log in again on the next resync pass
|
|
69
|
+
return { probe: true, state: Object.assign({}, state, { checkedAt: now }) };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Compares the STATUS answer of a second connection with what the primary connection knows
|
|
74
|
+
* @param {Object} state - State returned by planStaleViewProbe() for the pass that probed
|
|
75
|
+
* @param {Object} known - { uidNext, uidValidity } the primary knows, read after the probe answered
|
|
76
|
+
* @param {Object|null} serverStatus - STATUS answer (uidNext, uidValidity) from the second connection
|
|
77
|
+
* @param {Number} now - Current time in milliseconds
|
|
78
|
+
* @returns {{ stale: Boolean, ahead: Boolean, state: Object|null }} Whether to drop the primary
|
|
79
|
+
* connection, whether this probe found the server ahead, and the state to keep
|
|
80
|
+
*/
|
|
81
|
+
function evaluateStaleViewProbe(state, known, serverStatus, now) {
|
|
82
|
+
if (!known.uidNext) {
|
|
83
|
+
return { stale: false, ahead: false, state: null };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!state || state.uidNext !== known.uidNext) {
|
|
87
|
+
// Something arrived on the primary connection while the probe was running - it is alive
|
|
88
|
+
return { stale: false, ahead: false, state: baseline(now, known.uidNext) };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const ahead =
|
|
92
|
+
typeof serverStatus?.uidNext === 'number' &&
|
|
93
|
+
serverStatus.uidNext > known.uidNext &&
|
|
94
|
+
// A different UIDVALIDITY is another folder incarnation, which the open handler deals
|
|
95
|
+
// with - UIDs of two incarnations say nothing about each other
|
|
96
|
+
!!known.uidValidity &&
|
|
97
|
+
known.uidValidity === serverStatus.uidValidity;
|
|
98
|
+
|
|
99
|
+
const confirmations = ahead ? state.confirmations + 1 : 0;
|
|
100
|
+
const stale = confirmations >= STALE_CONFIRMATIONS;
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
stale,
|
|
104
|
+
ahead,
|
|
105
|
+
state: { checkedAt: now, uidNext: known.uidNext, confirmations: stale ? 0 : confirmations }
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
module.exports = { knownUidNext, planStaleViewProbe, evaluateStaleViewProbe, STALE_CONFIRMATIONS };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { createImapClient } = require('../../create-imap-client');
|
|
4
4
|
const { backOff } = require('exponential-backoff');
|
|
5
5
|
const { ReconnectBackoff } = require('../reconnect-backoff');
|
|
6
6
|
const { detachImapClient } = require('./detach-client');
|
|
@@ -92,12 +92,23 @@ class Subconnection extends EventEmitter {
|
|
|
92
92
|
return false;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
try {
|
|
96
|
+
await backOff(() => this.start(), {
|
|
97
|
+
maxDelay: this.reconnectBackoff.maxDelay,
|
|
98
|
+
numOfAttempts: Infinity,
|
|
99
|
+
// A refused credential is not retried here: every subconnection would repeat
|
|
100
|
+
// the failed login every 30 seconds for the whole auth-failure park window
|
|
101
|
+
// (lockout and fail2ban territory). The primary connection owns that retry
|
|
102
|
+
retry: err => !this.isClosing && !this.isClosed && !isRefusedImapLogin(err),
|
|
103
|
+
startingDelay: 2000
|
|
104
|
+
});
|
|
105
|
+
} catch (err) {
|
|
106
|
+
if (!isRefusedImapLogin(err) || this.isClosing || this.isClosed) {
|
|
107
|
+
throw err;
|
|
108
|
+
}
|
|
109
|
+
this.disableAfterRefusedLogin();
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
101
112
|
} finally {
|
|
102
113
|
// Cleared before the mailbox validation below on purpose: if the
|
|
103
114
|
// server drops the connection while the monitored mailbox is being
|
|
@@ -174,6 +185,25 @@ class Subconnection extends EventEmitter {
|
|
|
174
185
|
}
|
|
175
186
|
}
|
|
176
187
|
|
|
188
|
+
/**
|
|
189
|
+
* Shuts the subconnection down after the server refused its credential. The entry stays
|
|
190
|
+
* disabled until the parent reconciles its subconnections again (on the next primary
|
|
191
|
+
* connection setup, or the next resync pass through the loginRefused marker), which then
|
|
192
|
+
* replaces it with a fresh connection
|
|
193
|
+
*/
|
|
194
|
+
disableAfterRefusedLogin() {
|
|
195
|
+
this.logger.warn({ msg: 'Subconnection login was refused, leaving the retry to the primary connection', path: this.path });
|
|
196
|
+
|
|
197
|
+
this.close();
|
|
198
|
+
this.imapClient = null;
|
|
199
|
+
|
|
200
|
+
// close() resets these, so set the disabled state afterwards
|
|
201
|
+
this.disabled = true;
|
|
202
|
+
this.state = 'authenticationError';
|
|
203
|
+
this.disabledReason = 'Authentication failed';
|
|
204
|
+
this.loginRefused = true;
|
|
205
|
+
}
|
|
206
|
+
|
|
177
207
|
async start() {
|
|
178
208
|
if (this.imapClient) {
|
|
179
209
|
// close previous
|
|
@@ -201,7 +231,7 @@ class Subconnection extends EventEmitter {
|
|
|
201
231
|
// this context
|
|
202
232
|
let imapConfig = await this.parent.getImapConfig(null, this);
|
|
203
233
|
|
|
204
|
-
let imapClient =
|
|
234
|
+
let imapClient = createImapClient(
|
|
205
235
|
Object.assign({}, imapConfig, {
|
|
206
236
|
logger: this.logger,
|
|
207
237
|
expungeHandler: async payload => await this.expungeHandler(payload)
|
|
@@ -215,7 +245,14 @@ class Subconnection extends EventEmitter {
|
|
|
215
245
|
imapClient.subConnection = true;
|
|
216
246
|
|
|
217
247
|
imapClient.on('error', err => {
|
|
218
|
-
imapClient
|
|
248
|
+
if (!imapClient) {
|
|
249
|
+
// The close handler already let go of this client. The missing-mailbox and
|
|
250
|
+
// refused-login shutdowns also null this.imapClient, so the identity check below
|
|
251
|
+
// would read null === null as "still current" and call close() on null
|
|
252
|
+
this.logger.warn({ msg: 'IMAP connection error', account: this.account, err });
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
imapClient.log.warn({ msg: 'IMAP connection error', account: this.account, err });
|
|
219
256
|
if (imapClient !== this.imapClient || this._connecting) {
|
|
220
257
|
return;
|
|
221
258
|
}
|
|
@@ -66,7 +66,10 @@ function isRecentFullSync(storedStatus) {
|
|
|
66
66
|
* @returns {Boolean} True if UIDVALIDITY changed
|
|
67
67
|
*/
|
|
68
68
|
function hasUidValidityChanged(storedStatus, mailboxStatus) {
|
|
69
|
-
|
|
69
|
+
// Both sides have to be real values. mailboxStatusFromInfo() reports a missing or malformed
|
|
70
|
+
// UIDVALIDITY in the SELECT answer as false, and reading that as a change wiped the folder
|
|
71
|
+
// index and sent mailboxReset over what is only a non-compliant response
|
|
72
|
+
return validUidValidity(storedStatus.uidValidity) && validUidValidity(mailboxStatus.uidValidity) && mailboxStatus.uidValidity !== storedStatus.uidValidity;
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
/**
|
|
@@ -196,42 +199,6 @@ class SyncOperations {
|
|
|
196
199
|
return this.runPartialSync();
|
|
197
200
|
}
|
|
198
201
|
|
|
199
|
-
/**
|
|
200
|
-
* Determines the appropriate sync strategy based on mailbox state
|
|
201
|
-
* @param {Object} storedStatus - Stored mailbox status
|
|
202
|
-
* @param {Object} mailboxStatus - Current mailbox status from IMAP
|
|
203
|
-
* @returns {Object} Sync decision with type and reason
|
|
204
|
-
*/
|
|
205
|
-
determineSyncStrategy(storedStatus, mailboxStatus) {
|
|
206
|
-
// No changes if MODSEQ hasn't changed
|
|
207
|
-
if (hasNoModseqChanges(storedStatus, mailboxStatus)) {
|
|
208
|
-
return { type: 'none', reason: 'modseq_unchanged' };
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// No changes if mailbox is empty
|
|
212
|
-
if (storedStatus.messages === 0 && mailboxStatus.messages === 0) {
|
|
213
|
-
return { type: 'none', reason: 'empty_mailbox' };
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// Partial sync if CONDSTORE indicates only new messages or flag changes
|
|
217
|
-
if (canUseCondstorePartialSync(this.connection.imapClient, storedStatus, mailboxStatus)) {
|
|
218
|
-
return { type: 'partial', reason: 'condstore_changes' };
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Partial sync if only new messages
|
|
222
|
-
if (canUseSimplePartialSync(storedStatus, mailboxStatus)) {
|
|
223
|
-
return { type: 'partial', reason: 'new_messages_only' };
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// Skip if nothing changed and recent full sync
|
|
227
|
-
if (canSkipSync(storedStatus, mailboxStatus)) {
|
|
228
|
-
return { type: 'none', reason: 'recent_full_sync' };
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// Full sync for all other cases
|
|
232
|
-
return { type: 'full', reason: 'changes_detected' };
|
|
233
|
-
}
|
|
234
|
-
|
|
235
202
|
/**
|
|
236
203
|
* Rebuilds the mailbox baseline from the server's current state WITHOUT emitting
|
|
237
204
|
* messageNew notifications. Used when the stored sync state was lost (e.g. Redis evicted
|
|
@@ -965,6 +932,7 @@ class SyncOperations {
|
|
|
965
932
|
|
|
966
933
|
module.exports = {
|
|
967
934
|
SyncOperations,
|
|
935
|
+
checkFetchRetryTimeout,
|
|
968
936
|
getFetchRange,
|
|
969
937
|
isRecentFullSync,
|
|
970
938
|
hasUidValidityChanged,
|