NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
attach.c File Reference

Compose Attachments. More...

#include "config.h"
#include <stddef.h>
#include <stdbool.h>
#include <stdint.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 "menu/lib.h"
#include "send/lib.h"
#include "attach_data.h"
#include "format_flags.h"
#include "muttlib.h"
#include "recvattach.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. More...
 
int attach_recalc (struct MuttWindow *win)
 Recalculate the Window data - Implements MuttWindow::recalc() -. More...
 
int attach_repaint (struct MuttWindow *win)
 Repaint the Window - Implements MuttWindow::repaint() -. More...
 
static int attach_compose_observer (struct NotifyCallback *nc)
 Notification that the Compose data has changed - Implements observer_t. More...
 
int attach_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t. More...
 
static int attach_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t. More...
 
static int compose_attach_tag (struct Menu *menu, int sel, int act)
 Tag an attachment - Implements Menu::tag() -. More...
 
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() -. More...
 
struct MuttWindowattach_new (struct MuttWindow *parent, struct ComposeSharedData *shared)
 Create the Attachments Menu. More...
 

Detailed Description

Compose Attachments.

Authors
  • 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 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 89 of file attach.c.

90 {
91  if (!adata || !adata->actx)
92  return 0;
93 
94  size_t s = 0;
95  struct Content *info = NULL;
96  struct Body *b = NULL;
97  struct AttachCtx *actx = adata->actx;
98  struct AttachPtr **idx = actx->idx;
99 
100  for (unsigned short i = 0; i < actx->idxlen; i++)
101  {
102  b = idx[i]->body;
103 
104  if (!b->content)
105  b->content = mutt_get_content_info(b->filename, b, sub);
106 
107  info = b->content;
108  if (info)
109  {
110  switch (b->encoding)
111  {
113  s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
114  break;
115  case ENC_BASE64:
116  s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
117  break;
118  default:
119  s += info->lobin + info->hibin + info->ascii + info->crlf;
120  break;
121  }
122  }
123  }
124 
125  return s;
126 }
struct Content * mutt_get_content_info(const char *fname, struct Body *b, struct ConfigSubset *sub)
Analyze file to determine MIME encoding to use.
Definition: sendlib.c:465
char * filename
when sending a message, this is the file to which this structure refers
Definition: body.h:46
An email to which things will be attached.
Definition: attach.h:34
struct Content * content
Detailed info about the content of the attachment.
Definition: body.h:51
size_t idx
Definition: mailbox.c:257
short idxlen
Number of attachmentes.
Definition: attach.h:55
long hibin
8-bit characters
Definition: content.h:35
The body of an email.
Definition: body.h:34
unsigned int encoding
content-transfer-encoding, ContentEncoding
Definition: body.h:66
Base-64 encoded text.
Definition: mime.h:52
Info about an attachment.
Definition: content.h:33
long ascii
Number of ascii chars.
Definition: content.h:39
struct AttachCtx * actx
Definition: attach_data.h:34
long lobin
Unprintable 7-bit chars (eg., control chars)
Definition: content.h:36
Quoted-printable text.
Definition: mime.h:51
long crlf
\r and \n characters
Definition: content.h:38
A set of attachments.
Definition: attach.h:49
struct AttachPtr ** idx
Array of attachments.
Definition: attach.h:54
struct Body * body
Attachment.
Definition: attach.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ attach_compose_observer()

static int attach_compose_observer ( struct NotifyCallback nc)
static

Notification that the Compose data has changed - Implements observer_t.

Definition at line 180 of file attach.c.

181 {
182  if ((nc->event_type != NT_COMPOSE) || !nc->global_data)
183  return -1;
184 
185  if (nc->event_subtype != NT_COMPOSE_ATTACH)
186  return 0;
187 
188  struct MuttWindow *win_attach = nc->global_data;
189 
190  win_attach->actions |= WA_RECALC;
191  mutt_debug(LL_DEBUG5, "compose done, request WA_RECALC\n");
192 
193  return 0;
194 }
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:43
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
#define NT_COMPOSE_ATTACH
Attachments have changed.
Definition: private.h:36
Compose data has changed, NotifyCompose.
Definition: notify_type.h:41
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Log at debug level 5.
Definition: logging.h:44
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ Here is the caller graph for this function:

◆ attach_config_observer()

int attach_config_observer ( struct NotifyCallback nc)

Notification that a Config Variable has changed - Implements observer_t.

Definition at line 199 of file attach.c.

200 {
201  if ((nc->event_type != NT_CONFIG) || !nc->global_data || !nc->event_data)
202  return -1;
203 
204  struct EventConfig *ev_c = nc->event_data;
205  if (!mutt_str_equal(ev_c->name, "attach_format"))
206  return 0;
207 
208  struct MuttWindow *win_attach = nc->global_data;
209  win_attach->actions |= WA_RECALC;
210  mutt_debug(LL_DEBUG5, "config, request WA_RECALC\n");
211 
212  return 0;
213 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
A config-change event.
Definition: subset.h:69
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
Log at debug level 5.
Definition: logging.h:44
const char * name
Name of config item that changed.
Definition: subset.h:72
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ 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 218 of file attach.c.

219 {
220  if ((nc->event_type != NT_WINDOW) || !nc->global_data || !nc->event_data)
221  return -1;
222 
223  struct MuttWindow *win_attach = nc->global_data;
224  struct EventWindow *ev_w = nc->event_data;
225  if (ev_w->win != win_attach)
226  return 0;
227 
228  if (nc->event_subtype == NT_WINDOW_STATE)
229  {
230  win_attach->actions |= WA_RECALC;
231  mutt_debug(LL_DEBUG5, "window state done, request WA_RECALC\n");
232  }
233  else if (nc->event_subtype == NT_WINDOW_DELETE)
234  {
235  notify_observer_remove(win_attach->parent->notify, attach_compose_observer, win_attach);
237  notify_observer_remove(win_attach->notify, attach_window_observer, win_attach);
238  mutt_debug(LL_DEBUG5, "window delete done\n");
239  }
240 
241  return 0;
242 }
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
An Event that happened to a Window.
Definition: mutt_window.h:215
int attach_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t.
Definition: attach.c:199
Window is about to be deleted.
Definition: mutt_window.h:206
Container for Accounts, Notifications.
Definition: neomutt.h:36
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:43
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:207
static int attach_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: attach.c:218
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
static int attach_compose_observer(struct NotifyCallback *nc)
Notification that the Compose data has changed - Implements observer_t.
Definition: attach.c:180
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:228
Log at debug level 5.
Definition: logging.h:44
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ 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 279 of file attach.c.

280 {
281  struct MuttWindow *win_attach = menu_new_window(MENU_COMPOSE, NeoMutt->sub);
282 
283  struct ComposeAttachData *adata = attach_data_new(shared->email);
284 
285  shared->adata = adata;
286 
287  // win_attach->recalc = attach_recalc;
288  // win_attach->repaint = attach_repaint;
289 
290  // NT_COLOR is handled by the Menu Window
293  notify_observer_add(win_attach->notify, NT_WINDOW, attach_window_observer, win_attach);
294 
295  struct Menu *menu = win_attach->wdata;
296  menu->pagelen = win_attach->state.rows;
297  menu->win = win_attach;
298 
300  menu->tag = compose_attach_tag;
301  menu->mdata = adata;
303  adata->menu = menu;
304 
305  return win_attach;
306 }
Definition: lib.h:67
Data to fill the Compose Attach Window.
Definition: attach_data.h:32
int attach_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t.
Definition: attach.c:199
Compose an email.
Definition: type.h:42
Container for Accounts, Notifications.
Definition: neomutt.h:36
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:105
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
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:261
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
static int compose_attach_tag(struct Menu *menu, int sel, int act)
Tag an attachment - Implements Menu::tag() -.
Definition: attach.c:247
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
static int attach_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: attach.c:218
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
void * mdata
Private data.
Definition: lib.h:155
struct ComposeAttachData * attach_data_new(struct Email *e)
Create new Compose Attach Data.
Definition: attach_data.c:50
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61
Compose data has changed, NotifyCompose.
Definition: notify_type.h:41
int(* tag)(struct Menu *menu, int sel, int act)
Definition: lib.h:130
int pagelen
Number of entries per screen.
Definition: lib.h:74
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:170
struct Menu * menu
Definition: attach_data.h:35
static int attach_compose_observer(struct NotifyCallback *nc)
Notification that the Compose data has changed - Implements observer_t.
Definition: attach.c:180
void attach_data_free(struct Menu *menu, void **ptr)
Free the Compose Attach Data - Implements Menu::mdata_free() -.
Definition: attach_data.c:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
void * wdata
Private data.
Definition: mutt_window.h:145
struct Email * email
Email being composed.
Definition: shared_data.h:33
struct ComposeAttachData * adata
Attachments.
Definition: shared_data.h:34
+ Here is the call graph for this function:
+ Here is the caller graph for this function: