changeset 12709:4741f1b4f9b3

IDLE: Don't assert-crash if IDLE+DONE is sent in same TCP packet.
author Timo Sirainen <tss@iki.fi>
date Fri, 21 Jan 2011 21:46:24 +0200
parents 108754651836
children 42ca32299617
files src/imap/cmd-idle.c
diffstat 1 files changed, 21 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/cmd-idle.c	Fri Jan 21 19:16:34 2011 +0200
+++ b/src/imap/cmd-idle.c	Fri Jan 21 21:46:24 2011 +0200
@@ -55,10 +55,26 @@
 		client_command_free(&ctx->cmd);
 }
 
+static bool
+idle_client_handle_input(struct cmd_idle_context *ctx, bool free_cmd)
+{
+	const char *line;
+
+	while ((line = i_stream_next_line(ctx->client->input)) != NULL) {
+		if (ctx->client->input_skip_line)
+			ctx->client->input_skip_line = FALSE;
+		else {
+			idle_finish(ctx, strcasecmp(line, "DONE") == 0,
+				    free_cmd);
+			return TRUE;
+		}
+	}
+	return FALSE;
+}
+
 static void idle_client_input_more(struct cmd_idle_context *ctx)
 {
 	struct client *client = ctx->client;
-	char *line;
 
 	client->last_input = ioloop_time;
 	timeout_reset(client->to_idle);
@@ -82,15 +98,9 @@
 		return;
 	}
 
-	while ((line = i_stream_next_line(client->input)) != NULL) {
-		if (client->input_skip_line)
-			client->input_skip_line = FALSE;
-		else {
-			idle_finish(ctx, strcasecmp(line, "DONE") == 0, TRUE);
-			if (!client->disconnected)
-				client_continue_pending_input(client);
-			break;
-		}
+	if (idle_client_handle_input(ctx, TRUE)) {
+		if (!client->disconnected)
+			client_continue_pending_input(client);
 	}
 }
 
@@ -264,6 +274,5 @@
 	   added mailbox-notifier, we wouldn't see them otherwise. */
 	if (client->mailbox != NULL)
 		idle_sync_now(client->mailbox, ctx);
-	idle_client_input_more(ctx);
-	return FALSE;
+	return idle_client_handle_input(ctx, FALSE);
 }