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/curses.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"
41 mutt_error _("There are no attachments."); \
65 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
67 HDR_ATTACH = (HDR_FCC + 7)
71 #define HDR_XOFFSET 14
72 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
73 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
74 #define W (COLS - HDR_XOFFSET - SW)
76 static const char *Prompts[] = {
85 "", "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: "
89 static void snd_entry (char *b, ssize_t blen, MUTTMENU * menu, int num) {
90 m_strformat(b, blen, COLS - SW, AttachFormat, mutt_attach_fmt,
91 ((ATTACHPTR **)menu->data)[num], M_FORMAT_STAT_FILE);
94 static void redraw_crypt_lines (HEADER * msg)
99 mvaddstr (HDR_CRYPT, SW, " Security: ");
100 else if (msg->security & APPLICATION_SMIME)
101 mvaddstr (HDR_CRYPT, SW, " S/MIME: ");
102 else if (msg->security & APPLICATION_PGP)
103 mvaddstr (HDR_CRYPT, SW, " PGP: ");
105 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
106 addstr (_("Sign, Encrypt"));
107 else if (msg->security & ENCRYPT)
108 addstr (_("Encrypt"));
109 else if (msg->security & SIGN)
114 if ((msg->security & APPLICATION_PGP)
115 && (msg->security & (ENCRYPT | SIGN))) {
116 if ((msg->security & INLINE))
117 addstr (_(" (inline)"));
119 addstr (_(" (PGP/MIME)"));
123 move (HDR_CRYPTINFO, SW);
125 if (msg->security & APPLICATION_PGP && msg->security & SIGN)
126 printw ("%s%s", _(" sign as: "),
127 PgpSignAs ? PgpSignAs : _("<default>"));
129 if (msg->security & APPLICATION_SMIME && msg->security & SIGN) {
130 printw ("%s%s", _(" sign as: "),
131 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
134 if ((msg->security & APPLICATION_SMIME)
135 && (msg->security & ENCRYPT)
136 && SmimeCryptAlg && *SmimeCryptAlg) {
137 mvprintw (HDR_CRYPTINFO, SW + 40, "%s%s", _("Encrypt with: "),
138 NONULL (SmimeCryptAlg));
143 static void redraw_mix_line (string_list_t * chain)
148 mvaddstr (HDR_MIX, SW, " Mix: ");
151 addstr ("<no chain defined>");
156 for (c = 12; chain; chain = chain->next) {
158 if (t && t[0] == '0' && t[1] == '\0')
161 if (c + m_strlen(t) + 2 >= COLS - SW)
168 c += m_strlen(t) + 2;
172 static int check_attachments (ATTACHPTR ** idx, short idxlen)
176 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + STRING];
178 for (i = 0; i < idxlen; i++) {
179 m_strcpy(pretty, sizeof(pretty), idx[i]->content->filename);
180 if (stat (idx[i]->content->filename, &st) != 0) {
181 mutt_pretty_mailbox (pretty);
182 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
186 if (idx[i]->content->stamp < st.st_mtime) {
187 mutt_pretty_mailbox (pretty);
188 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
191 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
192 mutt_update_encoding (idx[i]->content);
201 static void draw_envelope_addr (int line, address_t * addr)
206 rfc822_addrcat(buf, sizeof (buf), addr, 1);
207 mvprintw (line, SW, TITLE_FMT, Prompts[line - 1]);
208 mutt_paddstr (W, buf);
211 static void draw_envelope (HEADER * msg, char *fcc)
213 draw_envelope_addr (HDR_FROM, msg->env->from);
215 if (!option (OPTNEWSSEND)) {
217 draw_envelope_addr (HDR_TO, msg->env->to);
218 draw_envelope_addr (HDR_CC, msg->env->cc);
219 draw_envelope_addr (HDR_BCC, msg->env->bcc);
222 mvprintw (HDR_TO, SW, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
223 mutt_paddstr (W, NONULL (msg->env->newsgroups));
224 mvprintw (HDR_CC, SW, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
225 mutt_paddstr (W, NONULL (msg->env->followup_to));
228 mvprintw (HDR_SUBJECT, SW, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
229 mutt_paddstr (W, NONULL (msg->env->subject));
230 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
231 mvprintw (HDR_FCC, SW, TITLE_FMT, Prompts[HDR_FCC - 1]);
232 mutt_paddstr (W, fcc);
234 redraw_crypt_lines (msg);
235 redraw_mix_line (msg->chain);
237 SETCOLOR (MT_COLOR_STATUS);
238 mvaddstr (HDR_ATTACH - 1, SW, _("-- Attachments"));
239 BKGDSET (MT_COLOR_STATUS);
242 BKGDSET (MT_COLOR_NORMAL);
243 SETCOLOR (MT_COLOR_NORMAL);
246 static int edit_address_list (int line, address_t ** addr)
248 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
251 mutt_addrlist_to_local (*addr);
252 rfc822_addrcat(buf, sizeof (buf), *addr, 0);
253 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
254 address_list_wipe(addr);
255 *addr = mutt_parse_adrlist (*addr, buf);
256 *addr = mutt_expand_aliases (*addr);
259 if (option (OPTNEEDREDRAW)) {
260 unset_option (OPTNEEDREDRAW);
264 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
265 mutt_error (_("Warning: '%s' is a bad IDN."), err);
270 /* redraw the expanded list so the user can see the result */
272 rfc822_addrcat(buf, sizeof (buf), *addr, 1);
273 move (line, HDR_XOFFSET + SW);
274 mutt_paddstr (W, buf);
279 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
281 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
284 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
286 if (x == 0 && menu->max == 1) {
287 mutt_error _("You may not delete the only attachment.");
289 idx[x]->content->tagged = 0;
293 for (y = 0; y < *idxlen; y++) {
294 if (idx[y]->content->next == idx[x]->content) {
295 idx[y]->content->next = idx[x]->content->next;
300 idx[x]->content->next = NULL;
301 idx[x]->content->parts = NULL;
302 body_list_wipe(&(idx[x]->content));
303 p_delete(&idx[x]->tree);
305 for (; x < *idxlen - 1; x++)
307 menu->max = --(*idxlen);
312 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
314 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
316 idx[idxlen - 1]->content->next = idx[idxlen]->content;
317 idx[idxlen]->content->aptr = idx[idxlen];
318 menu->current = idxlen++;
319 mutt_update_tree (idx, idxlen);
326 * cum_attachs_size: Cumulative Attachments Size
328 * Returns the total number of bytes used by the attachments in the
329 * attachment list _after_ content-transfer-encodings have been
333 static unsigned long cum_attachs_size(MUTTMENU * menu)
337 ATTACHPTR **idx = menu->data;
341 for (i = 0, s = 0; i < menu->max; i++) {
345 b->content = mutt_get_content_info (b->filename, b);
347 if ((info = b->content)) {
348 switch (b->encoding) {
349 case ENCQUOTEDPRINTABLE:
350 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
353 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
356 s += info->lobin + info->hibin + info->ascii + info->crlf;
366 * compose_format_str()
368 * %a = total number of attachments
369 * %h = hostname [option]
370 * %l = approx. length of current message (in bytes)
373 * This function is similar to status_format_str(). Look at that function for
374 * help when modifying this function.
376 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
379 static const char *compose_format_str (char *buf, ssize_t buflen, char op,
380 const char *src, const char *prefix,
383 anytype data, format_flag flags)
385 char fmt[STRING], tmp[STRING];
386 int optional = (flags & M_FORMAT_OPTIONAL);
387 MUTTMENU *menu = data.ptr;
391 case 'a': /* total number of attachments */
392 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
393 snprintf (buf, buflen, fmt, menu->max);
396 case 'h': /* hostname */
397 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
398 snprintf (buf, buflen, fmt, NONULL(mod_core.shorthost));
401 case 'l': /* approx length of current message in bytes */
402 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
403 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
404 snprintf (buf, buflen, fmt, tmp);
408 m_strcpy(buf, buflen, mutt_make_version());
420 if (flags & M_FORMAT_OPTIONAL)
421 compose_status_line(buf, buflen, menu, optional ? ifstr : elstr);
426 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
429 m_strformat(buf, buflen, COLS - SW, p, compose_format_str, menu, 0);
434 * 1 message should be postponed
438 int mutt_compose_menu (HEADER * msg, /* structure for new message */
439 char *fcc, /* where to save a copy of the message */
441 HEADER * cur __attribute__ ((unused)))
442 { /* current message */
443 char buf[LONG_STRING];
444 char fname[_POSIX_PATH_MAX];
446 ATTACHPTR **idx = NULL;
450 int r = -1; /* return value */
453 int fccSet = 0; /* has the user edited the Fcc: field ? */
454 CONTEXT *ctx = NULL, *this = NULL;
456 /* Sort, SortAux could be changed in mutt_index_menu() */
457 int oldSort, oldSortAux;
461 int news = 0; /* is it a news article ? */
463 if (option (OPTNEWSSEND))
467 mutt_attach_init (msg->content);
468 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
470 menu = mutt_new_menu ();
471 menu->menu = MENU_COMPOSE;
472 menu->offset = HDR_ATTACH;
474 menu->make_entry = snd_entry;
475 menu->tag = mutt_tag_attach;
478 if (option (OPTMBOXPANE))
482 unset_option (OPTNEWS); /* for any case */
484 switch (op = mutt_menuLoop (menu)) {
486 draw_envelope (msg, fcc);
487 menu->offset = HDR_ATTACH;
488 menu->pagelen = LINES - HDR_ATTACH - 2;
490 case OP_COMPOSE_EDIT_FROM:
491 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
492 mutt_message_hook (NULL, msg, M_SEND2HOOK);
494 case OP_COMPOSE_EDIT_TO:
498 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
499 mutt_message_hook (NULL, msg, M_SEND2HOOK);
504 case OP_COMPOSE_EDIT_BCC:
508 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
509 mutt_message_hook (NULL, msg, M_SEND2HOOK);
514 case OP_COMPOSE_EDIT_CC:
518 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
519 mutt_message_hook (NULL, msg, M_SEND2HOOK);
525 case OP_COMPOSE_EDIT_NEWSGROUPS:
527 if (msg->env->newsgroups)
528 m_strcpy(buf, sizeof(buf), msg->env->newsgroups);
531 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
533 p_delete(&msg->env->newsgroups);
535 msg->env->newsgroups = m_strdup(skipspaces(buf));
536 move (HDR_TO, HDR_XOFFSET);
538 if (msg->env->newsgroups)
539 printw ("%-*.*s", W, W, msg->env->newsgroups);
544 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
547 if (msg->env->followup_to)
548 m_strcpy(buf, sizeof(buf), msg->env->followup_to);
549 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
551 p_delete(&msg->env->followup_to);
553 msg->env->followup_to = m_strdup(skipspaces(buf));
554 move (HDR_CC, HDR_XOFFSET);
556 if (msg->env->followup_to)
557 printw ("%-*.*s", W, W, msg->env->followup_to);
563 case OP_COMPOSE_EDIT_SUBJECT:
564 if (msg->env->subject)
565 m_strcpy(buf, sizeof(buf), msg->env->subject);
568 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
569 m_strreplace(&msg->env->subject, buf);
570 move (HDR_SUBJECT, HDR_XOFFSET + SW);
572 if (msg->env->subject)
573 mutt_paddstr (W, msg->env->subject);
575 mutt_message_hook (NULL, msg, M_SEND2HOOK);
577 case OP_COMPOSE_EDIT_REPLY_TO:
578 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
579 mutt_message_hook (NULL, msg, M_SEND2HOOK);
581 case OP_COMPOSE_EDIT_FCC:
582 m_strcpy(buf, sizeof(buf), fcc);
583 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
584 m_strcpy(fcc, _POSIX_PATH_MAX, buf);
585 mutt_pretty_mailbox (fcc);
586 move (HDR_FCC, HDR_XOFFSET + SW);
587 mutt_paddstr (W, fcc);
590 MAYBE_REDRAW (menu->redraw);
591 mutt_message_hook (NULL, msg, M_SEND2HOOK);
593 case OP_COMPOSE_EDIT_MESSAGE:
594 if (!option (OPTEDITHDRS)) {
595 mutt_edit_file(msg->content->filename);
596 mutt_update_encoding (msg->content);
597 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
598 mutt_message_hook (NULL, msg, M_SEND2HOOK);
602 case OP_COMPOSE_EDIT_HEADERS:
603 if ((op == OP_COMPOSE_EDIT_HEADERS ||
604 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
605 const char *tag = NULL;
608 mutt_env_to_local (msg->env);
609 mutt_edit_headers(msg->content->filename, msg, fcc, fcclen);
610 if (mutt_env_to_idna (msg->env, &tag, &err)) {
611 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
615 mutt_update_encoding (msg->content);
617 /* attachments may have been added */
618 if (idxlen && idx[idxlen - 1]->content->next) {
619 for (i = 0; i < idxlen; i++)
623 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
629 menu->redraw = REDRAW_FULL;
630 mutt_message_hook (NULL, msg, M_SEND2HOOK);
633 case OP_COMPOSE_ATTACH_FILE:
640 prompt = _("Attach file");
644 if (_mutt_enter_fname
645 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
646 &numfiles) == -1 || *fname == '\0')
649 if (idxlen + numfiles >= idxmax) {
650 p_realloc(&idx, idxmax += 5 + numfiles);
656 mutt_message _("Attaching selected files...");
658 for (i = 0; i < numfiles; i++) {
659 char *att = files[i];
661 idx[idxlen] = p_new(ATTACHPTR, 1);
662 idx[idxlen]->unowned = 1;
663 idx[idxlen]->content = mutt_make_file_attach (att);
664 if (idx[idxlen]->content != NULL)
665 update_idx (menu, idx, idxlen++);
668 mutt_error (_("Unable to attach %s!"), att);
669 p_delete(&idx[idxlen]);
677 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
679 mutt_message_hook (NULL, msg, M_SEND2HOOK);
682 case OP_COMPOSE_ATTACH_MESSAGE:
684 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
691 prompt = _("Open mailbox to attach message from");
694 unset_option (OPTNEWS);
695 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
696 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
699 prompt = _("Open newsgroup to attach message from");
700 set_option (OPTNEWS);
706 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
709 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
710 mutt_pretty_mailbox (fname);
713 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
718 if (option (OPTNEWS))
719 nntp_expand_path (fname, sizeof (fname),
720 &CurrentNewsSrv->conn->account);
723 mutt_expand_path (fname, sizeof (fname));
724 if (mx_get_magic (fname) != M_IMAP)
725 if (mx_get_magic (fname) != M_POP)
727 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
729 /* check to make sure the file exists and is readable */
730 if (access (fname, R_OK) == -1) {
735 menu->redraw = REDRAW_FULL;
737 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
743 if (!ctx->msgcount) {
744 mx_close_mailbox (ctx, NULL);
746 mutt_error _("No messages in that folder.");
751 this = Context; /* remember current folder and sort methods */
753 oldSortAux = SortAux;
756 set_option (OPTATTACHMSG);
757 mutt_message _("Tag the messages you want to attach!");
759 closed = mutt_index_menu ();
760 unset_option (OPTATTACHMSG);
763 /* go back to the folder we started from */
765 /* Restore old $sort and $sort_aux */
767 SortAux = oldSortAux;
768 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
772 if (idxlen + Context->tagged >= idxmax) {
773 p_realloc(&idx, idxmax += 5 + Context->tagged);
777 for (i = 0; i < Context->msgcount; i++) {
778 h = Context->hdrs[i];
780 idx[idxlen] = p_new(ATTACHPTR, 1);
781 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
782 if (idx[idxlen]->content != NULL)
783 update_idx (menu, idx, idxlen++);
785 mutt_error _("Unable to attach!");
787 p_delete(&idx[idxlen]);
791 menu->redraw |= REDRAW_FULL;
793 if (closed == OP_QUIT)
794 mx_close_mailbox (Context, NULL);
796 mx_fastclose_mailbox (Context);
799 /* go back to the folder we started from */
801 /* Restore old $sort and $sort_aux */
803 SortAux = oldSortAux;
805 mutt_message_hook (NULL, msg, M_SEND2HOOK);
810 if (idx[menu->current]->unowned)
811 idx[menu->current]->content->unlink = 0;
812 if (delete_attachment (menu, &idxlen, menu->current) == -1)
814 mutt_update_tree (idx, idxlen);
816 if (menu->current > idxlen - 1)
817 menu->current = idxlen - 1;
822 if (menu->current == 0)
823 msg->content = idx[0]->content;
825 menu->redraw |= REDRAW_STATUS;
826 mutt_message_hook (NULL, msg, M_SEND2HOOK);
829 #define CURRENT idx[menu->current]->content
831 case OP_COMPOSE_TOGGLE_RECODE:
834 if (!mutt_is_text_part (CURRENT)) {
835 mutt_error (_("Recoding only affects text attachments."));
838 CURRENT->noconv = !CURRENT->noconv;
840 mutt_message (_("The current attachment won't be converted."));
842 mutt_message (_("The current attachment will be converted."));
843 menu->redraw = REDRAW_CURRENT;
844 mutt_message_hook (NULL, msg, M_SEND2HOOK);
849 case OP_COMPOSE_EDIT_DESCRIPTION:
851 m_strcpy(buf, sizeof(buf),
852 NONULL(idx[menu->current]->content->description));
853 /* header names should not be translated */
854 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
855 m_strreplace(&idx[menu->current]->content->description, buf);
856 menu->redraw = REDRAW_CURRENT;
858 mutt_message_hook (NULL, msg, M_SEND2HOOK);
861 case OP_COMPOSE_UPDATE_ENCODING:
863 if (menu->tagprefix) {
866 for (top = msg->content; top; top = top->next) {
868 mutt_update_encoding (top);
870 menu->redraw = REDRAW_FULL;
873 mutt_update_encoding (idx[menu->current]->content);
874 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
876 mutt_message_hook (NULL, msg, M_SEND2HOOK);
879 case OP_COMPOSE_TOGGLE_DISPOSITION:
880 /* toggle the content-disposition between inline/attachment */
881 idx[menu->current]->content->disposition =
882 (idx[menu->current]->content->disposition ==
883 DISPINLINE) ? DISPATTACH : DISPINLINE;
884 menu->redraw = REDRAW_CURRENT;
890 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
892 /* this may have been a change to text/something */
893 mutt_update_encoding (idx[menu->current]->content);
895 menu->redraw = REDRAW_CURRENT;
897 mutt_message_hook (NULL, msg, M_SEND2HOOK);
900 case OP_COMPOSE_EDIT_ENCODING:
902 m_strcpy(buf, sizeof(buf),
903 ENCODING(idx[menu->current]->content->encoding));
904 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
905 sizeof (buf), 0) == 0 && buf[0]) {
906 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
907 idx[menu->current]->content->encoding = i;
908 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
912 mutt_error _("Invalid encoding.");
914 mutt_message_hook (NULL, msg, M_SEND2HOOK);
917 case OP_COMPOSE_SEND_MESSAGE:
919 /* Note: We don't invoke send2-hook here, since we want to leave
920 * users an opportunity to change settings from the ":" prompt.
923 if (check_attachments (idx, idxlen) != 0) {
924 menu->redraw = REDRAW_FULL;
928 if (msg->chain && mix_check_message (msg) != 0)
931 if (!fccSet && *fcc) {
932 if ((i = query_quadoption (OPT_COPY,
933 _("Save a copy of this message?"))) == -1)
943 case OP_COMPOSE_EDIT_FILE:
945 mutt_edit_file(idx[menu->current]->content->filename);
946 mutt_update_encoding (idx[menu->current]->content);
947 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
948 mutt_message_hook (NULL, msg, M_SEND2HOOK);
951 case OP_COMPOSE_TOGGLE_UNLINK:
953 idx[menu->current]->content->unlink =
954 !idx[menu->current]->content->unlink;
956 menu->redraw = REDRAW_INDEX;
957 /* No send2hook since this doesn't change the message. */
960 case OP_COMPOSE_GET_ATTACHMENT:
962 if (menu->tagprefix) {
965 for (top = msg->content; top; top = top->next) {
967 mutt_get_tmp_attachment (top);
969 menu->redraw = REDRAW_FULL;
971 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
972 menu->redraw = REDRAW_CURRENT;
974 /* No send2hook since this doesn't change the message. */
977 case OP_COMPOSE_RENAME_FILE:
979 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
980 mutt_pretty_mailbox (fname);
981 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
983 if (stat (idx[menu->current]->content->filename, &st) == -1) {
984 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
988 mutt_expand_path (fname, sizeof (fname));
989 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
992 m_strreplace(&idx[menu->current]->content->filename, fname);
993 menu->redraw = REDRAW_CURRENT;
995 if (idx[menu->current]->content->stamp >= st.st_mtime)
996 mutt_stamp_attachment (idx[menu->current]->content);
999 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1002 case OP_COMPOSE_NEW_MIME:
1009 CLEARLINE (LINES - 1);
1011 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1014 mutt_expand_path (fname, sizeof (fname));
1016 /* Call to lookup_mime_type () ? maybe later */
1018 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1022 if (!(p = strchr (type, '/'))) {
1023 mutt_error _("Content-Type is of the form base/sub");
1028 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1029 mutt_error (_("Unknown Content-Type %s"), type);
1032 if (idxlen == idxmax) {
1033 p_realloc(&idx, idxmax += 5);
1037 idx[idxlen] = p_new(ATTACHPTR, 1);
1038 /* Touch the file */
1039 if (!(fp = safe_fopen (fname, "w"))) {
1040 mutt_error (_("Can't create file %s"), fname);
1041 p_delete(&idx[idxlen]);
1046 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1048 _("What we have here is a failure to make an attachment");
1051 update_idx (menu, idx, idxlen++);
1053 idx[menu->current]->content->type = itype;
1054 m_strreplace(&idx[menu->current]->content->subtype, p);
1055 idx[menu->current]->content->unlink = 1;
1056 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1058 if (mutt_compose_attachment (idx[menu->current]->content)) {
1059 mutt_update_encoding (idx[menu->current]->content);
1060 menu->redraw = REDRAW_FULL;
1063 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1066 case OP_COMPOSE_EDIT_MIME:
1068 if (mutt_edit_attachment (idx[menu->current]->content)) {
1069 mutt_update_encoding (idx[menu->current]->content);
1070 menu->redraw = REDRAW_FULL;
1072 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1075 case OP_VIEW_ATTACH:
1076 case OP_DISPLAY_HEADERS:
1078 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1080 menu->redraw = REDRAW_FULL;
1081 /* no send2hook, since this doesn't modify the message */
1086 mutt_save_attachment_list (NULL, menu->tagprefix,
1087 menu->tagprefix ? msg->content : idx[menu->
1089 content, NULL, menu);
1090 MAYBE_REDRAW (menu->redraw);
1091 /* no send2hook, since this doesn't modify the message */
1096 mutt_print_attachment_list (NULL, menu->tagprefix,
1097 menu->tagprefix ? msg->content : idx[menu->
1100 /* no send2hook, since this doesn't modify the message */
1106 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1107 menu->tagprefix ? msg->content : idx[menu->
1109 content, op == OP_FILTER);
1110 if (op == OP_FILTER) /* cte might have changed */
1111 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1112 menu->redraw |= REDRAW_STATUS;
1113 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1118 query_quadoption (OPT_POSTPONE,
1119 _("Postpone this message?"))) == M_NO) {
1120 while (idxlen-- > 0) {
1121 /* avoid freeing other attachments */
1122 idx[idxlen]->content->next = NULL;
1123 idx[idxlen]->content->parts = NULL;
1124 if (idx[idxlen]->unowned)
1125 idx[idxlen]->content->unlink = 0;
1126 body_list_wipe(&idx[idxlen]->content);
1127 p_delete(&idx[idxlen]->tree);
1128 p_delete(&idx[idxlen]);
1140 /* fall through to postpone! */
1142 case OP_COMPOSE_POSTPONE_MESSAGE:
1144 if (check_attachments (idx, idxlen) != 0) {
1145 menu->redraw = REDRAW_FULL;
1153 case OP_COMPOSE_WRITE_MESSAGE:
1156 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
1157 mutt_pretty_mailbox (fname);
1160 msg->content = idx[0]->content;
1161 if (mutt_enter_fname
1162 (_("Write message to mailbox"), fname, sizeof (fname),
1163 &menu->redraw, 1) != -1 && fname[0]) {
1164 mutt_message (_("Writing message to %s ..."), fname);
1165 mutt_expand_path (fname, sizeof (fname));
1167 if (msg->content->next)
1168 msg->content = mutt_make_multipart (msg->content);
1170 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1171 msg->content = mutt_remove_multipart (msg->content);
1173 mutt_message _("Message written.");
1177 case OP_COMPOSE_PGP_MENU:
1178 if (msg->security & APPLICATION_SMIME) {
1179 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1181 mutt_clear_error ();
1186 msg->security = crypt_send_menu (msg, &menu->redraw, 0);
1187 redraw_crypt_lines (msg);
1188 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1191 case OP_COMPOSE_SMIME_MENU:
1192 if (msg->security & APPLICATION_PGP) {
1193 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1195 mutt_clear_error ();
1200 msg->security = crypt_send_menu(msg, &menu->redraw, 1);
1201 redraw_crypt_lines (msg);
1202 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1205 case OP_COMPOSE_MIX:
1206 mix_make_chain (&msg->chain, &menu->redraw);
1207 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1211 /* Draw formated compose status line */
1212 if (menu->redraw & REDRAW_STATUS) {
1213 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1214 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1215 SETCOLOR (MT_COLOR_STATUS);
1216 move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
1217 printw ("%-*.*s", COLS-SW, COLS-SW, buf);
1218 SETCOLOR (MT_COLOR_NORMAL);
1219 menu->redraw &= ~REDRAW_STATUS;
1223 mutt_menuDestroy (&menu);
1226 msg->content = idx[0]->content;
1227 for (i = 0; i < idxlen; i++) {
1228 idx[i]->content->aptr = NULL;
1232 msg->content = NULL;