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>
18 #include <lib-mime/mime.h>
20 #include <lib-ui/curses.h>
21 #include <lib-ui/enter.h>
22 #include <lib-ui/menu.h>
26 #include "mutt_idna.h"
28 #include "recvattach.h"
43 static const char *There_are_no_attachments = N_("There are no attachments.");
45 #define CHECK_COUNT if (idxlen == 0) { mutt_error _(There_are_no_attachments); break; }
72 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
74 HDR_ATTACH = (HDR_FCC + 7)
78 #define HDR_XOFFSET 14
79 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
80 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
81 #define W (COLS - HDR_XOFFSET - SW)
83 static const char *Prompts[] = {
95 , "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: "
99 static struct mapping_t ComposeHelp[] = {
100 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
101 {N_("Abort"), OP_EXIT},
102 {"To", OP_COMPOSE_EDIT_TO},
103 {"CC", OP_COMPOSE_EDIT_CC},
104 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
105 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
106 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
107 {N_("Help"), OP_HELP},
112 static struct mapping_t ComposeNewsHelp[] = {
113 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
114 {N_("Abort"), OP_EXIT},
115 {"Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS},
116 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
117 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
118 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
119 {N_("Help"), OP_HELP},
125 static void snd_entry (char *b, ssize_t blen, MUTTMENU * menu, int num) {
126 int w=(COLS-SW)>blen?blen:COLS-SW;
127 mutt_FormatString (b, w, NONULL (AttachFormat), mutt_attach_fmt,
128 (unsigned long) (((ATTACHPTR **) menu->data)[num]),
129 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
132 #include <lib-crypt/crypt.h>
134 static void redraw_crypt_lines (HEADER * msg)
139 mvaddstr (HDR_CRYPT, SW, " Security: ");
140 else if (msg->security & APPLICATION_SMIME)
141 mvaddstr (HDR_CRYPT, SW, " S/MIME: ");
142 else if (msg->security & APPLICATION_PGP)
143 mvaddstr (HDR_CRYPT, SW, " PGP: ");
145 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
146 addstr (_("Sign, Encrypt"));
147 else if (msg->security & ENCRYPT)
148 addstr (_("Encrypt"));
149 else if (msg->security & SIGN)
154 if ((msg->security & APPLICATION_PGP)
155 && (msg->security & (ENCRYPT | SIGN))) {
156 if ((msg->security & INLINE))
157 addstr (_(" (inline)"));
159 addstr (_(" (PGP/MIME)"));
163 move (HDR_CRYPTINFO, SW);
165 if (msg->security & APPLICATION_PGP && msg->security & SIGN)
166 printw ("%s%s", _(" sign as: "),
167 PgpSignAs ? PgpSignAs : _("<default>"));
169 if (msg->security & APPLICATION_SMIME && msg->security & SIGN) {
170 printw ("%s%s", _(" sign as: "),
171 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
174 if ((msg->security & APPLICATION_SMIME)
175 && (msg->security & ENCRYPT)
176 && SmimeCryptAlg && *SmimeCryptAlg) {
177 mvprintw (HDR_CRYPTINFO, SW + 40, "%s%s", _("Encrypt with: "),
178 NONULL (SmimeCryptAlg));
186 static void redraw_mix_line (string_list_t * chain)
191 mvaddstr (HDR_MIX, SW, " Mix: ");
194 addstr ("<no chain defined>");
199 for (c = 12; chain; chain = chain->next) {
201 if (t && t[0] == '0' && t[1] == '\0')
204 if (c + m_strlen(t) + 2 >= COLS - SW)
211 c += m_strlen(t) + 2;
214 #endif /* MIXMASTER */
216 static int check_attachments (ATTACHPTR ** idx, short idxlen)
220 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
222 for (i = 0; i < idxlen; i++) {
223 m_strcpy(pretty, sizeof(pretty), idx[i]->content->filename);
224 if (stat (idx[i]->content->filename, &st) != 0) {
225 mutt_pretty_mailbox (pretty);
226 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
230 if (idx[i]->content->stamp < st.st_mtime) {
231 mutt_pretty_mailbox (pretty);
232 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
235 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
236 mutt_update_encoding (idx[i]->content);
245 static void draw_envelope_addr (int line, address_t * addr)
250 rfc822_write_address (buf, sizeof (buf), addr, 1);
251 mvprintw (line, SW, TITLE_FMT, Prompts[line - 1]);
252 mutt_paddstr (W, buf);
255 static void draw_envelope (HEADER * msg, char *fcc)
257 draw_envelope_addr (HDR_FROM, msg->env->from);
259 if (!option (OPTNEWSSEND)) {
261 draw_envelope_addr (HDR_TO, msg->env->to);
262 draw_envelope_addr (HDR_CC, msg->env->cc);
263 draw_envelope_addr (HDR_BCC, msg->env->bcc);
267 mvprintw (HDR_TO, SW, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
268 mutt_paddstr (W, NONULL (msg->env->newsgroups));
269 mvprintw (HDR_CC, SW, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
270 mutt_paddstr (W, NONULL (msg->env->followup_to));
271 if (option (OPTXCOMMENTTO)) {
272 mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]);
273 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
277 mvprintw (HDR_SUBJECT, SW, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
278 mutt_paddstr (W, NONULL (msg->env->subject));
279 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
280 mvprintw (HDR_FCC, SW, TITLE_FMT, Prompts[HDR_FCC - 1]);
281 mutt_paddstr (W, fcc);
283 redraw_crypt_lines (msg);
286 redraw_mix_line (msg->chain);
289 SETCOLOR (MT_COLOR_STATUS);
290 mvaddstr (HDR_ATTACH - 1, SW, _("-- Attachments"));
291 BKGDSET (MT_COLOR_STATUS);
294 BKGDSET (MT_COLOR_NORMAL);
295 SETCOLOR (MT_COLOR_NORMAL);
298 static int edit_address_list (int line, address_t ** addr)
300 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
303 mutt_addrlist_to_local (*addr);
304 rfc822_write_address (buf, sizeof (buf), *addr, 0);
305 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
306 address_list_wipe(addr);
307 *addr = mutt_parse_adrlist (*addr, buf);
308 *addr = mutt_expand_aliases (*addr);
311 if (option (OPTNEEDREDRAW)) {
312 unset_option (OPTNEEDREDRAW);
313 return (REDRAW_FULL);
316 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
317 mutt_error (_("Warning: '%s' is a bad IDN."), err);
322 /* redraw the expanded list so the user can see the result */
324 rfc822_write_address (buf, sizeof (buf), *addr, 1);
325 move (line, HDR_XOFFSET + SW);
326 mutt_paddstr (W, buf);
331 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
333 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
336 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
338 if (x == 0 && menu->max == 1) {
339 mutt_error _("You may not delete the only attachment.");
341 idx[x]->content->tagged = 0;
345 for (y = 0; y < *idxlen; y++) {
346 if (idx[y]->content->next == idx[x]->content) {
347 idx[y]->content->next = idx[x]->content->next;
352 idx[x]->content->next = NULL;
353 idx[x]->content->parts = NULL;
354 body_list_wipe(&(idx[x]->content));
355 p_delete(&idx[x]->tree);
357 for (; x < *idxlen - 1; x++)
359 menu->max = --(*idxlen);
364 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
366 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
368 idx[idxlen - 1]->content->next = idx[idxlen]->content;
369 idx[idxlen]->content->aptr = idx[idxlen];
370 menu->current = idxlen++;
371 mutt_update_tree (idx, idxlen);
378 * cum_attachs_size: Cumulative Attachments Size
380 * Returns the total number of bytes used by the attachments in the
381 * attachment list _after_ content-transfer-encodings have been
386 static unsigned long cum_attachs_size (MUTTMENU * menu)
390 ATTACHPTR **idx = menu->data;
394 for (i = 0, s = 0; i < menu->max; i++) {
398 b->content = mutt_get_content_info (b->filename, b);
400 if ((info = b->content)) {
401 switch (b->encoding) {
402 case ENCQUOTEDPRINTABLE:
403 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
406 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
409 s += info->lobin + info->hibin + info->ascii + info->crlf;
419 * compose_format_str()
421 * %a = total number of attachments
422 * %h = hostname [option]
423 * %l = approx. length of current message (in bytes)
426 * This function is similar to status_format_str(). Look at that function for
427 * help when modifying this function.
430 static const char *compose_format_str (char *buf, ssize_t buflen, char op,
431 const char *src, const char *prefix,
432 const char *ifstring,
433 const char *elsestring,
434 unsigned long data, format_flag flags)
436 char fmt[SHORT_STRING], tmp[SHORT_STRING];
437 int optional = (flags & M_FORMAT_OPTIONAL);
438 MUTTMENU *menu = (MUTTMENU *) data;
442 case 'a': /* total number of attachments */
443 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
444 snprintf (buf, buflen, fmt, menu->max);
447 case 'h': /* hostname */
448 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
449 snprintf (buf, buflen, fmt, NONULL (Hostname));
452 case 'l': /* approx length of current message in bytes */
453 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
454 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
455 snprintf (buf, buflen, fmt, tmp);
459 m_strcpy(buf, buflen, mutt_make_version (0));
467 snprintf (buf, buflen, "%%%s%c", prefix, op);
472 compose_status_line (buf, buflen, menu, ifstring);
473 else if (flags & M_FORMAT_OPTIONAL)
474 compose_status_line (buf, buflen, menu, elsestring);
479 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
482 int w=(COLS-SW)>buflen?buflen:(COLS-SW);
483 mutt_FormatString (buf, w, p, compose_format_str,
484 (unsigned long) menu, 0);
490 * 1 message should be postponed
494 int mutt_compose_menu (HEADER * msg, /* structure for new message */
495 char *fcc, /* where to save a copy of the message */
497 HEADER * cur __attribute__ ((unused)))
498 { /* current message */
499 char helpstr[SHORT_STRING];
500 char buf[LONG_STRING];
501 char fname[_POSIX_PATH_MAX];
503 ATTACHPTR **idx = NULL;
507 int r = -1; /* return value */
510 int fccSet = 0; /* has the user edited the Fcc: field ? */
511 CONTEXT *ctx = NULL, *this = NULL;
513 /* Sort, SortAux could be changed in mutt_index_menu() */
514 int oldSort, oldSortAux;
518 int news = 0; /* is it a news article ? */
520 if (option (OPTNEWSSEND))
524 mutt_attach_init (msg->content);
525 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
527 menu = mutt_new_menu ();
528 menu->menu = MENU_COMPOSE;
529 menu->offset = HDR_ATTACH;
531 menu->make_entry = snd_entry;
532 menu->tag = mutt_tag_attach;
537 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
542 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
545 if (option (OPTMBOXPANE))
549 unset_option (OPTNEWS); /* for any case */
551 switch (op = mutt_menuLoop (menu)) {
553 draw_envelope (msg, fcc);
554 menu->offset = HDR_ATTACH;
555 menu->pagelen = LINES - HDR_ATTACH - 2;
557 case OP_COMPOSE_EDIT_FROM:
558 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
559 mutt_message_hook (NULL, msg, M_SEND2HOOK);
561 case OP_COMPOSE_EDIT_TO:
565 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
566 mutt_message_hook (NULL, msg, M_SEND2HOOK);
571 case OP_COMPOSE_EDIT_BCC:
575 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
576 mutt_message_hook (NULL, msg, M_SEND2HOOK);
581 case OP_COMPOSE_EDIT_CC:
585 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
586 mutt_message_hook (NULL, msg, M_SEND2HOOK);
592 case OP_COMPOSE_EDIT_NEWSGROUPS:
594 if (msg->env->newsgroups)
595 m_strcpy(buf, sizeof(buf), msg->env->newsgroups);
598 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
600 p_delete(&msg->env->newsgroups);
602 msg->env->newsgroups = m_strdup(skipspaces(buf));
603 move (HDR_TO, HDR_XOFFSET);
605 if (msg->env->newsgroups)
606 printw ("%-*.*s", W, W, msg->env->newsgroups);
611 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
614 if (msg->env->followup_to)
615 m_strcpy(buf, sizeof(buf), msg->env->followup_to);
616 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
618 p_delete(&msg->env->followup_to);
620 msg->env->followup_to = m_strdup(skipspaces(buf));
621 move (HDR_CC, HDR_XOFFSET);
623 if (msg->env->followup_to)
624 printw ("%-*.*s", W, W, msg->env->followup_to);
629 case OP_COMPOSE_EDIT_X_COMMENT_TO:
630 if (news && option (OPTXCOMMENTTO)) {
632 if (msg->env->x_comment_to)
633 m_strcpy(buf, sizeof(buf), msg->env->x_comment_to);
634 if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
636 p_delete(&msg->env->x_comment_to);
637 msg->env->x_comment_to = m_strdup(buf);
638 move (HDR_BCC, HDR_XOFFSET);
640 if (msg->env->x_comment_to)
641 printw ("%-*.*s", W, W, msg->env->x_comment_to);
646 case OP_COMPOSE_EDIT_SUBJECT:
647 if (msg->env->subject)
648 m_strcpy(buf, sizeof(buf), msg->env->subject);
651 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
652 m_strreplace(&msg->env->subject, buf);
653 move (HDR_SUBJECT, HDR_XOFFSET + SW);
655 if (msg->env->subject)
656 mutt_paddstr (W, msg->env->subject);
658 mutt_message_hook (NULL, msg, M_SEND2HOOK);
660 case OP_COMPOSE_EDIT_REPLY_TO:
661 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
662 mutt_message_hook (NULL, msg, M_SEND2HOOK);
664 case OP_COMPOSE_EDIT_FCC:
665 m_strcpy(buf, sizeof(buf), fcc);
666 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
667 m_strcpy(fcc, _POSIX_PATH_MAX, buf);
668 mutt_pretty_mailbox (fcc);
669 move (HDR_FCC, HDR_XOFFSET + SW);
670 mutt_paddstr (W, fcc);
673 MAYBE_REDRAW (menu->redraw);
674 mutt_message_hook (NULL, msg, M_SEND2HOOK);
676 case OP_COMPOSE_EDIT_MESSAGE:
677 if (Editor && !option (OPTEDITHDRS)) {
678 mutt_edit_file (Editor, msg->content->filename);
679 mutt_update_encoding (msg->content);
680 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
681 mutt_message_hook (NULL, msg, M_SEND2HOOK);
685 case OP_COMPOSE_EDIT_HEADERS:
686 if ((op == OP_COMPOSE_EDIT_HEADERS ||
687 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
688 const char *tag = NULL;
691 mutt_env_to_local (msg->env);
692 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
694 if (mutt_env_to_idna (msg->env, &tag, &err)) {
695 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
699 mutt_update_encoding (msg->content);
701 /* attachments may have been added */
702 if (idxlen && idx[idxlen - 1]->content->next) {
703 for (i = 0; i < idxlen; i++)
707 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
713 menu->redraw = REDRAW_FULL;
714 mutt_message_hook (NULL, msg, M_SEND2HOOK);
719 case OP_COMPOSE_ATTACH_KEY:
720 if (idxlen == idxmax) {
721 p_realloc(&idx, idxmax += 5);
725 idx[idxlen] = p_new(ATTACHPTR, 1);
726 if ((idx[idxlen]->content =
727 crypt_pgp_make_key_attachment (NULL)) != NULL) {
728 update_idx (menu, idx, idxlen++);
729 menu->redraw |= REDRAW_INDEX;
732 p_delete(&idx[idxlen]);
734 menu->redraw |= REDRAW_STATUS;
736 if (option (OPTNEEDREDRAW)) {
737 menu->redraw = REDRAW_FULL;
738 unset_option (OPTNEEDREDRAW);
741 mutt_message_hook (NULL, msg, M_SEND2HOOK);
745 case OP_COMPOSE_ATTACH_FILE:
747 char *prompt, **files;
751 prompt = _("Attach file");
755 if (_mutt_enter_fname
756 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
757 &numfiles) == -1 || *fname == '\0')
760 if (idxlen + numfiles >= idxmax) {
761 p_realloc(&idx, idxmax += 5 + numfiles);
767 mutt_message _("Attaching selected files...");
769 for (i = 0; i < numfiles; i++) {
770 char *att = files[i];
772 idx[idxlen] = p_new(ATTACHPTR, 1);
773 idx[idxlen]->unowned = 1;
774 idx[idxlen]->content = mutt_make_file_attach (att);
775 if (idx[idxlen]->content != NULL)
776 update_idx (menu, idx, idxlen++);
779 mutt_error (_("Unable to attach %s!"), att);
780 p_delete(&idx[idxlen]);
788 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
790 mutt_message_hook (NULL, msg, M_SEND2HOOK);
793 case OP_COMPOSE_ATTACH_MESSAGE:
795 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
802 prompt = _("Open mailbox to attach message from");
805 unset_option (OPTNEWS);
806 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
807 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
810 prompt = _("Open newsgroup to attach message from");
811 set_option (OPTNEWS);
817 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
820 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
821 mutt_pretty_mailbox (fname);
824 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
829 if (option (OPTNEWS))
830 nntp_expand_path (fname, sizeof (fname),
831 &CurrentNewsSrv->conn->account);
834 mutt_expand_path (fname, sizeof (fname));
835 if (mx_get_magic (fname) != M_IMAP)
836 if (mx_get_magic (fname) != M_POP)
838 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
840 /* check to make sure the file exists and is readable */
841 if (access (fname, R_OK) == -1) {
846 menu->redraw = REDRAW_FULL;
848 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
854 if (!ctx->msgcount) {
855 mx_close_mailbox (ctx, NULL);
857 mutt_error _("No messages in that folder.");
862 this = Context; /* remember current folder and sort methods */
864 oldSortAux = SortAux;
867 set_option (OPTATTACHMSG);
868 mutt_message _("Tag the messages you want to attach!");
870 closed = mutt_index_menu ();
871 unset_option (OPTATTACHMSG);
874 /* go back to the folder we started from */
876 /* Restore old $sort and $sort_aux */
878 SortAux = oldSortAux;
879 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
883 if (idxlen + Context->tagged >= idxmax) {
884 p_realloc(&idx, idxmax += 5 + Context->tagged);
888 for (i = 0; i < Context->msgcount; i++) {
889 h = Context->hdrs[i];
891 idx[idxlen] = p_new(ATTACHPTR, 1);
892 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
893 if (idx[idxlen]->content != NULL)
894 update_idx (menu, idx, idxlen++);
896 mutt_error _("Unable to attach!");
898 p_delete(&idx[idxlen]);
902 menu->redraw |= REDRAW_FULL;
904 if (closed == OP_QUIT)
905 mx_close_mailbox (Context, NULL);
907 mx_fastclose_mailbox (Context);
910 /* go back to the folder we started from */
912 /* Restore old $sort and $sort_aux */
914 SortAux = oldSortAux;
916 mutt_message_hook (NULL, msg, M_SEND2HOOK);
921 if (idx[menu->current]->unowned)
922 idx[menu->current]->content->unlink = 0;
923 if (delete_attachment (menu, &idxlen, menu->current) == -1)
925 mutt_update_tree (idx, idxlen);
927 if (menu->current > idxlen - 1)
928 menu->current = idxlen - 1;
933 if (menu->current == 0)
934 msg->content = idx[0]->content;
936 menu->redraw |= REDRAW_STATUS;
937 mutt_message_hook (NULL, msg, M_SEND2HOOK);
940 #define CURRENT idx[menu->current]->content
942 case OP_COMPOSE_TOGGLE_RECODE:
945 if (!mutt_is_text_part (CURRENT)) {
946 mutt_error (_("Recoding only affects text attachments."));
949 CURRENT->noconv = !CURRENT->noconv;
951 mutt_message (_("The current attachment won't be converted."));
953 mutt_message (_("The current attachment will be converted."));
954 menu->redraw = REDRAW_CURRENT;
955 mutt_message_hook (NULL, msg, M_SEND2HOOK);
960 case OP_COMPOSE_EDIT_DESCRIPTION:
962 m_strcpy(buf, sizeof(buf),
963 NONULL(idx[menu->current]->content->description));
964 /* header names should not be translated */
965 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
966 m_strreplace(&idx[menu->current]->content->description, buf);
967 menu->redraw = REDRAW_CURRENT;
969 mutt_message_hook (NULL, msg, M_SEND2HOOK);
972 case OP_COMPOSE_UPDATE_ENCODING:
974 if (menu->tagprefix) {
977 for (top = msg->content; top; top = top->next) {
979 mutt_update_encoding (top);
981 menu->redraw = REDRAW_FULL;
984 mutt_update_encoding (idx[menu->current]->content);
985 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
987 mutt_message_hook (NULL, msg, M_SEND2HOOK);
990 case OP_COMPOSE_TOGGLE_DISPOSITION:
991 /* toggle the content-disposition between inline/attachment */
992 idx[menu->current]->content->disposition =
993 (idx[menu->current]->content->disposition ==
994 DISPINLINE) ? DISPATTACH : DISPINLINE;
995 menu->redraw = REDRAW_CURRENT;
1001 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
1003 /* this may have been a change to text/something */
1004 mutt_update_encoding (idx[menu->current]->content);
1006 menu->redraw = REDRAW_CURRENT;
1008 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1011 case OP_COMPOSE_EDIT_ENCODING:
1013 m_strcpy(buf, sizeof(buf),
1014 ENCODING(idx[menu->current]->content->encoding));
1015 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
1016 sizeof (buf), 0) == 0 && buf[0]) {
1017 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
1018 idx[menu->current]->content->encoding = i;
1019 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1020 mutt_clear_error ();
1023 mutt_error _("Invalid encoding.");
1025 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1028 case OP_COMPOSE_SEND_MESSAGE:
1030 /* Note: We don't invoke send2-hook here, since we want to leave
1031 * users an opportunity to change settings from the ":" prompt.
1034 if (check_attachments (idx, idxlen) != 0) {
1035 menu->redraw = REDRAW_FULL;
1041 if (msg->chain && mix_check_message (msg) != 0)
1045 if (!fccSet && *fcc) {
1046 if ((i = query_quadoption (OPT_COPY,
1047 _("Save a copy of this message?"))) == -1)
1057 case OP_COMPOSE_EDIT_FILE:
1059 mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename);
1060 mutt_update_encoding (idx[menu->current]->content);
1061 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1062 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1065 case OP_COMPOSE_TOGGLE_UNLINK:
1067 idx[menu->current]->content->unlink =
1068 !idx[menu->current]->content->unlink;
1071 /* OPTRESOLVE is otherwise ignored on this menu.
1075 if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
1078 menu->redraw = REDRAW_INDEX;
1079 /* No send2hook since this doesn't change the message. */
1082 case OP_COMPOSE_GET_ATTACHMENT:
1084 if (menu->tagprefix) {
1087 for (top = msg->content; top; top = top->next) {
1089 mutt_get_tmp_attachment (top);
1091 menu->redraw = REDRAW_FULL;
1093 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1094 menu->redraw = REDRAW_CURRENT;
1096 /* No send2hook since this doesn't change the message. */
1099 case OP_COMPOSE_RENAME_FILE:
1101 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
1102 mutt_pretty_mailbox (fname);
1103 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1105 if (stat (idx[menu->current]->content->filename, &st) == -1) {
1106 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1110 mutt_expand_path (fname, sizeof (fname));
1111 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1114 m_strreplace(&idx[menu->current]->content->filename, fname);
1115 menu->redraw = REDRAW_CURRENT;
1117 if (idx[menu->current]->content->stamp >= st.st_mtime)
1118 mutt_stamp_attachment (idx[menu->current]->content);
1121 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1124 case OP_COMPOSE_NEW_MIME:
1131 CLEARLINE (LINES - 1);
1133 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1136 mutt_expand_path (fname, sizeof (fname));
1138 /* Call to lookup_mime_type () ? maybe later */
1140 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1144 if (!(p = strchr (type, '/'))) {
1145 mutt_error _("Content-Type is of the form base/sub");
1150 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1151 mutt_error (_("Unknown Content-Type %s"), type);
1154 if (idxlen == idxmax) {
1155 p_realloc(&idx, idxmax += 5);
1159 idx[idxlen] = p_new(ATTACHPTR, 1);
1160 /* Touch the file */
1161 if (!(fp = safe_fopen (fname, "w"))) {
1162 mutt_error (_("Can't create file %s"), fname);
1163 p_delete(&idx[idxlen]);
1168 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1170 _("What we have here is a failure to make an attachment");
1173 update_idx (menu, idx, idxlen++);
1175 idx[menu->current]->content->type = itype;
1176 m_strreplace(&idx[menu->current]->content->subtype, p);
1177 idx[menu->current]->content->unlink = 1;
1178 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1180 if (mutt_compose_attachment (idx[menu->current]->content)) {
1181 mutt_update_encoding (idx[menu->current]->content);
1182 menu->redraw = REDRAW_FULL;
1185 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1188 case OP_COMPOSE_EDIT_MIME:
1190 if (mutt_edit_attachment (idx[menu->current]->content)) {
1191 mutt_update_encoding (idx[menu->current]->content);
1192 menu->redraw = REDRAW_FULL;
1194 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1197 case OP_VIEW_ATTACH:
1198 case OP_DISPLAY_HEADERS:
1200 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1202 menu->redraw = REDRAW_FULL;
1203 /* no send2hook, since this doesn't modify the message */
1208 mutt_save_attachment_list (NULL, menu->tagprefix,
1209 menu->tagprefix ? msg->content : idx[menu->
1211 content, NULL, menu);
1212 MAYBE_REDRAW (menu->redraw);
1213 /* no send2hook, since this doesn't modify the message */
1218 mutt_print_attachment_list (NULL, menu->tagprefix,
1219 menu->tagprefix ? msg->content : idx[menu->
1222 /* no send2hook, since this doesn't modify the message */
1228 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1229 menu->tagprefix ? msg->content : idx[menu->
1231 content, op == OP_FILTER);
1232 if (op == OP_FILTER) /* cte might have changed */
1233 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1234 menu->redraw |= REDRAW_STATUS;
1235 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1240 query_quadoption (OPT_POSTPONE,
1241 _("Postpone this message?"))) == M_NO) {
1242 while (idxlen-- > 0) {
1243 /* avoid freeing other attachments */
1244 idx[idxlen]->content->next = NULL;
1245 idx[idxlen]->content->parts = NULL;
1246 if (idx[idxlen]->unowned)
1247 idx[idxlen]->content->unlink = 0;
1248 body_list_wipe(&idx[idxlen]->content);
1249 p_delete(&idx[idxlen]->tree);
1250 p_delete(&idx[idxlen]);
1262 /* fall through to postpone! */
1264 case OP_COMPOSE_POSTPONE_MESSAGE:
1266 if (check_attachments (idx, idxlen) != 0) {
1267 menu->redraw = REDRAW_FULL;
1275 case OP_COMPOSE_ISPELL:
1277 snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1278 msg->content->filename);
1279 if (mutt_system (buf) == -1)
1280 mutt_error (_("Error running \"%s\"!"), buf);
1282 mutt_update_encoding (msg->content);
1283 menu->redraw |= REDRAW_STATUS;
1287 case OP_COMPOSE_WRITE_MESSAGE:
1291 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
1292 mutt_pretty_mailbox (fname);
1295 msg->content = idx[0]->content;
1296 if (mutt_enter_fname
1297 (_("Write message to mailbox"), fname, sizeof (fname),
1298 &menu->redraw, 1) != -1 && fname[0]) {
1299 mutt_message (_("Writing message to %s ..."), fname);
1300 mutt_expand_path (fname, sizeof (fname));
1302 if (msg->content->next)
1303 msg->content = mutt_make_multipart (msg->content);
1305 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1306 msg->content = mutt_remove_multipart (msg->content);
1308 mutt_message _("Message written.");
1314 case OP_COMPOSE_PGP_MENU:
1315 if (msg->security & APPLICATION_SMIME) {
1316 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1318 mutt_clear_error ();
1323 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1324 redraw_crypt_lines (msg);
1325 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1329 case OP_FORGET_PASSPHRASE:
1330 crypt_forget_passphrase ();
1334 case OP_COMPOSE_SMIME_MENU:
1335 if (msg->security & APPLICATION_PGP) {
1336 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1338 mutt_clear_error ();
1343 msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1344 redraw_crypt_lines (msg);
1345 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1350 case OP_COMPOSE_MIX:
1352 mix_make_chain (&msg->chain, &menu->redraw);
1353 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1359 /* Draw formated compose status line */
1360 if (menu->redraw & REDRAW_STATUS) {
1361 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1362 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1363 SETCOLOR (MT_COLOR_STATUS);
1364 move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
1365 printw ("%-*.*s", COLS-SW, COLS-SW, buf);
1366 SETCOLOR (MT_COLOR_NORMAL);
1367 menu->redraw &= ~REDRAW_STATUS;
1371 mutt_menuDestroy (&menu);
1374 msg->content = idx[0]->content;
1375 for (i = 0; i < idxlen; i++) {
1376 idx[i]->content->aptr = NULL;
1381 msg->content = NULL;