]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap: If SEARCH/SORT fails but returns some results, send them to client.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 17 Feb 2017 16:32:05 +0000 (18:32 +0200)
committerGitLab <gitlab@git.dovecot.net>
Sun, 19 Feb 2017 18:42:32 +0000 (20:42 +0200)
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.

src/imap/imap-search.c

index 2e1716481b1d6d42083a09158c3adbd4bc7843da..313d4c70c4b86b4ae29553e156c4921e667fe0c3 100644 (file)
@@ -616,9 +616,14 @@ static int imap_search_deinit(struct imap_search_context *ctx)
        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);