comparison src/imap/client.c @ 9075:d77225a64128 HEAD

IMAP: Make sure pending syncs are done before a mailbox-changing command is run.
author Timo Sirainen <tss@iki.fi>
date Sun, 24 May 2009 18:09:12 -0400
parents 421393827a81
children 73b468723964
comparison
equal deleted inserted replaced
9074:995d501d8f41 9075:d77225a64128
368 return i == count; 368 return i == count;
369 } 369 }
370 370
371 static struct client_command_context * 371 static struct client_command_context *
372 client_command_find_with_flags(struct client_command_context *new_cmd, 372 client_command_find_with_flags(struct client_command_context *new_cmd,
373 enum command_flags flags) 373 enum command_flags flags,
374 enum client_command_state max_state)
374 { 375 {
375 struct client_command_context *cmd; 376 struct client_command_context *cmd;
376 377
377 cmd = new_cmd->client->command_queue; 378 cmd = new_cmd->client->command_queue;
378 for (; cmd != NULL; cmd = cmd->next) { 379 for (; cmd != NULL; cmd = cmd->next) {
379 if (cmd->state < CLIENT_COMMAND_STATE_WAIT_SYNC && 380 if (cmd->state <= max_state &&
380 cmd != new_cmd && (cmd->cmd_flags & flags) != 0) 381 cmd != new_cmd && (cmd->cmd_flags & flags) != 0)
381 return cmd; 382 return cmd;
382 } 383 }
383 return NULL; 384 return NULL;
384 } 385 }
385 386
386 static bool client_command_check_ambiguity(struct client_command_context *cmd) 387 static bool client_command_check_ambiguity(struct client_command_context *cmd)
387 { 388 {
388 enum command_flags flags; 389 enum command_flags flags;
390 enum client_command_state max_state =
391 CLIENT_COMMAND_STATE_WAIT_UNAMBIGUITY;
389 bool broken_client = FALSE; 392 bool broken_client = FALSE;
390 393
391 if ((cmd->cmd_flags & COMMAND_FLAG_BREAKS_MAILBOX) == 394 if ((cmd->cmd_flags & COMMAND_FLAG_BREAKS_MAILBOX) ==
392 COMMAND_FLAG_BREAKS_MAILBOX) { 395 COMMAND_FLAG_BREAKS_MAILBOX) {
393 /* there must be no other command running that uses the 396 /* there must be no other command running that uses the
394 selected mailbox */ 397 selected mailbox */
395 flags = COMMAND_FLAG_USES_MAILBOX; 398 flags = COMMAND_FLAG_USES_MAILBOX;
399 max_state = CLIENT_COMMAND_STATE_DONE;
396 } else if ((cmd->cmd_flags & COMMAND_FLAG_USES_SEQS) != 0) { 400 } else if ((cmd->cmd_flags & COMMAND_FLAG_USES_SEQS) != 0) {
397 /* no existing command must be breaking sequences */ 401 /* no existing command must be breaking sequences */
398 flags = COMMAND_FLAG_BREAKS_SEQS; 402 flags = COMMAND_FLAG_BREAKS_SEQS;
399 broken_client = TRUE; 403 broken_client = TRUE;
400 } else if ((cmd->cmd_flags & COMMAND_FLAG_BREAKS_SEQS) != 0) { 404 } else if ((cmd->cmd_flags & COMMAND_FLAG_BREAKS_SEQS) != 0) {
402 flags = COMMAND_FLAG_USES_SEQS; 406 flags = COMMAND_FLAG_USES_SEQS;
403 } else { 407 } else {
404 return FALSE; 408 return FALSE;
405 } 409 }
406 410
407 if (client_command_find_with_flags(cmd, flags) == NULL) { 411 if (client_command_find_with_flags(cmd, flags, max_state) == NULL) {
408 if (cmd->client->syncing) { 412 if (cmd->client->syncing) {
409 /* don't do anything until syncing is finished */ 413 /* don't do anything until syncing is finished */
410 return TRUE; 414 return TRUE;
411 } 415 }
412 if (cmd->client->mailbox_change_lock != NULL && 416 if (cmd->client->mailbox_change_lock != NULL &&