2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4 * Copyright (C) 2004 g10 Code GmbH
6 * Parts were written/modified by:
7 * Nico Golde <nico@ngolde.de>
9 * This file is part of mutt-ng, see http://www.muttng.org/.
10 * It's licensed under the GNU General Public License,
11 * please see the file GPL in the top level source directory.
14 #include <lib-lib/lib-lib.h>
16 #include <lib-sys/unix.h>
17 #include <lib-mime/mime.h>
18 #include <lib-crypt/crypt.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>
41 mutt_error _("There are no attachments."); \
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[] = {
85 "", "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: "
89 static struct mapping_t ComposeHelp[] = {
90 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
91 {N_("Abort"), OP_EXIT},
92 {"To", OP_COMPOSE_EDIT_TO},
93 {"CC", OP_COMPOSE_EDIT_CC},
94 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
95 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
96 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
97 {N_("Help"), OP_HELP},
102 static struct mapping_t ComposeNewsHelp[] = {
103 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
104 {N_("Abort"), OP_EXIT},
105 {"Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS},
106 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
107 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
108 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
109 {N_("Help"), OP_HELP},
115 static void snd_entry (char *b, ssize_t blen, MUTTMENU * menu, int num) {
116 int w=(COLS-SW)>blen?blen:COLS-SW;
117 mutt_FormatString (b, w, NONULL (AttachFormat), mutt_attach_fmt,
118 (unsigned long) (((ATTACHPTR **) menu->data)[num]),
119 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
122 static void redraw_crypt_lines (HEADER * msg)
127 mvaddstr (HDR_CRYPT, SW, " Security: ");
128 else if (msg->security & APPLICATION_SMIME)
129 mvaddstr (HDR_CRYPT, SW, " S/MIME: ");
130 else if (msg->security & APPLICATION_PGP)
131 mvaddstr (HDR_CRYPT, SW, " PGP: ");
133 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
134 addstr (_("Sign, Encrypt"));
135 else if (msg->security & ENCRYPT)
136 addstr (_("Encrypt"));
137 else if (msg->security & SIGN)
142 if ((msg->security & APPLICATION_PGP)
143 && (msg->security & (ENCRYPT | SIGN))) {
144 if ((msg->security & INLINE))
145 addstr (_(" (inline)"));
147 addstr (_(" (PGP/MIME)"));
151 move (HDR_CRYPTINFO, SW);
153 if (msg->security & APPLICATION_PGP && msg->security & SIGN)
154 printw ("%s%s", _(" sign as: "),
155 PgpSignAs ? PgpSignAs : _("<default>"));
157 if (msg->security & APPLICATION_SMIME && msg->security & SIGN) {
158 printw ("%s%s", _(" sign as: "),
159 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
162 if ((msg->security & APPLICATION_SMIME)
163 && (msg->security & ENCRYPT)
164 && SmimeCryptAlg && *SmimeCryptAlg) {
165 mvprintw (HDR_CRYPTINFO, SW + 40, "%s%s", _("Encrypt with: "),
166 NONULL (SmimeCryptAlg));
171 static void redraw_mix_line (string_list_t * chain)
176 mvaddstr (HDR_MIX, SW, " Mix: ");
179 addstr ("<no chain defined>");
184 for (c = 12; chain; chain = chain->next) {
186 if (t && t[0] == '0' && t[1] == '\0')
189 if (c + m_strlen(t) + 2 >= COLS - SW)
196 c += m_strlen(t) + 2;
200 static int check_attachments (ATTACHPTR ** idx, short idxlen)
204 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + STRING];
206 for (i = 0; i < idxlen; i++) {
207 m_strcpy(pretty, sizeof(pretty), idx[i]->content->filename);
208 if (stat (idx[i]->content->filename, &st) != 0) {
209 mutt_pretty_mailbox (pretty);
210 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
214 if (idx[i]->content->stamp < st.st_mtime) {
215 mutt_pretty_mailbox (pretty);
216 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
219 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
220 mutt_update_encoding (idx[i]->content);
229 static void draw_envelope_addr (int line, address_t * addr)
234 rfc822_addrcat(buf, sizeof (buf), addr, 1);
235 mvprintw (line, SW, TITLE_FMT, Prompts[line - 1]);
236 mutt_paddstr (W, buf);
239 static void draw_envelope (HEADER * msg, char *fcc)
241 draw_envelope_addr (HDR_FROM, msg->env->from);
243 if (!option (OPTNEWSSEND)) {
245 draw_envelope_addr (HDR_TO, msg->env->to);
246 draw_envelope_addr (HDR_CC, msg->env->cc);
247 draw_envelope_addr (HDR_BCC, msg->env->bcc);
250 mvprintw (HDR_TO, SW, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
251 mutt_paddstr (W, NONULL (msg->env->newsgroups));
252 mvprintw (HDR_CC, SW, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
253 mutt_paddstr (W, NONULL (msg->env->followup_to));
254 if (option (OPTXCOMMENTTO)) {
255 mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]);
256 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
260 mvprintw (HDR_SUBJECT, SW, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
261 mutt_paddstr (W, NONULL (msg->env->subject));
262 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
263 mvprintw (HDR_FCC, SW, TITLE_FMT, Prompts[HDR_FCC - 1]);
264 mutt_paddstr (W, fcc);
266 redraw_crypt_lines (msg);
267 redraw_mix_line (msg->chain);
269 SETCOLOR (MT_COLOR_STATUS);
270 mvaddstr (HDR_ATTACH - 1, SW, _("-- Attachments"));
271 BKGDSET (MT_COLOR_STATUS);
274 BKGDSET (MT_COLOR_NORMAL);
275 SETCOLOR (MT_COLOR_NORMAL);
278 static int edit_address_list (int line, address_t ** addr)
280 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
283 mutt_addrlist_to_local (*addr);
284 rfc822_addrcat(buf, sizeof (buf), *addr, 0);
285 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
286 address_list_wipe(addr);
287 *addr = mutt_parse_adrlist (*addr, buf);
288 *addr = mutt_expand_aliases (*addr);
291 if (option (OPTNEEDREDRAW)) {
292 unset_option (OPTNEEDREDRAW);
296 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
297 mutt_error (_("Warning: '%s' is a bad IDN."), err);
302 /* redraw the expanded list so the user can see the result */
304 rfc822_addrcat(buf, sizeof (buf), *addr, 1);
305 move (line, HDR_XOFFSET + SW);
306 mutt_paddstr (W, buf);
311 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
313 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
316 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
318 if (x == 0 && menu->max == 1) {
319 mutt_error _("You may not delete the only attachment.");
321 idx[x]->content->tagged = 0;
325 for (y = 0; y < *idxlen; y++) {
326 if (idx[y]->content->next == idx[x]->content) {
327 idx[y]->content->next = idx[x]->content->next;
332 idx[x]->content->next = NULL;
333 idx[x]->content->parts = NULL;
334 body_list_wipe(&(idx[x]->content));
335 p_delete(&idx[x]->tree);
337 for (; x < *idxlen - 1; x++)
339 menu->max = --(*idxlen);
344 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
346 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
348 idx[idxlen - 1]->content->next = idx[idxlen]->content;
349 idx[idxlen]->content->aptr = idx[idxlen];
350 menu->current = idxlen++;
351 mutt_update_tree (idx, idxlen);
358 * cum_attachs_size: Cumulative Attachments Size
360 * Returns the total number of bytes used by the attachments in the
361 * attachment list _after_ content-transfer-encodings have been
365 static unsigned long cum_attachs_size(MUTTMENU * menu)
369 ATTACHPTR **idx = menu->data;
373 for (i = 0, s = 0; i < menu->max; i++) {
377 b->content = mutt_get_content_info (b->filename, b);
379 if ((info = b->content)) {
380 switch (b->encoding) {
381 case ENCQUOTEDPRINTABLE:
382 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
385 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
388 s += info->lobin + info->hibin + info->ascii + info->crlf;
398 * compose_format_str()
400 * %a = total number of attachments
401 * %h = hostname [option]
402 * %l = approx. length of current message (in bytes)
405 * This function is similar to status_format_str(). Look at that function for
406 * help when modifying this function.
408 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
411 static const char *compose_format_str (char *buf, ssize_t buflen, char op,
412 const char *src, const char *prefix,
413 const char *ifstring,
414 const char *elsestring,
415 unsigned long data, format_flag flags)
417 char fmt[STRING], tmp[STRING];
418 int optional = (flags & M_FORMAT_OPTIONAL);
419 MUTTMENU *menu = (MUTTMENU *) data;
423 case 'a': /* total number of attachments */
424 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
425 snprintf (buf, buflen, fmt, menu->max);
428 case 'h': /* hostname */
429 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
430 snprintf (buf, buflen, fmt, NONULL (Hostname));
433 case 'l': /* approx length of current message in bytes */
434 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
435 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
436 snprintf (buf, buflen, fmt, tmp);
440 m_strcpy(buf, buflen, mutt_make_version (0));
448 snprintf (buf, buflen, "%%%s%c", prefix, op);
453 compose_status_line (buf, buflen, menu, ifstring);
454 else if (flags & M_FORMAT_OPTIONAL)
455 compose_status_line (buf, buflen, menu, elsestring);
460 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
463 int w=(COLS-SW)>buflen?buflen:(COLS-SW);
464 mutt_FormatString (buf, w, p, compose_format_str,
465 (unsigned long) menu, 0);
470 * 1 message should be postponed
474 int mutt_compose_menu (HEADER * msg, /* structure for new message */
475 char *fcc, /* where to save a copy of the message */
477 HEADER * cur __attribute__ ((unused)))
478 { /* current message */
479 char helpstr[STRING];
480 char buf[LONG_STRING];
481 char fname[_POSIX_PATH_MAX];
483 ATTACHPTR **idx = NULL;
487 int r = -1; /* return value */
490 int fccSet = 0; /* has the user edited the Fcc: field ? */
491 CONTEXT *ctx = NULL, *this = NULL;
493 /* Sort, SortAux could be changed in mutt_index_menu() */
494 int oldSort, oldSortAux;
498 int news = 0; /* is it a news article ? */
500 if (option (OPTNEWSSEND))
504 mutt_attach_init (msg->content);
505 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
507 menu = mutt_new_menu ();
508 menu->menu = MENU_COMPOSE;
509 menu->offset = HDR_ATTACH;
511 menu->make_entry = snd_entry;
512 menu->tag = mutt_tag_attach;
516 menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_COMPOSE,
520 menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_COMPOSE,
523 if (option (OPTMBOXPANE))
527 unset_option (OPTNEWS); /* for any case */
529 switch (op = mutt_menuLoop (menu)) {
531 draw_envelope (msg, fcc);
532 menu->offset = HDR_ATTACH;
533 menu->pagelen = LINES - HDR_ATTACH - 2;
535 case OP_COMPOSE_EDIT_FROM:
536 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
537 mutt_message_hook (NULL, msg, M_SEND2HOOK);
539 case OP_COMPOSE_EDIT_TO:
543 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
544 mutt_message_hook (NULL, msg, M_SEND2HOOK);
549 case OP_COMPOSE_EDIT_BCC:
553 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
554 mutt_message_hook (NULL, msg, M_SEND2HOOK);
559 case OP_COMPOSE_EDIT_CC:
563 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
564 mutt_message_hook (NULL, msg, M_SEND2HOOK);
570 case OP_COMPOSE_EDIT_NEWSGROUPS:
572 if (msg->env->newsgroups)
573 m_strcpy(buf, sizeof(buf), msg->env->newsgroups);
576 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
578 p_delete(&msg->env->newsgroups);
580 msg->env->newsgroups = m_strdup(skipspaces(buf));
581 move (HDR_TO, HDR_XOFFSET);
583 if (msg->env->newsgroups)
584 printw ("%-*.*s", W, W, msg->env->newsgroups);
589 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
592 if (msg->env->followup_to)
593 m_strcpy(buf, sizeof(buf), msg->env->followup_to);
594 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
596 p_delete(&msg->env->followup_to);
598 msg->env->followup_to = m_strdup(skipspaces(buf));
599 move (HDR_CC, HDR_XOFFSET);
601 if (msg->env->followup_to)
602 printw ("%-*.*s", W, W, msg->env->followup_to);
607 case OP_COMPOSE_EDIT_X_COMMENT_TO:
608 if (news && option (OPTXCOMMENTTO)) {
610 if (msg->env->x_comment_to)
611 m_strcpy(buf, sizeof(buf), msg->env->x_comment_to);
612 if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
614 p_delete(&msg->env->x_comment_to);
615 msg->env->x_comment_to = m_strdup(buf);
616 move (HDR_BCC, HDR_XOFFSET);
618 if (msg->env->x_comment_to)
619 printw ("%-*.*s", W, W, msg->env->x_comment_to);
624 case OP_COMPOSE_EDIT_SUBJECT:
625 if (msg->env->subject)
626 m_strcpy(buf, sizeof(buf), msg->env->subject);
629 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
630 m_strreplace(&msg->env->subject, buf);
631 move (HDR_SUBJECT, HDR_XOFFSET + SW);
633 if (msg->env->subject)
634 mutt_paddstr (W, msg->env->subject);
636 mutt_message_hook (NULL, msg, M_SEND2HOOK);
638 case OP_COMPOSE_EDIT_REPLY_TO:
639 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
640 mutt_message_hook (NULL, msg, M_SEND2HOOK);
642 case OP_COMPOSE_EDIT_FCC:
643 m_strcpy(buf, sizeof(buf), fcc);
644 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
645 m_strcpy(fcc, _POSIX_PATH_MAX, buf);
646 mutt_pretty_mailbox (fcc);
647 move (HDR_FCC, HDR_XOFFSET + SW);
648 mutt_paddstr (W, fcc);
651 MAYBE_REDRAW (menu->redraw);
652 mutt_message_hook (NULL, msg, M_SEND2HOOK);
654 case OP_COMPOSE_EDIT_MESSAGE:
655 if (Editor && !option (OPTEDITHDRS)) {
656 mutt_edit_file (Editor, msg->content->filename);
657 mutt_update_encoding (msg->content);
658 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
659 mutt_message_hook (NULL, msg, M_SEND2HOOK);
663 case OP_COMPOSE_EDIT_HEADERS:
664 if ((op == OP_COMPOSE_EDIT_HEADERS ||
665 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
666 const char *tag = NULL;
669 mutt_env_to_local (msg->env);
670 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
672 if (mutt_env_to_idna (msg->env, &tag, &err)) {
673 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
677 mutt_update_encoding (msg->content);
679 /* attachments may have been added */
680 if (idxlen && idx[idxlen - 1]->content->next) {
681 for (i = 0; i < idxlen; i++)
685 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
691 menu->redraw = REDRAW_FULL;
692 mutt_message_hook (NULL, msg, M_SEND2HOOK);
695 case OP_COMPOSE_ATTACH_KEY:
696 if (idxlen == idxmax) {
697 p_realloc(&idx, idxmax += 5);
701 idx[idxlen] = p_new(ATTACHPTR, 1);
702 if ((idx[idxlen]->content =
703 crypt_pgp_make_key_attachment (NULL)) != NULL) {
704 update_idx (menu, idx, idxlen++);
705 menu->redraw |= REDRAW_INDEX;
708 p_delete(&idx[idxlen]);
710 menu->redraw |= REDRAW_STATUS;
712 if (option (OPTNEEDREDRAW)) {
713 menu->redraw = REDRAW_FULL;
714 unset_option (OPTNEEDREDRAW);
717 mutt_message_hook (NULL, msg, M_SEND2HOOK);
720 case OP_COMPOSE_ATTACH_FILE:
722 char *prompt, **files;
726 prompt = _("Attach file");
730 if (_mutt_enter_fname
731 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
732 &numfiles) == -1 || *fname == '\0')
735 if (idxlen + numfiles >= idxmax) {
736 p_realloc(&idx, idxmax += 5 + numfiles);
742 mutt_message _("Attaching selected files...");
744 for (i = 0; i < numfiles; i++) {
745 char *att = files[i];
747 idx[idxlen] = p_new(ATTACHPTR, 1);
748 idx[idxlen]->unowned = 1;
749 idx[idxlen]->content = mutt_make_file_attach (att);
750 if (idx[idxlen]->content != NULL)
751 update_idx (menu, idx, idxlen++);
754 mutt_error (_("Unable to attach %s!"), att);
755 p_delete(&idx[idxlen]);
763 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
765 mutt_message_hook (NULL, msg, M_SEND2HOOK);
768 case OP_COMPOSE_ATTACH_MESSAGE:
770 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
777 prompt = _("Open mailbox to attach message from");
780 unset_option (OPTNEWS);
781 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
782 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
785 prompt = _("Open newsgroup to attach message from");
786 set_option (OPTNEWS);
792 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
795 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
796 mutt_pretty_mailbox (fname);
799 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
804 if (option (OPTNEWS))
805 nntp_expand_path (fname, sizeof (fname),
806 &CurrentNewsSrv->conn->account);
809 mutt_expand_path (fname, sizeof (fname));
810 if (mx_get_magic (fname) != M_IMAP)
811 if (mx_get_magic (fname) != M_POP)
813 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
815 /* check to make sure the file exists and is readable */
816 if (access (fname, R_OK) == -1) {
821 menu->redraw = REDRAW_FULL;
823 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
829 if (!ctx->msgcount) {
830 mx_close_mailbox (ctx, NULL);
832 mutt_error _("No messages in that folder.");
837 this = Context; /* remember current folder and sort methods */
839 oldSortAux = SortAux;
842 set_option (OPTATTACHMSG);
843 mutt_message _("Tag the messages you want to attach!");
845 closed = mutt_index_menu ();
846 unset_option (OPTATTACHMSG);
849 /* go back to the folder we started from */
851 /* Restore old $sort and $sort_aux */
853 SortAux = oldSortAux;
854 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
858 if (idxlen + Context->tagged >= idxmax) {
859 p_realloc(&idx, idxmax += 5 + Context->tagged);
863 for (i = 0; i < Context->msgcount; i++) {
864 h = Context->hdrs[i];
866 idx[idxlen] = p_new(ATTACHPTR, 1);
867 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
868 if (idx[idxlen]->content != NULL)
869 update_idx (menu, idx, idxlen++);
871 mutt_error _("Unable to attach!");
873 p_delete(&idx[idxlen]);
877 menu->redraw |= REDRAW_FULL;
879 if (closed == OP_QUIT)
880 mx_close_mailbox (Context, NULL);
882 mx_fastclose_mailbox (Context);
885 /* go back to the folder we started from */
887 /* Restore old $sort and $sort_aux */
889 SortAux = oldSortAux;
891 mutt_message_hook (NULL, msg, M_SEND2HOOK);
896 if (idx[menu->current]->unowned)
897 idx[menu->current]->content->unlink = 0;
898 if (delete_attachment (menu, &idxlen, menu->current) == -1)
900 mutt_update_tree (idx, idxlen);
902 if (menu->current > idxlen - 1)
903 menu->current = idxlen - 1;
908 if (menu->current == 0)
909 msg->content = idx[0]->content;
911 menu->redraw |= REDRAW_STATUS;
912 mutt_message_hook (NULL, msg, M_SEND2HOOK);
915 #define CURRENT idx[menu->current]->content
917 case OP_COMPOSE_TOGGLE_RECODE:
920 if (!mutt_is_text_part (CURRENT)) {
921 mutt_error (_("Recoding only affects text attachments."));
924 CURRENT->noconv = !CURRENT->noconv;
926 mutt_message (_("The current attachment won't be converted."));
928 mutt_message (_("The current attachment will be converted."));
929 menu->redraw = REDRAW_CURRENT;
930 mutt_message_hook (NULL, msg, M_SEND2HOOK);
935 case OP_COMPOSE_EDIT_DESCRIPTION:
937 m_strcpy(buf, sizeof(buf),
938 NONULL(idx[menu->current]->content->description));
939 /* header names should not be translated */
940 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
941 m_strreplace(&idx[menu->current]->content->description, buf);
942 menu->redraw = REDRAW_CURRENT;
944 mutt_message_hook (NULL, msg, M_SEND2HOOK);
947 case OP_COMPOSE_UPDATE_ENCODING:
949 if (menu->tagprefix) {
952 for (top = msg->content; top; top = top->next) {
954 mutt_update_encoding (top);
956 menu->redraw = REDRAW_FULL;
959 mutt_update_encoding (idx[menu->current]->content);
960 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
962 mutt_message_hook (NULL, msg, M_SEND2HOOK);
965 case OP_COMPOSE_TOGGLE_DISPOSITION:
966 /* toggle the content-disposition between inline/attachment */
967 idx[menu->current]->content->disposition =
968 (idx[menu->current]->content->disposition ==
969 DISPINLINE) ? DISPATTACH : DISPINLINE;
970 menu->redraw = REDRAW_CURRENT;
976 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
978 /* this may have been a change to text/something */
979 mutt_update_encoding (idx[menu->current]->content);
981 menu->redraw = REDRAW_CURRENT;
983 mutt_message_hook (NULL, msg, M_SEND2HOOK);
986 case OP_COMPOSE_EDIT_ENCODING:
988 m_strcpy(buf, sizeof(buf),
989 ENCODING(idx[menu->current]->content->encoding));
990 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
991 sizeof (buf), 0) == 0 && buf[0]) {
992 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
993 idx[menu->current]->content->encoding = i;
994 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
998 mutt_error _("Invalid encoding.");
1000 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1003 case OP_COMPOSE_SEND_MESSAGE:
1005 /* Note: We don't invoke send2-hook here, since we want to leave
1006 * users an opportunity to change settings from the ":" prompt.
1009 if (check_attachments (idx, idxlen) != 0) {
1010 menu->redraw = REDRAW_FULL;
1014 if (msg->chain && mix_check_message (msg) != 0)
1017 if (!fccSet && *fcc) {
1018 if ((i = query_quadoption (OPT_COPY,
1019 _("Save a copy of this message?"))) == -1)
1029 case OP_COMPOSE_EDIT_FILE:
1031 mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename);
1032 mutt_update_encoding (idx[menu->current]->content);
1033 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1034 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1037 case OP_COMPOSE_TOGGLE_UNLINK:
1039 idx[menu->current]->content->unlink =
1040 !idx[menu->current]->content->unlink;
1042 menu->redraw = REDRAW_INDEX;
1043 /* No send2hook since this doesn't change the message. */
1046 case OP_COMPOSE_GET_ATTACHMENT:
1048 if (menu->tagprefix) {
1051 for (top = msg->content; top; top = top->next) {
1053 mutt_get_tmp_attachment (top);
1055 menu->redraw = REDRAW_FULL;
1057 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1058 menu->redraw = REDRAW_CURRENT;
1060 /* No send2hook since this doesn't change the message. */
1063 case OP_COMPOSE_RENAME_FILE:
1065 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
1066 mutt_pretty_mailbox (fname);
1067 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1069 if (stat (idx[menu->current]->content->filename, &st) == -1) {
1070 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1074 mutt_expand_path (fname, sizeof (fname));
1075 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1078 m_strreplace(&idx[menu->current]->content->filename, fname);
1079 menu->redraw = REDRAW_CURRENT;
1081 if (idx[menu->current]->content->stamp >= st.st_mtime)
1082 mutt_stamp_attachment (idx[menu->current]->content);
1085 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1088 case OP_COMPOSE_NEW_MIME:
1095 CLEARLINE (LINES - 1);
1097 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1100 mutt_expand_path (fname, sizeof (fname));
1102 /* Call to lookup_mime_type () ? maybe later */
1104 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1108 if (!(p = strchr (type, '/'))) {
1109 mutt_error _("Content-Type is of the form base/sub");
1114 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1115 mutt_error (_("Unknown Content-Type %s"), type);
1118 if (idxlen == idxmax) {
1119 p_realloc(&idx, idxmax += 5);
1123 idx[idxlen] = p_new(ATTACHPTR, 1);
1124 /* Touch the file */
1125 if (!(fp = safe_fopen (fname, "w"))) {
1126 mutt_error (_("Can't create file %s"), fname);
1127 p_delete(&idx[idxlen]);
1132 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1134 _("What we have here is a failure to make an attachment");
1137 update_idx (menu, idx, idxlen++);
1139 idx[menu->current]->content->type = itype;
1140 m_strreplace(&idx[menu->current]->content->subtype, p);
1141 idx[menu->current]->content->unlink = 1;
1142 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1144 if (mutt_compose_attachment (idx[menu->current]->content)) {
1145 mutt_update_encoding (idx[menu->current]->content);
1146 menu->redraw = REDRAW_FULL;
1149 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1152 case OP_COMPOSE_EDIT_MIME:
1154 if (mutt_edit_attachment (idx[menu->current]->content)) {
1155 mutt_update_encoding (idx[menu->current]->content);
1156 menu->redraw = REDRAW_FULL;
1158 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1161 case OP_VIEW_ATTACH:
1162 case OP_DISPLAY_HEADERS:
1164 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1166 menu->redraw = REDRAW_FULL;
1167 /* no send2hook, since this doesn't modify the message */
1172 mutt_save_attachment_list (NULL, menu->tagprefix,
1173 menu->tagprefix ? msg->content : idx[menu->
1175 content, NULL, menu);
1176 MAYBE_REDRAW (menu->redraw);
1177 /* no send2hook, since this doesn't modify the message */
1182 mutt_print_attachment_list (NULL, menu->tagprefix,
1183 menu->tagprefix ? msg->content : idx[menu->
1186 /* no send2hook, since this doesn't modify the message */
1192 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1193 menu->tagprefix ? msg->content : idx[menu->
1195 content, op == OP_FILTER);
1196 if (op == OP_FILTER) /* cte might have changed */
1197 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1198 menu->redraw |= REDRAW_STATUS;
1199 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1204 query_quadoption (OPT_POSTPONE,
1205 _("Postpone this message?"))) == M_NO) {
1206 while (idxlen-- > 0) {
1207 /* avoid freeing other attachments */
1208 idx[idxlen]->content->next = NULL;
1209 idx[idxlen]->content->parts = NULL;
1210 if (idx[idxlen]->unowned)
1211 idx[idxlen]->content->unlink = 0;
1212 body_list_wipe(&idx[idxlen]->content);
1213 p_delete(&idx[idxlen]->tree);
1214 p_delete(&idx[idxlen]);
1226 /* fall through to postpone! */
1228 case OP_COMPOSE_POSTPONE_MESSAGE:
1230 if (check_attachments (idx, idxlen) != 0) {
1231 menu->redraw = REDRAW_FULL;
1239 case OP_COMPOSE_ISPELL:
1241 snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1242 msg->content->filename);
1243 if (mutt_system (buf) == -1)
1244 mutt_error (_("Error running \"%s\"!"), buf);
1246 mutt_update_encoding (msg->content);
1247 menu->redraw |= REDRAW_STATUS;
1251 case OP_COMPOSE_WRITE_MESSAGE:
1255 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
1256 mutt_pretty_mailbox (fname);
1259 msg->content = idx[0]->content;
1260 if (mutt_enter_fname
1261 (_("Write message to mailbox"), fname, sizeof (fname),
1262 &menu->redraw, 1) != -1 && fname[0]) {
1263 mutt_message (_("Writing message to %s ..."), fname);
1264 mutt_expand_path (fname, sizeof (fname));
1266 if (msg->content->next)
1267 msg->content = mutt_make_multipart (msg->content);
1269 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1270 msg->content = mutt_remove_multipart (msg->content);
1272 mutt_message _("Message written.");
1276 case OP_COMPOSE_PGP_MENU:
1277 if (msg->security & APPLICATION_SMIME) {
1278 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1280 mutt_clear_error ();
1285 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1286 redraw_crypt_lines (msg);
1287 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1290 case OP_FORGET_PASSPHRASE:
1291 crypt_forget_passphrase ();
1294 case OP_COMPOSE_SMIME_MENU:
1295 if (msg->security & APPLICATION_PGP) {
1296 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1298 mutt_clear_error ();
1303 msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1304 redraw_crypt_lines (msg);
1305 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1308 case OP_COMPOSE_MIX:
1309 mix_make_chain (&msg->chain, &menu->redraw);
1310 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1314 /* Draw formated compose status line */
1315 if (menu->redraw & REDRAW_STATUS) {
1316 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1317 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1318 SETCOLOR (MT_COLOR_STATUS);
1319 move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
1320 printw ("%-*.*s", COLS-SW, COLS-SW, buf);
1321 SETCOLOR (MT_COLOR_NORMAL);
1322 menu->redraw &= ~REDRAW_STATUS;
1326 mutt_menuDestroy (&menu);
1329 msg->content = idx[0]->content;
1330 for (i = 0; i < idxlen; i++) {
1331 idx[i]->content->aptr = NULL;
1335 msg->content = NULL;