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 <lib-crypt/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));
856 if (mx_get_magic (fname) != M_IMAP)
857 if (mx_get_magic (fname) != M_POP)
859 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
861 /* check to make sure the file exists and is readable */
862 if (access (fname, R_OK) == -1) {
867 menu->redraw = REDRAW_FULL;
869 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
875 if (!ctx->msgcount) {
876 mx_close_mailbox (ctx, NULL);
878 mutt_error _("No messages in that folder.");
883 this = Context; /* remember current folder and sort methods */
885 oldSortAux = SortAux;
888 set_option (OPTATTACHMSG);
889 mutt_message _("Tag the messages you want to attach!");
891 closed = mutt_index_menu ();
892 unset_option (OPTATTACHMSG);
895 /* go back to the folder we started from */
897 /* Restore old $sort and $sort_aux */
899 SortAux = oldSortAux;
900 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
904 if (idxlen + Context->tagged >= idxmax) {
905 p_realloc(&idx, idxmax += 5 + Context->tagged);
909 for (i = 0; i < Context->msgcount; i++) {
910 h = Context->hdrs[i];
912 idx[idxlen] = p_new(ATTACHPTR, 1);
913 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
914 if (idx[idxlen]->content != NULL)
915 update_idx (menu, idx, idxlen++);
917 mutt_error _("Unable to attach!");
919 p_delete(&idx[idxlen]);
923 menu->redraw |= REDRAW_FULL;
925 if (closed == OP_QUIT)
926 mx_close_mailbox (Context, NULL);
928 mx_fastclose_mailbox (Context);
931 /* go back to the folder we started from */
933 /* Restore old $sort and $sort_aux */
935 SortAux = oldSortAux;
937 mutt_message_hook (NULL, msg, M_SEND2HOOK);
942 if (idx[menu->current]->unowned)
943 idx[menu->current]->content->unlink = 0;
944 if (delete_attachment (menu, &idxlen, menu->current) == -1)
946 mutt_update_tree (idx, idxlen);
948 if (menu->current > idxlen - 1)
949 menu->current = idxlen - 1;
954 if (menu->current == 0)
955 msg->content = idx[0]->content;
957 menu->redraw |= REDRAW_STATUS;
958 mutt_message_hook (NULL, msg, M_SEND2HOOK);
961 #define CURRENT idx[menu->current]->content
963 case OP_COMPOSE_TOGGLE_RECODE:
966 if (!mutt_is_text_part (CURRENT)) {
967 mutt_error (_("Recoding only affects text attachments."));
970 CURRENT->noconv = !CURRENT->noconv;
972 mutt_message (_("The current attachment won't be converted."));
974 mutt_message (_("The current attachment will be converted."));
975 menu->redraw = REDRAW_CURRENT;
976 mutt_message_hook (NULL, msg, M_SEND2HOOK);
981 case OP_COMPOSE_EDIT_DESCRIPTION:
983 m_strcpy(buf, sizeof(buf),
984 NONULL(idx[menu->current]->content->description));
985 /* header names should not be translated */
986 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
987 m_strreplace(&idx[menu->current]->content->description, buf);
988 menu->redraw = REDRAW_CURRENT;
990 mutt_message_hook (NULL, msg, M_SEND2HOOK);
993 case OP_COMPOSE_UPDATE_ENCODING:
995 if (menu->tagprefix) {
998 for (top = msg->content; top; top = top->next) {
1000 mutt_update_encoding (top);
1002 menu->redraw = REDRAW_FULL;
1005 mutt_update_encoding (idx[menu->current]->content);
1006 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1008 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1011 case OP_COMPOSE_TOGGLE_DISPOSITION:
1012 /* toggle the content-disposition between inline/attachment */
1013 idx[menu->current]->content->disposition =
1014 (idx[menu->current]->content->disposition ==
1015 DISPINLINE) ? DISPATTACH : DISPINLINE;
1016 menu->redraw = REDRAW_CURRENT;
1022 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
1024 /* this may have been a change to text/something */
1025 mutt_update_encoding (idx[menu->current]->content);
1027 menu->redraw = REDRAW_CURRENT;
1029 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1032 case OP_COMPOSE_EDIT_ENCODING:
1034 m_strcpy(buf, sizeof(buf),
1035 ENCODING(idx[menu->current]->content->encoding));
1036 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
1037 sizeof (buf), 0) == 0 && buf[0]) {
1038 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
1039 idx[menu->current]->content->encoding = i;
1040 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1041 mutt_clear_error ();
1044 mutt_error _("Invalid encoding.");
1046 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1049 case OP_COMPOSE_SEND_MESSAGE:
1051 /* Note: We don't invoke send2-hook here, since we want to leave
1052 * users an opportunity to change settings from the ":" prompt.
1055 if (check_attachments (idx, idxlen) != 0) {
1056 menu->redraw = REDRAW_FULL;
1062 if (msg->chain && mix_check_message (msg) != 0)
1066 if (!fccSet && *fcc) {
1067 if ((i = query_quadoption (OPT_COPY,
1068 _("Save a copy of this message?"))) == -1)
1078 case OP_COMPOSE_EDIT_FILE:
1080 mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename);
1081 mutt_update_encoding (idx[menu->current]->content);
1082 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1083 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1086 case OP_COMPOSE_TOGGLE_UNLINK:
1088 idx[menu->current]->content->unlink =
1089 !idx[menu->current]->content->unlink;
1092 /* OPTRESOLVE is otherwise ignored on this menu.
1096 if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
1099 menu->redraw = REDRAW_INDEX;
1100 /* No send2hook since this doesn't change the message. */
1103 case OP_COMPOSE_GET_ATTACHMENT:
1105 if (menu->tagprefix) {
1108 for (top = msg->content; top; top = top->next) {
1110 mutt_get_tmp_attachment (top);
1112 menu->redraw = REDRAW_FULL;
1114 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1115 menu->redraw = REDRAW_CURRENT;
1117 /* No send2hook since this doesn't change the message. */
1120 case OP_COMPOSE_RENAME_FILE:
1122 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
1123 mutt_pretty_mailbox (fname);
1124 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1126 if (stat (idx[menu->current]->content->filename, &st) == -1) {
1127 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1131 mutt_expand_path (fname, sizeof (fname));
1132 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1135 m_strreplace(&idx[menu->current]->content->filename, fname);
1136 menu->redraw = REDRAW_CURRENT;
1138 if (idx[menu->current]->content->stamp >= st.st_mtime)
1139 mutt_stamp_attachment (idx[menu->current]->content);
1142 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1145 case OP_COMPOSE_NEW_MIME:
1152 CLEARLINE (LINES - 1);
1154 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1157 mutt_expand_path (fname, sizeof (fname));
1159 /* Call to lookup_mime_type () ? maybe later */
1161 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1165 if (!(p = strchr (type, '/'))) {
1166 mutt_error _("Content-Type is of the form base/sub");
1171 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1172 mutt_error (_("Unknown Content-Type %s"), type);
1175 if (idxlen == idxmax) {
1176 p_realloc(&idx, idxmax += 5);
1180 idx[idxlen] = p_new(ATTACHPTR, 1);
1181 /* Touch the file */
1182 if (!(fp = safe_fopen (fname, "w"))) {
1183 mutt_error (_("Can't create file %s"), fname);
1184 p_delete(&idx[idxlen]);
1189 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1191 _("What we have here is a failure to make an attachment");
1194 update_idx (menu, idx, idxlen++);
1196 idx[menu->current]->content->type = itype;
1197 m_strreplace(&idx[menu->current]->content->subtype, p);
1198 idx[menu->current]->content->unlink = 1;
1199 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1201 if (mutt_compose_attachment (idx[menu->current]->content)) {
1202 mutt_update_encoding (idx[menu->current]->content);
1203 menu->redraw = REDRAW_FULL;
1206 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1209 case OP_COMPOSE_EDIT_MIME:
1211 if (mutt_edit_attachment (idx[menu->current]->content)) {
1212 mutt_update_encoding (idx[menu->current]->content);
1213 menu->redraw = REDRAW_FULL;
1215 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1218 case OP_VIEW_ATTACH:
1219 case OP_DISPLAY_HEADERS:
1221 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1223 menu->redraw = REDRAW_FULL;
1224 /* no send2hook, since this doesn't modify the message */
1229 mutt_save_attachment_list (NULL, menu->tagprefix,
1230 menu->tagprefix ? msg->content : idx[menu->
1232 content, NULL, menu);
1233 MAYBE_REDRAW (menu->redraw);
1234 /* no send2hook, since this doesn't modify the message */
1239 mutt_print_attachment_list (NULL, menu->tagprefix,
1240 menu->tagprefix ? msg->content : idx[menu->
1243 /* no send2hook, since this doesn't modify the message */
1249 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1250 menu->tagprefix ? msg->content : idx[menu->
1252 content, op == OP_FILTER);
1253 if (op == OP_FILTER) /* cte might have changed */
1254 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1255 menu->redraw |= REDRAW_STATUS;
1256 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1261 query_quadoption (OPT_POSTPONE,
1262 _("Postpone this message?"))) == M_NO) {
1263 while (idxlen-- > 0) {
1264 /* avoid freeing other attachments */
1265 idx[idxlen]->content->next = NULL;
1266 idx[idxlen]->content->parts = NULL;
1267 if (idx[idxlen]->unowned)
1268 idx[idxlen]->content->unlink = 0;
1269 mutt_free_body (&idx[idxlen]->content);
1270 p_delete(&idx[idxlen]->tree);
1271 p_delete(&idx[idxlen]);
1283 /* fall through to postpone! */
1285 case OP_COMPOSE_POSTPONE_MESSAGE:
1287 if (check_attachments (idx, idxlen) != 0) {
1288 menu->redraw = REDRAW_FULL;
1296 case OP_COMPOSE_ISPELL:
1298 snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1299 msg->content->filename);
1300 if (mutt_system (buf) == -1)
1301 mutt_error (_("Error running \"%s\"!"), buf);
1303 mutt_update_encoding (msg->content);
1304 menu->redraw |= REDRAW_STATUS;
1308 case OP_COMPOSE_WRITE_MESSAGE:
1312 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
1313 mutt_pretty_mailbox (fname);
1316 msg->content = idx[0]->content;
1317 if (mutt_enter_fname
1318 (_("Write message to mailbox"), fname, sizeof (fname),
1319 &menu->redraw, 1) != -1 && fname[0]) {
1320 mutt_message (_("Writing message to %s ..."), fname);
1321 mutt_expand_path (fname, sizeof (fname));
1323 if (msg->content->next)
1324 msg->content = mutt_make_multipart (msg->content);
1326 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1327 msg->content = mutt_remove_multipart (msg->content);
1329 mutt_message _("Message written.");
1335 case OP_COMPOSE_PGP_MENU:
1336 if (msg->security & APPLICATION_SMIME) {
1337 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1339 mutt_clear_error ();
1344 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1345 redraw_crypt_lines (msg);
1346 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1350 case OP_FORGET_PASSPHRASE:
1351 crypt_forget_passphrase ();
1355 case OP_COMPOSE_SMIME_MENU:
1356 if (msg->security & APPLICATION_PGP) {
1357 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1359 mutt_clear_error ();
1364 msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1365 redraw_crypt_lines (msg);
1366 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1371 case OP_COMPOSE_MIX:
1373 mix_make_chain (&msg->chain, &menu->redraw);
1374 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1380 /* Draw formated compose status line */
1381 if (menu->redraw & REDRAW_STATUS) {
1382 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1383 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1384 SETCOLOR (MT_COLOR_STATUS);
1385 move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
1386 printw ("%-*.*s", COLS-SW, COLS-SW, buf);
1387 SETCOLOR (MT_COLOR_NORMAL);
1388 menu->redraw &= ~REDRAW_STATUS;
1392 mutt_menuDestroy (&menu);
1395 msg->content = idx[0]->content;
1396 for (i = 0; i < idxlen; i++) {
1397 idx[i]->content->aptr = NULL;
1402 msg->content = NULL;