Conversation
EmailView will contain all the GUI properties of the Email.
This gives the front-end its own independent array of Emails.
The EmailView will contain all the GUI properties of the Email.
Move the independent Email array into MailboxView.
Add a parallel array of EmailViews to MailboxView, providing the GUI with its own copy of the email list. Each EmailView wraps a pointer to the backend's Email. - Add eviews[], eview_max, eview_count, eview_hash to MailboxView - Populate eviews in mview_update() and mview_new() - Clean up eviews in mview_free() and mview_cleanup() - Add mview_eview_by_email() for O(1) Email->EmailView lookup Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Extract eviews rebuild logic into mview_sync_eviews() and call it from both mview_update() and mutt_sort_headers(). This ensures the GUI's email list stays synchronized with the backend's email list whenever the mailbox is updated or re-sorted. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Change mview_update(), mview_free(), ea_add_tagged(), and mutt_limit_current_thread() to iterate the GUI's eviews array instead of directly accessing the backend's m->emails[]. The only remaining m->emails[] access is in mview_sync_eviews() which is the designated sync point between backend and GUI. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Migrate mutt_clear_threads(), check_subjects(), mutt_sort_threads(), and mutt_set_vnum() to iterate mv->eviews[] instead of m->emails[]. Functions that build backend hash tables (make_subj_hash, mutt_make_id_hash) and linearize_tree() which writes to m->emails[] are left unchanged as they are legitimate backend operations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Migrate email iteration in index/dlg_index.c, index/functions.c, index/index.c, and index/subjectrx.c to use mv->eviews[] instead of m->emails[]. Sites that access backend emails before sync (save_new in update_index_threaded, NNTP fetch) or that serve as null guards (index_repaint) are left unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Migrate email iteration in MUTT_LIMIT and search pattern reset to use mv->eviews[] instead of m->emails[]. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@codex review |
| if (!ptr || !*ptr) | ||
| return; | ||
|
|
||
| // struct EmailView *ev = *ptr; |
Check notice
Code scanning / CodeQL
Commented-out code Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 days ago
In general, the way to fix commented-out code is to either (a) remove it entirely if it is no longer needed, or (b) reinstate it as active code and ensure it is compiled, tested, and actually used. For snippets included only for documentation, they should be clearly marked as examples, not commented-out “live” code.
For this specific case in core/eview.c, the best fix without changing functionality is simply to delete the commented-out line // struct EmailView *ev = *ptr;. The function eview_free currently checks for null pointers and then calls FREE(ptr);; it does not need a local ev variable, and the commented line provides no value. No additional imports, methods, or definitions are required.
Concretely, edit core/eview.c in eview_free and remove line 44. No other changes are needed.
| @@ -41,8 +41,6 @@ | ||
| if (!ptr || !*ptr) | ||
| return; | ||
|
|
||
| // struct EmailView *ev = *ptr; | ||
|
|
||
| FREE(ptr); | ||
| } | ||
|
|
| if (update) | ||
| { | ||
| email_set_color(m, e); | ||
| //QWQ email_set_color(m, e); |
Check notice
Code scanning / CodeQL
Commented-out code Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 days ago
To fix the problem, we should either remove the commented-out function call entirely or reinstate it as active code, depending on whether it is still needed for functionality. Since we must avoid changing existing functionality, the safer approach is to remove the commented-out call, as it is currently not executed and therefore does not affect behavior. This directly satisfies the guideline to avoid commented-out code while preserving runtime behavior.
Concretely, in flags.c, inside mutt_set_flag, locate the if (update) block (around lines 333–338). Remove the line //QWQ email_set_color(m, e); and leave the rest of the block unchanged. No new imports, methods, or definitions are required, and no other parts of the file need modification.
| @@ -332,7 +332,6 @@ | ||
|
|
||
| if (update) | ||
| { | ||
| //QWQ email_set_color(m, e); | ||
| struct EventMailbox ev_m = { m }; | ||
| notify_send(m->notify, NT_MAILBOX, NT_MAILBOX_CHANGE, &ev_m); | ||
| } |
| update_email_flags(m, e, buf); | ||
| update_email_tags(e, msg); | ||
| email_set_color(m, e); | ||
| //QWQ email_set_color(m, e); |
Check notice
Code scanning / CodeQL
Commented-out code Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 days ago
In general, to fix commented-out code, either reinstate it as active code (if it is still required and correct) or remove it entirely (if it is obsolete or intentionally disabled without clear purpose). Since we must avoid changing existing functionality and do not know the current expectations around color handling, reinstating email_set_color(m, e); could introduce unintended side effects. The minimal, behavior-preserving fix is to delete the commented-out line.
Concretely, in notmuch/notmuch.c, within the nm_tags_commit function (around lines 2445–2449), remove the line //QWQ email_set_color(m, e);. No additional imports, methods, or definitions are required, since we are not adding or re-enabling any functionality—only cleaning up commented-out code.
| @@ -2445,7 +2445,6 @@ | ||
| update_tags(msg, buf); | ||
| update_email_flags(m, e, buf); | ||
| update_email_tags(e, msg); | ||
| //QWQ email_set_color(m, e); | ||
|
|
||
| rc = 0; | ||
| e->changed = true; |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c85f640c71
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (m->email_max > mv->eview_max) | ||
| { | ||
| notify_observer_remove(mv->mailbox->notify, mview_mailbox_observer, mv); | ||
|
|
||
| // Disconnect the Emails before freeing the Threads | ||
| for (int i = 0; i < mv->mailbox->msg_count; i++) | ||
| { | ||
| struct Email *e = mv->mailbox->emails[i]; | ||
| if (!e) | ||
| continue; | ||
| e->thread = NULL; | ||
| e->threaded = false; | ||
| } | ||
| mutt_mem_realloc(&mv->eviews, m->email_max * sizeof(struct EmailView *)); | ||
| memset(mv->eviews + mv->eview_max, 0, | ||
| (m->email_max - mv->eview_max) * sizeof(struct EmailView *)); | ||
| mv->eview_max = m->email_max; |
There was a problem hiding this comment.
Resize virtual view map when mailbox capacity increases
When mx_alloc_memory() grows m->email_max after new mail arrives, this function only reallocates mv->eviews and leaves mv->v2r at its old size. Subsequent paths (mview_update(), mutt_set_vnum(), and limit updates) write mv->v2r[mv->vcount] up to the new message count, so folders that grow beyond their initial capacity can trigger out-of-bounds writes and crashes.
Useful? React with 👍 / 👎.
| mutt_qsort_r((void *) mv->v2r, mv->vcount, sizeof(struct EmailView *), | ||
| email_sort_shim, &cmp); |
There was a problem hiding this comment.
Preserve sorted order in unthreaded header sorting
The unthreaded branch now sorts mv->v2r, but immediately afterward the code rebuilds mv->v2r by iterating m->emails in mailbox order, which overwrites the sorted result. This effectively disables $sort/$sort_aux ordering for non-threaded index views because the displayed mapping is reset to unsorted order every time.
Useful? React with 👍 / 👎.
| if (update) | ||
| { | ||
| email_set_color(m, e); | ||
| //QWQ email_set_color(m, e); | ||
| struct EventMailbox ev_m = { m }; |
There was a problem hiding this comment.
Recompute cached color when mutt_set_flag changes state
This change comments out the color refresh in mutt_set_flag(), so flag/read/delete/tag operations can leave e->attr_color stale. Since index_color() returns the cached color when present, users can see incorrect highlighting after state changes until another code path happens to clear or recompute the cache.
Useful? React with 👍 / 👎.
WIP