From: Kevin McCarthy Date: Mon, 13 Aug 2018 16:43:55 +0000 (-0700) Subject: Only sync CONDSTORE and QRESYNC on the initial download. X-Git-Tag: 2019-10-25~665^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4cbba8ac6501f325210e5d4dcc828f580ebd5a19;p=neomutt Only sync CONDSTORE and QRESYNC on the initial download. In the midst of the imap_read_headers() refactor, I forgot to put this guard on the /MODSEQ and /UIDSEQSET storage. Because we don't deal with flag sync issues while the mailbox is open, or when it closes, we only want to write those values to the header cache during the initial download. It makes no sense to perform all the header cache work if new messages come into an open empty mailbox, so add a parameter to flag the initial download, rather than check for msn_begin==1. --- diff --git a/imap/command.c b/imap/command.c index c8be25112..bfefd4acd 100644 --- a/imap/command.c +++ b/imap/command.c @@ -1332,7 +1332,7 @@ void imap_cmd_finish(struct ImapData *idata) /* check_status: curs_main uses imap_check_mailbox to detect * whether the index needs updating */ idata->check_status = IMAP_NEWMAIL_PENDING; - imap_read_headers(idata, idata->max_msn + 1, count); + imap_read_headers(idata, idata->max_msn + 1, count, 0); } else if (idata->reopen & IMAP_EXPUNGE_PENDING) { diff --git a/imap/imap.c b/imap/imap.c index 0a4d4dc89..05663d097 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -2224,7 +2224,7 @@ static int imap_mbox_open(struct Context *ctx) ctx->v2r = mutt_mem_calloc(count, sizeof(int)); ctx->msgcount = 0; - if (count && (imap_read_headers(idata, 1, count) < 0)) + if (count && (imap_read_headers(idata, 1, count, 1) < 0)) { mutt_error(_("Error opening mailbox")); goto fail; diff --git a/imap/imap_private.h b/imap/imap_private.h index 90e51381c..126eb92e4 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -314,7 +314,8 @@ int imap_cmd_idle(struct ImapData *idata); /* message.c */ void imap_free_header_data(struct ImapHeaderData **data); -int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, unsigned int msn_end); +int imap_read_headers (struct ImapData* idata, unsigned int msn_begin, unsigned int msn_end, + int initial_download); char *imap_set_flags(struct ImapData *idata, struct Header *h, char *s, int *server_changes); int imap_cache_del(struct ImapData *idata, struct Header *h); int imap_cache_clean(struct ImapData *idata); diff --git a/imap/message.c b/imap/message.c index 97db6d1c7..97a3a1111 100644 --- a/imap/message.c +++ b/imap/message.c @@ -1092,7 +1092,8 @@ bail: * the last message read. It will return a value other than msn_end if mail * comes in while downloading headers (in theory). */ -int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, unsigned int msn_end) +int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, + unsigned int msn_end, int initial_download) { struct ImapStatus *status = NULL; int oldmsgcount; @@ -1128,7 +1129,7 @@ int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, unsigned i #ifdef USE_HCACHE idata->hcache = imap_hcache_open(idata, NULL); - if (idata->hcache && (msn_begin == 1)) + if (idata->hcache && initial_download) { uid_validity = mutt_hcache_fetch_raw(idata->hcache, "/UIDVALIDITY", 12); puidnext = mutt_hcache_fetch_raw(idata->hcache, "/UIDNEXT", 8); @@ -1223,16 +1224,24 @@ int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, unsigned i mutt_hcache_store_raw(idata->hcache, "/UIDNEXT", 8, &idata->uidnext, sizeof(idata->uidnext)); - if (has_condstore || has_qresync) - mutt_hcache_store_raw(idata->hcache, "/MODSEQ", 7, &idata->modseq, - sizeof(idata->modseq)); - else - mutt_hcache_delete(idata->hcache, "/MODSEQ", 7); + /* We currently only sync CONDSTORE and QRESYNC on the initial download. + * To do it more often, we'll need to deal with flag updates combined with + * unsync'ed local flag changes. We'll also need to properly sync flags to + * the header cache on close. I'm not sure it's worth the added complexity. + */ + if (initial_download) + { + if (has_condstore || has_qresync) + mutt_hcache_store_raw(idata->hcache, "/MODSEQ", 7, &idata->modseq, + sizeof(idata->modseq)); + else + mutt_hcache_delete(idata->hcache, "/MODSEQ", 7); - if (has_qresync) - imap_hcache_store_uid_seqset(idata); - else - imap_hcache_clear_uid_seqset(idata); + if (has_qresync) + imap_hcache_store_uid_seqset(idata); + else + imap_hcache_clear_uid_seqset(idata); + } #endif /* USE_HCACHE */ if (ctx->msgcount > oldmsgcount)