# HG changeset patch # User Timo Sirainen # Date 1511519482 -7200 # Node ID b66965f62ae89381e95b7d39727c394d09c8fa65 # Parent ac58eecfb8b08526876c83051fbe69fa0f327828 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 -r ac58eecfb8b0 -r b66965f62ae8 src/lib-storage/index/index-sort-string.c --- a/src/lib-storage/index/index-sort-string.c Mon Nov 27 11:58:39 2017 +0200 +++ b/src/lib-storage/index/index-sort-string.c Fri Nov 24 12:31:22 2017 +0200 @@ -496,6 +496,11 @@ 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;