deal with UIDVALIDITY of 0 properly.

-REF: 20080822094543.GA3528@ugly.local
This commit is contained in:
Oswald Buddenhagen 2008-08-23 07:54:00 +00:00
parent 0d8bce1675
commit 92914b37cc
2 changed files with 10 additions and 6 deletions

View File

@ -882,7 +882,7 @@ parse_capability( imap_store_t *ctx, char *cmd )
static int static int
parse_response_code( imap_store_t *ctx, struct imap_cmd_cb *cb, char *s ) parse_response_code( imap_store_t *ctx, struct imap_cmd_cb *cb, char *s )
{ {
char *arg, *p; char *arg, *earg, *p;
if (*s != '[') if (*s != '[')
return RESP_OK; /* no response code */ return RESP_OK; /* no response code */
@ -894,7 +894,9 @@ parse_response_code( imap_store_t *ctx, struct imap_cmd_cb *cb, char *s )
*p++ = 0; *p++ = 0;
arg = next_arg( &s ); arg = next_arg( &s );
if (!strcmp( "UIDVALIDITY", arg )) { 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))
{
error( "IMAP error: malformed UIDVALIDITY status\n" ); error( "IMAP error: malformed UIDVALIDITY status\n" );
return RESP_BAD; return RESP_BAD;
} }
@ -912,7 +914,8 @@ parse_response_code( imap_store_t *ctx, struct imap_cmd_cb *cb, char *s )
for (; isspace( (unsigned char)*p ); p++); for (; isspace( (unsigned char)*p ); p++);
error( "*** IMAP ALERT *** %s\n", p ); error( "*** IMAP ALERT *** %s\n", p );
} else if (cb && cb->ctx && !strcmp( "APPENDUID", arg )) { } 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 ))) !(arg = next_arg( &s )) || !(*(int *)cb->ctx = atoi( arg )))
{ {
error( "IMAP error: malformed APPENDUID status\n" ); error( "IMAP error: malformed APPENDUID status\n" );

View File

@ -470,13 +470,14 @@ sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan,
svars->ctx[0] = ctx[0]; svars->ctx[0] = ctx[0];
svars->ctx[1] = ctx[1]; svars->ctx[1] = ctx[1];
svars->chan = chan; svars->chan = chan;
svars->uidval[0] = svars->uidval[1] = -1;
svars->srecadd = &svars->srecs; svars->srecadd = &svars->srecs;
for (t = 0; t < 2; t++) { for (t = 0; t < 2; t++) {
ctx[t]->name = ctx[t]->name =
(!names[t] || (ctx[t]->conf->map_inbox && !strcmp( ctx[t]->conf->map_inbox, names[t] ))) ? (!names[t] || (ctx[t]->conf->map_inbox && !strcmp( ctx[t]->conf->map_inbox, names[t] ))) ?
"INBOX" : names[t]; "INBOX" : names[t];
ctx[t]->uidvalidity = 0; ctx[t]->uidvalidity = -1;
svars->drv[t] = ctx[t]->conf->driver; svars->drv[t] = ctx[t]->conf->driver;
svars->drv[t]->prepare_paths( ctx[t] ); svars->drv[t]->prepare_paths( ctx[t] );
} }
@ -862,7 +863,7 @@ box_selected( int sts, void *aux )
if (check_ret( sts, svars, t )) if (check_ret( sts, svars, t ))
return 1; return 1;
if (svars->uidval[t] && svars->uidval[t] != svars->ctx[t]->uidvalidity) { if (svars->uidval[t] >= 0 && svars->uidval[t] != svars->ctx[t]->uidvalidity) {
error( "Error: UIDVALIDITY of %s changed (got %d, expected %d)\n", error( "Error: UIDVALIDITY of %s changed (got %d, expected %d)\n",
str_ms[t], svars->ctx[t]->uidvalidity, svars->uidval[t] ); str_ms[t], svars->ctx[t]->uidvalidity, svars->uidval[t] );
svars->ret |= SYNC_FAIL; svars->ret |= SYNC_FAIL;
@ -1056,7 +1057,7 @@ msgs_found_sel( sync_vars_t *svars, int t )
if (!(svars->state[1-t] & ST_SENT_FIND_OLD) || svars->find_old_done[1-t] < svars->find_new_total[1-t]) if (!(svars->state[1-t] & ST_SENT_FIND_OLD) || svars->find_old_done[1-t] < svars->find_new_total[1-t])
return 0; return 0;
if (!svars->uidval[M] || !svars->uidval[S]) { if (svars->uidval[M] < 0 || svars->uidval[S] < 0) {
svars->uidval[M] = svars->ctx[M]->uidvalidity; svars->uidval[M] = svars->ctx[M]->uidvalidity;
svars->uidval[S] = svars->ctx[S]->uidvalidity; svars->uidval[S] = svars->ctx[S]->uidvalidity;
Fprintf( svars->jfp, "| %d %d\n", svars->uidval[M], svars->uidval[S] ); Fprintf( svars->jfp, "| %d %d\n", svars->uidval[M], svars->uidval[S] );