changeset 21602:9aac2a64e5c2

imap: If SEARCH/SORT fails but returns some results, send them to client. The previous error handling fixes cause SEARCH/SORT to now fail if there are any problems reading mails. This change makes the commands still return the best known results, so the IMAP client can still use them, even though they may not be entirely correct.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Fri, 17 Feb 2017 18:32:05 +0200
parents 15e700c083c0
children 6d50f63cfa67
files src/imap/imap-search.c
diffstat 1 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/imap-search.c	Fri Feb 17 18:30:51 2017 +0200
+++ b/src/imap/imap-search.c	Fri Feb 17 18:32:05 2017 +0200
@@ -616,9 +616,14 @@
 	if (mailbox_search_deinit(&ctx->search_ctx) < 0)
 		ret = -1;
 
-	if (ret == 0 && !ctx->cmd->cancel)
+	/* Send the result also after failing. It might have something useful,
+	   even though it didn't fully succeed. The client should be able to
+	   realize that there was some failure because NO is returned. */
+	if (!ctx->cmd->cancel &&
+	    (ret == 0 || array_count(&ctx->result) > 0))
 		imap_search_send_result(ctx);
-	else {
+
+	if (ret < 0 || ctx->cmd->cancel) {
 		/* search failed */
 		if ((ctx->return_options & SEARCH_RETURN_SAVE) != 0)
 			array_clear(&ctx->cmd->client->search_saved_uidset);