NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dlg_compose.c
Go to the documentation of this file.
1
65#include "config.h"
66#include <stdbool.h>
67#include <stdint.h>
68#include <stdio.h>
69#include "private.h"
70#include "mutt/lib.h"
71#include "config/lib.h"
72#include "email/lib.h"
73#include "core/lib.h"
74#include "gui/lib.h"
75#include "lib.h"
76#include "attach/lib.h"
77#include "envelope/lib.h"
78#include "index/lib.h"
79#include "key/lib.h"
80#include "menu/lib.h"
81#include "ncrypt/lib.h"
82#include "attach_data.h"
83#include "cbar.h"
84#include "functions.h"
85#include "globals.h"
86#include "hook.h"
87#include "mutt_logging.h"
88#include "shared_data.h"
89
91static const struct Mapping ComposeHelp[] = {
92 // clang-format off
93 { N_("Send"), OP_COMPOSE_SEND_MESSAGE },
94 { N_("Abort"), OP_EXIT },
95 /* L10N: compose menu help line entry */
96 { N_("To"), OP_ENVELOPE_EDIT_TO },
97 /* L10N: compose menu help line entry */
98 { N_("CC"), OP_ENVELOPE_EDIT_CC },
99 /* L10N: compose menu help line entry */
100 { N_("Subj"), OP_ENVELOPE_EDIT_SUBJECT },
101 { N_("Attach file"), OP_ATTACHMENT_ATTACH_FILE },
102 { N_("Descrip"), OP_ATTACHMENT_EDIT_DESCRIPTION },
103 { N_("Help"), OP_HELP },
104 { NULL, 0 },
105 // clang-format on
106};
107
109static const struct Mapping ComposeNewsHelp[] = {
110 // clang-format off
111 { N_("Send"), OP_COMPOSE_SEND_MESSAGE },
112 { N_("Abort"), OP_EXIT },
113 { N_("Newsgroups"), OP_ENVELOPE_EDIT_NEWSGROUPS },
114 { N_("Subj"), OP_ENVELOPE_EDIT_SUBJECT },
115 { N_("Attach file"), OP_ATTACHMENT_ATTACH_FILE },
116 { N_("Descrip"), OP_ATTACHMENT_EDIT_DESCRIPTION },
117 { N_("Help"), OP_HELP },
118 { NULL, 0 },
119 // clang-format on
120};
121
126{
127 if (nc->event_type != NT_CONFIG)
128 return 0;
129 if (!nc->global_data || !nc->event_data)
130 return -1;
131
132 struct EventConfig *ev_c = nc->event_data;
133 struct MuttWindow *dlg = nc->global_data;
134
135 if (!mutt_str_equal(ev_c->name, "status_on_top"))
136 return 0;
137
139 mutt_debug(LL_DEBUG5, "config done, request WA_REFLOW\n");
140 return 0;
141}
142
147{
148 if (nc->event_type != NT_ENVELOPE)
149 return 0;
150 if (!nc->global_data || !nc->event_data)
151 return -1;
152
153 struct ComposeSharedData *shared = nc->global_data;
154
156 shared->fcc_set = true;
157
159 return 0;
160}
161
166{
167 if (nc->event_type != NT_WINDOW)
168 return 0;
169 if (!nc->global_data || !nc->event_data)
170 return -1;
172 return 0;
173
174 struct MuttWindow *dlg = nc->global_data;
175 struct EventWindow *ev_w = nc->event_data;
176 if (ev_w->win != dlg)
177 return 0;
178
179 struct ComposeSharedData *shared = dlg->wdata;
180
184 mutt_debug(LL_DEBUG5, "window delete done\n");
185
186 return 0;
187}
188
196static void gen_attach_list(struct AttachCtx *actx, struct Body *b, int parent_type, int level)
197{
198 for (; b; b = b->next)
199 {
200 struct AttachPtr *ap = mutt_aptr_new();
201 mutt_actx_add_attach(actx, ap);
202 ap->body = b;
203 b->aptr = ap;
205 ap->level = level;
206 if ((b->type == TYPE_MULTIPART) && b->parts &&
208 {
209 gen_attach_list(actx, b->parts, b->type, level + 1);
210 }
211 }
212}
213
220void update_menu(struct AttachCtx *actx, struct Menu *menu, bool init)
221{
222 if (init)
223 {
224 gen_attach_list(actx, actx->email->body, -1, 0);
225 mutt_attach_init(actx);
226
227 struct ComposeAttachData *adata = menu->mdata;
228 adata->actx = actx;
229 }
230
232
233 menu->max = actx->vcount;
234 if (menu->max)
235 {
236 int index = menu_get_index(menu);
237 if (index >= menu->max)
239 }
240 else
241 {
243 }
244
246}
247
255static struct MuttWindow *compose_dlg_init(struct ConfigSubset *sub,
256 struct Email *e, struct Buffer *fcc)
257{
259 shared->sub = sub;
260 shared->email = e;
261
265 dlg->wdata = shared;
267
268 struct MuttWindow *win_env = env_window_new(e, fcc, sub);
269 struct MuttWindow *win_attach = attach_new(dlg, shared);
270 struct MuttWindow *win_cbar = cbar_new(shared);
271 struct MuttWindow *win_abar = sbar_new();
272 sbar_set_title(win_abar, _("-- Attachments"));
273
274 const bool c_status_on_top = cs_subset_bool(sub, "status_on_top");
275 if (c_status_on_top)
276 {
277 mutt_window_add_child(dlg, win_cbar);
278 mutt_window_add_child(dlg, win_env);
279 mutt_window_add_child(dlg, win_abar);
280 mutt_window_add_child(dlg, win_attach);
281 }
282 else
283 {
284 mutt_window_add_child(dlg, win_env);
285 mutt_window_add_child(dlg, win_abar);
286 mutt_window_add_child(dlg, win_attach);
287 mutt_window_add_child(dlg, win_cbar);
288 }
289
290 dlg->help_data = ComposeHelp;
291 dlg->help_menu = MENU_COMPOSE;
292
293 return dlg;
294}
295
308int dlg_compose(struct Email *e, struct Buffer *fcc, uint8_t flags, struct ConfigSubset *sub)
309{
310 struct MuttWindow *dlg = compose_dlg_init(sub, e, fcc);
311 struct ComposeSharedData *shared = dlg->wdata;
312 shared->mailbox = get_current_mailbox();
313 shared->email = e;
314 shared->sub = sub;
315 shared->fcc = fcc;
316 shared->fcc_set = false;
317 shared->flags = flags;
318 shared->rc = -1;
319
323
324 if (OptNewsSend)
326 else
327 dlg->help_data = ComposeHelp;
328 dlg->help_menu = MENU_COMPOSE;
329
330 struct Menu *menu = shared->adata->menu;
331 update_menu(shared->adata->actx, menu, true);
333
334 struct MuttWindow *win_env = window_find_child(dlg, WT_CUSTOM);
335
336 dialog_push(dlg);
337 struct MuttWindow *old_focus = window_set_focus(menu->win);
338 // ---------------------------------------------------------------------------
339 // Event Loop
340 int rc = 0;
341 int op = OP_NULL;
342 do
343 {
344 OptNews = false; /* for any case */
345 menu_tagging_dispatcher(menu->win, op);
346 window_redraw(NULL);
347
349 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
350 if (op < 0)
351 continue;
352 if (op == OP_NULL)
353 {
355 continue;
356 }
358
359 rc = compose_function_dispatcher(dlg, op);
360 if (rc == FR_UNKNOWN)
361 rc = env_function_dispatcher(win_env, op);
362 if (rc == FR_UNKNOWN)
363 rc = menu_function_dispatcher(menu->win, op);
364 if (rc == FR_UNKNOWN)
365 rc = global_function_dispatcher(NULL, op);
366 } while (rc != FR_DONE);
367 // ---------------------------------------------------------------------------
368
369#ifdef USE_AUTOCRYPT
370 /* This is a fail-safe to make sure the bit isn't somehow turned
371 * on. The user could have disabled the option after setting SEC_AUTOCRYPT,
372 * or perhaps resuming or replying to an autocrypt message. */
373 const bool c_autocrypt = cs_subset_bool(sub, "autocrypt");
374 if (!c_autocrypt)
375 e->security &= ~SEC_AUTOCRYPT;
376#endif
377
378 if (shared->adata->actx->idxlen)
379 e->body = shared->adata->actx->idx[0]->body;
380 else
381 e->body = NULL;
382
383 rc = shared->rc;
384
385 window_set_focus(old_focus);
386 dialog_pop();
387 mutt_window_free(&dlg);
388
389 return rc;
390}
void mutt_actx_add_attach(struct AttachCtx *actx, struct AttachPtr *attach)
Add an Attachment to an Attachment Context.
Definition: attach.c:65
struct AttachPtr * mutt_aptr_new(void)
Create a new Attachment Pointer.
Definition: attach.c:40
GUI display the mailboxes in a side panel.
Compose Attach Data.
struct MuttWindow * cbar_new(struct ComposeSharedData *shared)
Create the Compose Bar (status)
Definition: cbar.c:298
Compose Bar.
struct MuttWindow * attach_new(struct MuttWindow *parent, struct ComposeSharedData *shared)
Create the Attachments Menu.
Definition: attach.c:242
struct ComposeSharedData * compose_shared_data_new(void)
Free the compose shared data.
Definition: shared_data.c:48
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
SecurityFlags mutt_is_multipart_encrypted(struct Body *b)
Does the message have encrypted parts?
Definition: crypt.c:443
void dialog_push(struct MuttWindow *dlg)
Display a Window to the user.
Definition: dialog.c:109
void dialog_pop(void)
Hide a Window from the user.
Definition: dialog.c:142
@ FR_DONE
Exit the Dialog.
Definition: dispatcher.h:35
@ FR_UNKNOWN
Unknown function.
Definition: dispatcher.h:33
static void gen_attach_list(struct AttachCtx *actx, struct Body *b, int parent_type, int level)
Generate the attachment list for the compose screen.
Definition: dlg_compose.c:196
void update_menu(struct AttachCtx *actx, struct Menu *menu, bool init)
Redraw the compose window.
Definition: dlg_compose.c:220
static const struct Mapping ComposeHelp[]
Help Bar for the Compose dialog.
Definition: dlg_compose.c:91
static const struct Mapping ComposeNewsHelp[]
Help Bar for the News Compose dialog.
Definition: dlg_compose.c:109
static struct MuttWindow * compose_dlg_init(struct ConfigSubset *sub, struct Email *e, struct Buffer *fcc)
Allocate the Windows for Compose.
Definition: dlg_compose.c:255
Structs that make up an email.
@ NT_EMAIL_CHANGE
Email has changed.
Definition: email.h:186
Envelope-editing Window.
struct MuttWindow * env_window_new(struct Email *e, struct Buffer *fcc, struct ConfigSubset *sub)
Create the Envelope Window.
Definition: window.c:944
@ NT_ENVELOPE_FCC
"Fcc:" header has changed
Definition: envelope.h:139
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
bool OptNews
(pseudo) used to change reader mode
Definition: globals.c:67
bool OptNewsSend
(pseudo) used to change behavior when posting
Definition: globals.c:68
int menu_tagging_dispatcher(struct MuttWindow *win, int op)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition: tagging.c:230
int env_function_dispatcher(struct MuttWindow *win, int op)
Perform an Envelope function - Implements function_dispatcher_t -.
Definition: functions.c:530
int compose_function_dispatcher(struct MuttWindow *win, int op)
Perform a Compose function - Implements function_dispatcher_t -.
Definition: functions.c:2136
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:172
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:318
int dlg_compose(struct Email *e, struct Buffer *fcc, uint8_t flags, struct ConfigSubset *sub)
Allow the user to edit the message envelope -.
Definition: dlg_compose.c:308
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
static int compose_email_observer(struct NotifyCallback *nc)
Notification that an Email has changed - Implements observer_t -.
Definition: dlg_compose.c:146
static int compose_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: dlg_compose.c:125
static int compose_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: dlg_compose.c:165
void compose_shared_data_free(struct MuttWindow *win, void **ptr)
Free the compose shared data - Implements MuttWindow::wdata_free() -.
Definition: shared_data.c:36
Convenience wrapper for the gui headers.
void mutt_message_hook(struct Mailbox *m, struct Email *e, HookFlags type)
Perform a message hook.
Definition: hook.c:700
Parse and execute user-defined hooks.
#define MUTT_SEND2_HOOK
send2-hook: when changing fields in the compose menu
Definition: hook.h:48
GUI manage the main index (list of emails)
Data shared between Index, Pager and Sidebar.
struct Mailbox * get_current_mailbox(void)
Get the current Mailbox.
Definition: index.c:715
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_INDEX
Redraw the index.
Definition: lib.h:56
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:184
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:160
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:174
@ TYPE_MULTIPART
Type: 'multipart/*'.
Definition: mime.h:37
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 notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:173
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:633
bool window_status_on_top(struct MuttWindow *panel, struct ConfigSubset *sub)
Organise windows according to config variable.
Definition: mutt_window.c:783
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:201
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
Definition: mutt_window.c:445
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
Definition: mutt_window.c:181
struct MuttWindow * window_set_focus(struct MuttWindow *win)
Set the Window focus.
Definition: mutt_window.c:683
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:532
@ WT_CUSTOM
Window with a custom drawing function.
Definition: mutt_window.h:94
@ WT_DLG_COMPOSE
Compose Dialog, dlg_compose()
Definition: mutt_window.h:82
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition: mutt_window.h:38
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:228
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:52
@ MUTT_WIN_SIZE_MAXIMISE
Window wants as much space as possible.
Definition: mutt_window.h:48
API for encryption/signing of emails.
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:90
#define WithCrypto
Definition: lib.h:116
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:57
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
@ NT_EMAIL
Email has changed, NotifyEmail, EventEmail.
Definition: notify_type.h:44
@ NT_ENVELOPE
Envelope has changed, NotifyEnvelope.
Definition: notify_type.h:45
@ NT_ALL
Register for all notifications.
Definition: notify_type.h:35
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:48
void mutt_attach_init(struct AttachCtx *actx)
Create a new Attachment context.
Definition: recvattach.c:1189
void mutt_update_tree(struct AttachCtx *actx)
Refresh the list of attachments.
Definition: recvattach.c:122
struct MuttWindow * sbar_new(void)
Add the Simple Bar (status)
Definition: sbar.c:203
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:227
Sidebar functions.
GUI display the mailboxes in a side panel.
Key value store.
A set of attachments.
Definition: attach.h:65
short vcount
The number of virtual attachments.
Definition: attach.h:74
struct Email * email
Used by recvattach for updating.
Definition: attach.h:66
struct AttachPtr ** idx
Array of attachments.
Definition: attach.h:69
short idxlen
Number of attachmentes.
Definition: attach.h:70
An email to which things will be attached.
Definition: attach.h:37
struct Body * body
Attachment.
Definition: attach.h:38
int level
Nesting depth of attachment.
Definition: attach.h:42
int parent_type
Type of parent attachment, e.g. TYPE_MULTIPART.
Definition: attach.h:40
The body of an email.
Definition: body.h:36
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:73
struct AttachPtr * aptr
Menu information, used in recvattach.c.
Definition: body.h:75
struct Body * next
next attachment in the list
Definition: body.h:72
unsigned int type
content-type primary type, ContentType
Definition: body.h:40
String manipulation buffer.
Definition: buffer.h:36
Data to fill the Compose Attach Window.
Definition: attach_data.h:33
struct Menu * menu
Menu displaying the attachments.
Definition: attach_data.h:35
struct AttachCtx * actx
Set of attachments.
Definition: attach_data.h:34
Shared Compose Data.
Definition: shared_data.h:35
struct ConfigSubset * sub
Config set to use.
Definition: shared_data.h:36
struct Mailbox * mailbox
Current Mailbox.
Definition: shared_data.h:37
int flags
Flags, e.g. MUTT_COMPOSE_NOFREEHEADER.
Definition: shared_data.h:42
bool fcc_set
User has edited the Fcc: field.
Definition: shared_data.h:43
int rc
Return code to leave compose.
Definition: shared_data.h:44
struct ComposeAttachData * adata
Attachments.
Definition: shared_data.h:39
struct Email * email
Email being composed.
Definition: shared_data.h:38
struct Buffer * fcc
Buffer to save FCC.
Definition: shared_data.h:41
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
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
Definition: email.h:43
struct Body * body
List of MIME parts.
Definition: email.h:69
struct Notify * notify
Notifications: NotifyEmail, EventEmail.
Definition: email.h:73
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:238
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:239
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
Private data.
Definition: lib.h:147
int max
Number of entries in the menu.
Definition: lib.h:81
const struct Mapping * help_data
Data for the Help Bar.
Definition: mutt_window.h:141
void * wdata
Private data.
Definition: mutt_window.h:144
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:137
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:158
int help_menu
Menu for key bindings, e.g. MENU_PAGER.
Definition: mutt_window.h:140
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
@ MENU_COMPOSE
Compose an email.
Definition: type.h:42