return 0;
}
-static void update_idx(struct Menu *menu, struct AttachCtx *actx)
+static void update_idx(struct Menu *menu, struct AttachCtx *actx, struct AttachPtr *new)
{
- actx->idx[actx->idxlen]->level =
- (actx->idxlen > 0) ? actx->idx[actx->idxlen - 1]->level : 0;
+ new->level = (actx->idxlen > 0) ? actx->idx[actx->idxlen - 1]->level : 0;
if (actx->idxlen)
- actx->idx[actx->idxlen - 1]->content->next = actx->idx[actx->idxlen]->content;
- actx->idx[actx->idxlen]->content->aptr = actx->idx[actx->idxlen];
- menu->current = actx->idxlen++;
+ actx->idx[actx->idxlen - 1]->content->next = new->content;
+ new->content->aptr = new;
+ mutt_actx_add_attach(actx, new, menu);
+ menu->current = actx->idxlen - 1;
mutt_update_tree(actx);
menu->max = actx->idxlen;
}
char fname[_POSIX_PATH_MAX];
struct Menu *menu = NULL;
struct AttachCtx *actx = NULL;
+ struct AttachPtr *new = NULL;
int i, close = 0;
int r = -1; /* return value */
int op = 0;
/* attachments may have been added */
if (actx->idxlen && actx->idx[actx->idxlen - 1]->content->next)
{
- for (i = 0; i < actx->idxlen; i++)
- {
- FREE(&actx->idx[i]->tree);
- FREE(&actx->idx[i]);
- }
- actx->idxlen = 0;
+ mutt_actx_free_entries(actx);
mutt_gen_attach_list(actx, msg->content, -1, 0, 1);
menu->data = actx->idx;
menu->max = actx->idxlen;
case OP_COMPOSE_ATTACH_KEY:
if (!(WithCrypto & APPLICATION_PGP))
break;
- if (actx->idxlen == actx->idxmax)
- {
- safe_realloc(&actx->idx, sizeof(struct AttachPtr *) * (actx->idxmax += 5));
- menu->data = actx->idx;
- }
-
- actx->idx[actx->idxlen] = safe_calloc(1, sizeof(struct AttachPtr));
- if ((actx->idx[actx->idxlen]->content = crypt_pgp_make_key_attachment(NULL)) != NULL)
+ new = safe_calloc(1, sizeof(struct AttachPtr));
+ if ((new->content = crypt_pgp_make_key_attachment(NULL)) != NULL)
{
- update_idx(menu, actx);
+ update_idx(menu, actx, new);
menu->redraw |= REDRAW_INDEX;
}
else
- FREE(&actx->idx[actx->idxlen]);
+ FREE(&new);
menu->redraw |= REDRAW_STATUS;
*fname == '\0')
break;
- if (actx->idxlen + numfiles >= actx->idxmax)
- {
- safe_realloc(&actx->idx, sizeof(struct AttachPtr *) * (actx->idxmax += 5 + numfiles));
- menu->data = actx->idx;
- }
-
error = 0;
if (numfiles > 1)
mutt_message(_("Attaching selected files..."));
for (i = 0; i < numfiles; i++)
{
char *att = files[i];
- actx->idx[actx->idxlen] = safe_calloc(1, sizeof(struct AttachPtr));
- actx->idx[actx->idxlen]->unowned = true;
- actx->idx[actx->idxlen]->content = mutt_make_file_attach(att);
- if (actx->idx[actx->idxlen]->content != NULL)
- update_idx(menu, actx);
+ new = (struct AttachPtr *) safe_calloc(1, sizeof(struct AttachPtr));
+ new->unowned = 1;
+ new->content = mutt_make_file_attach(att);
+ if (new->content != NULL)
+ update_idx(menu, actx, new);
else
{
error = 1;
mutt_error(_("Unable to attach %s!"), att);
- FREE(&actx->idx[actx->idxlen]);
+ FREE(&new);
}
FREE(&files[i]);
}
break;
}
- if (actx->idxlen + Context->tagged >= actx->idxmax)
- {
- safe_realloc(&actx->idx,
- sizeof(struct AttachPtr *) * (actx->idxmax += 5 + Context->tagged));
- menu->data = actx->idx;
- }
-
for (i = 0; i < Context->msgcount; i++)
{
h = Context->hdrs[i];
if (h->tagged)
{
- actx->idx[actx->idxlen] = safe_calloc(1, sizeof(struct AttachPtr));
- actx->idx[actx->idxlen]->content = mutt_make_message_attach(Context, h, 1);
- if (actx->idx[actx->idxlen]->content != NULL)
- update_idx(menu, actx);
+ new = (struct AttachPtr *) safe_calloc(1, sizeof(struct AttachPtr));
+ new->content = mutt_make_message_attach(Context, h, 1);
+ if (new->content != NULL)
+ update_idx(menu, actx, new);
else
{
mutt_error(_("Unable to attach!"));
- FREE(&actx->idx[actx->idxlen]);
+ FREE(&new);
}
}
}
mutt_error(_("Unknown Content-Type %s"), type);
continue;
}
- if (actx->idxlen == actx->idxmax)
- {
- safe_realloc(&actx->idx, sizeof(struct AttachPtr *) * (actx->idxmax += 5));
- menu->data = actx->idx;
- }
-
- actx->idx[actx->idxlen] = safe_calloc(1, sizeof(struct AttachPtr));
+ new = (struct AttachPtr *) safe_calloc(1, sizeof(struct AttachPtr));
/* Touch the file */
if (!(fp = safe_fopen(fname, "w")))
{
mutt_error(_("Can't create file %s"), fname);
- FREE(&actx->idx[actx->idxlen]);
+ FREE(&new);
continue;
}
safe_fclose(&fp);
- if ((actx->idx[actx->idxlen]->content = mutt_make_file_attach(fname)) == NULL)
+ if ((new->content = mutt_make_file_attach(fname)) == NULL)
{
mutt_error(_("What we have here is a failure to make an attachment"));
+ FREE(&new);
continue;
}
- update_idx(menu, actx);
+ update_idx(menu, actx, new);
actx->idx[menu->current]->content->type = itype;
mutt_str_replace(&actx->idx[menu->current]->content->subtype, p);
for (; m; m = m->next)
{
- if (actx->idxlen == actx->idxmax)
- {
- safe_realloc(&actx->idx, sizeof(struct AttachPtr *) * (actx->idxmax += 5));
- for (int i = actx->idxlen; i < actx->idxmax; i++)
- actx->idx[i] = NULL;
- }
-
if (m->type == TYPEMULTIPART && m->parts &&
(compose || (parent_type == -1 && (mutt_strcasecmp("alternative", m->subtype) != 0))) &&
(!(WithCrypto & APPLICATION_PGP) || !mutt_is_multipart_encrypted(m)))
}
else
{
- if (!actx->idx[actx->idxlen])
- actx->idx[actx->idxlen] = safe_calloc(1, sizeof(struct AttachPtr));
-
- new = actx->idx[actx->idxlen++];
+ new = safe_calloc(1, sizeof(struct AttachPtr));
+ mutt_actx_add_attach(actx, new, NULL);
new->content = m;
m->aptr = new;
new->parent_type = parent_type;
static void update_attach_index(struct AttachCtx *actx, struct Body *cur, struct Menu *menu)
{
- while (--(actx->idxlen) >= 0)
- actx->idx[actx->idxlen]->content = NULL;
- actx->idxlen = 0;
-
+ mutt_actx_free_entries(actx);
mutt_gen_attach_list(actx, cur, -1, 0, 0);
menu->max = actx->idxlen;