NeoMutt  2022-04-29-215-gc12b98
Teaching an old dog new tricks
compose.c File Reference

Compose Email Dialog. More...

#include "config.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "attach/lib.h"
#include "envelope/lib.h"
#include "index/lib.h"
#include "menu/lib.h"
#include "ncrypt/lib.h"
#include "attach_data.h"
#include "cbar.h"
#include "functions.h"
#include "hook.h"
#include "keymap.h"
#include "mutt_logging.h"
#include "opcodes.h"
#include "options.h"
#include "shared_data.h"
+ Include dependency graph for compose.c:

Go to the source code of this file.


static int compose_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t -. More...
static int compose_email_observer (struct NotifyCallback *nc)
 Notification that an Email has changed - Implements observer_t -. More...
static int compose_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t -. More...
static void gen_attach_list (struct AttachCtx *actx, struct Body *m, int parent_type, int level)
 Generate the attachment list for the compose screen. More...
void update_menu (struct AttachCtx *actx, struct Menu *menu, bool init)
 Redraw the compose window. More...
static struct MuttWindowcompose_dlg_init (struct ConfigSubset *sub, struct Email *e, struct Buffer *fcc)
 Allocate the Windows for Compose. More...
int mutt_compose_menu (struct Email *e, struct Buffer *fcc, uint8_t flags, struct ConfigSubset *sub)
 Allow the user to edit the message envelope. More...


static const struct Mapping ComposeHelp []
 Help Bar for the Compose dialog. More...
static const struct Mapping ComposeNewsHelp []
 Help Bar for the News Compose dialog. More...

Detailed Description

Compose Email Dialog.

  • Michael R. Elkins
  • g10 Code GmbH
  • Pietro Cerutti
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see

Definition in file compose.c.

Function Documentation

◆ gen_attach_list()

static void gen_attach_list ( struct AttachCtx actx,
struct Body m,
int  parent_type,
int  level 

Generate the attachment list for the compose screen.

actxAttachment context
parent_typeAttachment type, e.g TYPE_MULTIPART
levelNesting depth of attachment

Definition at line 198 of file compose.c.

200 for (; m; m = m->next)
201 {
202 struct AttachPtr *ap = mutt_aptr_new();
203 mutt_actx_add_attach(actx, ap);
204 ap->body = m;
205 m->aptr = ap;
207 ap->level = level;
208 if ((m->type == TYPE_MULTIPART) && m->parts &&
210 {
211 gen_attach_list(actx, m->parts, m->type, level + 1);
212 }
213 }
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
static void gen_attach_list(struct AttachCtx *actx, struct Body *m, int parent_type, int level)
Generate the attachment list for the compose screen.
Definition: compose.c:198
SecurityFlags mutt_is_multipart_encrypted(struct Body *b)
Does the message have encrypted parts?
Definition: crypt.c:439
Type: 'multipart/*'.
Definition: mime.h:37
Use PGP to encrypt/sign.
Definition: lib.h:90
#define WithCrypto
Definition: lib.h:116
An email to which things will be attached.
Definition: attach.h:35
struct Body * body
Definition: attach.h:36
int level
Nesting depth of attachment.
Definition: attach.h:40
int parent_type
Type of parent attachment, e.g. TYPE_MULTIPART.
Definition: attach.h:38
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:72
struct AttachPtr * aptr
Menu information, used in recvattach.c.
Definition: body.h:74
struct Body * next
next attachment in the list
Definition: body.h:71
unsigned int type
content-type primary type, ContentType
Definition: body.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update_menu()

void update_menu ( struct AttachCtx actx,
struct Menu menu,
bool  init 

Redraw the compose window.

actxAttachment context
menuCurrent menu
initIf true, initialise the attachment list

Definition at line 222 of file compose.c.

224 if (init)
225 {
226 gen_attach_list(actx, actx->email->body, -1, 0);
227 mutt_attach_init(actx);
229 struct ComposeAttachData *adata = menu->mdata;
230 adata->actx = actx;
231 }
235 menu->max = actx->vcount;
236 if (menu->max)
237 {
238 int index = menu_get_index(menu);
239 if (index >= menu->max)
241 }
242 else
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:178
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:154
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:168
void mutt_attach_init(struct AttachCtx *actx)
Create a new Attachment context.
Definition: recvattach.c:1167
void mutt_update_tree(struct AttachCtx *actx)
Refresh the list of attachments.
Definition: recvattach.c:112
short vcount
The number of virtual attachments.
Definition: attach.h:60
struct Email * email
Used by recvattach for updating.
Definition: attach.h:52
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
struct Body * body
List of MIME parts.
Definition: email.h:67
void * mdata
Private data.
Definition: lib.h:137
int max
Number of entries in the menu.
Definition: lib.h:71
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compose_dlg_init()

static struct MuttWindow * compose_dlg_init ( struct ConfigSubset sub,
struct Email e,
struct Buffer fcc 

Allocate the Windows for Compose.

fccBuffer to save FCC
Return values
ptrDialog containing nested Windows

Definition at line 255 of file compose.c.

259 shared->sub = sub;
260 shared->email = e;
265 dlg->wdata = shared;
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"));
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 }
290 dlg->help_data = ComposeHelp;
291 dlg->help_menu = MENU_COMPOSE;
292 dlg->focus = win_attach;
294 return dlg;
struct MuttWindow * cbar_new(struct ComposeSharedData *shared)
Create the Compose Bar (status)
Definition: cbar.c:304
struct MuttWindow * attach_new(struct MuttWindow *parent, struct ComposeSharedData *shared)
Create the Attachments Menu.
Definition: attach.c:236
struct ComposeSharedData * compose_shared_data_new(void)
Free the compose shared data.
Definition: shared_data.c:47
static const struct Mapping ComposeHelp[]
Help Bar for the Compose dialog.
Definition: compose.c:94
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
struct MuttWindow * env_window_new(struct Email *e, struct Buffer *fcc, struct ConfigSubset *sub)
Create the Envelope Window.
Definition: window.c:969
void compose_shared_data_free(struct MuttWindow *win, void **ptr)
Create the compose shared data - Implements MuttWindow::wdata_free() -.
Definition: shared_data.c:36
#define _(a)
Definition: message.h:28
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
Definition: mutt_window.c:439
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
Compose Dialog, mutt_compose_menu()
Definition: mutt_window.h:82
Window uses all available vertical space.
Definition: mutt_window.h:38
Use as much space as possible.
Definition: mutt_window.h:52
Window wants as much space as possible.
Definition: mutt_window.h:48
struct MuttWindow * sbar_new(void)
Add the Simple Bar (status)
Definition: sbar.c:200
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:224
Shared Compose Data.
Definition: shared_data.h:33
struct ConfigSubset * sub
Config set to use.
Definition: shared_data.h:34
struct Email * email
Email being composed.
Definition: shared_data.h:36
const struct Mapping * help_data
Data for the Help Bar.
Definition: mutt_window.h:142
struct MuttWindow * focus
Focused Window.
Definition: mutt_window.h:140
void * wdata
Private data.
Definition: mutt_window.h:145
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:160
int help_menu
Menu for key bindings, e.g. MENU_PAGER.
Definition: mutt_window.h:141
Compose an email.
Definition: type.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_compose_menu()

int mutt_compose_menu ( struct Email e,
struct Buffer fcc,
uint8_t  flags,
struct ConfigSubset sub 

Allow the user to edit the message envelope.

eEmail to fill
fccBuffer to save FCC
Return values
1Message should be postponed
0Normal exit
-1Abort message

Definition at line 307 of file compose.c.

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;
323 dialog_push(dlg);
325#ifdef USE_NNTP
326 if (OptNewsSend)
328 else
330 dlg->help_data = ComposeHelp;
331 dlg->help_menu = MENU_COMPOSE;
333 struct Menu *menu = shared->adata->menu;
334 update_menu(shared->adata->actx, menu, true);
337 struct MuttWindow *win_env = window_find_child(dlg, WT_CUSTOM);
339 // ---------------------------------------------------------------------------
340 // Event Loop
341 int rc = 0;
342 int op = OP_NULL;
343 do
344 {
345#ifdef USE_NNTP
346 OptNews = false; /* for any case */
348 menu_tagging_dispatcher(menu->win, op);
349 window_redraw(NULL);
352 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
353 if (op < 0)
354 continue;
355 if (op == OP_NULL)
356 {
358 continue;
359 }
362 rc = compose_function_dispatcher(dlg, op);
363 if (rc == FR_UNKNOWN)
364 rc = env_function_dispatcher(win_env, op);
365 if (rc == FR_UNKNOWN)
366 rc = menu_function_dispatcher(menu->win, op);
367 if (rc == FR_UNKNOWN)
368 rc = global_function_dispatcher(NULL, op);
369 } while (rc != FR_DONE);
370 // ---------------------------------------------------------------------------
373 /* This is a fail-safe to make sure the bit isn't somehow turned
374 * on. The user could have disabled the option after setting SEC_AUTOCRYPT,
375 * or perhaps resuming or replying to an autocrypt message. */
376 const bool c_autocrypt = cs_subset_bool(sub, "autocrypt");
377 if (!c_autocrypt)
378 e->security &= ~SEC_AUTOCRYPT;
381 if (shared->adata->actx->idxlen)
382 e->body = shared->adata->actx->idx[0]->body;
383 else
384 e->body = NULL;
386 rc = shared->rc;
388 dialog_pop();
389 mutt_window_free(&dlg);
391 return rc;
void update_menu(struct AttachCtx *actx, struct Menu *menu, bool init)
Redraw the compose window.
Definition: compose.c:222
static const struct Mapping ComposeNewsHelp[]
Help Bar for the News Compose dialog.
Definition: compose.c:113
static struct MuttWindow * compose_dlg_init(struct ConfigSubset *sub, struct Email *e, struct Buffer *fcc)
Allocate the Windows for Compose.
Definition: compose.c:255
void dialog_push(struct MuttWindow *dlg)
Display a Window to the user.
Definition: dialog.c:103
void dialog_pop(void)
Hide a Window from the user.
Definition: dialog.c:137
Exit the Dialog.
Definition: dispatcher.h:35
Unknown function.
Definition: dispatcher.h:33
Email has changed.
Definition: email.h:150
int menu_tagging_dispatcher(struct MuttWindow *win, int op)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition: tagging.c:223
int env_function_dispatcher(struct MuttWindow *win, int op)
Perform an Envelope function - Implements function_dispatcher_t -.
Definition: functions.c:559
int compose_function_dispatcher(struct MuttWindow *win, int op)
Perform a Compose function - Implements function_dispatcher_t -.
Definition: functions.c:1970
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:164
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:320
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
static int compose_email_observer(struct NotifyCallback *nc)
Notification that an Email has changed - Implements observer_t -.
Definition: compose.c:151
static int compose_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: compose.c:130
static int compose_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: compose.c:170
struct Mailbox * get_current_mailbox(void)
Get the current Mailbox.
Definition: index.c:624
int km_dokey(enum MenuType mtype)
Determine what a keypress should do.
Definition: keymap.c:795
void km_error_key(enum MenuType mtype)
Handle an unbound key sequence.
Definition: keymap.c:1061
Log at debug level 1.
Definition: logging.h:40
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:189
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:171
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:604
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:201
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:522
Window with a custom drawing function.
Definition: mutt_window.h:95
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:55
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
Email has changed, NotifyEmail, EventEmail.
Definition: notify_type.h:44
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:46
bool OptNews
(pseudo) used to change reader mode
Definition: options.h:50
bool OptNewsSend
(pseudo) used to change behavior when posting
Definition: options.h:51
struct AttachPtr ** idx
Array of attachments.
Definition: attach.h:55
short idxlen
Number of attachmentes.
Definition: attach.h:56
struct Mailbox * mailbox
Current Mailbox.
Definition: shared_data.h:35
int flags
Definition: shared_data.h:41
bool fcc_set
User has edited the Fcc: field.
Definition: shared_data.h:42
int rc
Return code to leave compose.
Definition: shared_data.h:43
struct ComposeAttachData * adata
Definition: shared_data.h:37
struct Buffer * fcc
Buffer to save FCC.
Definition: shared_data.h:40
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
Definition: email.h:41
struct Notify * notify
Notifications: NotifyEmail, EventEmail.
Definition: email.h:71
Definition: lib.h:69
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ ComposeHelp

const struct Mapping ComposeHelp[]
Initial value:
= {
{ N_("Abort"), OP_EXIT },
{ N_("Attach file"), OP_ATTACHMENT_ATTACH_FILE },
{ N_("Help"), OP_HELP },
{ NULL, 0 },
#define N_(a)
Definition: message.h:32

Help Bar for the Compose dialog.

Definition at line 94 of file compose.c.

◆ ComposeNewsHelp

const struct Mapping ComposeNewsHelp[]
Initial value:
= {
{ N_("Abort"), OP_EXIT },
{ N_("Attach file"), OP_ATTACHMENT_ATTACH_FILE },
{ N_("Help"), OP_HELP },
{ NULL, 0 },

Help Bar for the News Compose dialog.

Definition at line 113 of file compose.c.