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>
18 #include <lib-mime/mime.h>
20 #include <lib-ui/curses.h>
21 #include <lib-ui/enter.h>
22 #include <lib-ui/menu.h>
23 #include <lib-mx/mx.h>
27 #include "mutt_idna.h"
29 #include "recvattach.h"
36 #include <nntp/nntp.h>
39 static const char *There_are_no_attachments = N_("There are no attachments.");
41 #define CHECK_COUNT if (idxlen == 0) { mutt_error _(There_are_no_attachments); break; }
65 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
67 HDR_ATTACH = (HDR_FCC + 7)
71 #define HDR_XOFFSET 14
72 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
73 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
74 #define W (COLS - HDR_XOFFSET - SW)
76 static const char *Prompts[] = {
86 "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: "
90 static struct mapping_t ComposeHelp[] = {
91 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
92 {N_("Abort"), OP_EXIT},
93 {"To", OP_COMPOSE_EDIT_TO},
94 {"CC", OP_COMPOSE_EDIT_CC},
95 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
96 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
97 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
98 {N_("Help"), OP_HELP},
103 static struct mapping_t ComposeNewsHelp[] = {
104 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
105 {N_("Abort"), OP_EXIT},
106 {"Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS},
107 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
108 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
109 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
110 {N_("Help"), OP_HELP},
116 static void snd_entry (char *b, ssize_t blen, MUTTMENU * menu, int num) {
117 int w=(COLS-SW)>blen?blen:COLS-SW;
118 mutt_FormatString (b, w, NONULL (AttachFormat), mutt_attach_fmt,
119 (unsigned long) (((ATTACHPTR **) menu->data)[num]),
120 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
123 #include <lib-crypt/crypt.h>
125 static void redraw_crypt_lines (HEADER * msg)
130 mvaddstr (HDR_CRYPT, SW, " Security: ");
131 else if (msg->security & APPLICATION_SMIME)
132 mvaddstr (HDR_CRYPT, SW, " S/MIME: ");
133 else if (msg->security & APPLICATION_PGP)
134 mvaddstr (HDR_CRYPT, SW, " PGP: ");
136 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
137 addstr (_("Sign, Encrypt"));
138 else if (msg->security & ENCRYPT)
139 addstr (_("Encrypt"));
140 else if (msg->security & SIGN)
145 if ((msg->security & APPLICATION_PGP)
146 && (msg->security & (ENCRYPT | SIGN))) {
147 if ((msg->security & INLINE))
148 addstr (_(" (inline)"));
150 addstr (_(" (PGP/MIME)"));
154 move (HDR_CRYPTINFO, SW);
156 if (msg->security & APPLICATION_PGP && msg->security & SIGN)
157 printw ("%s%s", _(" sign as: "),
158 PgpSignAs ? PgpSignAs : _("<default>"));
160 if (msg->security & APPLICATION_SMIME && msg->security & SIGN) {
161 printw ("%s%s", _(" sign as: "),
162 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
165 if ((msg->security & APPLICATION_SMIME)
166 && (msg->security & ENCRYPT)
167 && SmimeCryptAlg && *SmimeCryptAlg) {
168 mvprintw (HDR_CRYPTINFO, SW + 40, "%s%s", _("Encrypt with: "),
169 NONULL (SmimeCryptAlg));
174 static void redraw_mix_line (string_list_t * chain)
179 mvaddstr (HDR_MIX, SW, " Mix: ");
182 addstr ("<no chain defined>");
187 for (c = 12; chain; chain = chain->next) {
189 if (t && t[0] == '0' && t[1] == '\0')
192 if (c + m_strlen(t) + 2 >= COLS - SW)
199 c += m_strlen(t) + 2;
203 static int check_attachments (ATTACHPTR ** idx, short idxlen)
207 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
209 for (i = 0; i < idxlen; i++) {
210 m_strcpy(pretty, sizeof(pretty), idx[i]->content->filename);
211 if (stat (idx[i]->content->filename, &st) != 0) {
212 mutt_pretty_mailbox (pretty);
213 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
217 if (idx[i]->content->stamp < st.st_mtime) {
218 mutt_pretty_mailbox (pretty);
219 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
222 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
223 mutt_update_encoding (idx[i]->content);
232 static void draw_envelope_addr (int line, address_t * addr)
237 rfc822_write_address (buf, sizeof (buf), addr, 1);
238 mvprintw (line, SW, TITLE_FMT, Prompts[line - 1]);
239 mutt_paddstr (W, buf);
242 static void draw_envelope (HEADER * msg, char *fcc)
244 draw_envelope_addr (HDR_FROM, msg->env->from);
246 if (!option (OPTNEWSSEND)) {
248 draw_envelope_addr (HDR_TO, msg->env->to);
249 draw_envelope_addr (HDR_CC, msg->env->cc);
250 draw_envelope_addr (HDR_BCC, msg->env->bcc);
254 mvprintw (HDR_TO, SW, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
255 mutt_paddstr (W, NONULL (msg->env->newsgroups));
256 mvprintw (HDR_CC, SW, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
257 mutt_paddstr (W, NONULL (msg->env->followup_to));
258 if (option (OPTXCOMMENTTO)) {
259 mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]);
260 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
264 mvprintw (HDR_SUBJECT, SW, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
265 mutt_paddstr (W, NONULL (msg->env->subject));
266 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
267 mvprintw (HDR_FCC, SW, TITLE_FMT, Prompts[HDR_FCC - 1]);
268 mutt_paddstr (W, fcc);
270 redraw_crypt_lines (msg);
271 redraw_mix_line (msg->chain);
273 SETCOLOR (MT_COLOR_STATUS);
274 mvaddstr (HDR_ATTACH - 1, SW, _("-- Attachments"));
275 BKGDSET (MT_COLOR_STATUS);
278 BKGDSET (MT_COLOR_NORMAL);
279 SETCOLOR (MT_COLOR_NORMAL);
282 static int edit_address_list (int line, address_t ** addr)
284 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
287 mutt_addrlist_to_local (*addr);
288 rfc822_write_address (buf, sizeof (buf), *addr, 0);
289 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
290 address_list_wipe(addr);
291 *addr = mutt_parse_adrlist (*addr, buf);
292 *addr = mutt_expand_aliases (*addr);
295 if (option (OPTNEEDREDRAW)) {
296 unset_option (OPTNEEDREDRAW);
297 return (REDRAW_FULL);
300 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
301 mutt_error (_("Warning: '%s' is a bad IDN."), err);
306 /* redraw the expanded list so the user can see the result */
308 rfc822_write_address (buf, sizeof (buf), *addr, 1);
309 move (line, HDR_XOFFSET + SW);
310 mutt_paddstr (W, buf);
315 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
317 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
320 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
322 if (x == 0 && menu->max == 1) {
323 mutt_error _("You may not delete the only attachment.");
325 idx[x]->content->tagged = 0;
329 for (y = 0; y < *idxlen; y++) {
330 if (idx[y]->content->next == idx[x]->content) {
331 idx[y]->content->next = idx[x]->content->next;
336 idx[x]->content->next = NULL;
337 idx[x]->content->parts = NULL;
338 body_list_wipe(&(idx[x]->content));
339 p_delete(&idx[x]->tree);
341 for (; x < *idxlen - 1; x++)
343 menu->max = --(*idxlen);
348 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
350 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
352 idx[idxlen - 1]->content->next = idx[idxlen]->content;
353 idx[idxlen]->content->aptr = idx[idxlen];
354 menu->current = idxlen++;
355 mutt_update_tree (idx, idxlen);
362 * cum_attachs_size: Cumulative Attachments Size
364 * Returns the total number of bytes used by the attachments in the
365 * attachment list _after_ content-transfer-encodings have been
370 static unsigned long cum_attachs_size (MUTTMENU * menu)
374 ATTACHPTR **idx = menu->data;
378 for (i = 0, s = 0; i < menu->max; i++) {
382 b->content = mutt_get_content_info (b->filename, b);
384 if ((info = b->content)) {
385 switch (b->encoding) {
386 case ENCQUOTEDPRINTABLE:
387 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
390 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
393 s += info->lobin + info->hibin + info->ascii + info->crlf;
403 * compose_format_str()
405 * %a = total number of attachments
406 * %h = hostname [option]
407 * %l = approx. length of current message (in bytes)
410 * This function is similar to status_format_str(). Look at that function for
411 * help when modifying this function.
414 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
417 static const char *compose_format_str (char *buf, ssize_t buflen, char op,
418 const char *src, const char *prefix,
419 const char *ifstring,
420 const char *elsestring,
421 unsigned long data, format_flag flags)
423 char fmt[SHORT_STRING], tmp[SHORT_STRING];
424 int optional = (flags & M_FORMAT_OPTIONAL);
425 MUTTMENU *menu = (MUTTMENU *) data;
429 case 'a': /* total number of attachments */
430 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
431 snprintf (buf, buflen, fmt, menu->max);
434 case 'h': /* hostname */
435 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
436 snprintf (buf, buflen, fmt, NONULL (Hostname));
439 case 'l': /* approx length of current message in bytes */
440 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
441 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
442 snprintf (buf, buflen, fmt, tmp);
446 m_strcpy(buf, buflen, mutt_make_version (0));
454 snprintf (buf, buflen, "%%%s%c", prefix, op);
459 compose_status_line (buf, buflen, menu, ifstring);
460 else if (flags & M_FORMAT_OPTIONAL)
461 compose_status_line (buf, buflen, menu, elsestring);
466 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
469 int w=(COLS-SW)>buflen?buflen:(COLS-SW);
470 mutt_FormatString (buf, w, p, compose_format_str,
471 (unsigned long) menu, 0);
477 * 1 message should be postponed
481 int mutt_compose_menu (HEADER * msg, /* structure for new message */
482 char *fcc, /* where to save a copy of the message */
484 HEADER * cur __attribute__ ((unused)))
485 { /* current message */
486 char helpstr[SHORT_STRING];
487 char buf[LONG_STRING];
488 char fname[_POSIX_PATH_MAX];
490 ATTACHPTR **idx = NULL;
494 int r = -1; /* return value */
497 int fccSet = 0; /* has the user edited the Fcc: field ? */
498 CONTEXT *ctx = NULL, *this = NULL;
500 /* Sort, SortAux could be changed in mutt_index_menu() */
501 int oldSort, oldSortAux;
505 int news = 0; /* is it a news article ? */
507 if (option (OPTNEWSSEND))
511 mutt_attach_init (msg->content);
512 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
514 menu = mutt_new_menu ();
515 menu->menu = MENU_COMPOSE;
516 menu->offset = HDR_ATTACH;
518 menu->make_entry = snd_entry;
519 menu->tag = mutt_tag_attach;
524 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
529 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
532 if (option (OPTMBOXPANE))
536 unset_option (OPTNEWS); /* for any case */
538 switch (op = mutt_menuLoop (menu)) {
540 draw_envelope (msg, fcc);
541 menu->offset = HDR_ATTACH;
542 menu->pagelen = LINES - HDR_ATTACH - 2;
544 case OP_COMPOSE_EDIT_FROM:
545 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
546 mutt_message_hook (NULL, msg, M_SEND2HOOK);
548 case OP_COMPOSE_EDIT_TO:
552 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
553 mutt_message_hook (NULL, msg, M_SEND2HOOK);
558 case OP_COMPOSE_EDIT_BCC:
562 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
563 mutt_message_hook (NULL, msg, M_SEND2HOOK);
568 case OP_COMPOSE_EDIT_CC:
572 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
573 mutt_message_hook (NULL, msg, M_SEND2HOOK);
579 case OP_COMPOSE_EDIT_NEWSGROUPS:
581 if (msg->env->newsgroups)
582 m_strcpy(buf, sizeof(buf), msg->env->newsgroups);
585 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
587 p_delete(&msg->env->newsgroups);
589 msg->env->newsgroups = m_strdup(skipspaces(buf));
590 move (HDR_TO, HDR_XOFFSET);
592 if (msg->env->newsgroups)
593 printw ("%-*.*s", W, W, msg->env->newsgroups);
598 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
601 if (msg->env->followup_to)
602 m_strcpy(buf, sizeof(buf), msg->env->followup_to);
603 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
605 p_delete(&msg->env->followup_to);
607 msg->env->followup_to = m_strdup(skipspaces(buf));
608 move (HDR_CC, HDR_XOFFSET);
610 if (msg->env->followup_to)
611 printw ("%-*.*s", W, W, msg->env->followup_to);
616 case OP_COMPOSE_EDIT_X_COMMENT_TO:
617 if (news && option (OPTXCOMMENTTO)) {
619 if (msg->env->x_comment_to)
620 m_strcpy(buf, sizeof(buf), msg->env->x_comment_to);
621 if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
623 p_delete(&msg->env->x_comment_to);
624 msg->env->x_comment_to = m_strdup(buf);
625 move (HDR_BCC, HDR_XOFFSET);
627 if (msg->env->x_comment_to)
628 printw ("%-*.*s", W, W, msg->env->x_comment_to);
633 case OP_COMPOSE_EDIT_SUBJECT:
634 if (msg->env->subject)
635 m_strcpy(buf, sizeof(buf), msg->env->subject);
638 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
639 m_strreplace(&msg->env->subject, buf);
640 move (HDR_SUBJECT, HDR_XOFFSET + SW);
642 if (msg->env->subject)
643 mutt_paddstr (W, msg->env->subject);
645 mutt_message_hook (NULL, msg, M_SEND2HOOK);
647 case OP_COMPOSE_EDIT_REPLY_TO:
648 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
649 mutt_message_hook (NULL, msg, M_SEND2HOOK);
651 case OP_COMPOSE_EDIT_FCC:
652 m_strcpy(buf, sizeof(buf), fcc);
653 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
654 m_strcpy(fcc, _POSIX_PATH_MAX, buf);
655 mutt_pretty_mailbox (fcc);
656 move (HDR_FCC, HDR_XOFFSET + SW);
657 mutt_paddstr (W, fcc);
660 MAYBE_REDRAW (menu->redraw);
661 mutt_message_hook (NULL, msg, M_SEND2HOOK);
663 case OP_COMPOSE_EDIT_MESSAGE:
664 if (Editor && !option (OPTEDITHDRS)) {
665 mutt_edit_file (Editor, msg->content->filename);
666 mutt_update_encoding (msg->content);
667 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
668 mutt_message_hook (NULL, msg, M_SEND2HOOK);
672 case OP_COMPOSE_EDIT_HEADERS:
673 if ((op == OP_COMPOSE_EDIT_HEADERS ||
674 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
675 const char *tag = NULL;
678 mutt_env_to_local (msg->env);
679 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
681 if (mutt_env_to_idna (msg->env, &tag, &err)) {
682 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
686 mutt_update_encoding (msg->content);
688 /* attachments may have been added */
689 if (idxlen && idx[idxlen - 1]->content->next) {
690 for (i = 0; i < idxlen; i++)
694 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
700 menu->redraw = REDRAW_FULL;
701 mutt_message_hook (NULL, msg, M_SEND2HOOK);
706 case OP_COMPOSE_ATTACH_KEY:
707 if (idxlen == idxmax) {
708 p_realloc(&idx, idxmax += 5);
712 idx[idxlen] = p_new(ATTACHPTR, 1);
713 if ((idx[idxlen]->content =
714 crypt_pgp_make_key_attachment (NULL)) != NULL) {
715 update_idx (menu, idx, idxlen++);
716 menu->redraw |= REDRAW_INDEX;
719 p_delete(&idx[idxlen]);
721 menu->redraw |= REDRAW_STATUS;
723 if (option (OPTNEEDREDRAW)) {
724 menu->redraw = REDRAW_FULL;
725 unset_option (OPTNEEDREDRAW);
728 mutt_message_hook (NULL, msg, M_SEND2HOOK);
732 case OP_COMPOSE_ATTACH_FILE:
734 char *prompt, **files;
738 prompt = _("Attach file");
742 if (_mutt_enter_fname
743 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
744 &numfiles) == -1 || *fname == '\0')
747 if (idxlen + numfiles >= idxmax) {
748 p_realloc(&idx, idxmax += 5 + numfiles);
754 mutt_message _("Attaching selected files...");
756 for (i = 0; i < numfiles; i++) {
757 char *att = files[i];
759 idx[idxlen] = p_new(ATTACHPTR, 1);
760 idx[idxlen]->unowned = 1;
761 idx[idxlen]->content = mutt_make_file_attach (att);
762 if (idx[idxlen]->content != NULL)
763 update_idx (menu, idx, idxlen++);
766 mutt_error (_("Unable to attach %s!"), att);
767 p_delete(&idx[idxlen]);
775 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
777 mutt_message_hook (NULL, msg, M_SEND2HOOK);
780 case OP_COMPOSE_ATTACH_MESSAGE:
782 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
789 prompt = _("Open mailbox to attach message from");
792 unset_option (OPTNEWS);
793 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
794 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
797 prompt = _("Open newsgroup to attach message from");
798 set_option (OPTNEWS);
804 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
807 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
808 mutt_pretty_mailbox (fname);
811 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
816 if (option (OPTNEWS))
817 nntp_expand_path (fname, sizeof (fname),
818 &CurrentNewsSrv->conn->account);
821 mutt_expand_path (fname, sizeof (fname));
822 if (mx_get_magic (fname) != M_IMAP)
823 if (mx_get_magic (fname) != M_POP)
825 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
827 /* check to make sure the file exists and is readable */
828 if (access (fname, R_OK) == -1) {
833 menu->redraw = REDRAW_FULL;
835 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
841 if (!ctx->msgcount) {
842 mx_close_mailbox (ctx, NULL);
844 mutt_error _("No messages in that folder.");
849 this = Context; /* remember current folder and sort methods */
851 oldSortAux = SortAux;
854 set_option (OPTATTACHMSG);
855 mutt_message _("Tag the messages you want to attach!");
857 closed = mutt_index_menu ();
858 unset_option (OPTATTACHMSG);
861 /* go back to the folder we started from */
863 /* Restore old $sort and $sort_aux */
865 SortAux = oldSortAux;
866 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
870 if (idxlen + Context->tagged >= idxmax) {
871 p_realloc(&idx, idxmax += 5 + Context->tagged);
875 for (i = 0; i < Context->msgcount; i++) {
876 h = Context->hdrs[i];
878 idx[idxlen] = p_new(ATTACHPTR, 1);
879 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
880 if (idx[idxlen]->content != NULL)
881 update_idx (menu, idx, idxlen++);
883 mutt_error _("Unable to attach!");
885 p_delete(&idx[idxlen]);
889 menu->redraw |= REDRAW_FULL;
891 if (closed == OP_QUIT)
892 mx_close_mailbox (Context, NULL);
894 mx_fastclose_mailbox (Context);
897 /* go back to the folder we started from */
899 /* Restore old $sort and $sort_aux */
901 SortAux = oldSortAux;
903 mutt_message_hook (NULL, msg, M_SEND2HOOK);
908 if (idx[menu->current]->unowned)
909 idx[menu->current]->content->unlink = 0;
910 if (delete_attachment (menu, &idxlen, menu->current) == -1)
912 mutt_update_tree (idx, idxlen);
914 if (menu->current > idxlen - 1)
915 menu->current = idxlen - 1;
920 if (menu->current == 0)
921 msg->content = idx[0]->content;
923 menu->redraw |= REDRAW_STATUS;
924 mutt_message_hook (NULL, msg, M_SEND2HOOK);
927 #define CURRENT idx[menu->current]->content
929 case OP_COMPOSE_TOGGLE_RECODE:
932 if (!mutt_is_text_part (CURRENT)) {
933 mutt_error (_("Recoding only affects text attachments."));
936 CURRENT->noconv = !CURRENT->noconv;
938 mutt_message (_("The current attachment won't be converted."));
940 mutt_message (_("The current attachment will be converted."));
941 menu->redraw = REDRAW_CURRENT;
942 mutt_message_hook (NULL, msg, M_SEND2HOOK);
947 case OP_COMPOSE_EDIT_DESCRIPTION:
949 m_strcpy(buf, sizeof(buf),
950 NONULL(idx[menu->current]->content->description));
951 /* header names should not be translated */
952 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
953 m_strreplace(&idx[menu->current]->content->description, buf);
954 menu->redraw = REDRAW_CURRENT;
956 mutt_message_hook (NULL, msg, M_SEND2HOOK);
959 case OP_COMPOSE_UPDATE_ENCODING:
961 if (menu->tagprefix) {
964 for (top = msg->content; top; top = top->next) {
966 mutt_update_encoding (top);
968 menu->redraw = REDRAW_FULL;
971 mutt_update_encoding (idx[menu->current]->content);
972 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
974 mutt_message_hook (NULL, msg, M_SEND2HOOK);
977 case OP_COMPOSE_TOGGLE_DISPOSITION:
978 /* toggle the content-disposition between inline/attachment */
979 idx[menu->current]->content->disposition =
980 (idx[menu->current]->content->disposition ==
981 DISPINLINE) ? DISPATTACH : DISPINLINE;
982 menu->redraw = REDRAW_CURRENT;
988 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
990 /* this may have been a change to text/something */
991 mutt_update_encoding (idx[menu->current]->content);
993 menu->redraw = REDRAW_CURRENT;
995 mutt_message_hook (NULL, msg, M_SEND2HOOK);
998 case OP_COMPOSE_EDIT_ENCODING:
1000 m_strcpy(buf, sizeof(buf),
1001 ENCODING(idx[menu->current]->content->encoding));
1002 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
1003 sizeof (buf), 0) == 0 && buf[0]) {
1004 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
1005 idx[menu->current]->content->encoding = i;
1006 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1007 mutt_clear_error ();
1010 mutt_error _("Invalid encoding.");
1012 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1015 case OP_COMPOSE_SEND_MESSAGE:
1017 /* Note: We don't invoke send2-hook here, since we want to leave
1018 * users an opportunity to change settings from the ":" prompt.
1021 if (check_attachments (idx, idxlen) != 0) {
1022 menu->redraw = REDRAW_FULL;
1026 if (msg->chain && mix_check_message (msg) != 0)
1029 if (!fccSet && *fcc) {
1030 if ((i = query_quadoption (OPT_COPY,
1031 _("Save a copy of this message?"))) == -1)
1041 case OP_COMPOSE_EDIT_FILE:
1043 mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename);
1044 mutt_update_encoding (idx[menu->current]->content);
1045 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1046 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1049 case OP_COMPOSE_TOGGLE_UNLINK:
1051 idx[menu->current]->content->unlink =
1052 !idx[menu->current]->content->unlink;
1054 menu->redraw = REDRAW_INDEX;
1055 /* No send2hook since this doesn't change the message. */
1058 case OP_COMPOSE_GET_ATTACHMENT:
1060 if (menu->tagprefix) {
1063 for (top = msg->content; top; top = top->next) {
1065 mutt_get_tmp_attachment (top);
1067 menu->redraw = REDRAW_FULL;
1069 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1070 menu->redraw = REDRAW_CURRENT;
1072 /* No send2hook since this doesn't change the message. */
1075 case OP_COMPOSE_RENAME_FILE:
1077 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
1078 mutt_pretty_mailbox (fname);
1079 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1081 if (stat (idx[menu->current]->content->filename, &st) == -1) {
1082 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1086 mutt_expand_path (fname, sizeof (fname));
1087 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1090 m_strreplace(&idx[menu->current]->content->filename, fname);
1091 menu->redraw = REDRAW_CURRENT;
1093 if (idx[menu->current]->content->stamp >= st.st_mtime)
1094 mutt_stamp_attachment (idx[menu->current]->content);
1097 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1100 case OP_COMPOSE_NEW_MIME:
1107 CLEARLINE (LINES - 1);
1109 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1112 mutt_expand_path (fname, sizeof (fname));
1114 /* Call to lookup_mime_type () ? maybe later */
1116 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1120 if (!(p = strchr (type, '/'))) {
1121 mutt_error _("Content-Type is of the form base/sub");
1126 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1127 mutt_error (_("Unknown Content-Type %s"), type);
1130 if (idxlen == idxmax) {
1131 p_realloc(&idx, idxmax += 5);
1135 idx[idxlen] = p_new(ATTACHPTR, 1);
1136 /* Touch the file */
1137 if (!(fp = safe_fopen (fname, "w"))) {
1138 mutt_error (_("Can't create file %s"), fname);
1139 p_delete(&idx[idxlen]);
1144 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1146 _("What we have here is a failure to make an attachment");
1149 update_idx (menu, idx, idxlen++);
1151 idx[menu->current]->content->type = itype;
1152 m_strreplace(&idx[menu->current]->content->subtype, p);
1153 idx[menu->current]->content->unlink = 1;
1154 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1156 if (mutt_compose_attachment (idx[menu->current]->content)) {
1157 mutt_update_encoding (idx[menu->current]->content);
1158 menu->redraw = REDRAW_FULL;
1161 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1164 case OP_COMPOSE_EDIT_MIME:
1166 if (mutt_edit_attachment (idx[menu->current]->content)) {
1167 mutt_update_encoding (idx[menu->current]->content);
1168 menu->redraw = REDRAW_FULL;
1170 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1173 case OP_VIEW_ATTACH:
1174 case OP_DISPLAY_HEADERS:
1176 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1178 menu->redraw = REDRAW_FULL;
1179 /* no send2hook, since this doesn't modify the message */
1184 mutt_save_attachment_list (NULL, menu->tagprefix,
1185 menu->tagprefix ? msg->content : idx[menu->
1187 content, NULL, menu);
1188 MAYBE_REDRAW (menu->redraw);
1189 /* no send2hook, since this doesn't modify the message */
1194 mutt_print_attachment_list (NULL, menu->tagprefix,
1195 menu->tagprefix ? msg->content : idx[menu->
1198 /* no send2hook, since this doesn't modify the message */
1204 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1205 menu->tagprefix ? msg->content : idx[menu->
1207 content, op == OP_FILTER);
1208 if (op == OP_FILTER) /* cte might have changed */
1209 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1210 menu->redraw |= REDRAW_STATUS;
1211 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1216 query_quadoption (OPT_POSTPONE,
1217 _("Postpone this message?"))) == M_NO) {
1218 while (idxlen-- > 0) {
1219 /* avoid freeing other attachments */
1220 idx[idxlen]->content->next = NULL;
1221 idx[idxlen]->content->parts = NULL;
1222 if (idx[idxlen]->unowned)
1223 idx[idxlen]->content->unlink = 0;
1224 body_list_wipe(&idx[idxlen]->content);
1225 p_delete(&idx[idxlen]->tree);
1226 p_delete(&idx[idxlen]);
1238 /* fall through to postpone! */
1240 case OP_COMPOSE_POSTPONE_MESSAGE:
1242 if (check_attachments (idx, idxlen) != 0) {
1243 menu->redraw = REDRAW_FULL;
1251 case OP_COMPOSE_ISPELL:
1253 snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1254 msg->content->filename);
1255 if (mutt_system (buf) == -1)
1256 mutt_error (_("Error running \"%s\"!"), buf);
1258 mutt_update_encoding (msg->content);
1259 menu->redraw |= REDRAW_STATUS;
1263 case OP_COMPOSE_WRITE_MESSAGE:
1267 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
1268 mutt_pretty_mailbox (fname);
1271 msg->content = idx[0]->content;
1272 if (mutt_enter_fname
1273 (_("Write message to mailbox"), fname, sizeof (fname),
1274 &menu->redraw, 1) != -1 && fname[0]) {
1275 mutt_message (_("Writing message to %s ..."), fname);
1276 mutt_expand_path (fname, sizeof (fname));
1278 if (msg->content->next)
1279 msg->content = mutt_make_multipart (msg->content);
1281 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1282 msg->content = mutt_remove_multipart (msg->content);
1284 mutt_message _("Message written.");
1290 case OP_COMPOSE_PGP_MENU:
1291 if (msg->security & APPLICATION_SMIME) {
1292 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1294 mutt_clear_error ();
1299 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1300 redraw_crypt_lines (msg);
1301 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1305 case OP_FORGET_PASSPHRASE:
1306 crypt_forget_passphrase ();
1310 case OP_COMPOSE_SMIME_MENU:
1311 if (msg->security & APPLICATION_PGP) {
1312 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1314 mutt_clear_error ();
1319 msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1320 redraw_crypt_lines (msg);
1321 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1324 case OP_COMPOSE_MIX:
1325 mix_make_chain (&msg->chain, &menu->redraw);
1326 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1330 /* Draw formated compose status line */
1331 if (menu->redraw & REDRAW_STATUS) {
1332 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1333 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1334 SETCOLOR (MT_COLOR_STATUS);
1335 move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
1336 printw ("%-*.*s", COLS-SW, COLS-SW, buf);
1337 SETCOLOR (MT_COLOR_NORMAL);
1338 menu->redraw &= ~REDRAW_STATUS;
1342 mutt_menuDestroy (&menu);
1345 msg->content = idx[0]->content;
1346 for (i = 0; i < idxlen; i++) {
1347 idx[i]->content->aptr = NULL;
1352 msg->content = NULL;