NeoMutt  2023-05-17-56-ga67199
Teaching an old dog new tricks
DOXYGEN
functions.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stddef.h>
31#include "mutt/lib.h"
32#include "config/lib.h"
33#include "core/lib.h"
34#include "gui/lib.h"
35#include "mutt.h"
36#include "functions.h"
37#include "menu/lib.h"
38#include "pattern/lib.h"
39#include "mview.h"
40#include "opcodes.h"
41#include "protos.h"
42
43struct Email;
44
48static int op_delete(struct PostponeData *pd, int op)
49{
50 struct Menu *menu = pd->menu;
51 struct MailboxView *mv = pd->mailbox_view;
52 struct Mailbox *m = mv->mailbox;
53
54 const int index = menu_get_index(menu);
55 /* should deleted draft messages be saved in the trash folder? */
56 mutt_set_flag(m, m->emails[index], MUTT_DELETE, (op == OP_DELETE), true);
58 const bool c_resolve = cs_subset_bool(NeoMutt->sub, "resolve");
59 if (c_resolve && (index < (menu->max - 1)))
60 {
61 menu_set_index(menu, index + 1);
62 if (index >= (menu->top + menu->page_len))
63 {
64 menu->top = index;
66 }
67 }
68 else
69 {
71 }
72
73 return FR_SUCCESS;
74}
75
79static int op_exit(struct PostponeData *pd, int op)
80{
81 pd->done = true;
82 return FR_SUCCESS;
83}
84
88static int op_generic_select_entry(struct PostponeData *pd, int op)
89{
90 int index = menu_get_index(pd->menu);
91 struct MailboxView *mv = pd->mailbox_view;
92 struct Mailbox *m = mv->mailbox;
93 pd->email = m->emails[index];
94 pd->done = true;
95 return FR_SUCCESS;
96}
97
101static int op_search(struct PostponeData *pd, int op)
102{
103 int index = menu_get_index(pd->menu);
104 struct MailboxView *mv = pd->mailbox_view;
105 index = mutt_search_command(mv, pd->menu, index, op);
106 if (index != -1)
107 menu_set_index(pd->menu, index);
108
109 return FR_SUCCESS;
110}
111
112// -----------------------------------------------------------------------------
113
117static const struct PostponeFunction PostponeFunctions[] = {
118 // clang-format off
119 { OP_DELETE, op_delete },
120 { OP_EXIT, op_exit },
121 { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
122 { OP_SEARCH, op_search },
123 { OP_SEARCH_NEXT, op_search },
124 { OP_SEARCH_OPPOSITE, op_search },
125 { OP_SEARCH_REVERSE, op_search },
126 { OP_UNDELETE, op_delete },
127 { 0, NULL },
128 // clang-format on
129};
130
135{
136 if (!win || !win->wdata)
137 return FR_UNKNOWN;
138
139 struct MuttWindow *dlg = dialog_find(win);
140 if (!dlg)
141 return FR_ERROR;
142
143 struct PostponeData *pd = dlg->wdata;
144
145 int rc = FR_UNKNOWN;
146 for (size_t i = 0; PostponeFunctions[i].op != OP_NULL; i++)
147 {
148 const struct PostponeFunction *fn = &PostponeFunctions[i];
149 if (fn->op == op)
150 {
151 rc = fn->function(pd, op);
152 break;
153 }
154 }
155
156 if (rc == FR_UNKNOWN) // Not our function
157 return rc;
158
159 const char *result = dispacher_get_retval_name(rc);
160 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
161
162 return rc;
163}
164
171{
172 if (!dlg)
173 return NULL;
174
175 struct PostponeData *pd = dlg->wdata;
176 if (!pd)
177 return NULL;
178
179 return pd->mailbox_view;
180}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
struct MuttWindow * dialog_find(struct MuttWindow *win)
Find the parent Dialog of a Window.
Definition: dialog.c:83
const char * dispacher_get_retval_name(int rv)
Get the name of a return value.
Definition: dispatcher.c:54
@ FR_SUCCESS
Valid function - successfully performed.
Definition: dispatcher.h:39
@ FR_UNKNOWN
Unknown function.
Definition: dispatcher.h:33
@ FR_ERROR
Valid function - error occurred.
Definition: dispatcher.h:38
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:52
int postpone_function_dispatcher(struct MuttWindow *win, int op)
Perform a Postpone function - Implements function_dispatcher_t -.
Definition: functions.c:134
#define mutt_debug(LEVEL,...)
Definition: logging2.h:87
static int op_delete(struct PostponeData *pd, int op)
Delete the current entry - Implements postpone_function_t -.
Definition: functions.c:48
static int op_search(struct PostponeData *pd, int op)
Search for a regular expression - Implements postpone_function_t -.
Definition: functions.c:101
static int op_exit(struct PostponeData *pd, int op)
Exit this menu - Implements postpone_function_t -.
Definition: functions.c:79
static int op_generic_select_entry(struct PostponeData *pd, int op)
Select the current entry - Implements postpone_function_t -.
Definition: functions.c:88
Convenience wrapper for the gui headers.
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
GUI present the user with a selectable list.
#define MENU_REDRAW_INDEX
Redraw the index.
Definition: lib.h:57
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:179
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:155
#define MENU_REDRAW_CURRENT
Redraw the current line of the menu.
Definition: lib.h:59
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:169
Convenience wrapper for the library headers.
Many unsorted constants and some structs.
@ MUTT_DELETE
Messages to be deleted.
Definition: mutt.h:83
View of a Mailbox.
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:48
All user-callable functions.
Match patterns to emails.
int mutt_search_command(struct MailboxView *mv, struct Menu *menu, int cur, int op)
Perform a search.
Definition: pattern.c:444
struct MailboxView * postponed_get_mailbox_view(struct MuttWindow *dlg)
Extract the Mailbox from the Postponed Dialog.
Definition: functions.c:170
static const struct PostponeFunction PostponeFunctions[]
All the NeoMutt functions that the Postpone supports.
Definition: functions.c:117
short PostCount
Number of postponed (draft) emails.
Definition: postpone.c:58
Prototypes for many functions.
Sidebar functions.
#define NONULL(x)
Definition: string2.h:37
The envelope/body of an email.
Definition: email.h:37
View of a Mailbox.
Definition: mview.h:39
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
int msg_deleted
Number of deleted messages.
Definition: mailbox.h:93
Definition: lib.h:70
int top
Entry that is the top of the current page.
Definition: lib.h:81
int max
Number of entries in the menu.
Definition: lib.h:72
int page_len
Number of entries per screen.
Definition: lib.h:75
void * wdata
Private data.
Definition: mutt_window.h:145
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
Data to pass to the Postpone Functions.
Definition: functions.h:34
struct Email * email
Selected Email.
Definition: functions.h:37
bool done
Should we close the Dialog?
Definition: functions.h:38
struct MailboxView * mailbox_view
Postponed Mailbox view.
Definition: functions.h:35
struct Menu * menu
Postponed Menu.
Definition: functions.h:36
A NeoMutt function.
Definition: functions.h:57
postpone_function_t function
Function to call.
Definition: functions.h:59
int op
Op code, e.g. OP_DELETE.
Definition: functions.h:58