NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dlg_attach.c
Go to the documentation of this file.
1
24
69
70#include "config.h"
71#include <stdbool.h>
72#include <stdio.h>
73#include "mutt/lib.h"
74#include "config/lib.h"
75#include "email/lib.h"
76#include "core/lib.h"
77#include "gui/lib.h"
78#include "lib.h"
79#include "expando/lib.h"
80#include "hooks/lib.h"
81#include "key/lib.h"
82#include "menu/lib.h"
83#include "attach.h"
84#include "commands.h"
85#include "functions.h"
86#include "module_data.h"
87#include "mutt_logging.h"
88#include "private_data.h"
89#include "recvattach.h"
90
92static const struct Mapping AttachmentHelp[] = {
93 // clang-format off
94 { N_("Exit"), OP_EXIT },
95 { N_("Save"), OP_ATTACH_SAVE },
96 { N_("Pipe"), OP_PIPE },
97 { N_("Print"), OP_ATTACH_PRINT },
98 { N_("Help"), OP_HELP },
99 { NULL, 0 },
100 // clang-format on
101};
102
109{
110 if (nc->event_type != NT_CONFIG)
111 return 0;
112 if (!nc->global_data || !nc->event_data)
113 return -1;
114
115 struct EventConfig *ev_c = nc->event_data;
116
117 if (!mutt_str_equal(ev_c->name, "attach_format") && !mutt_str_equal(ev_c->name, "message_format"))
118 return 0;
119
120 struct Menu *menu = nc->global_data;
122 mutt_debug(LL_DEBUG5, "config done, request WA_RECALC, MENU_REDRAW_FULL\n");
123
124 return 0;
125}
126
132static int attach_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
133{
134 struct AttachPrivateData *priv = menu->mdata;
135 struct AttachCtx *actx = priv->actx;
136
137 const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
138 if (c_arrow_cursor)
139 {
140 const char *const c_arrow_string = cs_subset_string(menu->sub, "arrow_string");
141 if (max_cols > 0)
142 max_cols -= (mutt_strwidth(c_arrow_string) + 1);
143 }
144
145 const struct Expando *c_attach_format = cs_subset_expando(NeoMutt->sub, "attach_format");
146 return expando_filter(c_attach_format, AttachRenderCallbacks,
147 (actx->idx[actx->v2r[line]]), MUTT_FORMAT_ARROWCURSOR,
148 max_cols, NeoMutt->env, buf);
149}
150
154static int attach_tag(struct Menu *menu, int sel, int act)
155{
156 struct AttachPrivateData *priv = menu->mdata;
157 struct AttachCtx *actx = priv->actx;
158
159 struct Body *cur = actx->idx[actx->v2r[sel]]->body;
160 bool ot = cur->tagged;
161
162 cur->tagged = ((act >= 0) ? act : !cur->tagged);
163 return cur->tagged - ot;
164}
165
174{
175 if (nc->event_type != NT_WINDOW)
176 return 0;
177 if (!nc->global_data || !nc->event_data)
178 return -1;
180 return 0;
181
182 struct MuttWindow *win_menu = nc->global_data;
183 struct EventWindow *ev_w = nc->event_data;
184 if (ev_w->win != win_menu)
185 return 0;
186
187 struct Menu *menu = win_menu->wdata;
188
191
192 mutt_debug(LL_DEBUG5, "window delete done\n");
193 return 0;
194}
195
208void dlg_attach(struct ConfigSubset *sub, struct MailboxView *mv,
209 struct Email *e, FILE *fp, bool attach_msg)
210{
212 ASSERT(mod_data);
213
214 if (!mv || !mv->mailbox || !e || !fp)
215 return;
216
217 struct Mailbox *m = mv->mailbox;
218
219 /* make sure we have parsed this message */
222
225 struct Menu *menu = sdw.menu;
227 menu->tag = attach_tag;
228
229 struct AttachCtx *actx = mutt_actx_new();
230 actx->email = e;
231 actx->fp_root = fp;
232 mutt_update_recvattach_menu(actx, menu, true);
233
235 priv->menu = menu;
236 priv->actx = actx;
237 priv->sub = sub;
238 priv->mailbox = m;
239 priv->attach_msg = attach_msg;
240 menu->mdata = priv;
242
243 // NT_COLOR is handled by the SimpleDialog
246
247 sbar_set_title(sdw.sbar, _("Attachments"));
248
249 struct MuttWindow *old_focus = window_set_focus(menu->win);
250 // ---------------------------------------------------------------------------
251 // Event Loop
252 int rc = 0;
253 int op = OP_NULL;
254 struct KeyEvent event = { 0, OP_NULL };
255 do
256 {
257 menu_tagging_dispatcher(menu->win, &event);
258 window_redraw(NULL);
259
260 event = km_dokey(mod_data->menu_attach, GETCH_NONE);
261 op = event.op;
262 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
263 if (op < 0)
264 continue;
265 if (op == OP_NULL)
266 {
267 km_error_key(mod_data->menu_attach);
268 continue;
269 }
271
272 rc = attach_function_dispatcher(sdw.dlg, &event);
273 if (rc == FR_UNKNOWN)
274 rc = menu_function_dispatcher(menu->win, &event);
275 if (rc == FR_UNKNOWN)
276 rc = global_function_dispatcher(menu->win, &event);
277
278 if (rc == FR_CONTINUE)
279 {
280 event.op = priv->op;
281 }
282
283 } while (rc != FR_DONE);
284 // ---------------------------------------------------------------------------
285
286 window_set_focus(old_focus);
288}
struct AttachCtx * mutt_actx_new(void)
Create a new Attachment Context.
Definition attach.c:189
void mutt_parse_mime_message(struct Email *e, FILE *fp)
Parse a MIME email.
Definition commands.c:627
Handle the attachments command.
const struct ExpandoRenderCallback AttachRenderCallbacks[]
Callbacks for Attachment Expandos.
Definition expando.c:375
Attachment functions.
GUI display the mailboxes in a side panel.
Attach private Module data.
struct AttachPrivateData * attach_private_data_new(void)
Create new Attach Data.
Private state data for Attachments.
Handling of email attachments.
@ CMD_MESSAGE_HOOK
:message-hook
Definition command.h:97
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
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:446
@ FR_DONE
Exit the Dialog.
Definition dispatcher.h:36
@ FR_UNKNOWN
Unknown function.
Definition dispatcher.h:34
@ FR_CONTINUE
Remain in the Dialog.
Definition dispatcher.h:35
static const struct Mapping AttachmentHelp[]
Help Bar for the Attachment selection dialog.
Definition dlg_attach.c:92
Structs that make up an email.
int expando_filter(const struct Expando *exp, const struct ExpandoRenderCallback *erc, void *data, MuttFormatFlags flags, int max_cols, char **env_list, struct Buffer *buf)
Render an Expando and run the result through a filter.
Definition filter.c:139
Parse Expando string.
struct KeyEvent km_dokey(const struct MenuDefinition *md, GetChFlags flags)
Determine what a keypress should do.
Definition get.c:518
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 attach_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Attach function - Implements function_dispatcher_t -.
Definition functions.c:829
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:182
int menu_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Menu function - Implements function_dispatcher_t -.
Definition functions.c:366
void dlg_attach(struct ConfigSubset *sub, struct MailboxView *mv, struct Email *e, FILE *fp, bool attach_msg)
Show the attachments in a Menu -.
Definition dlg_attach.c:208
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
static int attach_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Format an Attachment for the Menu - Implements Menu::make_entry() -.
Definition dlg_attach.c:132
void attach_private_data_free(struct Menu *menu, void **ptr)
Free the Attach Data - Implements Menu::mdata_free() -.
static int attach_tag(struct Menu *menu, int sel, int act)
Tag an attachment - Implements Menu::tag() -.
Definition dlg_attach.c:154
static int attach_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition dlg_attach.c:108
static int attach_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition dlg_attach.c:173
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
void exec_message_hook(struct Mailbox *m, struct Email *e, enum CommandId id)
Perform a message hook.
Definition exec.c:137
Hook Commands.
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:179
@ MENU_REDRAW_FULL
Redraw everything.
Definition lib.h:64
@ MODULE_ID_ATTACH
ModuleAttach, Attachments
Definition module_api.h:49
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:665
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_ATTACH
Attach Dialog, dlg_attach()
Definition mutt_window.h:78
@ NT_WINDOW_DELETE
Window is about to be deleted.
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
@ 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
void mutt_update_recvattach_menu(struct AttachCtx *actx, struct Menu *menu, bool init)
Update the Attachment Menu.
Routines for managing attachments.
@ 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
#define ASSERT(COND)
Definition signal2.h:59
A set of attachments.
Definition attach.h:65
FILE * fp_root
Used by recvattach for updating.
Definition attach.h:67
struct Email * email
Used by recvattach for updating.
Definition attach.h:66
struct AttachPtr ** idx
Array of attachments.
Definition attach.h:69
short * v2r
Mapping from virtual to real attachment.
Definition attach.h:73
Attach private Module data.
Definition module_data.h:32
struct MenuDefinition * menu_attach
Attach menu definition.
Definition module_data.h:40
Private state data for Attachments.
int op
Op returned from the Pager, e.g. OP_NEXT_ENTRY.
struct Menu * menu
Current Menu.
struct ConfigSubset * sub
Config subset.
struct AttachCtx * actx
List of all Attachments.
bool attach_msg
Are we in "attach message" mode?
struct Mailbox * mailbox
Current Mailbox.
struct Body * body
Attachment.
Definition attach.h:37
The body of an email.
Definition body.h:36
bool tagged
This attachment is tagged.
Definition body.h:90
String manipulation buffer.
Definition buffer.h:36
A set of inherited config items.
Definition subset.h:46
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition subset.h:51
The envelope/body of an email.
Definition email.h:39
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
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
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
void * wdata
Private data.
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Container for Accounts, Notifications.
Definition neomutt.h:41
char ** env
Private copy of the environment variables.
Definition neomutt.h:57
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
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