NeoMutt  2024-12-12-14-g7b49f7
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
attach.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <string.h>
32#include "mutt/lib.h"
33#include "email/lib.h"
34#include "attach.h"
35
41{
42 return MUTT_MEM_CALLOC(1, struct AttachPtr);
43}
44
49void mutt_aptr_free(struct AttachPtr **ptr)
50{
51 if (!ptr || !*ptr)
52 return;
53
54 struct AttachPtr *aptr = *ptr;
55 FREE(&aptr->tree);
56
57 FREE(ptr);
58}
59
65void mutt_actx_add_attach(struct AttachCtx *actx, struct AttachPtr *attach)
66{
67 const int grow = 5;
68
69 if (!actx || !attach)
70 return;
71
72 if (actx->idxlen == actx->idxmax)
73 {
74 actx->idxmax += grow;
75 MUTT_MEM_REALLOC(&actx->idx, actx->idxmax, struct AttachPtr *);
76 MUTT_MEM_REALLOC(&actx->v2r, actx->idxmax, short);
77
78 memset(&actx->idx[actx->idxlen], 0, grow * sizeof(struct AttachPtr *));
79 memset(&actx->v2r[actx->idxlen], 0, grow * sizeof(short));
80 }
81
82 actx->idx[actx->idxlen++] = attach;
83}
84
91void mutt_actx_ins_attach(struct AttachCtx *actx, struct AttachPtr *attach, int aidx)
92{
93 if (!actx || !attach)
94 return;
95
96 if ((aidx < 0) || (aidx > actx->idxmax))
97 return;
98
99 if (actx->idxlen == actx->idxmax)
100 {
101 actx->idxmax += 5;
102 MUTT_MEM_REALLOC(&actx->idx, actx->idxmax, struct AttachPtr *);
103 MUTT_MEM_REALLOC(&actx->v2r, actx->idxmax, short);
104 for (int i = actx->idxlen; i < actx->idxmax; i++)
105 actx->idx[i] = NULL;
106 }
107
108 actx->idxlen++;
109
110 for (int i = actx->idxlen - 1; i > aidx; i--)
111 actx->idx[i] = actx->idx[i - 1];
112
113 actx->idx[aidx] = attach;
114}
115
121void mutt_actx_add_fp(struct AttachCtx *actx, FILE *fp_new)
122{
123 if (!actx || !fp_new)
124 return;
125
126 if (actx->fp_len == actx->fp_max)
127 {
128 actx->fp_max += 5;
129 MUTT_MEM_REALLOC(&actx->fp_idx, actx->fp_max, FILE *);
130 for (int i = actx->fp_len; i < actx->fp_max; i++)
131 actx->fp_idx[i] = NULL;
132 }
133
134 actx->fp_idx[actx->fp_len++] = fp_new;
135}
136
142void mutt_actx_add_body(struct AttachCtx *actx, struct Body *b)
143{
144 if (!actx || !b)
145 return;
146
147 if (actx->body_len == actx->body_max)
148 {
149 actx->body_max += 5;
150 MUTT_MEM_REALLOC(&actx->body_idx, actx->body_max, struct Body *);
151 for (int i = actx->body_len; i < actx->body_max; i++)
152 actx->body_idx[i] = NULL;
153 }
154
155 actx->body_idx[actx->body_len++] = b;
156}
157
163{
164 if (!actx)
165 return;
166
167 for (int i = 0; i < actx->idxlen; i++)
168 {
169 if (actx->idx[i]->body)
170 actx->idx[i]->body->aptr = NULL;
171 mutt_aptr_free(&actx->idx[i]);
172 }
173 actx->idxlen = 0;
174 actx->vcount = 0;
175
176 for (int i = 0; i < actx->fp_len; i++)
177 mutt_file_fclose(&actx->fp_idx[i]);
178 actx->fp_len = 0;
179
180 for (int i = 0; i < actx->body_len; i++)
181 mutt_body_free(&actx->body_idx[i]);
182 actx->body_len = 0;
183}
184
190{
191 return MUTT_MEM_CALLOC(1, struct AttachCtx);
192}
193
198void mutt_actx_free(struct AttachCtx **ptr)
199{
200 if (!ptr || !*ptr)
201 return;
202
203 struct AttachCtx *actx = *ptr;
204
206 FREE(&actx->idx);
207 FREE(&actx->v2r);
208 FREE(&actx->fp_idx);
209 FREE(&actx->body_idx);
210 FREE(ptr);
211}
struct AttachCtx * mutt_actx_new(void)
Create a new Attachment Context.
Definition: attach.c:189
void mutt_actx_add_attach(struct AttachCtx *actx, struct AttachPtr *attach)
Add an Attachment to an Attachment Context.
Definition: attach.c:65
void mutt_actx_ins_attach(struct AttachCtx *actx, struct AttachPtr *attach, int aidx)
Insert an Attachment into an Attachment Context at Specified Index.
Definition: attach.c:91
void mutt_actx_add_fp(struct AttachCtx *actx, FILE *fp_new)
Save a File handle to the Attachment Context.
Definition: attach.c:121
struct AttachPtr * mutt_aptr_new(void)
Create a new Attachment Pointer.
Definition: attach.c:40
void mutt_actx_add_body(struct AttachCtx *actx, struct Body *b)
Add an email body to an Attachment Context.
Definition: attach.c:142
void mutt_actx_entries_free(struct AttachCtx *actx)
Free entries in an Attachment Context.
Definition: attach.c:162
void mutt_aptr_free(struct AttachPtr **ptr)
Free an Attachment Pointer.
Definition: attach.c:49
void mutt_actx_free(struct AttachCtx **ptr)
Free an Attachment Context.
Definition: attach.c:198
Handling of email attachments.
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:58
Structs that make up an email.
#define mutt_file_fclose(FP)
Definition: file.h:138
#define FREE(x)
Definition: memory.h:55
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
#define MUTT_MEM_REALLOC(pptr, n, type)
Definition: memory.h:43
Convenience wrapper for the library headers.
A set of attachments.
Definition: attach.h:63
short vcount
The number of virtual attachments.
Definition: attach.h:72
short body_len
Number of Body parts.
Definition: attach.h:79
short fp_max
Size of FILE array.
Definition: attach.h:76
struct AttachPtr ** idx
Array of attachments.
Definition: attach.h:67
struct Body ** body_idx
Extra struct Body* used for decryption.
Definition: attach.h:78
short fp_len
Number of FILE handles.
Definition: attach.h:75
short body_max
Size of Body array.
Definition: attach.h:80
FILE ** fp_idx
Extra FILE* used for decryption.
Definition: attach.h:74
short idxmax
Size of attachment array.
Definition: attach.h:69
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
char * tree
Tree characters to display.
Definition: attach.h:39
The body of an email.
Definition: body.h:36
struct AttachPtr * aptr
Menu information, used in recvattach.c.
Definition: body.h:75