diff --git a/lib/email-client/imap/mailbox.js b/lib/email-client/imap/mailbox.js index d4872bf77..3546afccb 100644 --- a/lib/email-client/imap/mailbox.js +++ b/lib/email-client/imap/mailbox.js @@ -174,6 +174,16 @@ class Mailbox { await op.hmset(this.getMailboxKey(), Object.fromEntries(list)).exec(); } + async getImapIndexer(skipCache) { + const imapIndexer = this.imapIndexer || (!skipCache && this._cachedImapIndexer) || (await settings.get('imapIndexer')) || 'full'; + + if (!this.imapIndexer && (skipCache || !this._cachedImapIndexer)) { + this._cachedImapIndexer = imapIndexer; + } + + return imapIndexer; + } + /** * Sets message entry object. Entries are ordered by `uid` property * @param {Object} data @@ -439,7 +449,9 @@ class Mailbox { async onExpunge(event) { this.logEvent('Untagged EXPUNGE', event); - if (this.imapIndexer !== 'full') { + const imapIndexer = await this.getImapIndexer(); + + if (imapIndexer !== 'full') { // ignore as we can not compare this value against the index return null; } @@ -463,7 +475,9 @@ class Mailbox { async onFlags(event) { this.logEvent('Untagged FETCH', event); - if (this.imapIndexer !== 'full') { + const imapIndexer = await this.getImapIndexer(); + + if (imapIndexer !== 'full') { // ignore as we can not compare this value against the index return null; } @@ -1499,7 +1513,9 @@ class Mailbox { } async fullSync() { - switch (this.imapIndexer) { + const imapIndexer = await this.getImapIndexer(true); + + switch (imapIndexer) { case 'fast': return this.runFastSync(); case 'full': @@ -1509,7 +1525,9 @@ class Mailbox { } async partialSync(storedStatus) { - switch (this.imapIndexer) { + const imapIndexer = await this.getImapIndexer(true); + + switch (imapIndexer) { case 'fast': return this.runFastSync(storedStatus); case 'full': diff --git a/lib/routes-ui.js b/lib/routes-ui.js index e819f6567..9a9b39825 100644 --- a/lib/routes-ui.js +++ b/lib/routes-ui.js @@ -1314,13 +1314,6 @@ function applyRoutes(server, call) { } for (let key of Object.keys(data)) { - if (key === 'imapIndexer') { - let existingValue = await settings.get(key); - if ((existingValue && existingValue !== data[key]) || (!existingValue && data[key] !== 'full')) { - await request.flash({ type: 'warning', message: `You may need to restart EmailEngine for indexing changes to take effect` }); - } - } - await settings.set(key, data[key]); } diff --git a/workers/imap.js b/workers/imap.js index 81cabd800..f69dcda81 100644 --- a/workers/imap.js +++ b/workers/imap.js @@ -203,7 +203,7 @@ class ConnectionHandler { } if (!accountObject.connection) { - let imapIndexer = typeof accountData.imap?.imapIndexer === 'boolean' ? accountData.imap?.indexer : (await settings.get('imapIndexer')) || 'full'; + let imapIndexer = typeof accountData.imap?.imapIndexer === 'string' && accountData.imap?.imapIndexer ? accountData.imap?.indexer : null; accountObject.connection = new IMAPClient(account, { runIndex,