2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4 * Copyright (C) 2004 g10 Code GmbH
6 * Parts were written/modified by:
7 * Nico Golde <nico@ngolde.de>
9 * This file is part of mutt-ng, see http://www.muttng.org/.
10 * It's licensed under the GNU General Public License,
11 * please see the file GPL in the top level source directory.
18 #include <lib-lib/mem.h>
19 #include <lib-lib/str.h>
20 #include <lib-lib/macros.h>
21 #include <lib-lib/file.h>
22 #include <lib-lib/mapping.h>
24 #include <lib-mime/mime.h>
28 #include "mutt_curses.h"
29 #include "mutt_idna.h"
30 #include "mutt_menu.h"
33 #include "recvattach.h"
56 static const char *There_are_no_attachments = N_("There are no attachments.");
58 #define CHECK_COUNT if (idxlen == 0) { mutt_error _(There_are_no_attachments); break; }
85 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
87 HDR_ATTACH = (HDR_FCC + 7)
91 #define HDR_XOFFSET 14
92 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
93 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
94 #define W (COLS - HDR_XOFFSET - SW)
96 static const char *Prompts[] = {
108 , "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: "
112 static struct mapping_t ComposeHelp[] = {
113 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
114 {N_("Abort"), OP_EXIT},
115 {"To", OP_COMPOSE_EDIT_TO},
116 {"CC", OP_COMPOSE_EDIT_CC},
117 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
118 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
119 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
120 {N_("Help"), OP_HELP},
125 static struct mapping_t ComposeNewsHelp[] = {
126 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
127 {N_("Abort"), OP_EXIT},
128 {"Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS},
129 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
130 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
131 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
132 {N_("Help"), OP_HELP},
138 static void snd_entry (char *b, ssize_t blen, MUTTMENU * menu, int num) {
139 int w=(COLS-SW)>blen?blen:COLS-SW;
140 mutt_FormatString (b, w, NONULL (AttachFormat), mutt_attach_fmt,
141 (unsigned long) (((ATTACHPTR **) menu->data)[num]),
142 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
145 #include "mutt_crypt.h"
147 static void redraw_crypt_lines (HEADER * msg)
152 mvaddstr (HDR_CRYPT, SW, " Security: ");
153 else if (msg->security & APPLICATION_SMIME)
154 mvaddstr (HDR_CRYPT, SW, " S/MIME: ");
155 else if (msg->security & APPLICATION_PGP)
156 mvaddstr (HDR_CRYPT, SW, " PGP: ");
158 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
159 addstr (_("Sign, Encrypt"));
160 else if (msg->security & ENCRYPT)
161 addstr (_("Encrypt"));
162 else if (msg->security & SIGN)
167 if ((msg->security & APPLICATION_PGP)
168 && (msg->security & (ENCRYPT | SIGN))) {
169 if ((msg->security & INLINE))
170 addstr (_(" (inline)"));
172 addstr (_(" (PGP/MIME)"));
176 move (HDR_CRYPTINFO, SW);
178 if (msg->security & APPLICATION_PGP && msg->security & SIGN)
179 printw ("%s%s", _(" sign as: "),
180 PgpSignAs ? PgpSignAs : _("<default>"));
182 if (msg->security & APPLICATION_SMIME && msg->security & SIGN) {
183 printw ("%s%s", _(" sign as: "),
184 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
187 if ((msg->security & APPLICATION_SMIME)
188 && (msg->security & ENCRYPT)
189 && SmimeCryptAlg && *SmimeCryptAlg) {
190 mvprintw (HDR_CRYPTINFO, SW + 40, "%s%s", _("Encrypt with: "),
191 NONULL (SmimeCryptAlg));
199 static void redraw_mix_line (LIST * chain)
204 mvaddstr (HDR_MIX, SW, " Mix: ");
207 addstr ("<no chain defined>");
212 for (c = 12; chain; chain = chain->next) {
214 if (t && t[0] == '0' && t[1] == '\0')
217 if (c + m_strlen(t) + 2 >= COLS - SW)
224 c += m_strlen(t) + 2;
227 #endif /* MIXMASTER */
229 static int check_attachments (ATTACHPTR ** idx, short idxlen)
233 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
235 for (i = 0; i < idxlen; i++) {
236 m_strcpy(pretty, sizeof(pretty), idx[i]->content->filename);
237 if (stat (idx[i]->content->filename, &st) != 0) {
238 mutt_pretty_mailbox (pretty);
239 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
243 if (idx[i]->content->stamp < st.st_mtime) {
244 mutt_pretty_mailbox (pretty);
245 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
248 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
249 mutt_update_encoding (idx[i]->content);
258 static void draw_envelope_addr (int line, address_t * addr)
263 rfc822_write_address (buf, sizeof (buf), addr, 1);
264 mvprintw (line, SW, TITLE_FMT, Prompts[line - 1]);
265 mutt_paddstr (W, buf);
268 static void draw_envelope (HEADER * msg, char *fcc)
270 draw_envelope_addr (HDR_FROM, msg->env->from);
272 if (!option (OPTNEWSSEND)) {
274 draw_envelope_addr (HDR_TO, msg->env->to);
275 draw_envelope_addr (HDR_CC, msg->env->cc);
276 draw_envelope_addr (HDR_BCC, msg->env->bcc);
280 mvprintw (HDR_TO, SW, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
281 mutt_paddstr (W, NONULL (msg->env->newsgroups));
282 mvprintw (HDR_CC, SW, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
283 mutt_paddstr (W, NONULL (msg->env->followup_to));
284 if (option (OPTXCOMMENTTO)) {
285 mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]);
286 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
290 mvprintw (HDR_SUBJECT, SW, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
291 mutt_paddstr (W, NONULL (msg->env->subject));
292 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
293 mvprintw (HDR_FCC, SW, TITLE_FMT, Prompts[HDR_FCC - 1]);
294 mutt_paddstr (W, fcc);
296 redraw_crypt_lines (msg);
299 redraw_mix_line (msg->chain);
302 SETCOLOR (MT_COLOR_STATUS);
303 mvaddstr (HDR_ATTACH - 1, SW, _("-- Attachments"));
304 BKGDSET (MT_COLOR_STATUS);
307 BKGDSET (MT_COLOR_NORMAL);
308 SETCOLOR (MT_COLOR_NORMAL);
311 static int edit_address_list (int line, address_t ** addr)
313 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
316 mutt_addrlist_to_local (*addr);
317 rfc822_write_address (buf, sizeof (buf), *addr, 0);
318 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
319 address_delete (addr);
320 *addr = mutt_parse_adrlist (*addr, buf);
321 *addr = mutt_expand_aliases (*addr);
324 if (option (OPTNEEDREDRAW)) {
325 unset_option (OPTNEEDREDRAW);
326 return (REDRAW_FULL);
329 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
330 mutt_error (_("Warning: '%s' is a bad IDN."), err);
335 /* redraw the expanded list so the user can see the result */
337 rfc822_write_address (buf, sizeof (buf), *addr, 1);
338 move (line, HDR_XOFFSET + SW);
339 mutt_paddstr (W, buf);
344 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
346 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
349 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
351 if (x == 0 && menu->max == 1) {
352 mutt_error _("You may not delete the only attachment.");
354 idx[x]->content->tagged = 0;
358 for (y = 0; y < *idxlen; y++) {
359 if (idx[y]->content->next == idx[x]->content) {
360 idx[y]->content->next = idx[x]->content->next;
365 idx[x]->content->next = NULL;
366 idx[x]->content->parts = NULL;
367 mutt_free_body (&(idx[x]->content));
368 p_delete(&idx[x]->tree);
370 for (; x < *idxlen - 1; x++)
372 menu->max = --(*idxlen);
377 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
379 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
381 idx[idxlen - 1]->content->next = idx[idxlen]->content;
382 idx[idxlen]->content->aptr = idx[idxlen];
383 menu->current = idxlen++;
384 mutt_update_tree (idx, idxlen);
391 * cum_attachs_size: Cumulative Attachments Size
393 * Returns the total number of bytes used by the attachments in the
394 * attachment list _after_ content-transfer-encodings have been
399 static unsigned long cum_attachs_size (MUTTMENU * menu)
403 ATTACHPTR **idx = menu->data;
407 for (i = 0, s = 0; i < menu->max; i++) {
411 b->content = mutt_get_content_info (b->filename, b);
413 if ((info = b->content)) {
414 switch (b->encoding) {
415 case ENCQUOTEDPRINTABLE:
416 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
419 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
422 s += info->lobin + info->hibin + info->ascii + info->crlf;
432 * compose_format_str()
434 * %a = total number of attachments
435 * %h = hostname [option]
436 * %l = approx. length of current message (in bytes)
439 * This function is similar to status_format_str(). Look at that function for
440 * help when modifying this function.
443 static const char *compose_format_str (char *buf, size_t buflen, char op,
444 const char *src, const char *prefix,
445 const char *ifstring,
446 const char *elsestring,
447 unsigned long data, format_flag flags)
449 char fmt[SHORT_STRING], tmp[SHORT_STRING];
450 int optional = (flags & M_FORMAT_OPTIONAL);
451 MUTTMENU *menu = (MUTTMENU *) data;
455 case 'a': /* total number of attachments */
456 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
457 snprintf (buf, buflen, fmt, menu->max);
460 case 'h': /* hostname */
461 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
462 snprintf (buf, buflen, fmt, NONULL (Hostname));
465 case 'l': /* approx length of current message in bytes */
466 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
467 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
468 snprintf (buf, buflen, fmt, tmp);
472 m_strcpy(buf, buflen, mutt_make_version (0));
480 snprintf (buf, buflen, "%%%s%c", prefix, op);
485 compose_status_line (buf, buflen, menu, ifstring);
486 else if (flags & M_FORMAT_OPTIONAL)
487 compose_status_line (buf, buflen, menu, elsestring);
492 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
495 int w=(COLS-SW)>buflen?buflen:(COLS-SW);
496 mutt_FormatString (buf, w, p, compose_format_str,
497 (unsigned long) menu, 0);
503 * 1 message should be postponed
507 int mutt_compose_menu (HEADER * msg, /* structure for new message */
508 char *fcc, /* where to save a copy of the message */
509 size_t fcclen, HEADER * cur)
510 { /* current message */
511 char helpstr[SHORT_STRING];
512 char buf[LONG_STRING];
513 char fname[_POSIX_PATH_MAX];
515 ATTACHPTR **idx = NULL;
519 int r = -1; /* return value */
522 int fccSet = 0; /* has the user edited the Fcc: field ? */
523 CONTEXT *ctx = NULL, *this = NULL;
525 /* Sort, SortAux could be changed in mutt_index_menu() */
526 int oldSort, oldSortAux;
530 int news = 0; /* is it a news article ? */
532 if (option (OPTNEWSSEND))
536 mutt_attach_init (msg->content);
537 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
539 menu = mutt_new_menu ();
540 menu->menu = MENU_COMPOSE;
541 menu->offset = HDR_ATTACH;
543 menu->make_entry = snd_entry;
544 menu->tag = mutt_tag_attach;
549 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
554 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
557 if (option (OPTMBOXPANE))
561 unset_option (OPTNEWS); /* for any case */
563 switch (op = mutt_menuLoop (menu)) {
565 draw_envelope (msg, fcc);
566 menu->offset = HDR_ATTACH;
567 menu->pagelen = LINES - HDR_ATTACH - 2;
569 case OP_COMPOSE_EDIT_FROM:
570 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
571 mutt_message_hook (NULL, msg, M_SEND2HOOK);
573 case OP_COMPOSE_EDIT_TO:
577 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
578 mutt_message_hook (NULL, msg, M_SEND2HOOK);
583 case OP_COMPOSE_EDIT_BCC:
587 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
588 mutt_message_hook (NULL, msg, M_SEND2HOOK);
593 case OP_COMPOSE_EDIT_CC:
597 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
598 mutt_message_hook (NULL, msg, M_SEND2HOOK);
604 case OP_COMPOSE_EDIT_NEWSGROUPS:
606 if (msg->env->newsgroups)
607 m_strcpy(buf, sizeof(buf), msg->env->newsgroups);
610 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
612 p_delete(&msg->env->newsgroups);
614 msg->env->newsgroups = m_strdup(skipspaces(buf));
615 move (HDR_TO, HDR_XOFFSET);
617 if (msg->env->newsgroups)
618 printw ("%-*.*s", W, W, msg->env->newsgroups);
623 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
626 if (msg->env->followup_to)
627 m_strcpy(buf, sizeof(buf), msg->env->followup_to);
628 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
630 p_delete(&msg->env->followup_to);
632 msg->env->followup_to = m_strdup(skipspaces(buf));
633 move (HDR_CC, HDR_XOFFSET);
635 if (msg->env->followup_to)
636 printw ("%-*.*s", W, W, msg->env->followup_to);
641 case OP_COMPOSE_EDIT_X_COMMENT_TO:
642 if (news && option (OPTXCOMMENTTO)) {
644 if (msg->env->x_comment_to)
645 m_strcpy(buf, sizeof(buf), msg->env->x_comment_to);
646 if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
648 p_delete(&msg->env->x_comment_to);
649 msg->env->x_comment_to = m_strdup(buf);
650 move (HDR_BCC, HDR_XOFFSET);
652 if (msg->env->x_comment_to)
653 printw ("%-*.*s", W, W, msg->env->x_comment_to);
658 case OP_COMPOSE_EDIT_SUBJECT:
659 if (msg->env->subject)
660 m_strcpy(buf, sizeof(buf), msg->env->subject);
663 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
664 m_strreplace(&msg->env->subject, buf);
665 move (HDR_SUBJECT, HDR_XOFFSET + SW);
667 if (msg->env->subject)
668 mutt_paddstr (W, msg->env->subject);
670 mutt_message_hook (NULL, msg, M_SEND2HOOK);
672 case OP_COMPOSE_EDIT_REPLY_TO:
673 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
674 mutt_message_hook (NULL, msg, M_SEND2HOOK);
676 case OP_COMPOSE_EDIT_FCC:
677 m_strcpy(buf, sizeof(buf), fcc);
678 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
679 m_strcpy(fcc, _POSIX_PATH_MAX, buf);
680 mutt_pretty_mailbox (fcc);
681 move (HDR_FCC, HDR_XOFFSET + SW);
682 mutt_paddstr (W, fcc);
685 MAYBE_REDRAW (menu->redraw);
686 mutt_message_hook (NULL, msg, M_SEND2HOOK);
688 case OP_COMPOSE_EDIT_MESSAGE:
689 if (Editor && (m_strcmp("builtin", Editor) != 0)
690 && !option (OPTEDITHDRS)) {
691 mutt_edit_file (Editor, msg->content->filename);
692 mutt_update_encoding (msg->content);
693 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
694 mutt_message_hook (NULL, msg, M_SEND2HOOK);
698 case OP_COMPOSE_EDIT_HEADERS:
699 if (m_strcmp("builtin", Editor) != 0 &&
700 (op == OP_COMPOSE_EDIT_HEADERS ||
701 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
702 const char *tag = NULL;
703 const char *err = NULL;
705 mutt_env_to_local (msg->env);
706 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
708 if (mutt_env_to_idna (msg->env, &tag, &err)) {
709 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
714 /* this is grouped with OP_COMPOSE_EDIT_HEADERS because the
715 attachment list could change if the user invokes ~v to edit
716 the message with headers, in which we need to execute the
717 code below to regenerate the index array */
718 mutt_builtin_editor (msg->content->filename, msg, cur);
720 mutt_update_encoding (msg->content);
722 /* attachments may have been added */
723 if (idxlen && idx[idxlen - 1]->content->next) {
724 for (i = 0; i < idxlen; i++)
728 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
734 menu->redraw = REDRAW_FULL;
735 mutt_message_hook (NULL, msg, M_SEND2HOOK);
740 case OP_COMPOSE_ATTACH_KEY:
741 if (idxlen == idxmax) {
742 p_realloc(&idx, idxmax += 5);
746 idx[idxlen] = p_new(ATTACHPTR, 1);
747 if ((idx[idxlen]->content =
748 crypt_pgp_make_key_attachment (NULL)) != NULL) {
749 update_idx (menu, idx, idxlen++);
750 menu->redraw |= REDRAW_INDEX;
753 p_delete(&idx[idxlen]);
755 menu->redraw |= REDRAW_STATUS;
757 if (option (OPTNEEDREDRAW)) {
758 menu->redraw = REDRAW_FULL;
759 unset_option (OPTNEEDREDRAW);
762 mutt_message_hook (NULL, msg, M_SEND2HOOK);
766 case OP_COMPOSE_ATTACH_FILE:
768 char *prompt, **files;
772 prompt = _("Attach file");
776 if (_mutt_enter_fname
777 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
778 &numfiles) == -1 || *fname == '\0')
781 if (idxlen + numfiles >= idxmax) {
782 p_realloc(&idx, idxmax += 5 + numfiles);
788 mutt_message _("Attaching selected files...");
790 for (i = 0; i < numfiles; i++) {
791 char *att = files[i];
793 idx[idxlen] = p_new(ATTACHPTR, 1);
794 idx[idxlen]->unowned = 1;
795 idx[idxlen]->content = mutt_make_file_attach (att);
796 if (idx[idxlen]->content != NULL)
797 update_idx (menu, idx, idxlen++);
800 mutt_error (_("Unable to attach %s!"), att);
801 p_delete(&idx[idxlen]);
809 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
811 mutt_message_hook (NULL, msg, M_SEND2HOOK);
814 case OP_COMPOSE_ATTACH_MESSAGE:
816 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
823 prompt = _("Open mailbox to attach message from");
826 unset_option (OPTNEWS);
827 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
828 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
831 prompt = _("Open newsgroup to attach message from");
832 set_option (OPTNEWS);
838 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
841 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
842 mutt_pretty_mailbox (fname);
845 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
850 if (option (OPTNEWS))
851 nntp_expand_path (fname, sizeof (fname),
852 &CurrentNewsSrv->conn->account);
855 mutt_expand_path (fname, sizeof (fname));
857 if (mx_get_magic (fname) != M_IMAP)
860 if (mx_get_magic (fname) != M_POP)
863 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
865 /* check to make sure the file exists and is readable */
866 if (access (fname, R_OK) == -1) {
871 menu->redraw = REDRAW_FULL;
873 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
879 if (!ctx->msgcount) {
880 mx_close_mailbox (ctx, NULL);
882 mutt_error _("No messages in that folder.");
887 this = Context; /* remember current folder and sort methods */
889 oldSortAux = SortAux;
892 set_option (OPTATTACHMSG);
893 mutt_message _("Tag the messages you want to attach!");
895 closed = mutt_index_menu ();
896 unset_option (OPTATTACHMSG);
899 /* go back to the folder we started from */
901 /* Restore old $sort and $sort_aux */
903 SortAux = oldSortAux;
904 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
908 if (idxlen + Context->tagged >= idxmax) {
909 p_realloc(&idx, idxmax += 5 + Context->tagged);
913 for (i = 0; i < Context->msgcount; i++) {
914 h = Context->hdrs[i];
916 idx[idxlen] = p_new(ATTACHPTR, 1);
917 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
918 if (idx[idxlen]->content != NULL)
919 update_idx (menu, idx, idxlen++);
921 mutt_error _("Unable to attach!");
923 p_delete(&idx[idxlen]);
927 menu->redraw |= REDRAW_FULL;
929 if (closed == OP_QUIT)
930 mx_close_mailbox (Context, NULL);
932 mx_fastclose_mailbox (Context);
935 /* go back to the folder we started from */
937 /* Restore old $sort and $sort_aux */
939 SortAux = oldSortAux;
941 mutt_message_hook (NULL, msg, M_SEND2HOOK);
946 if (idx[menu->current]->unowned)
947 idx[menu->current]->content->unlink = 0;
948 if (delete_attachment (menu, &idxlen, menu->current) == -1)
950 mutt_update_tree (idx, idxlen);
952 if (menu->current > idxlen - 1)
953 menu->current = idxlen - 1;
958 if (menu->current == 0)
959 msg->content = idx[0]->content;
961 menu->redraw |= REDRAW_STATUS;
962 mutt_message_hook (NULL, msg, M_SEND2HOOK);
965 #define CURRENT idx[menu->current]->content
967 case OP_COMPOSE_TOGGLE_RECODE:
970 if (!mutt_is_text_part (CURRENT)) {
971 mutt_error (_("Recoding only affects text attachments."));
974 CURRENT->noconv = !CURRENT->noconv;
976 mutt_message (_("The current attachment won't be converted."));
978 mutt_message (_("The current attachment will be converted."));
979 menu->redraw = REDRAW_CURRENT;
980 mutt_message_hook (NULL, msg, M_SEND2HOOK);
985 case OP_COMPOSE_EDIT_DESCRIPTION:
987 m_strcpy(buf, sizeof(buf),
988 NONULL(idx[menu->current]->content->description));
989 /* header names should not be translated */
990 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
991 m_strreplace(&idx[menu->current]->content->description, buf);
992 menu->redraw = REDRAW_CURRENT;
994 mutt_message_hook (NULL, msg, M_SEND2HOOK);
997 case OP_COMPOSE_UPDATE_ENCODING:
999 if (menu->tagprefix) {
1002 for (top = msg->content; top; top = top->next) {
1004 mutt_update_encoding (top);
1006 menu->redraw = REDRAW_FULL;
1009 mutt_update_encoding (idx[menu->current]->content);
1010 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1012 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1015 case OP_COMPOSE_TOGGLE_DISPOSITION:
1016 /* toggle the content-disposition between inline/attachment */
1017 idx[menu->current]->content->disposition =
1018 (idx[menu->current]->content->disposition ==
1019 DISPINLINE) ? DISPATTACH : DISPINLINE;
1020 menu->redraw = REDRAW_CURRENT;
1026 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
1028 /* this may have been a change to text/something */
1029 mutt_update_encoding (idx[menu->current]->content);
1031 menu->redraw = REDRAW_CURRENT;
1033 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1036 case OP_COMPOSE_EDIT_ENCODING:
1038 m_strcpy(buf, sizeof(buf),
1039 ENCODING(idx[menu->current]->content->encoding));
1040 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
1041 sizeof (buf), 0) == 0 && buf[0]) {
1042 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
1043 idx[menu->current]->content->encoding = i;
1044 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1045 mutt_clear_error ();
1048 mutt_error _("Invalid encoding.");
1050 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1053 case OP_COMPOSE_SEND_MESSAGE:
1055 /* Note: We don't invoke send2-hook here, since we want to leave
1056 * users an opportunity to change settings from the ":" prompt.
1059 if (check_attachments (idx, idxlen) != 0) {
1060 menu->redraw = REDRAW_FULL;
1066 if (msg->chain && mix_check_message (msg) != 0)
1070 if (!fccSet && *fcc) {
1071 if ((i = query_quadoption (OPT_COPY,
1072 _("Save a copy of this message?"))) == -1)
1082 case OP_COMPOSE_EDIT_FILE:
1084 mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename);
1085 mutt_update_encoding (idx[menu->current]->content);
1086 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1087 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1090 case OP_COMPOSE_TOGGLE_UNLINK:
1092 idx[menu->current]->content->unlink =
1093 !idx[menu->current]->content->unlink;
1096 /* OPTRESOLVE is otherwise ignored on this menu.
1100 if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
1103 menu->redraw = REDRAW_INDEX;
1104 /* No send2hook since this doesn't change the message. */
1107 case OP_COMPOSE_GET_ATTACHMENT:
1109 if (menu->tagprefix) {
1112 for (top = msg->content; top; top = top->next) {
1114 mutt_get_tmp_attachment (top);
1116 menu->redraw = REDRAW_FULL;
1118 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1119 menu->redraw = REDRAW_CURRENT;
1121 /* No send2hook since this doesn't change the message. */
1124 case OP_COMPOSE_RENAME_FILE:
1126 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
1127 mutt_pretty_mailbox (fname);
1128 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1130 if (stat (idx[menu->current]->content->filename, &st) == -1) {
1131 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1135 mutt_expand_path (fname, sizeof (fname));
1136 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1139 m_strreplace(&idx[menu->current]->content->filename, fname);
1140 menu->redraw = REDRAW_CURRENT;
1142 if (idx[menu->current]->content->stamp >= st.st_mtime)
1143 mutt_stamp_attachment (idx[menu->current]->content);
1146 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1149 case OP_COMPOSE_NEW_MIME:
1156 CLEARLINE (LINES - 1);
1158 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1161 mutt_expand_path (fname, sizeof (fname));
1163 /* Call to lookup_mime_type () ? maybe later */
1165 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1169 if (!(p = strchr (type, '/'))) {
1170 mutt_error _("Content-Type is of the form base/sub");
1175 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1176 mutt_error (_("Unknown Content-Type %s"), type);
1179 if (idxlen == idxmax) {
1180 p_realloc(&idx, idxmax += 5);
1184 idx[idxlen] = p_new(ATTACHPTR, 1);
1185 /* Touch the file */
1186 if (!(fp = safe_fopen (fname, "w"))) {
1187 mutt_error (_("Can't create file %s"), fname);
1188 p_delete(&idx[idxlen]);
1193 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1195 _("What we have here is a failure to make an attachment");
1198 update_idx (menu, idx, idxlen++);
1200 idx[menu->current]->content->type = itype;
1201 m_strreplace(&idx[menu->current]->content->subtype, p);
1202 idx[menu->current]->content->unlink = 1;
1203 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1205 if (mutt_compose_attachment (idx[menu->current]->content)) {
1206 mutt_update_encoding (idx[menu->current]->content);
1207 menu->redraw = REDRAW_FULL;
1210 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1213 case OP_COMPOSE_EDIT_MIME:
1215 if (mutt_edit_attachment (idx[menu->current]->content)) {
1216 mutt_update_encoding (idx[menu->current]->content);
1217 menu->redraw = REDRAW_FULL;
1219 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1222 case OP_VIEW_ATTACH:
1223 case OP_DISPLAY_HEADERS:
1225 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1227 menu->redraw = REDRAW_FULL;
1228 /* no send2hook, since this doesn't modify the message */
1233 mutt_save_attachment_list (NULL, menu->tagprefix,
1234 menu->tagprefix ? msg->content : idx[menu->
1236 content, NULL, menu);
1237 MAYBE_REDRAW (menu->redraw);
1238 /* no send2hook, since this doesn't modify the message */
1243 mutt_print_attachment_list (NULL, menu->tagprefix,
1244 menu->tagprefix ? msg->content : idx[menu->
1247 /* no send2hook, since this doesn't modify the message */
1253 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1254 menu->tagprefix ? msg->content : idx[menu->
1256 content, op == OP_FILTER);
1257 if (op == OP_FILTER) /* cte might have changed */
1258 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1259 menu->redraw |= REDRAW_STATUS;
1260 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1265 query_quadoption (OPT_POSTPONE,
1266 _("Postpone this message?"))) == M_NO) {
1267 while (idxlen-- > 0) {
1268 /* avoid freeing other attachments */
1269 idx[idxlen]->content->next = NULL;
1270 idx[idxlen]->content->parts = NULL;
1271 if (idx[idxlen]->unowned)
1272 idx[idxlen]->content->unlink = 0;
1273 mutt_free_body (&idx[idxlen]->content);
1274 p_delete(&idx[idxlen]->tree);
1275 p_delete(&idx[idxlen]);
1287 /* fall through to postpone! */
1289 case OP_COMPOSE_POSTPONE_MESSAGE:
1291 if (check_attachments (idx, idxlen) != 0) {
1292 menu->redraw = REDRAW_FULL;
1300 case OP_COMPOSE_ISPELL:
1302 snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1303 msg->content->filename);
1304 if (mutt_system (buf) == -1)
1305 mutt_error (_("Error running \"%s\"!"), buf);
1307 mutt_update_encoding (msg->content);
1308 menu->redraw |= REDRAW_STATUS;
1312 case OP_COMPOSE_WRITE_MESSAGE:
1316 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
1317 mutt_pretty_mailbox (fname);
1320 msg->content = idx[0]->content;
1321 if (mutt_enter_fname
1322 (_("Write message to mailbox"), fname, sizeof (fname),
1323 &menu->redraw, 1) != -1 && fname[0]) {
1324 mutt_message (_("Writing message to %s ..."), fname);
1325 mutt_expand_path (fname, sizeof (fname));
1327 if (msg->content->next)
1328 msg->content = mutt_make_multipart (msg->content);
1330 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1331 msg->content = mutt_remove_multipart (msg->content);
1333 mutt_message _("Message written.");
1339 case OP_COMPOSE_PGP_MENU:
1340 if (msg->security & APPLICATION_SMIME) {
1341 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1343 mutt_clear_error ();
1348 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1349 redraw_crypt_lines (msg);
1350 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1354 case OP_FORGET_PASSPHRASE:
1355 crypt_forget_passphrase ();
1359 case OP_COMPOSE_SMIME_MENU:
1360 if (msg->security & APPLICATION_PGP) {
1361 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1363 mutt_clear_error ();
1368 msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1369 redraw_crypt_lines (msg);
1370 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1375 case OP_COMPOSE_MIX:
1377 mix_make_chain (&msg->chain, &menu->redraw);
1378 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1384 /* Draw formated compose status line */
1385 if (menu->redraw & REDRAW_STATUS) {
1386 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1387 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1388 SETCOLOR (MT_COLOR_STATUS);
1389 move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
1390 printw ("%-*.*s", COLS-SW, COLS-SW, buf);
1391 SETCOLOR (MT_COLOR_NORMAL);
1392 menu->redraw &= ~REDRAW_STATUS;
1396 mutt_menuDestroy (&menu);
1399 msg->content = idx[0]->content;
1400 for (i = 0; i < idxlen; i++) {
1401 idx[i]->content->aptr = NULL;
1406 msg->content = NULL;