From: Pietro Cerutti Date: Mon, 3 Dec 2018 15:25:01 +0000 (+0000) Subject: Recompute and re-thread everything in mx_update_context X-Git-Tag: 2019-10-25~467 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=918885f32db41;p=neomutt Recompute and re-thread everything in mx_update_context This allows us to be less strict about calling mx_update_context, e.g., by calling it twice if it so happens within a code path. --- diff --git a/maildir/maildir.c b/maildir/maildir.c index 306afe63b..53cdba349 100644 --- a/maildir/maildir.c +++ b/maildir/maildir.c @@ -530,7 +530,7 @@ int maildir_mbox_check(struct Context *ctx, int *index_hint) /* Incorporate new messages */ num_new = maildir_move_to_context(m, &md); if (num_new > 0) - mx_update_context(ctx, num_new); + mx_update_context(ctx); mutt_buffer_pool_release(&buf); diff --git a/maildir/mh.c b/maildir/mh.c index d1c4e3510..4fa77503d 100644 --- a/maildir/mh.c +++ b/maildir/mh.c @@ -720,7 +720,7 @@ int mh_mbox_check(struct Context *ctx, int *index_hint) /* Incorporate new messages */ num_new = maildir_move_to_context(m, &md); if (num_new > 0) - mx_update_context(ctx, num_new); + mx_update_context(ctx); if (occult) return MUTT_REOPENED; diff --git a/mbox/mbox.c b/mbox/mbox.c index 0ce572681..4f4b22410 100644 --- a/mbox/mbox.c +++ b/mbox/mbox.c @@ -1031,7 +1031,7 @@ static int mbox_mbox_check(struct Context *ctx, int *index_hint) { if (mbox_mbox_open(m, ctx) < 0) return -1; - mx_update_context(ctx, m->msg_count); + mx_update_context(ctx); } struct stat st; @@ -1094,7 +1094,7 @@ static int mbox_mbox_check(struct Context *ctx, int *index_hint) mmdf_parse_mailbox(ctx); if (m->msg_count > old_msg_count) - mx_update_context(ctx, m->msg_count > old_msg_count); + mx_update_context(ctx); /* Only unlock the folder if it was locked inside of this routine. * It may have been locked elsewhere, like in @@ -1124,7 +1124,7 @@ static int mbox_mbox_check(struct Context *ctx, int *index_hint) { if (reopen_mailbox(ctx, index_hint) != -1) { - mx_update_context(ctx, m->msg_count); + mx_update_context(ctx); if (unlock) { mbox_unlock_mailbox(m); diff --git a/mx.c b/mx.c index 2d6b0bbe6..e9e649da6 100644 --- a/mx.c +++ b/mx.c @@ -370,7 +370,7 @@ struct Context *mx_mbox_open(struct Mailbox *m, const char *path, int flags) int rc = m->mx_ops->mbox_open(ctx->mailbox, ctx); m->opened++; if (rc == 0) - mx_update_context(ctx, ctx->mailbox->msg_count); + mx_update_context(ctx); if ((rc == 0) || (rc == -2)) { @@ -1236,20 +1236,44 @@ void mx_alloc_memory(struct Mailbox *m) /** * mx_update_context - Update the Context's message counts * @param ctx Mailbox - * @param new_messages Number of new messages * - * this routine is called to update the counts in the context structure for the - * last message header parsed. + * this routine is called to update the counts in the context structure */ -void mx_update_context(struct Context *ctx, int new_messages) +void mx_update_context(struct Context *ctx) { if (!ctx || !ctx->mailbox) return; struct Mailbox *m = ctx->mailbox; + if (!m) + return; + + if (m->subj_hash) + { + mutt_hash_destroy(&m->subj_hash); + } + m->subj_hash = NULL; + + if (m->id_hash) + { + mutt_hash_destroy(&m->id_hash); + } + m->id_hash = NULL; + + /* reset counters */ + m->msg_unread = 0; + m->msg_flagged = 0; + m->msg_new = 0; + m->msg_deleted = 0; + m->msg_tagged = 0; + m->vcount = 0; + m->changed = false; + + mutt_clear_threads(ctx); + struct Email *e = NULL; - for (int msgno = m->msg_count - new_messages; msgno < m->msg_count; msgno++) + for (int msgno = 0; msgno < m->msg_count; msgno++) { e = m->hdrs[msgno]; @@ -1307,6 +1331,8 @@ void mx_update_context(struct Context *ctx, int new_messages) m->msg_new++; } } + + mutt_sort_headers(ctx, true); /* rethread from scratch */ } /** diff --git a/mx.h b/mx.h index ecc7258c8..4e7ea1fa0 100644 --- a/mx.h +++ b/mx.h @@ -282,7 +282,7 @@ int mx_check_empty (const char *path); void mx_fastclose_mailbox(struct Context *ctx); const struct MxOps *mx_get_ops (enum MailboxType magic); bool mx_tags_is_supported(struct Mailbox *m); -void mx_update_context (struct Context *ctx, int new_messages); +void mx_update_context (struct Context *ctx); void mx_update_tables (struct Context *ctx, bool committing); void mx_cleanup_context (struct Context *ctx); diff --git a/nntp/nntp.c b/nntp/nntp.c index 0a0969a5b..22878b625 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -1692,21 +1692,7 @@ static int check_mailbox(struct Context *ctx) /* some headers were removed, context must be updated */ if (ret == MUTT_REOPENED) { - if (m->subj_hash) - mutt_hash_destroy(&m->subj_hash); - if (m->id_hash) - mutt_hash_destroy(&m->id_hash); - mutt_clear_threads(ctx); - - m->vcount = 0; - m->msg_deleted = 0; - m->msg_new = 0; - m->msg_unread = 0; - m->msg_flagged = 0; - m->changed = false; - m->id_hash = NULL; - m->subj_hash = NULL; - mx_update_context(ctx, m->msg_count); + mx_update_context(ctx); } /* fetch headers of new articles */ @@ -1728,7 +1714,7 @@ static int check_mailbox(struct Context *ctx) if (rc == 0) { if (m->msg_count > old_msg_count) - mx_update_context(ctx, m->msg_count > old_msg_count); + mx_update_context(ctx); mdata->last_loaded = mdata->last_message; } if (ret == 0 && m->msg_count > oldmsgcount) @@ -2297,7 +2283,7 @@ int nntp_check_msgid(struct Context *ctx, const char *msgid) e->changed = true; e->received = e->date_sent; e->index = m->msg_count++; - mx_update_context(ctx, 1); + mx_update_context(ctx); return 0; } @@ -2367,7 +2353,7 @@ int nntp_check_children(struct Context *ctx, const char *msgid) break; } if (m->msg_count > old_msg_count) - mx_update_context(ctx, m->msg_count > old_msg_count); + mx_update_context(ctx); #ifdef USE_HCACHE mutt_hcache_close(hc); diff --git a/notmuch/mutt_notmuch.c b/notmuch/mutt_notmuch.c index 7786ba861..253c8d7ac 100644 --- a/notmuch/mutt_notmuch.c +++ b/notmuch/mutt_notmuch.c @@ -1632,7 +1632,7 @@ int nm_read_entire_thread(struct Context *ctx, struct Email *e) rc = 0; if (m->msg_count > mdata->oldmsgcount) - mx_update_context(ctx, m->msg_count - mdata->oldmsgcount); + mx_update_context(ctx); done: if (q) notmuch_query_destroy(q); @@ -2286,7 +2286,7 @@ static int nm_mbox_check(struct Context *ctx, int *index_hint) } if (m->msg_count > mdata->oldmsgcount) - mx_update_context(ctx, m->msg_count - mdata->oldmsgcount); + mx_update_context(ctx); done: if (q) notmuch_query_destroy(q); diff --git a/pop/pop.c b/pop/pop.c index 8208df134..cc0d9c49a 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -928,7 +928,7 @@ static int pop_mbox_check(struct Context *ctx, int *index_hint) int ret = pop_fetch_headers(ctx); pop_clear_cache(adata); if (m->msg_count > old_msg_count) - mx_update_context(ctx, m->msg_count > old_msg_count); + mx_update_context(ctx); if (ret < 0) return -1;