dovecot-1.2: Renamed imap-search.[ch] to imap-search-args.[ch]
dovecot at dovecot.org
dovecot at dovecot.org
Wed Feb 4 21:19:04 EET 2009
details: http://hg.dovecot.org/dovecot-1.2/rev/bd2bb6ff0a83
changeset: 8711:bd2bb6ff0a83
user: Timo Sirainen <tss at iki.fi>
date: Wed Feb 04 12:47:27 2009 -0500
description:
Renamed imap-search.[ch] to imap-search-args.[ch]
diffstat:
12 files changed, 235 insertions(+), 235 deletions(-)
src/imap/Makefile.am | 4
src/imap/cmd-copy.c | 2
src/imap/cmd-expunge.c | 2
src/imap/cmd-fetch.c | 2
src/imap/cmd-search.c | 2
src/imap/cmd-sort.c | 2
src/imap/cmd-store.c | 2
src/imap/cmd-thread.c | 2
src/imap/imap-search-args.c | 200 +++++++++++++++++++++++++++++++++++++++++++
src/imap/imap-search-args.h | 26 +++++
src/imap/imap-search.c | 200 -------------------------------------------
src/imap/imap-search.h | 26 -----
diffs (truncated from 573 to 300 lines):
diff -r eaf8c93be56e -r bd2bb6ff0a83 src/imap/Makefile.am
--- a/src/imap/Makefile.am Wed Feb 04 12:30:07 2009 -0500
+++ b/src/imap/Makefile.am Wed Feb 04 12:47:27 2009 -0500
@@ -71,7 +71,7 @@ imap_SOURCES = \
imap-expunge.c \
imap-fetch.c \
imap-fetch-body.c \
- imap-search.c \
+ imap-search-args.c \
imap-sort.c \
imap-status.c \
imap-sync.c \
@@ -86,7 +86,7 @@ headers = \
common.h \
imap-expunge.h \
imap-fetch.h \
- imap-search.h \
+ imap-search-args.h \
imap-sort.h \
imap-status.h \
imap-sync.h
diff -r eaf8c93be56e -r bd2bb6ff0a83 src/imap/cmd-copy.c
--- a/src/imap/cmd-copy.c Wed Feb 04 12:30:07 2009 -0500
+++ b/src/imap/cmd-copy.c Wed Feb 04 12:47:27 2009 -0500
@@ -5,7 +5,7 @@
#include "ostream.h"
#include "imap-resp-code.h"
#include "commands.h"
-#include "imap-search.h"
+#include "imap-search-args.h"
#include <time.h>
diff -r eaf8c93be56e -r bd2bb6ff0a83 src/imap/cmd-expunge.c
--- a/src/imap/cmd-expunge.c Wed Feb 04 12:30:07 2009 -0500
+++ b/src/imap/cmd-expunge.c Wed Feb 04 12:47:27 2009 -0500
@@ -2,7 +2,7 @@
#include "common.h"
#include "commands.h"
-#include "imap-search.h"
+#include "imap-search-args.h"
#include "imap-expunge.h"
static bool cmd_expunge_callback(struct client_command_context *cmd)
diff -r eaf8c93be56e -r bd2bb6ff0a83 src/imap/cmd-fetch.c
--- a/src/imap/cmd-fetch.c Wed Feb 04 12:30:07 2009 -0500
+++ b/src/imap/cmd-fetch.c Wed Feb 04 12:47:27 2009 -0500
@@ -5,7 +5,7 @@
#include "imap-resp-code.h"
#include "commands.h"
#include "imap-fetch.h"
-#include "imap-search.h"
+#include "imap-search-args.h"
#include "mail-search.h"
#include <stdlib.h>
diff -r eaf8c93be56e -r bd2bb6ff0a83 src/imap/cmd-search.c
--- a/src/imap/cmd-search.c Wed Feb 04 12:30:07 2009 -0500
+++ b/src/imap/cmd-search.c Wed Feb 04 12:47:27 2009 -0500
@@ -10,7 +10,7 @@
#include "imap-util.h"
#include "mail-search-build.h"
#include "commands.h"
-#include "imap-search.h"
+#include "imap-search-args.h"
enum search_return_options {
SEARCH_RETURN_ESEARCH = 0x0001,
diff -r eaf8c93be56e -r bd2bb6ff0a83 src/imap/cmd-sort.c
--- a/src/imap/cmd-sort.c Wed Feb 04 12:30:07 2009 -0500
+++ b/src/imap/cmd-sort.c Wed Feb 04 12:47:27 2009 -0500
@@ -3,7 +3,7 @@
#include "common.h"
#include "buffer.h"
#include "commands.h"
-#include "imap-search.h"
+#include "imap-search-args.h"
#include "imap-sort.h"
struct sort_name {
diff -r eaf8c93be56e -r bd2bb6ff0a83 src/imap/cmd-store.c
--- a/src/imap/cmd-store.c Wed Feb 04 12:30:07 2009 -0500
+++ b/src/imap/cmd-store.c Wed Feb 04 12:47:27 2009 -0500
@@ -4,7 +4,7 @@
#include "seq-range-array.h"
#include "str.h"
#include "commands.h"
-#include "imap-search.h"
+#include "imap-search-args.h"
#include "imap-util.h"
#include <stdlib.h>
diff -r eaf8c93be56e -r bd2bb6ff0a83 src/imap/cmd-thread.c
--- a/src/imap/cmd-thread.c Wed Feb 04 12:30:07 2009 -0500
+++ b/src/imap/cmd-thread.c Wed Feb 04 12:47:27 2009 -0500
@@ -4,7 +4,7 @@
#include "str.h"
#include "ostream.h"
#include "commands.h"
-#include "imap-search.h"
+#include "imap-search-args.h"
#include "mail-thread.h"
static int imap_thread_write(struct mail_thread_iterate_context *iter,
diff -r eaf8c93be56e -r bd2bb6ff0a83 src/imap/imap-search-args.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/imap/imap-search-args.c Wed Feb 04 12:47:27 2009 -0500
@@ -0,0 +1,200 @@
+/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
+
+#include "common.h"
+#include "mail-storage.h"
+#include "mail-search-build.h"
+#include "imap-search-args.h"
+#include "imap-parser.h"
+#include "imap-seqset.h"
+
+#include <stdlib.h>
+
+struct search_build_data {
+ pool_t pool;
+ struct mailbox *box;
+ const char *error;
+};
+
+static bool search_args_have_searchres(struct mail_search_arg *sargs)
+{
+ for (; sargs != NULL; sargs = sargs->next) {
+ switch (sargs->type) {
+ case SEARCH_UIDSET:
+ if (strcmp(sargs->value.str, "$") == 0)
+ return TRUE;
+ break;
+ case SEARCH_SUB:
+ case SEARCH_OR:
+ if (search_args_have_searchres(sargs->value.subargs))
+ return TRUE;
+ break;
+ default:
+ break;
+ }
+ }
+ return FALSE;
+}
+
+int imap_search_args_build(struct client_command_context *cmd,
+ const struct imap_arg *args, const char *charset,
+ struct mail_search_args **search_args_r)
+{
+ struct mail_search_args *sargs;
+ const char *error;
+
+ if (args->type == IMAP_ARG_EOL) {
+ client_send_command_error(cmd, "Missing search parameters");
+ return -1;
+ }
+
+ if (mail_search_build_from_imap_args(args, charset,
+ &sargs, &error) < 0) {
+ client_send_command_error(cmd, error);
+ return -1;
+ }
+
+ if (search_args_have_searchres(sargs->args)) {
+ if (client_handle_search_save_ambiguity(cmd))
+ return 0;
+ }
+
+ mail_search_args_init(sargs, cmd->client->mailbox, TRUE,
+ &cmd->client->search_saved_uidset);
+ *search_args_r = sargs;
+ return 1;
+}
+
+static bool
+msgset_is_valid(ARRAY_TYPE(seq_range) *seqset, uint32_t messages_count)
+{
+ const struct seq_range *range;
+ unsigned int count;
+
+ /* when there are no messages, all messagesets are invalid.
+ if there's at least one message:
+ - * gives seq1 = seq2 = (uint32_t)-1
+ - n:* should work if n <= messages_count
+ - n:m or m should work if m <= messages_count
+ */
+ range = array_get(seqset, &count);
+ if (count == 0 || messages_count == 0)
+ return FALSE;
+
+ if (range[count-1].seq2 == (uint32_t)-1) {
+ if (range[count-1].seq1 > messages_count &&
+ range[count-1].seq1 != (uint32_t)-1)
+ return FALSE;
+ } else {
+ if (range[count-1].seq2 > messages_count)
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static int imap_search_get_msgset_arg(struct client_command_context *cmd,
+ const char *messageset,
+ struct mail_search_args **args_r,
+ const char **error_r)
+{
+ struct mail_search_args *args;
+
+ args = mail_search_build_init();
+ args->args = p_new(args->pool, struct mail_search_arg, 1);
+ args->args->type = SEARCH_SEQSET;
+ p_array_init(&args->args->value.seqset, args->pool, 16);
+ if (imap_seq_set_parse(messageset, &args->args->value.seqset) < 0 ||
+ !msgset_is_valid(&args->args->value.seqset,
+ cmd->client->messages_count)) {
+ *error_r = "Invalid messageset";
+ return -1;
+ }
+ *args_r = args;
+ return 0;
+}
+
+static int
+imap_search_get_uidset_arg(struct client_command_context *cmd,
+ const char *uidset, struct mail_search_args **args_r,
+ const char **error_r)
+{
+ struct mail_search_args *args;
+
+ args = mail_search_build_init();
+ args->args = p_new(args->pool, struct mail_search_arg, 1);
+ args->args->type = SEARCH_UIDSET;
+ p_array_init(&args->args->value.seqset, cmd->pool, 16);
+ if (imap_seq_set_parse(uidset, &args->args->value.seqset) < 0) {
+ *error_r = "Invalid uidset";
+ return -1;
+ }
+
+ *args_r = args;
+ return 0;
+}
+
+int imap_search_get_seqset(struct client_command_context *cmd,
+ const char *set, bool uid,
+ struct mail_search_args **search_args_r)
+{
+ int ret;
+
+ ret = imap_search_get_anyset(cmd, set, uid, search_args_r);
+ if (ret > 0) {
+ mail_search_args_init(*search_args_r,
+ cmd->client->mailbox, TRUE,
+ &cmd->client->search_saved_uidset);
+ }
+ return ret;
+}
+
+static int imap_search_get_searchres(struct client_command_context *cmd,
+ struct mail_search_args **search_args_r)
+{
+ struct mail_search_args *search_args;
+
+ if (client_handle_search_save_ambiguity(cmd))
+ return 0;
+
+ search_args = mail_search_build_init();
+ search_args->args = p_new(search_args->pool, struct mail_search_arg, 1);
+ if (array_is_created(&cmd->client->search_saved_uidset)) {
+ search_args->args->type = SEARCH_UIDSET;
+ p_array_init(&search_args->args->value.seqset,
+ search_args->pool,
+ array_count(&cmd->client->search_saved_uidset));
+ array_append_array(&search_args->args->value.seqset,
+ &cmd->client->search_saved_uidset);
+ } else {
+ /* $ not set yet, match nothing */
+ search_args->args->type = SEARCH_ALL;
+ search_args->args->not = TRUE;
+ }
+ *search_args_r = search_args;
+ return 1;
+}
+
+int imap_search_get_anyset(struct client_command_context *cmd,
+ const char *set, bool uid,
+ struct mail_search_args **search_args_r)
+{
+ const char *error = NULL;
+ int ret;
+
+ if (strcmp(set, "$") == 0) {
+ /* SEARCHRES extension: replace $ with the last saved
+ search result */
+ return imap_search_get_searchres(cmd, search_args_r);
+ }
+ if (!uid) {
+ ret = imap_search_get_msgset_arg(cmd, set, search_args_r,
+ &error);
+ } else {
More information about the dovecot-cvs
mailing list