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.
25 #include <lib-lib/lib-lib.h>
27 #include <lib-sys/unix.h>
29 #include <lib-mime/mime.h>
31 #include <lib-ui/curses.h>
32 #include <lib-ui/enter.h>
33 #include <lib-ui/menu.h>
37 #include "mutt_idna.h"
39 #include "recvattach.h"
54 static const char *There_are_no_attachments = N_("There are no attachments.");
56 #define CHECK_COUNT if (idxlen == 0) { mutt_error _(There_are_no_attachments); break; }
83 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
85 HDR_ATTACH = (HDR_FCC + 7)
89 #define HDR_XOFFSET 14
90 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
91 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
92 #define W (COLS - HDR_XOFFSET - SW)
94 static const char *Prompts[] = {
106 , "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: "
110 static struct mapping_t ComposeHelp[] = {
111 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
112 {N_("Abort"), OP_EXIT},
113 {"To", OP_COMPOSE_EDIT_TO},
114 {"CC", OP_COMPOSE_EDIT_CC},
115 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
116 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
117 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
118 {N_("Help"), OP_HELP},
123 static struct mapping_t ComposeNewsHelp[] = {
124 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
125 {N_("Abort"), OP_EXIT},
126 {"Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS},
127 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
128 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
129 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
130 {N_("Help"), OP_HELP},
136 static void snd_entry (char *b, ssize_t blen, MUTTMENU * menu, int num) {
137 int w=(COLS-SW)>blen?blen:COLS-SW;
138 mutt_FormatString (b, w, NONULL (AttachFormat), mutt_attach_fmt,
139 (unsigned long) (((ATTACHPTR **) menu->data)[num]),
140 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
143 #include <lib-crypt/crypt.h>
145 static void redraw_crypt_lines (HEADER * msg)
150 mvaddstr (HDR_CRYPT, SW, " Security: ");
151 else if (msg->security & APPLICATION_SMIME)
152 mvaddstr (HDR_CRYPT, SW, " S/MIME: ");
153 else if (msg->security & APPLICATION_PGP)
154 mvaddstr (HDR_CRYPT, SW, " PGP: ");
156 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
157 addstr (_("Sign, Encrypt"));
158 else if (msg->security & ENCRYPT)
159 addstr (_("Encrypt"));
160 else if (msg->security & SIGN)
165 if ((msg->security & APPLICATION_PGP)
166 && (msg->security & (ENCRYPT | SIGN))) {
167 if ((msg->security & INLINE))
168 addstr (_(" (inline)"));
170 addstr (_(" (PGP/MIME)"));
174 move (HDR_CRYPTINFO, SW);
176 if (msg->security & APPLICATION_PGP && msg->security & SIGN)
177 printw ("%s%s", _(" sign as: "),
178 PgpSignAs ? PgpSignAs : _("<default>"));
180 if (msg->security & APPLICATION_SMIME && msg->security & SIGN) {
181 printw ("%s%s", _(" sign as: "),
182 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
185 if ((msg->security & APPLICATION_SMIME)
186 && (msg->security & ENCRYPT)
187 && SmimeCryptAlg && *SmimeCryptAlg) {
188 mvprintw (HDR_CRYPTINFO, SW + 40, "%s%s", _("Encrypt with: "),
189 NONULL (SmimeCryptAlg));
197 static void redraw_mix_line (string_list_t * chain)
202 mvaddstr (HDR_MIX, SW, " Mix: ");
205 addstr ("<no chain defined>");
210 for (c = 12; chain; chain = chain->next) {
212 if (t && t[0] == '0' && t[1] == '\0')
215 if (c + m_strlen(t) + 2 >= COLS - SW)
222 c += m_strlen(t) + 2;
225 #endif /* MIXMASTER */
227 static int check_attachments (ATTACHPTR ** idx, short idxlen)
231 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
233 for (i = 0; i < idxlen; i++) {
234 m_strcpy(pretty, sizeof(pretty), idx[i]->content->filename);
235 if (stat (idx[i]->content->filename, &st) != 0) {
236 mutt_pretty_mailbox (pretty);
237 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
241 if (idx[i]->content->stamp < st.st_mtime) {
242 mutt_pretty_mailbox (pretty);
243 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
246 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
247 mutt_update_encoding (idx[i]->content);
256 static void draw_envelope_addr (int line, address_t * addr)
261 rfc822_write_address (buf, sizeof (buf), addr, 1);
262 mvprintw (line, SW, TITLE_FMT, Prompts[line - 1]);
263 mutt_paddstr (W, buf);
266 static void draw_envelope (HEADER * msg, char *fcc)
268 draw_envelope_addr (HDR_FROM, msg->env->from);
270 if (!option (OPTNEWSSEND)) {
272 draw_envelope_addr (HDR_TO, msg->env->to);
273 draw_envelope_addr (HDR_CC, msg->env->cc);
274 draw_envelope_addr (HDR_BCC, msg->env->bcc);
278 mvprintw (HDR_TO, SW, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
279 mutt_paddstr (W, NONULL (msg->env->newsgroups));
280 mvprintw (HDR_CC, SW, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
281 mutt_paddstr (W, NONULL (msg->env->followup_to));
282 if (option (OPTXCOMMENTTO)) {
283 mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]);
284 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
288 mvprintw (HDR_SUBJECT, SW, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
289 mutt_paddstr (W, NONULL (msg->env->subject));
290 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
291 mvprintw (HDR_FCC, SW, TITLE_FMT, Prompts[HDR_FCC - 1]);
292 mutt_paddstr (W, fcc);
294 redraw_crypt_lines (msg);
297 redraw_mix_line (msg->chain);
300 SETCOLOR (MT_COLOR_STATUS);
301 mvaddstr (HDR_ATTACH - 1, SW, _("-- Attachments"));
302 BKGDSET (MT_COLOR_STATUS);
305 BKGDSET (MT_COLOR_NORMAL);
306 SETCOLOR (MT_COLOR_NORMAL);
309 static int edit_address_list (int line, address_t ** addr)
311 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
314 mutt_addrlist_to_local (*addr);
315 rfc822_write_address (buf, sizeof (buf), *addr, 0);
316 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
317 address_list_wipe(addr);
318 *addr = mutt_parse_adrlist (*addr, buf);
319 *addr = mutt_expand_aliases (*addr);
322 if (option (OPTNEEDREDRAW)) {
323 unset_option (OPTNEEDREDRAW);
324 return (REDRAW_FULL);
327 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
328 mutt_error (_("Warning: '%s' is a bad IDN."), err);
333 /* redraw the expanded list so the user can see the result */
335 rfc822_write_address (buf, sizeof (buf), *addr, 1);
336 move (line, HDR_XOFFSET + SW);
337 mutt_paddstr (W, buf);
342 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
344 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
347 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
349 if (x == 0 && menu->max == 1) {
350 mutt_error _("You may not delete the only attachment.");
352 idx[x]->content->tagged = 0;
356 for (y = 0; y < *idxlen; y++) {
357 if (idx[y]->content->next == idx[x]->content) {
358 idx[y]->content->next = idx[x]->content->next;
363 idx[x]->content->next = NULL;
364 idx[x]->content->parts = NULL;
365 body_list_wipe(&(idx[x]->content));
366 p_delete(&idx[x]->tree);
368 for (; x < *idxlen - 1; x++)
370 menu->max = --(*idxlen);
375 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
377 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
379 idx[idxlen - 1]->content->next = idx[idxlen]->content;
380 idx[idxlen]->content->aptr = idx[idxlen];
381 menu->current = idxlen++;
382 mutt_update_tree (idx, idxlen);
389 * cum_attachs_size: Cumulative Attachments Size
391 * Returns the total number of bytes used by the attachments in the
392 * attachment list _after_ content-transfer-encodings have been
397 static unsigned long cum_attachs_size (MUTTMENU * menu)
401 ATTACHPTR **idx = menu->data;
405 for (i = 0, s = 0; i < menu->max; i++) {
409 b->content = mutt_get_content_info (b->filename, b);
411 if ((info = b->content)) {
412 switch (b->encoding) {
413 case ENCQUOTEDPRINTABLE:
414 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
417 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
420 s += info->lobin + info->hibin + info->ascii + info->crlf;
430 * compose_format_str()
432 * %a = total number of attachments
433 * %h = hostname [option]
434 * %l = approx. length of current message (in bytes)
437 * This function is similar to status_format_str(). Look at that function for
438 * help when modifying this function.
441 static const char *compose_format_str (char *buf, ssize_t buflen, char op,
442 const char *src, const char *prefix,
443 const char *ifstring,
444 const char *elsestring,
445 unsigned long data, format_flag flags)
447 char fmt[SHORT_STRING], tmp[SHORT_STRING];
448 int optional = (flags & M_FORMAT_OPTIONAL);
449 MUTTMENU *menu = (MUTTMENU *) data;
453 case 'a': /* total number of attachments */
454 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
455 snprintf (buf, buflen, fmt, menu->max);
458 case 'h': /* hostname */
459 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
460 snprintf (buf, buflen, fmt, NONULL (Hostname));
463 case 'l': /* approx length of current message in bytes */
464 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
465 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
466 snprintf (buf, buflen, fmt, tmp);
470 m_strcpy(buf, buflen, mutt_make_version (0));
478 snprintf (buf, buflen, "%%%s%c", prefix, op);
483 compose_status_line (buf, buflen, menu, ifstring);
484 else if (flags & M_FORMAT_OPTIONAL)
485 compose_status_line (buf, buflen, menu, elsestring);
490 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
493 int w=(COLS-SW)>buflen?buflen:(COLS-SW);
494 mutt_FormatString (buf, w, p, compose_format_str,
495 (unsigned long) menu, 0);
501 * 1 message should be postponed
505 int mutt_compose_menu (HEADER * msg, /* structure for new message */
506 char *fcc, /* where to save a copy of the message */
508 HEADER * cur __attribute__ ((unused)))
509 { /* current message */
510 char helpstr[SHORT_STRING];
511 char buf[LONG_STRING];
512 char fname[_POSIX_PATH_MAX];
514 ATTACHPTR **idx = NULL;
518 int r = -1; /* return value */
521 int fccSet = 0; /* has the user edited the Fcc: field ? */
522 CONTEXT *ctx = NULL, *this = NULL;
524 /* Sort, SortAux could be changed in mutt_index_menu() */
525 int oldSort, oldSortAux;
529 int news = 0; /* is it a news article ? */
531 if (option (OPTNEWSSEND))
535 mutt_attach_init (msg->content);
536 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
538 menu = mutt_new_menu ();
539 menu->menu = MENU_COMPOSE;
540 menu->offset = HDR_ATTACH;
542 menu->make_entry = snd_entry;
543 menu->tag = mutt_tag_attach;
548 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
553 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
556 if (option (OPTMBOXPANE))
560 unset_option (OPTNEWS); /* for any case */
562 switch (op = mutt_menuLoop (menu)) {
564 draw_envelope (msg, fcc);
565 menu->offset = HDR_ATTACH;
566 menu->pagelen = LINES - HDR_ATTACH - 2;
568 case OP_COMPOSE_EDIT_FROM:
569 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
570 mutt_message_hook (NULL, msg, M_SEND2HOOK);
572 case OP_COMPOSE_EDIT_TO:
576 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
577 mutt_message_hook (NULL, msg, M_SEND2HOOK);
582 case OP_COMPOSE_EDIT_BCC:
586 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
587 mutt_message_hook (NULL, msg, M_SEND2HOOK);
592 case OP_COMPOSE_EDIT_CC:
596 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
597 mutt_message_hook (NULL, msg, M_SEND2HOOK);
603 case OP_COMPOSE_EDIT_NEWSGROUPS:
605 if (msg->env->newsgroups)
606 m_strcpy(buf, sizeof(buf), msg->env->newsgroups);
609 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
611 p_delete(&msg->env->newsgroups);
613 msg->env->newsgroups = m_strdup(skipspaces(buf));
614 move (HDR_TO, HDR_XOFFSET);
616 if (msg->env->newsgroups)
617 printw ("%-*.*s", W, W, msg->env->newsgroups);
622 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
625 if (msg->env->followup_to)
626 m_strcpy(buf, sizeof(buf), msg->env->followup_to);
627 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
629 p_delete(&msg->env->followup_to);
631 msg->env->followup_to = m_strdup(skipspaces(buf));
632 move (HDR_CC, HDR_XOFFSET);
634 if (msg->env->followup_to)
635 printw ("%-*.*s", W, W, msg->env->followup_to);
640 case OP_COMPOSE_EDIT_X_COMMENT_TO:
641 if (news && option (OPTXCOMMENTTO)) {
643 if (msg->env->x_comment_to)
644 m_strcpy(buf, sizeof(buf), msg->env->x_comment_to);
645 if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
647 p_delete(&msg->env->x_comment_to);
648 msg->env->x_comment_to = m_strdup(buf);
649 move (HDR_BCC, HDR_XOFFSET);
651 if (msg->env->x_comment_to)
652 printw ("%-*.*s", W, W, msg->env->x_comment_to);
657 case OP_COMPOSE_EDIT_SUBJECT:
658 if (msg->env->subject)
659 m_strcpy(buf, sizeof(buf), msg->env->subject);
662 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
663 m_strreplace(&msg->env->subject, buf);
664 move (HDR_SUBJECT, HDR_XOFFSET + SW);
666 if (msg->env->subject)
667 mutt_paddstr (W, msg->env->subject);
669 mutt_message_hook (NULL, msg, M_SEND2HOOK);
671 case OP_COMPOSE_EDIT_REPLY_TO:
672 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
673 mutt_message_hook (NULL, msg, M_SEND2HOOK);
675 case OP_COMPOSE_EDIT_FCC:
676 m_strcpy(buf, sizeof(buf), fcc);
677 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
678 m_strcpy(fcc, _POSIX_PATH_MAX, buf);
679 mutt_pretty_mailbox (fcc);
680 move (HDR_FCC, HDR_XOFFSET + SW);
681 mutt_paddstr (W, fcc);
684 MAYBE_REDRAW (menu->redraw);
685 mutt_message_hook (NULL, msg, M_SEND2HOOK);
687 case OP_COMPOSE_EDIT_MESSAGE:
688 if (Editor && !option (OPTEDITHDRS)) {
689 mutt_edit_file (Editor, msg->content->filename);
690 mutt_update_encoding (msg->content);
691 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
692 mutt_message_hook (NULL, msg, M_SEND2HOOK);
696 case OP_COMPOSE_EDIT_HEADERS:
697 if ((op == OP_COMPOSE_EDIT_HEADERS ||
698 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
699 const char *tag = NULL;
702 mutt_env_to_local (msg->env);
703 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
705 if (mutt_env_to_idna (msg->env, &tag, &err)) {
706 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
710 mutt_update_encoding (msg->content);
712 /* attachments may have been added */
713 if (idxlen && idx[idxlen - 1]->content->next) {
714 for (i = 0; i < idxlen; i++)
718 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
724 menu->redraw = REDRAW_FULL;
725 mutt_message_hook (NULL, msg, M_SEND2HOOK);
730 case OP_COMPOSE_ATTACH_KEY:
731 if (idxlen == idxmax) {
732 p_realloc(&idx, idxmax += 5);
736 idx[idxlen] = p_new(ATTACHPTR, 1);
737 if ((idx[idxlen]->content =
738 crypt_pgp_make_key_attachment (NULL)) != NULL) {
739 update_idx (menu, idx, idxlen++);
740 menu->redraw |= REDRAW_INDEX;
743 p_delete(&idx[idxlen]);
745 menu->redraw |= REDRAW_STATUS;
747 if (option (OPTNEEDREDRAW)) {
748 menu->redraw = REDRAW_FULL;
749 unset_option (OPTNEEDREDRAW);
752 mutt_message_hook (NULL, msg, M_SEND2HOOK);
756 case OP_COMPOSE_ATTACH_FILE:
758 char *prompt, **files;
762 prompt = _("Attach file");
766 if (_mutt_enter_fname
767 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
768 &numfiles) == -1 || *fname == '\0')
771 if (idxlen + numfiles >= idxmax) {
772 p_realloc(&idx, idxmax += 5 + numfiles);
778 mutt_message _("Attaching selected files...");
780 for (i = 0; i < numfiles; i++) {
781 char *att = files[i];
783 idx[idxlen] = p_new(ATTACHPTR, 1);
784 idx[idxlen]->unowned = 1;
785 idx[idxlen]->content = mutt_make_file_attach (att);
786 if (idx[idxlen]->content != NULL)
787 update_idx (menu, idx, idxlen++);
790 mutt_error (_("Unable to attach %s!"), att);
791 p_delete(&idx[idxlen]);
799 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
801 mutt_message_hook (NULL, msg, M_SEND2HOOK);
804 case OP_COMPOSE_ATTACH_MESSAGE:
806 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
813 prompt = _("Open mailbox to attach message from");
816 unset_option (OPTNEWS);
817 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
818 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
821 prompt = _("Open newsgroup to attach message from");
822 set_option (OPTNEWS);
828 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
831 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
832 mutt_pretty_mailbox (fname);
835 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
840 if (option (OPTNEWS))
841 nntp_expand_path (fname, sizeof (fname),
842 &CurrentNewsSrv->conn->account);
845 mutt_expand_path (fname, sizeof (fname));
846 if (mx_get_magic (fname) != M_IMAP)
847 if (mx_get_magic (fname) != M_POP)
849 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
851 /* check to make sure the file exists and is readable */
852 if (access (fname, R_OK) == -1) {
857 menu->redraw = REDRAW_FULL;
859 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
865 if (!ctx->msgcount) {
866 mx_close_mailbox (ctx, NULL);
868 mutt_error _("No messages in that folder.");
873 this = Context; /* remember current folder and sort methods */
875 oldSortAux = SortAux;
878 set_option (OPTATTACHMSG);
879 mutt_message _("Tag the messages you want to attach!");
881 closed = mutt_index_menu ();
882 unset_option (OPTATTACHMSG);
885 /* go back to the folder we started from */
887 /* Restore old $sort and $sort_aux */
889 SortAux = oldSortAux;
890 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
894 if (idxlen + Context->tagged >= idxmax) {
895 p_realloc(&idx, idxmax += 5 + Context->tagged);
899 for (i = 0; i < Context->msgcount; i++) {
900 h = Context->hdrs[i];
902 idx[idxlen] = p_new(ATTACHPTR, 1);
903 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
904 if (idx[idxlen]->content != NULL)
905 update_idx (menu, idx, idxlen++);
907 mutt_error _("Unable to attach!");
909 p_delete(&idx[idxlen]);
913 menu->redraw |= REDRAW_FULL;
915 if (closed == OP_QUIT)
916 mx_close_mailbox (Context, NULL);
918 mx_fastclose_mailbox (Context);
921 /* go back to the folder we started from */
923 /* Restore old $sort and $sort_aux */
925 SortAux = oldSortAux;
927 mutt_message_hook (NULL, msg, M_SEND2HOOK);
932 if (idx[menu->current]->unowned)
933 idx[menu->current]->content->unlink = 0;
934 if (delete_attachment (menu, &idxlen, menu->current) == -1)
936 mutt_update_tree (idx, idxlen);
938 if (menu->current > idxlen - 1)
939 menu->current = idxlen - 1;
944 if (menu->current == 0)
945 msg->content = idx[0]->content;
947 menu->redraw |= REDRAW_STATUS;
948 mutt_message_hook (NULL, msg, M_SEND2HOOK);
951 #define CURRENT idx[menu->current]->content
953 case OP_COMPOSE_TOGGLE_RECODE:
956 if (!mutt_is_text_part (CURRENT)) {
957 mutt_error (_("Recoding only affects text attachments."));
960 CURRENT->noconv = !CURRENT->noconv;
962 mutt_message (_("The current attachment won't be converted."));
964 mutt_message (_("The current attachment will be converted."));
965 menu->redraw = REDRAW_CURRENT;
966 mutt_message_hook (NULL, msg, M_SEND2HOOK);
971 case OP_COMPOSE_EDIT_DESCRIPTION:
973 m_strcpy(buf, sizeof(buf),
974 NONULL(idx[menu->current]->content->description));
975 /* header names should not be translated */
976 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
977 m_strreplace(&idx[menu->current]->content->description, buf);
978 menu->redraw = REDRAW_CURRENT;
980 mutt_message_hook (NULL, msg, M_SEND2HOOK);
983 case OP_COMPOSE_UPDATE_ENCODING:
985 if (menu->tagprefix) {
988 for (top = msg->content; top; top = top->next) {
990 mutt_update_encoding (top);
992 menu->redraw = REDRAW_FULL;
995 mutt_update_encoding (idx[menu->current]->content);
996 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
998 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1001 case OP_COMPOSE_TOGGLE_DISPOSITION:
1002 /* toggle the content-disposition between inline/attachment */
1003 idx[menu->current]->content->disposition =
1004 (idx[menu->current]->content->disposition ==
1005 DISPINLINE) ? DISPATTACH : DISPINLINE;
1006 menu->redraw = REDRAW_CURRENT;
1012 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
1014 /* this may have been a change to text/something */
1015 mutt_update_encoding (idx[menu->current]->content);
1017 menu->redraw = REDRAW_CURRENT;
1019 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1022 case OP_COMPOSE_EDIT_ENCODING:
1024 m_strcpy(buf, sizeof(buf),
1025 ENCODING(idx[menu->current]->content->encoding));
1026 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
1027 sizeof (buf), 0) == 0 && buf[0]) {
1028 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
1029 idx[menu->current]->content->encoding = i;
1030 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1031 mutt_clear_error ();
1034 mutt_error _("Invalid encoding.");
1036 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1039 case OP_COMPOSE_SEND_MESSAGE:
1041 /* Note: We don't invoke send2-hook here, since we want to leave
1042 * users an opportunity to change settings from the ":" prompt.
1045 if (check_attachments (idx, idxlen) != 0) {
1046 menu->redraw = REDRAW_FULL;
1052 if (msg->chain && mix_check_message (msg) != 0)
1056 if (!fccSet && *fcc) {
1057 if ((i = query_quadoption (OPT_COPY,
1058 _("Save a copy of this message?"))) == -1)
1068 case OP_COMPOSE_EDIT_FILE:
1070 mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename);
1071 mutt_update_encoding (idx[menu->current]->content);
1072 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1073 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1076 case OP_COMPOSE_TOGGLE_UNLINK:
1078 idx[menu->current]->content->unlink =
1079 !idx[menu->current]->content->unlink;
1082 /* OPTRESOLVE is otherwise ignored on this menu.
1086 if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
1089 menu->redraw = REDRAW_INDEX;
1090 /* No send2hook since this doesn't change the message. */
1093 case OP_COMPOSE_GET_ATTACHMENT:
1095 if (menu->tagprefix) {
1098 for (top = msg->content; top; top = top->next) {
1100 mutt_get_tmp_attachment (top);
1102 menu->redraw = REDRAW_FULL;
1104 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1105 menu->redraw = REDRAW_CURRENT;
1107 /* No send2hook since this doesn't change the message. */
1110 case OP_COMPOSE_RENAME_FILE:
1112 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
1113 mutt_pretty_mailbox (fname);
1114 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1116 if (stat (idx[menu->current]->content->filename, &st) == -1) {
1117 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1121 mutt_expand_path (fname, sizeof (fname));
1122 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1125 m_strreplace(&idx[menu->current]->content->filename, fname);
1126 menu->redraw = REDRAW_CURRENT;
1128 if (idx[menu->current]->content->stamp >= st.st_mtime)
1129 mutt_stamp_attachment (idx[menu->current]->content);
1132 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1135 case OP_COMPOSE_NEW_MIME:
1142 CLEARLINE (LINES - 1);
1144 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1147 mutt_expand_path (fname, sizeof (fname));
1149 /* Call to lookup_mime_type () ? maybe later */
1151 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1155 if (!(p = strchr (type, '/'))) {
1156 mutt_error _("Content-Type is of the form base/sub");
1161 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1162 mutt_error (_("Unknown Content-Type %s"), type);
1165 if (idxlen == idxmax) {
1166 p_realloc(&idx, idxmax += 5);
1170 idx[idxlen] = p_new(ATTACHPTR, 1);
1171 /* Touch the file */
1172 if (!(fp = safe_fopen (fname, "w"))) {
1173 mutt_error (_("Can't create file %s"), fname);
1174 p_delete(&idx[idxlen]);
1179 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1181 _("What we have here is a failure to make an attachment");
1184 update_idx (menu, idx, idxlen++);
1186 idx[menu->current]->content->type = itype;
1187 m_strreplace(&idx[menu->current]->content->subtype, p);
1188 idx[menu->current]->content->unlink = 1;
1189 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1191 if (mutt_compose_attachment (idx[menu->current]->content)) {
1192 mutt_update_encoding (idx[menu->current]->content);
1193 menu->redraw = REDRAW_FULL;
1196 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1199 case OP_COMPOSE_EDIT_MIME:
1201 if (mutt_edit_attachment (idx[menu->current]->content)) {
1202 mutt_update_encoding (idx[menu->current]->content);
1203 menu->redraw = REDRAW_FULL;
1205 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1208 case OP_VIEW_ATTACH:
1209 case OP_DISPLAY_HEADERS:
1211 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1213 menu->redraw = REDRAW_FULL;
1214 /* no send2hook, since this doesn't modify the message */
1219 mutt_save_attachment_list (NULL, menu->tagprefix,
1220 menu->tagprefix ? msg->content : idx[menu->
1222 content, NULL, menu);
1223 MAYBE_REDRAW (menu->redraw);
1224 /* no send2hook, since this doesn't modify the message */
1229 mutt_print_attachment_list (NULL, menu->tagprefix,
1230 menu->tagprefix ? msg->content : idx[menu->
1233 /* no send2hook, since this doesn't modify the message */
1239 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1240 menu->tagprefix ? msg->content : idx[menu->
1242 content, op == OP_FILTER);
1243 if (op == OP_FILTER) /* cte might have changed */
1244 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1245 menu->redraw |= REDRAW_STATUS;
1246 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1251 query_quadoption (OPT_POSTPONE,
1252 _("Postpone this message?"))) == M_NO) {
1253 while (idxlen-- > 0) {
1254 /* avoid freeing other attachments */
1255 idx[idxlen]->content->next = NULL;
1256 idx[idxlen]->content->parts = NULL;
1257 if (idx[idxlen]->unowned)
1258 idx[idxlen]->content->unlink = 0;
1259 body_list_wipe(&idx[idxlen]->content);
1260 p_delete(&idx[idxlen]->tree);
1261 p_delete(&idx[idxlen]);
1273 /* fall through to postpone! */
1275 case OP_COMPOSE_POSTPONE_MESSAGE:
1277 if (check_attachments (idx, idxlen) != 0) {
1278 menu->redraw = REDRAW_FULL;
1286 case OP_COMPOSE_ISPELL:
1288 snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1289 msg->content->filename);
1290 if (mutt_system (buf) == -1)
1291 mutt_error (_("Error running \"%s\"!"), buf);
1293 mutt_update_encoding (msg->content);
1294 menu->redraw |= REDRAW_STATUS;
1298 case OP_COMPOSE_WRITE_MESSAGE:
1302 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
1303 mutt_pretty_mailbox (fname);
1306 msg->content = idx[0]->content;
1307 if (mutt_enter_fname
1308 (_("Write message to mailbox"), fname, sizeof (fname),
1309 &menu->redraw, 1) != -1 && fname[0]) {
1310 mutt_message (_("Writing message to %s ..."), fname);
1311 mutt_expand_path (fname, sizeof (fname));
1313 if (msg->content->next)
1314 msg->content = mutt_make_multipart (msg->content);
1316 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1317 msg->content = mutt_remove_multipart (msg->content);
1319 mutt_message _("Message written.");
1325 case OP_COMPOSE_PGP_MENU:
1326 if (msg->security & APPLICATION_SMIME) {
1327 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1329 mutt_clear_error ();
1334 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1335 redraw_crypt_lines (msg);
1336 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1340 case OP_FORGET_PASSPHRASE:
1341 crypt_forget_passphrase ();
1345 case OP_COMPOSE_SMIME_MENU:
1346 if (msg->security & APPLICATION_PGP) {
1347 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1349 mutt_clear_error ();
1354 msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1355 redraw_crypt_lines (msg);
1356 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1361 case OP_COMPOSE_MIX:
1363 mix_make_chain (&msg->chain, &menu->redraw);
1364 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1370 /* Draw formated compose status line */
1371 if (menu->redraw & REDRAW_STATUS) {
1372 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1373 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1374 SETCOLOR (MT_COLOR_STATUS);
1375 move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
1376 printw ("%-*.*s", COLS-SW, COLS-SW, buf);
1377 SETCOLOR (MT_COLOR_NORMAL);
1378 menu->redraw &= ~REDRAW_STATUS;
1382 mutt_menuDestroy (&menu);
1385 msg->content = idx[0]->content;
1386 for (i = 0; i < idxlen; i++) {
1387 idx[i]->content->aptr = NULL;
1392 msg->content = NULL;