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: mutt-1-11-rel~93 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fe455d5fbcc464f5c0b462b04bcacf6861d32298;p=mutt 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 8e0ed562..ebfeaccf 100644 --- a/imap/command.c +++ b/imap/command.c @@ -315,7 +315,7 @@ void imap_cmd_finish (IMAP_DATA* 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 fce5622d..f1997ac8 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -817,7 +817,7 @@ static int imap_open_mailbox (CONTEXT* ctx) ctx->v2r = safe_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"); mutt_sleep (1); diff --git a/imap/imap_private.h b/imap/imap_private.h index d13a2c58..d1b9ff42 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -285,7 +285,8 @@ int imap_cmd_idle (IMAP_DATA* idata); /* message.c */ void imap_add_keywords (char* s, HEADER* keywords, LIST* mailbox_flags, size_t slen); void imap_free_header_data (IMAP_HEADER_DATA** data); -int imap_read_headers (IMAP_DATA* idata, unsigned int msn_begin, unsigned int msn_end); +int imap_read_headers (IMAP_DATA* idata, unsigned int msn_begin, unsigned int msn_end, + int initial_download); char* imap_set_flags (IMAP_DATA* idata, HEADER* h, char* s, int *server_changes); int imap_cache_del (IMAP_DATA* idata, HEADER* h); int imap_cache_clean (IMAP_DATA* idata); diff --git a/imap/message.c b/imap/message.c index dbddee4e..a42369f5 100644 --- a/imap/message.c +++ b/imap/message.c @@ -173,7 +173,8 @@ static void imap_fetch_msn_seqset (BUFFER *b, IMAP_DATA *idata, unsigned int msn * msn of 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 (IMAP_DATA* idata, unsigned int msn_begin, unsigned int msn_end) +int imap_read_headers (IMAP_DATA* idata, unsigned int msn_begin, unsigned int msn_end, + int initial_download) { CONTEXT* ctx; IMAP_STATUS* status; @@ -210,7 +211,7 @@ int imap_read_headers (IMAP_DATA* idata, unsigned int msn_begin, unsigned int ms #if 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", imap_hcache_keylen); puidnext = mutt_hcache_fetch_raw (idata->hcache, "/UIDNEXT", imap_hcache_keylen); @@ -306,16 +307,24 @@ int imap_read_headers (IMAP_DATA* idata, unsigned int msn_begin, unsigned int ms mutt_hcache_store_raw (idata->hcache, "/UIDNEXT", &idata->uidnext, sizeof (idata->uidnext), imap_hcache_keylen); - if (has_condstore || has_qresync) - mutt_hcache_store_raw (idata->hcache, "/MODSEQ", &idata->modseq, - sizeof (idata->modseq), imap_hcache_keylen); - else - mutt_hcache_delete (idata->hcache, "/MODSEQ", imap_hcache_keylen); + /* 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", &idata->modseq, + sizeof (idata->modseq), imap_hcache_keylen); + else + mutt_hcache_delete (idata->hcache, "/MODSEQ", imap_hcache_keylen); - 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)