NeoMutt  2024-12-12-14-g7b49f7
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dlg_attach.c
Go to the documentation of this file.
1
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 "key/lib.h"
81#include "menu/lib.h"
82#include "attach.h"
83#include "attachments.h"
84#include "functions.h"
85#include "hook.h"
86#include "mutt_logging.h"
87#include "mview.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_ATTACHMENT_SAVE },
96 { N_("Pipe"), OP_PIPE },
97 { N_("Print"), OP_ATTACHMENT_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, 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
209 struct Email *e, FILE *fp, bool attach_msg)
210{
211 if (!mv || !mv->mailbox || !e || !fp)
212 return;
213
214 struct Mailbox *m = mv->mailbox;
215
216 /* make sure we have parsed this message */
219
222 struct Menu *menu = sdw.menu;
224 menu->tag = attach_tag;
225
226 struct AttachCtx *actx = mutt_actx_new();
227 actx->email = e;
228 actx->fp_root = fp;
229 mutt_update_recvattach_menu(actx, menu, true);
230
232 priv->menu = menu;
233 priv->actx = actx;
234 priv->sub = sub;
235 priv->mailbox = m;
236 priv->attach_msg = attach_msg;
237 menu->mdata = priv;
239
240 // NT_COLOR is handled by the SimpleDialog
243
244 sbar_set_title(sdw.sbar, _("Attachments"));
245
246 struct MuttWindow *old_focus = window_set_focus(menu->win);
247 // ---------------------------------------------------------------------------
248 // Event Loop
249 int rc = 0;
250 int op = OP_NULL;
251 do
252 {
253 menu_tagging_dispatcher(menu->win, op);
254 window_redraw(NULL);
255
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, op);
268 if (rc == FR_UNKNOWN)
269 rc = menu_function_dispatcher(menu->win, op);
270 if (rc == FR_UNKNOWN)
271 rc = global_function_dispatcher(NULL, op);
272
273 if (rc == FR_CONTINUE)
274 {
275 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
const struct ExpandoRenderCallback AttachRenderCallbacks[]
Callbacks for Attachment Expandos.
Definition: expando.c:378
struct AttachPrivateData * attach_private_data_new(void)
Create new Attach Data.
Definition: private_data.c:50
Handling of email attachments.
void mutt_parse_mime_message(struct Email *e, FILE *fp)
Parse a MIME email.
Definition: attachments.c:596
Miscellaneous email parsing routines.
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.
Definition: config_type.c:357
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:443
@ FR_DONE
Exit the Dialog.
Definition: dispatcher.h:35
@ FR_UNKNOWN
Unknown function.
Definition: dispatcher.h:33
@ FR_CONTINUE
Remain in the Dialog.
Definition: dispatcher.h:34
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, struct Buffer *buf)
Render an Expando and run the result through a filter.
Definition: filter.c:138
Parse Expando string.
int km_dokey(enum MenuType mtype, GetChFlags flags)
Determine what a keypress should do.
Definition: get.c:464
void km_error_key(enum MenuType mtype)
Handle an unbound key sequence.
Definition: get.c:294
int menu_tagging_dispatcher(struct MuttWindow *win, int op)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition: tagging.c:230
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:172
int attach_function_dispatcher(struct MuttWindow *win, int op)
Perform a Attach function - Implements function_dispatcher_t -.
Definition: functions.c:711
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:318
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:208
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
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() -.
Definition: private_data.c:38
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:168
struct SimpleDialogWindows simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:132
void mutt_message_hook(struct Mailbox *m, struct Email *e, HookFlags type)
Perform a message hook.
Definition: hook.c:699
Parse and execute user-defined hooks.
#define MUTT_MESSAGE_HOOK
message-hook: run before displaying a message
Definition: hook.h:44
Manage keymappings.
#define GETCH_NO_FLAGS
No flags are set.
Definition: lib.h:51
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
GUI present the user with a selectable list.
#define MENU_REDRAW_FULL
Redraw everything.
Definition: lib.h:59
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:184
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:660
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
NeoMutt Logging.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:634
struct MuttWindow * window_set_focus(struct MuttWindow *win)
Set the Window focus.
Definition: mutt_window.c:684
@ WT_DLG_ATTACHMENT
Attachment Dialog, dlg_attachment()
Definition: mutt_window.h:79
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:229
View of a Mailbox.
@ 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
Private state data for the Pager.
void mutt_update_recvattach_menu(struct AttachCtx *actx, struct Menu *menu, bool init)
Update the Attachment Menu.
Definition: recvattach.c:1214
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
Sidebar functions.
Key value store.
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.
Definition: private_data.h:36
int op
Op returned from the Pager, e.g. OP_NEXT_ENTRY.
Definition: private_data.h:41
struct Menu * menu
Current Menu.
Definition: private_data.h:37
struct ConfigSubset * sub
Config subset.
Definition: private_data.h:39
struct AttachCtx * actx
List of all Attachments.
Definition: private_data.h:38
bool attach_msg
Are we in "attach message" mode?
Definition: private_data.h:42
struct Mailbox * mailbox
Current Mailbox.
Definition: private_data.h:40
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:47
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition: subset.h:52
The envelope/body of an email.
Definition: email.h:39
A config-change event.
Definition: subset.h:71
const char * name
Name of config item that changed.
Definition: subset.h:73
An Event that happened to a Window.
Definition: mutt_window.h:239
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:240
Parsed Expando trees.
Definition: expando.h:41
View of a Mailbox.
Definition: mview.h:40
struct Mailbox * mailbox
Current Mailbox.
Definition: mview.h:51
A mailbox.
Definition: mailbox.h:79
Mapping between user-readable string and a constant.
Definition: mapping.h:33
Definition: lib.h:79
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:86
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:161
int(* tag)(struct Menu *menu, int sel, int act)
Definition: lib.h:131
int(* make_entry)(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Definition: lib.h:106
struct ConfigSubset * sub
Inherited config items.
Definition: lib.h:87
void * mdata
Private data.
Definition: lib.h:147
void * wdata
Private data.
Definition: mutt_window.h:145
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
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
@ MENU_ATTACHMENT
Select an attachment.
Definition: type.h:38