mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-03-04 03:56:33 +08:00
[local-sync] When fetching /new/ messages, make sure we have fetchedmax
Summary: In `FetchNewMessagesInFolder`, sometimes we haven't synced anything in the folder we are trying to fetch new messages in. Previously this would just throw an error, now we properly check if we have a fetchedmax, and if not just run a normal fetch. Also, when the target folder box was already open, we were not fetching the /latest/ box status to check the latest uidnext value, so we would skip fetching new messages when in fact there were new messages to fetch (This can happen for example when moving a sent message to the Sent folder before we've started syncing the Sent folder) Test Plan: manual Reviewers: halla, mark, evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D3802
This commit is contained in:
parent
a0356ca76f
commit
e29fe2ee9b
1 changed files with 12 additions and 4 deletions
|
@ -17,15 +17,23 @@ class FetchNewMessagesInFolderIMAP extends FetchMessagesInFolderIMAP {
|
||||||
console.log(`🔜 📂 🆕 Looking for new messages in ${this._folder.name}`)
|
console.log(`🔜 📂 🆕 Looking for new messages in ${this._folder.name}`)
|
||||||
this._db = db;
|
this._db = db;
|
||||||
this._imap = imap;
|
this._imap = imap;
|
||||||
|
|
||||||
this._box = await this._imap.openBox(this._folder.name)
|
|
||||||
|
|
||||||
if (this._shouldFetchMessages(this._box)) {
|
|
||||||
const boxUidnext = this._box.uidnext
|
|
||||||
const {syncState: {fetchedmax}} = this._folder
|
const {syncState: {fetchedmax}} = this._folder
|
||||||
|
|
||||||
|
if (!fetchedmax) {
|
||||||
|
// Without a fetchedmax, can't tell what's new!
|
||||||
|
// If we haven't fetched anything on this folder, let's run a normal fetch
|
||||||
|
// operation
|
||||||
|
yield super.runTask(db, imap)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const latestBoxStatus = yield this._imap.getLatestBoxStatus(this._folder.name)
|
||||||
|
if (latestBoxStatus.uidnext > fetchedmax) {
|
||||||
|
this._box = await this._imap.openBox(this._folder.name)
|
||||||
|
const boxUidnext = this._box.uidnext
|
||||||
yield this._fetchAndProcessMessages({min: fetchedmax, max: boxUidnext});
|
yield this._fetchAndProcessMessages({min: fetchedmax, max: boxUidnext});
|
||||||
} else {
|
} else {
|
||||||
console.log(`🔚 📂 ${this._folder.name} has no new messages - skipping fetch messages`)
|
console.log(`🔚 📂 🆕$ {this._folder.name} has no new messages - skipping fetch messages`)
|
||||||
}
|
}
|
||||||
console.log(`🔚 📂 ${this._folder.name} done`)
|
console.log(`🔚 📂 ${this._folder.name} done`)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue