NeoMutt  2025-12-11-435-g4ac674
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 "mutt_logging.h"
87#include "private_data.h"
88#include "recvattach.h"
89
91static const struct Mapping AttachmentHelp[] = {
92 // clang-format off
93 { N_("Exit"), OP_EXIT },
94 { N_("Save"), OP_ATTACHMENT_SAVE },
95 { N_("Pipe"), OP_PIPE },
96 { N_("Print"), OP_ATTACHMENT_PRINT },
97 { N_("Help"), OP_HELP },
98 { NULL, 0 },
99 // clang-format on
100};
101
108{
109 if (nc->event_type != NT_CONFIG)
110 return 0;
111 if (!nc->global_data || !nc->event_data)
112 return -1;
113
114 struct EventConfig *ev_c = nc->event_data;
115
116 if (!mutt_str_equal(ev_c->name, "attach_format") && !mutt_str_equal(ev_c->name, "message_format"))
117 return 0;
118
119 struct Menu *menu = nc->global_data;
121 mutt_debug(LL_DEBUG5, "config done, request WA_RECALC, MENU_REDRAW_FULL\n");
122
123 return 0;
124}
125
131static int attach_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
132{
133 struct AttachPrivateData *priv = menu->mdata;
134 struct AttachCtx *actx = priv->actx;
135
136 const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
137 if (c_arrow_cursor)
138 {
139 const char *const c_arrow_string = cs_subset_string(menu->sub, "arrow_string");
140 if (max_cols > 0)
141 max_cols -= (mutt_strwidth(c_arrow_string) + 1);
142 }
143
144 const struct Expando *c_attach_format = cs_subset_expando(NeoMutt->sub, "attach_format");
145 return expando_filter(c_attach_format, AttachRenderCallbacks,
146 (actx->idx[actx->v2r[line]]), MUTT_FORMAT_ARROWCURSOR,
147 max_cols, NeoMutt->env, buf);
148}
149
153static int attach_tag(struct Menu *menu, int sel, int act)
154{
155 struct AttachPrivateData *priv = menu->mdata;
156 struct AttachCtx *actx = priv->actx;
157
158 struct Body *cur = actx->idx[actx->v2r[sel]]->body;
159 bool ot = cur->tagged;
160
161 cur->tagged = ((act >= 0) ? act : !cur->tagged);
162 return cur->tagged - ot;
163}
164
173{
174 if (nc->event_type != NT_WINDOW)
175 return 0;
176 if (!nc->global_data || !nc->event_data)
177 return -1;
179 return 0;
180
181 struct MuttWindow *win_menu = nc->global_data;
182 struct EventWindow *ev_w = nc->event_data;
183 if (ev_w->win != win_menu)
184 return 0;
185
186 struct Menu *menu = win_menu->wdata;
187
190
191 mutt_debug(LL_DEBUG5, "window delete done\n");
192 return 0;
193}
194
208 struct Email *e, FILE *fp, bool attach_msg)
209{
210 if (!mv || !mv->mailbox || !e || !fp)
211 return;
212
213 struct Mailbox *m = mv->mailbox;
214
215 /* make sure we have parsed this message */
218
220 struct Menu *menu = sdw.menu;
222 menu->tag = attach_tag;
223
224 struct AttachCtx *actx = mutt_actx_new();
225 actx->email = e;
226 actx->fp_root = fp;
227 mutt_update_recvattach_menu(actx, menu, true);
228
230 priv->menu = menu;
231 priv->actx = actx;
232 priv->sub = sub;
233 priv->mailbox = m;
234 priv->attach_msg = attach_msg;
235 menu->mdata = priv;
237
238 // NT_COLOR is handled by the SimpleDialog
241
242 sbar_set_title(sdw.sbar, _("Attachments"));
243
244 struct MuttWindow *old_focus = window_set_focus(menu->win);
245 // ---------------------------------------------------------------------------
246 // Event Loop
247 int rc = 0;
248 int op = OP_NULL;
249 struct KeyEvent event = { 0, OP_NULL };
250 do
251 {
252 menu_tagging_dispatcher(menu->win, &event);
253 window_redraw(NULL);
254
256 op = event.op;
257 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
258 if (op < 0)
259 continue;
260 if (op == OP_NULL)
261 {
263 continue;
264 }
266
267 rc = attach_function_dispatcher(sdw.dlg, &event);
268 if (rc == FR_UNKNOWN)
269 rc = menu_function_dispatcher(menu->win, &event);
270 if (rc == FR_UNKNOWN)
271 rc = global_function_dispatcher(menu->win, &event);
272
273 if (rc == FR_CONTINUE)
274 {
275 event.op = priv->op;
276 }
277
278 } while (rc != FR_DONE);
279 // ---------------------------------------------------------------------------
280
281 window_set_focus(old_focus);
283}
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
struct MenuDefinition * MdAttach
Attach Menu Definition.
Definition functions.c:55
Attachment functions.
GUI display the mailboxes in a side panel.
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:94
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:444
@ 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:91
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:434
void km_error_key(const struct MenuDefinition *md)
Handle an unbound key sequence.
Definition get.c:285
#define GETCH_NO_FLAGS
No flags are set.
Definition get.h:34
int attach_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Attach function - Implements function_dispatcher_t -.
Definition functions.c:734
int menu_tagging_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition tagging.c:230
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:320
void dlg_attachment(struct ConfigSubset *sub, struct MailboxView *mv, struct Email *e, FILE *fp, bool attach_msg)
Show the attachments in a Menu -.
Definition dlg_attach.c:207
#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:131
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:153
static int attach_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition dlg_attach.c:107
static int attach_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition dlg_attach.c:172
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:135
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.
#define MENU_REDRAW_FULL
Redraw everything.
Definition lib.h:60
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition menu.c:188
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:662
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_ATTACHMENT
Attachment Dialog, dlg_attachment()
Definition mutt_window.h:78
@ NT_WINDOW_DELETE
Window is about to be deleted.
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition notify_type.h:57
@ 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.
#define MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition render.h:37
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition sbar.c:227
A set of attachments.
Definition attach.h:63
FILE * fp_root
Used by recvattach for updating.
Definition attach.h:65
struct Email * email
Used by recvattach for updating.
Definition attach.h:64
struct AttachPtr ** idx
Array of attachments.
Definition attach.h:67
short * v2r
Mapping from virtual to real attachment.
Definition attach.h:71
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:36
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:50
int op
Function opcode, e.g. OP_HELP.
Definition get.h:52
View of a Mailbox.
Definition mview.h:40
struct Mailbox * mailbox
Current Mailbox.
Definition mview.h:51
A mailbox.
Definition mailbox.h:78
Mapping between user-readable string and a constant.
Definition mapping.h:33
Definition lib.h:80
struct MuttWindow * win
Window holding the Menu.
Definition lib.h:88
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition lib.h:163
int(* tag)(struct Menu *menu, int sel, int act)
Definition lib.h:133
int(* make_entry)(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Definition lib.h:108
struct ConfigSubset * sub
Inherited config items.
Definition lib.h:89
void * mdata
Private data.
Definition lib.h:149
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:58
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