diff options
-rw-r--r-- | attach.c | 17 | ||||
-rw-r--r-- | attach.h | 16 | ||||
-rw-r--r-- | compose.c | 253 | ||||
-rw-r--r-- | recvattach.c | 207 |
4 files changed, 248 insertions, 245 deletions
@@ -1042,3 +1042,20 @@ int mutt_print_attachment (FILE *fp, BODY *a) return 0; } } + +void mutt_free_attach_context (ATTACH_CONTEXT **pactx) +{ + int i; + ATTACH_CONTEXT *actx = *pactx; + + for (i = 0; i < actx->idxlen; i++) + { + if (actx->idx[i]->content) + actx->idx[i]->content->aptr = NULL; + FREE (&actx->idx[i]->tree); + FREE (&actx->idx[i]); + } + FREE (&actx->idx); + + FREE (pactx); /* __FREE_CHECKED__ */ +} @@ -33,14 +33,20 @@ typedef struct attachptr unsigned int unowned : 1; /* don't unlink on detach */ } ATTACHPTR; -ATTACHPTR **mutt_gen_attach_list (BODY *, int, ATTACHPTR **, short *, short *, - int, int); -void mutt_update_tree (ATTACHPTR **, short); +typedef struct attach_ctx +{ + ATTACHPTR **idx; + short idxlen; + short idxmax; +} ATTACH_CONTEXT; + +void mutt_gen_attach_list (ATTACH_CONTEXT *, BODY *, int, int, int); +void mutt_update_tree (ATTACH_CONTEXT *); int mutt_view_attachment (FILE*, BODY *, int, HEADER *, ATTACHPTR **, short); int mutt_tag_attach (MUTTMENU *menu, int n, int m); int mutt_attach_display_loop (MUTTMENU *menu, int op, FILE *fp, HEADER *hdr, - BODY *cur, ATTACHPTR ***idxp, short *idxlen, short *idxmax, + BODY *cur, ATTACH_CONTEXT *acvtx, int recv); @@ -53,4 +59,6 @@ void mutt_attach_resend (FILE *, HEADER *, ATTACHPTR **, short, BODY *); void mutt_attach_forward (FILE *, HEADER *, ATTACHPTR **, short, BODY *); void mutt_attach_reply (FILE *, HEADER *, ATTACHPTR **, short, BODY *, int); +void mutt_free_attach_context (ATTACH_CONTEXT **pactx); + #endif /* _ATTACH_H_ */ @@ -46,7 +46,7 @@ static const char* There_are_no_attachments = N_("There are no attachments."); -#define CHECK_COUNT if (idxlen == 0) { mutt_error _(There_are_no_attachments); break; } +#define CHECK_COUNT if (actx->idxlen == 0) { mutt_error _(There_are_no_attachments); break; } @@ -305,16 +305,16 @@ static void redraw_mix_line (LIST *chain) #endif /* MIXMASTER */ static int -check_attachments(ATTACHPTR **idx, short idxlen) +check_attachments(ATTACH_CONTEXT *actx) { int i, r; struct stat st; char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING]; - for (i = 0; i < idxlen; i++) + for (i = 0; i < actx->idxlen; i++) { - strfcpy(pretty, idx[i]->content->filename, sizeof(pretty)); - if(stat(idx[i]->content->filename, &st) != 0) + strfcpy(pretty, actx->idx[i]->content->filename, sizeof(pretty)); + if(stat(actx->idx[i]->content->filename, &st) != 0) { mutt_pretty_mailbox(pretty, sizeof (pretty)); mutt_error(_("%s [#%d] no longer exists!"), @@ -322,14 +322,14 @@ check_attachments(ATTACHPTR **idx, short idxlen) return -1; } - if(idx[i]->content->stamp < st.st_mtime) + if(actx->idx[i]->content->stamp < st.st_mtime) { mutt_pretty_mailbox(pretty, sizeof (pretty)); snprintf(msg, sizeof(msg), _("%s [#%d] modified. Update encoding?"), pretty, i+1); if((r = mutt_yesorno(msg, MUTT_YES)) == MUTT_YES) - mutt_update_encoding(idx[i]->content); + mutt_update_encoding(actx->idx[i]->content); else if(r == -1) return -1; } @@ -450,16 +450,15 @@ static int delete_attachment (MUTTMENU *menu, short *idxlen, int x) return (0); } -static void update_idx (MUTTMENU *menu, ATTACHPTR **idx, short idxlen) +static void update_idx (MUTTMENU *menu, ATTACH_CONTEXT *actx) { - idx[idxlen]->level = (idxlen > 0) ? idx[idxlen-1]->level : 0; - if (idxlen) - idx[idxlen - 1]->content->next = idx[idxlen]->content; - idx[idxlen]->content->aptr = idx[idxlen]; - menu->current = idxlen++; - mutt_update_tree (idx, idxlen); - menu->max = idxlen; - return; + actx->idx[actx->idxlen]->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++; + mutt_update_tree (actx); + menu->max = actx->idxlen; } @@ -646,9 +645,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ char buf[LONG_STRING]; char fname[_POSIX_PATH_MAX]; MUTTMENU *menu; - ATTACHPTR **idx = NULL; - short idxlen = 0; - short idxmax = 0; + ATTACH_CONTEXT *actx; int i, close = 0; int r = -1; /* return value */ int op = 0; @@ -665,15 +662,16 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ rd.msg = msg; rd.fcc = fcc; + actx = safe_calloc (sizeof(ATTACH_CONTEXT), 1); mutt_attach_init (msg->content); - idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1); + mutt_gen_attach_list (actx, msg->content, -1, 0, 1); menu = mutt_new_menu (MENU_COMPOSE); menu->offset = HDR_ATTACH; - menu->max = idxlen; + menu->max = actx->idxlen; menu->make_entry = snd_entry; menu->tag = mutt_tag_attach; - menu->data = idx; + menu->data = actx->idx; menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeHelp); menu->custom_menu_redraw = compose_menu_redraw; menu->redraw_data = &rd; @@ -784,17 +782,17 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ mutt_update_encoding (msg->content); /* attachments may have been added */ - if (idxlen && idx[idxlen - 1]->content->next) + if (actx->idxlen && actx->idx[actx->idxlen - 1]->content->next) { - for (i = 0; i < idxlen; i++) + for (i = 0; i < actx->idxlen; i++) { - FREE (&idx[i]->tree); - FREE (&idx[i]); + FREE (&actx->idx[i]->tree); + FREE (&actx->idx[i]); } - idxlen = 0; - idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1); - menu->data = idx; - menu->max = idxlen; + actx->idxlen = 0; + mutt_gen_attach_list (actx, msg->content, -1, 0, 1); + menu->data = actx->idx; + menu->max = actx->idxlen; } menu->redraw = REDRAW_FULL; @@ -806,20 +804,20 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ case OP_COMPOSE_ATTACH_KEY: if (!(WithCrypto & APPLICATION_PGP)) break; - if (idxlen == idxmax) + if (actx->idxlen == actx->idxmax) { - safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5)); - menu->data = idx; + safe_realloc (&actx->idx, sizeof (ATTACHPTR *) * (actx->idxmax += 5)); + menu->data = actx->idx; } - idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); - if ((idx[idxlen]->content = crypt_pgp_make_key_attachment(NULL)) != NULL) + actx->idx[actx->idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); + if ((actx->idx[actx->idxlen]->content = crypt_pgp_make_key_attachment(NULL)) != NULL) { - update_idx (menu, idx, idxlen++); + update_idx (menu, actx); menu->redraw |= REDRAW_INDEX; } else - FREE (&idx[idxlen]); + FREE (&actx->idx[actx->idxlen]); menu->redraw |= REDRAW_STATUS; @@ -841,10 +839,10 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ *fname == '\0') break; - if (idxlen + numfiles >= idxmax) + if (actx->idxlen + numfiles >= actx->idxmax) { - safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles)); - menu->data = idx; + safe_realloc (&actx->idx, sizeof (ATTACHPTR *) * (actx->idxmax += 5 + numfiles)); + menu->data = actx->idx; } error = 0; @@ -853,16 +851,16 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ for (i = 0; i < numfiles; i++) { char *att = files[i]; - idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); - idx[idxlen]->unowned = 1; - idx[idxlen]->content = mutt_make_file_attach (att); - if (idx[idxlen]->content != NULL) - update_idx (menu, idx, idxlen++); + 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); else { error = 1; mutt_error (_("Unable to attach %s!"), att); - FREE (&idx[idxlen]); + FREE (&actx->idx[actx->idxlen]); } FREE (&files[i]); } @@ -943,10 +941,10 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ break; } - if (idxlen + Context->tagged >= idxmax) + if (actx->idxlen + Context->tagged >= actx->idxmax) { - safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + Context->tagged)); - menu->data = idx; + safe_realloc (&actx->idx, sizeof (ATTACHPTR *) * (actx->idxmax += 5 + Context->tagged)); + menu->data = actx->idx; } for (i = 0; i < Context->msgcount; i++) @@ -954,14 +952,14 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ h = Context->hdrs[i]; if (h->tagged) { - idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); - idx[idxlen]->content = mutt_make_message_attach (Context, h, 1); - if (idx[idxlen]->content != NULL) - update_idx (menu, idx, idxlen++); + 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); else { mutt_error _("Unable to attach!"); - FREE (&idx[idxlen]); + FREE (&actx->idx[actx->idxlen]); } } } @@ -984,27 +982,27 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ case OP_DELETE: CHECK_COUNT; - if (idx[menu->current]->unowned) - idx[menu->current]->content->unlink = 0; - if (delete_attachment (menu, &idxlen, menu->current) == -1) + if (actx->idx[menu->current]->unowned) + actx->idx[menu->current]->content->unlink = 0; + if (delete_attachment (menu, &actx->idxlen, menu->current) == -1) break; - mutt_update_tree (idx, idxlen); - if (idxlen) + mutt_update_tree (actx); + if (actx->idxlen) { - if (menu->current > idxlen - 1) - menu->current = idxlen - 1; + if (menu->current > actx->idxlen - 1) + menu->current = actx->idxlen - 1; } else menu->current = 0; if (menu->current == 0) - msg->content = idx[0]->content; + msg->content = actx->idx[0]->content; menu->redraw |= REDRAW_STATUS; mutt_message_hook (NULL, msg, MUTT_SEND2HOOK); break; -#define CURRENT idx[menu->current]->content +#define CURRENT actx->idx[menu->current]->content case OP_COMPOSE_TOGGLE_RECODE: { @@ -1028,13 +1026,13 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ case OP_COMPOSE_EDIT_DESCRIPTION: CHECK_COUNT; strfcpy (buf, - idx[menu->current]->content->description ? - idx[menu->current]->content->description : "", + actx->idx[menu->current]->content->description ? + actx->idx[menu->current]->content->description : "", sizeof (buf)); /* header names should not be translated */ if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) { - mutt_str_replace (&idx[menu->current]->content->description, buf); + mutt_str_replace (&actx->idx[menu->current]->content->description, buf); menu->redraw = REDRAW_CURRENT; } mutt_message_hook (NULL, msg, MUTT_SEND2HOOK); @@ -1054,7 +1052,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ } else { - mutt_update_encoding(idx[menu->current]->content); + mutt_update_encoding(actx->idx[menu->current]->content); menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; } mutt_message_hook (NULL, msg, MUTT_SEND2HOOK); @@ -1062,17 +1060,17 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ case OP_COMPOSE_TOGGLE_DISPOSITION: /* toggle the content-disposition between inline/attachment */ - idx[menu->current]->content->disposition = (idx[menu->current]->content->disposition == DISPINLINE) ? DISPATTACH : DISPINLINE; + actx->idx[menu->current]->content->disposition = (actx->idx[menu->current]->content->disposition == DISPINLINE) ? DISPATTACH : DISPINLINE; menu->redraw = REDRAW_CURRENT; break; case OP_EDIT_TYPE: CHECK_COUNT; { - mutt_edit_content_type (NULL, idx[menu->current]->content, NULL); + mutt_edit_content_type (NULL, actx->idx[menu->current]->content, NULL); /* this may have been a change to text/something */ - mutt_update_encoding (idx[menu->current]->content); + mutt_update_encoding (actx->idx[menu->current]->content); menu->redraw = REDRAW_CURRENT; } @@ -1081,14 +1079,14 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ case OP_COMPOSE_EDIT_ENCODING: CHECK_COUNT; - strfcpy (buf, ENCODING (idx[menu->current]->content->encoding), + strfcpy (buf, ENCODING (actx->idx[menu->current]->content->encoding), sizeof (buf)); if (mutt_get_field ("Content-Transfer-Encoding: ", buf, sizeof (buf), 0) == 0 && buf[0]) { if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) { - idx[menu->current]->content->encoding = i; + actx->idx[menu->current]->content->encoding = i; menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; mutt_clear_error(); } @@ -1104,7 +1102,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ * users an opportunity to change settings from the ":" prompt. */ - if(check_attachments(idx, idxlen) != 0) + if(check_attachments(actx) != 0) { menu->redraw = REDRAW_FULL; break; @@ -1131,15 +1129,15 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ case OP_COMPOSE_EDIT_FILE: CHECK_COUNT; - mutt_edit_file (NONULL(Editor), idx[menu->current]->content->filename); - mutt_update_encoding (idx[menu->current]->content); + mutt_edit_file (NONULL(Editor), actx->idx[menu->current]->content->filename); + mutt_update_encoding (actx->idx[menu->current]->content); menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; mutt_message_hook (NULL, msg, MUTT_SEND2HOOK); break; case OP_COMPOSE_TOGGLE_UNLINK: CHECK_COUNT; - idx[menu->current]->content->unlink = !idx[menu->current]->content->unlink; + actx->idx[menu->current]->content->unlink = !actx->idx[menu->current]->content->unlink; #if 0 /* OPTRESOLVE is otherwise ignored on this menu. @@ -1165,7 +1163,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ } menu->redraw = REDRAW_FULL; } - else if (mutt_get_tmp_attachment(idx[menu->current]->content) == 0) + else if (mutt_get_tmp_attachment(actx->idx[menu->current]->content) == 0) menu->redraw = REDRAW_CURRENT; /* No send2hook since this doesn't change the message. */ @@ -1177,10 +1175,10 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ int ret; CHECK_COUNT; - if (idx[menu->current]->content->d_filename) - src = idx[menu->current]->content->d_filename; + if (actx->idx[menu->current]->content->d_filename) + src = actx->idx[menu->current]->content->d_filename; else - src = idx[menu->current]->content->filename; + src = actx->idx[menu->current]->content->filename; strfcpy (fname, mutt_basename (NONULL (src)), sizeof (fname)); ret = mutt_get_field (_("Send attachment with name: "), fname, sizeof (fname), MUTT_FILE); @@ -1190,7 +1188,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ * As opposed to RENAME_FILE, we don't check fname[0] because it's * valid to set an empty string here, to erase what was set */ - mutt_str_replace (&idx[menu->current]->content->d_filename, fname); + mutt_str_replace (&actx->idx[menu->current]->content->d_filename, fname); menu->redraw = REDRAW_CURRENT; } } @@ -1198,12 +1196,12 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ case OP_COMPOSE_RENAME_FILE: CHECK_COUNT; - strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname)); + strfcpy (fname, actx->idx[menu->current]->content->filename, sizeof (fname)); mutt_pretty_mailbox (fname, sizeof (fname)); if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), MUTT_FILE) == 0 && fname[0]) { - if (stat(idx[menu->current]->content->filename, &st) == -1) + if (stat(actx->idx[menu->current]->content->filename, &st) == -1) { /* L10N: "stat" is a system call. Do "man 2 stat" for more information. */ @@ -1212,14 +1210,14 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ } mutt_expand_path (fname, sizeof (fname)); - if(mutt_rename_file (idx[menu->current]->content->filename, fname)) + if(mutt_rename_file (actx->idx[menu->current]->content->filename, fname)) break; - mutt_str_replace (&idx[menu->current]->content->filename, fname); + mutt_str_replace (&actx->idx[menu->current]->content->filename, fname); menu->redraw = REDRAW_CURRENT; - if(idx[menu->current]->content->stamp >= st.st_mtime) - mutt_stamp_attachment(idx[menu->current]->content); + if(actx->idx[menu->current]->content->stamp >= st.st_mtime) + mutt_stamp_attachment(actx->idx[menu->current]->content); } mutt_message_hook (NULL, msg, MUTT_SEND2HOOK); @@ -1256,37 +1254,37 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ mutt_error (_("Unknown Content-Type %s"), type); continue; } - if (idxlen == idxmax) + if (actx->idxlen == actx->idxmax) { - safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5)); - menu->data = idx; + safe_realloc (&actx->idx, sizeof (ATTACHPTR *) * (actx->idxmax += 5)); + menu->data = actx->idx; } - idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); + actx->idx[actx->idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); /* Touch the file */ if (!(fp = safe_fopen (fname, "w"))) { mutt_error (_("Can't create file %s"), fname); - FREE (&idx[idxlen]); + FREE (&actx->idx[actx->idxlen]); continue; } safe_fclose (&fp); - if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) + if ((actx->idx[actx->idxlen]->content = mutt_make_file_attach (fname)) == NULL) { mutt_error _("What we have here is a failure to make an attachment"); continue; } - update_idx (menu, idx, idxlen++); + update_idx (menu, actx); - idx[menu->current]->content->type = itype; - mutt_str_replace (&idx[menu->current]->content->subtype, p); - idx[menu->current]->content->unlink = 1; + actx->idx[menu->current]->content->type = itype; + mutt_str_replace (&actx->idx[menu->current]->content->subtype, p); + actx->idx[menu->current]->content->unlink = 1; menu->redraw |= REDRAW_INDEX | REDRAW_STATUS; - if (mutt_compose_attachment (idx[menu->current]->content)) + if (mutt_compose_attachment (actx->idx[menu->current]->content)) { - mutt_update_encoding (idx[menu->current]->content); + mutt_update_encoding (actx->idx[menu->current]->content); menu->redraw = REDRAW_FULL; } } @@ -1295,9 +1293,9 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ case OP_COMPOSE_EDIT_MIME: CHECK_COUNT; - if (mutt_edit_attachment (idx[menu->current]->content)) + if (mutt_edit_attachment (actx->idx[menu->current]->content)) { - mutt_update_encoding (idx[menu->current]->content); + mutt_update_encoding (actx->idx[menu->current]->content); menu->redraw = REDRAW_FULL; } mutt_message_hook (NULL, msg, MUTT_SEND2HOOK); @@ -1306,27 +1304,27 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ case OP_VIEW_ATTACH: case OP_DISPLAY_HEADERS: CHECK_COUNT; - mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen, NULL, 0); + mutt_attach_display_loop (menu, op, NULL, NULL, NULL, actx, 0); menu->redraw = REDRAW_FULL; /* no send2hook, since this doesn't modify the message */ break; case OP_SAVE: CHECK_COUNT; - mutt_save_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, NULL, menu); + mutt_save_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : actx->idx[menu->current]->content, NULL, menu); /* no send2hook, since this doesn't modify the message */ break; case OP_PRINT: CHECK_COUNT; - mutt_print_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content); + mutt_print_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : actx->idx[menu->current]->content); /* no send2hook, since this doesn't modify the message */ break; case OP_PIPE: case OP_FILTER: CHECK_COUNT; - mutt_pipe_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, op == OP_FILTER); + mutt_pipe_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : actx->idx[menu->current]->content, op == OP_FILTER); if (op == OP_FILTER) /* cte might have changed */ menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT; menu->redraw |= REDRAW_STATUS; @@ -1336,24 +1334,24 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ case OP_EXIT: if ((i = query_quadoption (OPT_POSTPONE, _("Postpone this message?"))) == MUTT_NO) { - for (i = 0; i < idxlen; i++) - if (idx[i]->unowned) - idx[i]->content->unlink = 0; + for (i = 0; i < actx->idxlen; i++) + if (actx->idx[i]->unowned) + actx->idx[i]->content->unlink = 0; if (!(flags & MUTT_COMPOSE_NOFREEHEADER)) { - while (idxlen-- > 0) + while (actx->idxlen-- > 0) { /* avoid freeing other attachments */ - idx[idxlen]->content->next = NULL; - idx[idxlen]->content->parts = NULL; - mutt_free_body (&idx[idxlen]->content); - FREE (&idx[idxlen]->tree); - FREE (&idx[idxlen]); + actx->idx[actx->idxlen]->content->next = NULL; + actx->idx[actx->idxlen]->content->parts = NULL; + mutt_free_body (&actx->idx[actx->idxlen]->content); + FREE (&actx->idx[actx->idxlen]->tree); + FREE (&actx->idx[actx->idxlen]); } - FREE (&idx); - idxlen = 0; - idxmax = 0; + FREE (&actx->idx); + actx->idxlen = 0; + actx->idxmax = 0; } r = -1; loop = 0; @@ -1366,7 +1364,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ case OP_COMPOSE_POSTPONE_MESSAGE: - if(check_attachments(idx, idxlen) != 0) + if(check_attachments(actx) != 0) { menu->redraw = REDRAW_FULL; break; @@ -1396,8 +1394,8 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ strfcpy (fname, NONULL (Context->path), sizeof (fname)); mutt_pretty_mailbox (fname, sizeof (fname)); } - if (idxlen) - msg->content = idx[0]->content; + if (actx->idxlen) + msg->content = actx->idx[0]->content; if (mutt_enter_fname (_("Write message to mailbox"), fname, sizeof (fname), 1) != -1 && fname[0]) { @@ -1490,20 +1488,21 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ mutt_pop_current_menu (menu); mutt_menuDestroy (&menu); - if (idxlen) + if (actx->idxlen) { - msg->content = idx[0]->content; - for (i = 0; i < idxlen; i++) + msg->content = actx->idx[0]->content; + for (i = 0; i < actx->idxlen; i++) { - idx[i]->content->aptr = NULL; - FREE (&idx[i]->tree); - FREE (&idx[i]); + actx->idx[i]->content->aptr = NULL; + FREE (&actx->idx[i]->tree); + FREE (&actx->idx[i]); } } else msg->content = NULL; - FREE (&idx); + FREE (&actx->idx); + FREE (&actx); return (r); } diff --git a/recvattach.c b/recvattach.c index 0f079b12..2e09d844 100644 --- a/recvattach.c +++ b/recvattach.c @@ -58,21 +58,21 @@ static const struct mapping_t AttachHelp[] = { { NULL, 0 } }; -void mutt_update_tree (ATTACHPTR **idx, short idxlen) +void mutt_update_tree (ATTACH_CONTEXT *actx) { char buf[STRING]; char *s; int x; - for (x = 0; x < idxlen; x++) + for (x = 0; x < actx->idxlen; x++) { - idx[x]->num = x; - if (2 * (idx[x]->level + 2) < sizeof (buf)) + actx->idx[x]->num = x; + if (2 * (actx->idx[x]->level + 2) < sizeof (buf)) { - if (idx[x]->level) + if (actx->idx[x]->level) { - s = buf + 2 * (idx[x]->level - 1); - *s++ = (idx[x]->content->next) ? MUTT_TREE_LTEE : MUTT_TREE_LLCORNER; + s = buf + 2 * (actx->idx[x]->level - 1); + *s++ = (actx->idx[x]->content->next) ? MUTT_TREE_LTEE : MUTT_TREE_LLCORNER; *s++ = MUTT_TREE_HLINE; *s++ = MUTT_TREE_RARROW; } @@ -81,41 +81,39 @@ void mutt_update_tree (ATTACHPTR **idx, short idxlen) *s = 0; } - if (idx[x]->tree) + if (actx->idx[x]->tree) { - if (mutt_strcmp (idx[x]->tree, buf) != 0) - mutt_str_replace (&idx[x]->tree, buf); + if (mutt_strcmp (actx->idx[x]->tree, buf) != 0) + mutt_str_replace (&actx->idx[x]->tree, buf); } else - idx[x]->tree = safe_strdup (buf); + actx->idx[x]->tree = safe_strdup (buf); - if (2 * (idx[x]->level + 2) < sizeof (buf) && idx[x]->level) + if (2 * (actx->idx[x]->level + 2) < sizeof (buf) && actx->idx[x]->level) { - s = buf + 2 * (idx[x]->level - 1); - *s++ = (idx[x]->content->next) ? '\005' : '\006'; + s = buf + 2 * (actx->idx[x]->level - 1); + *s++ = (actx->idx[x]->content->next) ? '\005' : '\006'; *s++ = '\006'; } } } -ATTACHPTR **mutt_gen_attach_list (BODY *m, - int parent_type, - ATTACHPTR **idx, - short *idxlen, - short *idxmax, - int level, - int compose) +void mutt_gen_attach_list (ATTACH_CONTEXT *actx, + BODY *m, + int parent_type, + int level, + int compose) { ATTACHPTR *new; int i; - + for (; m; m = m->next) { - if (*idxlen == *idxmax) + if (actx->idxlen == actx->idxmax) { - safe_realloc (&idx, sizeof (ATTACHPTR *) * ((*idxmax) += 5)); - for (i = *idxlen; i < *idxmax; i++) - idx[i] = NULL; + 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 @@ -123,36 +121,34 @@ ATTACHPTR **mutt_gen_attach_list (BODY *m, && (!(WithCrypto & APPLICATION_PGP) || !mutt_is_multipart_encrypted(m)) ) { - idx = mutt_gen_attach_list (m->parts, m->type, idx, idxlen, idxmax, level, compose); + mutt_gen_attach_list (actx, m->parts, m->type, level, compose); } else { - if (!idx[*idxlen]) - idx[*idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); + if (!actx->idx[actx->idxlen]) + actx->idx[actx->idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); - new = idx[(*idxlen)++]; + new = actx->idx[actx->idxlen++]; new->content = m; m->aptr = new; new->parent_type = parent_type; new->level = level; /* We don't support multipart messages in the compose menu yet */ - if (!compose && !m->collapsed && + if (!compose && !m->collapsed && ((m->type == TYPEMULTIPART && (!(WithCrypto & APPLICATION_PGP) || !mutt_is_multipart_encrypted (m)) ) || mutt_is_message_type(m->type, m->subtype))) { - idx = mutt_gen_attach_list (m->parts, m->type, idx, idxlen, idxmax, level + 1, compose); + mutt_gen_attach_list (actx, m->parts, m->type, level + 1, compose); } } } if (level == 0) - mutt_update_tree (idx, *idxlen); - - return (idx); + mutt_update_tree (actx); } /* %c = character set: convert? @@ -811,39 +807,28 @@ void mutt_print_attachment_list (FILE *fp, int tag, BODY *top) } static void -mutt_update_attach_index (BODY *cur, ATTACHPTR ***idxp, - short *idxlen, short *idxmax, - MUTTMENU *menu) +mutt_update_attach_index (ATTACH_CONTEXT *actx, BODY *cur, MUTTMENU *menu) { - ATTACHPTR **idx = *idxp; - while (--(*idxlen) >= 0) - idx[(*idxlen)]->content = NULL; - *idxlen = 0; + while (--(actx->idxlen) >= 0) + actx->idx[actx->idxlen]->content = NULL; + actx->idxlen = 0; - idx = *idxp = mutt_gen_attach_list (cur, -1, idx, idxlen, idxmax, 0, 0); - - menu->max = *idxlen; - menu->data = *idxp; + mutt_gen_attach_list (actx, cur, -1, 0, 0); + + menu->max = actx->idxlen; + menu->data = actx->idx; if (menu->current >= menu->max) menu->current = menu->max - 1; menu_check_recenter (menu); menu->redraw |= REDRAW_INDEX; - } int mutt_attach_display_loop (MUTTMENU *menu, int op, FILE *fp, HEADER *hdr, - BODY *cur, ATTACHPTR ***idxp, short *idxlen, short *idxmax, - int recv) + BODY *cur, ATTACH_CONTEXT *actx, int recv) { - ATTACHPTR **idx = *idxp; -#if 0 - int old_optweed = option (OPTWEED); - set_option (OPTWEED); -#endif - do { switch (op) @@ -853,8 +838,8 @@ mutt_attach_display_loop (MUTTMENU *menu, int op, FILE *fp, HEADER *hdr, /* fall through */ case OP_VIEW_ATTACH: - op = mutt_view_attachment (fp, idx[menu->current]->content, MUTT_REGULAR, - hdr, idx, *idxlen); + op = mutt_view_attachment (fp, actx->idx[menu->current]->content, MUTT_REGULAR, + hdr, actx->idx, actx->idxlen); break; case OP_NEXT_ENTRY: @@ -880,12 +865,9 @@ mutt_attach_display_loop (MUTTMENU *menu, int op, FILE *fp, HEADER *hdr, case OP_EDIT_TYPE: /* when we edit the content-type, we should redisplay the attachment immediately */ - mutt_edit_content_type (hdr, idx[menu->current]->content, fp); - if (idxmax) - { - mutt_update_attach_index (cur, idxp, idxlen, idxmax, menu); - idx = *idxp; - } + mutt_edit_content_type (hdr, actx->idx[menu->current]->content, fp); + if (recv) + mutt_update_attach_index (actx, cur, menu); op = OP_VIEW_ATTACH; break; /* functions which are passed through from the pager */ @@ -962,17 +944,16 @@ void mutt_view_attachments (HEADER *hdr) BODY *cur = NULL; MESSAGE *msg; FILE *fp; - ATTACHPTR **idx = NULL; - short idxlen = 0; - short idxmax = 0; + ATTACH_CONTEXT *actx; int flags = 0; int op = OP_NULL; - + int i; + /* make sure we have parsed this message */ mutt_parse_mime_message (Context, hdr); mutt_message_hook (Context, hdr, MUTT_MESSAGEHOOK); - + if ((msg = mx_open_message (Context, hdr->msgno)) == NULL) return; @@ -1043,9 +1024,10 @@ void mutt_view_attachments (HEADER *hdr) menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_ATTACH, AttachHelp); mutt_push_current_menu (menu); + actx = safe_calloc (sizeof(ATTACH_CONTEXT), 1); mutt_attach_init (cur); attach_collapse (cur, 0, 1, 0); - mutt_update_attach_index (cur, &idx, &idxlen, &idxmax, menu); + mutt_update_attach_index (actx, cur, menu); FOREVER { @@ -1054,34 +1036,34 @@ void mutt_view_attachments (HEADER *hdr) switch (op) { case OP_ATTACH_VIEW_MAILCAP: - mutt_view_attachment (fp, idx[menu->current]->content, MUTT_MAILCAP, - hdr, idx, idxlen); + mutt_view_attachment (fp, actx->idx[menu->current]->content, MUTT_MAILCAP, + hdr, actx->idx, actx->idxlen); menu->redraw = REDRAW_FULL; break; case OP_ATTACH_VIEW_TEXT: - mutt_view_attachment (fp, idx[menu->current]->content, MUTT_AS_TEXT, - hdr, idx, idxlen); + mutt_view_attachment (fp, actx->idx[menu->current]->content, MUTT_AS_TEXT, + hdr, actx->idx, actx->idxlen); menu->redraw = REDRAW_FULL; break; case OP_DISPLAY_HEADERS: case OP_VIEW_ATTACH: - op = mutt_attach_display_loop (menu, op, fp, hdr, cur, &idx, &idxlen, &idxmax, 1); + op = mutt_attach_display_loop (menu, op, fp, hdr, cur, actx, 1); menu->redraw = REDRAW_FULL; continue; case OP_ATTACH_COLLAPSE: - if (!idx[menu->current]->content->parts) + if (!actx->idx[menu->current]->content->parts) { mutt_error _("There are no subparts to show!"); break; } - if (!idx[menu->current]->content->collapsed) - attach_collapse (idx[menu->current]->content, 1, 0, 1); + if (!actx->idx[menu->current]->content->collapsed) + attach_collapse (actx->idx[menu->current]->content, 1, 0, 1); else - attach_collapse (idx[menu->current]->content, 0, 1, 1); - mutt_update_attach_index (cur, &idx, &idxlen, &idxmax, menu); + attach_collapse (actx->idx[menu->current]->content, 0, 1, 1); + mutt_update_attach_index (actx, cur, menu); break; case OP_FORGET_PASSPHRASE: @@ -1092,7 +1074,7 @@ void mutt_view_attachments (HEADER *hdr) if ((WithCrypto & APPLICATION_PGP)) { crypt_pgp_extract_keys_from_attachment_list (fp, menu->tagprefix, - menu->tagprefix ? cur : idx[menu->current]->content); + menu->tagprefix ? cur : actx->idx[menu->current]->content); menu->redraw = REDRAW_FULL; } break; @@ -1100,7 +1082,7 @@ void mutt_view_attachments (HEADER *hdr) case OP_ |