changeset 8711:bd2bb6ff0a83 HEAD

Renamed imap-search.[ch] to imap-search-args.[ch]
author Timo Sirainen <tss@iki.fi>
date Wed, 04 Feb 2009 12:47:27 -0500
parents eaf8c93be56e
children 69cdbfd4c1ed
files src/imap/Makefile.am src/imap/cmd-copy.c src/imap/cmd-expunge.c src/imap/cmd-fetch.c src/imap/cmd-search.c src/imap/cmd-sort.c src/imap/cmd-store.c src/imap/cmd-thread.c src/imap/imap-search-args.c src/imap/imap-search-args.h src/imap/imap-search.c src/imap/imap-search.h
diffstat 12 files changed, 235 insertions(+), 235 deletions(-) [+]
line wrap: on
line diff
--- 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-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 @@
 	common.h \
 	imap-expunge.h \
 	imap-fetch.h \
-	imap-search.h \
+	imap-search-args.h \
 	imap-sort.h \
 	imap-status.h \
 	imap-sync.h
--- 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>
 
--- 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)
--- 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>
--- 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,
--- 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 {
--- 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>
--- 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,
--- /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 {
+		ret = imap_search_get_uidset_arg(cmd, set, search_args_r,
+						 &error);
+	}
+	if (ret < 0) {
+		client_send_command_error(cmd, error);
+		return -1;
+	}
+	return 1;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/imap/imap-search-args.h	Wed Feb 04 12:47:27 2009 -0500
@@ -0,0 +1,26 @@
+#ifndef IMAP_SEARCH_ARGS_H
+#define IMAP_SEARCH_ARGS_H
+
+#include "mail-search.h"
+
+struct imap_arg;
+struct mailbox;
+struct client_command_context;
+
+/* Builds search arguments based on IMAP arguments. Returns -1 if search
+   arguments are invalid, 0 if we have to wait for unambiguity,
+   1 if we can continue. */
+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);
+
+/* Returns -1 if set is invalid, 0 if we have to wait for unambiguity,
+   1 if we can continue. */
+int imap_search_get_seqset(struct client_command_context *cmd,
+			   const char *set, bool uid,
+			   struct mail_search_args **search_args_r);
+int imap_search_get_anyset(struct client_command_context *cmd,
+			   const char *set, bool uid,
+			   struct mail_search_args **search_args_r);
+
+#endif
--- a/src/imap/imap-search.c	Wed Feb 04 12:30:07 2009 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,200 +0,0 @@
-/* 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.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 {
-		ret = imap_search_get_uidset_arg(cmd, set, search_args_r,
-						 &error);
-	}
-	if (ret < 0) {
-		client_send_command_error(cmd, error);
-		return -1;
-	}
-	return 1;
-}
--- a/src/imap/imap-search.h	Wed Feb 04 12:30:07 2009 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-#ifndef IMAP_SEARCH_H
-#define IMAP_SEARCH_H
-
-#include "mail-search.h"
-
-struct imap_arg;
-struct mailbox;
-struct client_command_context;
-
-/* Builds search arguments based on IMAP arguments. Returns -1 if search
-   arguments are invalid, 0 if we have to wait for unambiguity,
-   1 if we can continue. */
-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);
-
-/* Returns -1 if set is invalid, 0 if we have to wait for unambiguity,
-   1 if we can continue. */
-int imap_search_get_seqset(struct client_command_context *cmd,
-			   const char *set, bool uid,
-			   struct mail_search_args **search_args_r);
-int imap_search_get_anyset(struct client_command_context *cmd,
-			   const char *set, bool uid,
-			   struct mail_search_args **search_args_r);
-
-#endif