NeoMutt
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 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
  • 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 93 of file index.c.

94{
95 static bool warned = false;
96 if (!warned)
97 {
98 mutt_warning(_("Changing threaded display should prefer $use_threads over $sort"));
99 warned = true;
100 mutt_sleep(0);
101 }
102}
#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:1428
+ 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 110 of file index.c.

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

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

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

195{
196 if (!mv || !mv->mailbox)
197 return 0;
198
199 struct Mailbox *m = mv->mailbox;
200
201 regmatch_t pmatch[1];
202
203 const struct Regex *c_reply_regex = cs_subset_regex(NeoMutt->sub, "reply_regex");
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 if (mutt_regex_capture(c_reply_regex, env->subject, 1, pmatch))
214 {
215 env->real_subj = env->subject + pmatch[0].rm_eo;
216 if (env->real_subj[0] == '\0')
217 env->real_subj = NULL;
218 continue;
219 }
220
221 env->real_subj = env->subject;
222 }
223
224 OptResortInit = true; /* trigger a redraw of the index */
225 return 0;
226}
const struct Regex * cs_subset_regex(const struct ConfigSubset *sub, const char *name)
Get a regex config item by name.
Definition: helpers.c:218
bool OptResortInit
(pseudo) used to force the next resort to be from scratch
Definition: globals.c:81
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:619
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
struct Mailbox * mailbox
Current Mailbox.
Definition: mview.h:50
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
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
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)

Parameters
privPrivate Index data
Return values
ptrNew Window

Definition at line 598 of file index.c.

599{
601 win->recalc = index_recalc;
602 win->repaint = index_repaint;
603
604 struct Menu *menu = win->wdata;
605 menu->mdata = priv;
606 menu->mdata_free = NULL; // Menu doesn't own the data
607 priv->menu = menu;
608
619
620 return win;
621}
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:269
static int index_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: index.c:323
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:231
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:250
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:534
static int index_repaint(struct MuttWindow *win)
Repaint the Index display - Implements MuttWindow::repaint() -.
Definition: index.c:544
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:41
struct Menu * menu
Menu controlling the index.
Definition: private_data.h:42
struct Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition: shared_data.h:44
Definition: lib.h:70
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:77
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:151
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: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
struct Notify * notify
Notifications handler.
Definition: neomutt.h:42
@ 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 630 of file index.c.

631{
632 if (!AllDialogsWindow)
633 return NULL;
634
635 struct MuttWindow *np = NULL;
636 TAILQ_FOREACH_REVERSE(np, &AllDialogsWindow->children, MuttWindowList, entries)
637 {
638 struct MuttWindow *win = window_find_child(np, WT_DLG_INDEX);
639 if (win)
640 {
641 struct IndexSharedData *shared = win->wdata;
642 return shared->mailbox_view;
643 }
644
646 if (win)
647 {
648 return postponed_get_mailbox_view(win);
649 }
650 }
651
652 return NULL;
653}
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:212
#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 662 of file index.c.

663{
665 if (mv)
666 return mv->mailbox;
667
668 return NULL;
669}
struct MailboxView * get_current_mailbox_view(void)
Get the current Mailbox view.
Definition: index.c:630
View of a Mailbox.
Definition: mview.h:39
+ 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 678 of file index.c.

679{
680 if (!AllDialogsWindow)
681 return NULL;
682
683 struct MuttWindow *np = NULL;
684 TAILQ_FOREACH_REVERSE(np, &AllDialogsWindow->children, MuttWindowList, entries)
685 {
686 struct MuttWindow *dlg = window_find_child(np, WT_DLG_INDEX);
687 if (dlg)
688 {
689 struct MuttWindow *panel_index = window_find_child(dlg, WT_INDEX);
690 struct IndexPrivateData *priv = panel_index->wdata;
691 return priv->menu;
692 }
693 }
694
695 return NULL;
696}
@ 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: