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 SW (option(OPTMBOXPANE)?SidebarWidth:0)
91 #define W (COLS - HDR_XOFFSET - SW)
93 static char *Prompts[] = {
105 , "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: "
109 static struct mapping_t ComposeHelp[] = {
110 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
111 {N_("Abort"), OP_EXIT},
112 {"To", OP_COMPOSE_EDIT_TO},
113 {"CC", OP_COMPOSE_EDIT_CC},
114 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
115 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
116 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
117 {N_("Help"), OP_HELP},
122 static struct mapping_t ComposeNewsHelp[] = {
123 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
124 {N_("Abort"), OP_EXIT},
125 {"Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS},
126 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
127 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
128 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
129 {N_("Help"), OP_HELP},
134 static void snd_entry (char *b, size_t blen, MUTTMENU * menu, int num)
136 mutt_FormatString (b, blen, NONULL (AttachFormat), mutt_attach_fmt,
137 (unsigned long) (((ATTACHPTR **) menu->data)[num]),
138 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
143 #include "mutt_crypt.h"
145 static void redraw_crypt_lines (HEADER * msg)
149 if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME)) {
151 mvaddstr (HDR_CRYPT, SW, " Security: ");
152 else if (msg->security & APPLICATION_SMIME)
153 mvaddstr (HDR_CRYPT, SW, " S/MIME: ");
154 else if (msg->security & APPLICATION_PGP)
155 mvaddstr (HDR_CRYPT, SW, " PGP: ");
157 else if ((WithCrypto & APPLICATION_SMIME))
158 mvaddstr (HDR_CRYPT, SW, " S/MIME: ");
159 else if ((WithCrypto & APPLICATION_PGP))
160 mvaddstr (HDR_CRYPT, SW, " PGP: ");
164 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
165 addstr (_("Sign, Encrypt"));
166 else if (msg->security & ENCRYPT)
167 addstr (_("Encrypt"));
168 else if (msg->security & SIGN)
173 if ((WithCrypto & APPLICATION_PGP))
174 if ((msg->security & APPLICATION_PGP)
175 && (msg->security & (ENCRYPT | SIGN))) {
176 if ((msg->security & INLINE))
177 addstr (_(" (inline)"));
179 addstr (_(" (PGP/MIME)"));
183 move (HDR_CRYPTINFO, SW);
185 if ((WithCrypto & APPLICATION_PGP)
186 && msg->security & APPLICATION_PGP && msg->security & SIGN)
187 printw ("%s%s", _(" sign as: "),
188 PgpSignAs ? PgpSignAs : _("<default>"));
190 if ((WithCrypto & APPLICATION_SMIME)
191 && msg->security & APPLICATION_SMIME && msg->security & SIGN) {
192 printw ("%s%s", _(" sign as: "),
193 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
196 if ((WithCrypto & APPLICATION_SMIME)
197 && (msg->security & APPLICATION_SMIME)
198 && (msg->security & ENCRYPT)
199 && SmimeCryptAlg && *SmimeCryptAlg) {
200 mvprintw (HDR_CRYPTINFO, SW + 40, "%s%s", _("Encrypt with: "),
201 NONULL (SmimeCryptAlg));
209 static void redraw_mix_line (LIST * chain)
214 mvaddstr (HDR_MIX, SW, " Mix: ");
217 addstr ("<no chain defined>");
222 for (c = 12; chain; chain = chain->next) {
224 if (t && t[0] == '0' && t[1] == '\0')
227 if (c + str_len (t) + 2 >= COLS - SW)
234 c += str_len (t) + 2;
237 #endif /* MIXMASTER */
239 static int check_attachments (ATTACHPTR ** idx, short idxlen)
243 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
245 for (i = 0; i < idxlen; i++) {
246 strfcpy (pretty, idx[i]->content->filename, sizeof (pretty));
247 if (stat (idx[i]->content->filename, &st) != 0) {
248 mutt_pretty_mailbox (pretty);
249 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
253 if (idx[i]->content->stamp < st.st_mtime) {
254 mutt_pretty_mailbox (pretty);
255 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
258 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
259 mutt_update_encoding (idx[i]->content);
268 static void draw_envelope_addr (int line, ADDRESS * addr)
273 rfc822_write_address (buf, sizeof (buf), addr, 1);
274 mvprintw (line, SW, TITLE_FMT, Prompts[line - 1]);
275 mutt_paddstr (W, buf);
278 static void draw_envelope (HEADER * msg, char *fcc)
280 draw_envelope_addr (HDR_FROM, msg->env->from);
282 if (!option (OPTNEWSSEND)) {
284 draw_envelope_addr (HDR_TO, msg->env->to);
285 draw_envelope_addr (HDR_CC, msg->env->cc);
286 draw_envelope_addr (HDR_BCC, msg->env->bcc);
290 mvprintw (HDR_TO, SW, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
291 mutt_paddstr (W, NONULL (msg->env->newsgroups));
292 mvprintw (HDR_CC, SW, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
293 mutt_paddstr (W, NONULL (msg->env->followup_to));
294 if (option (OPTXCOMMENTTO)) {
295 mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]);
296 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
300 mvprintw (HDR_SUBJECT, SW, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
301 mutt_paddstr (W, NONULL (msg->env->subject));
302 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
303 mvprintw (HDR_FCC, SW, TITLE_FMT, Prompts[HDR_FCC - 1]);
304 mutt_paddstr (W, fcc);
307 redraw_crypt_lines (msg);
310 redraw_mix_line (msg->chain);
313 SETCOLOR (MT_COLOR_STATUS);
314 mvaddstr (HDR_ATTACH - 1, SW, _("-- Attachments"));
315 BKGDSET (MT_COLOR_STATUS);
318 BKGDSET (MT_COLOR_NORMAL);
319 SETCOLOR (MT_COLOR_NORMAL);
322 static int edit_address_list (int line, ADDRESS ** addr)
324 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
327 mutt_addrlist_to_local (*addr);
328 rfc822_write_address (buf, sizeof (buf), *addr, 0);
329 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
330 rfc822_free_address (addr);
331 *addr = mutt_parse_adrlist (*addr, buf);
332 *addr = mutt_expand_aliases (*addr);
335 if (option (OPTNEEDREDRAW)) {
336 unset_option (OPTNEEDREDRAW);
337 return (REDRAW_FULL);
340 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
341 mutt_error (_("Warning: '%s' is a bad IDN."), err);
346 /* redraw the expanded list so the user can see the result */
348 rfc822_write_address (buf, sizeof (buf), *addr, 1);
349 move (line, HDR_XOFFSET + SW);
350 mutt_paddstr (W, buf);
355 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
357 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
360 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
362 if (x == 0 && menu->max == 1) {
363 mutt_error _("You may not delete the only attachment.");
365 idx[x]->content->tagged = 0;
369 for (y = 0; y < *idxlen; y++) {
370 if (idx[y]->content->next == idx[x]->content) {
371 idx[y]->content->next = idx[x]->content->next;
376 idx[x]->content->next = NULL;
377 idx[x]->content->parts = NULL;
378 mutt_free_body (&(idx[x]->content));
379 mem_free (&idx[x]->tree);
381 for (; x < *idxlen - 1; x++)
383 menu->max = --(*idxlen);
388 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
390 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
392 idx[idxlen - 1]->content->next = idx[idxlen]->content;
393 idx[idxlen]->content->aptr = idx[idxlen];
394 menu->current = idxlen++;
395 mutt_update_tree (idx, idxlen);
402 * cum_attachs_size: Cumulative Attachments Size
404 * Returns the total number of bytes used by the attachments in the
405 * attachment list _after_ content-transfer-encodings have been
410 static unsigned long cum_attachs_size (MUTTMENU * menu)
414 ATTACHPTR **idx = menu->data;
418 for (i = 0, s = 0; i < menu->max; i++) {
422 b->content = mutt_get_content_info (b->filename, b);
424 if ((info = b->content)) {
425 switch (b->encoding) {
426 case ENCQUOTEDPRINTABLE:
427 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
430 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
433 s += info->lobin + info->hibin + info->ascii + info->crlf;
443 * compose_format_str()
445 * %a = total number of attachments
446 * %h = hostname [option]
447 * %l = approx. length of current message (in bytes)
450 * This function is similar to status_format_str(). Look at that function for
451 * help when modifying this function.
454 static const char *compose_format_str (char *buf, size_t buflen, char op,
455 const char *src, const char *prefix,
456 const char *ifstring,
457 const char *elsestring,
458 unsigned long data, format_flag flags)
460 char fmt[SHORT_STRING], tmp[SHORT_STRING];
461 int optional = (flags & M_FORMAT_OPTIONAL);
462 MUTTMENU *menu = (MUTTMENU *) data;
466 case 'a': /* total number of attachments */
467 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
468 snprintf (buf, buflen, fmt, menu->max);
471 case 'h': /* hostname */
472 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
473 snprintf (buf, buflen, fmt, NONULL (Hostname));
476 case 'l': /* approx length of current message in bytes */
477 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
478 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
479 snprintf (buf, buflen, fmt, tmp);
483 strncpy (buf, mutt_make_version (0), buflen);
491 snprintf (buf, buflen, "%%%s%c", prefix, op);
496 compose_status_line (buf, buflen, menu, ifstring);
497 else if (flags & M_FORMAT_OPTIONAL)
498 compose_status_line (buf, buflen, menu, elsestring);
503 static void compose_status_line (char *buf, size_t buflen, MUTTMENU * menu,
506 mutt_FormatString (buf, buflen, p, compose_format_str,
507 (unsigned long) menu, 0);
513 * 1 message should be postponed
517 int mutt_compose_menu (HEADER * msg, /* structure for new message */
518 char *fcc, /* where to save a copy of the message */
519 size_t fcclen, HEADER * cur)
520 { /* current message */
521 char helpstr[SHORT_STRING];
522 char buf[LONG_STRING];
523 char fname[_POSIX_PATH_MAX];
525 ATTACHPTR **idx = NULL;
529 int r = -1; /* return value */
532 int fccSet = 0; /* has the user edited the Fcc: field ? */
533 CONTEXT *ctx = NULL, *this = NULL;
535 /* Sort, SortAux could be changed in mutt_index_menu() */
536 int oldSort, oldSortAux;
540 int news = 0; /* is it a news article ? */
542 if (option (OPTNEWSSEND))
546 mutt_attach_init (msg->content);
547 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
549 menu = mutt_new_menu ();
550 menu->menu = MENU_COMPOSE;
551 menu->offset = HDR_ATTACH;
553 menu->make_entry = snd_entry;
554 menu->tag = mutt_tag_attach;
559 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
564 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
567 if (option (OPTMBOXPANE))
571 unset_option (OPTNEWS); /* for any case */
573 switch (op = mutt_menuLoop (menu)) {
575 draw_envelope (msg, fcc);
576 menu->offset = HDR_ATTACH;
577 menu->pagelen = LINES - HDR_ATTACH - 2;
579 case OP_COMPOSE_EDIT_FROM:
580 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
581 mutt_message_hook (NULL, msg, M_SEND2HOOK);
583 case OP_COMPOSE_EDIT_TO:
587 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
588 mutt_message_hook (NULL, msg, M_SEND2HOOK);
593 case OP_COMPOSE_EDIT_BCC:
597 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
598 mutt_message_hook (NULL, msg, M_SEND2HOOK);
603 case OP_COMPOSE_EDIT_CC:
607 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
608 mutt_message_hook (NULL, msg, M_SEND2HOOK);
614 case OP_COMPOSE_EDIT_NEWSGROUPS:
616 if (msg->env->newsgroups)
617 strfcpy (buf, msg->env->newsgroups, sizeof (buf));
620 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
622 mem_free (&msg->env->newsgroups);
623 str_skip_trailws (buf);
624 msg->env->newsgroups = str_dup (str_skip_initws (buf));
625 move (HDR_TO, HDR_XOFFSET);
627 if (msg->env->newsgroups)
628 printw ("%-*.*s", W, W, msg->env->newsgroups);
633 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
636 if (msg->env->followup_to)
637 strfcpy (buf, msg->env->followup_to, sizeof (buf));
638 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
640 mem_free (&msg->env->followup_to);
641 str_skip_trailws (buf);
642 msg->env->followup_to = str_dup (str_skip_initws (buf));
643 move (HDR_CC, HDR_XOFFSET);
645 if (msg->env->followup_to)
646 printw ("%-*.*s", W, W, msg->env->followup_to);
651 case OP_COMPOSE_EDIT_X_COMMENT_TO:
652 if (news && option (OPTXCOMMENTTO)) {
654 if (msg->env->x_comment_to)
655 strfcpy (buf, msg->env->x_comment_to, sizeof (buf));
656 if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
658 mem_free (&msg->env->x_comment_to);
659 msg->env->x_comment_to = str_dup (buf);
660 move (HDR_BCC, HDR_XOFFSET);
662 if (msg->env->x_comment_to)
663 printw ("%-*.*s", W, W, msg->env->x_comment_to);
668 case OP_COMPOSE_EDIT_SUBJECT:
669 if (msg->env->subject)
670 strfcpy (buf, msg->env->subject, sizeof (buf));
673 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
674 str_replace (&msg->env->subject, buf);
675 move (HDR_SUBJECT, HDR_XOFFSET + SW);
677 if (msg->env->subject)
678 mutt_paddstr (W, msg->env->subject);
680 mutt_message_hook (NULL, msg, M_SEND2HOOK);
682 case OP_COMPOSE_EDIT_REPLY_TO:
683 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
684 mutt_message_hook (NULL, msg, M_SEND2HOOK);
686 case OP_COMPOSE_EDIT_FCC:
687 strfcpy (buf, fcc, sizeof (buf));
688 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
689 strfcpy (fcc, buf, _POSIX_PATH_MAX);
690 mutt_pretty_mailbox (fcc);
691 move (HDR_FCC, HDR_XOFFSET + SW);
692 mutt_paddstr (W, fcc);
695 MAYBE_REDRAW (menu->redraw);
696 mutt_message_hook (NULL, msg, M_SEND2HOOK);
698 case OP_COMPOSE_EDIT_MESSAGE:
699 if (Editor && (str_cmp ("builtin", Editor) != 0)
700 && !option (OPTEDITHDRS)) {
701 mutt_edit_file (Editor, msg->content->filename);
702 mutt_update_encoding (msg->content);
703 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
704 mutt_message_hook (NULL, msg, M_SEND2HOOK);
708 case OP_COMPOSE_EDIT_HEADERS:
709 if (str_cmp ("builtin", Editor) != 0 &&
710 (op == OP_COMPOSE_EDIT_HEADERS ||
711 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
712 char *tag = NULL, *err = NULL;
714 mutt_env_to_local (msg->env);
715 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
717 if (mutt_env_to_idna (msg->env, &tag, &err)) {
718 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
723 /* this is grouped with OP_COMPOSE_EDIT_HEADERS because the
724 attachment list could change if the user invokes ~v to edit
725 the message with headers, in which we need to execute the
726 code below to regenerate the index array */
727 mutt_builtin_editor (msg->content->filename, msg, cur);
729 mutt_update_encoding (msg->content);
731 /* attachments may have been added */
732 if (idxlen && idx[idxlen - 1]->content->next) {
733 for (i = 0; i < idxlen; i++)
737 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
743 menu->redraw = REDRAW_FULL;
744 mutt_message_hook (NULL, msg, M_SEND2HOOK);
749 case OP_COMPOSE_ATTACH_KEY:
750 if (!(WithCrypto & APPLICATION_PGP))
752 if (idxlen == idxmax) {
753 mem_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
757 idx[idxlen] = (ATTACHPTR *) mem_calloc (1, sizeof (ATTACHPTR));
758 if ((idx[idxlen]->content =
759 crypt_pgp_make_key_attachment (NULL)) != NULL) {
760 update_idx (menu, idx, idxlen++);
761 menu->redraw |= REDRAW_INDEX;
764 mem_free (&idx[idxlen]);
766 menu->redraw |= REDRAW_STATUS;
768 if (option (OPTNEEDREDRAW)) {
769 menu->redraw = REDRAW_FULL;
770 unset_option (OPTNEEDREDRAW);
773 mutt_message_hook (NULL, msg, M_SEND2HOOK);
777 case OP_COMPOSE_ATTACH_FILE:
779 char *prompt, **files;
783 prompt = _("Attach file");
787 if (_mutt_enter_fname
788 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
789 &numfiles) == -1 || *fname == '\0')
792 if (idxlen + numfiles >= idxmax) {
794 sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles));
800 mutt_message _("Attaching selected files...");
802 for (i = 0; i < numfiles; i++) {
803 char *att = files[i];
805 idx[idxlen] = (ATTACHPTR *) mem_calloc (1, sizeof (ATTACHPTR));
806 idx[idxlen]->unowned = 1;
807 idx[idxlen]->content = mutt_make_file_attach (att);
808 if (idx[idxlen]->content != NULL)
809 update_idx (menu, idx, idxlen++);
812 mutt_error (_("Unable to attach %s!"), att);
813 mem_free (&idx[idxlen]);
821 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
823 mutt_message_hook (NULL, msg, M_SEND2HOOK);
826 case OP_COMPOSE_ATTACH_MESSAGE:
828 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
835 prompt = _("Open mailbox to attach message from");
838 unset_option (OPTNEWS);
839 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
840 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
843 prompt = _("Open newsgroup to attach message from");
844 set_option (OPTNEWS);
850 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
853 strfcpy (fname, NONULL (Context->path), sizeof (fname));
854 mutt_pretty_mailbox (fname);
857 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
862 if (option (OPTNEWS))
863 nntp_expand_path (fname, sizeof (fname),
864 &CurrentNewsSrv->conn->account);
867 mutt_expand_path (fname, sizeof (fname));
869 if (mx_get_magic (fname) != M_IMAP)
872 if (mx_get_magic (fname) != M_POP)
875 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
877 /* check to make sure the file exists and is readable */
878 if (access (fname, R_OK) == -1) {
883 menu->redraw = REDRAW_FULL;
885 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
891 if (!ctx->msgcount) {
892 mx_close_mailbox (ctx, NULL);
894 mutt_error _("No messages in that folder.");
899 this = Context; /* remember current folder and sort methods */
901 oldSortAux = SortAux;
904 set_option (OPTATTACHMSG);
905 mutt_message _("Tag the messages you want to attach!");
907 close = mutt_index_menu ();
908 unset_option (OPTATTACHMSG);
911 /* go back to the folder we started from */
913 /* Restore old $sort and $sort_aux */
915 SortAux = oldSortAux;
916 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
920 if (idxlen + Context->tagged >= idxmax) {
922 sizeof (ATTACHPTR *) * (idxmax +=
923 5 + Context->tagged));
927 for (i = 0; i < Context->msgcount; i++) {
928 h = Context->hdrs[i];
930 idx[idxlen] = (ATTACHPTR *) mem_calloc (1, sizeof (ATTACHPTR));
931 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
932 if (idx[idxlen]->content != NULL)
933 update_idx (menu, idx, idxlen++);
935 mutt_error _("Unable to attach!");
937 mem_free (&idx[idxlen]);
941 menu->redraw |= REDRAW_FULL;
943 if (close == OP_QUIT)
944 mx_close_mailbox (Context, NULL);
946 mx_fastclose_mailbox (Context);
949 /* go back to the folder we started from */
951 /* Restore old $sort and $sort_aux */
953 SortAux = oldSortAux;
955 mutt_message_hook (NULL, msg, M_SEND2HOOK);
960 if (idx[menu->current]->unowned)
961 idx[menu->current]->content->unlink = 0;
962 if (delete_attachment (menu, &idxlen, menu->current) == -1)
964 mutt_update_tree (idx, idxlen);
966 if (menu->current > idxlen - 1)
967 menu->current = idxlen - 1;
972 if (menu->current == 0)
973 msg->content = idx[0]->content;
975 menu->redraw |= REDRAW_STATUS;
976 mutt_message_hook (NULL, msg, M_SEND2HOOK);
979 #define CURRENT idx[menu->current]->content
981 case OP_COMPOSE_TOGGLE_RECODE:
984 if (!mutt_is_text_part (CURRENT)) {
985 mutt_error (_("Recoding only affects text attachments."));
988 CURRENT->noconv = !CURRENT->noconv;
990 mutt_message (_("The current attachment won't be converted."));
992 mutt_message (_("The current attachment will be converted."));
993 menu->redraw = REDRAW_CURRENT;
994 mutt_message_hook (NULL, msg, M_SEND2HOOK);
999 case OP_COMPOSE_EDIT_DESCRIPTION:
1002 idx[menu->current]->content->description ?
1003 idx[menu->current]->content->description : "", sizeof (buf));
1004 /* header names should not be translated */
1005 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
1006 str_replace (&idx[menu->current]->content->description, buf);
1007 menu->redraw = REDRAW_CURRENT;
1009 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1012 case OP_COMPOSE_UPDATE_ENCODING:
1014 if (menu->tagprefix) {
1017 for (top = msg->content; top; top = top->next) {
1019 mutt_update_encoding (top);
1021 menu->redraw = REDRAW_FULL;
1024 mutt_update_encoding (idx[menu->current]->content);
1025 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1027 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1030 case OP_COMPOSE_TOGGLE_DISPOSITION:
1031 /* toggle the content-disposition between inline/attachment */
1032 idx[menu->current]->content->disposition =
1033 (idx[menu->current]->content->disposition ==
1034 DISPINLINE) ? DISPATTACH : DISPINLINE;
1035 menu->redraw = REDRAW_CURRENT;
1041 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
1043 /* this may have been a change to text/something */
1044 mutt_update_encoding (idx[menu->current]->content);
1046 menu->redraw = REDRAW_CURRENT;
1048 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1051 case OP_COMPOSE_EDIT_ENCODING:
1053 strfcpy (buf, ENCODING (idx[menu->current]->content->encoding),
1055 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
1056 sizeof (buf), 0) == 0 && buf[0]) {
1057 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
1058 idx[menu->current]->content->encoding = i;
1059 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1060 mutt_clear_error ();
1063 mutt_error _("Invalid encoding.");
1065 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1068 case OP_COMPOSE_SEND_MESSAGE:
1070 /* Note: We don't invoke send2-hook here, since we want to leave
1071 * users an opportunity to change settings from the ":" prompt.
1074 if (check_attachments (idx, idxlen) != 0) {
1075 menu->redraw = REDRAW_FULL;
1081 if (msg->chain && mix_check_message (msg) != 0)
1085 if (!fccSet && *fcc) {
1086 if ((i = query_quadoption (OPT_COPY,
1087 _("Save a copy of this message?"))) == -1)
1097 case OP_COMPOSE_EDIT_FILE:
1099 mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename);
1100 mutt_update_encoding (idx[menu->current]->content);
1101 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1102 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1105 case OP_COMPOSE_TOGGLE_UNLINK:
1107 idx[menu->current]->content->unlink =
1108 !idx[menu->current]->content->unlink;
1111 /* OPTRESOLVE is otherwise ignored on this menu.
1115 if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
1118 menu->redraw = REDRAW_INDEX;
1119 /* No send2hook since this doesn't change the message. */
1122 case OP_COMPOSE_GET_ATTACHMENT:
1124 if (menu->tagprefix) {
1127 for (top = msg->content; top; top = top->next) {
1129 mutt_get_tmp_attachment (top);
1131 menu->redraw = REDRAW_FULL;
1133 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1134 menu->redraw = REDRAW_CURRENT;
1136 /* No send2hook since this doesn't change the message. */
1139 case OP_COMPOSE_RENAME_FILE:
1141 strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname));
1142 mutt_pretty_mailbox (fname);
1143 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1145 if (stat (idx[menu->current]->content->filename, &st) == -1) {
1146 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1150 mutt_expand_path (fname, sizeof (fname));
1151 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1154 str_replace (&idx[menu->current]->content->filename, fname);
1155 menu->redraw = REDRAW_CURRENT;
1157 if (idx[menu->current]->content->stamp >= st.st_mtime)
1158 mutt_stamp_attachment (idx[menu->current]->content);
1161 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1164 case OP_COMPOSE_NEW_MIME:
1171 CLEARLINE (LINES - 1);
1173 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1176 mutt_expand_path (fname, sizeof (fname));
1178 /* Call to lookup_mime_type () ? maybe later */
1180 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1184 if (!(p = strchr (type, '/'))) {
1185 mutt_error _("Content-Type is of the form base/sub");
1190 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1191 mutt_error (_("Unknown Content-Type %s"), type);
1194 if (idxlen == idxmax) {
1195 mem_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
1199 idx[idxlen] = (ATTACHPTR *) mem_calloc (1, sizeof (ATTACHPTR));
1200 /* Touch the file */
1201 if (!(fp = safe_fopen (fname, "w"))) {
1202 mutt_error (_("Can't create file %s"), fname);
1203 mem_free (&idx[idxlen]);
1208 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1210 _("What we have here is a failure to make an attachment");
1213 update_idx (menu, idx, idxlen++);
1215 idx[menu->current]->content->type = itype;
1216 str_replace (&idx[menu->current]->content->subtype, p);
1217 idx[menu->current]->content->unlink = 1;
1218 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1220 if (mutt_compose_attachment (idx[menu->current]->content)) {
1221 mutt_update_encoding (idx[menu->current]->content);
1222 menu->redraw = REDRAW_FULL;
1225 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1228 case OP_COMPOSE_EDIT_MIME:
1230 if (mutt_edit_attachment (idx[menu->current]->content)) {
1231 mutt_update_encoding (idx[menu->current]->content);
1232 menu->redraw = REDRAW_FULL;
1234 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1237 case OP_VIEW_ATTACH:
1238 case OP_DISPLAY_HEADERS:
1240 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1242 menu->redraw = REDRAW_FULL;
1243 /* no send2hook, since this doesn't modify the message */
1248 mutt_save_attachment_list (NULL, menu->tagprefix,
1249 menu->tagprefix ? msg->content : idx[menu->
1251 content, NULL, menu);
1252 MAYBE_REDRAW (menu->redraw);
1253 /* no send2hook, since this doesn't modify the message */
1258 mutt_print_attachment_list (NULL, menu->tagprefix,
1259 menu->tagprefix ? msg->content : idx[menu->
1262 /* no send2hook, since this doesn't modify the message */
1268 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1269 menu->tagprefix ? msg->content : idx[menu->
1271 content, op == OP_FILTER);
1272 if (op == OP_FILTER) /* cte might have changed */
1273 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1274 menu->redraw |= REDRAW_STATUS;
1275 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1280 query_quadoption (OPT_POSTPONE,
1281 _("Postpone this message?"))) == M_NO) {
1282 while (idxlen-- > 0) {
1283 /* avoid freeing other attachments */
1284 idx[idxlen]->content->next = NULL;
1285 idx[idxlen]->content->parts = NULL;
1286 if (idx[idxlen]->unowned)
1287 idx[idxlen]->content->unlink = 0;
1288 mutt_free_body (&idx[idxlen]->content);
1289 mem_free (&idx[idxlen]->tree);
1290 mem_free (&idx[idxlen]);
1302 /* fall through to postpone! */
1304 case OP_COMPOSE_POSTPONE_MESSAGE:
1306 if (check_attachments (idx, idxlen) != 0) {
1307 menu->redraw = REDRAW_FULL;
1315 case OP_COMPOSE_ISPELL:
1317 snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1318 msg->content->filename);
1319 if (mutt_system (buf) == -1)
1320 mutt_error (_("Error running \"%s\"!"), buf);
1322 mutt_update_encoding (msg->content);
1323 menu->redraw |= REDRAW_STATUS;
1327 case OP_COMPOSE_WRITE_MESSAGE:
1331 strfcpy (fname, NONULL (Context->path), sizeof (fname));
1332 mutt_pretty_mailbox (fname);
1335 msg->content = idx[0]->content;
1336 if (mutt_enter_fname
1337 (_("Write message to mailbox"), fname, sizeof (fname),
1338 &menu->redraw, 1) != -1 && fname[0]) {
1339 mutt_message (_("Writing message to %s ..."), fname);
1340 mutt_expand_path (fname, sizeof (fname));
1342 if (msg->content->next)
1343 msg->content = mutt_make_multipart (msg->content);
1345 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1346 msg->content = mutt_remove_multipart (msg->content);
1348 mutt_message _("Message written.");
1354 case OP_COMPOSE_PGP_MENU:
1355 if (!(WithCrypto & APPLICATION_PGP))
1357 if ((WithCrypto & APPLICATION_SMIME)
1358 && msg->security & APPLICATION_SMIME) {
1359 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1361 mutt_clear_error ();
1366 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1367 redraw_crypt_lines (msg);
1368 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1372 case OP_FORGET_PASSPHRASE:
1373 crypt_forget_passphrase ();
1377 case OP_COMPOSE_SMIME_MENU:
1378 if (!(WithCrypto & APPLICATION_SMIME))
1381 if ((WithCrypto & APPLICATION_PGP)
1382 && msg->security & APPLICATION_PGP) {
1383 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1385 mutt_clear_error ();
1390 msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1391 redraw_crypt_lines (msg);
1392 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1397 case OP_COMPOSE_MIX:
1399 mix_make_chain (&msg->chain, &menu->redraw);
1400 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1406 /* Draw formated compose status line */
1407 if (menu->redraw & REDRAW_STATUS) {
1408 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1409 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1410 SETCOLOR (MT_COLOR_STATUS);
1411 printw ("%-*.*s", COLS, COLS, buf);
1412 SETCOLOR (MT_COLOR_NORMAL);
1413 menu->redraw &= ~REDRAW_STATUS;
1417 mutt_menuDestroy (&menu);
1420 msg->content = idx[0]->content;
1421 for (i = 0; i < idxlen; i++) {
1422 idx[i]->content->aptr = NULL;
1427 msg->content = NULL;