[dovecot-cvs] dovecot/src/imap client.c, 1.52, 1.53 client.h, 1.27, 1.28 cmd-append.c, 1.53, 1.54 cmd-authenticate.c, 1.2, 1.3 cmd-capability.c, 1.5, 1.6 cmd-check.c, 1.6, 1.7 cmd-close.c, 1.14, 1.15 cmd-copy.c, 1.25, 1.26 cmd-create.c, 1.11, 1.12 cmd-delete.c, 1.7, 1.8 cmd-examine.c, 1.3, 1.4 cmd-expunge.c, 1.10, 1.11 cmd-fetch.c, 1.25, 1.26 cmd-idle.c, 1.17, 1.18 cmd-list.c, 1.43, 1.44 cmd-login.c, 1.2, 1.3 cmd-logout.c, 1.8, 1.9 cmd-lsub.c, 1.3, 1.4 cmd-namespace.c, 1.3, 1.4 cmd-noop.c, 1.4, 1.5 cmd-rename.c, 1.7, 1.8 cmd-search.c, 1.22, 1.23 cmd-select.c, 1.33, 1.34 cmd-sort.c, 1.17, 1.18 cmd-status.c, 1.20, 1.21 cmd-store.c, 1.30, 1.31 cmd-subscribe.c, 1.10, 1.11 cmd-thread.c, 1.8, 1.9 cmd-uid.c, 1.5, 1.6 cmd-unselect.c, 1.4, 1.5 cmd-unsubscribe.c, 1.3, 1.4 commands-util.c, 1.40, 1.41 commands-util.h, 1.20, 1.21 commands.h, 1.16, 1.17 imap-fetch-body.c, 1.16, 1.17 imap-fetch.c, 1.35, 1.36 imap-fetch.h, 1.12, 1.13 imap-search.c, 1.9, 1.10 imap-search.h, 1.5, 1.6 imap-sort.c, 1.18, 1.19 imap-sort.h, 1.2, 1.3 imap-sync.c, 1.7, 1.8 imap-sync.h, 1.2, 1.3 imap-thread.c, 1.13, 1.14 imap-thread.h, 1.2, 1.3

cras at dovecot.org cras at dovecot.org
Sat Feb 5 20:07:29 EET 2005


Update of /var/lib/cvs/dovecot/src/imap
In directory talvi:/tmp/cvs-serv26806

Modified Files:
	client.c client.h cmd-append.c cmd-authenticate.c 
	cmd-capability.c cmd-check.c cmd-close.c cmd-copy.c 
	cmd-create.c cmd-delete.c cmd-examine.c cmd-expunge.c 
	cmd-fetch.c cmd-idle.c cmd-list.c cmd-login.c cmd-logout.c 
	cmd-lsub.c cmd-namespace.c cmd-noop.c cmd-rename.c 
	cmd-search.c cmd-select.c cmd-sort.c cmd-status.c cmd-store.c 
	cmd-subscribe.c cmd-thread.c cmd-uid.c cmd-unselect.c 
	cmd-unsubscribe.c commands-util.c commands-util.h commands.h 
	imap-fetch-body.c imap-fetch.c imap-fetch.h imap-search.c 
	imap-search.h imap-sort.c imap-sort.h imap-sync.c imap-sync.h 
	imap-thread.c imap-thread.h 
Log Message:
Moved command-specific variables from struct client to struct
client_command_context and changed code to use it.



Index: client.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/client.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- client.c	15 Dec 2004 21:38:33 -0000	1.52
+++ client.c	5 Feb 2005 18:07:26 -0000	1.53
@@ -36,7 +36,9 @@
 					    imap_max_line_length);
         client->last_input = ioloop_time;
 
-	client->cmd_pool = pool_alloconly_create("command pool", 8192);
+	client->cmd.pool = pool_alloconly_create("command pool", 8192);
+	client->cmd.client = client;
+
 	client->keywords.pool = pool_alloconly_create("mailbox_keywords", 512);
 	client->namespaces = namespaces;
 
@@ -62,7 +64,7 @@
 		/* try to deinitialize the command */
 		i_stream_close(client->input);
 		o_stream_close(client->output);
-		ret = client->cmd_func(client);
+		ret = client->cmd.func(&client->cmd);
 		i_assert(ret);
 	}
 
@@ -78,7 +80,7 @@
 	o_stream_unref(client->output);
 
 	pool_unref(client->keywords.pool);
-	pool_unref(client->cmd_pool);
+	pool_unref(client->cmd.pool);
 	i_free(client);
 
 	/* quit the program */
@@ -119,9 +121,10 @@
 		CLIENT_OUTPUT_OPTIMAL_SIZE;
 }
 
-void client_send_tagline(struct client *client, const char *data)
+void client_send_tagline(struct client_command_context *cmd, const char *data)
 {
-	const char *tag = client->cmd_tag;
+	struct client *client = cmd->client;
+	const char *tag = cmd->tag;
 
 	if (client->output->closed)
 		return;
@@ -135,9 +138,11 @@
 	(void)o_stream_send(client->output, "\r\n", 2);
 }
 
-void client_send_command_error(struct client *client, const char *msg)
+void client_send_command_error(struct client_command_context *cmd,
+			       const char *msg)
 {
-	const char *error, *cmd;
+	struct client *client = cmd->client;
+	const char *error, *cmd_name;
 	int fatal;
 
 	if (msg == NULL) {
@@ -148,17 +153,17 @@
 		}
 	}
 
-	if (client->cmd_tag == NULL)
+	if (cmd->tag == NULL)
 		error = t_strconcat("BAD Error in IMAP tag: ", msg, NULL);
-	else if (client->cmd_name == NULL)
+	else if (cmd->name == NULL)
 		error = t_strconcat("BAD Error in IMAP command: ", msg, NULL);
 	else {
-		cmd = t_str_ucase(client->cmd_name);
+		cmd_name = t_str_ucase(cmd->name);
 		error = t_strconcat("BAD Error in IMAP command ",
-				    cmd, ": ", msg, NULL);
+				    cmd_name, ": ", msg, NULL);
 	}
 
-	client_send_tagline(client, error);
+	client_send_tagline(cmd, error);
 
 	if (++client->bad_counter >= CLIENT_MAX_BAD_COMMANDS) {
 		client_disconnect_with_error(client,
@@ -168,17 +173,17 @@
 	/* client_read_args() failures rely on this being set, so that the
 	   command processing is stopped even while command function returns
 	   FALSE. */
-	client->cmd_param_error = TRUE;
+	cmd->param_error = TRUE;
 }
 
-int client_read_args(struct client *client, unsigned int count,
+int client_read_args(struct client_command_context *cmd, unsigned int count,
 		     unsigned int flags, struct imap_arg **args)
 {
 	int ret;
 
 	i_assert(count <= INT_MAX);
 
-	ret = imap_parser_read_args(client->parser, count, flags, args);
+	ret = imap_parser_read_args(cmd->client->parser, count, flags, args);
 	if (ret >= (int)count) {
 		/* all parameters read successfully */
 		return TRUE;
@@ -187,20 +192,21 @@
 		return FALSE;
 	} else {
 		/* error, or missing arguments */
-		client_send_command_error(client, ret < 0 ? NULL :
+		client_send_command_error(cmd, ret < 0 ? NULL :
 					  "Missing arguments");
 		return FALSE;
 	}
 }
 
-int client_read_string_args(struct client *client, unsigned int count, ...)
+int client_read_string_args(struct client_command_context *cmd,
+			    unsigned int count, ...)
 {
 	struct imap_arg *imap_args;
 	va_list va;
 	const char *str;
 	unsigned int i;
 
-	if (!client_read_args(client, count, 0, &imap_args))
+	if (!client_read_args(cmd, count, 0, &imap_args))
 		return FALSE;
 
 	va_start(va, count);
@@ -208,13 +214,13 @@
 		const char **ret = va_arg(va, const char **);
 
 		if (imap_args[i].type == IMAP_ARG_EOL) {
-			client_send_command_error(client, "Missing arguments.");
+			client_send_command_error(cmd, "Missing arguments.");
 			break;
 		}
 
 		str = imap_arg_string(&imap_args[i]);
 		if (str == NULL) {
-			client_send_command_error(client, "Invalid arguments.");
+			client_send_command_error(cmd, "Invalid arguments.");
 			break;
 		}
 
@@ -228,6 +234,8 @@
 
 void _client_reset_command(struct client *client)
 {
+	pool_t pool;
+
 	/* reset input idle time because command output might have taken a
 	   long time and we don't want to disconnect client immediately then */
 	client->last_input = ioloop_time;
@@ -238,13 +246,13 @@
 				    IO_READ, _client_input, client);
 	}
 
-	client->cmd_tag = NULL;
-	client->cmd_name = NULL;
-	client->cmd_func = NULL;
-	client->cmd_uid = FALSE;
-	client->cmd_param_error = FALSE;
+	pool = client->cmd.pool;
+	memset(&client->cmd, 0, sizeof(client->cmd));
+
+	p_clear(pool);
+	client->cmd.pool = pool;
+	client->cmd.client = client;
 
-	p_clear(client->cmd_pool);
 	imap_parser_reset(client->parser);
 }
 
@@ -269,11 +277,13 @@
 	return !client->input_skip_line;
 }
 
-static int client_handle_input(struct client *client)
+static int client_handle_input(struct client_command_context *cmd)
 {
-        if (client->cmd_func != NULL) {
+	struct client *client = cmd->client;
+
+        if (cmd->func != NULL) {
 		/* command is being executed - continue it */
-		if (client->cmd_func(client) || client->cmd_param_error) {
+		if (cmd->func(cmd) || cmd->param_error) {
 			/* command execution was finished */
                         client->bad_counter = 0;
 			_client_reset_command(client);
@@ -293,35 +303,35 @@
 		/* pass through to parse next command */
 	}
 
-	if (client->cmd_tag == NULL) {
-                client->cmd_tag = imap_parser_read_word(client->parser);
-		if (client->cmd_tag == NULL)
+	if (cmd->tag == NULL) {
+                cmd->tag = imap_parser_read_word(client->parser);
+		if (cmd->tag == NULL)
 			return FALSE; /* need more data */
-		client->cmd_tag = p_strdup(client->cmd_pool, client->cmd_tag);
+		cmd->tag = p_strdup(cmd->pool, cmd->tag);
 	}
 
-	if (client->cmd_name == NULL) {
-		client->cmd_name = imap_parser_read_word(client->parser);
-		if (client->cmd_name == NULL)
+	if (cmd->name == NULL) {
+		cmd->name = imap_parser_read_word(client->parser);
+		if (cmd->name == NULL)
 			return FALSE; /* need more data */
-		client->cmd_name = p_strdup(client->cmd_pool, client->cmd_name);
+		cmd->name = p_strdup(cmd->pool, cmd->name);
 	}
 
-	if (client->cmd_name == '\0') {
+	if (cmd->name == '\0') {
 		/* command not given - cmd_func is already NULL. */
 	} else {
 		/* find the command function */
-		client->cmd_func = command_find(client->cmd_name);
+		cmd->func = command_find(cmd->name);
 	}
 
-	if (client->cmd_func == NULL) {
+	if (cmd->func == NULL) {
 		/* unknown command */
-		client_send_command_error(client, "Unknown command.");
+		client_send_command_error(cmd, "Unknown command.");
 		client->input_skip_line = TRUE;
 		_client_reset_command(client);
 	} else {
 		client->input_skip_line = TRUE;
-		if (client->cmd_func(client) || client->cmd_param_error) {
+		if (cmd->func(cmd) || cmd->param_error) {
 			/* command execution was finished. */
                         client->bad_counter = 0;
 			_client_reset_command(client);
@@ -337,6 +347,7 @@
 void _client_input(void *context)
 {
 	struct client *client = context;
+	struct client_command_context *cmd = &client->cmd;
 
 	if (client->command_pending) {
 		/* already processing one command. wait. */
@@ -359,13 +370,13 @@
 		   until newline is found. */
 		client->input_skip_line = TRUE;
 
-		client_send_command_error(client, "Too long argument.");
+		client_send_command_error(cmd, "Too long argument.");
 		_client_reset_command(client);
 		break;
 	}
 
 	o_stream_cork(client->output);
-	while (client_handle_input(client))
+	while (client_handle_input(cmd))
 		;
 	o_stream_uncork(client->output);
 
@@ -379,6 +390,7 @@
 int _client_output(void *context)
 {
 	struct client *client = context;
+	struct client_command_context *cmd = &client->cmd;
 	int ret, finished;
 
 	client->last_output = ioloop_time;
@@ -394,7 +406,7 @@
 	/* continue processing command */
 	o_stream_cork(client->output);
 	client->output_pending = TRUE;
-	finished = client->cmd_func(client) || client->cmd_param_error;
+	finished = cmd->func(cmd) || cmd->param_error;
 	o_stream_uncork(client->output);
 
 	/* a bit kludgy. normally we would want to get back here, but IDLE

Index: client.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/client.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- client.h	5 Feb 2005 14:45:48 -0000	1.27
+++ client.h	5 Feb 2005 18:07:26 -0000	1.28
@@ -15,6 +15,20 @@
         unsigned int keywords_count;
 };
 
+struct client_command_context {
+	struct client *client;
+
+	pool_t pool;
+	const char *tag;
+	const char *name;
+
+	command_func_t *func;
+	void *context;
+
+	unsigned int uid:1; /* used UID command */
+	unsigned int param_error:1;
+};
+
 struct client {
 	int socket;
 	struct io *io;
@@ -31,17 +45,11 @@
 	unsigned int bad_counter;
 
 	struct imap_parser *parser;
-	pool_t cmd_pool;
-	const char *cmd_tag;
-	const char *cmd_name;
-	command_func_t *cmd_func;
-	void *cmd_context;
+	struct client_command_context cmd;
 
 	unsigned int command_pending:1;
 	unsigned int input_pending:1;
 	unsigned int output_pending:1;
-	unsigned int cmd_uid:1; /* used UID command */
-	unsigned int cmd_param_error:1;
 	unsigned int rawlog:1;
 	unsigned int input_skip_line:1; /* skip all the data until we've
 					   found a new line */
@@ -60,18 +68,20 @@
    -1 if error */
 int client_send_line(struct client *client, const char *data);
 /* Send line of data to client, prefixed with client->tag */
-void client_send_tagline(struct client *client, const char *data);
+void client_send_tagline(struct client_command_context *cmd, const char *data);
 
 /* Send BAD command error to client. msg can be NULL. */
-void client_send_command_error(struct client *client, const char *msg);
+void client_send_command_error(struct client_command_context *cmd,
+			       const char *msg);
 
 /* Read a number of arguments. Returns TRUE if everything was read or
    FALSE if either needs more data or error occured. */
-int client_read_args(struct client *client, unsigned int count,
+int client_read_args(struct client_command_context *cmd, unsigned int count,
 		     unsigned int flags, struct imap_arg **args);
 /* Reads a number of string arguments. ... is a list of pointers where to
    store the arguments. */
-int client_read_string_args(struct client *client, unsigned int count, ...);
+int client_read_string_args(struct client_command_context *cmd,
+			    unsigned int count, ...);
 
 void clients_init(void);
 void clients_deinit(void);

Index: cmd-append.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-append.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- cmd-append.c	5 Feb 2005 12:01:41 -0000	1.53
+++ cmd-append.c	5 Feb 2005 18:07:26 -0000	1.54
@@ -14,6 +14,7 @@
 
 struct cmd_append_context {
 	struct client *client;
+        struct client_command_context *cmd;
 	struct mail_storage *storage;
 	struct mailbox *box;
         struct mailbox_transaction_context *t;
@@ -25,11 +26,12 @@
 	struct mail_save_context *save_ctx;
 };
 
-static int cmd_append_continue_message(struct client *client);
+static int cmd_append_continue_message(struct client_command_context *cmd);
 
 static void client_input(void *context)
 {
 	struct client *client = context;
+	struct client_command_context *cmd = &client->cmd;
 
 	client->last_input = ioloop_time;
 
@@ -50,12 +52,12 @@
 		   until newline is found. */
 		client->input_skip_line = TRUE;
 
-		client_send_command_error(client, "Too long argument.");
+		client_send_command_error(cmd, "Too long argument.");
 		_client_reset_command(client);
 		break;
 	}
 
-	if (client->cmd_func(client)) {
+	if (cmd->func(cmd)) {
 		/* command execution was finished */
 		client->bad_counter = 0;
 		_client_reset_command(client);
@@ -119,16 +121,16 @@
 	if (ctx->t != NULL)
 		mailbox_transaction_rollback(ctx->t);
 
-	if (ctx->box != ctx->client->mailbox && ctx->box != NULL)
+	if (ctx->box != ctx->cmd->client->mailbox && ctx->box != NULL)
 		mailbox_close(ctx->box);
 
 	(void)i_stream_get_data(ctx->client->input, &size);
 	ctx->client->input_pending = size != 0;
 }
 
-static int cmd_append_continue_cancel(struct client *client)
+static int cmd_append_continue_cancel(struct client_command_context *cmd)
 {
-	struct cmd_append_context *ctx = client->cmd_context;
+	struct cmd_append_context *ctx = cmd->context;
 	size_t size;
 
 	(void)i_stream_read(ctx->input);
@@ -156,14 +158,15 @@
 					   ctx->msg_size);
 
 	ctx->client->command_pending = TRUE;
-	ctx->client->cmd_func = cmd_append_continue_cancel;
-	ctx->client->cmd_context = ctx;
-	return cmd_append_continue_cancel(ctx->client);
+	ctx->cmd->func = cmd_append_continue_cancel;
+	ctx->cmd->context = ctx;
+	return cmd_append_continue_cancel(ctx->cmd);
 }
 
-static int cmd_append_continue_parsing(struct client *client)
+static int cmd_append_continue_parsing(struct client_command_context *cmd)
 {
-	struct cmd_append_context *ctx = client->cmd_context;
+	struct client *client = cmd->client;
+	struct cmd_append_context *ctx = cmd->context;
 	struct imap_arg *args;
 	struct imap_arg_list *flags_list;
 	enum mail_flags flags;
@@ -181,7 +184,7 @@
 				    IMAP_PARSE_FLAG_LITERAL_SIZE, &args);
 	if (ret == -1) {
 		if (ctx->box != NULL)
-			client_send_command_error(client, NULL);
+			client_send_command_error(cmd, NULL);
 		cmd_append_finish(ctx);
 		return TRUE;
 	}
@@ -203,22 +206,22 @@
 		ret = mailbox_transaction_commit(ctx->t, 0);
 		ctx->t = NULL;
 		if (ret < 0) {
-			client_send_storage_error(client, ctx->storage);
+			client_send_storage_error(cmd, ctx->storage);
 			cmd_append_finish(ctx);
 			return TRUE;
 		}
 
-		sync_flags = ctx->box == client->mailbox ?
+		sync_flags = ctx->box == cmd->client->mailbox ?
 			0 : MAILBOX_SYNC_FLAG_FAST;
 
 		client->input_skip_line = TRUE;
 		cmd_append_finish(ctx);
-		return cmd_sync(client, sync_flags, "OK Append completed.");
+		return cmd_sync(cmd, sync_flags, "OK Append completed.");
 	}
 
 	if (!validate_args(args, &flags_list, &internal_date_str,
 			   &ctx->msg_size, &nonsync)) {
-		client_send_command_error(client, "Invalid arguments.");
+		client_send_command_error(cmd, "Invalid arguments.");
 		return cmd_append_cancel(ctx, nonsync);
 	}
 
@@ -229,7 +232,7 @@
 	}
 
 	if (flags_list != NULL) {
-		if (!client_parse_mail_flags(client, flags_list->args,
+		if (!client_parse_mail_flags(cmd, flags_list->args,
 					     &flags, &keywords_list))
 			return cmd_append_cancel(ctx, nonsync);
 		keywords = keywords_list == NULL ? NULL :
@@ -245,13 +248,13 @@
 		timezone_offset = 0;
 	} else if (!imap_parse_datetime(internal_date_str,
 					&internal_date, &timezone_offset)) {
-		client_send_tagline(client, "BAD Invalid internal date.");
+		client_send_tagline(cmd, "BAD Invalid internal date.");
 		return cmd_append_cancel(ctx, nonsync);
 	}
 
 	if (ctx->msg_size == 0) {
 		/* no message data, abort */
-		client_send_tagline(client, "NO Append aborted.");
+		client_send_tagline(cmd, "NO Append aborted.");
 		cmd_append_finish(ctx);
 		return TRUE;
 	}
@@ -276,13 +279,14 @@
 		mailbox_keywords_free(ctx->t, keywords);
 
 	client->command_pending = TRUE;
-	client->cmd_func = cmd_append_continue_message;
-	return cmd_append_continue_message(client);
+	cmd->func = cmd_append_continue_message;
+	return cmd_append_continue_message(cmd);
 }
 
-static int cmd_append_continue_message(struct client *client)
+static int cmd_append_continue_message(struct client_command_context *cmd)
 {
-	struct cmd_append_context *ctx = client->cmd_context;
+	struct client *client = cmd->client;
+	struct cmd_append_context *ctx = cmd->context;
 	size_t size;
 	int failed;
 
@@ -310,7 +314,7 @@
 
 		if (ctx->save_ctx == NULL) {
 			/* failed above */
-			client_send_storage_error(client, ctx->storage);
+			client_send_storage_error(cmd, ctx->storage);
 			failed = TRUE;
 		} else if (client->input->eof) {
 			/* client disconnected */
@@ -318,7 +322,7 @@
 			mailbox_save_cancel(ctx->save_ctx);
 		} else if (mailbox_save_finish(ctx->save_ctx, NULL) < 0) {
 			failed = TRUE;
-			client_send_storage_error(client, ctx->storage);
+			client_send_storage_error(cmd, ctx->storage);
 		}
 		ctx->save_ctx = NULL;
 
@@ -330,57 +334,60 @@
 		/* prepare for next message */
 		client->command_pending = FALSE;
 		imap_parser_reset(ctx->save_parser);
-		client->cmd_func = cmd_append_continue_parsing;
-		return cmd_append_continue_parsing(client);
+		cmd->func = cmd_append_continue_parsing;
+		return cmd_append_continue_parsing(cmd);
 	}
 
 	return FALSE;
 }
 
-static struct mailbox *get_mailbox(struct client *client, const char *name)
+static struct mailbox *
+get_mailbox(struct client_command_context *cmd, const char *name)
 {
 	struct mail_storage *storage;
 	struct mailbox *box;
 
-	if (!client_verify_mailbox_name(client, name, TRUE, FALSE))
+	if (!client_verify_mailbox_name(cmd, name, TRUE, FALSE))
 		return NULL;
 
-	storage = client_find_storage(client, &name);
+	storage = client_find_storage(cmd, &name);
 	if (storage == NULL)
 		return NULL;
 
-	if (client->mailbox != NULL &&
-	    mailbox_name_equals(mailbox_get_name(client->mailbox), name))
-		return client->mailbox;
+	if (cmd->client->mailbox != NULL &&
+	    mailbox_name_equals(mailbox_get_name(cmd->client->mailbox), name))
+		return cmd->client->mailbox;
 
 	box = mailbox_open(storage, name, MAILBOX_OPEN_FAST |
 			   MAILBOX_OPEN_KEEP_RECENT);
 	if (box == NULL) {
-		client_send_storage_error(client, storage);
+		client_send_storage_error(cmd, storage);
 		return NULL;
 	}
 	return box;
 }
 
-int cmd_append(struct client *client)
+int cmd_append(struct client_command_context *cmd)
 {
+	struct client *client = cmd->client;
         struct cmd_append_context *ctx;
 	struct mailbox_status status;
 	const char *mailbox;
 
 	/* <mailbox> */
-	if (!client_read_string_args(client, 1, &mailbox))
+	if (!client_read_string_args(cmd, 1, &mailbox))
 		return FALSE;
 
-	ctx = p_new(client->cmd_pool, struct cmd_append_context, 1);
+	ctx = p_new(cmd->pool, struct cmd_append_context, 1);
+	ctx->cmd = cmd;
 	ctx->client = client;
-	ctx->box = get_mailbox(client, mailbox);
+	ctx->box = get_mailbox(cmd, mailbox);
 	if (ctx->box != NULL) {
 		ctx->storage = mailbox_get_storage(ctx->box);
 
 		if (mailbox_get_status(ctx->box, STATUS_KEYWORDS,
 				       &status) < 0) {
-			client_send_storage_error(client, ctx->storage);
+			client_send_storage_error(cmd, ctx->storage);
 			mailbox_close(ctx->box);
 			ctx->box = NULL;
 		} else {
@@ -402,7 +409,7 @@
 	ctx->save_parser = imap_parser_create(client->input, client->output,
 					      imap_max_line_length);
 
-	client->cmd_func = cmd_append_continue_parsing;
-	client->cmd_context = ctx;
-	return cmd_append_continue_parsing(client);
+	cmd->func = cmd_append_continue_parsing;
+	cmd->context = ctx;
+	return cmd_append_continue_parsing(cmd);
 }

Index: cmd-authenticate.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-authenticate.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- cmd-authenticate.c	5 Jan 2003 13:09:51 -0000	1.2
+++ cmd-authenticate.c	5 Feb 2005 18:07:26 -0000	1.3
@@ -3,8 +3,8 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_authenticate(struct client *client)
+int cmd_authenticate(struct client_command_context *cmd)
 {
-	client_send_tagline(client, "OK Already authenticated.");
+	client_send_tagline(cmd, "OK Already authenticated.");
 	return TRUE;
 }

Index: cmd-capability.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-capability.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- cmd-capability.c	30 Jun 2003 15:54:17 -0000	1.5
+++ cmd-capability.c	5 Feb 2005 18:07:26 -0000	1.6
@@ -4,11 +4,12 @@
 #include "commands.h"
 #include "str.h"
 
-int cmd_capability(struct client *client)
+int cmd_capability(struct client_command_context *cmd)
 {
-	client_send_line(client, t_strconcat("* CAPABILITY ",
-					     str_c(capability_string), NULL));
+	client_send_line(cmd->client,
+			 t_strconcat("* CAPABILITY ",
+				     str_c(capability_string), NULL));
 
-	client_send_tagline(client, "OK Capability completed.");
+	client_send_tagline(cmd, "OK Capability completed.");
 	return TRUE;
 }

Index: cmd-check.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-check.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- cmd-check.c	24 Sep 2004 11:47:30 -0000	1.6
+++ cmd-check.c	5 Feb 2005 18:07:26 -0000	1.7
@@ -3,11 +3,11 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_check(struct client *client)
+int cmd_check(struct client_command_context *cmd)
 {
-	if (!client_verify_open_mailbox(client))
+	if (!client_verify_open_mailbox(cmd))
 		return TRUE;
 
-	return cmd_sync(client, MAILBOX_SYNC_FLAG_FULL_READ |
+	return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FULL_READ |
 			MAILBOX_SYNC_FLAG_FULL_WRITE, "OK Check completed.");
 }

Index: cmd-close.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-close.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- cmd-close.c	28 Sep 2004 13:19:25 -0000	1.14
+++ cmd-close.c	5 Feb 2005 18:07:26 -0000	1.15
@@ -4,12 +4,13 @@
 #include "commands.h"
 #include "imap-expunge.h"
 
-int cmd_close(struct client *client)
+int cmd_close(struct client_command_context *cmd)
 {
+	struct client *client = cmd->client;
 	struct mailbox *mailbox = client->mailbox;
 	struct mail_storage *storage;
 
-	if (!client_verify_open_mailbox(client))
+	if (!client_verify_open_mailbox(cmd))
 		return TRUE;
 
 	storage = mailbox_get_storage(mailbox);
@@ -23,6 +24,6 @@
 	if (mailbox_close(mailbox) < 0)
                 client_send_untagged_storage_error(client, storage);
 
-	client_send_tagline(client, "OK Close completed.");
+	client_send_tagline(cmd, "OK Close completed.");
 	return TRUE;
 }

Index: cmd-copy.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-copy.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- cmd-copy.c	2 Sep 2004 10:55:47 -0000	1.25
+++ cmd-copy.c	5 Feb 2005 18:07:26 -0000	1.26
@@ -48,8 +48,9 @@
 	return ret;
 }
 
-int cmd_copy(struct client *client)
+int cmd_copy(struct client_command_context *cmd)
 {
+	struct client *client = cmd->client;
 	struct mail_storage *storage;
 	struct mailbox *destbox;
 	struct mailbox_transaction_context *t;
@@ -59,21 +60,21 @@
 	int ret;
 
 	/* <message set> <mailbox> */
-	if (!client_read_string_args(client, 2, &messageset, &mailbox))
+	if (!client_read_string_args(cmd, 2, &messageset, &mailbox))
 		return FALSE;
 
-	if (!client_verify_open_mailbox(client))
+	if (!client_verify_open_mailbox(cmd))
 		return TRUE;
 
 	/* open the destination mailbox */
-	if (!client_verify_mailbox_name(client, mailbox, TRUE, FALSE))
+	if (!client_verify_mailbox_name(cmd, mailbox, TRUE, FALSE))
 		return TRUE;
 
-	search_arg = imap_search_get_arg(client, messageset, client->cmd_uid);
+	search_arg = imap_search_get_arg(cmd, messageset, cmd->uid);
 	if (search_arg == NULL)
 		return TRUE;
 
-	storage = client_find_storage(client, &mailbox);
+	storage = client_find_storage(cmd, &mailbox);
 	if (storage == NULL)
 		return TRUE;
 
@@ -83,7 +84,7 @@
 		destbox = mailbox_open(storage, mailbox, MAILBOX_OPEN_FAST |
 				       MAILBOX_OPEN_KEEP_RECENT);
 		if (destbox == NULL) {
-			client_send_storage_error(client, storage);
+			client_send_storage_error(cmd, storage);
 			return TRUE;
 		}
 	}
@@ -104,13 +105,13 @@
 	}
 
 	if (ret > 0)
-		return cmd_sync(client, sync_flags, "OK Copy completed.");
+		return cmd_sync(cmd, sync_flags, "OK Copy completed.");
 	else if (ret == 0) {
 		/* some messages were expunged, sync them */
-		return cmd_sync(client, 0,
+		return cmd_sync(cmd, 0,
 			"NO Some of the requested messages no longer exist.");
 	} else {
-		client_send_storage_error(client, storage);
+		client_send_storage_error(cmd, storage);
 		return TRUE;
 	}
 }

Index: cmd-create.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-create.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- cmd-create.c	8 Dec 2004 17:22:42 -0000	1.11
+++ cmd-create.c	5 Feb 2005 18:07:26 -0000	1.12
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_create(struct client *client)
+int cmd_create(struct client_command_context *cmd)
 {
 	struct mail_storage *storage;
 	const char *mailbox, *full_mailbox;
@@ -11,11 +11,11 @@
 	size_t len;
 
 	/* <mailbox> */
-	if (!client_read_string_args(client, 1, &mailbox))
+	if (!client_read_string_args(cmd, 1, &mailbox))
 		return FALSE;
 	full_mailbox = mailbox;
 
-	storage = client_find_storage(client, &mailbox);
+	storage = client_find_storage(cmd, &mailbox);
 	if (storage == NULL)
 		return TRUE;
 
@@ -31,12 +31,12 @@
 		full_mailbox = t_strndup(full_mailbox, strlen(full_mailbox)-1);
 	}
 
-	if (!client_verify_mailbox_name(client, full_mailbox, FALSE, TRUE))
+	if (!client_verify_mailbox_name(cmd, full_mailbox, FALSE, TRUE))
 		return TRUE;
 
 	if (mail_storage_mailbox_create(storage, mailbox, directory) < 0)
-		client_send_storage_error(client, storage);
+		client_send_storage_error(cmd, storage);
 	else
-		client_send_tagline(client, "OK Create completed.");
+		client_send_tagline(cmd, "OK Create completed.");
 	return TRUE;
 }

Index: cmd-delete.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-delete.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- cmd-delete.c	22 Jul 2004 21:20:00 -0000	1.7
+++ cmd-delete.c	5 Feb 2005 18:07:26 -0000	1.8
@@ -3,19 +3,20 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_delete(struct client *client)
+int cmd_delete(struct client_command_context *cmd)
 {
+	struct client *client = cmd->client;
 	struct mail_storage *storage;
 	struct mailbox *mailbox;
 	const char *name;
 
 	/* <mailbox> */
-	if (!client_read_string_args(client, 1, &name))
+	if (!client_read_string_args(cmd, 1, &name))
 		return FALSE;
 
 	if (strcasecmp(name, "INBOX") == 0) {
 		/* INBOX can't be deleted */
-		client_send_tagline(client, "NO INBOX can't be deleted.");
+		client_send_tagline(cmd, "NO INBOX can't be deleted.");
 		return TRUE;
 	}
 
@@ -28,14 +29,14 @@
 		if (mailbox_close(mailbox) < 0)
 			client_send_untagged_storage_error(client, storage);
 	} else {
-		storage = client_find_storage(client, &name);
+		storage = client_find_storage(cmd, &name);
 		if (storage == NULL)
 			return TRUE;
 	}
 
 	if (mail_storage_mailbox_delete(storage, name) < 0)
-		client_send_storage_error(client, storage);
+		client_send_storage_error(cmd, storage);
 	else
-		client_send_tagline(client, "OK Delete completed.");
+		client_send_tagline(cmd, "OK Delete completed.");
 	return TRUE;
 }

Index: cmd-examine.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-examine.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cmd-examine.c	5 Jan 2003 13:09:51 -0000	1.3
+++ cmd-examine.c	5 Feb 2005 18:07:26 -0000	1.4
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_examine(struct client *client)
+int cmd_examine(struct client_command_context *cmd)
 {
-	return _cmd_select_full(client, TRUE);
+	return _cmd_select_full(cmd, TRUE);
 }

Index: cmd-expunge.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-expunge.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- cmd-expunge.c	29 Aug 2004 07:52:02 -0000	1.10
+++ cmd-expunge.c	5 Feb 2005 18:07:26 -0000	1.11
@@ -5,48 +5,51 @@
 #include "imap-search.h"
 #include "imap-expunge.h"
 
-int cmd_uid_expunge(struct client *client)
+int cmd_uid_expunge(struct client_command_context *cmd)
 {
+	struct client *client = cmd->client;
 	struct imap_arg *args;
 	struct mail_search_arg *search_arg;
 	const char *uidset;
 
-	if (!client_read_args(client, 1, 0, &args))
+	if (!client_read_args(cmd, 1, 0, &args))
 		return FALSE;
 
-	if (!client_verify_open_mailbox(client))
+	if (!client_verify_open_mailbox(cmd))
 		return TRUE;
 
 	uidset = imap_arg_string(&args[0]);
 	if (uidset == NULL) {
-		client_send_command_error(client, "Invalid arguments.");
+		client_send_command_error(cmd, "Invalid arguments.");
 		return TRUE;
 	}
 
-	search_arg = imap_search_get_arg(client, uidset, TRUE);
+	search_arg = imap_search_get_arg(cmd, uidset, TRUE);
 	if (search_arg == NULL)
 		return TRUE;
 
 	if (imap_expunge(client->mailbox, search_arg)) {
-		return cmd_sync(client, MAILBOX_SYNC_FLAG_FAST,
+		return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST,
 				"OK Expunge completed.");
 	} else {
-		client_send_storage_error(client,
+		client_send_storage_error(cmd,
 					  mailbox_get_storage(client->mailbox));
 		return TRUE;
 	}
 }
 
-int cmd_expunge(struct client *client)
+int cmd_expunge(struct client_command_context *cmd)
 {
-	if (!client_verify_open_mailbox(client))
+	struct client *client = cmd->client;
+
+	if (!client_verify_open_mailbox(cmd))
 		return TRUE;
 
 	if (imap_expunge(client->mailbox, NULL)) {
-		return cmd_sync(client, MAILBOX_SYNC_FLAG_FAST,
+		return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST,
 				"OK Expunge completed.");
 	} else {
-		client_send_storage_error(client,
+		client_send_storage_error(cmd,
 					  mailbox_get_storage(client->mailbox));
 		return TRUE;
 	}

Index: cmd-fetch.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-fetch.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- cmd-fetch.c	11 Nov 2004 17:36:51 -0000	1.25
+++ cmd-fetch.c	5 Feb 2005 18:07:26 -0000	1.26
@@ -18,8 +18,7 @@
 };
 
 static int
-fetch_parse_args(struct client *client, struct imap_fetch_context *ctx,
-		 struct imap_arg *arg)
+fetch_parse_args(struct imap_fetch_context *ctx, struct imap_arg *arg)
 {
 	const char *str, *const *macro;
 
@@ -55,13 +54,13 @@
 				return FALSE;
 		}
 		if (arg->type != IMAP_ARG_EOL) {
-			client_send_command_error(client,
+			client_send_command_error(ctx->cmd,
 				"FETCH list contains non-atoms.");
 			return FALSE;
 		}
 	}
 
-	if (client->cmd_uid) {
+	if (ctx->cmd->uid) {
 		if (!imap_fetch_init_handler(ctx, "UID", &arg))
 			return FALSE;
 	}
@@ -69,8 +68,9 @@
 	return TRUE;
 }
 
-static int cmd_fetch_finish(struct client *client, int failed)
+static int cmd_fetch_finish(struct client_command_context *cmd, int failed)
 {
+	struct client *client = cmd->client;
 	static const char *ok_message = "OK Fetch completed.";
 
 	if (failed) {
@@ -90,27 +90,27 @@
 			client_disconnect_with_error(client, error);
 		} else {
 			/* user error, we'll reply with BAD */
-			client_send_storage_error(client, storage);
+			client_send_storage_error(cmd, storage);
 		}
 		return TRUE;
 	}
 
 	if ((client_workarounds & WORKAROUND_OE6_FETCH_NO_NEWMAIL) != 0) {
-		client_send_tagline(client, ok_message);
+		client_send_tagline(cmd, ok_message);
 		return TRUE;
 	} else {
-		return cmd_sync(client, MAILBOX_SYNC_FLAG_FAST |
-				(client->cmd_uid ? 0 :
-				 MAILBOX_SYNC_FLAG_NO_EXPUNGES), ok_message);
+		return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST |
+				(cmd->uid ? 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES),
+				ok_message);
 	}
 }
 
-static int cmd_fetch_continue(struct client *client)
+static int cmd_fetch_continue(struct client_command_context *cmd)
 {
-        struct imap_fetch_context *ctx = client->cmd_context;
+        struct imap_fetch_context *ctx = cmd->context;
 	int ret;
 
-	if (client->output->closed)
+	if (cmd->client->output->closed)
 		ret = -1;
 	else {
 		if ((ret = imap_fetch(ctx)) == 0) {
@@ -123,39 +123,40 @@
 
 	if (imap_fetch_deinit(ctx) < 0)
 		ret = -1;
-	return cmd_fetch_finish(client, ret < 0);
+	return cmd_fetch_finish(cmd, ret < 0);
 }
 
-int cmd_fetch(struct client *client)
+int cmd_fetch(struct client_command_context *cmd)
 {
-        struct imap_fetch_context *ctx;
+	struct client *client = cmd->client;
+	struct imap_fetch_context *ctx;
 	struct imap_arg *args;
 	struct mail_search_arg *search_arg;
 	const char *messageset;
 	int ret;
 
-	if (!client_read_args(client, 0, 0, &args))
+	if (!client_read_args(cmd, 0, 0, &args))
 		return FALSE;
 
-	if (!client_verify_open_mailbox(client))
+	if (!client_verify_open_mailbox(cmd))
 		return TRUE;
 
 	messageset = imap_arg_string(&args[0]);
 	if (messageset == NULL ||
 	    (args[1].type != IMAP_ARG_LIST && args[1].type != IMAP_ARG_ATOM)) {
-		client_send_command_error(client, "Invalid arguments.");
+		client_send_command_error(cmd, "Invalid arguments.");
 		return TRUE;
 	}
 
-	search_arg = imap_search_get_arg(client, messageset, client->cmd_uid);
+	search_arg = imap_search_get_arg(cmd, messageset, cmd->uid);
 	if (search_arg == NULL)
 		return TRUE;
 
-	ctx = imap_fetch_init(client);
+	ctx = imap_fetch_init(cmd);
 	if (ctx == NULL)
 		return TRUE;
 
-	if (!fetch_parse_args(client, ctx, &args[1])) {
+	if (!fetch_parse_args(ctx, &args[1])) {
 		imap_fetch_deinit(ctx);
 		return TRUE;
 	}
@@ -164,13 +165,13 @@
 	if ((ret = imap_fetch(ctx)) == 0) {
 		/* unfinished */
 		client->command_pending = TRUE;
-		client->cmd_func = cmd_fetch_continue;
-		client->cmd_context = ctx;
+		cmd->func = cmd_fetch_continue;
+		cmd->context = ctx;
 		return FALSE;
 	}
 	if (ret < 0)
 		ctx->failed = TRUE;
 	if (imap_fetch_deinit(ctx) < 0)
 		ret = -1;
-	return cmd_fetch_finish(client, ret < 0);
+	return cmd_fetch_finish(cmd, ret < 0);
 }

Index: cmd-idle.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-idle.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- cmd-idle.c	21 Oct 2004 02:36:29 -0000	1.17
+++ cmd-idle.c	5 Feb 2005 18:07:26 -0000	1.18
@@ -13,6 +13,7 @@
 
 struct cmd_idle_context {
 	struct client *client;
+	struct client_command_context *cmd;
 
 	struct imap_sync_context *sync_ctx;
 	struct timeout *to;
@@ -22,7 +23,7 @@
 	unsigned int sync_pending:1;
 };
 
-static int cmd_idle_continue(struct client *client);
+static int cmd_idle_continue(struct client_command_context *cmd);
 
 static void idle_finish(struct cmd_idle_context *ctx, int done_ok)
 {
@@ -48,9 +49,9 @@
 		mailbox_notify_changes(client->mailbox, 0, NULL, NULL);
 
 	if (done_ok)
-		client_send_tagline(client, "OK Idle completed.");
+		client_send_tagline(ctx->cmd, "OK Idle completed.");
 	else
-		client_send_tagline(client, "BAD Expected DONE.");
+		client_send_tagline(ctx->cmd, "BAD Expected DONE.");
 
 	o_stream_uncork(client->output);
 
@@ -126,13 +127,14 @@
 	else {
 		ctx->sync_pending = FALSE;
 		ctx->sync_ctx = imap_sync_init(ctx->client, box, 0);
-		cmd_idle_continue(ctx->client);
+		cmd_idle_continue(ctx->cmd);
 	}
 }
 
-static int cmd_idle_continue(struct client *client)
+static int cmd_idle_continue(struct client_command_context *cmd)
 {
-	struct cmd_idle_context *ctx = client->cmd_context;
+	struct client *client = cmd->client;
+	struct cmd_idle_context *ctx = cmd->context;
 
 	if (client->output->closed) {
 		idle_finish(ctx, FALSE);
@@ -166,13 +168,15 @@
 	return FALSE;
 }
 
-int cmd_idle(struct client *client)
+int cmd_idle(struct client_command_context *cmd)
 {
+	struct client *client = cmd->client;
 	struct cmd_idle_context *ctx;
 	const char *str;
 	unsigned int interval;
 
-	ctx = p_new(client->cmd_pool, struct cmd_idle_context, 1);
+	ctx = p_new(cmd->pool, struct cmd_idle_context, 1);
+	ctx->cmd = cmd;
 	ctx->client = client;
 
 	if ((client_workarounds & WORKAROUND_OUTLOOK_IDLE) != 0 &&
@@ -197,7 +201,7 @@
 			    IO_READ, idle_client_input, ctx);
 
 	client->command_pending = TRUE;
-	client->cmd_func = cmd_idle_continue;
-	client->cmd_context = ctx;
+	cmd->func = cmd_idle_continue;
+	cmd->context = ctx;
 	return FALSE;
 }

Index: cmd-list.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-list.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- cmd-list.c	11 Sep 2004 10:38:33 -0000	1.43
+++ cmd-list.c	5 Feb 2005 18:07:26 -0000	1.44
@@ -63,14 +63,15 @@
 	return *str == '\0' ? "" : str+1;
 }
 
-static int parse_list_flags(struct client *client, struct imap_arg *args,
-			    enum mailbox_list_flags *list_flags)
+static int
+parse_list_flags(struct client_command_context *cmd, struct imap_arg *args,
+		 enum mailbox_list_flags *list_flags)
 {
 	const char *atom;
 
 	while (args->type != IMAP_ARG_EOL) {
 		if (args->type != IMAP_ARG_ATOM) {
-			client_send_command_error(client,
+			client_send_command_error(cmd,
 				"List options contains non-atoms.");
 			return FALSE;
 		}
@@ -82,7 +83,7 @@
 		else if (strcasecmp(atom, "CHILDREN") == 0)
 			*list_flags |= MAILBOX_LIST_CHILDREN;
 		else {
-			client_send_tagline(client, t_strconcat(
+			client_send_tagline(cmd, t_strconcat(
 				"BAD Invalid list option ", atom, NULL));
 			return FALSE;
 		}
@@ -178,8 +179,10 @@
 }
 
 static void
-list_namespace_init(struct client *client, struct cmd_list_context *ctx)
+list_namespace_init(struct client_command_context *cmd,
+		    struct cmd_list_context *ctx)
 {
+        struct client *client = cmd->client;
 	struct namespace *ns = ctx->ns;
 	const char *cur_prefix, *cur_ref, *cur_mask;
 	enum imap_match_result match;
@@ -206,7 +209,7 @@
 			    ctx->inbox && cur_ref == ctx->ref);
 	}
 
-	ctx->glob = imap_match_init(client->cmd_pool, ctx->mask,
+	ctx->glob = imap_match_init(cmd->pool, ctx->mask,
 				    ctx->inbox && cur_ref == ctx->ref, ns->sep);
 
 	if (*cur_ref != '\0' || *cur_prefix == '\0')
@@ -216,7 +219,7 @@
 		if (cur_prefix[len-1] == ns->sep)
 			cur_prefix = t_strndup(cur_prefix, len-1);
 		match = ns->hidden ? IMAP_MATCH_NO :
-			imap_match(ctx->glob, cur_prefix);
+		       imap_match(ctx->glob, cur_prefix);
 
 		if (match == IMAP_MATCH_YES) {
 			/* The prefix itself matches */
@@ -298,31 +301,33 @@
 						       list_flags);
 }
 
-static int cmd_list_continue(struct client *client)
+static int cmd_list_continue(struct client_command_context *cmd)
 {
-        struct cmd_list_context *ctx = client->cmd_context;
+	struct client *client = cmd->client;
+        struct cmd_list_context *ctx = cmd->context;
 	int ret;
 
 	for (; ctx->ns != NULL; ctx->ns = ctx->ns->next) {
 		if (ctx->list_ctx == NULL)
-			list_namespace_init(client, ctx);
+			list_namespace_init(cmd, ctx);
 
 		if ((ret = list_namespace_mailboxes(client, ctx)) < 0) {
-			client_send_storage_error(client, ctx->ns->storage);
+			client_send_storage_error(cmd, ctx->ns->storage);
 			return TRUE;
 		}
 		if (ret == 0)
 			return FALSE;
 	}
 
-	client_send_tagline(client, !ctx->lsub ?
+	client_send_tagline(cmd, !ctx->lsub ?
 			    "OK List completed." :
 			    "OK Lsub completed.");
 	return TRUE;
 }
 
-int _cmd_list_full(struct client *client, int lsub)
+int _cmd_list_full(struct client_command_context *cmd, int lsub)
 {
+	struct client *client = cmd->client;
 	struct namespace *ns;
 	struct imap_arg *args;
 	enum mailbox_list_flags list_flags;
@@ -330,7 +335,7 @@
 	const char *ref, *mask;
 
 	/* [(<options>)] <reference> <mailbox wildcards> */
-	if (!client_read_args(client, 0, 0, &args))
+	if (!client_read_args(cmd, 0, 0, &args))
 		return FALSE;
 
 	if (lsub) {
@@ -342,7 +347,7 @@
 		list_flags = 0;
 	} else {
 		list_flags = _MAILBOX_LIST_LISTEXT;
-		if (!parse_list_flags(client, IMAP_ARG_LIST(&args[0])->args,
+		if (!parse_list_flags(cmd, IMAP_ARG_LIST(&args[0])->args,
 				      &list_flags))
 			return TRUE;
 		args++;
@@ -356,7 +361,7 @@
 	mask = imap_arg_string(&args[1]);
 
 	if (ref == NULL || mask == NULL) {
-		client_send_command_error(client, "Invalid arguments.");
+		client_send_command_error(cmd, "Invalid arguments.");
 		return TRUE;
 	}
 
@@ -373,9 +378,9 @@
 				"* LIST (\\Noselect) \"", ns->sep_str,
 				"\" \"\"", NULL));
 		}
-		client_send_tagline(client, "OK List completed.");
+		client_send_tagline(cmd, "OK List completed.");
 	} else {
-		ctx = p_new(client->cmd_pool, struct cmd_list_context, 1);
+		ctx = p_new(cmd->pool, struct cmd_list_context, 1);
 		ctx->ref = ref;
 		ctx->mask = mask;
 		ctx->list_flags = list_flags;
@@ -384,21 +389,21 @@
 			(*ref == '\0' && strncasecmp(mask, "INBOX", 5) == 0);
 		ctx->ns = client->namespaces;
 
-		client->cmd_context = ctx;
-		if (!cmd_list_continue(client)) {
+		cmd->context = ctx;
+		if (!cmd_list_continue(cmd)) {
 			/* unfinished */
 			client->command_pending = TRUE;
-			client->cmd_func = cmd_list_continue;
+			cmd->func = cmd_list_continue;
 			return FALSE;
 		}
 
-		client->cmd_context = NULL;
+		cmd->context = NULL;
 		return TRUE;
 	}
 	return TRUE;
 }
 
-int cmd_list(struct client *client)
+int cmd_list(struct client_command_context *cmd)
 {
-	return _cmd_list_full(client, FALSE);
+	return _cmd_list_full(cmd, FALSE);
 }

Index: cmd-login.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-login.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- cmd-login.c	5 Jan 2003 13:09:51 -0000	1.2
+++ cmd-login.c	5 Feb 2005 18:07:26 -0000	1.3
@@ -3,8 +3,8 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_login(struct client *client)
+int cmd_login(struct client_command_context *cmd)
 {
-	client_send_tagline(client, "OK Already logged in.");
+	client_send_tagline(cmd, "OK Already logged in.");
 	return TRUE;
 }

Index: cmd-logout.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-logout.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- cmd-logout.c	5 Nov 2004 15:36:38 -0000	1.8
+++ cmd-logout.c	5 Feb 2005 18:07:26 -0000	1.9
@@ -4,8 +4,10 @@
 #include "ostream.h"
 #include "commands.h"
 
-int cmd_logout(struct client *client)
+int cmd_logout(struct client_command_context *cmd)
 {
+	struct client *client = cmd->client;
+
 	client_send_line(client, "* BYE Logging out");
 	o_stream_uncork(client->output);
 
@@ -17,7 +19,7 @@
 		client->mailbox = NULL;
 	}
 
-	client_send_tagline(client, "OK Logout completed.");
+	client_send_tagline(cmd, "OK Logout completed.");
 	client_disconnect(client);
 	return TRUE;
 }

Index: cmd-lsub.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-lsub.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cmd-lsub.c	5 Jan 2003 13:09:51 -0000	1.3
+++ cmd-lsub.c	5 Feb 2005 18:07:26 -0000	1.4
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_lsub(struct client *client)
+int cmd_lsub(struct client_command_context *cmd)
 {
-	return _cmd_list_full(client, TRUE);
+	return _cmd_list_full(cmd, TRUE);
 }

Index: cmd-namespace.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-namespace.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cmd-namespace.c	22 Jul 2004 21:20:00 -0000	1.3
+++ cmd-namespace.c	5 Feb 2005 18:07:26 -0000	1.4
@@ -33,8 +33,9 @@
 		str_append(str, "NIL");
 }
 
-int cmd_namespace(struct client *client)
+int cmd_namespace(struct client_command_context *cmd)
 {
+	struct client *client = cmd->client;
 	string_t *str;
 
 	str = t_str_new(256);
@@ -47,6 +48,6 @@
         list_namespaces(client->namespaces, NAMESPACE_PUBLIC, str);
 
 	client_send_line(client, str_c(str));
-	client_send_tagline(client, "OK Namespace completed.");
+	client_send_tagline(cmd, "OK Namespace completed.");
 	return TRUE;
 }

Index: cmd-noop.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-noop.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cmd-noop.c	18 Aug 2004 23:53:39 -0000	1.4
+++ cmd-noop.c	5 Feb 2005 18:07:26 -0000	1.5
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_noop(struct client *client)
+int cmd_noop(struct client_command_context *cmd)
 {
-	return cmd_sync(client, 0, "OK NOOP completed.");
+	return cmd_sync(cmd, 0, "OK NOOP completed.");
 }

Index: cmd-rename.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-rename.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- cmd-rename.c	22 Jul 2004 21:20:00 -0000	1.7
+++ cmd-rename.c	5 Feb 2005 18:07:26 -0000	1.8
@@ -3,36 +3,36 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_rename(struct client *client)
+int cmd_rename(struct client_command_context *cmd)
 {
 	struct mail_storage *old_storage, *new_storage;
 	const char *oldname, *newname;
 
 	/* <old name> <new name> */
-	if (!client_read_string_args(client, 2, &oldname, &newname))
+	if (!client_read_string_args(cmd, 2, &oldname, &newname))
 		return FALSE;
 
-	if (!client_verify_mailbox_name(client, newname, FALSE, TRUE))
+	if (!client_verify_mailbox_name(cmd, newname, FALSE, TRUE))
 		return TRUE;
 
-	old_storage = client_find_storage(client, &oldname);
+	old_storage = client_find_storage(cmd, &oldname);
 	if (old_storage == NULL)
 		return TRUE;
 
-	new_storage = client_find_storage(client, &newname);
+	new_storage = client_find_storage(cmd, &newname);
 	if (new_storage == NULL)
 		return TRUE;
 
 	if (old_storage != new_storage) {
-		client_send_tagline(client,
+		client_send_tagline(cmd,
 			"NO Can't rename mailbox to another storage type.");
 		return TRUE;
 	}
 
 	if (mail_storage_mailbox_rename(old_storage, oldname, newname) < 0)
-		client_send_storage_error(client, old_storage);
+		client_send_storage_error(cmd, old_storage);
 	else
-		client_send_tagline(client, "OK Rename completed.");
+		client_send_tagline(cmd, "OK Rename completed.");
 
 	return TRUE;
 }

Index: cmd-search.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-search.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- cmd-search.c	29 Aug 2004 07:52:02 -0000	1.22
+++ cmd-search.c	5 Feb 2005 18:07:26 -0000	1.23
@@ -8,9 +8,10 @@
 
 #define STRBUF_SIZE 1024
 
-static int imap_search(struct client *client, const char *charset,
+static int imap_search(struct client_command_context *cmd, const char *charset,
 		       struct mail_search_arg *sargs)
 {
+	struct client *client = cmd->client;
         struct mail_search_context *ctx;
         struct mailbox_transaction_context *trans;
 	const struct mail *mail;
@@ -18,7 +19,7 @@
 	int ret, uid, first = TRUE;
 
 	str = t_str_new(STRBUF_SIZE);
-	uid = client->cmd_uid;
+	uid = cmd->uid;
 
 	trans = mailbox_transaction_begin(client->mailbox, FALSE);
 	ctx = mailbox_search_init(trans, charset, sargs,
@@ -53,8 +54,9 @@
 	return ret == 0;
 }
 
-int cmd_search(struct client *client)
+int cmd_search(struct client_command_context *cmd)
 {
+	struct client *client = cmd->client;
 	struct mail_search_arg *sargs;
 	struct imap_arg *args;
 	int args_count;
@@ -65,12 +67,12 @@
 		if (args_count == -2)
 			return FALSE;
 
-		client_send_command_error(client, args_count < 0 ? NULL :
+		client_send_command_error(cmd, args_count < 0 ? NULL :
 					  "Missing SEARCH arguments.");
 		return TRUE;
 	}
 
-	if (!client_verify_open_mailbox(client))
+	if (!client_verify_open_mailbox(cmd))
 		return TRUE;
 
 	if (args->type == IMAP_ARG_ATOM &&
@@ -79,7 +81,7 @@
 		args++;
 		if (args->type != IMAP_ARG_ATOM &&
 		    args->type != IMAP_ARG_STRING) {
-			client_send_command_error(client,
+			client_send_command_error(cmd,
 						  "Invalid charset argument.");
 			return TRUE;
 		}
@@ -90,17 +92,17 @@
 		charset = NULL;
 	}
 
-	sargs = imap_search_args_build(client->cmd_pool, client->mailbox, args, &error);
+	sargs = imap_search_args_build(cmd->pool, client->mailbox,
+				       args, &error);
 	if (sargs == NULL) {
 		/* error in search arguments */
-		client_send_tagline(client, t_strconcat("NO ", error, NULL));
-	} else if (imap_search(client, charset, sargs)) {
-		return cmd_sync(client, MAILBOX_SYNC_FLAG_FAST |
-				(client->cmd_uid ?
-				 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES),
+		client_send_tagline(cmd, t_strconcat("NO ", error, NULL));
+	} else if (imap_search(cmd, charset, sargs)) {
+		return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST |
+				(cmd->uid ? 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES),
 				"OK Search completed.");
 	} else {
-		client_send_storage_error(client,
+		client_send_storage_error(cmd,
 					  mailbox_get_storage(client->mailbox));
 	}
 

Index: cmd-select.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-select.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- cmd-select.c	24 Sep 2004 11:47:30 -0000	1.33
+++ cmd-select.c	5 Feb 2005 18:07:26 -0000	1.34
@@ -4,15 +4,16 @@
 #include "commands.h"
 #include "imap-sync.h"
 
-int _cmd_select_full(struct client *client, int readonly)
+int _cmd_select_full(struct client_command_context *cmd, int readonly)
 {
+	struct client *client = cmd->client;
 	struct mail_storage *storage;
 	struct mailbox *box;
 	struct mailbox_status status;
 	const char *mailbox;
 
 	/* <mailbox> */
-	if (!client_read_string_args(client, 1, &mailbox))
+	if (!client_read_string_args(cmd, 1, &mailbox))
 		return FALSE;
 
 	if (client->mailbox != NULL) {
@@ -24,19 +25,19 @@
 		}
 	}
 
-	storage = client_find_storage(client, &mailbox);
+	storage = client_find_storage(cmd, &mailbox);
 	if (storage == NULL)
 		return TRUE;
 
 	box = mailbox_open(storage, mailbox, !readonly ? 0 :
 			   (MAILBOX_OPEN_READONLY | MAILBOX_OPEN_KEEP_RECENT));
 	if (box == NULL) {
-		client_send_storage_error(client, storage);
+		client_send_storage_error(cmd, storage);
 		return TRUE;
 	}
 
 	if (imap_sync_nonselected(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
-		client_send_storage_error(client, storage);
+		client_send_storage_error(cmd, storage);
 		mailbox_close(box);
 		return TRUE;
 	}
@@ -45,7 +46,7 @@
 			       STATUS_FIRST_UNSEEN_SEQ | STATUS_UIDVALIDITY |
 			       STATUS_UIDNEXT | STATUS_KEYWORDS,
 			       &status) < 0) {
-		client_send_storage_error(client, storage);
+		client_send_storage_error(cmd, storage);
 		mailbox_close(box);
 		return TRUE;
 	}
@@ -87,13 +88,13 @@
 				 "Disk space is full, delete some messages.");
 	}
 
-	client_send_tagline(client, mailbox_is_readonly(box) ?
+	client_send_tagline(cmd, mailbox_is_readonly(box) ?
 			    "OK [READ-ONLY] Select completed." :
 			    "OK [READ-WRITE] Select completed.");
 	return TRUE;
 }
 
-int cmd_select(struct client *client)
+int cmd_select(struct client_command_context *cmd)
 {
-	return _cmd_select_full(client, FALSE);
+	return _cmd_select_full(cmd, FALSE);
 }

Index: cmd-sort.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-sort.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- cmd-sort.c	8 Oct 2004 17:51:47 -0000	1.17
+++ cmd-sort.c	5 Feb 2005 18:07:26 -0000	1.18
@@ -25,7 +25,7 @@
 };
 
 static enum mail_sort_type *
-get_sort_program(struct client *client, struct imap_arg *args)
+get_sort_program(struct client_command_context *cmd, struct imap_arg *args)
 {
 	enum mail_sort_type type;
 	buffer_t *buf;
@@ -33,7 +33,7 @@
 
 	if (args->type == IMAP_ARG_EOL) {
 		/* empyty list */
-		client_send_command_error(client, "Empty sort program.");
+		client_send_command_error(cmd, "Empty sort program.");
 		return NULL;
 	}
 
@@ -49,7 +49,7 @@
 		}
 
 		if (sort_names[i].type == MAIL_SORT_END) {
-			client_send_command_error(client, t_strconcat(
+			client_send_command_error(cmd, t_strconcat(
 				"Unknown sort argument: ", arg, NULL));
 			return NULL;
 		}
@@ -63,7 +63,7 @@
 	buffer_append(buf, &type, sizeof(type));
 
 	if (args->type != IMAP_ARG_EOL) {
-		client_send_command_error(client,
+		client_send_command_error(cmd,
 					  "Invalid sort list argument.");
 		return NULL;
 	}
@@ -71,8 +71,9 @@
 	return buffer_free_without_data(buf);
 }
 
-int cmd_sort(struct client *client)
+int cmd_sort(struct client_command_context *cmd)
 {
+	struct client *client = cmd->client;
 	struct mail_search_arg *sargs;
 	enum mail_sort_type *sorting;
 	struct imap_arg *args;
@@ -85,28 +86,28 @@
 		return FALSE;
 
 	if (args_count < 3) {
-		client_send_command_error(client, args_count < 0 ? NULL :
+		client_send_command_error(cmd, args_count < 0 ? NULL :
 					  "Missing or invalid arguments.");
 		return TRUE;
 	}
 
-	if (!client_verify_open_mailbox(client))
+	if (!client_verify_open_mailbox(cmd))
 		return TRUE;
 
 	/* sort program */
 	if (args->type != IMAP_ARG_LIST) {
-		client_send_command_error(client, "Invalid sort argument.");
+		client_send_command_error(cmd, "Invalid sort argument.");
 		return TRUE;
 	}
 
-	sorting = get_sort_program(client, IMAP_ARG_LIST(args)->args);
+	sorting = get_sort_program(cmd, IMAP_ARG_LIST(args)->args);
 	if (sorting == NULL)
 		return TRUE;
 	args++;
 
 	/* charset */
 	if (args->type != IMAP_ARG_ATOM && args->type != IMAP_ARG_STRING) {
-		client_send_command_error(client,
+		client_send_command_error(cmd,
 					  "Invalid charset argument.");
 		return TRUE;
 	}
@@ -118,15 +119,14 @@
 	sargs = imap_search_args_build(pool, client->mailbox, args, &error);
 	if (sargs == NULL) {
 		/* error in search arguments */
-		client_send_tagline(client, t_strconcat("NO ", error, NULL));
-	} else if (imap_sort(client, charset, sargs, sorting) == 0) {
+		client_send_tagline(cmd, t_strconcat("NO ", error, NULL));
+	} else if (imap_sort(cmd, charset, sargs, sorting) == 0) {
 		pool_unref(pool);
-		return cmd_sync(client, MAILBOX_SYNC_FLAG_FAST |
-				(client->cmd_uid ?
-				 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES),
+		return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST |
+				(cmd->uid ? 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES),
 				"OK Sort completed.");
 	} else {
-		client_send_storage_error(client,
+		client_send_storage_error(cmd,
 					  mailbox_get_storage(client->mailbox));
 	}
 

Index: cmd-status.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-status.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- cmd-status.c	18 Aug 2004 23:53:39 -0000	1.20
+++ cmd-status.c	5 Feb 2005 18:07:26 -0000	1.21
@@ -8,7 +8,7 @@
 
 /* Returns status items, or -1 if error */
 static enum mailbox_status_items
-get_status_items(struct client *client, struct imap_arg *args)
+get_status_items(struct client_command_context *cmd, struct imap_arg *args)
 {
 	const char *item;
 	enum mailbox_status_items items;
@@ -17,7 +17,7 @@
 	for (; args->type != IMAP_ARG_EOL; args++) {
 		if (args->type != IMAP_ARG_ATOM) {
 			/* list may contain only atoms */
-			client_send_command_error(client,
+			client_send_command_error(cmd,
 				"Status list contains non-atoms.");
 			return -1;
 		}
@@ -35,7 +35,7 @@
 		else if (strcmp(item, "UNSEEN") == 0)
 			items |= STATUS_UNSEEN;
 		else {
-			client_send_tagline(client, t_strconcat(
+			client_send_tagline(cmd, t_strconcat(
 				"BAD Invalid status item ", item, NULL));
 			return -1;
 		}
@@ -76,8 +76,9 @@
 	return !failed;
 }
 
-int cmd_status(struct client *client)
+int cmd_status(struct client_command_context *cmd)
 {
+	struct client *client = cmd->client;
 	struct imap_arg *args;
 	struct mailbox_status status;
 	enum mailbox_status_items items;
@@ -86,29 +87,29 @@
 	string_t *str;
 
 	/* <mailbox> <status items> */
-	if (!client_read_args(client, 2, 0, &args))
+	if (!client_read_args(cmd, 2, 0, &args))
 		return FALSE;
 
 	mailbox = imap_arg_string(&args[0]);
 	if (mailbox == NULL || args[1].type != IMAP_ARG_LIST) {
-		client_send_command_error(client, "Status items must be list.");
+		client_send_command_error(cmd, "Status items must be list.");
 		return TRUE;
 	}
 
 	/* get the items client wants */
-	items = get_status_items(client, IMAP_ARG_LIST(&args[1])->args);
+	items = get_status_items(cmd, IMAP_ARG_LIST(&args[1])->args);
 	if (items == (enum mailbox_status_items)-1) {
 		/* error */
 		return TRUE;
 	}
 
-	storage = client_find_storage(client, &mailbox);
+	storage = client_find_storage(cmd, &mailbox);
 	if (storage == NULL)
 		return FALSE;
 
 	/* get status */
 	if (!get_mailbox_status(client, storage, mailbox, items, &status)) {
-		client_send_storage_error(client, storage);
+		client_send_storage_error(cmd, storage);
 		return TRUE;
 	}
 
@@ -133,7 +134,7 @@
 	str_append_c(str, ')');
 
 	client_send_line(client, str_c(str));
-	client_send_tagline(client, "OK Status completed.");
+	client_send_tagline(cmd, "OK Status completed.");
 
 	return TRUE;
 }

Index: cmd-store.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-store.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- cmd-store.c	5 Feb 2005 12:01:41 -0000	1.30
+++ cmd-store.c	5 Feb 2005 18:07:26 -0000	1.31
@@ -6,7 +6,7 @@
 #include "imap-search.h"
 #include "imap-util.h"
 
-static int get_modify_type(struct client *client, const char *item,
+static int get_modify_type(struct client_command_context *cmd, const char *item,
 			   enum modify_type *modify_type, int *silent)
 {
 	if (*item == '+') {
@@ -20,14 +20,14 @@
 	}
 
 	if (strncasecmp(item, "FLAGS", 5) != 0) {
-		client_send_tagline(client, t_strconcat(
+		client_send_tagline(cmd, t_strconcat(
 			"NO Invalid item ", item, NULL));
 		return FALSE;
 	}
 
 	*silent = strcasecmp(item+5, ".SILENT") == 0;
 	if (!*silent && item[5] != '\0') {
-		client_send_tagline(client, t_strconcat(
+		client_send_tagline(cmd, t_strconcat(
 			"NO Invalid item ", item, NULL));
 		return FALSE;
 	}
@@ -35,8 +35,9 @@
 	return TRUE;
 }
 
-int cmd_store(struct client *client)
+int cmd_store(struct client_command_context *cmd)
 {
+	struct client *client = cmd->client;
 	struct imap_arg *args;
 	enum mail_flags flags;
 	const char *const *keywords_list;
@@ -50,10 +51,10 @@
 	const char *messageset, *item;
 	int silent, failed;
 
-	if (!client_read_args(client, 0, 0, &args))
+	if (!client_read_args(cmd, 0, 0, &args))
 		return FALSE;
 
-	if (!client_verify_open_mailbox(client))
+	if (!client_verify_open_mailbox(cmd))
 		return TRUE;
 
 	/* validate arguments */
@@ -61,26 +62,26 @@
 	item = imap_arg_string(&args[1]);
 
 	if (messageset == NULL || item == NULL) {
-		client_send_command_error(client, "Invalid arguments.");
+		client_send_command_error(cmd, "Invalid arguments.");
 		return TRUE;
 	}
 
-	if (!get_modify_type(client, item, &modify_type, &silent))
+	if (!get_modify_type(cmd, item, &modify_type, &silent))
 		return TRUE;
 
 	if (args[2].type == IMAP_ARG_LIST) {
-		if (!client_parse_mail_flags(client,
+		if (!client_parse_mail_flags(cmd,
 					     IMAP_ARG_LIST(&args[2])->args,
 					     &flags, &keywords_list))
 			return TRUE;
 	} else {
-		if (!client_parse_mail_flags(client, args+2,
+		if (!client_parse_mail_flags(cmd, args+2,
 					     &flags, &keywords_list))
 			return TRUE;
 	}
 
 	box = client->mailbox;
-	search_arg = imap_search_get_arg(client, messageset, client->cmd_uid);
+	search_arg = imap_search_get_arg(cmd, messageset, cmd->uid);
 	if (search_arg == NULL)
 		return TRUE;
 
@@ -121,12 +122,11 @@
 	}
 
 	if (!failed) {
-		return cmd_sync(client, MAILBOX_SYNC_FLAG_FAST |
-				(client->cmd_uid ?
-				 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES),
+		return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST |
+				(cmd->uid ? 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES),
 				"OK Store completed.");
 	} else {
-		client_send_storage_error(client, mailbox_get_storage(box));
+		client_send_storage_error(cmd, mailbox_get_storage(box));
 		return TRUE;
 	}
 }

Index: cmd-subscribe.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-subscribe.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- cmd-subscribe.c	22 Jul 2004 21:20:00 -0000	1.10
+++ cmd-subscribe.c	5 Feb 2005 18:07:26 -0000	1.11
@@ -3,33 +3,33 @@
 #include "common.h"
 #include "commands.h"
 
-int _cmd_subscribe_full(struct client *client, int subscribe)
+int _cmd_subscribe_full(struct client_command_context *cmd, int subscribe)
 {
         struct mail_storage *storage;
 	const char *mailbox;
 
 	/* <mailbox> */
-	if (!client_read_string_args(client, 1, &mailbox))
+	if (!client_read_string_args(cmd, 1, &mailbox))
 		return FALSE;
 
-	if (!client_verify_mailbox_name(client, mailbox, subscribe, FALSE))
+	if (!client_verify_mailbox_name(cmd, mailbox, subscribe, FALSE))
 		return TRUE;
 
-	storage = client_find_storage(client, &mailbox);
+	storage = client_find_storage(cmd, &mailbox);
 	if (storage == NULL)
 		return TRUE;
 
 	if (mail_storage_set_subscribed(storage, mailbox, subscribe) < 0)
-		client_send_storage_error(client, storage);
+		client_send_storage_error(cmd, storage);
 	else {
-		client_send_tagline(client, subscribe ?
+		client_send_tagline(cmd, subscribe ?
 				    "OK Subscribe completed." :
 				    "OK Unsubscribe completed.");
 	}
 	return TRUE;
 }
 
-int cmd_subscribe(struct client *client)
+int cmd_subscribe(struct client_command_context *cmd)
 {
-	return _cmd_subscribe_full(client, TRUE);
+	return _cmd_subscribe_full(cmd, TRUE);
 }

Index: cmd-thread.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-thread.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- cmd-thread.c	18 Aug 2004 23:53:39 -0000	1.8
+++ cmd-thread.c	5 Feb 2005 18:07:26 -0000	1.9
@@ -6,8 +6,9 @@
 #include "imap-search.h"
 #include "imap-thread.h"
 
-int cmd_thread(struct client *client)
+int cmd_thread(struct client_command_context *cmd)
 {
+	struct client *client = cmd->client;
 	enum mail_thread_type threading;
 	struct mail_search_arg *sargs;
 	struct imap_arg *args;
@@ -20,16 +21,16 @@
 		return FALSE;
 
 	if (args_count < 3) {
-		client_send_command_error(client, args_count < 0 ? NULL :
+		client_send_command_error(cmd, args_count < 0 ? NULL :
 					  "Missing or invalid arguments.");
 		return TRUE;
 	}
 
-	if (!client_verify_open_mailbox(client))
+	if (!client_verify_open_mailbox(cmd))
 		return TRUE;
 
 	if (args->type != IMAP_ARG_ATOM && args->type != IMAP_ARG_STRING) {
-		client_send_command_error(client,
+		client_send_command_error(cmd,
 					  "Invalid thread algorithm argument.");
 		return TRUE;
 	}
@@ -38,18 +39,18 @@
 	if (strcasecmp(str, "REFERENCES") == 0)
 		threading = MAIL_THREAD_REFERENCES;
 	else if (strcasecmp(str, "ORDEREDSUBJECT") == 0) {
-		client_send_command_error(client,
+		client_send_command_error(cmd,
 			"ORDEREDSUBJECT threading is currently not supported.");
 		return TRUE;
 	} else {
-		client_send_command_error(client, "Unknown thread algorithm.");
+		client_send_command_error(cmd, "Unknown thread algorithm.");
 		return TRUE;
 	}
 	args++;
 
 	/* charset */
 	if (args->type != IMAP_ARG_ATOM && args->type != IMAP_ARG_STRING) {
-		client_send_command_error(client,
+		client_send_command_error(cmd,
 					  "Invalid charset argument.");
 		return TRUE;
 	}
@@ -61,15 +62,14 @@
 	sargs = imap_search_args_build(pool, client->mailbox, args, &error);
 	if (sargs == NULL) {
 		/* error in search arguments */
-		client_send_tagline(client, t_strconcat("NO ", error, NULL));
-	} else if (imap_thread(client, charset, sargs, threading) == 0) {
+		client_send_tagline(cmd, t_strconcat("NO ", error, NULL));
+	} else if (imap_thread(cmd, charset, sargs, threading) == 0) {
 		pool_unref(pool);
-		return cmd_sync(client, MAILBOX_SYNC_FLAG_FAST |
-				(client->cmd_uid ?
-				 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES),
+		return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST |
+				(cmd->uid ? 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES),
 				"OK Thread completed.");
 	} else {
-		client_send_storage_error(client,
+		client_send_storage_error(cmd,
 					  mailbox_get_storage(client->mailbox));
 	}
 

Index: cmd-uid.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-uid.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- cmd-uid.c	14 May 2003 17:23:11 -0000	1.5
+++ cmd-uid.c	5 Feb 2005 18:07:26 -0000	1.6
@@ -3,23 +3,23 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_uid(struct client *client)
+int cmd_uid(struct client_command_context *cmd)
 {
-	const char *cmd;
+	const char *cmd_name;
 
 	/* UID <command> <args> */
-	cmd = imap_parser_read_word(client->parser);
-	if (cmd == NULL)
+	cmd_name = imap_parser_read_word(cmd->client->parser);
+	if (cmd_name == NULL)
 		return FALSE;
 
-	client->cmd_func = command_find(t_strconcat("UID ", cmd, NULL));
+	cmd->func = command_find(t_strconcat("UID ", cmd_name, NULL));
 
-	if (client->cmd_func != NULL) {
-		client->cmd_uid = TRUE;
-		return client->cmd_func(client);
+	if (cmd->func != NULL) {
+		cmd->uid = TRUE;
+		return cmd->func(cmd);
 	} else {
-		client_send_tagline(client, t_strconcat(
-			"BAD Unknown UID command ", cmd, NULL));
+		client_send_tagline(cmd, t_strconcat(
+			"BAD Unknown UID command ", cmd_name, NULL));
 		return TRUE;
 	}
 }

Index: cmd-unselect.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-unselect.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cmd-unselect.c	27 Apr 2004 20:25:52 -0000	1.4
+++ cmd-unselect.c	5 Feb 2005 18:07:26 -0000	1.5
@@ -3,11 +3,12 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_unselect(struct client *client)
+int cmd_unselect(struct client_command_context *cmd)
 {
+	struct client *client = cmd->client;
 	struct mailbox *mailbox = client->mailbox;
 
-	if (!client_verify_open_mailbox(client))
+	if (!client_verify_open_mailbox(cmd))
 		return TRUE;
 
 	client->mailbox = NULL;
@@ -17,6 +18,6 @@
 						   mailbox_get_storage(mailbox));
 	}
 
-	client_send_tagline(client, "OK Unselect completed.");
+	client_send_tagline(cmd, "OK Unselect completed.");
 	return TRUE;
 }

Index: cmd-unsubscribe.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-unsubscribe.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cmd-unsubscribe.c	5 Jan 2003 13:09:51 -0000	1.3
+++ cmd-unsubscribe.c	5 Feb 2005 18:07:26 -0000	1.4
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_unsubscribe(struct client *client)
+int cmd_unsubscribe(struct client_command_context *cmd)
 {
-	return _cmd_subscribe_full(client, FALSE);
+	return _cmd_subscribe_full(cmd, FALSE);
 }

Index: commands-util.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/commands-util.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- commands-util.c	29 Dec 2004 15:48:54 -0000	1.40
+++ commands-util.c	5 Feb 2005 18:07:26 -0000	1.41
@@ -17,19 +17,20 @@
 #define MAILBOX_MAX_NAME_LEN 512
 
 struct mail_storage *
-client_find_storage(struct client *client, const char **mailbox)
+client_find_storage(struct client_command_context *cmd, const char **mailbox)
 {
 	struct namespace *ns;
 
-	ns = namespace_find(client->namespaces, mailbox);
+	ns = namespace_find(cmd->client->namespaces, mailbox);
 	if (ns != NULL)
 		return ns->storage;
 
-	client_send_tagline(client, "NO Unknown namespace.");
+	client_send_tagline(cmd, "NO Unknown namespace.");
 	return NULL;
 }
 
-int client_verify_mailbox_name(struct client *client, const char *mailbox,
+int client_verify_mailbox_name(struct client_command_context *cmd,
+			       const char *mailbox,
 			       int should_exist, int should_not_exist)
 {
 	struct mail_storage *storage;
@@ -37,34 +38,34 @@
 	const char *p;
 	char sep;
 
-	storage = client_find_storage(client, &mailbox);
+	storage = client_find_storage(cmd, &mailbox);
 	if (storage == NULL)
 		return FALSE;
 
 	/* make sure it even looks valid */
 	sep = mail_storage_get_hierarchy_sep(storage);
 	if (*mailbox == '\0' || strspn(mailbox, "\r\n*%?") != 0) {
-		client_send_tagline(client, "NO Invalid mailbox name.");
+		client_send_tagline(cmd, "NO Invalid mailbox name.");
 		return FALSE;
 	}
 
 	/* make sure two hierarchy separators aren't next to each others */
 	for (p = mailbox+1; *p != '\0'; p++) {
 		if (p[0] == sep && p[1] == sep) {
-			client_send_tagline(client, "NO Invalid mailbox name.");
+			client_send_tagline(cmd, "NO Invalid mailbox name.");
 			return FALSE;
 		}
 	}
 
 	if (strlen(mailbox) > MAILBOX_MAX_NAME_LEN) {
-		client_send_tagline(client, "NO Mailbox name too long.");
+		client_send_tagline(cmd, "NO Mailbox name too long.");
 		return FALSE;
 	}
 
 	/* check what our storage thinks of it */
 	if (mail_storage_get_mailbox_name_status(storage, mailbox,
 						 &mailbox_status) < 0) {
-		client_send_storage_error(client, storage);
+		client_send_storage_error(cmd, storage);
 		return FALSE;
 	}
 
@@ -73,25 +74,25 @@
 		if (should_exist || !should_not_exist)
 			return TRUE;
 
-		client_send_tagline(client, "NO Mailbox exists.");
+		client_send_tagline(cmd, "NO Mailbox exists.");
 		break;
 
 	case MAILBOX_NAME_VALID:
 		if (!should_exist)
 			return TRUE;
 
-		client_send_tagline(client, t_strconcat(
+		client_send_tagline(cmd, t_strconcat(
 			"NO [TRYCREATE] Mailbox doesn't exist: ",
 			mailbox, NULL));
 		break;
 
 	case MAILBOX_NAME_INVALID:
-		client_send_tagline(client, t_strconcat(
+		client_send_tagline(cmd, t_strconcat(
 			"NO Invalid mailbox name: ", mailbox, NULL));
 		break;
 
 	case MAILBOX_NAME_NOINFERIORS:
-		client_send_tagline(client,
+		client_send_tagline(cmd,
 			"NO Mailbox parent doesn't allow inferior mailboxes.");
 		break;
 
@@ -102,33 +103,33 @@
 	return FALSE;
 }
 
-int client_verify_open_mailbox(struct client *client)
+int client_verify_open_mailbox(struct client_command_context *cmd)
 {
-	if (client->mailbox != NULL)
+	if (cmd->client->mailbox != NULL)
 		return TRUE;
 	else {
-		client_send_tagline(client, "BAD No mailbox selected.");
+		client_send_tagline(cmd, "BAD No mailbox selected.");
 		return FALSE;
 	}
 }
 
-void client_send_storage_error(struct client *client,
+void client_send_storage_error(struct client_command_context *cmd,
 			       struct mail_storage *storage)
 {
 	const char *error;
 	int syntax;
 
-	if (client->mailbox != NULL &&
-	    mailbox_is_inconsistent(client->mailbox)) {
+	if (cmd->client->mailbox != NULL &&
+	    mailbox_is_inconsistent(cmd->client->mailbox)) {
 		/* we can't do forced CLOSE, so have to disconnect */
-		client_disconnect_with_error(client,
+		client_disconnect_with_error(cmd->client,
 			"Mailbox is in inconsistent state, please relogin.");
 		return;
 	}
 
 	error = mail_storage_get_last_error(storage, &syntax);
-	client_send_tagline(client, t_strconcat(syntax ? "BAD " : "NO ",
-						error, NULL));
+	client_send_tagline(cmd,
+			    t_strconcat(syntax ? "BAD " : "NO ", error, NULL));
 }
 
 void client_send_untagged_storage_error(struct client *client,
@@ -150,19 +151,21 @@
 			 t_strconcat(syntax ? "* BAD " : "* NO ", error, NULL));
 }
 
-static int is_valid_keyword(struct client *client, const char *keyword)
+static int is_valid_keyword(struct client_command_context *cmd,
+			    const char *keyword)
 {
+	struct mailbox_keywords *keywords = &cmd->client->keywords;
 	size_t i;
 
 	/* if it already exists, skip validity checks */
-	for (i = 0; i < client->keywords.keywords_count; i++) {
-		if (client->keywords.keywords[i] != NULL &&
-		    strcasecmp(client->keywords.keywords[i], keyword) == 0)
+	for (i = 0; i < keywords->keywords_count; i++) {
+		if (keywords->keywords[i] != NULL &&
+		    strcasecmp(keywords->keywords[i], keyword) == 0)
 			return TRUE;
 	}
 
 	if (strlen(keyword) > max_keyword_length) {
-		client_send_tagline(client,
+		client_send_tagline(cmd,
 			t_strdup_printf("BAD Invalid keyword name '%s': "
 					"Maximum length is %u characters",
 					keyword, max_keyword_length));
@@ -172,8 +175,8 @@
 	return TRUE;
 }
 
-int client_parse_mail_flags(struct client *client, struct imap_arg *args,
-			    enum mail_flags *flags_r,
+int client_parse_mail_flags(struct client_command_context *cmd,
+			    struct imap_arg *args, enum mail_flags *flags_r,
 			    const char *const **keywords_r)
 {
 	const char *const *keywords;
@@ -183,11 +186,11 @@
 
 	*flags_r = 0;
 	*keywords_r = NULL;
-	buffer = buffer_create_dynamic(client->cmd_pool, 256);
+	buffer = buffer_create_dynamic(cmd->pool, 256);
 
 	while (args->type != IMAP_ARG_EOL) {
 		if (args->type != IMAP_ARG_ATOM) {
-			client_send_command_error(client,
+			client_send_command_error(cmd,
 				"Flags list contains non-atoms.");
 			return FALSE;
 		}
@@ -207,7 +210,7 @@
 			else if (strcmp(atom, "\\DRAFT") == 0)
 				*flags_r |= MAIL_DRAFT;
 			else {
-				client_send_tagline(client, t_strconcat(
+				client_send_tagline(cmd, t_strconcat(
 					"BAD Invalid system flag ",
 					atom, NULL));
 				return FALSE;
@@ -222,7 +225,7 @@
 			}
 
 			if (i == size) {
-				if (!is_valid_keyword(client, atom))
+				if (!is_valid_keyword(cmd, atom))
 					return FALSE;
 				buffer_append(buffer, &atom, sizeof(atom));
 			}

Index: commands-util.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/commands-util.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- commands-util.h	5 Feb 2005 14:45:48 -0000	1.20
+++ commands-util.h	5 Feb 2005 18:07:26 -0000	1.21
@@ -12,7 +12,7 @@
 /* Finds mail storage for given mailbox from namespaces. If not found,
    sends "Unknown namespace" error message to client. */
 struct mail_storage *
-client_find_storage(struct client *client, const char **mailbox);
+client_find_storage(struct client_command_context *cmd, const char **mailbox);
 
 /* If should_exist is TRUE, this function returns TRUE if the mailbox
    exists. If it doesn't exist but would be a valid mailbox name, the
@@ -20,15 +20,16 @@
 
    If should_exist is FALSE, the should_not_exist specifies if we should
    return TRUE or FALSE if mailbox doesn't exist. */
-int client_verify_mailbox_name(struct client *client, const char *mailbox,
+int client_verify_mailbox_name(struct client_command_context *cmd,
+			       const char *mailbox,
 			       int should_exist, int should_not_exist);
 
 /* Returns TRUE if mailbox is selected. If not, sends "No mailbox selected"
    error message to client. */
-int client_verify_open_mailbox(struct client *client);
+int client_verify_open_mailbox(struct client_command_context *cmd);
 
 /* Send last mail storage error message to client. */
-void client_send_storage_error(struct client *client,
+void client_send_storage_error(struct client_command_context *cmd,
 			       struct mail_storage *storage);
 
 /* Send untagged error message to client. */
@@ -37,8 +38,8 @@
 
 /* Parse flags. Returns TRUE if successful, if not sends an error message to
    client. */
-int client_parse_mail_flags(struct client *client, struct imap_arg *args,
-			    enum mail_flags *flags_r,
+int client_parse_mail_flags(struct client_command_context *cmd,
+			    struct imap_arg *args, enum mail_flags *flags_r,
 			    const char *const **keywords_r);
 
 /* Send FLAGS + PERMANENTFLAGS to client. */

Index: commands.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/commands.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- commands.h	5 Feb 2005 14:45:48 -0000	1.16
+++ commands.h	5 Feb 2005 18:07:26 -0000	1.17
@@ -1,14 +1,14 @@
 #ifndef __COMMANDS_H
 #define __COMMANDS_H
 
-struct client;
+struct client_command_context;
 
 #include "mail-storage.h"
 #include "imap-parser.h"
 #include "imap-sync.h"
 #include "commands-util.h"
 
-typedef int command_func_t(struct client *client);
+typedef int command_func_t(struct client_command_context *cmd);
 
 struct command {
 	const char *name;
@@ -32,51 +32,51 @@
 /* IMAP4rev1 commands: */
 
 /* Non-Authenticated State */
-int cmd_authenticate(struct client *client);
-int cmd_login(struct client *client);
-int cmd_logout(struct client *client);
+int cmd_authenticate(struct client_command_context *cmd);
+int cmd_login(struct client_command_context *cmd);
+int cmd_logout(struct client_command_context *cmd);
 
-int cmd_capability(struct client *client);
-int cmd_noop(struct client *client);
+int cmd_capability(struct client_command_context *cmd);
+int cmd_noop(struct client_command_context *cmd);
 
 /* Authenticated State */
-int cmd_select(struct client *client);
-int cmd_examine(struct client *client);
+int cmd_select(struct client_command_context *cmd);
+int cmd_examine(struct client_command_context *cmd);
 
-int cmd_create(struct client *client);
-int cmd_delete(struct client *client);
-int cmd_rename(struct client *client);
+int cmd_create(struct client_command_context *cmd);
+int cmd_delete(struct client_command_context *cmd);
+int cmd_rename(struct client_command_context *cmd);
 
-int cmd_subscribe(struct client *client);
-int cmd_unsubscribe(struct client *client);
+int cmd_subscribe(struct client_command_context *cmd);
+int cmd_unsubscribe(struct client_command_context *cmd);
 
-int cmd_list(struct client *client);
-int cmd_lsub(struct client *client);
+int cmd_list(struct client_command_context *cmd);
+int cmd_lsub(struct client_command_context *cmd);
 
-int cmd_status(struct client *client);
-int cmd_append(struct client *client);
+int cmd_status(struct client_command_context *cmd);
+int cmd_append(struct client_command_context *cmd);
 
 /* Selected state */
-int cmd_check(struct client *client);
-int cmd_close(struct client *client);
-int cmd_expunge(struct client *client);
-int cmd_search(struct client *client);
-int cmd_fetch(struct client *client);
-int cmd_store(struct client *client);
-int cmd_copy(struct client *client);
-int cmd_uid(struct client *client);
+int cmd_check(struct client_command_context *cmd);
+int cmd_close(struct client_command_context *cmd);
+int cmd_expunge(struct client_command_context *cmd);
+int cmd_search(struct client_command_context *cmd);
+int cmd_fetch(struct client_command_context *cmd);
+int cmd_store(struct client_command_context *cmd);
+int cmd_copy(struct client_command_context *cmd);
+int cmd_uid(struct client_command_context *cmd);
 
 /* IMAP extensions: */
-int cmd_idle(struct client *client);
-int cmd_namespace(struct client *client);
-int cmd_sort(struct client *client);
-int cmd_thread(struct client *client);
-int cmd_uid_expunge(struct client *client);
-int cmd_unselect(struct client *client);
+int cmd_idle(struct client_command_context *cmd);
+int cmd_namespace(struct client_command_context *cmd);
+int cmd_sort(struct client_command_context *cmd);
+int cmd_thread(struct client_command_context *cmd);
+int cmd_uid_expunge(struct client_command_context *cmd);
+int cmd_unselect(struct client_command_context *cmd);
 
 /* private: */
-int _cmd_list_full(struct client *client, int lsub);
-int _cmd_select_full(struct client *client, int readonly);
-int _cmd_subscribe_full(struct client *client, int subscribe);
+int _cmd_list_full(struct client_command_context *cmd, int lsub);
+int _cmd_select_full(struct client_command_context *cmd, int readonly);
+int _cmd_subscribe_full(struct client_command_context *cmd, int subscribe);
 
 #endif

Index: imap-fetch-body.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/imap-fetch-body.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- imap-fetch-body.c	19 Dec 2004 00:46:10 -0000	1.16
+++ imap-fetch-body.c	5 Feb 2005 18:07:26 -0000	1.17
@@ -594,7 +594,7 @@
 	t_push();
 
 	for (arr = body->fields; *arr != NULL; arr++) {
-		char *hdr = p_strdup(ctx->client->cmd_pool, *arr);
+		char *hdr = p_strdup(ctx->cmd->pool, *arr);
 		buffer_append(ctx->all_headers_buf, &hdr, sizeof(hdr));
 	}
 
@@ -660,7 +660,7 @@
 		}
 	}
 
-	client_send_command_error(ctx->client,
+	client_send_command_error(ctx->cmd,
 		"Invalid BODY[..] parameter: Unknown or broken section");
 	return FALSE;
 }
@@ -694,17 +694,17 @@
 	const char **arr;
 	size_t i;
 
-	str = str_new(ctx->client->cmd_pool, 128);
+	str = str_new(ctx->cmd->pool, 128);
 	str_append(str, prefix);
 	str_append(str, " (");
 
 	/* @UNSAFE: NULL-terminated list of headers */
-	arr = p_new(ctx->client->cmd_pool, const char *, list->size + 1);
+	arr = p_new(ctx->cmd->pool, const char *, list->size + 1);
 
 	for (i = 0; i < list->size; i++) {
 		if (list->args[i].type != IMAP_ARG_ATOM &&
 		    list->args[i].type != IMAP_ARG_STRING) {
-			client_send_command_error(ctx->client,
+			client_send_command_error(ctx->cmd,
 				"Invalid BODY[..] parameter: "
 				"Header list contains non-strings");
 			return FALSE;
@@ -738,7 +738,7 @@
 	const char *partial;
 	const char *p = name + 4;
 
-	body = p_new(ctx->client->cmd_pool, struct imap_fetch_body_data, 1);
+	body = p_new(ctx->cmd->pool, struct imap_fetch_body_data, 1);
 	body->max_size = (uoff_t)-1;
 
 	if (strncmp(p, ".PEEK", 5) == 0) {
@@ -749,7 +749,7 @@
 	}
 
 	if (*p != '[') {
-		client_send_command_error(ctx->client,
+		client_send_command_error(ctx->cmd,
 			"Invalid BODY[..] parameter: Missing '['");
 		return FALSE;
 	}
@@ -758,7 +758,7 @@
 		/* BODY[HEADER.FIELDS.. (headers list)] */
 		if ((*args)[1].type != IMAP_ARG_ATOM ||
 		    IMAP_ARG_STR(&(*args)[1])[0] != ']') {
-			client_send_command_error(ctx->client,
+			client_send_command_error(ctx->cmd,
 				"Invalid BODY[..] parameter: Missing ']'");
 			return FALSE;
 		}
@@ -772,11 +772,11 @@
 		body->section = p+1;
 		p = strchr(body->section, ']');
 		if (p == NULL) {
-			client_send_command_error(ctx->client,
+			client_send_command_error(ctx->cmd,
 				"Invalid BODY[..] parameter: Missing ']'");
 			return FALSE;
 		}
-		body->section = p_strdup_until(ctx->client->cmd_pool,
+		body->section = p_strdup_until(ctx->cmd->pool,
 					       body->section, p);
 	}
 
@@ -788,7 +788,7 @@
 
 		if (!read_uoff_t(&p, &body->skip) || body->skip > OFF_T_MAX) {
 			/* wrapped */
-			client_send_command_error(ctx->client,
+			client_send_command_error(ctx->cmd,
 				"Invalid BODY[..] parameter: "
 				"Too big partial start");
 			return FALSE;
@@ -807,7 +807,7 @@
 			if (!read_uoff_t(&p, &body->max_size) ||
 			    body->max_size > OFF_T_MAX) {
 				/* wrapped */
-				client_send_command_error(ctx->client,
+				client_send_command_error(ctx->cmd,
 					"Invalid BODY[..] parameter: "
 					"Too big partial end");
 				return FALSE;
@@ -815,7 +815,7 @@
 		}
 
 		if (*p != '>') {
-			client_send_command_error(ctx->client,
+			client_send_command_error(ctx->cmd,
 				t_strdup_printf("Invalid BODY[..] parameter: "
 						"Missing '>' in '%s'",
 						partial));
@@ -947,7 +947,7 @@
 		return TRUE;
 	}
 
-	client_send_command_error(ctx->client, t_strconcat(
+	client_send_command_error(ctx->cmd, t_strconcat(
 		"Unknown parameter ", name, NULL));
 	return FALSE;
 }

Index: imap-fetch.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/imap-fetch.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- imap-fetch.c	17 Jan 2005 13:18:56 -0000	1.35
+++ imap-fetch.c	5 Feb 2005 18:07:26 -0000	1.36
@@ -67,7 +67,7 @@
                           sizeof(struct imap_fetch_handler),
 			  imap_fetch_handler_bsearch);
 	if (handler == NULL) {
-		client_send_command_error(ctx->client,
+		client_send_command_error(ctx->cmd,
 			t_strconcat("Unknown command ", name, NULL));
 		return FALSE;
 	}
@@ -75,8 +75,9 @@
 	return handler->init(ctx, name, args);
 }
 
-struct imap_fetch_context *imap_fetch_init(struct client *client)
+struct imap_fetch_context *imap_fetch_init(struct client_command_context *cmd)
 {
+	struct client *client = cmd->client;
 	struct imap_fetch_context *ctx;
 
 	if (fetch_handlers == NULL) {
@@ -85,13 +86,14 @@
 					     sizeof(default_handlers[0]));
 	}
 
-	ctx = p_new(client->cmd_pool, struct imap_fetch_context, 1);
+	ctx = p_new(cmd->pool, struct imap_fetch_context, 1);
 	ctx->client = client;
+	ctx->cmd = cmd;
 	ctx->box = client->mailbox;
 
 	ctx->cur_str = str_new(default_pool, 8192);
-	ctx->all_headers_buf = buffer_create_dynamic(client->cmd_pool, 128);
-	ctx->handlers = buffer_create_dynamic(client->cmd_pool, 128);
+	ctx->all_headers_buf = buffer_create_dynamic(cmd->pool, 128);
+	ctx->handlers = buffer_create_dynamic(cmd->pool, 128);
 	ctx->line_finished = TRUE;
 	return ctx;
 }

Index: imap-fetch.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/imap-fetch.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- imap-fetch.h	26 Dec 2004 09:12:40 -0000	1.12
+++ imap-fetch.h	5 Feb 2005 18:07:26 -0000	1.13
@@ -23,6 +23,7 @@
 
 struct imap_fetch_context {
 	struct client *client;
+	struct client_command_context *cmd;
 	struct mailbox *box;
 
 	struct mailbox_transaction_context *trans;
@@ -61,7 +62,7 @@
 void imap_fetch_add_handler(struct imap_fetch_context *ctx,
 			    imap_fetch_handler_t *handler, void *context);
 
-struct imap_fetch_context *imap_fetch_init(struct client *client);
+struct imap_fetch_context *imap_fetch_init(struct client_command_context *cmd);
 int imap_fetch_deinit(struct imap_fetch_context *ctx);
 int imap_fetch_init_handler(struct imap_fetch_context *ctx, const char *name,
 			    struct imap_arg **args);

Index: imap-search.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/imap-search.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- imap-search.c	20 Dec 2004 04:56:21 -0000	1.9
+++ imap-search.c	5 Feb 2005 18:07:26 -0000	1.10
@@ -444,22 +444,23 @@
 }
 
 struct mail_search_arg *
-imap_search_get_arg(struct client *client, const char *set, int uid)
+imap_search_get_arg(struct client_command_context *cmd,
+		    const char *set, int uid)
 {
 	struct mail_search_arg *search_arg;
 	const char *error;
 	int ret;
 
 	if (!uid) {
-		ret = imap_search_get_msgset_arg(client->cmd_pool, set,
+		ret = imap_search_get_msgset_arg(cmd->pool, set,
 						 &search_arg, &error);
 	} else {
-		ret = imap_search_get_uidset_arg(client->cmd_pool,
-						 client->mailbox, set,
+		ret = imap_search_get_uidset_arg(cmd->pool,
+						 cmd->client->mailbox, set,
 						 &search_arg, &error);
 	}
 	if (ret < 0) {
-		client_send_command_error(client, error);
+		client_send_command_error(cmd, error);
 		return NULL;
 	}
 

Index: imap-search.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/imap-search.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- imap-search.h	15 Aug 2004 03:40:30 -0000	1.5
+++ imap-search.h	5 Feb 2005 18:07:26 -0000	1.6
@@ -3,7 +3,7 @@
 
 struct imap_arg;
 struct mailbox;
-struct client;
+struct client_command_context;
 
 /* Builds search arguments based on IMAP arguments. */
 struct mail_search_arg *
@@ -11,6 +11,7 @@
 		       const char **error_r);
 
 struct mail_search_arg *
-imap_search_get_arg(struct client *client, const char *set, int uid);
+imap_search_get_arg(struct client_command_context *cmd,
+		    const char *set, int uid);
 
 #endif

Index: imap-sort.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/imap-sort.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- imap-sort.c	6 Jan 2005 18:14:28 -0000	1.18
+++ imap-sort.c	5 Feb 2005 18:07:26 -0000	1.19
@@ -187,10 +187,11 @@
 	i_free(ctx->last_to);
 }
 
-int imap_sort(struct client *client, const char *charset,
+int imap_sort(struct client_command_context *cmd, const char *charset,
 	      struct mail_search_arg *args,
 	      const enum mail_sort_type *sort_program)
 {
+	struct client *client = cmd->client;
 	enum mail_sort_type norm_prog[MAX_SORT_PROGRAM_SIZE];
         enum mail_fetch_field wanted_fields;
 	const char *wanted_headers[MAX_WANTED_HEADERS];
@@ -245,7 +246,7 @@
 	ctx->str = t_str_new(STRBUF_SIZE);
 	str_append(ctx->str, "* SORT");
 
-        ctx->id_is_uid = client->cmd_uid;
+        ctx->id_is_uid = cmd->uid;
 
 	while ((mail = mailbox_search_next(ctx->search_ctx)) != NULL)
 		mail_sort_input(ctx, mail);

Index: imap-sort.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/imap-sort.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- imap-sort.h	27 Jan 2003 02:05:32 -0000	1.2
+++ imap-sort.h	5 Feb 2005 18:07:26 -0000	1.3
@@ -1,7 +1,7 @@
 #ifndef __IMAP_SORT_H
 #define __IMAP_SORT_H
 
-int imap_sort(struct client *client, const char *charset,
+int imap_sort(struct client_command_context *cmd, const char *charset,
 	      struct mail_search_arg *args,
 	      const enum mail_sort_type *sort_program);
 

Index: imap-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/imap-sync.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- imap-sync.c	17 Jan 2005 13:02:35 -0000	1.7
+++ imap-sync.c	5 Feb 2005 18:07:26 -0000	1.8
@@ -164,38 +164,39 @@
 	return mailbox_sync_deinit(ctx, &status);
 }
 
-static int cmd_sync_continue(struct client *client)
+static int cmd_sync_continue(struct client_command_context *cmd)
 {
-	struct cmd_sync_context *ctx = client->cmd_context;
+	struct cmd_sync_context *ctx = cmd->context;
 
 	if (imap_sync_more(ctx->sync_ctx) == 0)
 		return FALSE;
 
 	if (imap_sync_deinit(ctx->sync_ctx) < 0) {
-		client_send_untagged_storage_error(client,
-			mailbox_get_storage(client->mailbox));
+		client_send_untagged_storage_error(cmd->client,
+			mailbox_get_storage(cmd->client->mailbox));
 	}
 
-	client_send_tagline(client, ctx->tagline);
+	client_send_tagline(cmd, ctx->tagline);
 	return TRUE;
 }
 
-int cmd_sync(struct client *client, enum mailbox_sync_flags flags,
+int cmd_sync(struct client_command_context *cmd, enum mailbox_sync_flags flags,
 	     const char *tagline)
 {
         struct cmd_sync_context *ctx;
 
-	if (client->mailbox == NULL) {
-		client_send_tagline(client, tagline);
+	if (cmd->client->mailbox == NULL) {
+		client_send_tagline(cmd, tagline);
 		return TRUE;
 	}
 
-	ctx = p_new(client->cmd_pool, struct cmd_sync_context, 1);
-	ctx->tagline = p_strdup(client->cmd_pool, tagline);
-	ctx->sync_ctx = imap_sync_init(client, client->mailbox, flags);
+	ctx = p_new(cmd->pool, struct cmd_sync_context, 1);
+	ctx->tagline = p_strdup(cmd->pool, tagline);
+	ctx->sync_ctx = imap_sync_init(cmd->client, cmd->client->mailbox,
+				       flags);
 
-	client->cmd_func = cmd_sync_continue;
-	client->cmd_context = ctx;
-	client->command_pending = TRUE;
-	return cmd_sync_continue(client);
+	cmd->func = cmd_sync_continue;
+	cmd->context = ctx;
+	cmd->client->command_pending = TRUE;
+	return cmd_sync_continue(cmd);
 }

Index: imap-sync.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/imap-sync.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- imap-sync.h	18 Aug 2004 23:53:39 -0000	1.2
+++ imap-sync.h	5 Feb 2005 18:07:26 -0000	1.3
@@ -1,6 +1,8 @@
 #ifndef __IMAP_SYNC_H
 #define __IMAP_SYNC_H
 
+struct client;
+
 struct imap_sync_context *
 imap_sync_init(struct client *client, struct mailbox *box,
 	       enum mailbox_sync_flags flags);
@@ -9,7 +11,7 @@
 
 int imap_sync_nonselected(struct mailbox *box, enum mailbox_sync_flags flags);
 
-int cmd_sync(struct client *client, enum mailbox_sync_flags flags,
+int cmd_sync(struct client_command_context *cmd, enum mailbox_sync_flags flags,
 	     const char *tagline);
 
 #endif

Index: imap-thread.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/imap-thread.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- imap-thread.c	29 Aug 2004 07:52:02 -0000	1.13
+++ imap-thread.c	5 Feb 2005 18:07:26 -0000	1.14
@@ -100,13 +100,14 @@
 	pool_unref(ctx->pool);
 }
 
-int imap_thread(struct client *client, const char *charset,
+int imap_thread(struct client_command_context *cmd, const char *charset,
 		struct mail_search_arg *args, enum mail_thread_type type)
 {
 	static const char *wanted_headers[] = {
 		"message-id", "in-reply-to", "references", "subject",
 		NULL
 	};
+	struct client *client = cmd->client;
 	struct mailbox_header_lookup_ctx *headers_ctx;
 	struct thread_context *ctx;
 	struct mail *mail;
@@ -142,7 +143,7 @@
 				      APPROX_MSG_COUNT*2, str_hash,
 				      (hash_cmp_callback_t *)strcmp);
 
-	ctx->id_is_uid = client->cmd_uid;
+	ctx->id_is_uid = cmd->uid;
 	while ((mail = mailbox_search_next(ctx->search_ctx)) != NULL)
 		mail_thread_input(ctx, mail);
 

Index: imap-thread.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/imap-thread.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- imap-thread.h	20 Jun 2004 21:27:20 -0000	1.2
+++ imap-thread.h	5 Feb 2005 18:07:26 -0000	1.3
@@ -7,7 +7,7 @@
 	MAIL_THREAD_REFERENCES
 };
 
-int imap_thread(struct client *client, const char *charset,
+int imap_thread(struct client_command_context *cmd, const char *charset,
 		struct mail_search_arg *args, enum mail_thread_type type);
 
 #endif



More information about the dovecot-cvs mailing list