]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Fix sorting mails with the same primary sort key
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 24 Nov 2017 10:31:22 +0000 (12:31 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 24 Nov 2017 10:31:22 +0000 (12:31 +0200)
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.

src/lib-storage/index/index-sort-string.c

index dbf5ce8cd49a089fd0e788c68f878b669d9c99d4..8ebc0866e9db7007008353c235c7c1d95ee11a21 100644 (file)
@@ -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;