From: Pietro Cerutti Date: Tue, 8 Jan 2019 10:22:31 +0000 (+0000) Subject: Sort by UID so sequence ranges in UID STORE make sense X-Git-Tag: 2019-10-25~392 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=97ca7d261ecba34c4fd9401c2930845c74c3658c;p=neomutt Sort by UID so sequence ranges in UID STORE make sense This fixes the use case where a bunch of messages are tagged, removed, then the mailbox is sync'd in a thread view. In this case, the sequence number given by email->index is not monotonic, which results in weird sequence sets being passed to UID STORE. --- diff --git a/imap/imap.c b/imap/imap.c index 260fd859d..bba5a764c 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -979,6 +979,13 @@ bool imap_has_flag(struct ListHead *flag_list, const char *flag) return false; } +static int compare_uid(const void *a, const void *b) +{ + struct Email **ea = (struct Email **) a; + struct Email **eb = (struct Email **) b; + return imap_edata_get(*ea)->uid - imap_edata_get(*eb)->uid; +} + /** * imap_exec_msgset - Prepare commands for all messages matching conditions * @param m Selected Imap Mailbox @@ -1020,7 +1027,7 @@ int imap_exec_msgset(struct Mailbox *m, const char *pre, const char *post, memcpy(m->emails, emails, m->msg_count * sizeof(struct Email *)); Sort = SORT_ORDER; - qsort(m->emails, m->msg_count, sizeof(struct Email *), mutt_get_sort_func(SORT_ORDER)); + qsort(m->emails, m->msg_count, sizeof(struct Email *), compare_uid); } pos = 0;