bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2008-2018 Dovecot authors, see the included COPYING file */
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen
08d6658a4e2ec8104cd1307f6baa75fdb07a24f8Mark Washenberger#include "imap-common.h"
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen#include "imap-search.h"
08d6658a4e2ec8104cd1307f6baa75fdb07a24f8Mark Washenberger#include "imap-commands.h"
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainenstatic bool client_search_update_cancel(struct client *client, const char *tag)
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen{
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen struct imap_search_update *update;
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen unsigned int idx;
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen update = client_search_update_lookup(client, tag, &idx);
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen if (update == NULL)
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen return FALSE;
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen imap_search_update_free(update);
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen array_delete(&client->search_updates, idx, 1);
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen return TRUE;
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen}
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainenbool cmd_cancelupdate(struct client_command_context *cmd)
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen{
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen const struct imap_arg *args;
c2fbbf7515aa419dc8b2d62a3c2bb0471d51a391Timo Sirainen const char *tag;
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen unsigned int i;
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen if (!client_read_args(cmd, 0, 0, &args))
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen return FALSE;
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen for (i = 0; args[i].type == IMAP_ARG_STRING; i++) ;
c2fbbf7515aa419dc8b2d62a3c2bb0471d51a391Timo Sirainen if (!IMAP_ARG_IS_EOL(&args[i]) || i == 0) {
ce85eb246b9f2d1cd332c3da886bfbdb5392d3fcTimo Sirainen client_send_command_error(cmd, "Invalid parameters.");
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen return TRUE;
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen }
c2fbbf7515aa419dc8b2d62a3c2bb0471d51a391Timo Sirainen
c2fbbf7515aa419dc8b2d62a3c2bb0471d51a391Timo Sirainen while (imap_arg_get_quoted(args, &tag)) {
c2fbbf7515aa419dc8b2d62a3c2bb0471d51a391Timo Sirainen if (!client_search_update_cancel(cmd->client, tag)) {
ce85eb246b9f2d1cd332c3da886bfbdb5392d3fcTimo Sirainen client_send_tagline(cmd, "NO Unknown tag.");
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen return TRUE;
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen }
c2fbbf7515aa419dc8b2d62a3c2bb0471d51a391Timo Sirainen args++;
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen }
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen client_send_tagline(cmd, "OK Updates cancelled.");
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen return TRUE;
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen}