2 * Copyright (C) 1996-2000,2002,2007 Michael R. Elkins <me@mutt.org>
3 * Copyright (C) 1999-2006 Thomas Roessler <roessler@does-not-exist.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "mutt_curses.h"
26 #include "mutt_menu.h"
33 #include "mutt_crypt.h"
43 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
45 #define CHECK_READONLY if (Context->readonly) \
48 mutt_error _(Mailbox_is_read_only); \
52 static struct mapping_t AttachHelp[] = {
53 { N_("Exit"), OP_EXIT },
54 { N_("Save"), OP_SAVE },
55 { N_("Pipe"), OP_PIPE },
56 { N_("Print"), OP_PRINT },
57 { N_("Help"), OP_HELP },
61 void mutt_update_tree (ATTACHPTR **idx, short idxlen)
67 for (x = 0; x < idxlen; x++)
70 if (2 * (idx[x]->level + 2) < sizeof (buf))
74 s = buf + 2 * (idx[x]->level - 1);
75 *s++ = (idx[x]->content->next) ? M_TREE_LTEE : M_TREE_LLCORNER;
86 if (mutt_strcmp (idx[x]->tree, buf) != 0)
87 mutt_str_replace (&idx[x]->tree, buf);
90 idx[x]->tree = safe_strdup (buf);
92 if (2 * (idx[x]->level + 2) < sizeof (buf) && idx[x]->level)
94 s = buf + 2 * (idx[x]->level - 1);
95 *s++ = (idx[x]->content->next) ? '\005' : '\006';
101 ATTACHPTR **mutt_gen_attach_list (BODY *m,
112 for (; m; m = m->next)
114 if (*idxlen == *idxmax)
116 safe_realloc (&idx, sizeof (ATTACHPTR *) * ((*idxmax) += 5));
117 for (i = *idxlen; i < *idxmax; i++)
121 if (m->type == TYPEMULTIPART && m->parts
122 && (compose || (parent_type == -1 && ascii_strcasecmp ("alternative", m->subtype)))
123 && (!(WithCrypto & APPLICATION_PGP) || !mutt_is_multipart_encrypted(m))
126 idx = mutt_gen_attach_list (m->parts, m->type, idx, idxlen, idxmax, level, compose);
131 idx[*idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
133 new = idx[(*idxlen)++];
136 new->parent_type = parent_type;
139 /* We don't support multipart messages in the compose menu yet */
140 if (!compose && !m->collapsed &&
141 ((m->type == TYPEMULTIPART
142 && (!(WithCrypto & APPLICATION_PGP)
143 || !mutt_is_multipart_encrypted (m))
145 || mutt_is_message_type(m->type, m->subtype)))
147 idx = mutt_gen_attach_list (m->parts, m->type, idx, idxlen, idxmax, level + 1, compose);
153 mutt_update_tree (idx, *idxlen);
158 /* %c = character set: convert?
162 * %e = MIME content-transfer-encoding
164 * %I = content-disposition, either I (inline) or A (attachment)
167 * %m = major MIME type
169 * %n = attachment number
173 const char *mutt_attach_fmt (char *dest,
179 const char *ifstring,
180 const char *elsestring,
185 char tmp[SHORT_STRING];
186 char charset[SHORT_STRING];
187 ATTACHPTR *aptr = (ATTACHPTR *) data;
188 int optional = (flags & M_FORMAT_OPTIONAL);
196 if (mutt_is_text_part (aptr->content) &&
197 mutt_get_body_charset (charset, sizeof (charset), aptr->content))
198 mutt_format_s (dest, destlen, prefix, charset);
200 mutt_format_s (dest, destlen, prefix, "");
202 else if (!mutt_is_text_part (aptr->content) ||
203 !mutt_get_body_charset (charset, sizeof (charset), aptr->content))
210 snprintf (fmt, sizeof (fmt), "%%%sc", prefix);
211 snprintf (dest, destlen, fmt, aptr->content->type != TYPETEXT ||
212 aptr->content->noconv ? 'n' : 'c');
214 else if (aptr->content->type != TYPETEXT || aptr->content->noconv)
220 if (aptr->content->description)
222 mutt_format_s (dest, destlen, prefix, aptr->content->description);
225 if (mutt_is_message_type(aptr->content->type, aptr->content->subtype) &&
226 MsgFmt && aptr->content->hdr)
228 char s[SHORT_STRING];
229 _mutt_make_string (s, sizeof (s), MsgFmt, NULL, aptr->content->hdr,
230 M_FORMAT_FORCESUBJ | M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR);
233 mutt_format_s (dest, destlen, prefix, s);
237 if (!aptr->content->filename)
239 mutt_format_s (dest, destlen, prefix, "<no description>");
243 else if(aptr->content->description ||
244 (mutt_is_message_type (aptr->content->type, aptr->content->subtype)
245 && MsgFmt && aptr->content->hdr))
247 /* FALLS THROUGH TO 'f' */
251 if (aptr->content->filename && *aptr->content->filename == '/')
253 char path[_POSIX_PATH_MAX];
255 strfcpy (path, aptr->content->filename, sizeof (path));
256 mutt_pretty_mailbox (path, sizeof (path));
257 mutt_format_s (dest, destlen, prefix, path);
260 mutt_format_s (dest, destlen, prefix, NONULL (aptr->content->filename));
262 else if(!aptr->content->filename)
267 snprintf (dest, destlen, "%c", aptr->content->deleted ? 'D' : ' ');
268 else if(!aptr->content->deleted)
273 mutt_format_s (dest, destlen, prefix,
274 ENCODING (aptr->content->encoding));
279 snprintf (dest, destlen, "%c",
280 (aptr->content->disposition == DISPINLINE) ? 'I' : 'A');
285 mutt_format_s (dest, destlen, prefix, TYPE (aptr->content));
289 mutt_format_s (dest, destlen, prefix, aptr->content->subtype);
290 else if(!aptr->content->subtype)
296 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
297 snprintf (dest, destlen, fmt, aptr->num + 1);
302 optional = aptr->content->attach_qualifies;
304 snprintf (fmt, sizeof (fmt), "%%%sc", prefix);
305 mutt_format_s (dest, destlen, fmt, "Q");
309 if (flags & M_FORMAT_STAT_FILE)
312 stat (aptr->content->filename, &st);
316 l = aptr->content->length;
320 mutt_pretty_size (tmp, sizeof(tmp), l);
321 mutt_format_s (dest, destlen, prefix, tmp);
329 snprintf (dest, destlen, "%c", aptr->content->tagged ? '*' : ' ');
330 else if(!aptr->content->tagged)
335 mutt_format_s_tree (dest, destlen, prefix, NONULL (aptr->tree));
336 else if (!aptr->tree)
341 snprintf (dest, destlen, "%c", aptr->content->unlink ? '-' : ' ');
342 else if (!aptr->content->unlink)
347 optional = (aptr->content->attach_count + aptr->content->attach_qualifies) != 0;
350 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
351 snprintf (dest, destlen, fmt, aptr->content->attach_count + aptr->content->attach_qualifies);
359 mutt_FormatString (dest, destlen, col, ifstring, mutt_attach_fmt, data, 0);
360 else if (flags & M_FORMAT_OPTIONAL)
361 mutt_FormatString (dest, destlen, col, elsestring, mutt_attach_fmt, data, 0);
365 static void attach_entry (char *b, size_t blen, MUTTMENU *menu, int num)
367 mutt_FormatString (b, blen, 0, NONULL (AttachFormat), mutt_attach_fmt, (unsigned long) (((ATTACHPTR **)menu->data)[num]), M_FORMAT_ARROWCURSOR);
370 int mutt_tag_attach (MUTTMENU *menu, int n, int m)
372 BODY *cur = ((ATTACHPTR **) menu->data)[n]->content;
373 int ot = cur->tagged;
375 cur->tagged = (m >= 0 ? m : !cur->tagged);
376 return cur->tagged - ot;
379 int mutt_is_message_type (int type, const char *subtype)
381 if (type != TYPEMESSAGE)
384 subtype = NONULL(subtype);
385 return (ascii_strcasecmp (subtype, "rfc822") == 0 || ascii_strcasecmp (subtype, "news") == 0);
388 static void prepend_curdir (char *dst, size_t dstlen)
392 if (!dst || !*dst || *dst == '/' || dstlen < 3 ||
393 /* XXX bad modularization, these are special to mutt_expand_path() */
394 !strchr ("~=+@<>!-^", *dst))
398 l = strlen (dst) + 2;
399 l = (l > dstlen ? dstlen : l);
400 memmove (dst + 2, dst, l);
406 static int mutt_query_save_attachment (FILE *fp, BODY *body, HEADER *hdr, char **directory)
409 char buf[_POSIX_PATH_MAX], tfile[_POSIX_PATH_MAX];
416 if (directory && *directory)
417 mutt_concat_path (buf, *directory, mutt_basename (body->filename), sizeof (buf));
419 strfcpy (buf, body->filename, sizeof (buf));
422 body->encoding != ENCBASE64 &&
423 body->encoding != ENCQUOTEDPRINTABLE &&
424 mutt_is_message_type(body->type, body->subtype))
425 mutt_default_save(buf, sizeof(buf), body->hdr);
429 prepend_curdir (buf, sizeof (buf));
431 prompt = _("Save to file: ");
434 if (mutt_get_field (prompt, buf, sizeof (buf), M_FILE | M_CLEAR) != 0
439 mutt_expand_path (buf, sizeof (buf));
443 body->encoding != ENCBASE64 &&
444 body->encoding != ENCQUOTEDPRINTABLE &&
445 mutt_is_message_type (body->type, body->subtype));
451 /* check to make sure that this file is really the one the user wants */
452 if ((rc = mutt_save_confirm (buf, &st)) == 1)
454 prompt = _("Save to file: ");
459 strfcpy(tfile, buf, sizeof(tfile));
463 if ((rc = mutt_check_overwrite (body->filename, buf, tfile, sizeof (tfile), &append, directory)) == -1)
467 prompt = _("Save to file: ");
472 mutt_message _("Saving...");
473 if (mutt_save_attachment (fp, body, tfile, append, (hdr || !is_message) ? hdr : body->hdr) == 0)
475 mutt_message _("Attachment saved.");
480 prompt = _("Save to file: ");
487 void mutt_save_attachment_list (FILE *fp, int tag, BODY *top, HEADER *hdr, MUTTMENU *menu)
489 char buf[_POSIX_PATH_MAX], tfile[_POSIX_PATH_MAX];
490 char *directory = NULL;
492 int last = menu ? menu->current : -1;
497 for (; top; top = top->next)
499 if (!tag || top->tagged)
501 if (!option (OPTATTACHSPLIT))
507 strfcpy (buf, mutt_basename (NONULL (top->filename)), sizeof (buf));
508 prepend_curdir (buf, sizeof (buf));
510 if (mutt_get_field (_("Save to file: "), buf, sizeof (buf),
511 M_FILE | M_CLEAR) != 0 || !buf[0])
513 mutt_expand_path (buf, sizeof (buf));
514 if (mutt_check_overwrite (top->filename, buf, tfile,
515 sizeof (tfile), &append, NULL))
517 rc = mutt_save_attachment (fp, top, tfile, append, hdr);
518 if (rc == 0 && AttachSep && (fpout = fopen (tfile,"a")) != NULL)
520 fprintf(fpout, "%s", AttachSep);
526 rc = mutt_save_attachment (fp, top, tfile, M_SAVE_APPEND, hdr);
527 if (rc == 0 && AttachSep && (fpout = fopen (tfile,"a")) != NULL)
529 fprintf(fpout, "%s", AttachSep);
536 if (tag && menu && top->aptr)
538 menu->oldcurrent = menu->current;
539 menu->current = top->aptr->num;
540 menu_check_recenter (menu);
541 menu->redraw |= REDRAW_MOTION;
545 if (mutt_query_save_attachment (fp, top, hdr, &directory) == -1)
550 mutt_save_attachment_list (fp, 1, top->parts, hdr, menu);
559 menu->oldcurrent = menu->current;
560 menu->current = last;
561 menu_check_recenter (menu);
562 menu->redraw |= REDRAW_MOTION;
565 if (!option (OPTATTACHSPLIT) && (rc == 0))
566 mutt_message _("Attachment saved.");
570 mutt_query_pipe_attachment (char *command, FILE *fp, BODY *body, int filter)
572 char tfile[_POSIX_PATH_MAX];
573 char warning[STRING+_POSIX_PATH_MAX];
577 snprintf (warning, sizeof (warning),
578 _("WARNING! You are about to overwrite %s, continue?"),
580 if (mutt_yesorno (warning, M_NO) != M_YES) {
589 if (mutt_pipe_attachment (fp, body, command, tfile))
593 mutt_unlink (body->filename);
594 mutt_rename_file (tfile, body->filename);
595 mutt_update_encoding (body);
596 mutt_message _("Attachment filtered.");
601 if (filter && tfile[0])
606 static void pipe_attachment (FILE *fp, BODY *b, STATE *state)
613 mutt_decode_attachment (b, state);
615 state_puts (AttachSep, state);
619 if ((ifp = fopen (b->filename, "r")) == NULL)
621 mutt_perror ("fopen");
624 mutt_copy_stream (ifp, state->fpout);
627 state_puts (AttachSep, state);
632 pipe_attachment_list (char *command, FILE *fp, int tag, BODY *top, int filter,
635 for (; top; top = top->next)
637 if (!tag || top->tagged)
639 if (!filter && !option (OPTATTACHSPLIT))
640 pipe_attachment (fp, top, state);
642 mutt_query_pipe_attachment (command, fp, top, filter);
645 pipe_attachment_list (command, fp, tag, top->parts, filter, state);
651 void mutt_pipe_attachment_list (FILE *fp, int tag, BODY *top, int filter)
654 char buf[SHORT_STRING];
658 filter = 0; /* sanity check: we can't filter in the recv case yet */
661 memset (&state, 0, sizeof (STATE));
663 if (mutt_get_field ((filter ? _("Filter through: ") : _("Pipe to: ")),
664 buf, sizeof (buf), M_CMD) != 0 || !buf[0])
667 mutt_expand_path (buf, sizeof (buf));
669 if (!filter && !option (OPTATTACHSPLIT))
672 thepid = mutt_create_filter (buf, &state.fpout, NULL, NULL);
673 pipe_attachment_list (buf, fp, tag, top, filter, &state);
674 fclose (state.fpout);
675 if (mutt_wait_filter (thepid) != 0 || option (OPTWAITKEY))
676 mutt_any_key_to_continue (NULL);
679 pipe_attachment_list (buf, fp, tag, top, filter, &state);
682 static int can_print (BODY *top, int tag)
686 for (; top; top = top->next)
688 snprintf (type, sizeof (type), "%s/%s", TYPE (top), top->subtype);
689 if (!tag || top->tagged)
691 if (!rfc1524_mailcap_lookup (top, type, NULL, M_PRINT))
693 if (ascii_strcasecmp ("text/plain", top->subtype) &&
694 ascii_strcasecmp ("application/postscript", top->subtype))
696 if (!mutt_can_decode (top))
698 mutt_error (_("I dont know how to print %s attachments!"), type);
705 return (can_print (top->parts, tag));
712 static void print_attachment_list (FILE *fp, int tag, BODY *top, STATE *state)
717 for (; top; top = top->next)
719 if (!tag || top->tagged)
721 snprintf (type, sizeof (type), "%s/%s", TYPE (top), top->subtype);
722 if (!option (OPTATTACHSPLIT) && !rfc1524_mailcap_lookup (top, type, NULL, M_PRINT))
724 if (!ascii_strcasecmp ("text/plain", top->subtype) ||
725 !ascii_strcasecmp ("application/postscript", top->subtype))
726 pipe_attachment (fp, top, state);
727 else if (mutt_can_decode (top))
729 /* decode and print */
731 char newfile[_POSIX_PATH_MAX] = "";
734 mutt_mktemp (newfile);
735 if (mutt_decode_save_attachment (fp, top, newfile, M_PRINTING, 0) == 0)
737 if ((ifp = fopen (newfile, "r")) != NULL)
739 mutt_copy_stream (ifp, state->fpout);
742 state_puts (AttachSep, state);
745 mutt_unlink (newfile);
749 mutt_print_attachment (fp, top);
752 print_attachment_list (fp, tag, top->parts, state);
758 void mutt_print_attachment_list (FILE *fp, int tag, BODY *top)
763 if (query_quadoption (OPT_PRINT, tag ? _("Print tagged attachment(s)?") : _("Print attachment?")) != M_YES)
766 if (!option (OPTATTACHSPLIT))
768 if (!can_print (top, tag))
771 memset (&state, 0, sizeof (STATE));
772 thepid = mutt_create_filter (NONULL (PrintCmd), &state.fpout, NULL, NULL);
773 print_attachment_list (fp, tag, top, &state);
774 fclose (state.fpout);
775 if (mutt_wait_filter (thepid) != 0 || option (OPTWAITKEY))
776 mutt_any_key_to_continue (NULL);
779 print_attachment_list (fp, tag, top, &state);
783 mutt_update_attach_index (BODY *cur, ATTACHPTR ***idxp,
784 short *idxlen, short *idxmax,
787 ATTACHPTR **idx = *idxp;
788 while (--(*idxlen) >= 0)
789 idx[(*idxlen)]->content = NULL;
792 idx = *idxp = mutt_gen_attach_list (cur, -1, idx, idxlen, idxmax, 0, 0);
797 if (menu->current >= menu->max)
798 menu->current = menu->max - 1;
799 menu_check_recenter (menu);
800 menu->redraw |= REDRAW_INDEX;
806 mutt_attach_display_loop (MUTTMENU *menu, int op, FILE *fp, HEADER *hdr,
807 BODY *cur, ATTACHPTR ***idxp, short *idxlen, short *idxmax,
810 ATTACHPTR **idx = *idxp;
812 int old_optweed = option (OPTWEED);
813 set_option (OPTWEED);
820 case OP_DISPLAY_HEADERS:
821 toggle_option (OPTWEED);
825 op = mutt_view_attachment (fp, idx[menu->current]->content, M_REGULAR,
830 case OP_MAIN_NEXT_UNDELETED: /* hack */
831 if (menu->current < menu->max - 1)
840 case OP_MAIN_PREV_UNDELETED: /* hack */
841 if (menu->current > 0)
850 /* when we edit the content-type, we should redisplay the attachment
852 mutt_edit_content_type (hdr, idx[menu->current]->content, fp);
855 mutt_update_attach_index (cur, idxp, idxlen, idxmax, menu);
860 /* functions which are passed through from the pager */
861 case OP_CHECK_TRADITIONAL:
862 if (!(WithCrypto & APPLICATION_PGP) || (hdr && hdr->security & PGP_TRADITIONAL_CHECKED))
868 case OP_ATTACH_COLLAPSE:
875 while (op != OP_NULL);
878 if (option (OPTWEED) != old_optweed)
879 toggle_option (OPTWEED);
884 static void attach_collapse (BODY *b, short collapse, short init, short just_one)
887 for (; b; b = b->next)
889 i = init || b->collapsed;
890 if (i && option (OPTDIGESTCOLLAPSE) && b->type == TYPEMULTIPART
891 && !ascii_strcasecmp (b->subtype, "digest"))
892 attach_collapse (b->parts, 1, 1, 0);
893 else if (b->type == TYPEMULTIPART || mutt_is_message_type (b->type, b->subtype))
894 attach_collapse (b->parts, collapse, i, 0);
895 b->collapsed = collapse;
901 void mutt_attach_init (BODY *b)
903 for (; b; b = b->next)
908 mutt_attach_init (b->parts);
912 static const char *Function_not_permitted = N_("Function not permitted in attach-message mode.");
914 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
917 mutt_error _(Function_not_permitted); \
924 void mutt_view_attachments (HEADER *hdr)
927 int need_secured = 0;
929 char helpstr[LONG_STRING];
934 ATTACHPTR **idx = NULL;
940 /* make sure we have parsed this message */
941 mutt_parse_mime_message (Context, hdr);
943 mutt_message_hook (Context, hdr, M_MESSAGEHOOK);
945 if ((msg = mx_open_message (Context, hdr->msgno)) == NULL)
949 if (WithCrypto && ((hdr->security & ENCRYPT) ||
950 (mutt_is_application_smime(hdr->content) & SMIMEOPAQUE)))
954 if ((hdr->security & ENCRYPT) && !crypt_valid_passphrase(hdr->security))
956 mx_close_message (&msg);
959 if ((WithCrypto & APPLICATION_SMIME) && (hdr->security & APPLICATION_SMIME))
962 crypt_smime_getkeys (hdr->env);
964 if (mutt_is_application_smime(hdr->content))
966 secured = ! crypt_smime_decrypt_mime (msg->fp, &fp,
970 if ((mutt_is_application_smime (cur) & SMIMEOPAQUE))
975 fp = NULL; cur = NULL;
976 secured = !crypt_smime_decrypt_mime (_fp, &fp, _cur, &cur);
978 mutt_free_body (&_cur);
985 if ((WithCrypto & APPLICATION_PGP) && (hdr->security & APPLICATION_PGP))
987 if (mutt_is_multipart_encrypted(hdr->content))
988 secured = !crypt_pgp_decrypt_mime (msg->fp, &fp, hdr->content, &cur);
993 if (need_secured && !secured)
995 mx_close_message (&msg);
996 mutt_error _("Can't decrypt encrypted message!");
1001 if (!WithCrypto || !need_secured)
1007 menu = mutt_new_menu (MENU_ATTACH);
1008 menu->title = _("Attachments");
1009 menu->make_entry = attach_entry;
1010 menu->tag = mutt_tag_attach;
1011 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_ATTACH, AttachHelp);
1013 mutt_attach_init (cur);
1014 attach_collapse (cur, 0, 1, 0);
1015 mutt_update_attach_index (cur, &idx, &idxlen, &idxmax, menu);
1020 op = mutt_menuLoop (menu);
1023 case OP_ATTACH_VIEW_MAILCAP:
1024 mutt_view_attachment (fp, idx[menu->current]->content, M_MAILCAP,
1026 menu->redraw = REDRAW_FULL;
1029 case OP_ATTACH_VIEW_TEXT:
1030 mutt_view_attachment (fp, idx[menu->current]->content, M_AS_TEXT,
1032 menu->redraw = REDRAW_FULL;
1035 case OP_DISPLAY_HEADERS:
1036 case OP_VIEW_ATTACH:
1037 op = mutt_attach_display_loop (menu, op, fp, hdr, cur, &idx, &idxlen, &idxmax, 1);
1038 menu->redraw = REDRAW_FULL;
1041 case OP_ATTACH_COLLAPSE:
1042 if (!idx[menu->current]->content->parts)
1044 mutt_error _("There are no subparts to show!");
1047 if (!idx[menu->current]->content->collapsed)
1048 attach_collapse (idx[menu->current]->content, 1, 0, 1);
1050 attach_collapse (idx[menu->current]->content, 0, 1, 1);
1051 mutt_update_attach_index (cur, &idx, &idxlen, &idxmax, menu);
1054 case OP_FORGET_PASSPHRASE:
1055 crypt_forget_passphrase ();
1058 case OP_EXTRACT_KEYS:
1059 if ((WithCrypto & APPLICATION_PGP))
1061 crypt_pgp_extract_keys_from_attachment_list (fp, menu->tagprefix,
1062 menu->tagprefix ? cur : idx[menu->current]->content);
1063 menu->redraw = REDRAW_FULL;
1067 case OP_CHECK_TRADITIONAL:
1068 if ((WithCrypto & APPLICATION_PGP)
1069 && crypt_pgp_check_traditional (fp, menu->tagprefix ? cur
1070 : idx[menu->current]->content,
1073 hdr->security = crypt_query (cur);
1074 menu->redraw = REDRAW_FULL;
1079 mutt_print_attachment_list (fp, menu->tagprefix,
1080 menu->tagprefix ? cur : idx[menu->current]->content);
1084 mutt_pipe_attachment_list (fp, menu->tagprefix,
1085 menu->tagprefix ? cur : idx[menu->current]->content, 0);
1089 mutt_save_attachment_list (fp, menu->tagprefix,
1090 menu->tagprefix ? cur : idx[menu->current]->content, hdr, menu);
1092 if (!menu->tagprefix && option (OPTRESOLVE) && menu->current < menu->max - 1)
1095 menu->redraw = REDRAW_MOTION_RESYNCH | REDRAW_FULL;
1102 if (Context->magic == M_POP)
1105 mutt_error _("Can't delete attachment from POP server.");
1110 if (WithCrypto && hdr->security & ~PGP_TRADITIONAL_CHECKED)
1113 "Deletion of attachments from encrypted messages is unsupported.");
1117 if (!menu->tagprefix)
1119 if (idx[menu->current]->parent_type == TYPEMULTIPART)
1121 idx[menu->current]->content->deleted = 1;
1122 if (option (OPTRESOLVE) && menu->current < menu->max - 1)
1125 menu->redraw = REDRAW_MOTION_RESYNCH;
1128 menu->redraw = REDRAW_CURRENT;
1132 "Only deletion of multipart attachments is supported.");
1138 for (x = 0; x < menu->max; x++)
1140 if (idx[x]->content->tagged)
1142 if (idx[x]->parent_type == TYPEMULTIPART)
1144 idx[x]->content->deleted = 1;
1145 menu->redraw = REDRAW_INDEX;
1149 "Only deletion of multipart attachments is supported.");
1158 if (!menu->tagprefix)
1160 idx[menu->current]->content->deleted = 0;
1161 if (option (OPTRESOLVE) && menu->current < menu->max - 1)
1164 menu->redraw = REDRAW_MOTION_RESYNCH;
1167 menu->redraw = REDRAW_CURRENT;
1173 for (x = 0; x < menu->max; x++)
1175 if (idx[x]->content->tagged)
1177 idx[x]->content->deleted = 0;
1178 menu->redraw = REDRAW_INDEX;
1186 mutt_attach_resend (fp, hdr, idx, idxlen,
1187 menu->tagprefix ? NULL : idx[menu->current]->content);
1188 menu->redraw = REDRAW_FULL;
1191 case OP_BOUNCE_MESSAGE:
1193 mutt_attach_bounce (fp, hdr, idx, idxlen,
1194 menu->tagprefix ? NULL : idx[menu->current]->content);
1195 menu->redraw = REDRAW_FULL;
1198 case OP_FORWARD_MESSAGE:
1200 mutt_attach_forward (fp, hdr, idx, idxlen,
1201 menu->tagprefix ? NULL : idx[menu->current]->content);
1202 menu->redraw = REDRAW_FULL;
1206 case OP_GROUP_REPLY:
1212 (op == OP_GROUP_REPLY ? SENDGROUPREPLY : 0) |
1213 (op == OP_LIST_REPLY ? SENDLISTREPLY : 0);
1214 mutt_attach_reply (fp, hdr, idx, idxlen,
1215 menu->tagprefix ? NULL : idx[menu->current]->content, flags);
1216 menu->redraw = REDRAW_FULL;
1220 mutt_edit_content_type (hdr, idx[menu->current]->content, fp);
1221 mutt_update_attach_index (cur, &idx, &idxlen, &idxmax, menu);
1225 mx_close_message (&msg);
1226 hdr->attach_del = 0;
1227 while (idxmax-- > 0)
1231 if (idx[idxmax]->content && idx[idxmax]->content->deleted)
1232 hdr->attach_del = 1;
1233 if (idx[idxmax]->content)
1234 idx[idxmax]->content->aptr = NULL;
1235 FREE (&idx[idxmax]->tree);
1236 FREE (&idx[idxmax]);
1238 if (hdr->attach_del)
1243 if (WithCrypto && need_secured && secured)
1246 mutt_free_body (&cur);
1249 mutt_menuDestroy (&menu);