From 9933f2d3fe83ddfc9f2e5a90a346f5d8efd9fcd7 Mon Sep 17 00:00:00 2001 From: Jim Nelson Date: Fri, 25 Jul 2014 13:36:09 -0700 Subject: [PATCH] Stabilize sort of search email identifiers: Bug #733271 Without stabilization, it was possible for multiple emails in search results with the same INTERNALDATE to be dropped due to the equality. --- .../imap-db/imap-db-search-email-identifier.vala | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/engine/imap-db/imap-db-search-email-identifier.vala b/src/engine/imap-db/imap-db-search-email-identifier.vala index 53c9b5b9..cea7f0b4 100644 --- a/src/engine/imap-db/imap-db-search-email-identifier.vala +++ b/src/engine/imap-db/imap-db-search-email-identifier.vala @@ -53,11 +53,18 @@ private class Geary.ImapDB.SearchEmailIdentifier : ImapDB.EmailIdentifier, } public virtual int compare_to(SearchEmailIdentifier other) { - if (date_received != null && other.date_received != null) - return date_received.compare(other.date_received); + // if both have date received, compare on that, using stable sort if the same + if (date_received != null && other.date_received != null) { + int compare = date_received.compare(other.date_received); + + return (compare != 0) ? compare : stable_sort_comparator(other); + } + + // if neither have date received, fall back on stable sort if (date_received == null && other.date_received == null) return stable_sort_comparator(other); + // put identifiers with no date ahead of those with return (date_received == null ? -1 : 1); }