NeoMutt  2025-01-09-104-g5de5ef
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
attach.c
Go to the documentation of this file.
1
60#include "config.h"
61#include <stdbool.h>
62#include <stddef.h>
63#include "private.h"
64#include "mutt/lib.h"
65#include "config/lib.h"
66#include "email/lib.h"
67#include "core/lib.h"
68#include "gui/lib.h"
69#include "attach/lib.h"
70#include "convert/lib.h"
71#include "expando/lib.h"
72#include "menu/lib.h"
73#include "attach_data.h"
74#include "globals.h"
75#include "shared_data.h"
76
86unsigned long cum_attachs_size(struct ConfigSubset *sub, struct ComposeAttachData *adata)
87{
88 if (!adata || !adata->actx)
89 return 0;
90
91 size_t s = 0;
92 struct Content *info = NULL;
93 struct Body *b = NULL;
94 struct AttachCtx *actx = adata->actx;
95 struct AttachPtr **idx = actx->idx;
96
97 for (unsigned short i = 0; i < actx->idxlen; i++)
98 {
99 b = idx[i]->body;
100
101 if (!b->content)
102 b->content = mutt_get_content_info(b->filename, b, sub);
103
104 info = b->content;
105 if (info)
106 {
107 switch (b->encoding)
108 {
110 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
111 break;
112 case ENC_BASE64:
113 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
114 break;
115 default:
116 s += info->lobin + info->hibin + info->ascii + info->crlf;
117 break;
118 }
119 }
120 }
121
122 return s;
123}
124
129{
130 if (nc->event_type != NT_EMAIL)
131 return 0;
132 if (!nc->global_data)
133 return -1;
135 return 0;
136
137 struct MuttWindow *win_attach = nc->global_data;
138
139 win_attach->actions |= WA_RECALC;
140 mutt_debug(LL_DEBUG5, "compose done, request WA_RECALC\n");
141
142 return 0;
143}
144
149{
150 if (nc->event_type != NT_CONFIG)
151 return 0;
152 if (!nc->global_data || !nc->event_data)
153 return -1;
154
155 struct EventConfig *ev_c = nc->event_data;
156 if (!mutt_str_equal(ev_c->name, "attach_format"))
157 return 0;
158
159 struct MuttWindow *win_attach = nc->global_data;
160 win_attach->actions |= WA_RECALC;
161 mutt_debug(LL_DEBUG5, "config, request WA_RECALC\n");
162
163 return 0;
164}
165
170{
171 if (nc->event_type != NT_WINDOW)
172 return 0;
173 if (!nc->global_data || !nc->event_data)
174 return -1;
175
176 struct MuttWindow *win_attach = nc->global_data;
177 struct EventWindow *ev_w = nc->event_data;
178 if (ev_w->win != win_attach)
179 return 0;
180
182 {
183 win_attach->actions |= WA_RECALC;
184 mutt_debug(LL_DEBUG5, "window state done, request WA_RECALC\n");
185 }
186 else if (nc->event_subtype == NT_WINDOW_DELETE)
187 {
188 struct Menu *menu = win_attach->wdata;
189 struct ComposeAttachData *adata = menu->mdata;
190 struct AttachCtx *actx = adata->actx;
193 notify_observer_remove(win_attach->notify, attach_window_observer, win_attach);
194 mutt_debug(LL_DEBUG5, "window delete done\n");
195 }
196
197 return 0;
198}
199
203static int compose_attach_tag(struct Menu *menu, int sel, int act)
204{
205 struct ComposeAttachData *adata = menu->mdata;
206 struct AttachCtx *actx = adata->actx;
207 struct Body *cur = actx->idx[actx->v2r[sel]]->body;
208 bool ot = cur->tagged;
209
210 cur->tagged = ((act >= 0) ? act : !cur->tagged);
211 return cur->tagged - ot;
212}
213
219static int compose_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
220{
221 struct ComposeAttachData *adata = menu->mdata;
222 struct AttachCtx *actx = adata->actx;
223 struct ComposeSharedData *shared = menu->win->parent->wdata;
224 struct ConfigSubset *sub = shared->sub;
225
226 const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
227 if (c_arrow_cursor)
228 {
229 const char *const c_arrow_string = cs_subset_string(menu->sub, "arrow_string");
230 if (max_cols > 0)
231 max_cols -= (mutt_strwidth(c_arrow_string) + 1);
232 }
233
234 const struct Expando *c_attach_format = cs_subset_expando(sub, "attach_format");
235 return expando_filter(c_attach_format, AttachRenderCallbacks,
236 (actx->idx[actx->v2r[line]]),
238 max_cols, EnvList, buf);
239}
240
244static int attach_recalc(struct MuttWindow *win)
245{
246 struct Menu *menu = win->wdata;
247 struct ComposeAttachData *adata = menu->mdata;
248
249 const int cur_rows = win->state.rows;
250 const int new_rows = adata->actx->idxlen;
251
252 if (new_rows != cur_rows)
253 {
254 win->req_rows = new_rows;
257 }
258
259 win->actions |= WA_REPAINT;
260 mutt_debug(LL_DEBUG5, "recalc done, request WA_REPAINT\n");
261 return 0;
262}
263
270{
271 struct MuttWindow *win_attach = menu_window_new(MENU_COMPOSE, NeoMutt->sub);
272
273 struct ComposeAttachData *adata = attach_data_new(shared->email);
274
275 shared->adata = adata;
276
277 // NT_COLOR is handled by the Menu Window
281
282 struct Menu *menu = win_attach->wdata;
283 menu->page_len = win_attach->state.rows;
284 menu->win = win_attach;
285
287 menu->tag = compose_attach_tag;
288 menu->mdata = adata;
290 adata->menu = menu;
291
292 return win_attach;
293}
294
300{
301 if (!win || (win->size == MUTT_WIN_SIZE_FIXED))
302 return;
303
306}
307
313{
314 if (!win || (win->size == MUTT_WIN_SIZE_MAXIMISE))
315 return;
316
318 win->recalc = NULL;
319}
const struct ExpandoRenderCallback AttachRenderCallbacks[]
Callbacks for Attachment Expandos.
Definition: expando.c:375
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:54
Compose Attach Data.
unsigned long cum_attachs_size(struct ConfigSubset *sub, struct ComposeAttachData *adata)
Cumulative Attachments Size.
Definition: attach.c:86
void attachment_size_fixed(struct MuttWindow *win)
Make the Attachment Window fixed-size.
Definition: attach.c:299
struct MuttWindow * attach_new(struct MuttWindow *parent, struct ComposeSharedData *shared)
Create the Attachments Menu.
Definition: attach.c:269
void attachment_size_max(struct MuttWindow *win)
Make the Attachment Window maximised.
Definition: attach.c:312
static int attach_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: attach.c:169
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:361
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:188
Conversion between different character encodings.
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:445
Structs that make up an email.
@ NT_EMAIL_CHANGE_ATTACH
Email's Attachments have changed.
Definition: email.h:188
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.
char ** EnvList
Private copy of the environment variables.
Definition: globals.c:75
#define mutt_debug(LEVEL,...)
Definition: logging2.h:90
static int compose_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Format an Attachment for the Menu - Implements Menu::make_entry() -.
Definition: attach.c:219
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:203
static int attach_email_observer(struct NotifyCallback *nc)
Notification that the Email has changed - Implements observer_t -.
Definition: attach.c:128
static int attach_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: dlg_attach.c:109
static int attach_recalc(struct MuttWindow *win)
Recalculate the Window data - Implements MuttWindow::recalc() -.
Definition: attach.c:244
Convenience wrapper for the gui headers.
Data shared between Index, Pager and Sidebar.
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:48
GUI present the user with a selectable list.
void menu_adjust(struct Menu *menu)
Reapply the config to the Menu.
Definition: move.c:319
struct MuttWindow * menu_window_new(enum MenuType type, struct ConfigSubset *sub)
Create a new Menu Window.
Definition: window.c:140
@ ENC_BASE64
Base-64 encoded text.
Definition: mime.h:52
@ ENC_QUOTED_PRINTABLE
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: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:661
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:309
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
@ NT_WINDOW_STATE
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:230
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:229
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
@ MUTT_WIN_SIZE_FIXED
Window has a fixed size.
Definition: mutt_window.h:48
@ MUTT_WIN_SIZE_MAXIMISE
Window wants as much space as possible.
Definition: mutt_window.h:49
@ 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
#define MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition: render.h:37
#define MUTT_FORMAT_STAT_FILE
Used by attach_format_str.
Definition: render.h:36
GUI display the mailboxes in a side panel.
A set of attachments.
Definition: attach.h:63
struct Email * email
Used by recvattach for updating.
Definition: attach.h:64
struct AttachPtr ** idx
Array of attachments.
Definition: attach.h:67
short idxlen
Number of attachmentes.
Definition: attach.h:68
short * v2r
Mapping from virtual to real attachment.
Definition: attach.h:71
An email to which things will be attached.
Definition: attach.h:35
struct Body * body
Attachment.
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:70
bool tagged
This attachment is tagged.
Definition: body.h:90
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:59
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:36
struct ConfigSubset * sub
Config set to use.
Definition: shared_data.h:37
struct ComposeAttachData * adata
Attachments.
Definition: shared_data.h:40
struct Email * email
Email being composed.
Definition: shared_data.h:39
A set of inherited config items.
Definition: subset.h:46
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition: subset.h:51
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:73
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:239
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:240
Parsed Expando trees.
Definition: expando.h:41
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
int page_len
Number of entries per screen.
Definition: lib.h:84
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
short req_rows
Number of rows required.
Definition: mutt_window.h:125
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:173
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
enum MuttWindowSize size
Type of Window, e.g. MUTT_WIN_SIZE_FIXED.
Definition: mutt_window.h:131
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
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:62
@ MENU_COMPOSE
Compose an email.
Definition: type.h:42