2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4 * Copyright (C) 2004 g10 Code GmbH
6 * Parts were written/modified by:
7 * Nico Golde <nico@ngolde.de>
9 * This file is part of mutt-ng, see http://www.muttng.org/.
10 * It's licensed under the GNU General Public License,
11 * please see the file GPL in the top level source directory.
14 #include <lib-lib/lib-lib.h>
16 #include <lib-sys/unix.h>
17 #include <lib-mime/mime.h>
19 #include <lib-ui/lib-ui.h>
20 #include <lib-ui/enter.h>
21 #include <lib-ui/menu.h>
22 #include <lib-mx/mx.h>
27 #include "mutt_idna.h"
29 #include "recvattach.h"
36 mutt_error _("There are no attachments."); \
52 HDR_ATTACH = (HDR_FCC + 7)
55 #define HDR_XOFFSET 14
56 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
57 #define W (getmaxx(main_w) - HDR_XOFFSET)
59 static const char *Prompts[] = {
69 static void snd_entry (char *b, ssize_t blen, MUTTMENU * menu, int num) {
70 m_strformat(b, blen, getmaxx(main_w), AttachFormat, mutt_attach_fmt,
71 ((ATTACHPTR **)menu->data)[num], M_FORMAT_STAT_FILE);
74 static void redraw_crypt_lines (HEADER * msg)
79 mvwaddstr (main_w, HDR_CRYPT, 0, " Security: ");
80 else if (msg->security & APPLICATION_SMIME)
81 mvwaddstr (main_w, HDR_CRYPT, 0, " S/MIME: ");
82 else if (msg->security & APPLICATION_PGP)
83 mvwaddstr (main_w, HDR_CRYPT, 0, " PGP: ");
85 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
86 waddstr (main_w, _("Sign, Encrypt"));
87 else if (msg->security & ENCRYPT)
88 waddstr (main_w, _("Encrypt"));
89 else if (msg->security & SIGN)
90 waddstr (main_w, _("Sign"));
92 waddstr (main_w, _("Clear"));
94 if ((msg->security & APPLICATION_PGP)
95 && (msg->security & (ENCRYPT | SIGN))) {
96 if ((msg->security & INLINE))
97 waddstr (main_w, _(" (inline)"));
99 waddstr (main_w, _(" (PGP/MIME)"));
103 wmove (main_w, HDR_CRYPTINFO, 0);
105 if (msg->security & APPLICATION_PGP && msg->security & SIGN)
106 wprintw (main_w, "%s%s", _(" sign as: "),
107 PgpSignAs ? PgpSignAs : _("<default>"));
109 if (msg->security & APPLICATION_SMIME && msg->security & SIGN) {
110 wprintw (main_w, "%s%s", _(" sign as: "),
111 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
114 if ((msg->security & APPLICATION_SMIME)
115 && (msg->security & ENCRYPT)
116 && SmimeCryptAlg && *SmimeCryptAlg) {
117 mvwprintw (main_w, HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "),
118 NONULL (SmimeCryptAlg));
123 static int check_attachments (ATTACHPTR ** idx, short idxlen)
127 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + STRING];
129 for (i = 0; i < idxlen; i++) {
130 m_strcpy(pretty, sizeof(pretty), idx[i]->content->filename);
131 if (stat (idx[i]->content->filename, &st) != 0) {
132 mutt_pretty_mailbox (pretty);
133 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
137 if (idx[i]->content->stamp < st.st_mtime) {
138 mutt_pretty_mailbox (pretty);
139 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
142 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
143 mutt_update_encoding (idx[i]->content);
152 static void draw_envelope_addr (int line, address_t * addr)
157 rfc822_addrcat(buf, sizeof (buf), addr, 1);
158 mvwprintw (main_w, line, 0, TITLE_FMT, Prompts[line - 1]);
159 mutt_paddstr (main_w, W, buf);
162 static void draw_envelope (HEADER * msg, char *fcc)
164 draw_envelope_addr (HDR_FROM, msg->env->from);
165 draw_envelope_addr (HDR_TO, msg->env->to);
166 draw_envelope_addr (HDR_CC, msg->env->cc);
167 draw_envelope_addr (HDR_BCC, msg->env->bcc);
168 mvwprintw (main_w, HDR_SUBJECT, 0, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
169 mutt_paddstr (main_w, W, NONULL (msg->env->subject));
170 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
171 mvwprintw (main_w, HDR_FCC, 0, TITLE_FMT, Prompts[HDR_FCC - 1]);
172 mutt_paddstr (main_w, W, fcc);
174 redraw_crypt_lines (msg);
176 SETCOLOR(main_w, MT_COLOR_STATUS);
177 mvwaddstr (main_w, HDR_ATTACH - 1, 0, _("-- Attachments"));
178 BKGDSET(main_w, MT_COLOR_STATUS);
181 BKGDSET(main_w, MT_COLOR_NORMAL);
182 SETCOLOR(main_w, MT_COLOR_NORMAL);
185 static int edit_address_list (int line, address_t ** addr)
187 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
190 mutt_addrlist_to_local (*addr);
191 rfc822_addrcat(buf, sizeof (buf), *addr, 0);
192 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
193 address_list_wipe(addr);
194 *addr = mutt_parse_adrlist (*addr, buf);
195 *addr = mutt_expand_aliases (*addr);
198 if (option (OPTNEEDREDRAW)) {
199 unset_option (OPTNEEDREDRAW);
203 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
204 mutt_error (_("Warning: '%s' is a bad IDN."), err);
209 /* redraw the expanded list so the user can see the result */
211 rfc822_addrcat(buf, sizeof (buf), *addr, 1);
212 wmove (main_w, line, HDR_XOFFSET);
213 mutt_paddstr (main_w, W, buf);
218 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
220 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
223 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
225 if (x == 0 && menu->max == 1) {
226 mutt_error _("You may not delete the only attachment.");
228 idx[x]->content->tagged = 0;
232 for (y = 0; y < *idxlen; y++) {
233 if (idx[y]->content->next == idx[x]->content) {
234 idx[y]->content->next = idx[x]->content->next;
239 idx[x]->content->next = NULL;
240 idx[x]->content->parts = NULL;
241 body_list_wipe(&(idx[x]->content));
242 p_delete(&idx[x]->tree);
244 for (; x < *idxlen - 1; x++)
246 menu->max = --(*idxlen);
251 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
253 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
255 idx[idxlen - 1]->content->next = idx[idxlen]->content;
256 idx[idxlen]->content->aptr = idx[idxlen];
257 menu->current = idxlen++;
258 mutt_update_tree (idx, idxlen);
265 * cum_attachs_size: Cumulative Attachments Size
267 * Returns the total number of bytes used by the attachments in the
268 * attachment list _after_ content-transfer-encodings have been
272 static unsigned long cum_attachs_size(MUTTMENU * menu)
276 ATTACHPTR **idx = menu->data;
280 for (i = 0, s = 0; i < menu->max; i++) {
284 b->content = mutt_get_content_info (b->filename, b);
286 if ((info = b->content)) {
287 switch (b->encoding) {
288 case ENCQUOTEDPRINTABLE:
289 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
292 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
295 s += info->lobin + info->hibin + info->ascii + info->crlf;
305 * compose_format_str()
307 * %a = total number of attachments
308 * %h = hostname [option]
309 * %l = approx. length of current message (in bytes)
312 * This function is similar to status_format_str(). Look at that function for
313 * help when modifying this function.
315 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
318 static const char *compose_format_str (char *buf, ssize_t buflen, char op,
319 const char *src, const char *prefix,
322 anytype data, format_flag flags)
324 char fmt[STRING], tmp[STRING];
325 int optional = (flags & M_FORMAT_OPTIONAL);
326 MUTTMENU *menu = data.ptr;
330 case 'a': /* total number of attachments */
331 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
332 snprintf (buf, buflen, fmt, menu->max);
335 case 'h': /* hostname */
336 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
337 snprintf (buf, buflen, fmt, NONULL(mod_core.shorthost));
340 case 'l': /* approx length of current message in bytes */
341 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
342 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
343 snprintf (buf, buflen, fmt, tmp);
347 m_strcpy(buf, buflen, mutt_make_version());
359 if (flags & M_FORMAT_OPTIONAL)
360 compose_status_line(buf, buflen, menu, optional ? ifstr : elstr);
365 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
368 m_strformat(buf, buflen, getmaxx(main_w), p, compose_format_str, menu, 0);
373 * 1 message should be postponed
377 int mutt_compose_menu (HEADER * msg, /* structure for new message */
378 char *fcc, /* where to save a copy of the message */
380 HEADER * cur __attribute__ ((unused)))
381 { /* current message */
382 char buf[LONG_STRING];
383 char fname[_POSIX_PATH_MAX];
385 ATTACHPTR **idx = NULL;
389 int r = -1; /* return value */
392 int fccSet = 0; /* has the user edited the Fcc: field ? */
393 CONTEXT *ctx = NULL, *this = NULL;
395 /* Sort, SortAux could be changed in mutt_index_menu() */
396 int oldSort, oldSortAux;
399 mutt_attach_init (msg->content);
400 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
402 menu = mutt_new_menu ();
403 menu->menu = MENU_COMPOSE;
404 menu->offset = HDR_ATTACH;
406 menu->make_entry = snd_entry;
407 menu->tag = mutt_tag_attach;
411 switch (op = mutt_menuLoop (menu)) {
413 draw_envelope (msg, fcc);
414 menu->offset = HDR_ATTACH;
415 menu->pagelen = LINES - HDR_ATTACH - 2;
417 case OP_COMPOSE_EDIT_FROM:
418 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
419 mutt_message_hook (NULL, msg, M_SEND2HOOK);
421 case OP_COMPOSE_EDIT_TO:
422 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
423 mutt_message_hook (NULL, msg, M_SEND2HOOK);
425 case OP_COMPOSE_EDIT_BCC:
426 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
427 mutt_message_hook (NULL, msg, M_SEND2HOOK);
429 case OP_COMPOSE_EDIT_CC:
430 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
431 mutt_message_hook (NULL, msg, M_SEND2HOOK);
433 case OP_COMPOSE_EDIT_SUBJECT:
434 if (msg->env->subject)
435 m_strcpy(buf, sizeof(buf), msg->env->subject);
438 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
439 m_strreplace(&msg->env->subject, buf);
440 wmove (main_w, HDR_SUBJECT, HDR_XOFFSET);
442 if (msg->env->subject)
443 mutt_paddstr (main_w, W, msg->env->subject);
445 mutt_message_hook (NULL, msg, M_SEND2HOOK);
447 case OP_COMPOSE_EDIT_REPLY_TO:
448 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
449 mutt_message_hook (NULL, msg, M_SEND2HOOK);
451 case OP_COMPOSE_EDIT_FCC:
452 m_strcpy(buf, sizeof(buf), fcc);
453 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
454 m_strcpy(fcc, _POSIX_PATH_MAX, buf);
455 mutt_pretty_mailbox (fcc);
456 wmove (main_w, HDR_FCC, HDR_XOFFSET);
457 mutt_paddstr (main_w, W, fcc);
460 MAYBE_REDRAW (menu->redraw);
461 mutt_message_hook (NULL, msg, M_SEND2HOOK);
463 case OP_COMPOSE_EDIT_MESSAGE:
464 if (!option (OPTEDITHDRS)) {
465 mutt_edit_file(msg->content->filename);
466 mutt_update_encoding (msg->content);
467 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
468 mutt_message_hook (NULL, msg, M_SEND2HOOK);
472 case OP_COMPOSE_EDIT_HEADERS:
473 if ((op == OP_COMPOSE_EDIT_HEADERS ||
474 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
475 const char *tag = NULL;
478 mutt_env_to_local (msg->env);
479 mutt_edit_headers(msg->content->filename, msg, fcc, fcclen);
480 if (mutt_env_to_idna (msg->env, &tag, &err)) {
481 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
485 mutt_update_encoding (msg->content);
487 /* attachments may have been added */
488 if (idxlen && idx[idxlen - 1]->content->next) {
489 for (i = 0; i < idxlen; i++)
493 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
499 menu->redraw = REDRAW_FULL;
500 mutt_message_hook (NULL, msg, M_SEND2HOOK);
503 case OP_COMPOSE_ATTACH_FILE:
510 prompt = _("Attach file");
514 if (_mutt_enter_fname
515 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
516 &numfiles) == -1 || *fname == '\0')
519 if (idxlen + numfiles >= idxmax) {
520 p_realloc(&idx, idxmax += 5 + numfiles);
526 mutt_message _("Attaching selected files...");
528 for (i = 0; i < numfiles; i++) {
529 char *att = files[i];
531 idx[idxlen] = p_new(ATTACHPTR, 1);
532 idx[idxlen]->unowned = 1;
533 idx[idxlen]->content = mutt_make_file_attach (att);
534 if (idx[idxlen]->content != NULL)
535 update_idx (menu, idx, idxlen++);
538 mutt_error (_("Unable to attach %s!"), att);
539 p_delete(&idx[idxlen]);
547 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
549 mutt_message_hook (NULL, msg, M_SEND2HOOK);
552 case OP_COMPOSE_ATTACH_MESSAGE:
558 prompt = _("Open mailbox to attach message from");
563 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
564 mutt_pretty_mailbox (fname);
567 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
571 mutt_expand_path (fname, sizeof (fname));
572 if (mx_get_magic (fname) != M_IMAP && mx_get_magic (fname) != M_POP) {
573 /* check to make sure the file exists and is readable */
574 if (access (fname, R_OK) == -1) {
580 menu->redraw = REDRAW_FULL;
582 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
588 if (!ctx->msgcount) {
589 mx_close_mailbox (ctx, NULL);
591 mutt_error _("No messages in that folder.");
595 this = Context; /* remember current folder and sort methods */
597 oldSortAux = SortAux;
600 set_option (OPTATTACHMSG);
601 mutt_message _("Tag the messages you want to attach!");
603 closed = mutt_index_menu ();
604 unset_option (OPTATTACHMSG);
607 /* go back to the folder we started from */
609 /* Restore old $sort and $sort_aux */
611 SortAux = oldSortAux;
612 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
616 if (idxlen + Context->tagged >= idxmax) {
617 p_realloc(&idx, idxmax += 5 + Context->tagged);
621 for (i = 0; i < Context->msgcount; i++) {
622 h = Context->hdrs[i];
624 idx[idxlen] = p_new(ATTACHPTR, 1);
625 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
626 if (idx[idxlen]->content != NULL)
627 update_idx (menu, idx, idxlen++);
629 mutt_error _("Unable to attach!");
630 p_delete(&idx[idxlen]);
634 menu->redraw |= REDRAW_FULL;
636 if (closed == OP_QUIT)
637 mx_close_mailbox (Context, NULL);
639 mx_fastclose_mailbox (Context);
642 /* go back to the folder we started from */
644 /* Restore old $sort and $sort_aux */
646 SortAux = oldSortAux;
647 mutt_message_hook (NULL, msg, M_SEND2HOOK);
653 if (idx[menu->current]->unowned)
654 idx[menu->current]->content->unlink = 0;
655 if (delete_attachment (menu, &idxlen, menu->current) == -1)
657 mutt_update_tree (idx, idxlen);
659 if (menu->current > idxlen - 1)
660 menu->current = idxlen - 1;
665 if (menu->current == 0)
666 msg->content = idx[0]->content;
668 menu->redraw |= REDRAW_STATUS;
669 mutt_message_hook (NULL, msg, M_SEND2HOOK);
672 #define CURRENT idx[menu->current]->content
674 case OP_COMPOSE_TOGGLE_RECODE:
677 if (!mutt_is_text_part (CURRENT)) {
678 mutt_error (_("Recoding only affects text attachments."));
681 CURRENT->noconv = !CURRENT->noconv;
683 mutt_message (_("The current attachment won't be converted."));
685 mutt_message (_("The current attachment will be converted."));
686 menu->redraw = REDRAW_CURRENT;
687 mutt_message_hook (NULL, msg, M_SEND2HOOK);
692 case OP_COMPOSE_EDIT_DESCRIPTION:
694 m_strcpy(buf, sizeof(buf),
695 NONULL(idx[menu->current]->content->description));
696 /* header names should not be translated */
697 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
698 m_strreplace(&idx[menu->current]->content->description, buf);
699 menu->redraw = REDRAW_CURRENT;
701 mutt_message_hook (NULL, msg, M_SEND2HOOK);
704 case OP_COMPOSE_UPDATE_ENCODING:
706 if (menu->tagprefix) {
709 for (top = msg->content; top; top = top->next) {
711 mutt_update_encoding (top);
713 menu->redraw = REDRAW_FULL;
716 mutt_update_encoding (idx[menu->current]->content);
717 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
719 mutt_message_hook (NULL, msg, M_SEND2HOOK);
722 case OP_COMPOSE_TOGGLE_DISPOSITION:
723 /* toggle the content-disposition between inline/attachment */
724 idx[menu->current]->content->disposition =
725 (idx[menu->current]->content->disposition ==
726 DISPINLINE) ? DISPATTACH : DISPINLINE;
727 menu->redraw = REDRAW_CURRENT;
733 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
735 /* this may have been a change to text/something */
736 mutt_update_encoding (idx[menu->current]->content);
738 menu->redraw = REDRAW_CURRENT;
740 mutt_message_hook (NULL, msg, M_SEND2HOOK);
743 case OP_COMPOSE_EDIT_ENCODING:
745 m_strcpy(buf, sizeof(buf),
746 ENCODING(idx[menu->current]->content->encoding));
747 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
748 sizeof (buf), 0) == 0 && buf[0]) {
749 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
750 idx[menu->current]->content->encoding = i;
751 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
755 mutt_error _("Invalid encoding.");
757 mutt_message_hook (NULL, msg, M_SEND2HOOK);
760 case OP_COMPOSE_SEND_MESSAGE:
762 /* Note: We don't invoke send2-hook here, since we want to leave
763 * users an opportunity to change settings from the ":" prompt.
766 if (check_attachments (idx, idxlen) != 0) {
767 menu->redraw = REDRAW_FULL;
771 if (!fccSet && *fcc) {
772 if ((i = query_quadoption (OPT_COPY,
773 _("Save a copy of this message?"))) == -1)
783 case OP_COMPOSE_EDIT_FILE:
785 mutt_edit_file(idx[menu->current]->content->filename);
786 mutt_update_encoding (idx[menu->current]->content);
787 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
788 mutt_message_hook (NULL, msg, M_SEND2HOOK);
791 case OP_COMPOSE_TOGGLE_UNLINK:
793 idx[menu->current]->content->unlink =
794 !idx[menu->current]->content->unlink;
796 menu->redraw = REDRAW_INDEX;
797 /* No send2hook since this doesn't change the message. */
800 case OP_COMPOSE_GET_ATTACHMENT:
802 if (menu->tagprefix) {
805 for (top = msg->content; top; top = top->next) {
807 mutt_get_tmp_attachment (top);
809 menu->redraw = REDRAW_FULL;
811 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
812 menu->redraw = REDRAW_CURRENT;
814 /* No send2hook since this doesn't change the message. */
817 case OP_COMPOSE_RENAME_FILE:
819 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
820 mutt_pretty_mailbox (fname);
821 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
823 if (stat (idx[menu->current]->content->filename, &st) == -1) {
824 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
828 mutt_expand_path (fname, sizeof (fname));
829 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
832 m_strreplace(&idx[menu->current]->content->filename, fname);
833 menu->redraw = REDRAW_CURRENT;
835 if (idx[menu->current]->content->stamp >= st.st_mtime)
836 mutt_stamp_attachment (idx[menu->current]->content);
839 mutt_message_hook (NULL, msg, M_SEND2HOOK);
842 case OP_COMPOSE_NEW_MIME:
850 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
853 mutt_expand_path (fname, sizeof (fname));
855 /* Call to lookup_mime_type () ? maybe later */
857 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
861 if (!(p = strchr (type, '/'))) {
862 mutt_error _("Content-Type is of the form base/sub");
867 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
868 mutt_error (_("Unknown Content-Type %s"), type);
871 if (idxlen == idxmax) {
872 p_realloc(&idx, idxmax += 5);
876 idx[idxlen] = p_new(ATTACHPTR, 1);
878 if (!(fp = safe_fopen (fname, "w"))) {
879 mutt_error (_("Can't create file %s"), fname);
880 p_delete(&idx[idxlen]);
885 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
887 _("What we have here is a failure to make an attachment");
890 update_idx (menu, idx, idxlen++);
892 idx[menu->current]->content->type = itype;
893 m_strreplace(&idx[menu->current]->content->subtype, p);
894 idx[menu->current]->content->unlink = 1;
895 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
897 if (mutt_compose_attachment (idx[menu->current]->content)) {
898 mutt_update_encoding (idx[menu->current]->content);
899 menu->redraw = REDRAW_FULL;
902 mutt_message_hook (NULL, msg, M_SEND2HOOK);
905 case OP_COMPOSE_EDIT_MIME:
907 if (mutt_edit_attachment (idx[menu->current]->content)) {
908 mutt_update_encoding (idx[menu->current]->content);
909 menu->redraw = REDRAW_FULL;
911 mutt_message_hook (NULL, msg, M_SEND2HOOK);
915 case OP_DISPLAY_HEADERS:
917 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
919 menu->redraw = REDRAW_FULL;
920 /* no send2hook, since this doesn't modify the message */
925 mutt_save_attachment_list (NULL, menu->tagprefix,
926 menu->tagprefix ? msg->content : idx[menu->
928 content, NULL, menu);
929 MAYBE_REDRAW (menu->redraw);
930 /* no send2hook, since this doesn't modify the message */
935 mutt_print_attachment_list (NULL, menu->tagprefix,
936 menu->tagprefix ? msg->content : idx[menu->
939 /* no send2hook, since this doesn't modify the message */
945 mutt_pipe_attachment_list (NULL, menu->tagprefix,
946 menu->tagprefix ? msg->content : idx[menu->
948 content, op == OP_FILTER);
949 if (op == OP_FILTER) /* cte might have changed */
950 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
951 menu->redraw |= REDRAW_STATUS;
952 mutt_message_hook (NULL, msg, M_SEND2HOOK);
957 query_quadoption (OPT_POSTPONE,
958 _("Postpone this message?"))) == M_NO) {
959 while (idxlen-- > 0) {
960 /* avoid freeing other attachments */
961 idx[idxlen]->content->next = NULL;
962 idx[idxlen]->content->parts = NULL;
963 if (idx[idxlen]->unowned)
964 idx[idxlen]->content->unlink = 0;
965 body_list_wipe(&idx[idxlen]->content);
966 p_delete(&idx[idxlen]->tree);
967 p_delete(&idx[idxlen]);
979 /* fall through to postpone! */
981 case OP_COMPOSE_POSTPONE_MESSAGE:
983 if (check_attachments (idx, idxlen) != 0) {
984 menu->redraw = REDRAW_FULL;
992 case OP_COMPOSE_WRITE_MESSAGE:
995 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
996 mutt_pretty_mailbox (fname);
999 msg->content = idx[0]->content;
1000 if (mutt_enter_fname
1001 (_("Write message to mailbox"), fname, sizeof (fname),
1002 &menu->redraw, 1) != -1 && fname[0]) {
1003 mutt_message (_("Writing message to %s ..."), fname);
1004 mutt_expand_path (fname, sizeof (fname));
1006 if (msg->content->next)
1007 msg->content = mutt_make_multipart (msg->content);
1009 if (mutt_write_fcc (fname, msg, NULL, 1, NULL) < 0)
1010 msg->content = mutt_remove_multipart (msg->content);
1012 mutt_message _("Message written.");
1016 case OP_COMPOSE_PGP_MENU:
1017 if (msg->security & APPLICATION_SMIME) {
1018 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1020 mutt_clear_error ();
1025 msg->security = crypt_send_menu (msg, &menu->redraw, 0);
1026 redraw_crypt_lines (msg);
1027 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1030 case OP_COMPOSE_SMIME_MENU:
1031 if (msg->security & APPLICATION_PGP) {
1032 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1034 mutt_clear_error ();
1039 msg->security = crypt_send_menu(msg, &menu->redraw, 1);
1040 redraw_crypt_lines (msg);
1041 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1045 /* Draw formated compose status line */
1046 if (menu->redraw & REDRAW_STATUS) {
1047 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1048 CLEARLINE(main_w, 0);
1049 SETCOLOR(main_w, MT_COLOR_STATUS);
1050 mvwprintw (main_w, 0, 0, "%-*.*s", getmaxx(main_w), getmaxx(main_w), buf);
1051 SETCOLOR(main_w, MT_COLOR_NORMAL);
1052 menu->redraw &= ~REDRAW_STATUS;
1056 mutt_menuDestroy (&menu);
1059 msg->content = idx[0]->content;
1060 for (i = 0; i < idxlen; i++) {
1061 idx[i]->content->aptr = NULL;
1065 msg->content = NULL;