From: Timo Sirainen Date: Fri, 24 Nov 2017 10:31:22 +0000 (+0200) Subject: lib-storage: Fix sorting mails with the same primary sort key X-Git-Tag: 2.3.0.rc1~408 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=06ff86fc92a789e9239dccbb4300f7994ee8842e;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Fix sorting mails with the same primary sort key The sorting order may have been wrong when there was a combination of: * Messages were sorted by a string (e.g. Subject) * Some messages had the same sort key (e.g. same base subject) * Within the messages with the same sort key, some of the messages already had the "sort-*" index number in Dovecot indexes, but some of them didn't. The result was that Dovecot found that the two messages had exactly the same sort key. It should have continued with the secondary sort key (e.g. message sequence number), but it didn't. --- diff --git a/src/lib-storage/index/index-sort-string.c b/src/lib-storage/index/index-sort-string.c index dbf5ce8cd4..8ebc0866e9 100644 --- a/src/lib-storage/index/index-sort-string.c +++ b/src/lib-storage/index/index-sort-string.c @@ -496,6 +496,11 @@ static void index_sort_merge(struct sort_string_context *ctx) ret = 1; } + if (ret == 0) { + ret = index_sort_node_cmp_type(ctx->program, + ctx->program->sort_program + 1, + znodes[zpos].seq, nznodes[nzpos].seq); + } if (ret <= 0) { array_append(&ctx->sorted_nodes, &znodes[zpos], 1); prev_str = zstr;