NeoMutt  2025-12-11-980-ge38c27
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dlg_postpone.c
Go to the documentation of this file.
1
22
68
69#include "config.h"
70#include <stdbool.h>
71#include <stdio.h>
72#include "mutt/lib.h"
73#include "config/lib.h"
74#include "email/lib.h"
75#include "core/lib.h"
76#include "gui/lib.h"
77#include "mutt.h"
78#include "expando/lib.h"
79#include "index/lib.h"
80#include "key/lib.h"
81#include "menu/lib.h"
82#include "pattern/lib.h"
83#include "functions.h"
84#include "module_data.h"
85#include "mutt_logging.h"
86
88static const struct Mapping PostponeHelp[] = {
89 // clang-format off
90 { N_("Exit"), OP_EXIT },
91 { N_("Del"), OP_DELETE },
92 { N_("Undel"), OP_UNDELETE },
93 { N_("Tag"), OP_TAG },
94 { N_("Help"), OP_HELP },
95 { NULL, 0 },
96 // clang-format on
97};
98
104static int post_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
105{
106 struct PostponeData *pd = menu->mdata;
107 struct MailboxView *mv = pd->mailbox_view;
108 struct Mailbox *m = mv->mailbox;
109
110 const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
111 if (c_arrow_cursor)
112 {
113 const char *const c_arrow_string = cs_subset_string(menu->sub, "arrow_string");
114 if (max_cols > 0)
115 max_cols -= (mutt_strwidth(c_arrow_string) + 1);
116 }
117
118 const struct Expando *c_index_format = cs_subset_expando(NeoMutt->sub, "index_format");
119 return mutt_make_string(buf, max_cols, c_index_format, m, -1, m->emails[line],
121}
122
129{
130 if (nc->event_type != NT_CONFIG)
131 return 0;
132 if (!nc->global_data || !nc->event_data)
133 return -1;
134
135 struct EventConfig *ev_c = nc->event_data;
136
137 if (!mutt_str_equal(ev_c->name, "index_format") && !mutt_str_equal(ev_c->name, "sort"))
138 return 0;
139
140 struct Menu *menu = nc->global_data;
142 mutt_debug(LL_DEBUG5, "config done, request WA_RECALC, MENU_REDRAW_FULL\n");
143
144 return 0;
145}
146
155{
156 if (nc->event_type != NT_WINDOW)
157 return 0;
158 if (!nc->global_data || !nc->event_data)
159 return -1;
161 return 0;
162
163 struct MuttWindow *win_menu = nc->global_data;
164 struct EventWindow *ev_w = nc->event_data;
165 if (ev_w->win != win_menu)
166 return 0;
167
168 struct Menu *menu = win_menu->wdata;
169
172
173 mutt_debug(LL_DEBUG5, "window delete done\n");
174 return 0;
175}
176
180static int post_tag(struct Menu *menu, int sel, int act)
181{
182 struct PostponeData *pd = menu->mdata;
183 struct MailboxView *mv = pd->mailbox_view;
184 struct Mailbox *m = mv->mailbox;
185
186 const bool c_auto_tag = cs_subset_bool(NeoMutt->sub, "auto_tag");
187 if (menu->tag_prefix && !c_auto_tag)
188 {
189 for (size_t i = 0; i < m->msg_count; i++)
190 {
191 struct Email *e = m->emails[i];
192 if (!e)
193 break;
194 mutt_set_flag(m, e, MUTT_TAG, false, true);
195 }
197 return FR_SUCCESS;
198 }
199
200 int index = menu_get_index(menu);
201 struct Email *e = m->emails[index];
202 if (!e)
203 return FR_NO_ACTION;
204
205 mutt_set_flag(m, e, MUTT_TAG, !e->tagged, true);
206
207 return FR_SUCCESS;
208}
209
213static const struct AttrColor *post_color(struct Menu *menu, int line)
214{
215 struct PostponeData *pd = menu->mdata;
216 struct MailboxView *mv = pd->mailbox_view;
217 if (!mv || (line < 0))
218 return NULL;
219
220 struct Mailbox *m = mv->mailbox;
221 if (!m)
222 return NULL;
223
224 struct Email *e = mutt_get_virt_email(m, line);
225 if (!e)
226 return NULL;
227
228 if (e->attr_color)
229 return e->attr_color;
230
231 email_set_color(m, e);
232 return e->attr_color;
233}
234
245struct Email *dlg_postpone(struct Mailbox *m)
246{
248 ASSERT(mod_data);
249
252 // Required to number the emails
253 struct MailboxView *mv = mview_new(m, NeoMutt->notify);
254
255 struct Menu *menu = sdw.menu;
257 menu->color = post_color;
258 menu->tag = post_tag;
259 menu->max = m->msg_count;
260
261 struct PostponeData pd = { mv, menu, NULL, false, search_state_new() };
262 menu->mdata = &pd;
263 menu->mdata_free = NULL; // Menu doesn't own the data
264
265 // NT_COLOR is handled by the SimpleDialog
268
269 sbar_set_title(sdw.sbar, _("Postponed Messages"));
270
271 /* The postponed mailbox is setup to have sorting disabled, but the global
272 * `$sort` variable may indicate something different. Sorting has to be
273 * disabled while the postpone menu is being displayed. */
274 const enum EmailSortType c_sort = cs_subset_sort(NeoMutt->sub, "sort");
276
277 struct MuttWindow *old_focus = window_set_focus(menu->win);
278 // ---------------------------------------------------------------------------
279 // Event Loop
280 int op = OP_NULL;
281 struct KeyEvent event = { 0, OP_NULL };
282 do
283 {
284 menu_tagging_dispatcher(menu->win, &event);
285 window_redraw(NULL);
286
287 event = km_dokey(mod_data->menu_postpone, GETCH_NONE);
288 op = event.op;
289 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
290 if (op < 0)
291 continue;
292 if (op == OP_NULL)
293 {
294 km_error_key(mod_data->menu_postpone);
295 continue;
296 }
298
299 int rc = postpone_function_dispatcher(sdw.dlg, &event);
300
301 if (rc == FR_UNKNOWN)
302 rc = menu_function_dispatcher(menu->win, &event);
303 if (rc == FR_UNKNOWN)
304 rc = global_function_dispatcher(menu->win, &event);
305 } while (!pd.done);
306 // ---------------------------------------------------------------------------
307
308 mview_free(&mv);
309 cs_subset_str_native_set(NeoMutt->sub, "sort", c_sort, NULL);
311 window_set_focus(old_focus);
313
314 return pd.email;
315}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition helpers.c:291
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition helpers.c:266
const struct Expando * cs_subset_expando(const struct ConfigSubset *sub, const char *name)
Get an Expando config item by name.
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
size_t mutt_strwidth(const char *s)
Measure a string's width in screen cells.
Definition curs_lib.c:449
@ FR_SUCCESS
Valid function - successfully performed.
Definition dispatcher.h:40
@ FR_UNKNOWN
Unknown function.
Definition dispatcher.h:34
@ FR_NO_ACTION
Valid function - no action performed.
Definition dispatcher.h:38
void email_set_color(struct Mailbox *m, struct Email *e)
Select an Index colour for an Email.
Definition dlg_index.c:1431
int mutt_make_string(struct Buffer *buf, size_t max_cols, const struct Expando *exp, struct Mailbox *m, int inpgr, struct Email *e, MuttFormatFlags flags, const char *progress)
Create formatted strings using mailbox expandos.
Definition dlg_index.c:824
static const struct Mapping PostponeHelp[]
Help Bar for the Postponed email selection dialog.
Structs that make up an email.
EmailSortType
Methods for sorting Emails.
Definition sort.h:53
@ EMAIL_SORT_UNSORTED
Sort by the order the messages appear in the mailbox.
Definition sort.h:64
Parse Expando string.
void mutt_set_flag(struct Mailbox *m, struct Email *e, enum MessageType flag, bool bf, bool upd_mbox)
Set a flag on an email.
Definition flags.c:54
struct KeyEvent km_dokey(const struct MenuDefinition *md, GetChFlags flags)
Determine what a keypress should do.
Definition get.c:519
void km_error_key(const struct MenuDefinition *md)
Handle an unbound key sequence.
Definition get.c:328
@ GETCH_NONE
No flags are set.
Definition get.h:38
int postpone_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Postpone function - Implements function_dispatcher_t -.
Definition functions.c:285
int menu_tagging_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition tagging.c:239
int global_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Global function - Implements function_dispatcher_t -.
Definition global.c:193
int menu_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Menu function - Implements function_dispatcher_t -.
Definition functions.c:366
struct Email * dlg_postpone(struct Mailbox *m)
Create a Menu to select a postponed message -.
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
static const struct AttrColor * post_color(struct Menu *menu, int line)
Calculate the colour for a line of the postpone index - Implements Menu::color() -.
static int post_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Format an Email for the Menu - Implements Menu::make_entry() -.
static int post_tag(struct Menu *menu, int sel, int act)
Tag an email in the postpone menu - Implements Menu::tag() -.
static int postpone_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
static int postpone_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Convenience wrapper for the gui headers.
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition simple.c:169
struct SimpleDialogWindows simple_dialog_new(const struct MenuDefinition *md, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition simple.c:132
GUI manage the main index (list of emails)
Manage keymappings.
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:49
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
GUI present the user with a selectable list.
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition menu.c:177
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition menu.c:153
@ MENU_REDRAW_INDEX
Redraw the index.
Definition lib.h:61
@ MENU_REDRAW_FULL
Redraw everything.
Definition lib.h:64
@ MODULE_ID_POSTPONE
ModulePostpone, Postponed Emails
Definition module_api.h:89
Convenience wrapper for the library headers.
#define N_(a)
Definition message.h:32
#define _(a)
Definition message.h:28
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition notify.c:230
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
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:666
Many unsorted constants and some structs.
@ MUTT_TAG
Tagged messages.
Definition mutt.h:99
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
NeoMutt Logging.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
struct MuttWindow * window_set_focus(struct MuttWindow *win)
Set the Window focus.
@ WT_DLG_POSTPONE
Postpone Dialog, dlg_postpone()
Definition mutt_window.h:90
@ NT_WINDOW_DELETE
Window is about to be deleted.
struct Email * mutt_get_virt_email(struct Mailbox *m, int vnum)
Get a virtual Email.
Definition mview.c:378
void mview_free(struct MailboxView **ptr)
Free a MailboxView.
Definition mview.c:47
struct MailboxView * mview_new(struct Mailbox *m, struct Notify *parent)
Create a new MailboxView.
Definition mview.c:88
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:666
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition notify_type.h:58
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition notify_type.h:43
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition opcodes.c:48
Match patterns to emails.
Postponed Email Functions.
Postpone private Module data.
@ MUTT_FORMAT_INDEX
This is a main index entry.
Definition render.h:42
@ MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition render.h:41
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition sbar.c:227
void search_state_free(struct SearchState **ptr)
Free a SearchState.
struct SearchState * search_state_new(void)
Create a new SearchState.
#define ASSERT(COND)
Definition signal2.h:59
A curses colour and its attributes.
Definition attr.h:65
String manipulation buffer.
Definition buffer.h:36
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition subset.h:51
The envelope/body of an email.
Definition email.h:39
const struct AttrColor * attr_color
Color-pair to use when displaying in the index.
Definition email.h:112
int index
The absolute (unsorted) message number.
Definition email.h:110
bool tagged
Email is tagged.
Definition email.h:107
A config-change event.
Definition subset.h:70
const char * name
Name of config item that changed.
Definition subset.h:72
An Event that happened to a Window.
struct MuttWindow * win
Window that changed.
Parsed Expando trees.
Definition expando.h:41
An event such as a keypress.
Definition get.h:75
int op
Function opcode, e.g. OP_HELP.
Definition get.h:77
View of a Mailbox.
Definition mview.h:40
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
Mapping between user-readable string and a constant.
Definition mapping.h:33
Definition lib.h:86
struct MuttWindow * win
Window holding the Menu.
Definition lib.h:94
const struct AttrColor *(* color)(struct Menu *menu, int line)
Definition lib.h:151
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition lib.h:169
int(* tag)(struct Menu *menu, int sel, int act)
Definition lib.h:139
int(* make_entry)(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Definition lib.h:114
struct ConfigSubset * sub
Inherited config items.
Definition lib.h:95
void * mdata
Private data.
Definition lib.h:155
bool tag_prefix
User has pressed <tag-prefix>
Definition lib.h:92
int max
Number of entries in the menu.
Definition lib.h:88
void * wdata
Private data.
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
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
Data passed to a notification function.
Definition observer.h:34
void * event_data
Data from notify_send()
Definition observer.h:38
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition observer.h:36
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition observer.h:37
void * global_data
Data from notify_observer_add()
Definition observer.h:39
Data to pass to the Postpone Functions.
Definition functions.h:35
struct Email * email
Selected Email.
Definition functions.h:38
struct SearchState * search_state
State of the current search.
Definition functions.h:40
bool done
Should we close the Dialog?
Definition functions.h:39
struct MailboxView * mailbox_view
Postponed Mailbox view.
Definition functions.h:36
struct Menu * menu
Postponed Menu.
Definition functions.h:37
Postpone private Module data.
Definition module_data.h:32
struct MenuDefinition * menu_postpone
Postpone menu definition.
Definition module_data.h:34
Tuple for the results of simple_dialog_new()
Definition simple.h:35
struct MuttWindow * sbar
Simple Bar.
Definition simple.h:37
struct Menu * menu
Menu.
Definition simple.h:38
struct MuttWindow * dlg
Main Dialog Window.
Definition simple.h:36
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