dovecot-2.2: imap: Brought back the original SEARCH PARTIAL code...

dovecot at dovecot.org dovecot at dovecot.org
Mon May 5 11:19:00 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/32b6a95c95cc
changeset: 17314:32b6a95c95cc
user:      Timo Sirainen <tss at iki.fi>
date:      Mon May 05 14:18:31 2014 +0300
description:
imap: Brought back the original SEARCH PARTIAL code with the minor fix that it actually needed.
The new code in v2.2.11 was completely wrong. The code in previous commit
was broken with SORT. The original code was correct otherwise, except it
couldn't handle partial1 pointing past the valid range.

diffstat:

 src/imap/imap-search.c |  39 +++++++++++++++++++++++++++++++++++++--
 1 files changed, 37 insertions(+), 2 deletions(-)

diffs (51 lines):

diff -r defefebf5f99 -r 32b6a95c95cc src/imap/imap-search.c
--- a/src/imap/imap-search.c	Mon May 05 14:02:58 2014 +0300
+++ b/src/imap/imap-search.c	Mon May 05 14:18:31 2014 +0300
@@ -228,10 +228,45 @@
 static void
 imap_search_send_partial(struct imap_search_context *ctx, string_t *str)
 {
+	struct seq_range *range;
+	uint32_t n, diff;
+	unsigned int i, count, delete_count;
+
 	str_printfa(str, " PARTIAL (%u:%u ", ctx->partial1, ctx->partial2);
+	ctx->partial1--;
+	ctx->partial2--;
 
-	seq_range_array_remove_nth(&ctx->result, ctx->partial2, (uint32_t)-1);
-	seq_range_array_remove_nth(&ctx->result, 0, ctx->partial1-1);
+	/* we need to be able to handle non-sorted seq ranges (for SORT
+	   replies), so do this ourself instead of using seq_range_array_*()
+	   functions. */
+	range = array_get_modifiable(&ctx->result, &count);
+	/* delete everything up to partial1 */
+	delete_count = 0;
+	for (i = n = 0; i < count; i++) {
+		diff = range[i].seq2 - range[i].seq1;
+		if (n + diff >= ctx->partial1) {
+			range[i].seq1 += ctx->partial1 - n;
+			delete_count = i;
+			break;
+		}
+		n += diff + 1;
+	}
+	if (i == count) {
+		/* partial1 points past the result */
+		array_clear(&ctx->result);
+	} else {
+		/* delete everything after partial2 */
+		for (n = ctx->partial1; i < count; i++) {
+			diff = range[i].seq2 - range[i].seq1;
+			if (n + diff >= ctx->partial2) {
+				range[i].seq2 = range[i].seq1 + (ctx->partial2 - n);
+				array_delete(&ctx->result, i + 1, count-(i+1));
+				break;
+			}
+			n += diff + 1;
+		}
+		array_delete(&ctx->result, 0, delete_count);
+	}
 
 	if (array_count(&ctx->result) == 0) {
 		/* no results (in range) */


More information about the dovecot-cvs mailing list