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"
40 mutt_error _("There are no attachments."); \
63 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
65 HDR_ATTACH = (HDR_FCC + 7)
69 #define HDR_XOFFSET 14
70 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
71 #define W (getmaxx(main_w) - HDR_XOFFSET)
73 static const char *Prompts[] = {
82 "", "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: "
86 static void snd_entry (char *b, ssize_t blen, MUTTMENU * menu, int num) {
87 m_strformat(b, blen, getmaxx(main_w), AttachFormat, mutt_attach_fmt,
88 ((ATTACHPTR **)menu->data)[num], M_FORMAT_STAT_FILE);
91 static void redraw_crypt_lines (HEADER * msg)
96 mvwaddstr (main_w, HDR_CRYPT, 0, " Security: ");
97 else if (msg->security & APPLICATION_SMIME)
98 mvwaddstr (main_w, HDR_CRYPT, 0, " S/MIME: ");
99 else if (msg->security & APPLICATION_PGP)
100 mvwaddstr (main_w, HDR_CRYPT, 0, " PGP: ");
102 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
103 waddstr (main_w, _("Sign, Encrypt"));
104 else if (msg->security & ENCRYPT)
105 waddstr (main_w, _("Encrypt"));
106 else if (msg->security & SIGN)
107 waddstr (main_w, _("Sign"));
109 waddstr (main_w, _("Clear"));
111 if ((msg->security & APPLICATION_PGP)
112 && (msg->security & (ENCRYPT | SIGN))) {
113 if ((msg->security & INLINE))
114 waddstr (main_w, _(" (inline)"));
116 waddstr (main_w, _(" (PGP/MIME)"));
120 wmove (main_w, HDR_CRYPTINFO, 0);
122 if (msg->security & APPLICATION_PGP && msg->security & SIGN)
123 wprintw (main_w, "%s%s", _(" sign as: "),
124 PgpSignAs ? PgpSignAs : _("<default>"));
126 if (msg->security & APPLICATION_SMIME && msg->security & SIGN) {
127 wprintw (main_w, "%s%s", _(" sign as: "),
128 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
131 if ((msg->security & APPLICATION_SMIME)
132 && (msg->security & ENCRYPT)
133 && SmimeCryptAlg && *SmimeCryptAlg) {
134 mvwprintw (main_w, HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "),
135 NONULL (SmimeCryptAlg));
140 static int check_attachments (ATTACHPTR ** idx, short idxlen)
144 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + STRING];
146 for (i = 0; i < idxlen; i++) {
147 m_strcpy(pretty, sizeof(pretty), idx[i]->content->filename);
148 if (stat (idx[i]->content->filename, &st) != 0) {
149 mutt_pretty_mailbox (pretty);
150 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
154 if (idx[i]->content->stamp < st.st_mtime) {
155 mutt_pretty_mailbox (pretty);
156 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
159 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
160 mutt_update_encoding (idx[i]->content);
169 static void draw_envelope_addr (int line, address_t * addr)
174 rfc822_addrcat(buf, sizeof (buf), addr, 1);
175 mvwprintw (main_w, line, 0, TITLE_FMT, Prompts[line - 1]);
176 mutt_paddstr (main_w, W, buf);
179 static void draw_envelope (HEADER * msg, char *fcc)
181 draw_envelope_addr (HDR_FROM, msg->env->from);
183 if (!option (OPTNEWSSEND)) {
185 draw_envelope_addr (HDR_TO, msg->env->to);
186 draw_envelope_addr (HDR_CC, msg->env->cc);
187 draw_envelope_addr (HDR_BCC, msg->env->bcc);
190 mvwprintw (main_w, HDR_TO, 0, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
191 mutt_paddstr (main_w, W, NONULL (msg->env->newsgroups));
192 mvwprintw (main_w, HDR_CC, 0, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
193 mutt_paddstr (main_w, W, NONULL (msg->env->followup_to));
196 mvwprintw (main_w, HDR_SUBJECT, 0, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
197 mutt_paddstr (main_w, W, NONULL (msg->env->subject));
198 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
199 mvwprintw (main_w, HDR_FCC, 0, TITLE_FMT, Prompts[HDR_FCC - 1]);
200 mutt_paddstr (main_w, W, fcc);
202 redraw_crypt_lines (msg);
204 SETCOLOR(main_w, MT_COLOR_STATUS);
205 mvwaddstr (main_w, HDR_ATTACH - 1, 0, _("-- Attachments"));
206 BKGDSET(main_w, MT_COLOR_STATUS);
209 BKGDSET(main_w, MT_COLOR_NORMAL);
210 SETCOLOR(main_w, MT_COLOR_NORMAL);
213 static int edit_address_list (int line, address_t ** addr)
215 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
218 mutt_addrlist_to_local (*addr);
219 rfc822_addrcat(buf, sizeof (buf), *addr, 0);
220 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
221 address_list_wipe(addr);
222 *addr = mutt_parse_adrlist (*addr, buf);
223 *addr = mutt_expand_aliases (*addr);
226 if (option (OPTNEEDREDRAW)) {
227 unset_option (OPTNEEDREDRAW);
231 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
232 mutt_error (_("Warning: '%s' is a bad IDN."), err);
237 /* redraw the expanded list so the user can see the result */
239 rfc822_addrcat(buf, sizeof (buf), *addr, 1);
240 wmove (main_w, line, HDR_XOFFSET);
241 mutt_paddstr (main_w, W, buf);
246 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
248 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
251 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
253 if (x == 0 && menu->max == 1) {
254 mutt_error _("You may not delete the only attachment.");
256 idx[x]->content->tagged = 0;
260 for (y = 0; y < *idxlen; y++) {
261 if (idx[y]->content->next == idx[x]->content) {
262 idx[y]->content->next = idx[x]->content->next;
267 idx[x]->content->next = NULL;
268 idx[x]->content->parts = NULL;
269 body_list_wipe(&(idx[x]->content));
270 p_delete(&idx[x]->tree);
272 for (; x < *idxlen - 1; x++)
274 menu->max = --(*idxlen);
279 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
281 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
283 idx[idxlen - 1]->content->next = idx[idxlen]->content;
284 idx[idxlen]->content->aptr = idx[idxlen];
285 menu->current = idxlen++;
286 mutt_update_tree (idx, idxlen);
293 * cum_attachs_size: Cumulative Attachments Size
295 * Returns the total number of bytes used by the attachments in the
296 * attachment list _after_ content-transfer-encodings have been
300 static unsigned long cum_attachs_size(MUTTMENU * menu)
304 ATTACHPTR **idx = menu->data;
308 for (i = 0, s = 0; i < menu->max; i++) {
312 b->content = mutt_get_content_info (b->filename, b);
314 if ((info = b->content)) {
315 switch (b->encoding) {
316 case ENCQUOTEDPRINTABLE:
317 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
320 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
323 s += info->lobin + info->hibin + info->ascii + info->crlf;
333 * compose_format_str()
335 * %a = total number of attachments
336 * %h = hostname [option]
337 * %l = approx. length of current message (in bytes)
340 * This function is similar to status_format_str(). Look at that function for
341 * help when modifying this function.
343 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
346 static const char *compose_format_str (char *buf, ssize_t buflen, char op,
347 const char *src, const char *prefix,
350 anytype data, format_flag flags)
352 char fmt[STRING], tmp[STRING];
353 int optional = (flags & M_FORMAT_OPTIONAL);
354 MUTTMENU *menu = data.ptr;
358 case 'a': /* total number of attachments */
359 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
360 snprintf (buf, buflen, fmt, menu->max);
363 case 'h': /* hostname */
364 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
365 snprintf (buf, buflen, fmt, NONULL(mod_core.shorthost));
368 case 'l': /* approx length of current message in bytes */
369 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
370 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
371 snprintf (buf, buflen, fmt, tmp);
375 m_strcpy(buf, buflen, mutt_make_version());
387 if (flags & M_FORMAT_OPTIONAL)
388 compose_status_line(buf, buflen, menu, optional ? ifstr : elstr);
393 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
396 m_strformat(buf, buflen, getmaxx(main_w), p, compose_format_str, menu, 0);
401 * 1 message should be postponed
405 int mutt_compose_menu (HEADER * msg, /* structure for new message */
406 char *fcc, /* where to save a copy of the message */
408 HEADER * cur __attribute__ ((unused)))
409 { /* current message */
410 char buf[LONG_STRING];
411 char fname[_POSIX_PATH_MAX];
413 ATTACHPTR **idx = NULL;
417 int r = -1; /* return value */
420 int fccSet = 0; /* has the user edited the Fcc: field ? */
421 CONTEXT *ctx = NULL, *this = NULL;
423 /* Sort, SortAux could be changed in mutt_index_menu() */
424 int oldSort, oldSortAux;
428 int news = 0; /* is it a news article ? */
430 if (option (OPTNEWSSEND))
434 mutt_attach_init (msg->content);
435 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
437 menu = mutt_new_menu ();
438 menu->menu = MENU_COMPOSE;
439 menu->offset = HDR_ATTACH;
441 menu->make_entry = snd_entry;
442 menu->tag = mutt_tag_attach;
447 unset_option (OPTNEWS); /* for any case */
449 switch (op = mutt_menuLoop (menu)) {
451 draw_envelope (msg, fcc);
452 menu->offset = HDR_ATTACH;
453 menu->pagelen = LINES - HDR_ATTACH - 2;
455 case OP_COMPOSE_EDIT_FROM:
456 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
457 mutt_message_hook (NULL, msg, M_SEND2HOOK);
459 case OP_COMPOSE_EDIT_TO:
463 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
464 mutt_message_hook (NULL, msg, M_SEND2HOOK);
469 case OP_COMPOSE_EDIT_BCC:
473 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
474 mutt_message_hook (NULL, msg, M_SEND2HOOK);
479 case OP_COMPOSE_EDIT_CC:
483 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
484 mutt_message_hook (NULL, msg, M_SEND2HOOK);
490 case OP_COMPOSE_EDIT_NEWSGROUPS:
492 if (msg->env->newsgroups)
493 m_strcpy(buf, sizeof(buf), msg->env->newsgroups);
496 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
498 p_delete(&msg->env->newsgroups);
500 msg->env->newsgroups = m_strdup(skipspaces(buf));
501 wmove (main_w, HDR_TO, HDR_XOFFSET);
503 if (msg->env->newsgroups)
504 wprintw (main_w, "%-*.*s", W, W, msg->env->newsgroups);
509 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
512 if (msg->env->followup_to)
513 m_strcpy(buf, sizeof(buf), msg->env->followup_to);
514 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
516 p_delete(&msg->env->followup_to);
518 msg->env->followup_to = m_strdup(skipspaces(buf));
519 wmove (main_w, HDR_CC, HDR_XOFFSET);
521 if (msg->env->followup_to)
522 wprintw (main_w, "%-*.*s", W, W, msg->env->followup_to);
528 case OP_COMPOSE_EDIT_SUBJECT:
529 if (msg->env->subject)
530 m_strcpy(buf, sizeof(buf), msg->env->subject);
533 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
534 m_strreplace(&msg->env->subject, buf);
535 wmove (main_w, HDR_SUBJECT, HDR_XOFFSET);
537 if (msg->env->subject)
538 mutt_paddstr (main_w, W, msg->env->subject);
540 mutt_message_hook (NULL, msg, M_SEND2HOOK);
542 case OP_COMPOSE_EDIT_REPLY_TO:
543 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
544 mutt_message_hook (NULL, msg, M_SEND2HOOK);
546 case OP_COMPOSE_EDIT_FCC:
547 m_strcpy(buf, sizeof(buf), fcc);
548 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
549 m_strcpy(fcc, _POSIX_PATH_MAX, buf);
550 mutt_pretty_mailbox (fcc);
551 wmove (main_w, HDR_FCC, HDR_XOFFSET);
552 mutt_paddstr (main_w, W, fcc);
555 MAYBE_REDRAW (menu->redraw);
556 mutt_message_hook (NULL, msg, M_SEND2HOOK);
558 case OP_COMPOSE_EDIT_MESSAGE:
559 if (!option (OPTEDITHDRS)) {
560 mutt_edit_file(msg->content->filename);
561 mutt_update_encoding (msg->content);
562 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
563 mutt_message_hook (NULL, msg, M_SEND2HOOK);
567 case OP_COMPOSE_EDIT_HEADERS:
568 if ((op == OP_COMPOSE_EDIT_HEADERS ||
569 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
570 const char *tag = NULL;
573 mutt_env_to_local (msg->env);
574 mutt_edit_headers(msg->content->filename, msg, fcc, fcclen);
575 if (mutt_env_to_idna (msg->env, &tag, &err)) {
576 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
580 mutt_update_encoding (msg->content);
582 /* attachments may have been added */
583 if (idxlen && idx[idxlen - 1]->content->next) {
584 for (i = 0; i < idxlen; i++)
588 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
594 menu->redraw = REDRAW_FULL;
595 mutt_message_hook (NULL, msg, M_SEND2HOOK);
598 case OP_COMPOSE_ATTACH_FILE:
605 prompt = _("Attach file");
609 if (_mutt_enter_fname
610 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
611 &numfiles) == -1 || *fname == '\0')
614 if (idxlen + numfiles >= idxmax) {
615 p_realloc(&idx, idxmax += 5 + numfiles);
621 mutt_message _("Attaching selected files...");
623 for (i = 0; i < numfiles; i++) {
624 char *att = files[i];
626 idx[idxlen] = p_new(ATTACHPTR, 1);
627 idx[idxlen]->unowned = 1;
628 idx[idxlen]->content = mutt_make_file_attach (att);
629 if (idx[idxlen]->content != NULL)
630 update_idx (menu, idx, idxlen++);
633 mutt_error (_("Unable to attach %s!"), att);
634 p_delete(&idx[idxlen]);
642 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
644 mutt_message_hook (NULL, msg, M_SEND2HOOK);
647 case OP_COMPOSE_ATTACH_MESSAGE:
649 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
656 prompt = _("Open mailbox to attach message from");
659 unset_option (OPTNEWS);
660 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
661 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
664 prompt = _("Open newsgroup to attach message from");
665 set_option (OPTNEWS);
671 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
674 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
675 mutt_pretty_mailbox (fname);
678 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
683 if (option (OPTNEWS))
684 nntp_expand_path (fname, sizeof (fname),
685 &CurrentNewsSrv->conn->account);
688 mutt_expand_path (fname, sizeof (fname));
689 if (mx_get_magic (fname) != M_IMAP && mx_get_magic (fname) != M_POP) {
691 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
693 /* check to make sure the file exists and is readable */
694 if (access (fname, R_OK) == -1) {
700 menu->redraw = REDRAW_FULL;
702 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
708 if (!ctx->msgcount) {
709 mx_close_mailbox (ctx, NULL);
711 mutt_error _("No messages in that folder.");
715 this = Context; /* remember current folder and sort methods */
717 oldSortAux = SortAux;
720 set_option (OPTATTACHMSG);
721 mutt_message _("Tag the messages you want to attach!");
723 closed = mutt_index_menu ();
724 unset_option (OPTATTACHMSG);
727 /* go back to the folder we started from */
729 /* Restore old $sort and $sort_aux */
731 SortAux = oldSortAux;
732 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
736 if (idxlen + Context->tagged >= idxmax) {
737 p_realloc(&idx, idxmax += 5 + Context->tagged);
741 for (i = 0; i < Context->msgcount; i++) {
742 h = Context->hdrs[i];
744 idx[idxlen] = p_new(ATTACHPTR, 1);
745 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
746 if (idx[idxlen]->content != NULL)
747 update_idx (menu, idx, idxlen++);
749 mutt_error _("Unable to attach!");
750 p_delete(&idx[idxlen]);
754 menu->redraw |= REDRAW_FULL;
756 if (closed == OP_QUIT)
757 mx_close_mailbox (Context, NULL);
759 mx_fastclose_mailbox (Context);
762 /* go back to the folder we started from */
764 /* Restore old $sort and $sort_aux */
766 SortAux = oldSortAux;
768 mutt_message_hook (NULL, msg, M_SEND2HOOK);
773 if (idx[menu->current]->unowned)
774 idx[menu->current]->content->unlink = 0;
775 if (delete_attachment (menu, &idxlen, menu->current) == -1)
777 mutt_update_tree (idx, idxlen);
779 if (menu->current > idxlen - 1)
780 menu->current = idxlen - 1;
785 if (menu->current == 0)
786 msg->content = idx[0]->content;
788 menu->redraw |= REDRAW_STATUS;
789 mutt_message_hook (NULL, msg, M_SEND2HOOK);
792 #define CURRENT idx[menu->current]->content
794 case OP_COMPOSE_TOGGLE_RECODE:
797 if (!mutt_is_text_part (CURRENT)) {
798 mutt_error (_("Recoding only affects text attachments."));
801 CURRENT->noconv = !CURRENT->noconv;
803 mutt_message (_("The current attachment won't be converted."));
805 mutt_message (_("The current attachment will be converted."));
806 menu->redraw = REDRAW_CURRENT;
807 mutt_message_hook (NULL, msg, M_SEND2HOOK);
812 case OP_COMPOSE_EDIT_DESCRIPTION:
814 m_strcpy(buf, sizeof(buf),
815 NONULL(idx[menu->current]->content->description));
816 /* header names should not be translated */
817 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
818 m_strreplace(&idx[menu->current]->content->description, buf);
819 menu->redraw = REDRAW_CURRENT;
821 mutt_message_hook (NULL, msg, M_SEND2HOOK);
824 case OP_COMPOSE_UPDATE_ENCODING:
826 if (menu->tagprefix) {
829 for (top = msg->content; top; top = top->next) {
831 mutt_update_encoding (top);
833 menu->redraw = REDRAW_FULL;
836 mutt_update_encoding (idx[menu->current]->content);
837 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
839 mutt_message_hook (NULL, msg, M_SEND2HOOK);
842 case OP_COMPOSE_TOGGLE_DISPOSITION:
843 /* toggle the content-disposition between inline/attachment */
844 idx[menu->current]->content->disposition =
845 (idx[menu->current]->content->disposition ==
846 DISPINLINE) ? DISPATTACH : DISPINLINE;
847 menu->redraw = REDRAW_CURRENT;
853 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
855 /* this may have been a change to text/something */
856 mutt_update_encoding (idx[menu->current]->content);
858 menu->redraw = REDRAW_CURRENT;
860 mutt_message_hook (NULL, msg, M_SEND2HOOK);
863 case OP_COMPOSE_EDIT_ENCODING:
865 m_strcpy(buf, sizeof(buf),
866 ENCODING(idx[menu->current]->content->encoding));
867 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
868 sizeof (buf), 0) == 0 && buf[0]) {
869 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
870 idx[menu->current]->content->encoding = i;
871 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
875 mutt_error _("Invalid encoding.");
877 mutt_message_hook (NULL, msg, M_SEND2HOOK);
880 case OP_COMPOSE_SEND_MESSAGE:
882 /* Note: We don't invoke send2-hook here, since we want to leave
883 * users an opportunity to change settings from the ":" prompt.
886 if (check_attachments (idx, idxlen) != 0) {
887 menu->redraw = REDRAW_FULL;
891 if (!fccSet && *fcc) {
892 if ((i = query_quadoption (OPT_COPY,
893 _("Save a copy of this message?"))) == -1)
903 case OP_COMPOSE_EDIT_FILE:
905 mutt_edit_file(idx[menu->current]->content->filename);
906 mutt_update_encoding (idx[menu->current]->content);
907 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
908 mutt_message_hook (NULL, msg, M_SEND2HOOK);
911 case OP_COMPOSE_TOGGLE_UNLINK:
913 idx[menu->current]->content->unlink =
914 !idx[menu->current]->content->unlink;
916 menu->redraw = REDRAW_INDEX;
917 /* No send2hook since this doesn't change the message. */
920 case OP_COMPOSE_GET_ATTACHMENT:
922 if (menu->tagprefix) {
925 for (top = msg->content; top; top = top->next) {
927 mutt_get_tmp_attachment (top);
929 menu->redraw = REDRAW_FULL;
931 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
932 menu->redraw = REDRAW_CURRENT;
934 /* No send2hook since this doesn't change the message. */
937 case OP_COMPOSE_RENAME_FILE:
939 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
940 mutt_pretty_mailbox (fname);
941 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
943 if (stat (idx[menu->current]->content->filename, &st) == -1) {
944 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
948 mutt_expand_path (fname, sizeof (fname));
949 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
952 m_strreplace(&idx[menu->current]->content->filename, fname);
953 menu->redraw = REDRAW_CURRENT;
955 if (idx[menu->current]->content->stamp >= st.st_mtime)
956 mutt_stamp_attachment (idx[menu->current]->content);
959 mutt_message_hook (NULL, msg, M_SEND2HOOK);
962 case OP_COMPOSE_NEW_MIME:
969 CLEARLINE(main_w, LINES - 1);
971 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
974 mutt_expand_path (fname, sizeof (fname));
976 /* Call to lookup_mime_type () ? maybe later */
978 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
982 if (!(p = strchr (type, '/'))) {
983 mutt_error _("Content-Type is of the form base/sub");
988 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
989 mutt_error (_("Unknown Content-Type %s"), type);
992 if (idxlen == idxmax) {
993 p_realloc(&idx, idxmax += 5);
997 idx[idxlen] = p_new(ATTACHPTR, 1);
999 if (!(fp = safe_fopen (fname, "w"))) {
1000 mutt_error (_("Can't create file %s"), fname);
1001 p_delete(&idx[idxlen]);
1006 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1008 _("What we have here is a failure to make an attachment");
1011 update_idx (menu, idx, idxlen++);
1013 idx[menu->current]->content->type = itype;
1014 m_strreplace(&idx[menu->current]->content->subtype, p);
1015 idx[menu->current]->content->unlink = 1;
1016 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1018 if (mutt_compose_attachment (idx[menu->current]->content)) {
1019 mutt_update_encoding (idx[menu->current]->content);
1020 menu->redraw = REDRAW_FULL;
1023 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1026 case OP_COMPOSE_EDIT_MIME:
1028 if (mutt_edit_attachment (idx[menu->current]->content)) {
1029 mutt_update_encoding (idx[menu->current]->content);
1030 menu->redraw = REDRAW_FULL;
1032 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1035 case OP_VIEW_ATTACH:
1036 case OP_DISPLAY_HEADERS:
1038 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1040 menu->redraw = REDRAW_FULL;
1041 /* no send2hook, since this doesn't modify the message */
1046 mutt_save_attachment_list (NULL, menu->tagprefix,
1047 menu->tagprefix ? msg->content : idx[menu->
1049 content, NULL, menu);
1050 MAYBE_REDRAW (menu->redraw);
1051 /* no send2hook, since this doesn't modify the message */
1056 mutt_print_attachment_list (NULL, menu->tagprefix,
1057 menu->tagprefix ? msg->content : idx[menu->
1060 /* no send2hook, since this doesn't modify the message */
1066 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1067 menu->tagprefix ? msg->content : idx[menu->
1069 content, op == OP_FILTER);
1070 if (op == OP_FILTER) /* cte might have changed */
1071 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1072 menu->redraw |= REDRAW_STATUS;
1073 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1078 query_quadoption (OPT_POSTPONE,
1079 _("Postpone this message?"))) == M_NO) {
1080 while (idxlen-- > 0) {
1081 /* avoid freeing other attachments */
1082 idx[idxlen]->content->next = NULL;
1083 idx[idxlen]->content->parts = NULL;
1084 if (idx[idxlen]->unowned)
1085 idx[idxlen]->content->unlink = 0;
1086 body_list_wipe(&idx[idxlen]->content);
1087 p_delete(&idx[idxlen]->tree);
1088 p_delete(&idx[idxlen]);
1100 /* fall through to postpone! */
1102 case OP_COMPOSE_POSTPONE_MESSAGE:
1104 if (check_attachments (idx, idxlen) != 0) {
1105 menu->redraw = REDRAW_FULL;
1113 case OP_COMPOSE_WRITE_MESSAGE:
1116 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
1117 mutt_pretty_mailbox (fname);
1120 msg->content = idx[0]->content;
1121 if (mutt_enter_fname
1122 (_("Write message to mailbox"), fname, sizeof (fname),
1123 &menu->redraw, 1) != -1 && fname[0]) {
1124 mutt_message (_("Writing message to %s ..."), fname);
1125 mutt_expand_path (fname, sizeof (fname));
1127 if (msg->content->next)
1128 msg->content = mutt_make_multipart (msg->content);
1130 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1131 msg->content = mutt_remove_multipart (msg->content);
1133 mutt_message _("Message written.");
1137 case OP_COMPOSE_PGP_MENU:
1138 if (msg->security & APPLICATION_SMIME) {
1139 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1141 mutt_clear_error ();
1146 msg->security = crypt_send_menu (msg, &menu->redraw, 0);
1147 redraw_crypt_lines (msg);
1148 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1151 case OP_COMPOSE_SMIME_MENU:
1152 if (msg->security & APPLICATION_PGP) {
1153 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1155 mutt_clear_error ();
1160 msg->security = crypt_send_menu(msg, &menu->redraw, 1);
1161 redraw_crypt_lines (msg);
1162 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1166 /* Draw formated compose status line */
1167 if (menu->redraw & REDRAW_STATUS) {
1168 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1169 CLEARLINE(main_w, 0);
1170 SETCOLOR(main_w, MT_COLOR_STATUS);
1171 wmove (main_w, 0, 0);
1172 wprintw (main_w, "%-*.*s", getmaxx(main_w), getmaxx(main_w), buf);
1173 SETCOLOR(main_w, MT_COLOR_NORMAL);
1174 menu->redraw &= ~REDRAW_STATUS;
1178 mutt_menuDestroy (&menu);
1181 msg->content = idx[0]->content;
1182 for (i = 0; i < idxlen; i++) {
1183 idx[i]->content->aptr = NULL;
1187 msg->content = NULL;