[dovecot-cvs] dovecot/src/imap cmd-idle.c,1.22,1.23

cras at dovecot.org cras at dovecot.org
Fri Dec 30 21:49:40 EET 2005


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

Modified Files:
	cmd-idle.c 
Log Message:
Don't crash if client disconnected in IDLE. If mailbox had been changed before IDLE
was started, show the changes immediately. If more changes happened to
mailbox while we were sending older changes to client, we crashed.



Index: cmd-idle.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-idle.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- cmd-idle.c	25 Dec 2005 11:24:45 -0000	1.22
+++ cmd-idle.c	30 Dec 2005 19:49:38 -0000	1.23
@@ -78,6 +78,7 @@
 	switch (i_stream_read(client->input)) {
 	case -1:
 		/* disconnected */
+		idle_finish(ctx, FALSE);
 		client_destroy(client);
 		return;
 	case -2:
@@ -134,17 +135,23 @@
 	idle_send_expunge(ctx);
 }
 
+static void idle_sync_now(struct mailbox *box, struct cmd_idle_context *ctx)
+{
+	i_assert(ctx->sync_ctx == NULL);
+
+	ctx->sync_pending = FALSE;
+	ctx->sync_ctx = imap_sync_init(ctx->client, box, 0, 0);
+	cmd_idle_continue(ctx->cmd);
+}
+
 static void idle_callback(struct mailbox *box, void *context)
 {
         struct cmd_idle_context *ctx = context;
 
 	if (ctx->sync_ctx != NULL)
 		ctx->sync_pending = TRUE;
-	else {
-		ctx->sync_pending = FALSE;
-		ctx->sync_ctx = imap_sync_init(ctx->client, box, 0, 0);
-		cmd_idle_continue(ctx->cmd);
-	}
+	else
+                idle_sync_now(box, ctx);
 }
 
 static int cmd_idle_continue(struct client_command_context *cmd)
@@ -177,7 +184,7 @@
 	} else if (ctx->sync_pending) {
 		/* more changes occurred while we were sending changes to
 		   client */
-                idle_callback(client->mailbox, client);
+                idle_sync_now(client->mailbox, ctx);
 	}
         client->output_pending = FALSE;
 
@@ -225,5 +232,9 @@
 	client->command_pending = TRUE;
 	cmd->func = cmd_idle_continue;
 	cmd->context = ctx;
+
+	/* check immediately if there are changes. if they came before we
+	   added mailbox-notifier, we wouldn't see them otherwise. */
+	idle_sync_now(client->mailbox, ctx);
 	return FALSE;
 }



More information about the dovecot-cvs mailing list