From: Timo Sirainen Date: Tue, 26 May 2009 18:20:23 +0000 (-0400) Subject: imap: Don't cancel sync if client disconnects in the middle. X-Git-Tag: 2.0.alpha1~668 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0b7651dc6ad21cce8579b5957252ae0daf972668;p=thirdparty%2Fdovecot%2Fcore.git imap: Don't cancel sync if client disconnects in the middle. Fixes "Message count decreased" errors. --HG-- branch : HEAD --- diff --git a/src/imap/imap-sync.c b/src/imap/imap-sync.c index f6429a28fe..c9bc02843e 100644 --- a/src/imap/imap-sync.c +++ b/src/imap/imap-sync.c @@ -372,6 +372,10 @@ int imap_sync_more(struct imap_sync_context *ctx) string_t *str; int ret = 1; + /* finish syncing even when client has disconnected. otherwise our + internal state (ctx->messages_count) can get messed up and unless + we immediately stop handling all commands and syncs we could end up + assert-crashing. */ str = t_str_new(256); for (;;) { if (ctx->seq == 0) { @@ -404,7 +408,7 @@ int imap_sync_more(struct imap_sync_context *ctx) ret = 1; for (; ctx->seq <= ctx->sync_rec.seq2; ctx->seq++) { - if (ret <= 0) + if (ret == 0) break; ret = imap_sync_send_flags(ctx, str); @@ -426,7 +430,7 @@ int imap_sync_more(struct imap_sync_context *ctx) ctx->seq = ctx->sync_rec.seq2; ret = 1; for (; ctx->seq >= ctx->sync_rec.seq1; ctx->seq--) { - if (ret <= 0) + if (ret == 0) break; str_truncate(str, 0); @@ -452,15 +456,15 @@ int imap_sync_more(struct imap_sync_context *ctx) ret = 1; for (; ctx->seq <= ctx->sync_rec.seq2; ctx->seq++) { - if (ret <= 0) + if (ret == 0) break; ret = imap_sync_send_modseq(ctx, str); } break; } - if (ret <= 0) { - /* failure / buffer full */ + if (ret == 0) { + /* buffer full */ break; }