Skip to content

Commit

Permalink
Use up to date imapIndexer settings when syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Oct 13, 2024
1 parent 1d6df05 commit 6c8dd93
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
26 changes: 22 additions & 4 deletions lib/email-client/imap/mailbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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':
Expand All @@ -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':
Expand Down
7 changes: 0 additions & 7 deletions lib/routes-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand Down
2 changes: 1 addition & 1 deletion workers/imap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6c8dd93

Please sign in to comment.