NeoMutt  2022-04-29-215-gc12b98
Teaching an old dog new tricks
DOXYGEN
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 "alternates.h"
#include "mutt_thread.h"
#include "muttlib.h"
#include "mview.h"
#include "options.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. More...
 
static int config_sort (const struct ConfigSubset *sub)
 React to changes to "sort". More...
 
static int config_use_threads (const struct ConfigSubset *sub)
 React to changes to "use_threads". More...
 
void index_adjust_sort_threads (const struct ConfigSubset *sub)
 Adjust use_threads/sort/sort_aux. More...
 
static int config_reply_regex (struct Mailbox *m)
 React to changes to $reply_regex. More...
 
static int index_altern_observer (struct NotifyCallback *nc)
 Notification that an 'alternates' command has occurred - Implements observer_t -. More...
 
static int index_attach_observer (struct NotifyCallback *nc)
 Notification that an 'attachments' command has occurred - Implements observer_t -. More...
 
static int index_color_observer (struct NotifyCallback *nc)
 Notification that a Color has changed - Implements observer_t -. More...
 
static int index_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t -. More...
 
static int index_global_observer (struct NotifyCallback *nc)
 Notification that a Global event occurred - Implements observer_t -. More...
 
static int index_index_observer (struct NotifyCallback *nc)
 Notification that the Index has changed - Implements observer_t -. More...
 
static int index_menu_observer (struct NotifyCallback *nc)
 Notification that the Menu has changed - Implements observer_t -. More...
 
static int index_score_observer (struct NotifyCallback *nc)
 Notification that a 'score' command has occurred - Implements observer_t -. More...
 
static int index_subjrx_observer (struct NotifyCallback *nc)
 Notification that a 'subjectrx' command has occurred - Implements observer_t -. More...
 
static int index_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t -. More...
 
static int index_recalc (struct MuttWindow *win)
 Recalculate the Index display - Implements MuttWindow::recalc() -. More...
 
static int index_repaint (struct MuttWindow *win)
 Repaint the Index display - Implements MuttWindow::repaint() -. More...
 
struct MuttWindowindex_window_new (struct IndexPrivateData *priv)
 Create a new Index Window (list of Emails) More...
 
struct Mailboxget_current_mailbox (void)
 Get the current Mailbox. More...
 
struct Menuget_current_menu (void)
 Get the current Menu. More...
 

Detailed Description

Index Window.

Authors
  • Richard Russon

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

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

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

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

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

React to changes to $reply_regex.

Parameters
mMailbox
Return values
0Successfully handled
-1Error

Definition at line 193 of file index.c.

194{
195 if (!m)
196 return 0;
197
198 regmatch_t pmatch[1];
199
200 for (int i = 0; i < m->msg_count; i++)
201 {
202 struct Email *e = m->emails[i];
203 if (!e)
204 break;
205 struct Envelope *env = e->env;
206 if (!env || !env->subject)
207 continue;
208
209 const struct Regex *c_reply_regex = cs_subset_regex(NeoMutt->sub, "reply_regex");
210 if (mutt_regex_capture(c_reply_regex, env->subject, 1, pmatch))
211 {
212 env->real_subj = env->subject + pmatch[0].rm_eo;
213 if (env->real_subj[0] == '\0')
214 env->real_subj = NULL;
215 continue;
216 }
217
218 env->real_subj = env->subject;
219 }
220
221 OptResortInit = true; /* trigger a redraw of the index */
222 return 0;
223}
const struct Regex * cs_subset_regex(const struct ConfigSubset *sub, const char *name)
Get a regex config item by name.
Definition: helpers.c:243
bool mutt_regex_capture(const struct Regex *regex, const char *str, size_t nmatch, regmatch_t matches[])
Match a regex against a string, with provided options.
Definition: regex.c:614
bool OptResortInit
(pseudo) used to force the next resort to be from scratch
Definition: options.h:56
The envelope/body of an email.
Definition: email.h:37
struct Envelope * env
Envelope information.
Definition: email.h:66
The header of an Email.
Definition: envelope.h:57
char * subject
Email's subject.
Definition: envelope.h:70
char * real_subj
Offset of the real subject.
Definition: envelope.h:71
int msg_count
Total number of messages.
Definition: mailbox.h:88
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
Cached regular expression.
Definition: regex3.h:89
+ 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)

Return values
ptrNew Window

Definition at line 592 of file index.c.

593{
595 win->recalc = index_recalc;
596 win->repaint = index_repaint;
597
598 struct Menu *menu = win->wdata;
599 menu->mdata = priv;
600 menu->mdata_free = NULL; // Menu doesn't own the data
601 priv->menu = menu;
602
613
614 return win;
615}
static int index_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t -.
Definition: index.c:266
static int index_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: index.c:326
static int index_index_observer(struct NotifyCallback *nc)
Notification that the Index has changed - Implements observer_t -.
Definition: index.c:396
static int index_menu_observer(struct NotifyCallback *nc)
Notification that the Menu has changed - Implements observer_t -.
Definition: index.c:421
static int index_score_observer(struct NotifyCallback *nc)
Notification that a 'score' command has occurred - Implements observer_t -.
Definition: index.c:443
static int index_global_observer(struct NotifyCallback *nc)
Notification that a Global event occurred - Implements observer_t -.
Definition: index.c:373
static int index_altern_observer(struct NotifyCallback *nc)
Notification that an 'alternates' command has occurred - Implements observer_t -.
Definition: index.c:228
static int index_subjrx_observer(struct NotifyCallback *nc)
Notification that a 'subjectrx' command has occurred - Implements observer_t -.
Definition: index.c:475
static int index_attach_observer(struct NotifyCallback *nc)
Notification that an 'attachments' command has occurred - Implements observer_t -.
Definition: index.c:247
static int index_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: index.c:494
static int index_recalc(struct MuttWindow *win)
Recalculate the Index display - Implements MuttWindow::recalc() -.
Definition: index.c:533
static int index_repaint(struct MuttWindow *win)
Repaint the Index display - Implements MuttWindow::repaint() -.
Definition: index.c:543
struct MuttWindow * menu_window_new(enum MenuType type, struct ConfigSubset *sub)
Create a new Menu Window.
Definition: window.c:136
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:189
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:55
@ 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_COLOR
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:41
@ NT_SCORE
Email scoring has changed.
Definition: notify_type.h:53
@ 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:54
struct IndexSharedData * shared
Shared Index data.
Definition: private_data.h:42
struct Menu * menu
Menu controlling the index.
Definition: private_data.h:43
struct Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition: shared_data.h:44
Definition: lib.h:69
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:152
struct Notify * notify
Notifications.
Definition: lib.h:135
void * mdata
Private data.
Definition: lib.h:137
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:182
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:171
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
@ MENU_INDEX
Index panel (list of emails)
Definition: type.h:50
+ 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 624 of file index.c.

625{
626 if (!AllDialogsWindow)
627 return NULL;
628
629 struct MuttWindow *np = NULL;
630 TAILQ_FOREACH_REVERSE(np, &AllDialogsWindow->children, MuttWindowList, entries)
631 {
632 struct MuttWindow *win = window_find_child(np, WT_DLG_INDEX);
633 if (win)
634 {
635 struct IndexSharedData *shared = win->wdata;
636 return shared->mailbox;
637 }
638 }
639
640 return NULL;
641}
struct MuttWindow * AllDialogsWindow
Parent of all Dialogs.
Definition: dialog.c:74
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:522
@ WT_DLG_INDEX
Index Dialog, index_pager_init()
Definition: mutt_window.h:86
#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 Mailbox * mailbox
Current Mailbox.
Definition: shared_data.h:41
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_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 650 of file index.c.

651{
652 if (!AllDialogsWindow)
653 return NULL;
654
655 struct MuttWindow *np = NULL;
656 TAILQ_FOREACH_REVERSE(np, &AllDialogsWindow->children, MuttWindowList, entries)
657 {
658 struct MuttWindow *dlg = window_find_child(np, WT_DLG_INDEX);
659 if (dlg)
660 {
661 struct MuttWindow *panel_index = window_find_child(dlg, WT_INDEX);
662 struct IndexPrivateData *priv = panel_index->wdata;
663 return priv->menu;
664 }
665 }
666
667 return NULL;
668}
@ 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: