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.
20 #include "mutt_curses.h"
21 #include "mutt_idna.h"
22 #include "mutt_menu.h"
26 #include "recvattach.h"
53 static const char *There_are_no_attachments = N_("There are no attachments.");
55 #define CHECK_COUNT if (idxlen == 0) { mutt_error _(There_are_no_attachments); break; }
82 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
84 HDR_ATTACH = (HDR_FCC + 7)
88 #define HDR_XOFFSET 14
89 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
90 #define W (COLS - HDR_XOFFSET - SidebarWidth)
92 static char *Prompts[] = {
104 , "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: "
108 static struct mapping_t ComposeHelp[] = {
109 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
110 {N_("Abort"), OP_EXIT},
111 {"To", OP_COMPOSE_EDIT_TO},
112 {"CC", OP_COMPOSE_EDIT_CC},
113 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
114 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
115 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
116 {N_("Help"), OP_HELP},
121 static struct mapping_t ComposeNewsHelp[] = {
122 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
123 {N_("Abort"), OP_EXIT},
124 {"Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS},
125 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
126 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
127 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
128 {N_("Help"), OP_HELP},
133 static void snd_entry (char *b, size_t blen, MUTTMENU * menu, int num)
135 mutt_FormatString (b, blen, NONULL (AttachFormat), mutt_attach_fmt,
136 (unsigned long) (((ATTACHPTR **) menu->data)[num]),
137 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
142 #include "mutt_crypt.h"
144 static void redraw_crypt_lines (HEADER * msg)
148 if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME)) {
150 mvaddstr (HDR_CRYPT, SidebarWidth, " Security: ");
151 else if (msg->security & APPLICATION_SMIME)
152 mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
153 else if (msg->security & APPLICATION_PGP)
154 mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
156 else if ((WithCrypto & APPLICATION_SMIME))
157 mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
158 else if ((WithCrypto & APPLICATION_PGP))
159 mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
163 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
164 addstr (_("Sign, Encrypt"));
165 else if (msg->security & ENCRYPT)
166 addstr (_("Encrypt"));
167 else if (msg->security & SIGN)
172 if ((WithCrypto & APPLICATION_PGP))
173 if ((msg->security & APPLICATION_PGP)
174 && (msg->security & (ENCRYPT | SIGN))) {
175 if ((msg->security & INLINE))
176 addstr (_(" (inline)"));
178 addstr (_(" (PGP/MIME)"));
182 move (HDR_CRYPTINFO, SidebarWidth);
184 if ((WithCrypto & APPLICATION_PGP)
185 && msg->security & APPLICATION_PGP && msg->security & SIGN)
186 printw ("%s%s", _(" sign as: "),
187 PgpSignAs ? PgpSignAs : _("<default>"));
189 if ((WithCrypto & APPLICATION_SMIME)
190 && msg->security & APPLICATION_SMIME && msg->security & SIGN) {
191 printw ("%s%s", _(" sign as: "),
192 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
195 if ((WithCrypto & APPLICATION_SMIME)
196 && (msg->security & APPLICATION_SMIME)
197 && (msg->security & ENCRYPT)
198 && SmimeCryptAlg && *SmimeCryptAlg) {
199 mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "),
200 NONULL (SmimeCryptAlg));
208 static void redraw_mix_line (LIST * chain)
213 mvaddstr (HDR_MIX, SidebarWidth, " Mix: ");
216 addstr ("<no chain defined>");
221 for (c = 12; chain; chain = chain->next) {
223 if (t && t[0] == '0' && t[1] == '\0')
226 if (c + str_len (t) + 2 >= COLS - SidebarWidth)
233 c += str_len (t) + 2;
236 #endif /* MIXMASTER */
238 static int check_attachments (ATTACHPTR ** idx, short idxlen)
242 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
244 for (i = 0; i < idxlen; i++) {
245 strfcpy (pretty, idx[i]->content->filename, sizeof (pretty));
246 if (stat (idx[i]->content->filename, &st) != 0) {
247 mutt_pretty_mailbox (pretty);
248 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
252 if (idx[i]->content->stamp < st.st_mtime) {
253 mutt_pretty_mailbox (pretty);
254 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
257 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
258 mutt_update_encoding (idx[i]->content);
267 static void draw_envelope_addr (int line, ADDRESS * addr)
272 rfc822_write_address (buf, sizeof (buf), addr, 1);
273 mvprintw (line, SidebarWidth, TITLE_FMT, Prompts[line - 1]);
274 mutt_paddstr (W, buf);
277 static void draw_envelope (HEADER * msg, char *fcc)
279 draw_envelope_addr (HDR_FROM, msg->env->from);
281 if (!option (OPTNEWSSEND)) {
283 draw_envelope_addr (HDR_TO, msg->env->to);
284 draw_envelope_addr (HDR_CC, msg->env->cc);
285 draw_envelope_addr (HDR_BCC, msg->env->bcc);
289 mvprintw (HDR_TO, SidebarWidth, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
290 mutt_paddstr (W, NONULL (msg->env->newsgroups));
291 mvprintw (HDR_CC, SidebarWidth, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
292 mutt_paddstr (W, NONULL (msg->env->followup_to));
293 if (option (OPTXCOMMENTTO)) {
294 mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]);
295 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
299 mvprintw (HDR_SUBJECT, SidebarWidth, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
300 mutt_paddstr (W, NONULL (msg->env->subject));
301 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
302 mvprintw (HDR_FCC, SidebarWidth, TITLE_FMT, Prompts[HDR_FCC - 1]);
303 mutt_paddstr (W, fcc);
306 redraw_crypt_lines (msg);
309 redraw_mix_line (msg->chain);
312 SETCOLOR (MT_COLOR_STATUS);
313 mvaddstr (HDR_ATTACH - 1, SidebarWidth, _("-- Attachments"));
314 BKGDSET (MT_COLOR_STATUS);
317 BKGDSET (MT_COLOR_NORMAL);
318 SETCOLOR (MT_COLOR_NORMAL);
321 static int edit_address_list (int line, ADDRESS ** addr)
323 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
326 mutt_addrlist_to_local (*addr);
327 rfc822_write_address (buf, sizeof (buf), *addr, 0);
328 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
329 rfc822_free_address (addr);
330 *addr = mutt_parse_adrlist (*addr, buf);
331 *addr = mutt_expand_aliases (*addr);
334 if (option (OPTNEEDREDRAW)) {
335 unset_option (OPTNEEDREDRAW);
336 return (REDRAW_FULL);
339 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
340 mutt_error (_("Warning: '%s' is a bad IDN."), err);
345 /* redraw the expanded list so the user can see the result */
347 rfc822_write_address (buf, sizeof (buf), *addr, 1);
348 move (line, HDR_XOFFSET + SidebarWidth);
349 mutt_paddstr (W, buf);
354 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
356 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
359 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
361 if (x == 0 && menu->max == 1) {
362 mutt_error _("You may not delete the only attachment.");
364 idx[x]->content->tagged = 0;
368 for (y = 0; y < *idxlen; y++) {
369 if (idx[y]->content->next == idx[x]->content) {
370 idx[y]->content->next = idx[x]->content->next;
375 idx[x]->content->next = NULL;
376 idx[x]->content->parts = NULL;
377 mutt_free_body (&(idx[x]->content));
378 mem_free (&idx[x]->tree);
380 for (; x < *idxlen - 1; x++)
382 menu->max = --(*idxlen);
387 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
389 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
391 idx[idxlen - 1]->content->next = idx[idxlen]->content;
392 idx[idxlen]->content->aptr = idx[idxlen];
393 menu->current = idxlen++;
394 mutt_update_tree (idx, idxlen);
401 * cum_attachs_size: Cumulative Attachments Size
403 * Returns the total number of bytes used by the attachments in the
404 * attachment list _after_ content-transfer-encodings have been
409 static unsigned long cum_attachs_size (MUTTMENU * menu)
413 ATTACHPTR **idx = menu->data;
417 for (i = 0, s = 0; i < menu->max; i++) {
421 b->content = mutt_get_content_info (b->filename, b);
423 if ((info = b->content)) {
424 switch (b->encoding) {
425 case ENCQUOTEDPRINTABLE:
426 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
429 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
432 s += info->lobin + info->hibin + info->ascii + info->crlf;
442 * compose_format_str()
444 * %a = total number of attachments
445 * %h = hostname [option]
446 * %l = approx. length of current message (in bytes)
449 * This function is similar to status_format_str(). Look at that function for
450 * help when modifying this function.
453 static const char *compose_format_str (char *buf, size_t buflen, char op,
454 const char *src, const char *prefix,
455 const char *ifstring,
456 const char *elsestring,
457 unsigned long data, format_flag flags)
459 char fmt[SHORT_STRING], tmp[SHORT_STRING];
460 int optional = (flags & M_FORMAT_OPTIONAL);
461 MUTTMENU *menu = (MUTTMENU *) data;
465 case 'a': /* total number of attachments */
466 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
467 snprintf (buf, buflen, fmt, menu->max);
470 case 'h': /* hostname */
471 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
472 snprintf (buf, buflen, fmt, NONULL (Hostname));
475 case 'l': /* approx length of current message in bytes */
476 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
477 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
478 snprintf (buf, buflen, fmt, tmp);
482 strncpy (buf, mutt_make_version (0), buflen);
490 snprintf (buf, buflen, "%%%s%c", prefix, op);
495 compose_status_line (buf, buflen, menu, ifstring);
496 else if (flags & M_FORMAT_OPTIONAL)
497 compose_status_line (buf, buflen, menu, elsestring);
502 static void compose_status_line (char *buf, size_t buflen, MUTTMENU * menu,
505 mutt_FormatString (buf, buflen, p, compose_format_str,
506 (unsigned long) menu, 0);
512 * 1 message should be postponed
516 int mutt_compose_menu (HEADER * msg, /* structure for new message */
517 char *fcc, /* where to save a copy of the message */
518 size_t fcclen, HEADER * cur)
519 { /* current message */
520 char helpstr[SHORT_STRING];
521 char buf[LONG_STRING];
522 char fname[_POSIX_PATH_MAX];
524 ATTACHPTR **idx = NULL;
528 int r = -1; /* return value */
531 int fccSet = 0; /* has the user edited the Fcc: field ? */
532 CONTEXT *ctx = NULL, *this = NULL;
534 /* Sort, SortAux could be changed in mutt_index_menu() */
535 int oldSort, oldSortAux;
539 int news = 0; /* is it a news article ? */
541 if (option (OPTNEWSSEND))
545 mutt_attach_init (msg->content);
546 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
548 menu = mutt_new_menu ();
549 menu->menu = MENU_COMPOSE;
550 menu->offset = HDR_ATTACH;
552 menu->make_entry = snd_entry;
553 menu->tag = mutt_tag_attach;
558 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
563 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
566 if (option (OPTMBOXPANE))
570 unset_option (OPTNEWS); /* for any case */
572 switch (op = mutt_menuLoop (menu)) {
574 draw_envelope (msg, fcc);
575 menu->offset = HDR_ATTACH;
576 menu->pagelen = LINES - HDR_ATTACH - 2;
578 case OP_COMPOSE_EDIT_FROM:
579 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
580 mutt_message_hook (NULL, msg, M_SEND2HOOK);
582 case OP_COMPOSE_EDIT_TO:
586 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
587 mutt_message_hook (NULL, msg, M_SEND2HOOK);
592 case OP_COMPOSE_EDIT_BCC:
596 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
597 mutt_message_hook (NULL, msg, M_SEND2HOOK);
602 case OP_COMPOSE_EDIT_CC:
606 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
607 mutt_message_hook (NULL, msg, M_SEND2HOOK);
613 case OP_COMPOSE_EDIT_NEWSGROUPS:
615 if (msg->env->newsgroups)
616 strfcpy (buf, msg->env->newsgroups, sizeof (buf));
619 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
621 mem_free (&msg->env->newsgroups);
622 str_skip_trailws (buf);
623 msg->env->newsgroups = str_dup (str_skip_initws (buf));
624 move (HDR_TO, HDR_XOFFSET);
626 if (msg->env->newsgroups)
627 printw ("%-*.*s", W, W, msg->env->newsgroups);
632 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
635 if (msg->env->followup_to)
636 strfcpy (buf, msg->env->followup_to, sizeof (buf));
637 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
639 mem_free (&msg->env->followup_to);
640 str_skip_trailws (buf);
641 msg->env->followup_to = str_dup (str_skip_initws (buf));
642 move (HDR_CC, HDR_XOFFSET);
644 if (msg->env->followup_to)
645 printw ("%-*.*s", W, W, msg->env->followup_to);
650 case OP_COMPOSE_EDIT_X_COMMENT_TO:
651 if (news && option (OPTXCOMMENTTO)) {
653 if (msg->env->x_comment_to)
654 strfcpy (buf, msg->env->x_comment_to, sizeof (buf));
655 if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
657 mem_free (&msg->env->x_comment_to);
658 msg->env->x_comment_to = str_dup (buf);
659 move (HDR_BCC, HDR_XOFFSET);
661 if (msg->env->x_comment_to)
662 printw ("%-*.*s", W, W, msg->env->x_comment_to);
667 case OP_COMPOSE_EDIT_SUBJECT:
668 if (msg->env->subject)
669 strfcpy (buf, msg->env->subject, sizeof (buf));
672 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
673 str_replace (&msg->env->subject, buf);
674 move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
676 if (msg->env->subject)
677 mutt_paddstr (W, msg->env->subject);
679 mutt_message_hook (NULL, msg, M_SEND2HOOK);
681 case OP_COMPOSE_EDIT_REPLY_TO:
682 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
683 mutt_message_hook (NULL, msg, M_SEND2HOOK);
685 case OP_COMPOSE_EDIT_FCC:
686 strfcpy (buf, fcc, sizeof (buf));
687 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
688 strfcpy (fcc, buf, _POSIX_PATH_MAX);
689 mutt_pretty_mailbox (fcc);
690 move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
691 mutt_paddstr (W, fcc);
694 MAYBE_REDRAW (menu->redraw);
695 mutt_message_hook (NULL, msg, M_SEND2HOOK);
697 case OP_COMPOSE_EDIT_MESSAGE:
698 if (Editor && (str_cmp ("builtin", Editor) != 0)
699 && !option (OPTEDITHDRS)) {
700 mutt_edit_file (Editor, msg->content->filename);
701 mutt_update_encoding (msg->content);
702 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
703 mutt_message_hook (NULL, msg, M_SEND2HOOK);
707 case OP_COMPOSE_EDIT_HEADERS:
708 if (str_cmp ("builtin", Editor) != 0 &&
709 (op == OP_COMPOSE_EDIT_HEADERS ||
710 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
711 char *tag = NULL, *err = NULL;
713 mutt_env_to_local (msg->env);
714 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
716 if (mutt_env_to_idna (msg->env, &tag, &err)) {
717 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
722 /* this is grouped with OP_COMPOSE_EDIT_HEADERS because the
723 attachment list could change if the user invokes ~v to edit
724 the message with headers, in which we need to execute the
725 code below to regenerate the index array */
726 mutt_builtin_editor (msg->content->filename, msg, cur);
728 mutt_update_encoding (msg->content);
730 /* attachments may have been added */
731 if (idxlen && idx[idxlen - 1]->content->next) {
732 for (i = 0; i < idxlen; i++)
736 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
742 menu->redraw = REDRAW_FULL;
743 mutt_message_hook (NULL, msg, M_SEND2HOOK);
748 case OP_COMPOSE_ATTACH_KEY:
749 if (!(WithCrypto & APPLICATION_PGP))
751 if (idxlen == idxmax) {
752 mem_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
756 idx[idxlen] = (ATTACHPTR *) mem_calloc (1, sizeof (ATTACHPTR));
757 if ((idx[idxlen]->content =
758 crypt_pgp_make_key_attachment (NULL)) != NULL) {
759 update_idx (menu, idx, idxlen++);
760 menu->redraw |= REDRAW_INDEX;
763 mem_free (&idx[idxlen]);
765 menu->redraw |= REDRAW_STATUS;
767 if (option (OPTNEEDREDRAW)) {
768 menu->redraw = REDRAW_FULL;
769 unset_option (OPTNEEDREDRAW);
772 mutt_message_hook (NULL, msg, M_SEND2HOOK);
776 case OP_COMPOSE_ATTACH_FILE:
778 char *prompt, **files;
782 prompt = _("Attach file");
786 if (_mutt_enter_fname
787 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
788 &numfiles) == -1 || *fname == '\0')
791 if (idxlen + numfiles >= idxmax) {
793 sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles));
799 mutt_message _("Attaching selected files...");
801 for (i = 0; i < numfiles; i++) {
802 char *att = files[i];
804 idx[idxlen] = (ATTACHPTR *) mem_calloc (1, sizeof (ATTACHPTR));
805 idx[idxlen]->unowned = 1;
806 idx[idxlen]->content = mutt_make_file_attach (att);
807 if (idx[idxlen]->content != NULL)
808 update_idx (menu, idx, idxlen++);
811 mutt_error (_("Unable to attach %s!"), att);
812 mem_free (&idx[idxlen]);
820 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
822 mutt_message_hook (NULL, msg, M_SEND2HOOK);
825 case OP_COMPOSE_ATTACH_MESSAGE:
827 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
834 prompt = _("Open mailbox to attach message from");
837 unset_option (OPTNEWS);
838 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
839 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
842 prompt = _("Open newsgroup to attach message from");
843 set_option (OPTNEWS);
849 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
852 strfcpy (fname, NONULL (Context->path), sizeof (fname));
853 mutt_pretty_mailbox (fname);
856 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
861 if (option (OPTNEWS))
862 nntp_expand_path (fname, sizeof (fname),
863 &CurrentNewsSrv->conn->account);
866 mutt_expand_path (fname, sizeof (fname));
868 if (mx_get_magic (fname) != M_IMAP)
871 if (mx_get_magic (fname) != M_POP)
874 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
876 /* check to make sure the file exists and is readable */
877 if (access (fname, R_OK) == -1) {
882 menu->redraw = REDRAW_FULL;
884 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
890 if (!ctx->msgcount) {
891 mx_close_mailbox (ctx, NULL);
893 mutt_error _("No messages in that folder.");
898 this = Context; /* remember current folder and sort methods */
900 oldSortAux = SortAux;
903 set_option (OPTATTACHMSG);
904 mutt_message _("Tag the messages you want to attach!");
906 close = mutt_index_menu ();
907 unset_option (OPTATTACHMSG);
910 /* go back to the folder we started from */
912 /* Restore old $sort and $sort_aux */
914 SortAux = oldSortAux;
915 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
919 if (idxlen + Context->tagged >= idxmax) {
921 sizeof (ATTACHPTR *) * (idxmax +=
922 5 + Context->tagged));
926 for (i = 0; i < Context->msgcount; i++) {
927 h = Context->hdrs[i];
929 idx[idxlen] = (ATTACHPTR *) mem_calloc (1, sizeof (ATTACHPTR));
930 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
931 if (idx[idxlen]->content != NULL)
932 update_idx (menu, idx, idxlen++);
934 mutt_error _("Unable to attach!");
936 mem_free (&idx[idxlen]);
940 menu->redraw |= REDRAW_FULL;
942 if (close == OP_QUIT)
943 mx_close_mailbox (Context, NULL);
945 mx_fastclose_mailbox (Context);
948 /* go back to the folder we started from */
950 /* Restore old $sort and $sort_aux */
952 SortAux = oldSortAux;
954 mutt_message_hook (NULL, msg, M_SEND2HOOK);
959 if (idx[menu->current]->unowned)
960 idx[menu->current]->content->unlink = 0;
961 if (delete_attachment (menu, &idxlen, menu->current) == -1)
963 mutt_update_tree (idx, idxlen);
965 if (menu->current > idxlen - 1)
966 menu->current = idxlen - 1;
971 if (menu->current == 0)
972 msg->content = idx[0]->content;
974 menu->redraw |= REDRAW_STATUS;
975 mutt_message_hook (NULL, msg, M_SEND2HOOK);
978 #define CURRENT idx[menu->current]->content
980 case OP_COMPOSE_TOGGLE_RECODE:
983 if (!mutt_is_text_part (CURRENT)) {
984 mutt_error (_("Recoding only affects text attachments."));
987 CURRENT->noconv = !CURRENT->noconv;
989 mutt_message (_("The current attachment won't be converted."));
991 mutt_message (_("The current attachment will be converted."));
992 menu->redraw = REDRAW_CURRENT;
993 mutt_message_hook (NULL, msg, M_SEND2HOOK);
998 case OP_COMPOSE_EDIT_DESCRIPTION:
1001 idx[menu->current]->content->description ?
1002 idx[menu->current]->content->description : "", sizeof (buf));
1003 /* header names should not be translated */
1004 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
1005 str_replace (&idx[menu->current]->content->description, buf);
1006 menu->redraw = REDRAW_CURRENT;
1008 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1011 case OP_COMPOSE_UPDATE_ENCODING:
1013 if (menu->tagprefix) {
1016 for (top = msg->content; top; top = top->next) {
1018 mutt_update_encoding (top);
1020 menu->redraw = REDRAW_FULL;
1023 mutt_update_encoding (idx[menu->current]->content);
1024 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1026 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1029 case OP_COMPOSE_TOGGLE_DISPOSITION:
1030 /* toggle the content-disposition between inline/attachment */
1031 idx[menu->current]->content->disposition =
1032 (idx[menu->current]->content->disposition ==
1033 DISPINLINE) ? DISPATTACH : DISPINLINE;
1034 menu->redraw = REDRAW_CURRENT;
1040 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
1042 /* this may have been a change to text/something */
1043 mutt_update_encoding (idx[menu->current]->content);
1045 menu->redraw = REDRAW_CURRENT;
1047 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1050 case OP_COMPOSE_EDIT_ENCODING:
1052 strfcpy (buf, ENCODING (idx[menu->current]->content->encoding),
1054 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
1055 sizeof (buf), 0) == 0 && buf[0]) {
1056 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
1057 idx[menu->current]->content->encoding = i;
1058 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1059 mutt_clear_error ();
1062 mutt_error _("Invalid encoding.");
1064 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1067 case OP_COMPOSE_SEND_MESSAGE:
1069 /* Note: We don't invoke send2-hook here, since we want to leave
1070 * users an opportunity to change settings from the ":" prompt.
1073 if (check_attachments (idx, idxlen) != 0) {
1074 menu->redraw = REDRAW_FULL;
1080 if (msg->chain && mix_check_message (msg) != 0)
1084 if (!fccSet && *fcc) {
1085 if ((i = query_quadoption (OPT_COPY,
1086 _("Save a copy of this message?"))) == -1)
1096 case OP_COMPOSE_EDIT_FILE:
1098 mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename);
1099 mutt_update_encoding (idx[menu->current]->content);
1100 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1101 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1104 case OP_COMPOSE_TOGGLE_UNLINK:
1106 idx[menu->current]->content->unlink =
1107 !idx[menu->current]->content->unlink;
1110 /* OPTRESOLVE is otherwise ignored on this menu.
1114 if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
1117 menu->redraw = REDRAW_INDEX;
1118 /* No send2hook since this doesn't change the message. */
1121 case OP_COMPOSE_GET_ATTACHMENT:
1123 if (menu->tagprefix) {
1126 for (top = msg->content; top; top = top->next) {
1128 mutt_get_tmp_attachment (top);
1130 menu->redraw = REDRAW_FULL;
1132 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1133 menu->redraw = REDRAW_CURRENT;
1135 /* No send2hook since this doesn't change the message. */
1138 case OP_COMPOSE_RENAME_FILE:
1140 strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname));
1141 mutt_pretty_mailbox (fname);
1142 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1144 if (stat (idx[menu->current]->content->filename, &st) == -1) {
1145 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1149 mutt_expand_path (fname, sizeof (fname));
1150 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1153 str_replace (&idx[menu->current]->content->filename, fname);
1154 menu->redraw = REDRAW_CURRENT;
1156 if (idx[menu->current]->content->stamp >= st.st_mtime)
1157 mutt_stamp_attachment (idx[menu->current]->content);
1160 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1163 case OP_COMPOSE_NEW_MIME:
1170 CLEARLINE (LINES - 1);
1172 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1175 mutt_expand_path (fname, sizeof (fname));
1177 /* Call to lookup_mime_type () ? maybe later */
1179 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1183 if (!(p = strchr (type, '/'))) {
1184 mutt_error _("Content-Type is of the form base/sub");
1189 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1190 mutt_error (_("Unknown Content-Type %s"), type);
1193 if (idxlen == idxmax) {
1194 mem_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
1198 idx[idxlen] = (ATTACHPTR *) mem_calloc (1, sizeof (ATTACHPTR));
1199 /* Touch the file */
1200 if (!(fp = safe_fopen (fname, "w"))) {
1201 mutt_error (_("Can't create file %s"), fname);
1202 mem_free (&idx[idxlen]);
1207 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1209 _("What we have here is a failure to make an attachment");
1212 update_idx (menu, idx, idxlen++);
1214 idx[menu->current]->content->type = itype;
1215 str_replace (&idx[menu->current]->content->subtype, p);
1216 idx[menu->current]->content->unlink = 1;
1217 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1219 if (mutt_compose_attachment (idx[menu->current]->content)) {
1220 mutt_update_encoding (idx[menu->current]->content);
1221 menu->redraw = REDRAW_FULL;
1224 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1227 case OP_COMPOSE_EDIT_MIME:
1229 if (mutt_edit_attachment (idx[menu->current]->content)) {
1230 mutt_update_encoding (idx[menu->current]->content);
1231 menu->redraw = REDRAW_FULL;
1233 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1236 case OP_VIEW_ATTACH:
1237 case OP_DISPLAY_HEADERS:
1239 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1241 menu->redraw = REDRAW_FULL;
1242 /* no send2hook, since this doesn't modify the message */
1247 mutt_save_attachment_list (NULL, menu->tagprefix,
1248 menu->tagprefix ? msg->content : idx[menu->
1250 content, NULL, menu);
1251 MAYBE_REDRAW (menu->redraw);
1252 /* no send2hook, since this doesn't modify the message */
1257 mutt_print_attachment_list (NULL, menu->tagprefix,
1258 menu->tagprefix ? msg->content : idx[menu->
1261 /* no send2hook, since this doesn't modify the message */
1267 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1268 menu->tagprefix ? msg->content : idx[menu->
1270 content, op == OP_FILTER);
1271 if (op == OP_FILTER) /* cte might have changed */
1272 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1273 menu->redraw |= REDRAW_STATUS;
1274 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1279 query_quadoption (OPT_POSTPONE,
1280 _("Postpone this message?"))) == M_NO) {
1281 while (idxlen-- > 0) {
1282 /* avoid freeing other attachments */
1283 idx[idxlen]->content->next = NULL;
1284 idx[idxlen]->content->parts = NULL;
1285 if (idx[idxlen]->unowned)
1286 idx[idxlen]->content->unlink = 0;
1287 mutt_free_body (&idx[idxlen]->content);
1288 mem_free (&idx[idxlen]->tree);
1289 mem_free (&idx[idxlen]);
1301 /* fall through to postpone! */
1303 case OP_COMPOSE_POSTPONE_MESSAGE:
1305 if (check_attachments (idx, idxlen) != 0) {
1306 menu->redraw = REDRAW_FULL;
1314 case OP_COMPOSE_ISPELL:
1316 snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1317 msg->content->filename);
1318 if (mutt_system (buf) == -1)
1319 mutt_error (_("Error running \"%s\"!"), buf);
1321 mutt_update_encoding (msg->content);
1322 menu->redraw |= REDRAW_STATUS;
1326 case OP_COMPOSE_WRITE_MESSAGE:
1330 strfcpy (fname, NONULL (Context->path), sizeof (fname));
1331 mutt_pretty_mailbox (fname);
1334 msg->content = idx[0]->content;
1335 if (mutt_enter_fname
1336 (_("Write message to mailbox"), fname, sizeof (fname),
1337 &menu->redraw, 1) != -1 && fname[0]) {
1338 mutt_message (_("Writing message to %s ..."), fname);
1339 mutt_expand_path (fname, sizeof (fname));
1341 if (msg->content->next)
1342 msg->content = mutt_make_multipart (msg->content);
1344 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1345 msg->content = mutt_remove_multipart (msg->content);
1347 mutt_message _("Message written.");
1353 case OP_COMPOSE_PGP_MENU:
1354 if (!(WithCrypto & APPLICATION_PGP))
1356 if ((WithCrypto & APPLICATION_SMIME)
1357 && msg->security & APPLICATION_SMIME) {
1358 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1360 mutt_clear_error ();
1365 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1366 redraw_crypt_lines (msg);
1367 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1371 case OP_FORGET_PASSPHRASE:
1372 crypt_forget_passphrase ();
1376 case OP_COMPOSE_SMIME_MENU:
1377 if (!(WithCrypto & APPLICATION_SMIME))
1380 if ((WithCrypto & APPLICATION_PGP)
1381 && msg->security & APPLICATION_PGP) {
1382 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1384 mutt_clear_error ();
1389 msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1390 redraw_crypt_lines (msg);
1391 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1396 case OP_COMPOSE_MIX:
1398 mix_make_chain (&msg->chain, &menu->redraw);
1399 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1405 /* Draw formated compose status line */
1406 if (menu->redraw & REDRAW_STATUS) {
1407 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1408 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1409 SETCOLOR (MT_COLOR_STATUS);
1410 printw ("%-*.*s", COLS, COLS, buf);
1411 SETCOLOR (MT_COLOR_NORMAL);
1412 menu->redraw &= ~REDRAW_STATUS;
1416 mutt_menuDestroy (&menu);
1419 msg->content = idx[0]->content;
1420 for (i = 0; i < idxlen; i++) {
1421 idx[i]->content->aptr = NULL;
1426 msg->content = NULL;