diff options
-rw-r--r-- | attach.c | 35 | ||||
-rw-r--r-- | attach.h | 2 | ||||
-rw-r--r-- | compose.c | 90 | ||||
-rw-r--r-- | recvattach.c | 19 |
4 files changed, 67 insertions, 79 deletions
@@ -1042,15 +1042,26 @@ int mutt_print_attachment (FILE *fp, BODY *a) } } -void mutt_free_attach_context (ATTACH_CONTEXT **pactx) +void mutt_actx_add_attach (ATTACH_CONTEXT *actx, ATTACHPTR *attach, MUTTMENU *menu) { int i; - ATTACH_CONTEXT *actx; - if (!pactx || !*pactx) - return; + if (actx->idxlen == actx->idxmax) + { + actx->idxmax += 5; + safe_realloc (&actx->idx, sizeof (ATTACHPTR *) * actx->idxmax); + for (i = actx->idxlen; i < actx->idxmax; i++) + actx->idx[i] = NULL; + if (menu) + menu->data = actx->idx; + } - actx = *pactx; + actx->idx[actx->idxlen++] = attach; +} + +void mutt_actx_free_entries (ATTACH_CONTEXT *actx) +{ + int i; for (i = 0; i < actx->idxlen; i++) { @@ -1059,7 +1070,19 @@ void mutt_free_attach_context (ATTACH_CONTEXT **pactx) FREE (&actx->idx[i]->tree); FREE (&actx->idx[i]); } - FREE (&actx->idx); + actx->idxlen = 0; +} + +void mutt_free_attach_context (ATTACH_CONTEXT **pactx) +{ + ATTACH_CONTEXT *actx; + + if (!pactx || !*pactx) + return; + + actx = *pactx; + mutt_actx_free_entries (actx); + FREE (&actx->idx); FREE (pactx); /* __FREE_CHECKED__ */ } @@ -59,6 +59,8 @@ void mutt_attach_resend (FILE *, HEADER *, ATTACH_CONTEXT *, BODY *); void mutt_attach_forward (FILE *, HEADER *, ATTACH_CONTEXT *, BODY *); void mutt_attach_reply (FILE *, HEADER *, ATTACH_CONTEXT *, BODY *, int); +void mutt_actx_add_attach (ATTACH_CONTEXT *actx, ATTACHPTR *attach, MUTTMENU *menu); +void mutt_actx_free_entries (ATTACH_CONTEXT *actx); void mutt_free_attach_context (ATTACH_CONTEXT **pactx); #endif /* _ATTACH_H_ */ @@ -450,13 +450,14 @@ static int delete_attachment (MUTTMENU *menu, short *idxlen, int x) return (0); } -static void update_idx (MUTTMENU *menu, ATTACH_CONTEXT *actx) +static void update_idx (MUTTMENU *menu, ATTACH_CONTEXT *actx, 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; } @@ -646,6 +647,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ char fname[_POSIX_PATH_MAX]; MUTTMENU *menu; ATTACH_CONTEXT *actx; + ATTACHPTR *new; int i, close = 0; int r = -1; /* return value */ int op = 0; @@ -784,12 +786,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ /* 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; @@ -803,24 +800,19 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ case OP_COMPOSE_ATTACH_KEY: if (!(WithCrypto & APPLICATION_PGP)) - break; - if (actx->idxlen == actx->idxmax) - { - safe_realloc (&actx->idx, sizeof (ATTACHPTR *) * (actx->idxmax += 5)); - menu->data = actx->idx; - } - - actx->idx[actx->idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); - if ((actx->idx[actx->idxlen]->content = crypt_pgp_make_key_attachment(NULL)) != NULL) + break; + + new = (ATTACHPTR *) safe_calloc (1, sizeof (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; - + mutt_message_hook (NULL, msg, MUTT_SEND2HOOK); break; @@ -839,32 +831,26 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ *fname == '\0') break; - if (actx->idxlen + numfiles >= actx->idxmax) - { - safe_realloc (&actx->idx, sizeof (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] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); - actx->idx[actx->idxlen]->unowned = 1; - actx->idx[actx->idxlen]->content = mutt_make_file_attach (att); - if (actx->idx[actx->idxlen]->content != NULL) - update_idx (menu, actx); + new = (ATTACHPTR *) safe_calloc (1, sizeof (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]); } - + FREE (&files); if (!error) mutt_clear_error (); @@ -923,7 +909,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ this = Context; /* remember current folder and sort methods*/ oldSort = Sort; oldSortAux = SortAux; - + Context = ctx; set_option(OPTATTACHMSG); mutt_message _("Tag the messages you want to attach!"); @@ -941,25 +927,19 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ break; } - if (actx->idxlen + Context->tagged >= actx->idxmax) - { - safe_realloc (&actx->idx, sizeof (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] = (ATTACHPTR *) safe_calloc (1, sizeof (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 = (ATTACHPTR *) safe_calloc (1, sizeof (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); } } } @@ -1254,28 +1234,24 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ mutt_error (_("Unknown Content-Type %s"), type); continue; } - if (actx->idxlen == actx->idxmax) - { - safe_realloc (&actx->idx, sizeof (ATTACHPTR *) * (actx->idxmax += 5)); - menu->data = actx->idx; - } - actx->idx[actx->idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); + new = (ATTACHPTR *) safe_calloc (1, sizeof (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); diff --git a/recvattach.c b/recvattach.c index 120f6bf4..02e80e84 100644 --- a/recvattach.c +++ b/recvattach.c @@ -105,17 +105,9 @@ void mutt_gen_attach_list (ATTACH_CONTEXT *actx, int compose) { ATTACHPTR *new; - int i; for (; m; m = m->next) { - if (actx->idxlen == actx->idxmax) - { - safe_realloc (&actx->idx, sizeof (ATTACHPTR *) * (actx->idxmax += 5)); - for (i = actx->idxlen; i < actx->idxmax; i++) - actx->idx[i] = NULL; - } - if (m->type == TYPEMULTIPART && m->parts && (compose || (parent_type == -1 && ascii_strcasecmp ("alternative", m->subtype))) && (!(WithCrypto & APPLICATION_PGP) || !mutt_is_multipart_encrypted(m)) @@ -125,10 +117,8 @@ void mutt_gen_attach_list (ATTACH_CONTEXT *actx, } else { - if (!actx->idx[actx->idxlen]) - actx->idx[actx->idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); - - new = actx->idx[actx->idxlen++]; + new = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); + mutt_actx_add_attach (actx, new, NULL); new->content = m; m->aptr = new; new->parent_type = parent_type; @@ -809,10 +799,7 @@ void mutt_print_attachment_list (FILE *fp, int tag, BODY *top) static void mutt_update_attach_index (ATTACH_CONTEXT *actx, BODY *cur, MUTTMENU *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; |