NeoMutt  2023-03-22
Teaching an old dog new tricks
Go to the documentation of this file.
58#include "config.h"
59#include <stddef.h>
60#include <stdbool.h>
61#include <stdint.h>
62#include "private.h"
63#include "mutt/lib.h"
64#include "config/lib.h"
65#include "email/lib.h"
66#include "core/lib.h"
67#include "gui/lib.h"
68#include "attach/lib.h"
69#include "convert/lib.h"
70#include "menu/lib.h"
71#include "attach_data.h"
72#include "format_flags.h"
73#include "muttlib.h"
74#include "shared_data.h"
85unsigned long cum_attachs_size(struct ConfigSubset *sub, struct ComposeAttachData *adata)
87 if (!adata || !adata->actx)
88 return 0;
90 size_t s = 0;
91 struct Content *info = NULL;
92 struct Body *b = NULL;
93 struct AttachCtx *actx = adata->actx;
94 struct AttachPtr **idx = actx->idx;
96 for (unsigned short i = 0; i < actx->idxlen; i++)
97 {
98 b = idx[i]->body;
100 if (!b->content)
101 b->content = mutt_get_content_info(b->filename, b, sub);
103 info = b->content;
104 if (info)
105 {
106 switch (b->encoding)
107 {
109 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
110 break;
111 case ENC_BASE64:
112 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
113 break;
114 default:
115 s += info->lobin + info->hibin + info->ascii + info->crlf;
116 break;
117 }
118 }
119 }
121 return s;
129 if (nc->event_type != NT_EMAIL)
130 return 0;
131 if (!nc->global_data)
132 return -1;
134 return 0;
136 struct MuttWindow *win_attach = nc->global_data;
138 win_attach->actions |= WA_RECALC;
139 mutt_debug(LL_DEBUG5, "compose done, request WA_RECALC\n");
141 return 0;
149 if (nc->event_type != NT_CONFIG)
150 return 0;
151 if (!nc->global_data || !nc->event_data)
152 return -1;
154 struct EventConfig *ev_c = nc->event_data;
155 if (!mutt_str_equal(ev_c->name, "attach_format"))
156 return 0;
158 struct MuttWindow *win_attach = nc->global_data;
159 win_attach->actions |= WA_RECALC;
160 mutt_debug(LL_DEBUG5, "config, request WA_RECALC\n");
162 return 0;
170 if (nc->event_type != NT_WINDOW)
171 return 0;
172 if (!nc->global_data || !nc->event_data)
173 return -1;
175 struct MuttWindow *win_attach = nc->global_data;
176 struct EventWindow *ev_w = nc->event_data;
177 if (ev_w->win != win_attach)
178 return 0;
181 {
182 win_attach->actions |= WA_RECALC;
183 mutt_debug(LL_DEBUG5, "window state done, request WA_RECALC\n");
184 }
185 else if (nc->event_subtype == NT_WINDOW_DELETE)
186 {
187 struct Menu *menu = win_attach->wdata;
188 struct ComposeAttachData *adata = menu->mdata;
189 struct AttachCtx *actx = adata->actx;
192 notify_observer_remove(win_attach->notify, attach_window_observer, win_attach);
193 mutt_debug(LL_DEBUG5, "window delete done\n");
194 }
196 return 0;
202static int compose_attach_tag(struct Menu *menu, int sel, int act)
204 struct ComposeAttachData *adata = menu->mdata;
205 struct AttachCtx *actx = adata->actx;
206 struct Body *cur = actx->idx[actx->v2r[sel]]->body;
207 bool ot = cur->tagged;
209 cur->tagged = ((act >= 0) ? act : !cur->tagged);
210 return cur->tagged - ot;
218static void compose_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
220 struct ComposeAttachData *adata = menu->mdata;
221 struct AttachCtx *actx = adata->actx;
222 struct ComposeSharedData *shared = menu->win->parent->wdata;
223 struct ConfigSubset *sub = shared->sub;
225 const char *const c_attach_format = cs_subset_string(sub, "attach_format");
226 mutt_expando_format(buf, buflen, 0, menu->win->state.cols, NONULL(c_attach_format),
227 attach_format_str, (intptr_t) (actx->idx[actx->v2r[line]]),
238 struct MuttWindow *win_attach = menu_window_new(MENU_COMPOSE, NeoMutt->sub);
240 struct ComposeAttachData *adata = attach_data_new(shared->email);
242 shared->adata = adata;
244 // NT_COLOR is handled by the Menu Window
249 struct Menu *menu = win_attach->wdata;
250 menu->page_len = win_attach->state.rows;
251 menu->win = win_attach;
254 menu->tag = compose_attach_tag;
255 menu->mdata = adata;
257 adata->menu = menu;
259 return win_attach;
GUI display the mailboxes in a side panel.
struct ComposeAttachData * attach_data_new(struct Email *e)
Create new Compose Attach Data.
Definition: attach_data.c:50
Compose Attach Data.
unsigned long cum_attachs_size(struct ConfigSubset *sub, struct ComposeAttachData *adata)
Cumulative Attachments Size.
Definition: attach.c:85
struct MuttWindow * attach_new(struct MuttWindow *parent, struct ComposeSharedData *shared)
Create the Attachments Menu.
Definition: attach.c:236
static int attach_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: attach.c:168
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
Convenience wrapper for the config headers.
struct Content * mutt_get_content_info(const char *fname, struct Body *b, struct ConfigSubset *sub)
Analyze file to determine MIME encoding to use.
Definition: content_info.c:180
Conversion between different character encodings.
Convenience wrapper for the core headers.
Structs that make up an email.
Email's Attachments have changed.
Definition: email.h:152
Flags to control mutt_expando_format()
Reserve space for arrow_cursor.
Definition: format_flags.h:35
Used by attach_format_str.
Definition: format_flags.h:34
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t callback, intptr_t data, MuttFormatFlags flags)
Expand expandos (x) in a string -.
Definition: muttlib.c:778
const char * attach_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
Format a string for the attachment menu - Implements format_t -.
Definition: dlg_attach.c:152
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
static void compose_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
Format a menu item for the attachment list - Implements Menu::make_entry() -.
Definition: attach.c:218
void attach_data_free(struct Menu *menu, void **ptr)
Free the Compose Attach Data - Implements Menu::mdata_free() -.
Definition: attach_data.c:37
static int compose_attach_tag(struct Menu *menu, int sel, int act)
Tag an attachment - Implements Menu::tag() -.
Definition: attach.c:202
static int attach_email_observer(struct NotifyCallback *nc)
Notification that the Email has changed - Implements observer_t -.
Definition: attach.c:127
static int attach_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: dlg_attach.c:110
Convenience wrapper for the gui headers.
Data shared between Index, Pager and Sidebar.
Log at debug level 5.
Definition: logging.h:44
GUI present the user with a selectable list.
struct MuttWindow * menu_window_new(enum MenuType type, struct ConfigSubset *sub)
Create a new Menu Window.
Definition: window.c:136
Base-64 encoded text.
Definition: mime.h:52
Quoted-printable text.
Definition: mime.h:51
Convenience wrapper for the library headers.
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition: notify.c:228
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 mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:807
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:206
Window is about to be deleted.
Definition: mutt_window.h:205
Some miscellaneous functions.
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
GUI display the mailboxes in a side panel.
#define NONULL(x)
Definition: string2.h:37
A set of attachments.
Definition: attach.h:51
struct Email * email
Used by recvattach for updating.
Definition: attach.h:52
struct AttachPtr ** idx
Array of attachments.
Definition: attach.h:55
short idxlen
Number of attachmentes.
Definition: attach.h:56
short * v2r
Mapping from virtual to real attachment.
Definition: attach.h:59
An email to which things will be attached.
Definition: attach.h:35
struct Body * body
Definition: attach.h:36
The body of an email.
Definition: body.h:36
struct Content * content
Detailed info about the content of the attachment.
Definition: body.h:69
bool tagged
This attachment is tagged.
Definition: body.h:89
unsigned int encoding
content-transfer-encoding, ContentEncoding
Definition: body.h:41
char * filename
When sending a message, this is the file to which this structure refers.
Definition: body.h:58
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:33
struct ConfigSubset * sub
Config set to use.
Definition: shared_data.h:34
struct ComposeAttachData * adata
Definition: shared_data.h:37
struct Email * email
Email being composed.
Definition: shared_data.h:36
A set of inherited config items.
Definition: subset.h:47
Info about an attachment.
Definition: content.h:35
long crlf
\r and \n characters
Definition: content.h:39
long hibin
8-bit characters
Definition: content.h:36
long ascii
Number of ascii chars.
Definition: content.h:40
long lobin
Unprintable 7-bit chars (eg., control chars)
Definition: content.h:37
struct Notify * notify
Notifications: NotifyEmail, EventEmail.
Definition: email.h:71
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.
Definition: mutt_window.h:215
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:216
Definition: lib.h:70
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:77
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:97
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:152
int(* tag)(struct Menu *menu, int sel, int act)
Definition: lib.h:122
struct ConfigSubset * sub
Inherited config items.
Definition: lib.h:78
void * mdata
Private data.
Definition: lib.h:138
int page_len
Number of entries per screen.
Definition: lib.h:75
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
void * wdata
Private data.
Definition: mutt_window.h:145
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
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
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61
Compose an email.
Definition: type.h:42