diff --git a/src/engine/imap-engine/imap-engine-account-synchronizer.vala b/src/engine/imap-engine/imap-engine-account-synchronizer.vala index 260a86b4..4080f647 100644 --- a/src/engine/imap-engine/imap-engine-account-synchronizer.vala +++ b/src/engine/imap-engine/imap-engine-account-synchronizer.vala @@ -216,9 +216,10 @@ private class Geary.ImapEngine.AccountSynchronizer : Geary.BaseObject { // Returns false if IOError.CANCELLED received private async bool process_folder_async(GenericFolder folder, bool availability_check, DateTime epoch) { - // get oldest local email and its position to start syncing from + // get oldest local email and its time, as well as number of messages in local store DateTime? oldest_local = null; Geary.EmailIdentifier? oldest_local_id = null; + int local_count = 0; try { Gee.List? list = yield folder.local_folder.list_email_by_id_async(null, 1, Email.Field.PROPERTIES, ImapDB.Folder.ListFlags.NONE | ImapDB.Folder.ListFlags.OLDEST_TO_NEWEST, @@ -227,6 +228,9 @@ private class Geary.ImapEngine.AccountSynchronizer : Geary.BaseObject { oldest_local = list[0].properties.date_received; oldest_local_id = list[0].id; } + + local_count = yield folder.local_folder.get_email_count_async(ImapDB.Folder.ListFlags.NONE, + bg_cancellable); } catch (Error err) { debug("Unable to fetch oldest local email for %s: %s", folder.to_string(), err.message); } @@ -239,6 +243,9 @@ private class Geary.ImapEngine.AccountSynchronizer : Geary.BaseObject { if (oldest_local.compare(epoch) < 0) { // Oldest local email before epoch, don't sync from network return true; + } else if (folder.properties.email_total == local_count) { + // Local email is after epoch, but there's nothing before it + return true; } else { debug("Oldest local email in %s not old enough (%s vs. %s), synchronizing...", folder.to_string(), oldest_local.to_string(), epoch.to_string()); diff --git a/src/engine/imap-engine/imap-engine-email-prefetcher.vala b/src/engine/imap-engine/imap-engine-email-prefetcher.vala index 928e3231..d73a4bbc 100644 --- a/src/engine/imap-engine/imap-engine-email-prefetcher.vala +++ b/src/engine/imap-engine/imap-engine-email-prefetcher.vala @@ -79,7 +79,6 @@ private class Geary.ImapEngine.EmailPrefetcher : Object { // emails should include PROPERTIES private void schedule_prefetch(Gee.Collection emails) { - debug("%s: scheduling %d emails for prefetch", folder.to_string(), emails.size); prefetch_emails.add_all(emails); // only increment active state if not rescheduling