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"
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 m_strformat(b, blen, COLS - SW, AttachFormat, mutt_attach_fmt,
117 ((ATTACHPTR **)menu->data)[num],
118 M_FORMAT_STAT_FILE | (option(OPTARROWCURSOR) ? M_FORMAT_ARROWCURSOR : 0));
121 static void redraw_crypt_lines (HEADER * msg)
126 mvaddstr (HDR_CRYPT, SW, " Security: ");
127 else if (msg->security & APPLICATION_SMIME)
128 mvaddstr (HDR_CRYPT, SW, " S/MIME: ");
129 else if (msg->security & APPLICATION_PGP)
130 mvaddstr (HDR_CRYPT, SW, " PGP: ");
132 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
133 addstr (_("Sign, Encrypt"));
134 else if (msg->security & ENCRYPT)
135 addstr (_("Encrypt"));
136 else if (msg->security & SIGN)
141 if ((msg->security & APPLICATION_PGP)
142 && (msg->security & (ENCRYPT | SIGN))) {
143 if ((msg->security & INLINE))
144 addstr (_(" (inline)"));
146 addstr (_(" (PGP/MIME)"));
150 move (HDR_CRYPTINFO, SW);
152 if (msg->security & APPLICATION_PGP && msg->security & SIGN)
153 printw ("%s%s", _(" sign as: "),
154 PgpSignAs ? PgpSignAs : _("<default>"));
156 if (msg->security & APPLICATION_SMIME && msg->security & SIGN) {
157 printw ("%s%s", _(" sign as: "),
158 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
161 if ((msg->security & APPLICATION_SMIME)
162 && (msg->security & ENCRYPT)
163 && SmimeCryptAlg && *SmimeCryptAlg) {
164 mvprintw (HDR_CRYPTINFO, SW + 40, "%s%s", _("Encrypt with: "),
165 NONULL (SmimeCryptAlg));
170 static void redraw_mix_line (string_list_t * chain)
175 mvaddstr (HDR_MIX, SW, " Mix: ");
178 addstr ("<no chain defined>");
183 for (c = 12; chain; chain = chain->next) {
185 if (t && t[0] == '0' && t[1] == '\0')
188 if (c + m_strlen(t) + 2 >= COLS - SW)
195 c += m_strlen(t) + 2;
199 static int check_attachments (ATTACHPTR ** idx, short idxlen)
203 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + STRING];
205 for (i = 0; i < idxlen; i++) {
206 m_strcpy(pretty, sizeof(pretty), idx[i]->content->filename);
207 if (stat (idx[i]->content->filename, &st) != 0) {
208 mutt_pretty_mailbox (pretty);
209 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
213 if (idx[i]->content->stamp < st.st_mtime) {
214 mutt_pretty_mailbox (pretty);
215 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
218 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
219 mutt_update_encoding (idx[i]->content);
228 static void draw_envelope_addr (int line, address_t * addr)
233 rfc822_addrcat(buf, sizeof (buf), addr, 1);
234 mvprintw (line, SW, TITLE_FMT, Prompts[line - 1]);
235 mutt_paddstr (W, buf);
238 static void draw_envelope (HEADER * msg, char *fcc)
240 draw_envelope_addr (HDR_FROM, msg->env->from);
242 if (!option (OPTNEWSSEND)) {
244 draw_envelope_addr (HDR_TO, msg->env->to);
245 draw_envelope_addr (HDR_CC, msg->env->cc);
246 draw_envelope_addr (HDR_BCC, msg->env->bcc);
249 mvprintw (HDR_TO, SW, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
250 mutt_paddstr (W, NONULL (msg->env->newsgroups));
251 mvprintw (HDR_CC, SW, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
252 mutt_paddstr (W, NONULL (msg->env->followup_to));
255 mvprintw (HDR_SUBJECT, SW, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
256 mutt_paddstr (W, NONULL (msg->env->subject));
257 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
258 mvprintw (HDR_FCC, SW, TITLE_FMT, Prompts[HDR_FCC - 1]);
259 mutt_paddstr (W, fcc);
261 redraw_crypt_lines (msg);
262 redraw_mix_line (msg->chain);
264 SETCOLOR (MT_COLOR_STATUS);
265 mvaddstr (HDR_ATTACH - 1, SW, _("-- Attachments"));
266 BKGDSET (MT_COLOR_STATUS);
269 BKGDSET (MT_COLOR_NORMAL);
270 SETCOLOR (MT_COLOR_NORMAL);
273 static int edit_address_list (int line, address_t ** addr)
275 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
278 mutt_addrlist_to_local (*addr);
279 rfc822_addrcat(buf, sizeof (buf), *addr, 0);
280 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
281 address_list_wipe(addr);
282 *addr = mutt_parse_adrlist (*addr, buf);
283 *addr = mutt_expand_aliases (*addr);
286 if (option (OPTNEEDREDRAW)) {
287 unset_option (OPTNEEDREDRAW);
291 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
292 mutt_error (_("Warning: '%s' is a bad IDN."), err);
297 /* redraw the expanded list so the user can see the result */
299 rfc822_addrcat(buf, sizeof (buf), *addr, 1);
300 move (line, HDR_XOFFSET + SW);
301 mutt_paddstr (W, buf);
306 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
308 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
311 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
313 if (x == 0 && menu->max == 1) {
314 mutt_error _("You may not delete the only attachment.");
316 idx[x]->content->tagged = 0;
320 for (y = 0; y < *idxlen; y++) {
321 if (idx[y]->content->next == idx[x]->content) {
322 idx[y]->content->next = idx[x]->content->next;
327 idx[x]->content->next = NULL;
328 idx[x]->content->parts = NULL;
329 body_list_wipe(&(idx[x]->content));
330 p_delete(&idx[x]->tree);
332 for (; x < *idxlen - 1; x++)
334 menu->max = --(*idxlen);
339 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
341 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
343 idx[idxlen - 1]->content->next = idx[idxlen]->content;
344 idx[idxlen]->content->aptr = idx[idxlen];
345 menu->current = idxlen++;
346 mutt_update_tree (idx, idxlen);
353 * cum_attachs_size: Cumulative Attachments Size
355 * Returns the total number of bytes used by the attachments in the
356 * attachment list _after_ content-transfer-encodings have been
360 static unsigned long cum_attachs_size(MUTTMENU * menu)
364 ATTACHPTR **idx = menu->data;
368 for (i = 0, s = 0; i < menu->max; i++) {
372 b->content = mutt_get_content_info (b->filename, b);
374 if ((info = b->content)) {
375 switch (b->encoding) {
376 case ENCQUOTEDPRINTABLE:
377 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
380 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
383 s += info->lobin + info->hibin + info->ascii + info->crlf;
393 * compose_format_str()
395 * %a = total number of attachments
396 * %h = hostname [option]
397 * %l = approx. length of current message (in bytes)
400 * This function is similar to status_format_str(). Look at that function for
401 * help when modifying this function.
403 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
406 static const char *compose_format_str (char *buf, ssize_t buflen, char op,
407 const char *src, const char *prefix,
410 anytype data, format_flag flags)
412 char fmt[STRING], tmp[STRING];
413 int optional = (flags & M_FORMAT_OPTIONAL);
414 MUTTMENU *menu = data.ptr;
418 case 'a': /* total number of attachments */
419 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
420 snprintf (buf, buflen, fmt, menu->max);
423 case 'h': /* hostname */
424 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
425 snprintf (buf, buflen, fmt, NONULL(mod_core.shorthost));
428 case 'l': /* approx length of current message in bytes */
429 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
430 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
431 snprintf (buf, buflen, fmt, tmp);
435 m_strcpy(buf, buflen, mutt_make_version());
447 if (flags & M_FORMAT_OPTIONAL)
448 compose_status_line(buf, buflen, menu, optional ? ifstr : elstr);
453 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
456 m_strformat(buf, buflen, COLS - SW, p, compose_format_str, menu, 0);
461 * 1 message should be postponed
465 int mutt_compose_menu (HEADER * msg, /* structure for new message */
466 char *fcc, /* where to save a copy of the message */
468 HEADER * cur __attribute__ ((unused)))
469 { /* current message */
470 char helpstr[STRING];
471 char buf[LONG_STRING];
472 char fname[_POSIX_PATH_MAX];
474 ATTACHPTR **idx = NULL;
478 int r = -1; /* return value */
481 int fccSet = 0; /* has the user edited the Fcc: field ? */
482 CONTEXT *ctx = NULL, *this = NULL;
484 /* Sort, SortAux could be changed in mutt_index_menu() */
485 int oldSort, oldSortAux;
489 int news = 0; /* is it a news article ? */
491 if (option (OPTNEWSSEND))
495 mutt_attach_init (msg->content);
496 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
498 menu = mutt_new_menu ();
499 menu->menu = MENU_COMPOSE;
500 menu->offset = HDR_ATTACH;
502 menu->make_entry = snd_entry;
503 menu->tag = mutt_tag_attach;
507 menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_COMPOSE,
511 menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_COMPOSE,
514 if (option (OPTMBOXPANE))
518 unset_option (OPTNEWS); /* for any case */
520 switch (op = mutt_menuLoop (menu)) {
522 draw_envelope (msg, fcc);
523 menu->offset = HDR_ATTACH;
524 menu->pagelen = LINES - HDR_ATTACH - 2;
526 case OP_COMPOSE_EDIT_FROM:
527 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
528 mutt_message_hook (NULL, msg, M_SEND2HOOK);
530 case OP_COMPOSE_EDIT_TO:
534 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
535 mutt_message_hook (NULL, msg, M_SEND2HOOK);
540 case OP_COMPOSE_EDIT_BCC:
544 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
545 mutt_message_hook (NULL, msg, M_SEND2HOOK);
550 case OP_COMPOSE_EDIT_CC:
554 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
555 mutt_message_hook (NULL, msg, M_SEND2HOOK);
561 case OP_COMPOSE_EDIT_NEWSGROUPS:
563 if (msg->env->newsgroups)
564 m_strcpy(buf, sizeof(buf), msg->env->newsgroups);
567 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
569 p_delete(&msg->env->newsgroups);
571 msg->env->newsgroups = m_strdup(skipspaces(buf));
572 move (HDR_TO, HDR_XOFFSET);
574 if (msg->env->newsgroups)
575 printw ("%-*.*s", W, W, msg->env->newsgroups);
580 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
583 if (msg->env->followup_to)
584 m_strcpy(buf, sizeof(buf), msg->env->followup_to);
585 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
587 p_delete(&msg->env->followup_to);
589 msg->env->followup_to = m_strdup(skipspaces(buf));
590 move (HDR_CC, HDR_XOFFSET);
592 if (msg->env->followup_to)
593 printw ("%-*.*s", W, W, msg->env->followup_to);
599 case OP_COMPOSE_EDIT_SUBJECT:
600 if (msg->env->subject)
601 m_strcpy(buf, sizeof(buf), msg->env->subject);
604 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
605 m_strreplace(&msg->env->subject, buf);
606 move (HDR_SUBJECT, HDR_XOFFSET + SW);
608 if (msg->env->subject)
609 mutt_paddstr (W, msg->env->subject);
611 mutt_message_hook (NULL, msg, M_SEND2HOOK);
613 case OP_COMPOSE_EDIT_REPLY_TO:
614 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
615 mutt_message_hook (NULL, msg, M_SEND2HOOK);
617 case OP_COMPOSE_EDIT_FCC:
618 m_strcpy(buf, sizeof(buf), fcc);
619 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
620 m_strcpy(fcc, _POSIX_PATH_MAX, buf);
621 mutt_pretty_mailbox (fcc);
622 move (HDR_FCC, HDR_XOFFSET + SW);
623 mutt_paddstr (W, fcc);
626 MAYBE_REDRAW (menu->redraw);
627 mutt_message_hook (NULL, msg, M_SEND2HOOK);
629 case OP_COMPOSE_EDIT_MESSAGE:
630 if (!option (OPTEDITHDRS)) {
631 mutt_edit_file(msg->content->filename);
632 mutt_update_encoding (msg->content);
633 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
634 mutt_message_hook (NULL, msg, M_SEND2HOOK);
638 case OP_COMPOSE_EDIT_HEADERS:
639 if ((op == OP_COMPOSE_EDIT_HEADERS ||
640 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
641 const char *tag = NULL;
644 mutt_env_to_local (msg->env);
645 mutt_edit_headers(msg->content->filename, msg, fcc, fcclen);
646 if (mutt_env_to_idna (msg->env, &tag, &err)) {
647 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
651 mutt_update_encoding (msg->content);
653 /* attachments may have been added */
654 if (idxlen && idx[idxlen - 1]->content->next) {
655 for (i = 0; i < idxlen; i++)
659 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
665 menu->redraw = REDRAW_FULL;
666 mutt_message_hook (NULL, msg, M_SEND2HOOK);
669 case OP_COMPOSE_ATTACH_FILE:
676 prompt = _("Attach file");
680 if (_mutt_enter_fname
681 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
682 &numfiles) == -1 || *fname == '\0')
685 if (idxlen + numfiles >= idxmax) {
686 p_realloc(&idx, idxmax += 5 + numfiles);
692 mutt_message _("Attaching selected files...");
694 for (i = 0; i < numfiles; i++) {
695 char *att = files[i];
697 idx[idxlen] = p_new(ATTACHPTR, 1);
698 idx[idxlen]->unowned = 1;
699 idx[idxlen]->content = mutt_make_file_attach (att);
700 if (idx[idxlen]->content != NULL)
701 update_idx (menu, idx, idxlen++);
704 mutt_error (_("Unable to attach %s!"), att);
705 p_delete(&idx[idxlen]);
713 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
715 mutt_message_hook (NULL, msg, M_SEND2HOOK);
718 case OP_COMPOSE_ATTACH_MESSAGE:
720 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
727 prompt = _("Open mailbox to attach message from");
730 unset_option (OPTNEWS);
731 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
732 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
735 prompt = _("Open newsgroup to attach message from");
736 set_option (OPTNEWS);
742 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
745 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
746 mutt_pretty_mailbox (fname);
749 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
754 if (option (OPTNEWS))
755 nntp_expand_path (fname, sizeof (fname),
756 &CurrentNewsSrv->conn->account);
759 mutt_expand_path (fname, sizeof (fname));
760 if (mx_get_magic (fname) != M_IMAP)
761 if (mx_get_magic (fname) != M_POP)
763 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
765 /* check to make sure the file exists and is readable */
766 if (access (fname, R_OK) == -1) {
771 menu->redraw = REDRAW_FULL;
773 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
779 if (!ctx->msgcount) {
780 mx_close_mailbox (ctx, NULL);
782 mutt_error _("No messages in that folder.");
787 this = Context; /* remember current folder and sort methods */
789 oldSortAux = SortAux;
792 set_option (OPTATTACHMSG);
793 mutt_message _("Tag the messages you want to attach!");
795 closed = mutt_index_menu ();
796 unset_option (OPTATTACHMSG);
799 /* go back to the folder we started from */
801 /* Restore old $sort and $sort_aux */
803 SortAux = oldSortAux;
804 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
808 if (idxlen + Context->tagged >= idxmax) {
809 p_realloc(&idx, idxmax += 5 + Context->tagged);
813 for (i = 0; i < Context->msgcount; i++) {
814 h = Context->hdrs[i];
816 idx[idxlen] = p_new(ATTACHPTR, 1);
817 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
818 if (idx[idxlen]->content != NULL)
819 update_idx (menu, idx, idxlen++);
821 mutt_error _("Unable to attach!");
823 p_delete(&idx[idxlen]);
827 menu->redraw |= REDRAW_FULL;
829 if (closed == OP_QUIT)
830 mx_close_mailbox (Context, NULL);
832 mx_fastclose_mailbox (Context);
835 /* go back to the folder we started from */
837 /* Restore old $sort and $sort_aux */
839 SortAux = oldSortAux;
841 mutt_message_hook (NULL, msg, M_SEND2HOOK);
846 if (idx[menu->current]->unowned)
847 idx[menu->current]->content->unlink = 0;
848 if (delete_attachment (menu, &idxlen, menu->current) == -1)
850 mutt_update_tree (idx, idxlen);
852 if (menu->current > idxlen - 1)
853 menu->current = idxlen - 1;
858 if (menu->current == 0)
859 msg->content = idx[0]->content;
861 menu->redraw |= REDRAW_STATUS;
862 mutt_message_hook (NULL, msg, M_SEND2HOOK);
865 #define CURRENT idx[menu->current]->content
867 case OP_COMPOSE_TOGGLE_RECODE:
870 if (!mutt_is_text_part (CURRENT)) {
871 mutt_error (_("Recoding only affects text attachments."));
874 CURRENT->noconv = !CURRENT->noconv;
876 mutt_message (_("The current attachment won't be converted."));
878 mutt_message (_("The current attachment will be converted."));
879 menu->redraw = REDRAW_CURRENT;
880 mutt_message_hook (NULL, msg, M_SEND2HOOK);
885 case OP_COMPOSE_EDIT_DESCRIPTION:
887 m_strcpy(buf, sizeof(buf),
888 NONULL(idx[menu->current]->content->description));
889 /* header names should not be translated */
890 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
891 m_strreplace(&idx[menu->current]->content->description, buf);
892 menu->redraw = REDRAW_CURRENT;
894 mutt_message_hook (NULL, msg, M_SEND2HOOK);
897 case OP_COMPOSE_UPDATE_ENCODING:
899 if (menu->tagprefix) {
902 for (top = msg->content; top; top = top->next) {
904 mutt_update_encoding (top);
906 menu->redraw = REDRAW_FULL;
909 mutt_update_encoding (idx[menu->current]->content);
910 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
912 mutt_message_hook (NULL, msg, M_SEND2HOOK);
915 case OP_COMPOSE_TOGGLE_DISPOSITION:
916 /* toggle the content-disposition between inline/attachment */
917 idx[menu->current]->content->disposition =
918 (idx[menu->current]->content->disposition ==
919 DISPINLINE) ? DISPATTACH : DISPINLINE;
920 menu->redraw = REDRAW_CURRENT;
926 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
928 /* this may have been a change to text/something */
929 mutt_update_encoding (idx[menu->current]->content);
931 menu->redraw = REDRAW_CURRENT;
933 mutt_message_hook (NULL, msg, M_SEND2HOOK);
936 case OP_COMPOSE_EDIT_ENCODING:
938 m_strcpy(buf, sizeof(buf),
939 ENCODING(idx[menu->current]->content->encoding));
940 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
941 sizeof (buf), 0) == 0 && buf[0]) {
942 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
943 idx[menu->current]->content->encoding = i;
944 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
948 mutt_error _("Invalid encoding.");
950 mutt_message_hook (NULL, msg, M_SEND2HOOK);
953 case OP_COMPOSE_SEND_MESSAGE:
955 /* Note: We don't invoke send2-hook here, since we want to leave
956 * users an opportunity to change settings from the ":" prompt.
959 if (check_attachments (idx, idxlen) != 0) {
960 menu->redraw = REDRAW_FULL;
964 if (msg->chain && mix_check_message (msg) != 0)
967 if (!fccSet && *fcc) {
968 if ((i = query_quadoption (OPT_COPY,
969 _("Save a copy of this message?"))) == -1)
979 case OP_COMPOSE_EDIT_FILE:
981 mutt_edit_file(idx[menu->current]->content->filename);
982 mutt_update_encoding (idx[menu->current]->content);
983 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
984 mutt_message_hook (NULL, msg, M_SEND2HOOK);
987 case OP_COMPOSE_TOGGLE_UNLINK:
989 idx[menu->current]->content->unlink =
990 !idx[menu->current]->content->unlink;
992 menu->redraw = REDRAW_INDEX;
993 /* No send2hook since this doesn't change the message. */
996 case OP_COMPOSE_GET_ATTACHMENT:
998 if (menu->tagprefix) {
1001 for (top = msg->content; top; top = top->next) {
1003 mutt_get_tmp_attachment (top);
1005 menu->redraw = REDRAW_FULL;
1007 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1008 menu->redraw = REDRAW_CURRENT;
1010 /* No send2hook since this doesn't change the message. */
1013 case OP_COMPOSE_RENAME_FILE:
1015 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
1016 mutt_pretty_mailbox (fname);
1017 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1019 if (stat (idx[menu->current]->content->filename, &st) == -1) {
1020 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1024 mutt_expand_path (fname, sizeof (fname));
1025 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1028 m_strreplace(&idx[menu->current]->content->filename, fname);
1029 menu->redraw = REDRAW_CURRENT;
1031 if (idx[menu->current]->content->stamp >= st.st_mtime)
1032 mutt_stamp_attachment (idx[menu->current]->content);
1035 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1038 case OP_COMPOSE_NEW_MIME:
1045 CLEARLINE (LINES - 1);
1047 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1050 mutt_expand_path (fname, sizeof (fname));
1052 /* Call to lookup_mime_type () ? maybe later */
1054 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1058 if (!(p = strchr (type, '/'))) {
1059 mutt_error _("Content-Type is of the form base/sub");
1064 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1065 mutt_error (_("Unknown Content-Type %s"), type);
1068 if (idxlen == idxmax) {
1069 p_realloc(&idx, idxmax += 5);
1073 idx[idxlen] = p_new(ATTACHPTR, 1);
1074 /* Touch the file */
1075 if (!(fp = safe_fopen (fname, "w"))) {
1076 mutt_error (_("Can't create file %s"), fname);
1077 p_delete(&idx[idxlen]);
1082 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1084 _("What we have here is a failure to make an attachment");
1087 update_idx (menu, idx, idxlen++);
1089 idx[menu->current]->content->type = itype;
1090 m_strreplace(&idx[menu->current]->content->subtype, p);
1091 idx[menu->current]->content->unlink = 1;
1092 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1094 if (mutt_compose_attachment (idx[menu->current]->content)) {
1095 mutt_update_encoding (idx[menu->current]->content);
1096 menu->redraw = REDRAW_FULL;
1099 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1102 case OP_COMPOSE_EDIT_MIME:
1104 if (mutt_edit_attachment (idx[menu->current]->content)) {
1105 mutt_update_encoding (idx[menu->current]->content);
1106 menu->redraw = REDRAW_FULL;
1108 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1111 case OP_VIEW_ATTACH:
1112 case OP_DISPLAY_HEADERS:
1114 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1116 menu->redraw = REDRAW_FULL;
1117 /* no send2hook, since this doesn't modify the message */
1122 mutt_save_attachment_list (NULL, menu->tagprefix,
1123 menu->tagprefix ? msg->content : idx[menu->
1125 content, NULL, menu);
1126 MAYBE_REDRAW (menu->redraw);
1127 /* no send2hook, since this doesn't modify the message */
1132 mutt_print_attachment_list (NULL, menu->tagprefix,
1133 menu->tagprefix ? msg->content : idx[menu->
1136 /* no send2hook, since this doesn't modify the message */
1142 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1143 menu->tagprefix ? msg->content : idx[menu->
1145 content, op == OP_FILTER);
1146 if (op == OP_FILTER) /* cte might have changed */
1147 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1148 menu->redraw |= REDRAW_STATUS;
1149 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1154 query_quadoption (OPT_POSTPONE,
1155 _("Postpone this message?"))) == M_NO) {
1156 while (idxlen-- > 0) {
1157 /* avoid freeing other attachments */
1158 idx[idxlen]->content->next = NULL;
1159 idx[idxlen]->content->parts = NULL;
1160 if (idx[idxlen]->unowned)
1161 idx[idxlen]->content->unlink = 0;
1162 body_list_wipe(&idx[idxlen]->content);
1163 p_delete(&idx[idxlen]->tree);
1164 p_delete(&idx[idxlen]);
1176 /* fall through to postpone! */
1178 case OP_COMPOSE_POSTPONE_MESSAGE:
1180 if (check_attachments (idx, idxlen) != 0) {
1181 menu->redraw = REDRAW_FULL;
1189 case OP_COMPOSE_WRITE_MESSAGE:
1192 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
1193 mutt_pretty_mailbox (fname);
1196 msg->content = idx[0]->content;
1197 if (mutt_enter_fname
1198 (_("Write message to mailbox"), fname, sizeof (fname),
1199 &menu->redraw, 1) != -1 && fname[0]) {
1200 mutt_message (_("Writing message to %s ..."), fname);
1201 mutt_expand_path (fname, sizeof (fname));
1203 if (msg->content->next)
1204 msg->content = mutt_make_multipart (msg->content);
1206 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1207 msg->content = mutt_remove_multipart (msg->content);
1209 mutt_message _("Message written.");
1213 case OP_COMPOSE_PGP_MENU:
1214 if (msg->security & APPLICATION_SMIME) {
1215 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1217 mutt_clear_error ();
1222 msg->security = crypt_send_menu (msg, &menu->redraw, 0);
1223 redraw_crypt_lines (msg);
1224 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1227 case OP_COMPOSE_SMIME_MENU:
1228 if (msg->security & APPLICATION_PGP) {
1229 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1231 mutt_clear_error ();
1236 msg->security = crypt_send_menu(msg, &menu->redraw, 1);
1237 redraw_crypt_lines (msg);
1238 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1241 case OP_COMPOSE_MIX:
1242 mix_make_chain (&msg->chain, &menu->redraw);
1243 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1247 /* Draw formated compose status line */
1248 if (menu->redraw & REDRAW_STATUS) {
1249 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1250 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1251 SETCOLOR (MT_COLOR_STATUS);
1252 move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
1253 printw ("%-*.*s", COLS-SW, COLS-SW, buf);
1254 SETCOLOR (MT_COLOR_NORMAL);
1255 menu->redraw &= ~REDRAW_STATUS;
1259 mutt_menuDestroy (&menu);
1262 msg->content = idx[0]->content;
1263 for (i = 0; i < idxlen; i++) {
1264 idx[i]->content->aptr = NULL;
1268 msg->content = NULL;