diff --git a/lib/email-client/gmail-client.js b/lib/email-client/gmail-client.js index 8f2e395f5..fccb84faa 100644 --- a/lib/email-client/gmail-client.js +++ b/lib/email-client/gmail-client.js @@ -315,7 +315,7 @@ class GmailClient extends BaseClient { clearTimeout(this.renewWatchTimer); this.closed = true; - if (this.state !== 'disconnected') { + if (['init', 'connecting', 'syncing', 'connected'].includes(this.state)) { this.state = 'disconnected'; await this.setStateVal(); await emitChangeEvent(this.logger, this.account, 'state', this.state); @@ -328,7 +328,7 @@ class GmailClient extends BaseClient { clearTimeout(this.renewWatchTimer); this.closed = true; - if (this.state !== 'disconnected') { + if (['init', 'connecting', 'syncing', 'connected'].includes(this.state)) { this.state = 'disconnected'; await this.setStateVal(); await emitChangeEvent(this.logger, this.account, 'state', this.state); diff --git a/lib/email-client/imap-client.js b/lib/email-client/imap-client.js index cbb3645a0..c26b6551f 100644 --- a/lib/email-client/imap-client.js +++ b/lib/email-client/imap-client.js @@ -1086,7 +1086,7 @@ class IMAPClient extends BaseClient { await this.redis.hSetExists(this.getAccountKey(), 'connections', this.connections.size.toString()); imapClient?.log.info({ msg: 'Connection closed', type: 'imapClient', account: this.account, disabled: imapClient.disabled }); - if (this.state !== 'disconnected') { + if (['init', 'connecting', 'syncing', 'connected'].includes(this.state)) { this.state = 'disconnected'; await this.setStateVal(); await emitChangeEvent(this.logger, this.account, 'state', this.state); diff --git a/lib/email-client/outlook-client.js b/lib/email-client/outlook-client.js index eea3c0ab3..9df26f314 100644 --- a/lib/email-client/outlook-client.js +++ b/lib/email-client/outlook-client.js @@ -216,7 +216,7 @@ class OutlookClient extends BaseClient { clearTimeout(this.renewWatchTimer); this.closed = true; - if (this.state !== 'disconnected') { + if (['init', 'connecting', 'syncing', 'connected'].includes(this.state)) { this.state = 'disconnected'; await this.setStateVal(); await emitChangeEvent(this.logger, this.account, 'state', this.state); @@ -229,7 +229,7 @@ class OutlookClient extends BaseClient { clearTimeout(this.renewWatchTimer); this.closed = true; - if (this.state !== 'disconnected') { + if (['init', 'connecting', 'syncing', 'connected'].includes(this.state)) { this.state = 'disconnected'; await this.setStateVal(); await emitChangeEvent(this.logger, this.account, 'state', this.state);