dovecot-2.2: lib-storage: Added mail_search_args_to_cmdline()
dovecot at dovecot.org
dovecot at dovecot.org
Wed Jun 3 21:47:33 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/53824319afb5
changeset: 18827:53824319afb5
user: Timo Sirainen <tss at iki.fi>
date: Thu Jun 04 00:44:42 2015 +0300
description:
lib-storage: Added mail_search_args_to_cmdline()
This isn't entirely correct yet, but it's only going to be used for
debugging for now.
diffstat:
src/lib-storage/Makefile.am | 1 +
src/lib-storage/mail-search-args-cmdline.c | 100 +++++++++++++++++++++++++++++
src/lib-storage/mail-search.h | 3 +
3 files changed, 104 insertions(+), 0 deletions(-)
diffs (128 lines):
diff -r e222d1265e4e -r 53824319afb5 src/lib-storage/Makefile.am
--- a/src/lib-storage/Makefile.am Wed Jun 03 23:56:32 2015 +0300
+++ b/src/lib-storage/Makefile.am Thu Jun 04 00:44:42 2015 +0300
@@ -28,6 +28,7 @@
mail-error.c \
mail-namespace.c \
mail-search.c \
+ mail-search-args-cmdline.c \
mail-search-args-imap.c \
mail-search-args-simplify.c \
mail-search-build.c \
diff -r e222d1265e4e -r 53824319afb5 src/lib-storage/mail-search-args-cmdline.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-storage/mail-search-args-cmdline.c Thu Jun 04 00:44:42 2015 +0300
@@ -0,0 +1,100 @@
+/* Copyright (c) 2015 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "str.h"
+#include "imap-quote.h"
+#include "mail-search.h"
+
+static void
+mail_search_arg_to_cmdline(string_t *dest, const struct mail_search_arg *arg);
+
+static void
+mail_search_subargs_to_cmdline(string_t *dest, const struct mail_search_arg *args,
+ const char *middle)
+{
+ const struct mail_search_arg *arg;
+
+ str_append(dest, "( ");
+ for (arg = args; arg != NULL; arg = arg->next) {
+ mail_search_arg_to_cmdline(dest, arg);
+ if (arg->next != NULL)
+ str_append(dest, middle);
+ }
+ str_append(dest, " )");
+}
+
+static void
+mail_search_arg_to_cmdline(string_t *dest, const struct mail_search_arg *arg)
+{
+ struct mail_search_arg new_arg;
+ const char *error;
+
+ if (arg->match_not)
+ str_append(dest, "NOT ");
+ switch (arg->type) {
+ case SEARCH_OR:
+ mail_search_subargs_to_cmdline(dest, arg->value.subargs, " OR ");
+ return;
+ case SEARCH_SUB:
+ mail_search_subargs_to_cmdline(dest, arg->value.subargs, " ");
+ return;
+ case SEARCH_FLAGS:
+ case SEARCH_KEYWORDS: {
+ size_t pos = str_len(dest);
+
+ if (!mail_search_arg_to_imap(dest, arg, &error))
+ i_unreached();
+ str_insert(dest, pos+1, " ");
+ str_insert(dest, str_len(dest)-2, " ");
+ return;
+ }
+ case SEARCH_INTHREAD:
+ str_append(dest, "INTHREAD ");
+ imap_append_astring(dest, mail_thread_type_to_str(arg->value.thread_type));
+ str_append_c(dest, ' ');
+ mail_search_subargs_to_cmdline(dest, arg->value.subargs, " ");
+ break;
+ case SEARCH_MAILBOX:
+ str_append(dest, "MAILBOX ");
+ imap_append_astring(dest, arg->value.str);
+ return;
+ case SEARCH_MAILBOX_GUID:
+ str_append(dest, "MAILBOX-GUID ");
+ imap_append_astring(dest, arg->value.str);
+ return;
+ case SEARCH_ALL:
+ case SEARCH_SEQSET:
+ case SEARCH_UIDSET:
+ case SEARCH_BEFORE:
+ case SEARCH_ON:
+ case SEARCH_SINCE:
+ case SEARCH_SMALLER:
+ case SEARCH_LARGER:
+ case SEARCH_HEADER:
+ case SEARCH_HEADER_ADDRESS:
+ case SEARCH_HEADER_COMPRESS_LWSP:
+ case SEARCH_BODY:
+ case SEARCH_TEXT:
+ case SEARCH_MODSEQ:
+ case SEARCH_GUID:
+ case SEARCH_MAILBOX_GLOB:
+ case SEARCH_REAL_UID:
+ break;
+ }
+ new_arg = *arg;
+ new_arg.match_not = FALSE;
+ if (!mail_search_arg_to_imap(dest, &new_arg, &error))
+ i_panic("mail_search_args_to_cmdline(): Missing handler: %s", error);
+}
+
+void mail_search_args_to_cmdline(string_t *dest,
+ const struct mail_search_arg *args)
+{
+ const struct mail_search_arg *arg;
+
+ for (arg = args; arg != NULL; arg = arg->next) {
+ mail_search_arg_to_cmdline(dest, arg);
+ if (arg->next != NULL)
+ str_append_c(dest, ' ');
+ }
+}
diff -r e222d1265e4e -r 53824319afb5 src/lib-storage/mail-search.h
--- a/src/lib-storage/mail-search.h Wed Jun 03 23:56:32 2015 +0300
+++ b/src/lib-storage/mail-search.h Thu Jun 04 00:44:42 2015 +0300
@@ -199,6 +199,9 @@
/* Like mail_search_args_to_imap(), but append only a single arg. */
bool mail_search_arg_to_imap(string_t *dest, const struct mail_search_arg *arg,
const char **error_r);
+/* Write all args to dest string as cmdline/human compatible input. */
+void mail_search_args_to_cmdline(string_t *dest,
+ const struct mail_search_arg *args);
/* Serialization for search args' results. */
void mail_search_args_result_serialize(const struct mail_search_args *args,
More information about the dovecot-cvs
mailing list