NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
index.c File Reference

Index Window. More...

#include "config.h"
#include <stdbool.h>
#include <stddef.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "alias/lib.h"
#include "gui/lib.h"
#include "gui/module_data.h"
#include "attach/lib.h"
#include "color/lib.h"
#include "index/lib.h"
#include "menu/lib.h"
#include "postpone/lib.h"
#include "globals.h"
#include "module_data.h"
#include "muttlib.h"
#include "private_data.h"
#include "shared_data.h"
#include "subjectrx.h"
+ Include dependency graph for index.c:

Go to the source code of this file.

Functions

static void sort_use_threads_warn (void)
 Alert the user to odd $sort settings.
 
static int config_sort (const struct ConfigSubset *sub)
 React to changes to "sort".
 
static int config_use_threads (const struct ConfigSubset *sub)
 React to changes to "use_threads".
 
void index_adjust_sort_threads (const struct ConfigSubset *sub)
 Adjust use_threads/sort/sort_aux.
 
static int config_reply_regex (struct MailboxView *mv)
 React to changes to $reply_regex.
 
static int index_altern_observer (struct NotifyCallback *nc)
 Notification that an 'alternates' command has occurred - Implements observer_t -.
 
static int index_attach_observer (struct NotifyCallback *nc)
 Notification that an 'attachments' command has occurred - Implements observer_t -.
 
static int index_color_observer (struct NotifyCallback *nc)
 Notification that a Color has changed - Implements observer_t -.
 
static bool config_check_sort (const char *option)
 Does this config option affect the Index sorting?
 
bool config_check_index (const char *option)
 Does this config option affect the Index?
 
static int index_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t -.
 
static int index_global_observer (struct NotifyCallback *nc)
 Notification that a Global event occurred - Implements observer_t -.
 
static int index_index_observer (struct NotifyCallback *nc)
 Notification that the Index has changed - Implements observer_t -.
 
static int index_menu_observer (struct NotifyCallback *nc)
 Notification that the Menu has changed - Implements observer_t -.
 
static int index_score_observer (struct NotifyCallback *nc)
 Notification that a 'score' command has occurred - Implements observer_t -.
 
static int index_subjectrx_observer (struct NotifyCallback *nc)
 Notification that a 'subject-regex' command has occurred - Implements observer_t -.
 
static int index_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t -.
 
static int index_recalc (struct MuttWindow *win)
 Recalculate the Index display - Implements MuttWindow::recalc() -.
 
static int index_repaint (struct MuttWindow *win)
 Repaint the Index display - Implements MuttWindow::repaint() -.
 
struct MuttWindowindex_window_new (struct IndexPrivateData *priv)
 Create a new Index Window (list of Emails)
 
struct MailboxViewget_current_mailbox_view (void)
 Get the current Mailbox view.
 
struct Mailboxget_current_mailbox (void)
 Get the current Mailbox.
 

Detailed Description

Index Window.

Authors
  • Eric Blake
  • Richard Russon
  • Pietro Cerutti
  • Alejandro Colomar

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file index.c.

Function Documentation

◆ sort_use_threads_warn()

static void sort_use_threads_warn ( void )
static

Alert the user to odd $sort settings.

Definition at line 96 of file index.c.

97{
98 static bool warned = false;
99 if (!warned)
100 {
101 mutt_warning(_("Changing threaded display should prefer $use_threads over $sort"));
102 warned = true;
103 mutt_sleep(0);
104 }
105}
#define mutt_warning(...)
Definition logging2.h:92
#define _(a)
Definition message.h:28
void mutt_sleep(short s)
Sleep for a while.
Definition muttlib.c:787
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ config_sort()

static int config_sort ( const struct ConfigSubset * sub)
static

React to changes to "sort".

Parameters
subthe config subset that was just updated
Return values
0Successfully handled
-1Error

Definition at line 113 of file index.c.

114{
115 const enum EmailSortType c_sort = cs_subset_sort(sub, "sort");
116 const unsigned char c_use_threads = cs_subset_enum(sub, "use_threads");
117
118 if (((c_sort & SORT_MASK) != EMAIL_SORT_THREADS) || (c_use_threads == UT_UNSET))
119 return 0;
120
122
123 /* Note: changing a config variable here kicks off a second round of
124 * observers before the first round has completed. Be careful that
125 * changes made here do not cause an infinite loop of toggling
126 * adjustments - the early exit above when $sort no longer uses
127 * EMAIL_SORT_THREADS ends the recursion.
128 */
129 int rc;
130 if ((c_use_threads == UT_FLAT) ||
131 (!(c_sort & SORT_REVERSE) == (c_use_threads == UT_REVERSE)))
132 {
133 /* If we were flat or the user wants to change thread
134 * directions, then leave $sort alone for now and change
135 * $use_threads to match the desired outcome. The 2nd-level
136 * observer for $use_threads will then adjust $sort, and our
137 * 3rd-level observer for $sort will be a no-op.
138 */
139 rc = cs_subset_str_native_set(sub, "use_threads",
140 (c_sort & SORT_REVERSE) ? UT_REVERSE : UT_THREADS, NULL);
141 }
142 else
143 {
144 /* We were threaded, and the user still wants the same thread
145 * direction. Adjust $sort based on $sort_aux, and the 2nd-level
146 * observer for $sort will be a no-op.
147 */
148 enum EmailSortType c_sort_aux = cs_subset_sort(sub, "sort_aux");
149 c_sort_aux ^= (c_sort & SORT_REVERSE);
150 rc = cs_subset_str_native_set(sub, "sort", c_sort_aux, NULL);
151 }
152 return (CSR_RESULT(rc) == CSR_SUCCESS) ? 0 : -1;
153}
unsigned char cs_subset_enum(const struct ConfigSubset *sub, const char *name)
Get a enumeration config item by name.
Definition helpers.c:71
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition helpers.c:266
#define CSR_RESULT(x)
Extract the result code from CSR_* flags.
Definition set.h:53
#define CSR_SUCCESS
Action completed successfully.
Definition set.h:33
#define SORT_MASK
Mask for the sort id.
Definition sort.h:39
#define SORT_REVERSE
Reverse the order of the sort.
Definition sort.h:40
EmailSortType
Methods for sorting Emails.
Definition sort.h:53
@ EMAIL_SORT_THREADS
Sort by email threads.
Definition sort.h:62
@ UT_FLAT
Unthreaded.
Definition thread.h:104
@ UT_UNSET
Not yet set by user, stick to legacy semantics.
Definition thread.h:103
@ UT_THREADS
Normal threading (root above subthreads)
Definition thread.h:105
@ UT_REVERSE
Reverse threading (subthreads above root)
Definition thread.h:106
static void sort_use_threads_warn(void)
Alert the user to odd $sort settings.
Definition index.c:96
int cs_subset_str_native_set(const struct ConfigSubset *sub, const char *name, intptr_t value, struct Buffer *err)
Natively set the value of a string config item.
Definition subset.c:303
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ config_use_threads()

static int config_use_threads ( const struct ConfigSubset * sub)
static

React to changes to "use_threads".

Parameters
subthe config subset that was just updated
Return values
0Successfully handled
-1Error

Definition at line 161 of file index.c.

162{
163 const enum EmailSortType c_sort = cs_subset_sort(sub, "sort");
164 const unsigned char c_use_threads = cs_subset_enum(sub, "use_threads");
165
166 if (((c_sort & SORT_MASK) != EMAIL_SORT_THREADS) || (c_use_threads == UT_UNSET))
167 return 0;
168
170
171 /* Note: changing a config variable here kicks off a second round of
172 * observers before the first round has completed. But since we
173 * aren't setting $sort to threads, the 2nd-level observer will be a
174 * no-op.
175 */
176 const enum EmailSortType c_sort_aux = cs_subset_sort(sub, "sort_aux");
177 int rc = cs_subset_str_native_set(sub, "sort", c_sort_aux, NULL);
178 return (CSR_RESULT(rc) == CSR_SUCCESS) ? 0 : -1;
179}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ index_adjust_sort_threads()

void index_adjust_sort_threads ( const struct ConfigSubset * sub)

Adjust use_threads/sort/sort_aux.

Parameters
subthe config subset that was just updated

Definition at line 185 of file index.c.

186{
187 /* For lack of a better way, we fake a "set use_threads" */
189}
static int config_use_threads(const struct ConfigSubset *sub)
React to changes to "use_threads".
Definition index.c:161
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ config_reply_regex()

static int config_reply_regex ( struct MailboxView * mv)
static

React to changes to $reply_regex.

Parameters
mvMailbox View
Return values
0Successfully handled
-1Error

Definition at line 197 of file index.c.

198{
199 if (!mv || !mv->mailbox)
200 return 0;
201
202 struct Mailbox *m = mv->mailbox;
203
204 for (int i = 0; i < m->msg_count; i++)
205 {
206 struct Email *e = m->emails[i];
207 if (!e)
208 break;
209 struct Envelope *env = e->env;
210 if (!env || !env->subject)
211 continue;
212
213 mutt_env_set_subject(env, env->subject);
214 }
215
216 OptResortInit = true; /* trigger a redraw of the index */
217 return 0;
218}
bool OptResortInit
(pseudo) used to force the next resort to be from scratch
Definition globals.c:56
void mutt_env_set_subject(struct Envelope *env, const char *subj)
Set both subject and real_subj to subj.
Definition envelope.c:68
The envelope/body of an email.
Definition email.h:39
struct Envelope * env
Envelope information.
Definition email.h:68
The header of an Email.
Definition envelope.h:57
char *const subject
Email's subject.
Definition envelope.h:70
struct Mailbox * mailbox
Current Mailbox.
Definition mview.h:51
A mailbox.
Definition mailbox.h:81
int msg_count
Total number of messages.
Definition mailbox.h:90
struct Email ** emails
Array of Emails.
Definition mailbox.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ config_check_sort()

static bool config_check_sort ( const char * option)
static

Does this config option affect the Index sorting?

Parameters
optionConfig option
Return values
trueIndex may need resorting

< Resort the mailbox

< Resort from scratch

< Resort subthreads

Definition at line 317 of file index.c.

318{
319 const int R_RESORT = (1 << 0);
320 const int R_RESORT_INIT = (1 << 1);
321 const int R_RESORT_SUB = (1 << 2);
322
323 static const struct Mapping sort_options[] = {
324 // clang-format off
325 { "duplicate_threads", R_RESORT | R_RESORT_INIT },
326 { "reply_regex", R_RESORT },
327 { "sort", R_RESORT },
328 { "sort_aux", R_RESORT | R_RESORT_SUB },
329 { "sort_re", R_RESORT | R_RESORT_INIT },
330 { "strict_threads", R_RESORT | R_RESORT_INIT },
331 { "thread_received", R_RESORT | R_RESORT_INIT },
332 { "use_threads", R_RESORT },
333 { NULL, 0 },
334 // clang-format on
335 };
336
337 int flags = mutt_map_get_value(option, sort_options);
338 if (flags < 0)
339 return false;
340
341 if (flags & R_RESORT)
342 OptNeedResort = true;
343 if (flags & R_RESORT_INIT)
344 OptResortInit = true;
345 if (flags & R_RESORT_SUB)
346 OptSortSubthreads = true;
347
348 return true;
349}
bool OptNeedResort
(pseudo) used to force a re-sort
Definition globals.c:52
bool OptSortSubthreads
(pseudo) used when $sort_aux changes
Definition globals.c:57
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition mapping.c:85
Mapping between user-readable string and a constant.
Definition mapping.h:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ config_check_index()

bool config_check_index ( const char * option)

Does this config option affect the Index?

Parameters
optionConfig option
Return values
trueIndex may need redrawing

Definition at line 356 of file index.c.

357{
358 static const char *index_options[] = {
359 "ascii_chars", "crypt_chars",
360 "flag_chars", "from_chars",
361 "group_index_format", "hide_limited",
362 "hide_missing", "hide_thread_subject",
363 "hide_top_limited", "hide_top_missing",
364 "imap_headers", "index_format",
365 "mark_old", "mbox",
366 "narrow_tree", "postponed",
367 "real_name", "reverse_alias",
368 "reverse_name", "reverse_real_name",
369 "status_chars", "status_format",
370 "to_chars", "ts_enabled",
371 "ts_icon_format", "ts_status_format"
372 };
373
374 for (size_t i = 0; i < countof(index_options); i++)
375 {
376 if (mutt_str_equal(option, index_options[i]))
377 return true;
378 }
379
380 return false;
381}
#define countof(x)
Definition memory.h:49
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ index_window_new()

struct MuttWindow * index_window_new ( struct IndexPrivateData * priv)

Create a new Index Window (list of Emails)

Parameters
privPrivate Index data
Return values
ptrNew Window

Definition at line 658 of file index.c.

659{
661 ASSERT(mod_data);
662
663 struct MuttWindow *win = menu_window_new(mod_data->menu_index, NeoMutt->sub);
664 win->recalc = index_recalc;
665 win->repaint = index_repaint;
666
667 struct Menu *menu = win->wdata;
668 menu->mdata = priv;
669 menu->mdata_free = NULL; // Menu doesn't own the data
670 priv->menu = menu;
671
682
683 return win;
684}
void mutt_color_observer_add(observer_t callback, void *global_data)
Add an observer.
Definition notify.c:62
static int index_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t -.
Definition index.c:261
static int index_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition index.c:386
static int index_index_observer(struct NotifyCallback *nc)
Notification that the Index has changed - Implements observer_t -.
Definition index.c:456
static int index_menu_observer(struct NotifyCallback *nc)
Notification that the Menu has changed - Implements observer_t -.
Definition index.c:481
static int index_score_observer(struct NotifyCallback *nc)
Notification that a 'score' command has occurred - Implements observer_t -.
Definition index.c:503
static int index_subjectrx_observer(struct NotifyCallback *nc)
Notification that a 'subject-regex' command has occurred - Implements observer_t -.
Definition index.c:535
static int index_global_observer(struct NotifyCallback *nc)
Notification that a Global event occurred - Implements observer_t -.
Definition index.c:433
static int index_altern_observer(struct NotifyCallback *nc)
Notification that an 'alternates' command has occurred - Implements observer_t -.
Definition index.c:223
static int index_attach_observer(struct NotifyCallback *nc)
Notification that an 'attachments' command has occurred - Implements observer_t -.
Definition index.c:242
static int index_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition index.c:554
static int index_recalc(struct MuttWindow *win)
Recalculate the Index display - Implements MuttWindow::recalc() -.
Definition index.c:594
static int index_repaint(struct MuttWindow *win)
Repaint the Index display - Implements MuttWindow::repaint() -.
Definition index.c:604
struct MuttWindow * menu_window_new(const struct MenuDefinition *md, struct ConfigSubset *sub)
Create a new Menu Window.
Definition window.c:140
@ MODULE_ID_INDEX
ModuleIndex, Index
Definition module_api.h:72
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition notify.c:191
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition notify_type.h:58
@ NT_MENU
Menu has changed, MenuRedrawFlags.
Definition notify_type.h:52
@ NT_ATTACH
Attachment command changed, NotifyAttach.
Definition notify_type.h:39
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition notify_type.h:43
@ NT_SCORE
Email scoring has changed.
Definition notify_type.h:55
@ NT_SUBJECTRX
Subject Regex has changed, NotifySubjectRx.
Definition notify_type.h:56
@ NT_ALL
Register for all notifications.
Definition notify_type.h:35
@ NT_GLOBAL
Not object-related, NotifyGlobal.
Definition notify_type.h:46
@ NT_ALTERN
Alternates command changed, NotifyAlternates.
Definition notify_type.h:38
#define ASSERT(COND)
Definition signal2.h:59
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition subset.h:51
Index private Module data.
Definition module_data.h:32
struct MenuDefinition * menu_index
Index menu definition.
Definition module_data.h:34
struct IndexSharedData * shared
Shared Index data.
struct Menu * menu
Menu controlling the index.
struct Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition shared_data.h:44
Definition lib.h:86
struct MuttWindow * win
Window holding the Menu.
Definition lib.h:94
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition lib.h:169
struct Notify * notify
Notifications.
Definition lib.h:153
void * mdata
Private data.
Definition lib.h:155
int(* repaint)(struct MuttWindow *win)
void * wdata
Private data.
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
int(* recalc)(struct MuttWindow *win)
Container for Accounts, Notifications.
Definition neomutt.h:41
struct Notify * notify
Notifications handler.
Definition neomutt.h:45
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_current_mailbox_view()

struct MailboxView * get_current_mailbox_view ( void )

Get the current Mailbox view.

Return values
ptrCurrent Mailbox view

Search for the last (most recent) dialog that has an Index. Then return the Mailbox from its shared data.

Definition at line 693 of file index.c.

694{
696 if (!mod_data || !mod_data->all_dialogs_window)
697 return NULL;
698
699 struct MuttWindow **wp = NULL;
701 {
702 struct MuttWindow *win = window_find_child(*wp, WT_DLG_INDEX);
703 if (win)
704 {
705 struct IndexSharedData *shared = win->wdata;
706 return shared->mailbox_view;
707 }
708
710 if (win)
711 {
712 return postponed_get_mailbox_view(win);
713 }
714 }
715
716 return NULL;
717}
#define ARRAY_FOREACH_REVERSE(elem, head)
Iterate backwards over all elements of the array.
Definition array.h:274
@ MODULE_ID_GUI
ModuleGui, Graphical code
Definition module_api.h:45
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
@ WT_DLG_INDEX
Index Dialog, dlg_index()
Definition mutt_window.h:86
@ WT_DLG_POSTPONE
Postpone Dialog, dlg_postpone()
Definition mutt_window.h:90
struct MailboxView * postponed_get_mailbox_view(struct MuttWindow *dlg)
Extract the Mailbox from the Postponed Dialog.
Definition functions.c:337
Gui private Module data.
Definition module_data.h:32
struct MuttWindow * all_dialogs_window
Parent of all Dialogs.
Definition module_data.h:38
Data shared between Index, Pager and Sidebar.
Definition shared_data.h:37
struct MailboxView * mailbox_view
Current Mailbox view.
Definition shared_data.h:40
struct MuttWindowArray children
Children Windows.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_current_mailbox()

struct Mailbox * get_current_mailbox ( void )

Get the current Mailbox.

Return values
ptrCurrent Mailbox

Search for the last (most recent) dialog that has an Index. Then return the Mailbox from its shared data.

Definition at line 726 of file index.c.

727{
729 if (mv)
730 return mv->mailbox;
731
732 return NULL;
733}
struct MailboxView * get_current_mailbox_view(void)
Get the current Mailbox view.
Definition index.c:693
View of a Mailbox.
Definition mview.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function: