NeoMutt  2018-07-16 +2481-68dcde
Teaching an old dog new tricks
DOXYGEN
attach.c
Go to the documentation of this file.
1 
30 #include "config.h"
31 #include "mutt/mutt.h"
32 #include "attach.h"
33 #include "body.h"
34 
40 void mutt_actx_add_attach(struct AttachCtx *actx, struct AttachPtr *attach)
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 }
56 
62 void mutt_actx_add_fp(struct AttachCtx *actx, FILE *fp_new)
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 }
77 
83 void mutt_actx_add_body(struct AttachCtx *actx, struct Body *new_body)
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 }
98 
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 }
126 
132 {
133  return mutt_mem_calloc(1, sizeof(struct AttachCtx));
134 }
135 
140 void mutt_actx_free(struct AttachCtx **ptr)
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 }
void mutt_actx_free(struct AttachCtx **ptr)
Free an Attachment Context.
Definition: attach.c:140
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
An email to which things will be attached.
Definition: attach.h:34
FILE ** fp_idx
Extra FILE* used for decryption.
Definition: attach.h:61
void mutt_actx_add_fp(struct AttachCtx *actx, FILE *fp_new)
Save a File handle to the Attachment Context.
Definition: attach.c:62
short body_len
Number of Body parts.
Definition: attach.h:66
Representation of the body of an email.
short idxmax
Size of attachment array.
Definition: attach.h:56
short idxlen
Number of attachmentes.
Definition: attach.h:55
void mutt_actx_add_attach(struct AttachCtx *actx, struct AttachPtr *attach)
Add an Attachment to an Attachment Context.
Definition: attach.c:40
The body of an email.
Definition: body.h:34
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 AttachCtx * mutt_actx_new(void)
Create a new Attachment Context.
Definition: attach.c:131
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
struct AttachPtr * aptr
Menu information, used in recvattach.c.
Definition: body.h:57
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
struct Body * content
Attachment.
Definition: attach.h:36
short fp_max
Size of FILE array.
Definition: attach.h:63
Handling of email attachments.
#define FREE(x)
Definition: memory.h:40
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:57
A set of attachments.
Definition: attach.h:49
struct AttachPtr ** idx
Array of attachments.
Definition: attach.h:54
short fp_len
Number of FILE handles.
Definition: attach.h:62
void mutt_actx_add_body(struct AttachCtx *actx, struct Body *new_body)
Add an email box to an Attachment Context.
Definition: attach.c:83
short vcount
The number of virtual attachments.
Definition: attach.h:59