NeoMutt  2024-12-12-14-g7b49f7
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
attach.c File Reference

Compose Attachments. More...

#include "config.h"
#include <stdbool.h>
#include <stddef.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 "attach/lib.h"
#include "convert/lib.h"
#include "expando/lib.h"
#include "menu/lib.h"
#include "attach_data.h"
#include "shared_data.h"
+ Include dependency graph for attach.c:

Go to the source code of this file.

Functions

unsigned long cum_attachs_size (struct ConfigSubset *sub, struct ComposeAttachData *adata)
 Cumulative Attachments Size.
 
static int attach_email_observer (struct NotifyCallback *nc)
 Notification that the Email has changed - Implements observer_t -.
 
static int attach_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t -.
 
static int attach_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t -.
 
static int compose_attach_tag (struct Menu *menu, int sel, int act)
 Tag an attachment - Implements Menu::tag() -.
 
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() -.
 
static int attach_recalc (struct MuttWindow *win)
 Recalculate the Window data - Implements MuttWindow::recalc() -.
 
struct MuttWindowattach_new (struct MuttWindow *parent, struct ComposeSharedData *shared)
 Create the Attachments Menu.
 
void attachment_size_fixed (struct MuttWindow *win)
 Make the Attachment Window fixed-size.
 
void attachment_size_max (struct MuttWindow *win)
 Make the Attachment Window maximised.
 

Detailed Description

Compose Attachments.

Authors
  • Richard Russon
  • Tóth János
  • Dennis Schön

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 http://www.gnu.org/licenses/.

Definition in file attach.c.

Function Documentation

◆ cum_attachs_size()

unsigned long cum_attachs_size ( struct ConfigSubset sub,
struct ComposeAttachData adata 
)

Cumulative Attachments Size.

Parameters
subConfig Subset
adataAttachment data
Return values
numBytes in attachments

Returns the total number of bytes used by the attachments in the attachment list after content-transfer-encodings have been applied.

Definition at line 85 of file attach.c.

86{
87 if (!adata || !adata->actx)
88 return 0;
89
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;
95
96 for (unsigned short i = 0; i < actx->idxlen; i++)
97 {
98 b = idx[i]->body;
99
100 if (!b->content)
101 b->content = mutt_get_content_info(b->filename, b, sub);
102
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 }
120
121 return s;
122}
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
@ ENC_BASE64
Base-64 encoded text.
Definition: mime.h:52
@ ENC_QUOTED_PRINTABLE
Quoted-printable text.
Definition: mime.h:51
A set of attachments.
Definition: attach.h:63
struct AttachPtr ** idx
Array of attachments.
Definition: attach.h:67
short idxlen
Number of attachmentes.
Definition: attach.h:68
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
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
struct AttachCtx * actx
Set of attachments.
Definition: attach_data.h:34
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ attach_window_observer()

static int attach_window_observer ( struct NotifyCallback nc)
static

Notification that a Window has changed - Implements observer_t -.

Definition at line 168 of file attach.c.

169{
170 if (nc->event_type != NT_WINDOW)
171 return 0;
172 if (!nc->global_data || !nc->event_data)
173 return -1;
174
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;
179
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 }
195
196 return 0;
197}
static int attach_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: attach.c:168
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
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:108
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
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
#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
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:57
struct Email * email
Used by recvattach for updating.
Definition: attach.h:64
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 Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition: subset.h:52
struct Notify * notify
Notifications: NotifyEmail, EventEmail.
Definition: email.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
Definition: lib.h:79
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
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ attach_new()

struct MuttWindow * attach_new ( struct MuttWindow parent,
struct ComposeSharedData shared 
)

Create the Attachments Menu.

Parameters
parentParent Window
sharedShared compose data

Definition at line 267 of file attach.c.

268{
269 struct MuttWindow *win_attach = menu_window_new(MENU_COMPOSE, NeoMutt->sub);
270
271 struct ComposeAttachData *adata = attach_data_new(shared->email);
272
273 shared->adata = adata;
274
275 // NT_COLOR is handled by the Menu Window
279
280 struct Menu *menu = win_attach->wdata;
281 menu->page_len = win_attach->state.rows;
282 menu->win = win_attach;
283
285 menu->tag = compose_attach_tag;
286 menu->mdata = adata;
288 adata->menu = menu;
289
290 return win_attach;
291}
struct ComposeAttachData * attach_data_new(struct Email *e)
Create new Compose Attach Data.
Definition: attach_data.c:54
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: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
struct MuttWindow * menu_window_new(enum MenuType type, struct ConfigSubset *sub)
Create a new Menu Window.
Definition: window.c:140
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
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
@ NT_EMAIL
Email has changed, NotifyEmail, EventEmail.
Definition: notify_type.h:44
struct ComposeAttachData * adata
Attachments.
Definition: shared_data.h:40
struct Email * email
Email being composed.
Definition: shared_data.h:39
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
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
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ attachment_size_fixed()

void attachment_size_fixed ( struct MuttWindow win)

Make the Attachment Window fixed-size.

Parameters
winAttachment Window

Definition at line 297 of file attach.c.

298{
299 if (!win || (win->size == MUTT_WIN_SIZE_FIXED))
300 return;
301
303 win->recalc = attach_recalc;
304}
static int attach_recalc(struct MuttWindow *win)
Recalculate the Window data - Implements MuttWindow::recalc() -.
Definition: attach.c:242
@ MUTT_WIN_SIZE_FIXED
Window has a fixed size.
Definition: mutt_window.h:48
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:173
enum MuttWindowSize size
Type of Window, e.g. MUTT_WIN_SIZE_FIXED.
Definition: mutt_window.h:131
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ attachment_size_max()

void attachment_size_max ( struct MuttWindow win)

Make the Attachment Window maximised.

Parameters
winAttachment Window

Definition at line 310 of file attach.c.

311{
312 if (!win || (win->size == MUTT_WIN_SIZE_MAXIMISE))
313 return;
314
316 win->recalc = NULL;
317}
@ MUTT_WIN_SIZE_MAXIMISE
Window wants as much space as possible.
Definition: mutt_window.h:49
+ Here is the caller graph for this function: