summaryrefslogtreecommitdiffstats
path: root/src/imap/cmd-search.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/imap/cmd-search.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/imap/cmd-search.c b/src/imap/cmd-search.c
new file mode 100644
index 0000000..52be6f6
--- /dev/null
+++ b/src/imap/cmd-search.c
@@ -0,0 +1,49 @@
+/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */
+
+#include "imap-common.h"
+#include "imap-search-args.h"
+#include "imap-search.h"
+
+bool cmd_search(struct client_command_context *cmd)
+{
+ struct imap_search_context *ctx;
+ struct mail_search_args *sargs;
+ const struct imap_arg *args;
+ const char *charset;
+ int ret;
+
+ if (!client_read_args(cmd, 0, 0, &args))
+ return FALSE;
+
+ if (!client_verify_open_mailbox(cmd))
+ return TRUE;
+
+ ctx = p_new(cmd->pool, struct imap_search_context, 1);
+ ctx->cmd = cmd;
+
+ if ((ret = cmd_search_parse_return_if_found(ctx, &args)) <= 0) {
+ /* error / waiting for unambiguity */
+ return ret < 0;
+ }
+
+ if (imap_arg_atom_equals(args, "CHARSET")) {
+ /* CHARSET specified */
+ if (!imap_arg_get_astring(&args[1], &charset)) {
+ client_send_command_error(cmd,
+ "Invalid charset argument.");
+ imap_search_context_free(ctx);
+ return TRUE;
+ }
+ args += 2;
+ } else {
+ charset = "UTF-8";
+ }
+
+ ret = imap_search_args_build(cmd, args, charset, &sargs);
+ if (ret <= 0) {
+ imap_search_context_free(ctx);
+ return ret < 0;
+ }
+
+ return imap_search_start(ctx, sargs, NULL);
+}