From d47cca7dd9a69dfaa8ca14cde393b8dc83f5a60b Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sat, 23 Aug 2008 07:55:15 +0000 Subject: [PATCH] backport: deal with UIDVALIDITY of 0 properly. CCMAIL: skinner@destiny-denied.co.uk -REF: 20080822094543.GA3528@ugly.local --- src/drv_imap.c | 9 ++++++--- src/sync.c | 11 ++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/drv_imap.c b/src/drv_imap.c index ae85524..9520cdd 100644 --- a/src/drv_imap.c +++ b/src/drv_imap.c @@ -817,7 +817,7 @@ static int parse_response_code( imap_store_t *ctx, struct imap_cmd_cb *cb, char *s ) { imap_t *imap = ctx->imap; - char *arg, *p; + char *arg, *earg, *p; if (*s != '[') return RESP_OK; /* no response code */ @@ -829,7 +829,9 @@ parse_response_code( imap_store_t *ctx, struct imap_cmd_cb *cb, char *s ) *p++ = 0; arg = next_arg( &s ); if (!strcmp( "UIDVALIDITY", arg )) { - if (!(arg = next_arg( &s )) || !(ctx->gen.uidvalidity = atoi( arg ))) { + if (!(arg = next_arg( &s )) || + (ctx->gen.uidvalidity = strtoll( arg, &earg, 10 ), *earg)) + { fprintf( stderr, "IMAP error: malformed UIDVALIDITY status\n" ); return RESP_BAD; } @@ -847,7 +849,8 @@ parse_response_code( imap_store_t *ctx, struct imap_cmd_cb *cb, char *s ) for (; isspace( (unsigned char)*p ); p++); fprintf( stderr, "*** IMAP ALERT *** %s\n", p ); } else if (cb && cb->ctx && !strcmp( "APPENDUID", arg )) { - if (!(arg = next_arg( &s )) || !(ctx->gen.uidvalidity = atoi( arg )) || + if (!(arg = next_arg( &s )) || + (ctx->gen.uidvalidity = strtoll( arg, &earg, 10 ), *earg) || !(arg = next_arg( &s )) || !(*(int *)cb->ctx = atoi( arg ))) { fprintf( stderr, "IMAP error: malformed APPENDUID status\n" ); diff --git a/src/sync.c b/src/sync.c index b9bfdb3..59035b6 100644 --- a/src/sync.c +++ b/src/sync.c @@ -474,7 +474,7 @@ sync_boxes( store_t *mctx, const char *mname, nmmsg = nsmsg = 0; - mctx->uidvalidity = sctx->uidvalidity = 0; + mctx->uidvalidity = sctx->uidvalidity = -1; mopts = sopts = 0; makeopts( chan->sops, chan->slave, &sopts, chan->master, &mopts ); makeopts( chan->mops, chan->master, &mopts, chan->slave, &sopts ); @@ -510,7 +510,8 @@ sync_boxes( store_t *mctx, const char *mname, nfasprintf( &jname, "%s.journal", dname ); nfasprintf( &nname, "%s.new", dname ); nfasprintf( &lname, "%s.lock", dname ); - muidval = suidval = smaxxuid = mmaxuid = smaxuid = 0; + muidval = suidval = -1; + smaxxuid = mmaxuid = smaxuid = 0; memset( &lck, 0, sizeof(lck) ); #if SEEK_SET != 0 lck.l_whence = SEEK_SET; @@ -705,7 +706,7 @@ sync_boxes( store_t *mctx, const char *mname, info( "%d messages, %d recent\n", sctx->count, sctx->recent ); dump_box( sctx ); - if (suidval && suidval != sctx->uidvalidity) { + if (suidval >= 0 && suidval != sctx->uidvalidity) { fprintf( stderr, "Error: UIDVALIDITY of slave changed\n" ); ret = SYNC_FAIL; goto bail; @@ -809,13 +810,13 @@ sync_boxes( store_t *mctx, const char *mname, info( "%d messages, %d recent\n", mctx->count, mctx->recent ); dump_box( mctx ); - if (muidval && muidval != mctx->uidvalidity) { + if (muidval >= 0 && muidval != mctx->uidvalidity) { fprintf( stderr, "Error: UIDVALIDITY of master changed\n" ); ret = SYNC_FAIL; goto finish; } - if (!muidval || !suidval) { + if (muidval < 0 || suidval < 0) { muidval = mctx->uidvalidity; suidval = sctx->uidvalidity; Fprintf( jfp, "| %d %d\n", muidval, suidval );