/* 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);
/* 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;
{
if (mbox_mbox_open(m, ctx) < 0)
return -1;
- mx_update_context(ctx, m->msg_count);
+ mx_update_context(ctx);
}
struct stat st;
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
{
if (reopen_mailbox(ctx, index_hint) != -1)
{
- mx_update_context(ctx, m->msg_count);
+ mx_update_context(ctx);
if (unlock)
{
mbox_unlock_mailbox(m);
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))
{
/**
* 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];
m->msg_new++;
}
}
+
+ mutt_sort_headers(ctx, true); /* rethread from scratch */
}
/**
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);
/* 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 */
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)
e->changed = true;
e->received = e->date_sent;
e->index = m->msg_count++;
- mx_update_context(ctx, 1);
+ mx_update_context(ctx);
return 0;
}
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);
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);
}
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);
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;