NeoMutt  2018-07-16 +2481-68dcde
Teaching an old dog new tricks
DOXYGEN
attach.c File Reference

Handling of email attachments. More...

#include "config.h"
#include "mutt/mutt.h"
#include "attach.h"
#include "body.h"
+ Include dependency graph for attach.c:

Go to the source code of this file.

Functions

void mutt_actx_add_attach (struct AttachCtx *actx, struct AttachPtr *attach)
 Add an Attachment to an Attachment Context. More...
 
void mutt_actx_add_fp (struct AttachCtx *actx, FILE *fp_new)
 Save a File handle to the Attachment Context. More...
 
void mutt_actx_add_body (struct AttachCtx *actx, struct Body *new_body)
 Add an email box to an Attachment Context. More...
 
void mutt_actx_entries_free (struct AttachCtx *actx)
 Free entries in an Attachment Context. More...
 
struct AttachCtxmutt_actx_new (void)
 Create a new Attachment Context. More...
 
void mutt_actx_free (struct AttachCtx **ptr)
 Free an Attachment Context. More...
 

Detailed Description

Handling of email attachments.

Authors
  • Michael R. Elkins
  • Thomas Roessler

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

◆ mutt_actx_add_attach()

void mutt_actx_add_attach ( struct AttachCtx actx,
struct AttachPtr attach 
)

Add an Attachment to an Attachment Context.

Parameters
actxAttachment context
attachAttachment to add

Definition at line 40 of file attach.c.

41 {
42  if (!actx || !attach)
43  return;
44 
45  if (actx->idxlen == actx->idxmax)
46  {
47  actx->idxmax += 5;
48  mutt_mem_realloc(&actx->idx, sizeof(struct AttachPtr *) * actx->idxmax);
49  mutt_mem_realloc(&actx->v2r, sizeof(short) * actx->idxmax);
50  for (int i = actx->idxlen; i < actx->idxmax; i++)
51  actx->idx[i] = NULL;
52  }
53 
54  actx->idx[actx->idxlen++] = attach;
55 }
An email to which things will be attached.
Definition: attach.h:34
short idxmax
Size of attachment array.
Definition: attach.h:56
short idxlen
Number of attachmentes.
Definition: attach.h:55
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
short * v2r
Mapping from virtual to real attachment.
Definition: attach.h:58
struct AttachPtr ** idx
Array of attachments.
Definition: attach.h:54
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_actx_add_fp()

void mutt_actx_add_fp ( struct AttachCtx actx,
FILE *  fp_new 
)

Save a File handle to the Attachment Context.

Parameters
actxAttachment context
fp_newFile handle to save

Definition at line 62 of file attach.c.

63 {
64  if (!actx || !fp_new)
65  return;
66 
67  if (actx->fp_len == actx->fp_max)
68  {
69  actx->fp_max += 5;
70  mutt_mem_realloc(&actx->fp_idx, sizeof(FILE *) * actx->fp_max);
71  for (int i = actx->fp_len; i < actx->fp_max; i++)
72  actx->fp_idx[i] = NULL;
73  }
74 
75  actx->fp_idx[actx->fp_len++] = fp_new;
76 }
FILE ** fp_idx
Extra FILE* used for decryption.
Definition: attach.h:61
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
short fp_max
Size of FILE array.
Definition: attach.h:63
short fp_len
Number of FILE handles.
Definition: attach.h:62
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_actx_add_body()

void mutt_actx_add_body ( struct AttachCtx actx,
struct Body new_body 
)

Add an email box to an Attachment Context.

Parameters
actxAttachment context
new_bodyEmail Body to add

Definition at line 83 of file attach.c.

84 {
85  if (!actx || !new_body)
86  return;
87 
88  if (actx->body_len == actx->body_max)
89  {
90  actx->body_max += 5;
91  mutt_mem_realloc(&actx->body_idx, sizeof(struct Body *) * actx->body_max);
92  for (int i = actx->body_len; i < actx->body_max; i++)
93  actx->body_idx[i] = NULL;
94  }
95 
96  actx->body_idx[actx->body_len++] = new_body;
97 }
short body_len
Number of Body parts.
Definition: attach.h:66
The body of an email.
Definition: body.h:34
struct Body ** body_idx
Extra struct Body* used for decryption.
Definition: attach.h:65
short body_max
Size of Body array.
Definition: attach.h:67
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_actx_entries_free()

void mutt_actx_entries_free ( struct AttachCtx actx)

Free entries in an Attachment Context.

Parameters
actxAttachment context

Definition at line 103 of file attach.c.

104 {
105  if (!actx)
106  return;
107 
108  for (int i = 0; i < actx->idxlen; i++)
109  {
110  if (actx->idx[i]->content)
111  actx->idx[i]->content->aptr = NULL;
112  FREE(&actx->idx[i]->tree);
113  FREE(&actx->idx[i]);
114  }
115  actx->idxlen = 0;
116  actx->vcount = 0;
117 
118  for (int i = 0; i < actx->fp_len; i++)
119  mutt_file_fclose(&actx->fp_idx[i]);
120  actx->fp_len = 0;
121 
122  for (int i = 0; i < actx->body_len; i++)
123  mutt_body_free(&actx->body_idx[i]);
124  actx->body_len = 0;
125 }
FILE ** fp_idx
Extra FILE* used for decryption.
Definition: attach.h:61
short body_len
Number of Body parts.
Definition: attach.h:66
short idxlen
Number of attachmentes.
Definition: attach.h:55
char * tree
Tree characters to display.
Definition: attach.h:39
struct Body ** body_idx
Extra struct Body* used for decryption.
Definition: attach.h:65
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:150
struct AttachPtr * aptr
Menu information, used in recvattach.c.
Definition: body.h:57
struct Body * content
Attachment.
Definition: attach.h:36
#define FREE(x)
Definition: memory.h:40
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:57
struct AttachPtr ** idx
Array of attachments.
Definition: attach.h:54
short fp_len
Number of FILE handles.
Definition: attach.h:62
short vcount
The number of virtual attachments.
Definition: attach.h:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_actx_new()

struct AttachCtx* mutt_actx_new ( void  )

Create a new Attachment Context.

Return values
ptrNew Attachment Context

Definition at line 131 of file attach.c.

132 {
133  return mutt_mem_calloc(1, sizeof(struct AttachCtx));
134 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
A set of attachments.
Definition: attach.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_actx_free()

void mutt_actx_free ( struct AttachCtx **  ptr)

Free an Attachment Context.

Parameters
[out]ptrAttachment context

Definition at line 140 of file attach.c.

141 {
142  if (!ptr || !*ptr)
143  return;
144 
145  struct AttachCtx *actx = *ptr;
146 
148  FREE(&actx->idx);
149  FREE(&actx->v2r);
150  FREE(&actx->fp_idx);
151  FREE(&actx->body_idx);
152  FREE(ptr);
153 }
FILE ** fp_idx
Extra FILE* used for decryption.
Definition: attach.h:61
struct Body ** body_idx
Extra struct Body* used for decryption.
Definition: attach.h:65
void mutt_actx_entries_free(struct AttachCtx *actx)
Free entries in an Attachment Context.
Definition: attach.c:103
short * v2r
Mapping from virtual to real attachment.
Definition: attach.h:58
#define FREE(x)
Definition: memory.h:40
A set of attachments.
Definition: attach.h:49
struct AttachPtr ** idx
Array of attachments.
Definition: attach.h:54
+ Here is the call graph for this function:
+ Here is the caller graph for this function: