diff --git a/src/engine/imap-db/imap-db-account.vala b/src/engine/imap-db/imap-db-account.vala index 47e032ed..25f58b63 100644 --- a/src/engine/imap-db/imap-db-account.vala +++ b/src/engine/imap-db/imap-db-account.vala @@ -172,7 +172,7 @@ private class Geary.ImapDB.Account : BaseObject { if (db_folder != null) { Imap.FolderProperties local_properties = db_folder.get_properties(); - local_properties.unseen = properties.unseen; + local_properties.set_status_unseen(properties.unseen); local_properties.recent = properties.recent; local_properties.attrs = properties.attrs; @@ -236,7 +236,7 @@ private class Geary.ImapDB.Account : BaseObject { if (db_folder != null) { Imap.FolderProperties local_properties = db_folder.get_properties(); - local_properties.unseen = properties.unseen; + local_properties.set_status_unseen(properties.unseen); local_properties.recent = properties.recent; local_properties.uid_validity = properties.uid_validity; local_properties.uid_next = properties.uid_next; @@ -321,7 +321,7 @@ private class Geary.ImapDB.Account : BaseObject { : new Geary.FolderRoot(basename, "/", Geary.Imap.Folder.CASE_SENSITIVE); Geary.Imap.FolderProperties properties = new Geary.Imap.FolderProperties( - result.int_for("last_seen_total"), 0, 0, + result.int_for("last_seen_total"), 0, new Imap.UIDValidity(result.int64_for("uid_validity")), new Imap.UID(result.int64_for("uid_next")), Geary.Imap.MailboxAttributes.deserialize(result.string_for("attributes"))); @@ -408,7 +408,7 @@ private class Geary.ImapDB.Account : BaseObject { Db.Result results = stmt.exec(cancellable); if (!results.finished) { - properties = new Imap.FolderProperties(results.int_for("last_seen_total"), 0, 0, + properties = new Imap.FolderProperties(results.int_for("last_seen_total"), 0, new Imap.UIDValidity(results.int64_for("uid_validity")), new Imap.UID(results.int64_for("uid_next")), Geary.Imap.MailboxAttributes.deserialize(results.string_for("attributes"))); diff --git a/src/engine/imap/api/imap-folder-properties.vala b/src/engine/imap/api/imap-folder-properties.vala index cfcbb410..01a62be9 100644 --- a/src/engine/imap/api/imap-folder-properties.vala +++ b/src/engine/imap/api/imap-folder-properties.vala @@ -45,26 +45,33 @@ public class Geary.Imap.FolderProperties : Geary.FolderProperties { */ public int select_examine_messages { get; private set; } /** - * -1 if the FolderProperties were not obtained via a STATUS command + * -1 if the FolderProperties were not obtained or updated via a STATUS command */ public int status_messages { get; private set; } - public int unseen { get; internal set; } + /** + * -1 if the FolderProperties were not obtained or updated via a STATUS command + */ + public int unseen { get; private set; } public int recent { get; internal set; } public UIDValidity? uid_validity { get; internal set; } public UID? uid_next { get; internal set; } public MailboxAttributes attrs { get; internal set; } - // Note that unseen from SELECT/EXAMINE is the *position* of the first unseen message, - // not the total unseen count, so it should not be passed in here, but rather the unseen - // count from a STATUS command - public FolderProperties(int messages, int recent, int unseen, UIDValidity? uid_validity, + /** + * Note that unseen from SELECT/EXAMINE is the *position* of the first unseen message, + * not the total unseen count, so it's not be passed in here, but rather only from the unseen + * count from a STATUS command + */ + public FolderProperties(int messages, int recent, UIDValidity? uid_validity, UID? uid_next, MailboxAttributes attrs) { - base (messages, unseen, Trillian.UNKNOWN, Trillian.UNKNOWN, Trillian.UNKNOWN); + // give the base class a zero email_unread, as the notion of "unknown" doesn't exist in + // its contract + base (messages, 0, Trillian.UNKNOWN, Trillian.UNKNOWN, Trillian.UNKNOWN); select_examine_messages = messages; status_messages = -1; this.recent = recent; - this.unseen = unseen; + this.unseen = -1; this.uid_validity = uid_validity; this.uid_next = uid_next; this.attrs = attrs; @@ -159,5 +166,16 @@ public class Geary.Imap.FolderProperties : Geary.FolderProperties { // select/examine more authoritative than status email_total = messages; } + + public void set_status_unseen(int count) { + // drop unknown counts, especially if known is held here + if (count < 0) + return; + + unseen = count; + + // update base class value (which clients see) + email_unread = count; + } } diff --git a/src/engine/imap/api/imap-folder.vala b/src/engine/imap/api/imap-folder.vala index ad0c0ef2..ca44b7ae 100644 --- a/src/engine/imap/api/imap-folder.vala +++ b/src/engine/imap/api/imap-folder.vala @@ -63,7 +63,7 @@ private class Geary.Imap.Folder : BaseObject { this.info = info; path = info.mailbox.to_folder_path(info.delim); - properties = new Imap.FolderProperties(0, 0, 0, null, null, info.attrs); + properties = new Imap.FolderProperties(0, 0, null, null, info.attrs); } public async void open_async(Cancellable? cancellable) throws Error { @@ -206,7 +206,9 @@ private class Geary.Imap.Folder : BaseObject { break; case ResponseCodeType.UNSEEN: - properties.unseen = response_code.get_unseen(); + // do NOT update properties.unseen, as the UNSEEN response code (here) means + // the sequence number of the first unseen message, not the total count of + // unseen messages break; case ResponseCodeType.PERMANENT_FLAGS: