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.
18 #include <lib-lib/mem.h>
19 #include <lib-lib/str.h>
20 #include <lib-lib/macros.h>
21 #include <lib-lib/file.h>
22 #include <lib-lib/mapping.h>
24 #include <lib-mime/mime.h>
28 #include "mutt_curses.h"
29 #include "mutt_idna.h"
30 #include "mutt_menu.h"
33 #include "recvattach.h"
56 static const char *There_are_no_attachments = N_("There are no attachments.");
58 #define CHECK_COUNT if (idxlen == 0) { mutt_error _(There_are_no_attachments); break; }
85 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
87 HDR_ATTACH = (HDR_FCC + 7)
91 #define HDR_XOFFSET 14
92 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
93 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
94 #define W (COLS - HDR_XOFFSET - SW)
96 static const char *Prompts[] = {
108 , "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: "
112 static struct mapping_t ComposeHelp[] = {
113 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
114 {N_("Abort"), OP_EXIT},
115 {"To", OP_COMPOSE_EDIT_TO},
116 {"CC", OP_COMPOSE_EDIT_CC},
117 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
118 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
119 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
120 {N_("Help"), OP_HELP},
125 static struct mapping_t ComposeNewsHelp[] = {
126 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
127 {N_("Abort"), OP_EXIT},
128 {"Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS},
129 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
130 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
131 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
132 {N_("Help"), OP_HELP},
138 static void snd_entry (char *b, ssize_t blen, MUTTMENU * menu, int num) {
139 int w=(COLS-SW)>blen?blen:COLS-SW;
140 mutt_FormatString (b, w, NONULL (AttachFormat), mutt_attach_fmt,
141 (unsigned long) (((ATTACHPTR **) menu->data)[num]),
142 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
145 #include "mutt_crypt.h"
147 static void redraw_crypt_lines (HEADER * msg)
151 if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME)) {
153 mvaddstr (HDR_CRYPT, SW, " Security: ");
154 else if (msg->security & APPLICATION_SMIME)
155 mvaddstr (HDR_CRYPT, SW, " S/MIME: ");
156 else if (msg->security & APPLICATION_PGP)
157 mvaddstr (HDR_CRYPT, SW, " PGP: ");
159 else if ((WithCrypto & APPLICATION_SMIME))
160 mvaddstr (HDR_CRYPT, SW, " S/MIME: ");
161 else if ((WithCrypto & APPLICATION_PGP))
162 mvaddstr (HDR_CRYPT, SW, " PGP: ");
166 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
167 addstr (_("Sign, Encrypt"));
168 else if (msg->security & ENCRYPT)
169 addstr (_("Encrypt"));
170 else if (msg->security & SIGN)
175 if ((WithCrypto & APPLICATION_PGP))
176 if ((msg->security & APPLICATION_PGP)
177 && (msg->security & (ENCRYPT | SIGN))) {
178 if ((msg->security & INLINE))
179 addstr (_(" (inline)"));
181 addstr (_(" (PGP/MIME)"));
185 move (HDR_CRYPTINFO, SW);
187 if ((WithCrypto & APPLICATION_PGP)
188 && msg->security & APPLICATION_PGP && msg->security & SIGN)
189 printw ("%s%s", _(" sign as: "),
190 PgpSignAs ? PgpSignAs : _("<default>"));
192 if ((WithCrypto & APPLICATION_SMIME)
193 && msg->security & APPLICATION_SMIME && msg->security & SIGN) {
194 printw ("%s%s", _(" sign as: "),
195 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
198 if ((WithCrypto & APPLICATION_SMIME)
199 && (msg->security & APPLICATION_SMIME)
200 && (msg->security & ENCRYPT)
201 && SmimeCryptAlg && *SmimeCryptAlg) {
202 mvprintw (HDR_CRYPTINFO, SW + 40, "%s%s", _("Encrypt with: "),
203 NONULL (SmimeCryptAlg));
211 static void redraw_mix_line (LIST * chain)
216 mvaddstr (HDR_MIX, SW, " Mix: ");
219 addstr ("<no chain defined>");
224 for (c = 12; chain; chain = chain->next) {
226 if (t && t[0] == '0' && t[1] == '\0')
229 if (c + m_strlen(t) + 2 >= COLS - SW)
236 c += m_strlen(t) + 2;
239 #endif /* MIXMASTER */
241 static int check_attachments (ATTACHPTR ** idx, short idxlen)
245 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
247 for (i = 0; i < idxlen; i++) {
248 m_strcpy(pretty, sizeof(pretty), idx[i]->content->filename);
249 if (stat (idx[i]->content->filename, &st) != 0) {
250 mutt_pretty_mailbox (pretty);
251 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
255 if (idx[i]->content->stamp < st.st_mtime) {
256 mutt_pretty_mailbox (pretty);
257 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
260 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
261 mutt_update_encoding (idx[i]->content);
270 static void draw_envelope_addr (int line, address_t * addr)
275 rfc822_write_address (buf, sizeof (buf), addr, 1);
276 mvprintw (line, SW, TITLE_FMT, Prompts[line - 1]);
277 mutt_paddstr (W, buf);
280 static void draw_envelope (HEADER * msg, char *fcc)
282 draw_envelope_addr (HDR_FROM, msg->env->from);
284 if (!option (OPTNEWSSEND)) {
286 draw_envelope_addr (HDR_TO, msg->env->to);
287 draw_envelope_addr (HDR_CC, msg->env->cc);
288 draw_envelope_addr (HDR_BCC, msg->env->bcc);
292 mvprintw (HDR_TO, SW, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
293 mutt_paddstr (W, NONULL (msg->env->newsgroups));
294 mvprintw (HDR_CC, SW, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
295 mutt_paddstr (W, NONULL (msg->env->followup_to));
296 if (option (OPTXCOMMENTTO)) {
297 mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]);
298 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
302 mvprintw (HDR_SUBJECT, SW, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
303 mutt_paddstr (W, NONULL (msg->env->subject));
304 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
305 mvprintw (HDR_FCC, SW, TITLE_FMT, Prompts[HDR_FCC - 1]);
306 mutt_paddstr (W, fcc);
309 redraw_crypt_lines (msg);
312 redraw_mix_line (msg->chain);
315 SETCOLOR (MT_COLOR_STATUS);
316 mvaddstr (HDR_ATTACH - 1, SW, _("-- Attachments"));
317 BKGDSET (MT_COLOR_STATUS);
320 BKGDSET (MT_COLOR_NORMAL);
321 SETCOLOR (MT_COLOR_NORMAL);
324 static int edit_address_list (int line, address_t ** addr)
326 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
329 mutt_addrlist_to_local (*addr);
330 rfc822_write_address (buf, sizeof (buf), *addr, 0);
331 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
332 address_delete (addr);
333 *addr = mutt_parse_adrlist (*addr, buf);
334 *addr = mutt_expand_aliases (*addr);
337 if (option (OPTNEEDREDRAW)) {
338 unset_option (OPTNEEDREDRAW);
339 return (REDRAW_FULL);
342 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
343 mutt_error (_("Warning: '%s' is a bad IDN."), err);
348 /* redraw the expanded list so the user can see the result */
350 rfc822_write_address (buf, sizeof (buf), *addr, 1);
351 move (line, HDR_XOFFSET + SW);
352 mutt_paddstr (W, buf);
357 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
359 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
362 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
364 if (x == 0 && menu->max == 1) {
365 mutt_error _("You may not delete the only attachment.");
367 idx[x]->content->tagged = 0;
371 for (y = 0; y < *idxlen; y++) {
372 if (idx[y]->content->next == idx[x]->content) {
373 idx[y]->content->next = idx[x]->content->next;
378 idx[x]->content->next = NULL;
379 idx[x]->content->parts = NULL;
380 mutt_free_body (&(idx[x]->content));
381 p_delete(&idx[x]->tree);
383 for (; x < *idxlen - 1; x++)
385 menu->max = --(*idxlen);
390 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
392 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
394 idx[idxlen - 1]->content->next = idx[idxlen]->content;
395 idx[idxlen]->content->aptr = idx[idxlen];
396 menu->current = idxlen++;
397 mutt_update_tree (idx, idxlen);
404 * cum_attachs_size: Cumulative Attachments Size
406 * Returns the total number of bytes used by the attachments in the
407 * attachment list _after_ content-transfer-encodings have been
412 static unsigned long cum_attachs_size (MUTTMENU * menu)
416 ATTACHPTR **idx = menu->data;
420 for (i = 0, s = 0; i < menu->max; i++) {
424 b->content = mutt_get_content_info (b->filename, b);
426 if ((info = b->content)) {
427 switch (b->encoding) {
428 case ENCQUOTEDPRINTABLE:
429 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
432 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
435 s += info->lobin + info->hibin + info->ascii + info->crlf;
445 * compose_format_str()
447 * %a = total number of attachments
448 * %h = hostname [option]
449 * %l = approx. length of current message (in bytes)
452 * This function is similar to status_format_str(). Look at that function for
453 * help when modifying this function.
456 static const char *compose_format_str (char *buf, size_t buflen, char op,
457 const char *src, const char *prefix,
458 const char *ifstring,
459 const char *elsestring,
460 unsigned long data, format_flag flags)
462 char fmt[SHORT_STRING], tmp[SHORT_STRING];
463 int optional = (flags & M_FORMAT_OPTIONAL);
464 MUTTMENU *menu = (MUTTMENU *) data;
468 case 'a': /* total number of attachments */
469 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
470 snprintf (buf, buflen, fmt, menu->max);
473 case 'h': /* hostname */
474 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
475 snprintf (buf, buflen, fmt, NONULL (Hostname));
478 case 'l': /* approx length of current message in bytes */
479 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
480 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
481 snprintf (buf, buflen, fmt, tmp);
485 m_strcpy(buf, buflen, mutt_make_version (0));
493 snprintf (buf, buflen, "%%%s%c", prefix, op);
498 compose_status_line (buf, buflen, menu, ifstring);
499 else if (flags & M_FORMAT_OPTIONAL)
500 compose_status_line (buf, buflen, menu, elsestring);
505 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
508 int w=(COLS-SW)>buflen?buflen:(COLS-SW);
509 mutt_FormatString (buf, w, p, compose_format_str,
510 (unsigned long) menu, 0);
516 * 1 message should be postponed
520 int mutt_compose_menu (HEADER * msg, /* structure for new message */
521 char *fcc, /* where to save a copy of the message */
522 size_t fcclen, HEADER * cur)
523 { /* current message */
524 char helpstr[SHORT_STRING];
525 char buf[LONG_STRING];
526 char fname[_POSIX_PATH_MAX];
528 ATTACHPTR **idx = NULL;
532 int r = -1; /* return value */
535 int fccSet = 0; /* has the user edited the Fcc: field ? */
536 CONTEXT *ctx = NULL, *this = NULL;
538 /* Sort, SortAux could be changed in mutt_index_menu() */
539 int oldSort, oldSortAux;
543 int news = 0; /* is it a news article ? */
545 if (option (OPTNEWSSEND))
549 mutt_attach_init (msg->content);
550 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
552 menu = mutt_new_menu ();
553 menu->menu = MENU_COMPOSE;
554 menu->offset = HDR_ATTACH;
556 menu->make_entry = snd_entry;
557 menu->tag = mutt_tag_attach;
562 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
567 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
570 if (option (OPTMBOXPANE))
574 unset_option (OPTNEWS); /* for any case */
576 switch (op = mutt_menuLoop (menu)) {
578 draw_envelope (msg, fcc);
579 menu->offset = HDR_ATTACH;
580 menu->pagelen = LINES - HDR_ATTACH - 2;
582 case OP_COMPOSE_EDIT_FROM:
583 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
584 mutt_message_hook (NULL, msg, M_SEND2HOOK);
586 case OP_COMPOSE_EDIT_TO:
590 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
591 mutt_message_hook (NULL, msg, M_SEND2HOOK);
596 case OP_COMPOSE_EDIT_BCC:
600 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
601 mutt_message_hook (NULL, msg, M_SEND2HOOK);
606 case OP_COMPOSE_EDIT_CC:
610 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
611 mutt_message_hook (NULL, msg, M_SEND2HOOK);
617 case OP_COMPOSE_EDIT_NEWSGROUPS:
619 if (msg->env->newsgroups)
620 m_strcpy(buf, sizeof(buf), msg->env->newsgroups);
623 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
625 p_delete(&msg->env->newsgroups);
626 str_skip_trailws (buf);
627 msg->env->newsgroups = m_strdup(vskipspaces(buf));
628 move (HDR_TO, HDR_XOFFSET);
630 if (msg->env->newsgroups)
631 printw ("%-*.*s", W, W, msg->env->newsgroups);
636 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
639 if (msg->env->followup_to)
640 m_strcpy(buf, sizeof(buf), msg->env->followup_to);
641 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
643 p_delete(&msg->env->followup_to);
644 str_skip_trailws (buf);
645 msg->env->followup_to = m_strdup(vskipspaces(buf));
646 move (HDR_CC, HDR_XOFFSET);
648 if (msg->env->followup_to)
649 printw ("%-*.*s", W, W, msg->env->followup_to);
654 case OP_COMPOSE_EDIT_X_COMMENT_TO:
655 if (news && option (OPTXCOMMENTTO)) {
657 if (msg->env->x_comment_to)
658 m_strcpy(buf, sizeof(buf), msg->env->x_comment_to);
659 if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
661 p_delete(&msg->env->x_comment_to);
662 msg->env->x_comment_to = m_strdup(buf);
663 move (HDR_BCC, HDR_XOFFSET);
665 if (msg->env->x_comment_to)
666 printw ("%-*.*s", W, W, msg->env->x_comment_to);
671 case OP_COMPOSE_EDIT_SUBJECT:
672 if (msg->env->subject)
673 m_strcpy(buf, sizeof(buf), msg->env->subject);
676 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
677 m_strreplace(&msg->env->subject, buf);
678 move (HDR_SUBJECT, HDR_XOFFSET + SW);
680 if (msg->env->subject)
681 mutt_paddstr (W, msg->env->subject);
683 mutt_message_hook (NULL, msg, M_SEND2HOOK);
685 case OP_COMPOSE_EDIT_REPLY_TO:
686 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
687 mutt_message_hook (NULL, msg, M_SEND2HOOK);
689 case OP_COMPOSE_EDIT_FCC:
690 m_strcpy(buf, sizeof(buf), fcc);
691 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
692 m_strcpy(fcc, _POSIX_PATH_MAX, buf);
693 mutt_pretty_mailbox (fcc);
694 move (HDR_FCC, HDR_XOFFSET + SW);
695 mutt_paddstr (W, fcc);
698 MAYBE_REDRAW (menu->redraw);
699 mutt_message_hook (NULL, msg, M_SEND2HOOK);
701 case OP_COMPOSE_EDIT_MESSAGE:
702 if (Editor && (m_strcmp("builtin", Editor) != 0)
703 && !option (OPTEDITHDRS)) {
704 mutt_edit_file (Editor, msg->content->filename);
705 mutt_update_encoding (msg->content);
706 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
707 mutt_message_hook (NULL, msg, M_SEND2HOOK);
711 case OP_COMPOSE_EDIT_HEADERS:
712 if (m_strcmp("builtin", Editor) != 0 &&
713 (op == OP_COMPOSE_EDIT_HEADERS ||
714 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
715 const char *tag = NULL;
716 const char *err = NULL;
718 mutt_env_to_local (msg->env);
719 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
721 if (mutt_env_to_idna (msg->env, &tag, &err)) {
722 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
727 /* this is grouped with OP_COMPOSE_EDIT_HEADERS because the
728 attachment list could change if the user invokes ~v to edit
729 the message with headers, in which we need to execute the
730 code below to regenerate the index array */
731 mutt_builtin_editor (msg->content->filename, msg, cur);
733 mutt_update_encoding (msg->content);
735 /* attachments may have been added */
736 if (idxlen && idx[idxlen - 1]->content->next) {
737 for (i = 0; i < idxlen; i++)
741 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
747 menu->redraw = REDRAW_FULL;
748 mutt_message_hook (NULL, msg, M_SEND2HOOK);
753 case OP_COMPOSE_ATTACH_KEY:
754 if (!(WithCrypto & APPLICATION_PGP))
756 if (idxlen == idxmax) {
757 p_realloc(&idx, idxmax += 5);
761 idx[idxlen] = p_new(ATTACHPTR, 1);
762 if ((idx[idxlen]->content =
763 crypt_pgp_make_key_attachment (NULL)) != NULL) {
764 update_idx (menu, idx, idxlen++);
765 menu->redraw |= REDRAW_INDEX;
768 p_delete(&idx[idxlen]);
770 menu->redraw |= REDRAW_STATUS;
772 if (option (OPTNEEDREDRAW)) {
773 menu->redraw = REDRAW_FULL;
774 unset_option (OPTNEEDREDRAW);
777 mutt_message_hook (NULL, msg, M_SEND2HOOK);
781 case OP_COMPOSE_ATTACH_FILE:
783 char *prompt, **files;
787 prompt = _("Attach file");
791 if (_mutt_enter_fname
792 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
793 &numfiles) == -1 || *fname == '\0')
796 if (idxlen + numfiles >= idxmax) {
797 p_realloc(&idx, idxmax += 5 + numfiles);
803 mutt_message _("Attaching selected files...");
805 for (i = 0; i < numfiles; i++) {
806 char *att = files[i];
808 idx[idxlen] = p_new(ATTACHPTR, 1);
809 idx[idxlen]->unowned = 1;
810 idx[idxlen]->content = mutt_make_file_attach (att);
811 if (idx[idxlen]->content != NULL)
812 update_idx (menu, idx, idxlen++);
815 mutt_error (_("Unable to attach %s!"), att);
816 p_delete(&idx[idxlen]);
824 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
826 mutt_message_hook (NULL, msg, M_SEND2HOOK);
829 case OP_COMPOSE_ATTACH_MESSAGE:
831 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
838 prompt = _("Open mailbox to attach message from");
841 unset_option (OPTNEWS);
842 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
843 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
846 prompt = _("Open newsgroup to attach message from");
847 set_option (OPTNEWS);
853 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
856 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
857 mutt_pretty_mailbox (fname);
860 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
865 if (option (OPTNEWS))
866 nntp_expand_path (fname, sizeof (fname),
867 &CurrentNewsSrv->conn->account);
870 mutt_expand_path (fname, sizeof (fname));
872 if (mx_get_magic (fname) != M_IMAP)
875 if (mx_get_magic (fname) != M_POP)
878 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
880 /* check to make sure the file exists and is readable */
881 if (access (fname, R_OK) == -1) {
886 menu->redraw = REDRAW_FULL;
888 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
894 if (!ctx->msgcount) {
895 mx_close_mailbox (ctx, NULL);
897 mutt_error _("No messages in that folder.");
902 this = Context; /* remember current folder and sort methods */
904 oldSortAux = SortAux;
907 set_option (OPTATTACHMSG);
908 mutt_message _("Tag the messages you want to attach!");
910 closed = mutt_index_menu ();
911 unset_option (OPTATTACHMSG);
914 /* go back to the folder we started from */
916 /* Restore old $sort and $sort_aux */
918 SortAux = oldSortAux;
919 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
923 if (idxlen + Context->tagged >= idxmax) {
924 p_realloc(&idx, idxmax += 5 + Context->tagged);
928 for (i = 0; i < Context->msgcount; i++) {
929 h = Context->hdrs[i];
931 idx[idxlen] = p_new(ATTACHPTR, 1);
932 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
933 if (idx[idxlen]->content != NULL)
934 update_idx (menu, idx, idxlen++);
936 mutt_error _("Unable to attach!");
938 p_delete(&idx[idxlen]);
942 menu->redraw |= REDRAW_FULL;
944 if (closed == OP_QUIT)
945 mx_close_mailbox (Context, NULL);
947 mx_fastclose_mailbox (Context);
950 /* go back to the folder we started from */
952 /* Restore old $sort and $sort_aux */
954 SortAux = oldSortAux;
956 mutt_message_hook (NULL, msg, M_SEND2HOOK);
961 if (idx[menu->current]->unowned)
962 idx[menu->current]->content->unlink = 0;
963 if (delete_attachment (menu, &idxlen, menu->current) == -1)
965 mutt_update_tree (idx, idxlen);
967 if (menu->current > idxlen - 1)
968 menu->current = idxlen - 1;
973 if (menu->current == 0)
974 msg->content = idx[0]->content;
976 menu->redraw |= REDRAW_STATUS;
977 mutt_message_hook (NULL, msg, M_SEND2HOOK);
980 #define CURRENT idx[menu->current]->content
982 case OP_COMPOSE_TOGGLE_RECODE:
985 if (!mutt_is_text_part (CURRENT)) {
986 mutt_error (_("Recoding only affects text attachments."));
989 CURRENT->noconv = !CURRENT->noconv;
991 mutt_message (_("The current attachment won't be converted."));
993 mutt_message (_("The current attachment will be converted."));
994 menu->redraw = REDRAW_CURRENT;
995 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1000 case OP_COMPOSE_EDIT_DESCRIPTION:
1002 m_strcpy(buf, sizeof(buf),
1003 NONULL(idx[menu->current]->content->description));
1004 /* header names should not be translated */
1005 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
1006 m_strreplace(&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 m_strcpy(buf, sizeof(buf),
1054 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 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
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 m_strreplace(&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 p_realloc(&idx, idxmax += 5);
1199 idx[idxlen] = p_new(ATTACHPTR, 1);
1200 /* Touch the file */
1201 if (!(fp = safe_fopen (fname, "w"))) {
1202 mutt_error (_("Can't create file %s"), fname);
1203 p_delete(&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 m_strreplace(&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 p_delete(&idx[idxlen]->tree);
1290 p_delete(&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 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
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 move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
1412 printw ("%-*.*s", COLS-SW, COLS-SW, buf);
1413 SETCOLOR (MT_COLOR_NORMAL);
1414 menu->redraw &= ~REDRAW_STATUS;
1418 mutt_menuDestroy (&menu);
1421 msg->content = idx[0]->content;
1422 for (i = 0; i < idxlen; i++) {
1423 idx[i]->content->aptr = NULL;
1428 msg->content = NULL;