NeoMutt  2024-03-23-142-g2b2e76
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
index.c File Reference

Index Window. More...

#include "config.h"
#include <stddef.h>
#include <stdbool.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "attach/lib.h"
#include "color/lib.h"
#include "menu/lib.h"
#include "postpone/lib.h"
#include "alternates.h"
#include "globals.h"
#include "mutt_thread.h"
#include "muttlib.h"
#include "mview.h"
#include "private_data.h"
#include "score.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_subjrx_observer (struct NotifyCallback *nc)
 Notification that a 'subjectrx' 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.
 
struct Menuget_current_menu (void)
 Get the current Menu.
 

Detailed Description

Index Window.

Authors
  • Eric Blake
  • Richard Russon
  • Pietro Cerutti

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 95 of file index.c.

96{
97 static bool warned = false;
98 if (!warned)
99 {
100 mutt_warning(_("Changing threaded display should prefer $use_threads over $sort"));
101 warned = true;
102 mutt_sleep(0);
103 }
104}
#define mutt_warning(...)
Definition: logging2.h:90
#define _(a)
Definition: message.h:28
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:878
+ 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 112 of file index.c.

113{
114 const enum SortType c_sort = cs_subset_sort(sub, "sort");
115 const unsigned char c_use_threads = cs_subset_enum(sub, "use_threads");
116
117 if (((c_sort & SORT_MASK) != SORT_THREADS) || (c_use_threads == UT_UNSET))
118 return 0;
119
121
122 /* Note: changing a config variable here kicks off a second round of
123 * observers before the first round has completed. Be careful that
124 * changes made here do not cause an infinite loop of toggling
125 * adjustments - the early exit above when $sort no longer uses
126 * SORT_THREADS ends the recursion.
127 */
128 int rc;
129 if ((c_use_threads == UT_FLAT) ||
130 (!(c_sort & SORT_REVERSE) == (c_use_threads == UT_REVERSE)))
131 {
132 /* If we were flat or the user wants to change thread
133 * directions, then leave $sort alone for now and change
134 * $use_threads to match the desired outcome. The 2nd-level
135 * observer for $use_threads will then adjust $sort, and our
136 * 3rd-level observer for $sort will be a no-op.
137 */
138 rc = cs_subset_str_native_set(sub, "use_threads",
139 (c_sort & SORT_REVERSE) ? UT_REVERSE : UT_THREADS, NULL);
140 }
141 else
142 {
143 /* We were threaded, and the user still wants the same thread
144 * direction. Adjust $sort based on $sort_aux, and the 2nd-level
145 * observer for $sort will be a no-op.
146 */
147 enum SortType c_sort_aux = cs_subset_sort(sub, "sort_aux");
148 c_sort_aux ^= (c_sort & SORT_REVERSE);
149 rc = cs_subset_str_native_set(sub, "sort", c_sort_aux, NULL);
150 }
151 return (CSR_RESULT(rc) == CSR_SUCCESS) ? 0 : -1;
152}
unsigned char cs_subset_enum(const struct ConfigSubset *sub, const char *name)
Get a enumeration config item by name.
Definition: helpers.c:72
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:267
#define CSR_RESULT(x)
Definition: set.h:52
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
static void sort_use_threads_warn(void)
Alert the user to odd $sort settings.
Definition: index.c:95
@ UT_FLAT
Unthreaded.
Definition: mutt_thread.h:99
@ UT_UNSET
Not yet set by user, stick to legacy semantics.
Definition: mutt_thread.h:98
@ UT_THREADS
Normal threading (root above subthreads)
Definition: mutt_thread.h:100
@ UT_REVERSE
Reverse threading (subthreads above root)
Definition: mutt_thread.h:101
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:70
SortType
Methods for sorting.
Definition: sort2.h:34
@ SORT_THREADS
Sort by email threads.
Definition: sort2.h:41
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:71
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:297
+ 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 160 of file index.c.

161{
162 const enum SortType c_sort = cs_subset_sort(sub, "sort");
163 const unsigned char c_use_threads = cs_subset_enum(sub, "use_threads");
164
165 if (((c_sort & SORT_MASK) != SORT_THREADS) || (c_use_threads == UT_UNSET))
166 return 0;
167
169
170 /* Note: changing a config variable here kicks off a second round of
171 * observers before the first round has completed. But since we
172 * aren't setting $sort to threads, the 2nd-level observer will be a
173 * no-op.
174 */
175 const enum SortType c_sort_aux = cs_subset_sort(sub, "sort_aux");
176 int rc = cs_subset_str_native_set(sub, "sort", c_sort_aux, NULL);
177 return (CSR_RESULT(rc) == CSR_SUCCESS) ? 0 : -1;
178}
+ 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 184 of file index.c.

185{
186 /* For lack of a better way, we fake a "set use_threads" */
188}
static int config_use_threads(const struct ConfigSubset *sub)
React to changes to "use_threads".
Definition: index.c:160
+ 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 196 of file index.c.

197{
198 if (!mv || !mv->mailbox)
199 return 0;
200
201 struct Mailbox *m = mv->mailbox;
202
203 for (int i = 0; i < m->msg_count; i++)
204 {
205 struct Email *e = m->emails[i];
206 if (!e)
207 break;
208 struct Envelope *env = e->env;
209 if (!env || !env->subject)
210 continue;
211
212 mutt_env_set_subject(env, env->subject);
213 }
214
215 OptResortInit = true; /* trigger a redraw of the index */
216 return 0;
217}
void mutt_env_set_subject(struct Envelope *env, const char *subj)
Set both subject and real_subj to subj.
Definition: envelope.c:69
bool OptResortInit
(pseudo) used to force the next resort to be from scratch
Definition: globals.c:74
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:79
int msg_count
Total number of messages.
Definition: mailbox.h:88
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
+ 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 316 of file index.c.

317{
318 const int R_RESORT = (1 << 0);
319 const int R_RESORT_INIT = (1 << 1);
320 const int R_RESORT_SUB = (1 << 2);
321
322 static const struct Mapping sort_options[] = {
323 // clang-format off
324 { "duplicate_threads", R_RESORT | R_RESORT_INIT },
325 { "reply_regex", R_RESORT },
326 { "sort", R_RESORT },
327 { "sort_aux", R_RESORT | R_RESORT_SUB },
328 { "sort_re", R_RESORT | R_RESORT_INIT },
329 { "strict_threads", R_RESORT | R_RESORT_INIT },
330 { "thread_received", R_RESORT | R_RESORT_INIT },
331 { "use_threads", R_RESORT },
332 { NULL, 0 }
333 // clang-format on
334 };
335
336 int flags = mutt_map_get_value(option, sort_options);
337 if (flags < 0)
338 return false;
339
340 if (flags & R_RESORT)
341 OptNeedResort = true;
342 if (flags & R_RESORT_INIT)
343 OptResortInit = true;
344 if (flags & R_RESORT_SUB)
345 OptSortSubthreads = true;
346
347 return true;
348}
bool OptSortSubthreads
(pseudo) used when $sort_aux changes
Definition: globals.c:75
bool OptNeedResort
(pseudo) used to force a re-sort
Definition: globals.c:69
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 355 of file index.c.

356{
357 static const char *index_options[] = {
358 "ascii_chars", "crypt_chars",
359 "flag_chars", "from_chars",
360 "group_index_format", "hide_limited",
361 "hide_missing", "hide_thread_subject",
362 "hide_top_limited", "hide_top_missing",
363 "imap_headers", "index_format",
364 "mark_old", "mbox",
365 "narrow_tree", "postponed",
366 "real_name", "reverse_alias",
367 "reverse_name", "reverse_real_name",
368 "status_chars", "status_format",
369 "to_chars", "ts_enabled",
370 "ts_icon_format", "ts_status_format"
371 };
372
373 for (size_t i = 0; i < mutt_array_size(index_options); i++)
374 {
375 if (mutt_str_equal(option, index_options[i]))
376 return true;
377 }
378
379 return false;
380}
#define mutt_array_size(x)
Definition: memory.h:38
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:709
+ 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 651 of file index.c.

652{
654 win->recalc = index_recalc;
655 win->repaint = index_repaint;
656
657 struct Menu *menu = win->wdata;
658 menu->mdata = priv;
659 menu->mdata_free = NULL; // Menu doesn't own the data
660 priv->menu = menu;
661
672
673 return win;
674}
void mutt_color_observer_add(observer_t callback, void *global_data)
Add an observer.
Definition: notify.c:59
static int index_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t -.
Definition: index.c:260
static int index_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: index.c:385
static int index_index_observer(struct NotifyCallback *nc)
Notification that the Index has changed - Implements observer_t -.
Definition: index.c:449
static int index_menu_observer(struct NotifyCallback *nc)
Notification that the Menu has changed - Implements observer_t -.
Definition: index.c:474
static int index_score_observer(struct NotifyCallback *nc)
Notification that a 'score' command has occurred - Implements observer_t -.
Definition: index.c:496
static int index_global_observer(struct NotifyCallback *nc)
Notification that a Global event occurred - Implements observer_t -.
Definition: index.c:426
static int index_altern_observer(struct NotifyCallback *nc)
Notification that an 'alternates' command has occurred - Implements observer_t -.
Definition: index.c:222
static int index_subjrx_observer(struct NotifyCallback *nc)
Notification that a 'subjectrx' command has occurred - Implements observer_t -.
Definition: index.c:528
static int index_attach_observer(struct NotifyCallback *nc)
Notification that an 'attachments' command has occurred - Implements observer_t -.
Definition: index.c:241
static int index_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: index.c:547
static int index_recalc(struct MuttWindow *win)
Recalculate the Index display - Implements MuttWindow::recalc() -.
Definition: index.c:587
static int index_repaint(struct MuttWindow *win)
Repaint the Index display - Implements MuttWindow::repaint() -.
Definition: index.c:597
struct MuttWindow * menu_window_new(enum MenuType type, struct ConfigSubset *sub)
Create a new Menu Window.
Definition: window.c:140
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
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:57
@ NT_MENU
Menu has changed, MenuRedrawFlags.
Definition: notify_type.h:51
@ 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:54
@ 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
@ NT_SUBJRX
Subject Regex has changed, NotifySubjRx.
Definition: notify_type.h:55
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition: subset.h:52
struct IndexSharedData * shared
Shared Index data.
Definition: private_data.h:40
struct Menu * menu
Menu controlling the index.
Definition: private_data.h:41
struct Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition: shared_data.h:44
Definition: lib.h:79
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:86
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:161
struct Notify * notify
Notifications.
Definition: lib.h:145
void * mdata
Private data.
Definition: lib.h:147
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:187
void * wdata
Private data.
Definition: mutt_window.h:145
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:173
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct Notify * notify
Notifications handler.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
@ MENU_INDEX
Index panel (list of emails)
Definition: type.h:51
+ 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 683 of file index.c.

684{
685 if (!AllDialogsWindow)
686 return NULL;
687
688 struct MuttWindow *np = NULL;
689 TAILQ_FOREACH_REVERSE(np, &AllDialogsWindow->children, MuttWindowList, entries)
690 {
691 struct MuttWindow *win = window_find_child(np, WT_DLG_INDEX);
692 if (win)
693 {
694 struct IndexSharedData *shared = win->wdata;
695 return shared->mailbox_view;
696 }
697
699 if (win)
700 {
701 return postponed_get_mailbox_view(win);
702 }
703 }
704
705 return NULL;
706}
struct MuttWindow * AllDialogsWindow
Parent of all Dialogs.
Definition: dialog.c:80
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:533
@ WT_DLG_INDEX
Index Dialog, dlg_index()
Definition: mutt_window.h:86
@ WT_DLG_POSTPONED
Postponed Dialog, dlg_postponed()
Definition: mutt_window.h:89
struct MailboxView * postponed_get_mailbox_view(struct MuttWindow *dlg)
Extract the Mailbox from the Postponed Dialog.
Definition: functions.c:213
#define TAILQ_FOREACH_REVERSE(var, head, headname, field)
Definition: queue.h:745
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 MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
+ 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 715 of file index.c.

716{
718 if (mv)
719 return mv->mailbox;
720
721 return NULL;
722}
struct MailboxView * get_current_mailbox_view(void)
Get the current Mailbox view.
Definition: index.c:683
View of a Mailbox.
Definition: mview.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_current_menu()

struct Menu * get_current_menu ( void  )

Get the current Menu.

Return values
ptrCurrent Menu

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

Definition at line 731 of file index.c.

732{
733 if (!AllDialogsWindow)
734 return NULL;
735
736 struct MuttWindow *np = NULL;
737 TAILQ_FOREACH_REVERSE(np, &AllDialogsWindow->children, MuttWindowList, entries)
738 {
739 struct MuttWindow *dlg = window_find_child(np, WT_DLG_INDEX);
740 if (dlg)
741 {
742 struct MuttWindow *panel_index = window_find_child(dlg, WT_INDEX);
743 struct IndexPrivateData *priv = panel_index->wdata;
744 return priv->menu;
745 }
746 }
747
748 return NULL;
749}
@ WT_INDEX
A panel containing the Index Window.
Definition: mutt_window.h:97
Private state data for the Index.
Definition: private_data.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function: