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>
19 #include <lib-ui/curses.h>
20 #include <lib-ui/enter.h>
21 #include <lib-ui/menu.h>
22 #include <lib-mx/mx.h>
27 #include "mutt_idna.h"
29 #include "recvattach.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 m_strformat(b, blen, COLS - SW, AttachFormat, mutt_attach_fmt,
117 ((ATTACHPTR **)menu->data)[num], M_FORMAT_STAT_FILE);
120 static void redraw_crypt_lines (HEADER * msg)
125 mvaddstr (HDR_CRYPT, SW, " Security: ");
126 else if (msg->security & APPLICATION_SMIME)
127 mvaddstr (HDR_CRYPT, SW, " S/MIME: ");
128 else if (msg->security & APPLICATION_PGP)
129 mvaddstr (HDR_CRYPT, SW, " PGP: ");
131 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
132 addstr (_("Sign, Encrypt"));
133 else if (msg->security & ENCRYPT)
134 addstr (_("Encrypt"));
135 else if (msg->security & SIGN)
140 if ((msg->security & APPLICATION_PGP)
141 && (msg->security & (ENCRYPT | SIGN))) {
142 if ((msg->security & INLINE))
143 addstr (_(" (inline)"));
145 addstr (_(" (PGP/MIME)"));
149 move (HDR_CRYPTINFO, SW);
151 if (msg->security & APPLICATION_PGP && msg->security & SIGN)
152 printw ("%s%s", _(" sign as: "),
153 PgpSignAs ? PgpSignAs : _("<default>"));
155 if (msg->security & APPLICATION_SMIME && msg->security & SIGN) {
156 printw ("%s%s", _(" sign as: "),
157 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
160 if ((msg->security & APPLICATION_SMIME)
161 && (msg->security & ENCRYPT)
162 && SmimeCryptAlg && *SmimeCryptAlg) {
163 mvprintw (HDR_CRYPTINFO, SW + 40, "%s%s", _("Encrypt with: "),
164 NONULL (SmimeCryptAlg));
169 static void redraw_mix_line (string_list_t * chain)
174 mvaddstr (HDR_MIX, SW, " Mix: ");
177 addstr ("<no chain defined>");
182 for (c = 12; chain; chain = chain->next) {
184 if (t && t[0] == '0' && t[1] == '\0')
187 if (c + m_strlen(t) + 2 >= COLS - SW)
194 c += m_strlen(t) + 2;
198 static int check_attachments (ATTACHPTR ** idx, short idxlen)
202 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + STRING];
204 for (i = 0; i < idxlen; i++) {
205 m_strcpy(pretty, sizeof(pretty), idx[i]->content->filename);
206 if (stat (idx[i]->content->filename, &st) != 0) {
207 mutt_pretty_mailbox (pretty);
208 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
212 if (idx[i]->content->stamp < st.st_mtime) {
213 mutt_pretty_mailbox (pretty);
214 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
217 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
218 mutt_update_encoding (idx[i]->content);
227 static void draw_envelope_addr (int line, address_t * addr)
232 rfc822_addrcat(buf, sizeof (buf), addr, 1);
233 mvprintw (line, SW, TITLE_FMT, Prompts[line - 1]);
234 mutt_paddstr (W, buf);
237 static void draw_envelope (HEADER * msg, char *fcc)
239 draw_envelope_addr (HDR_FROM, msg->env->from);
241 if (!option (OPTNEWSSEND)) {
243 draw_envelope_addr (HDR_TO, msg->env->to);
244 draw_envelope_addr (HDR_CC, msg->env->cc);
245 draw_envelope_addr (HDR_BCC, msg->env->bcc);
248 mvprintw (HDR_TO, SW, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
249 mutt_paddstr (W, NONULL (msg->env->newsgroups));
250 mvprintw (HDR_CC, SW, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
251 mutt_paddstr (W, NONULL (msg->env->followup_to));
254 mvprintw (HDR_SUBJECT, SW, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
255 mutt_paddstr (W, NONULL (msg->env->subject));
256 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
257 mvprintw (HDR_FCC, SW, TITLE_FMT, Prompts[HDR_FCC - 1]);
258 mutt_paddstr (W, fcc);
260 redraw_crypt_lines (msg);
261 redraw_mix_line (msg->chain);
263 SETCOLOR (MT_COLOR_STATUS);
264 mvaddstr (HDR_ATTACH - 1, SW, _("-- Attachments"));
265 BKGDSET (MT_COLOR_STATUS);
268 BKGDSET (MT_COLOR_NORMAL);
269 SETCOLOR (MT_COLOR_NORMAL);
272 static int edit_address_list (int line, address_t ** addr)
274 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
277 mutt_addrlist_to_local (*addr);
278 rfc822_addrcat(buf, sizeof (buf), *addr, 0);
279 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
280 address_list_wipe(addr);
281 *addr = mutt_parse_adrlist (*addr, buf);
282 *addr = mutt_expand_aliases (*addr);
285 if (option (OPTNEEDREDRAW)) {
286 unset_option (OPTNEEDREDRAW);
290 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
291 mutt_error (_("Warning: '%s' is a bad IDN."), err);
296 /* redraw the expanded list so the user can see the result */
298 rfc822_addrcat(buf, sizeof (buf), *addr, 1);
299 move (line, HDR_XOFFSET + SW);
300 mutt_paddstr (W, buf);
305 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
307 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
310 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
312 if (x == 0 && menu->max == 1) {
313 mutt_error _("You may not delete the only attachment.");
315 idx[x]->content->tagged = 0;
319 for (y = 0; y < *idxlen; y++) {
320 if (idx[y]->content->next == idx[x]->content) {
321 idx[y]->content->next = idx[x]->content->next;
326 idx[x]->content->next = NULL;
327 idx[x]->content->parts = NULL;
328 body_list_wipe(&(idx[x]->content));
329 p_delete(&idx[x]->tree);
331 for (; x < *idxlen - 1; x++)
333 menu->max = --(*idxlen);
338 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
340 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
342 idx[idxlen - 1]->content->next = idx[idxlen]->content;
343 idx[idxlen]->content->aptr = idx[idxlen];
344 menu->current = idxlen++;
345 mutt_update_tree (idx, idxlen);
352 * cum_attachs_size: Cumulative Attachments Size
354 * Returns the total number of bytes used by the attachments in the
355 * attachment list _after_ content-transfer-encodings have been
359 static unsigned long cum_attachs_size(MUTTMENU * menu)
363 ATTACHPTR **idx = menu->data;
367 for (i = 0, s = 0; i < menu->max; i++) {
371 b->content = mutt_get_content_info (b->filename, b);
373 if ((info = b->content)) {
374 switch (b->encoding) {
375 case ENCQUOTEDPRINTABLE:
376 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
379 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
382 s += info->lobin + info->hibin + info->ascii + info->crlf;
392 * compose_format_str()
394 * %a = total number of attachments
395 * %h = hostname [option]
396 * %l = approx. length of current message (in bytes)
399 * This function is similar to status_format_str(). Look at that function for
400 * help when modifying this function.
402 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
405 static const char *compose_format_str (char *buf, ssize_t buflen, char op,
406 const char *src, const char *prefix,
409 anytype data, format_flag flags)
411 char fmt[STRING], tmp[STRING];
412 int optional = (flags & M_FORMAT_OPTIONAL);
413 MUTTMENU *menu = data.ptr;
417 case 'a': /* total number of attachments */
418 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
419 snprintf (buf, buflen, fmt, menu->max);
422 case 'h': /* hostname */
423 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
424 snprintf (buf, buflen, fmt, NONULL(mod_core.shorthost));
427 case 'l': /* approx length of current message in bytes */
428 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
429 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
430 snprintf (buf, buflen, fmt, tmp);
434 m_strcpy(buf, buflen, mutt_make_version());
446 if (flags & M_FORMAT_OPTIONAL)
447 compose_status_line(buf, buflen, menu, optional ? ifstr : elstr);
452 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
455 m_strformat(buf, buflen, COLS - SW, p, compose_format_str, menu, 0);
460 * 1 message should be postponed
464 int mutt_compose_menu (HEADER * msg, /* structure for new message */
465 char *fcc, /* where to save a copy of the message */
467 HEADER * cur __attribute__ ((unused)))
468 { /* current message */
469 char helpstr[STRING];
470 char buf[LONG_STRING];
471 char fname[_POSIX_PATH_MAX];
473 ATTACHPTR **idx = NULL;
477 int r = -1; /* return value */
480 int fccSet = 0; /* has the user edited the Fcc: field ? */
481 CONTEXT *ctx = NULL, *this = NULL;
483 /* Sort, SortAux could be changed in mutt_index_menu() */
484 int oldSort, oldSortAux;
488 int news = 0; /* is it a news article ? */
490 if (option (OPTNEWSSEND))
494 mutt_attach_init (msg->content);
495 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
497 menu = mutt_new_menu ();
498 menu->menu = MENU_COMPOSE;
499 menu->offset = HDR_ATTACH;
501 menu->make_entry = snd_entry;
502 menu->tag = mutt_tag_attach;
506 menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_COMPOSE,
510 menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_COMPOSE,
513 if (option (OPTMBOXPANE))
517 unset_option (OPTNEWS); /* for any case */
519 switch (op = mutt_menuLoop (menu)) {
521 draw_envelope (msg, fcc);
522 menu->offset = HDR_ATTACH;
523 menu->pagelen = LINES - HDR_ATTACH - 2;
525 case OP_COMPOSE_EDIT_FROM:
526 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
527 mutt_message_hook (NULL, msg, M_SEND2HOOK);
529 case OP_COMPOSE_EDIT_TO:
533 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
534 mutt_message_hook (NULL, msg, M_SEND2HOOK);
539 case OP_COMPOSE_EDIT_BCC:
543 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
544 mutt_message_hook (NULL, msg, M_SEND2HOOK);
549 case OP_COMPOSE_EDIT_CC:
553 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
554 mutt_message_hook (NULL, msg, M_SEND2HOOK);
560 case OP_COMPOSE_EDIT_NEWSGROUPS:
562 if (msg->env->newsgroups)
563 m_strcpy(buf, sizeof(buf), msg->env->newsgroups);
566 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
568 p_delete(&msg->env->newsgroups);
570 msg->env->newsgroups = m_strdup(skipspaces(buf));
571 move (HDR_TO, HDR_XOFFSET);
573 if (msg->env->newsgroups)
574 printw ("%-*.*s", W, W, msg->env->newsgroups);
579 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
582 if (msg->env->followup_to)
583 m_strcpy(buf, sizeof(buf), msg->env->followup_to);
584 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
586 p_delete(&msg->env->followup_to);
588 msg->env->followup_to = m_strdup(skipspaces(buf));
589 move (HDR_CC, HDR_XOFFSET);
591 if (msg->env->followup_to)
592 printw ("%-*.*s", W, W, msg->env->followup_to);
598 case OP_COMPOSE_EDIT_SUBJECT:
599 if (msg->env->subject)
600 m_strcpy(buf, sizeof(buf), msg->env->subject);
603 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
604 m_strreplace(&msg->env->subject, buf);
605 move (HDR_SUBJECT, HDR_XOFFSET + SW);
607 if (msg->env->subject)
608 mutt_paddstr (W, msg->env->subject);
610 mutt_message_hook (NULL, msg, M_SEND2HOOK);
612 case OP_COMPOSE_EDIT_REPLY_TO:
613 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
614 mutt_message_hook (NULL, msg, M_SEND2HOOK);
616 case OP_COMPOSE_EDIT_FCC:
617 m_strcpy(buf, sizeof(buf), fcc);
618 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
619 m_strcpy(fcc, _POSIX_PATH_MAX, buf);
620 mutt_pretty_mailbox (fcc);
621 move (HDR_FCC, HDR_XOFFSET + SW);
622 mutt_paddstr (W, fcc);
625 MAYBE_REDRAW (menu->redraw);
626 mutt_message_hook (NULL, msg, M_SEND2HOOK);
628 case OP_COMPOSE_EDIT_MESSAGE:
629 if (!option (OPTEDITHDRS)) {
630 mutt_edit_file(msg->content->filename);
631 mutt_update_encoding (msg->content);
632 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
633 mutt_message_hook (NULL, msg, M_SEND2HOOK);
637 case OP_COMPOSE_EDIT_HEADERS:
638 if ((op == OP_COMPOSE_EDIT_HEADERS ||
639 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
640 const char *tag = NULL;
643 mutt_env_to_local (msg->env);
644 mutt_edit_headers(msg->content->filename, msg, fcc, fcclen);
645 if (mutt_env_to_idna (msg->env, &tag, &err)) {
646 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
650 mutt_update_encoding (msg->content);
652 /* attachments may have been added */
653 if (idxlen && idx[idxlen - 1]->content->next) {
654 for (i = 0; i < idxlen; i++)
658 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
664 menu->redraw = REDRAW_FULL;
665 mutt_message_hook (NULL, msg, M_SEND2HOOK);
668 case OP_COMPOSE_ATTACH_FILE:
675 prompt = _("Attach file");
679 if (_mutt_enter_fname
680 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
681 &numfiles) == -1 || *fname == '\0')
684 if (idxlen + numfiles >= idxmax) {
685 p_realloc(&idx, idxmax += 5 + numfiles);
691 mutt_message _("Attaching selected files...");
693 for (i = 0; i < numfiles; i++) {
694 char *att = files[i];
696 idx[idxlen] = p_new(ATTACHPTR, 1);
697 idx[idxlen]->unowned = 1;
698 idx[idxlen]->content = mutt_make_file_attach (att);
699 if (idx[idxlen]->content != NULL)
700 update_idx (menu, idx, idxlen++);
703 mutt_error (_("Unable to attach %s!"), att);
704 p_delete(&idx[idxlen]);
712 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
714 mutt_message_hook (NULL, msg, M_SEND2HOOK);
717 case OP_COMPOSE_ATTACH_MESSAGE:
719 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
726 prompt = _("Open mailbox to attach message from");
729 unset_option (OPTNEWS);
730 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
731 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
734 prompt = _("Open newsgroup to attach message from");
735 set_option (OPTNEWS);
741 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
744 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
745 mutt_pretty_mailbox (fname);
748 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
753 if (option (OPTNEWS))
754 nntp_expand_path (fname, sizeof (fname),
755 &CurrentNewsSrv->conn->account);
758 mutt_expand_path (fname, sizeof (fname));
759 if (mx_get_magic (fname) != M_IMAP)
760 if (mx_get_magic (fname) != M_POP)
762 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
764 /* check to make sure the file exists and is readable */
765 if (access (fname, R_OK) == -1) {
770 menu->redraw = REDRAW_FULL;
772 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
778 if (!ctx->msgcount) {
779 mx_close_mailbox (ctx, NULL);
781 mutt_error _("No messages in that folder.");
786 this = Context; /* remember current folder and sort methods */
788 oldSortAux = SortAux;
791 set_option (OPTATTACHMSG);
792 mutt_message _("Tag the messages you want to attach!");
794 closed = mutt_index_menu ();
795 unset_option (OPTATTACHMSG);
798 /* go back to the folder we started from */
800 /* Restore old $sort and $sort_aux */
802 SortAux = oldSortAux;
803 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
807 if (idxlen + Context->tagged >= idxmax) {
808 p_realloc(&idx, idxmax += 5 + Context->tagged);
812 for (i = 0; i < Context->msgcount; i++) {
813 h = Context->hdrs[i];
815 idx[idxlen] = p_new(ATTACHPTR, 1);
816 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
817 if (idx[idxlen]->content != NULL)
818 update_idx (menu, idx, idxlen++);
820 mutt_error _("Unable to attach!");
822 p_delete(&idx[idxlen]);
826 menu->redraw |= REDRAW_FULL;
828 if (closed == OP_QUIT)
829 mx_close_mailbox (Context, NULL);
831 mx_fastclose_mailbox (Context);
834 /* go back to the folder we started from */
836 /* Restore old $sort and $sort_aux */
838 SortAux = oldSortAux;
840 mutt_message_hook (NULL, msg, M_SEND2HOOK);
845 if (idx[menu->current]->unowned)
846 idx[menu->current]->content->unlink = 0;
847 if (delete_attachment (menu, &idxlen, menu->current) == -1)
849 mutt_update_tree (idx, idxlen);
851 if (menu->current > idxlen - 1)
852 menu->current = idxlen - 1;
857 if (menu->current == 0)
858 msg->content = idx[0]->content;
860 menu->redraw |= REDRAW_STATUS;
861 mutt_message_hook (NULL, msg, M_SEND2HOOK);
864 #define CURRENT idx[menu->current]->content
866 case OP_COMPOSE_TOGGLE_RECODE:
869 if (!mutt_is_text_part (CURRENT)) {
870 mutt_error (_("Recoding only affects text attachments."));
873 CURRENT->noconv = !CURRENT->noconv;
875 mutt_message (_("The current attachment won't be converted."));
877 mutt_message (_("The current attachment will be converted."));
878 menu->redraw = REDRAW_CURRENT;
879 mutt_message_hook (NULL, msg, M_SEND2HOOK);
884 case OP_COMPOSE_EDIT_DESCRIPTION:
886 m_strcpy(buf, sizeof(buf),
887 NONULL(idx[menu->current]->content->description));
888 /* header names should not be translated */
889 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
890 m_strreplace(&idx[menu->current]->content->description, buf);
891 menu->redraw = REDRAW_CURRENT;
893 mutt_message_hook (NULL, msg, M_SEND2HOOK);
896 case OP_COMPOSE_UPDATE_ENCODING:
898 if (menu->tagprefix) {
901 for (top = msg->content; top; top = top->next) {
903 mutt_update_encoding (top);
905 menu->redraw = REDRAW_FULL;
908 mutt_update_encoding (idx[menu->current]->content);
909 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
911 mutt_message_hook (NULL, msg, M_SEND2HOOK);
914 case OP_COMPOSE_TOGGLE_DISPOSITION:
915 /* toggle the content-disposition between inline/attachment */
916 idx[menu->current]->content->disposition =
917 (idx[menu->current]->content->disposition ==
918 DISPINLINE) ? DISPATTACH : DISPINLINE;
919 menu->redraw = REDRAW_CURRENT;
925 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
927 /* this may have been a change to text/something */
928 mutt_update_encoding (idx[menu->current]->content);
930 menu->redraw = REDRAW_CURRENT;
932 mutt_message_hook (NULL, msg, M_SEND2HOOK);
935 case OP_COMPOSE_EDIT_ENCODING:
937 m_strcpy(buf, sizeof(buf),
938 ENCODING(idx[menu->current]->content->encoding));
939 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
940 sizeof (buf), 0) == 0 && buf[0]) {
941 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
942 idx[menu->current]->content->encoding = i;
943 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
947 mutt_error _("Invalid encoding.");
949 mutt_message_hook (NULL, msg, M_SEND2HOOK);
952 case OP_COMPOSE_SEND_MESSAGE:
954 /* Note: We don't invoke send2-hook here, since we want to leave
955 * users an opportunity to change settings from the ":" prompt.
958 if (check_attachments (idx, idxlen) != 0) {
959 menu->redraw = REDRAW_FULL;
963 if (msg->chain && mix_check_message (msg) != 0)
966 if (!fccSet && *fcc) {
967 if ((i = query_quadoption (OPT_COPY,
968 _("Save a copy of this message?"))) == -1)
978 case OP_COMPOSE_EDIT_FILE:
980 mutt_edit_file(idx[menu->current]->content->filename);
981 mutt_update_encoding (idx[menu->current]->content);
982 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
983 mutt_message_hook (NULL, msg, M_SEND2HOOK);
986 case OP_COMPOSE_TOGGLE_UNLINK:
988 idx[menu->current]->content->unlink =
989 !idx[menu->current]->content->unlink;
991 menu->redraw = REDRAW_INDEX;
992 /* No send2hook since this doesn't change the message. */
995 case OP_COMPOSE_GET_ATTACHMENT:
997 if (menu->tagprefix) {
1000 for (top = msg->content; top; top = top->next) {
1002 mutt_get_tmp_attachment (top);
1004 menu->redraw = REDRAW_FULL;
1006 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1007 menu->redraw = REDRAW_CURRENT;
1009 /* No send2hook since this doesn't change the message. */
1012 case OP_COMPOSE_RENAME_FILE:
1014 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
1015 mutt_pretty_mailbox (fname);
1016 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1018 if (stat (idx[menu->current]->content->filename, &st) == -1) {
1019 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1023 mutt_expand_path (fname, sizeof (fname));
1024 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1027 m_strreplace(&idx[menu->current]->content->filename, fname);
1028 menu->redraw = REDRAW_CURRENT;
1030 if (idx[menu->current]->content->stamp >= st.st_mtime)
1031 mutt_stamp_attachment (idx[menu->current]->content);
1034 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1037 case OP_COMPOSE_NEW_MIME:
1044 CLEARLINE (LINES - 1);
1046 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1049 mutt_expand_path (fname, sizeof (fname));
1051 /* Call to lookup_mime_type () ? maybe later */
1053 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1057 if (!(p = strchr (type, '/'))) {
1058 mutt_error _("Content-Type is of the form base/sub");
1063 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1064 mutt_error (_("Unknown Content-Type %s"), type);
1067 if (idxlen == idxmax) {
1068 p_realloc(&idx, idxmax += 5);
1072 idx[idxlen] = p_new(ATTACHPTR, 1);
1073 /* Touch the file */
1074 if (!(fp = safe_fopen (fname, "w"))) {
1075 mutt_error (_("Can't create file %s"), fname);
1076 p_delete(&idx[idxlen]);
1081 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1083 _("What we have here is a failure to make an attachment");
1086 update_idx (menu, idx, idxlen++);
1088 idx[menu->current]->content->type = itype;
1089 m_strreplace(&idx[menu->current]->content->subtype, p);
1090 idx[menu->current]->content->unlink = 1;
1091 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1093 if (mutt_compose_attachment (idx[menu->current]->content)) {
1094 mutt_update_encoding (idx[menu->current]->content);
1095 menu->redraw = REDRAW_FULL;
1098 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1101 case OP_COMPOSE_EDIT_MIME:
1103 if (mutt_edit_attachment (idx[menu->current]->content)) {
1104 mutt_update_encoding (idx[menu->current]->content);
1105 menu->redraw = REDRAW_FULL;
1107 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1110 case OP_VIEW_ATTACH:
1111 case OP_DISPLAY_HEADERS:
1113 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1115 menu->redraw = REDRAW_FULL;
1116 /* no send2hook, since this doesn't modify the message */
1121 mutt_save_attachment_list (NULL, menu->tagprefix,
1122 menu->tagprefix ? msg->content : idx[menu->
1124 content, NULL, menu);
1125 MAYBE_REDRAW (menu->redraw);
1126 /* no send2hook, since this doesn't modify the message */
1131 mutt_print_attachment_list (NULL, menu->tagprefix,
1132 menu->tagprefix ? msg->content : idx[menu->
1135 /* no send2hook, since this doesn't modify the message */
1141 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1142 menu->tagprefix ? msg->content : idx[menu->
1144 content, op == OP_FILTER);
1145 if (op == OP_FILTER) /* cte might have changed */
1146 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1147 menu->redraw |= REDRAW_STATUS;
1148 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1153 query_quadoption (OPT_POSTPONE,
1154 _("Postpone this message?"))) == M_NO) {
1155 while (idxlen-- > 0) {
1156 /* avoid freeing other attachments */
1157 idx[idxlen]->content->next = NULL;
1158 idx[idxlen]->content->parts = NULL;
1159 if (idx[idxlen]->unowned)
1160 idx[idxlen]->content->unlink = 0;
1161 body_list_wipe(&idx[idxlen]->content);
1162 p_delete(&idx[idxlen]->tree);
1163 p_delete(&idx[idxlen]);
1175 /* fall through to postpone! */
1177 case OP_COMPOSE_POSTPONE_MESSAGE:
1179 if (check_attachments (idx, idxlen) != 0) {
1180 menu->redraw = REDRAW_FULL;
1188 case OP_COMPOSE_WRITE_MESSAGE:
1191 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
1192 mutt_pretty_mailbox (fname);
1195 msg->content = idx[0]->content;
1196 if (mutt_enter_fname
1197 (_("Write message to mailbox"), fname, sizeof (fname),
1198 &menu->redraw, 1) != -1 && fname[0]) {
1199 mutt_message (_("Writing message to %s ..."), fname);
1200 mutt_expand_path (fname, sizeof (fname));
1202 if (msg->content->next)
1203 msg->content = mutt_make_multipart (msg->content);
1205 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1206 msg->content = mutt_remove_multipart (msg->content);
1208 mutt_message _("Message written.");
1212 case OP_COMPOSE_PGP_MENU:
1213 if (msg->security & APPLICATION_SMIME) {
1214 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1216 mutt_clear_error ();
1221 msg->security = crypt_send_menu (msg, &menu->redraw, 0);
1222 redraw_crypt_lines (msg);
1223 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1226 case OP_COMPOSE_SMIME_MENU:
1227 if (msg->security & APPLICATION_PGP) {
1228 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1230 mutt_clear_error ();
1235 msg->security = crypt_send_menu(msg, &menu->redraw, 1);
1236 redraw_crypt_lines (msg);
1237 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1240 case OP_COMPOSE_MIX:
1241 mix_make_chain (&msg->chain, &menu->redraw);
1242 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1246 /* Draw formated compose status line */
1247 if (menu->redraw & REDRAW_STATUS) {
1248 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1249 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1250 SETCOLOR (MT_COLOR_STATUS);
1251 move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
1252 printw ("%-*.*s", COLS-SW, COLS-SW, buf);
1253 SETCOLOR (MT_COLOR_NORMAL);
1254 menu->redraw &= ~REDRAW_STATUS;
1258 mutt_menuDestroy (&menu);
1261 msg->content = idx[0]->content;
1262 for (i = 0; i < idxlen; i++) {
1263 idx[i]->content->aptr = NULL;
1267 msg->content = NULL;