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>
23 #include <lib-mx/mx.h>
27 #include "mutt_idna.h"
29 #include "recvattach.h"
36 #include <nntp/nntp.h>
41 mutt_error _("There are no attachments."); \
65 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
67 HDR_ATTACH = (HDR_FCC + 7)
71 #define HDR_XOFFSET 14
72 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
73 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
74 #define W (COLS - HDR_XOFFSET - SW)
76 static const char *Prompts[] = {
85 "", "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: "
89 static struct mapping_t ComposeHelp[] = {
90 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
91 {N_("Abort"), OP_EXIT},
92 {"To", OP_COMPOSE_EDIT_TO},
93 {"CC", OP_COMPOSE_EDIT_CC},
94 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
95 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
96 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
97 {N_("Help"), OP_HELP},
102 static struct mapping_t ComposeNewsHelp[] = {
103 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
104 {N_("Abort"), OP_EXIT},
105 {"Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS},
106 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
107 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
108 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
109 {N_("Help"), OP_HELP},
115 static void snd_entry (char *b, ssize_t blen, MUTTMENU * menu, int num) {
116 int w=(COLS-SW)>blen?blen:COLS-SW;
117 mutt_FormatString (b, w, NONULL (AttachFormat), mutt_attach_fmt,
118 (unsigned long) (((ATTACHPTR **) menu->data)[num]),
119 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
122 #include <lib-crypt/crypt.h>
124 static void redraw_crypt_lines (HEADER * msg)
129 mvaddstr (HDR_CRYPT, SW, " Security: ");
130 else if (msg->security & APPLICATION_SMIME)
131 mvaddstr (HDR_CRYPT, SW, " S/MIME: ");
132 else if (msg->security & APPLICATION_PGP)
133 mvaddstr (HDR_CRYPT, SW, " PGP: ");
135 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
136 addstr (_("Sign, Encrypt"));
137 else if (msg->security & ENCRYPT)
138 addstr (_("Encrypt"));
139 else if (msg->security & SIGN)
144 if ((msg->security & APPLICATION_PGP)
145 && (msg->security & (ENCRYPT | SIGN))) {
146 if ((msg->security & INLINE))
147 addstr (_(" (inline)"));
149 addstr (_(" (PGP/MIME)"));
153 move (HDR_CRYPTINFO, SW);
155 if (msg->security & APPLICATION_PGP && msg->security & SIGN)
156 printw ("%s%s", _(" sign as: "),
157 PgpSignAs ? PgpSignAs : _("<default>"));
159 if (msg->security & APPLICATION_SMIME && msg->security & SIGN) {
160 printw ("%s%s", _(" sign as: "),
161 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
164 if ((msg->security & APPLICATION_SMIME)
165 && (msg->security & ENCRYPT)
166 && SmimeCryptAlg && *SmimeCryptAlg) {
167 mvprintw (HDR_CRYPTINFO, SW + 40, "%s%s", _("Encrypt with: "),
168 NONULL (SmimeCryptAlg));
173 static void redraw_mix_line (string_list_t * chain)
178 mvaddstr (HDR_MIX, SW, " Mix: ");
181 addstr ("<no chain defined>");
186 for (c = 12; chain; chain = chain->next) {
188 if (t && t[0] == '0' && t[1] == '\0')
191 if (c + m_strlen(t) + 2 >= COLS - SW)
198 c += m_strlen(t) + 2;
202 static int check_attachments (ATTACHPTR ** idx, short idxlen)
206 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
208 for (i = 0; i < idxlen; i++) {
209 m_strcpy(pretty, sizeof(pretty), idx[i]->content->filename);
210 if (stat (idx[i]->content->filename, &st) != 0) {
211 mutt_pretty_mailbox (pretty);
212 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
216 if (idx[i]->content->stamp < st.st_mtime) {
217 mutt_pretty_mailbox (pretty);
218 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
221 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
222 mutt_update_encoding (idx[i]->content);
231 static void draw_envelope_addr (int line, address_t * addr)
236 rfc822_write_address (buf, sizeof (buf), addr, 1);
237 mvprintw (line, SW, TITLE_FMT, Prompts[line - 1]);
238 mutt_paddstr (W, buf);
241 static void draw_envelope (HEADER * msg, char *fcc)
243 draw_envelope_addr (HDR_FROM, msg->env->from);
245 if (!option (OPTNEWSSEND)) {
247 draw_envelope_addr (HDR_TO, msg->env->to);
248 draw_envelope_addr (HDR_CC, msg->env->cc);
249 draw_envelope_addr (HDR_BCC, msg->env->bcc);
252 mvprintw (HDR_TO, SW, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
253 mutt_paddstr (W, NONULL (msg->env->newsgroups));
254 mvprintw (HDR_CC, SW, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
255 mutt_paddstr (W, NONULL (msg->env->followup_to));
256 if (option (OPTXCOMMENTTO)) {
257 mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]);
258 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
262 mvprintw (HDR_SUBJECT, SW, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
263 mutt_paddstr (W, NONULL (msg->env->subject));
264 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
265 mvprintw (HDR_FCC, SW, TITLE_FMT, Prompts[HDR_FCC - 1]);
266 mutt_paddstr (W, fcc);
268 redraw_crypt_lines (msg);
269 redraw_mix_line (msg->chain);
271 SETCOLOR (MT_COLOR_STATUS);
272 mvaddstr (HDR_ATTACH - 1, SW, _("-- Attachments"));
273 BKGDSET (MT_COLOR_STATUS);
276 BKGDSET (MT_COLOR_NORMAL);
277 SETCOLOR (MT_COLOR_NORMAL);
280 static int edit_address_list (int line, address_t ** addr)
282 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
285 mutt_addrlist_to_local (*addr);
286 rfc822_write_address (buf, sizeof (buf), *addr, 0);
287 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
288 address_list_wipe(addr);
289 *addr = mutt_parse_adrlist (*addr, buf);
290 *addr = mutt_expand_aliases (*addr);
293 if (option (OPTNEEDREDRAW)) {
294 unset_option (OPTNEEDREDRAW);
298 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
299 mutt_error (_("Warning: '%s' is a bad IDN."), err);
304 /* redraw the expanded list so the user can see the result */
306 rfc822_write_address (buf, sizeof (buf), *addr, 1);
307 move (line, HDR_XOFFSET + SW);
308 mutt_paddstr (W, buf);
313 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
315 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
318 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
320 if (x == 0 && menu->max == 1) {
321 mutt_error _("You may not delete the only attachment.");
323 idx[x]->content->tagged = 0;
327 for (y = 0; y < *idxlen; y++) {
328 if (idx[y]->content->next == idx[x]->content) {
329 idx[y]->content->next = idx[x]->content->next;
334 idx[x]->content->next = NULL;
335 idx[x]->content->parts = NULL;
336 body_list_wipe(&(idx[x]->content));
337 p_delete(&idx[x]->tree);
339 for (; x < *idxlen - 1; x++)
341 menu->max = --(*idxlen);
346 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
348 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
350 idx[idxlen - 1]->content->next = idx[idxlen]->content;
351 idx[idxlen]->content->aptr = idx[idxlen];
352 menu->current = idxlen++;
353 mutt_update_tree (idx, idxlen);
360 * cum_attachs_size: Cumulative Attachments Size
362 * Returns the total number of bytes used by the attachments in the
363 * attachment list _after_ content-transfer-encodings have been
367 static unsigned long cum_attachs_size (MUTTMENU * menu)
371 ATTACHPTR **idx = menu->data;
375 for (i = 0, s = 0; i < menu->max; i++) {
379 b->content = mutt_get_content_info (b->filename, b);
381 if ((info = b->content)) {
382 switch (b->encoding) {
383 case ENCQUOTEDPRINTABLE:
384 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
387 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
390 s += info->lobin + info->hibin + info->ascii + info->crlf;
400 * compose_format_str()
402 * %a = total number of attachments
403 * %h = hostname [option]
404 * %l = approx. length of current message (in bytes)
407 * This function is similar to status_format_str(). Look at that function for
408 * help when modifying this function.
410 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
413 static const char *compose_format_str (char *buf, ssize_t buflen, char op,
414 const char *src, const char *prefix,
415 const char *ifstring,
416 const char *elsestring,
417 unsigned long data, format_flag flags)
419 char fmt[SHORT_STRING], tmp[SHORT_STRING];
420 int optional = (flags & M_FORMAT_OPTIONAL);
421 MUTTMENU *menu = (MUTTMENU *) data;
425 case 'a': /* total number of attachments */
426 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
427 snprintf (buf, buflen, fmt, menu->max);
430 case 'h': /* hostname */
431 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
432 snprintf (buf, buflen, fmt, NONULL (Hostname));
435 case 'l': /* approx length of current message in bytes */
436 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
437 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
438 snprintf (buf, buflen, fmt, tmp);
442 m_strcpy(buf, buflen, mutt_make_version (0));
450 snprintf (buf, buflen, "%%%s%c", prefix, op);
455 compose_status_line (buf, buflen, menu, ifstring);
456 else if (flags & M_FORMAT_OPTIONAL)
457 compose_status_line (buf, buflen, menu, elsestring);
462 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
465 int w=(COLS-SW)>buflen?buflen:(COLS-SW);
466 mutt_FormatString (buf, w, p, compose_format_str,
467 (unsigned long) menu, 0);
472 * 1 message should be postponed
476 int mutt_compose_menu (HEADER * msg, /* structure for new message */
477 char *fcc, /* where to save a copy of the message */
479 HEADER * cur __attribute__ ((unused)))
480 { /* current message */
481 char helpstr[SHORT_STRING];
482 char buf[LONG_STRING];
483 char fname[_POSIX_PATH_MAX];
485 ATTACHPTR **idx = NULL;
489 int r = -1; /* return value */
492 int fccSet = 0; /* has the user edited the Fcc: field ? */
493 CONTEXT *ctx = NULL, *this = NULL;
495 /* Sort, SortAux could be changed in mutt_index_menu() */
496 int oldSort, oldSortAux;
500 int news = 0; /* is it a news article ? */
502 if (option (OPTNEWSSEND))
506 mutt_attach_init (msg->content);
507 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
509 menu = mutt_new_menu ();
510 menu->menu = MENU_COMPOSE;
511 menu->offset = HDR_ATTACH;
513 menu->make_entry = snd_entry;
514 menu->tag = mutt_tag_attach;
518 menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_COMPOSE,
522 menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_COMPOSE,
525 if (option (OPTMBOXPANE))
529 unset_option (OPTNEWS); /* for any case */
531 switch (op = mutt_menuLoop (menu)) {
533 draw_envelope (msg, fcc);
534 menu->offset = HDR_ATTACH;
535 menu->pagelen = LINES - HDR_ATTACH - 2;
537 case OP_COMPOSE_EDIT_FROM:
538 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
539 mutt_message_hook (NULL, msg, M_SEND2HOOK);
541 case OP_COMPOSE_EDIT_TO:
545 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
546 mutt_message_hook (NULL, msg, M_SEND2HOOK);
551 case OP_COMPOSE_EDIT_BCC:
555 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
556 mutt_message_hook (NULL, msg, M_SEND2HOOK);
561 case OP_COMPOSE_EDIT_CC:
565 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
566 mutt_message_hook (NULL, msg, M_SEND2HOOK);
572 case OP_COMPOSE_EDIT_NEWSGROUPS:
574 if (msg->env->newsgroups)
575 m_strcpy(buf, sizeof(buf), msg->env->newsgroups);
578 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
580 p_delete(&msg->env->newsgroups);
582 msg->env->newsgroups = m_strdup(skipspaces(buf));
583 move (HDR_TO, HDR_XOFFSET);
585 if (msg->env->newsgroups)
586 printw ("%-*.*s", W, W, msg->env->newsgroups);
591 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
594 if (msg->env->followup_to)
595 m_strcpy(buf, sizeof(buf), msg->env->followup_to);
596 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
598 p_delete(&msg->env->followup_to);
600 msg->env->followup_to = m_strdup(skipspaces(buf));
601 move (HDR_CC, HDR_XOFFSET);
603 if (msg->env->followup_to)
604 printw ("%-*.*s", W, W, msg->env->followup_to);
609 case OP_COMPOSE_EDIT_X_COMMENT_TO:
610 if (news && option (OPTXCOMMENTTO)) {
612 if (msg->env->x_comment_to)
613 m_strcpy(buf, sizeof(buf), msg->env->x_comment_to);
614 if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
616 p_delete(&msg->env->x_comment_to);
617 msg->env->x_comment_to = m_strdup(buf);
618 move (HDR_BCC, HDR_XOFFSET);
620 if (msg->env->x_comment_to)
621 printw ("%-*.*s", W, W, msg->env->x_comment_to);
626 case OP_COMPOSE_EDIT_SUBJECT:
627 if (msg->env->subject)
628 m_strcpy(buf, sizeof(buf), msg->env->subject);
631 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
632 m_strreplace(&msg->env->subject, buf);
633 move (HDR_SUBJECT, HDR_XOFFSET + SW);
635 if (msg->env->subject)
636 mutt_paddstr (W, msg->env->subject);
638 mutt_message_hook (NULL, msg, M_SEND2HOOK);
640 case OP_COMPOSE_EDIT_REPLY_TO:
641 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
642 mutt_message_hook (NULL, msg, M_SEND2HOOK);
644 case OP_COMPOSE_EDIT_FCC:
645 m_strcpy(buf, sizeof(buf), fcc);
646 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
647 m_strcpy(fcc, _POSIX_PATH_MAX, buf);
648 mutt_pretty_mailbox (fcc);
649 move (HDR_FCC, HDR_XOFFSET + SW);
650 mutt_paddstr (W, fcc);
653 MAYBE_REDRAW (menu->redraw);
654 mutt_message_hook (NULL, msg, M_SEND2HOOK);
656 case OP_COMPOSE_EDIT_MESSAGE:
657 if (Editor && !option (OPTEDITHDRS)) {
658 mutt_edit_file (Editor, msg->content->filename);
659 mutt_update_encoding (msg->content);
660 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
661 mutt_message_hook (NULL, msg, M_SEND2HOOK);
665 case OP_COMPOSE_EDIT_HEADERS:
666 if ((op == OP_COMPOSE_EDIT_HEADERS ||
667 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
668 const char *tag = NULL;
671 mutt_env_to_local (msg->env);
672 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
674 if (mutt_env_to_idna (msg->env, &tag, &err)) {
675 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
679 mutt_update_encoding (msg->content);
681 /* attachments may have been added */
682 if (idxlen && idx[idxlen - 1]->content->next) {
683 for (i = 0; i < idxlen; i++)
687 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
693 menu->redraw = REDRAW_FULL;
694 mutt_message_hook (NULL, msg, M_SEND2HOOK);
699 case OP_COMPOSE_ATTACH_KEY:
700 if (idxlen == idxmax) {
701 p_realloc(&idx, idxmax += 5);
705 idx[idxlen] = p_new(ATTACHPTR, 1);
706 if ((idx[idxlen]->content =
707 crypt_pgp_make_key_attachment (NULL)) != NULL) {
708 update_idx (menu, idx, idxlen++);
709 menu->redraw |= REDRAW_INDEX;
712 p_delete(&idx[idxlen]);
714 menu->redraw |= REDRAW_STATUS;
716 if (option (OPTNEEDREDRAW)) {
717 menu->redraw = REDRAW_FULL;
718 unset_option (OPTNEEDREDRAW);
721 mutt_message_hook (NULL, msg, M_SEND2HOOK);
725 case OP_COMPOSE_ATTACH_FILE:
727 char *prompt, **files;
731 prompt = _("Attach file");
735 if (_mutt_enter_fname
736 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
737 &numfiles) == -1 || *fname == '\0')
740 if (idxlen + numfiles >= idxmax) {
741 p_realloc(&idx, idxmax += 5 + numfiles);
747 mutt_message _("Attaching selected files...");
749 for (i = 0; i < numfiles; i++) {
750 char *att = files[i];
752 idx[idxlen] = p_new(ATTACHPTR, 1);
753 idx[idxlen]->unowned = 1;
754 idx[idxlen]->content = mutt_make_file_attach (att);
755 if (idx[idxlen]->content != NULL)
756 update_idx (menu, idx, idxlen++);
759 mutt_error (_("Unable to attach %s!"), att);
760 p_delete(&idx[idxlen]);
768 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
770 mutt_message_hook (NULL, msg, M_SEND2HOOK);
773 case OP_COMPOSE_ATTACH_MESSAGE:
775 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
782 prompt = _("Open mailbox to attach message from");
785 unset_option (OPTNEWS);
786 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
787 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
790 prompt = _("Open newsgroup to attach message from");
791 set_option (OPTNEWS);
797 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
800 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
801 mutt_pretty_mailbox (fname);
804 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
809 if (option (OPTNEWS))
810 nntp_expand_path (fname, sizeof (fname),
811 &CurrentNewsSrv->conn->account);
814 mutt_expand_path (fname, sizeof (fname));
815 if (mx_get_magic (fname) != M_IMAP)
816 if (mx_get_magic (fname) != M_POP)
818 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
820 /* check to make sure the file exists and is readable */
821 if (access (fname, R_OK) == -1) {
826 menu->redraw = REDRAW_FULL;
828 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
834 if (!ctx->msgcount) {
835 mx_close_mailbox (ctx, NULL);
837 mutt_error _("No messages in that folder.");
842 this = Context; /* remember current folder and sort methods */
844 oldSortAux = SortAux;
847 set_option (OPTATTACHMSG);
848 mutt_message _("Tag the messages you want to attach!");
850 closed = mutt_index_menu ();
851 unset_option (OPTATTACHMSG);
854 /* go back to the folder we started from */
856 /* Restore old $sort and $sort_aux */
858 SortAux = oldSortAux;
859 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
863 if (idxlen + Context->tagged >= idxmax) {
864 p_realloc(&idx, idxmax += 5 + Context->tagged);
868 for (i = 0; i < Context->msgcount; i++) {
869 h = Context->hdrs[i];
871 idx[idxlen] = p_new(ATTACHPTR, 1);
872 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
873 if (idx[idxlen]->content != NULL)
874 update_idx (menu, idx, idxlen++);
876 mutt_error _("Unable to attach!");
878 p_delete(&idx[idxlen]);
882 menu->redraw |= REDRAW_FULL;
884 if (closed == OP_QUIT)
885 mx_close_mailbox (Context, NULL);
887 mx_fastclose_mailbox (Context);
890 /* go back to the folder we started from */
892 /* Restore old $sort and $sort_aux */
894 SortAux = oldSortAux;
896 mutt_message_hook (NULL, msg, M_SEND2HOOK);
901 if (idx[menu->current]->unowned)
902 idx[menu->current]->content->unlink = 0;
903 if (delete_attachment (menu, &idxlen, menu->current) == -1)
905 mutt_update_tree (idx, idxlen);
907 if (menu->current > idxlen - 1)
908 menu->current = idxlen - 1;
913 if (menu->current == 0)
914 msg->content = idx[0]->content;
916 menu->redraw |= REDRAW_STATUS;
917 mutt_message_hook (NULL, msg, M_SEND2HOOK);
920 #define CURRENT idx[menu->current]->content
922 case OP_COMPOSE_TOGGLE_RECODE:
925 if (!mutt_is_text_part (CURRENT)) {
926 mutt_error (_("Recoding only affects text attachments."));
929 CURRENT->noconv = !CURRENT->noconv;
931 mutt_message (_("The current attachment won't be converted."));
933 mutt_message (_("The current attachment will be converted."));
934 menu->redraw = REDRAW_CURRENT;
935 mutt_message_hook (NULL, msg, M_SEND2HOOK);
940 case OP_COMPOSE_EDIT_DESCRIPTION:
942 m_strcpy(buf, sizeof(buf),
943 NONULL(idx[menu->current]->content->description));
944 /* header names should not be translated */
945 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
946 m_strreplace(&idx[menu->current]->content->description, buf);
947 menu->redraw = REDRAW_CURRENT;
949 mutt_message_hook (NULL, msg, M_SEND2HOOK);
952 case OP_COMPOSE_UPDATE_ENCODING:
954 if (menu->tagprefix) {
957 for (top = msg->content; top; top = top->next) {
959 mutt_update_encoding (top);
961 menu->redraw = REDRAW_FULL;
964 mutt_update_encoding (idx[menu->current]->content);
965 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
967 mutt_message_hook (NULL, msg, M_SEND2HOOK);
970 case OP_COMPOSE_TOGGLE_DISPOSITION:
971 /* toggle the content-disposition between inline/attachment */
972 idx[menu->current]->content->disposition =
973 (idx[menu->current]->content->disposition ==
974 DISPINLINE) ? DISPATTACH : DISPINLINE;
975 menu->redraw = REDRAW_CURRENT;
981 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
983 /* this may have been a change to text/something */
984 mutt_update_encoding (idx[menu->current]->content);
986 menu->redraw = REDRAW_CURRENT;
988 mutt_message_hook (NULL, msg, M_SEND2HOOK);
991 case OP_COMPOSE_EDIT_ENCODING:
993 m_strcpy(buf, sizeof(buf),
994 ENCODING(idx[menu->current]->content->encoding));
995 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
996 sizeof (buf), 0) == 0 && buf[0]) {
997 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
998 idx[menu->current]->content->encoding = i;
999 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1000 mutt_clear_error ();
1003 mutt_error _("Invalid encoding.");
1005 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1008 case OP_COMPOSE_SEND_MESSAGE:
1010 /* Note: We don't invoke send2-hook here, since we want to leave
1011 * users an opportunity to change settings from the ":" prompt.
1014 if (check_attachments (idx, idxlen) != 0) {
1015 menu->redraw = REDRAW_FULL;
1019 if (msg->chain && mix_check_message (msg) != 0)
1022 if (!fccSet && *fcc) {
1023 if ((i = query_quadoption (OPT_COPY,
1024 _("Save a copy of this message?"))) == -1)
1034 case OP_COMPOSE_EDIT_FILE:
1036 mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename);
1037 mutt_update_encoding (idx[menu->current]->content);
1038 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1039 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1042 case OP_COMPOSE_TOGGLE_UNLINK:
1044 idx[menu->current]->content->unlink =
1045 !idx[menu->current]->content->unlink;
1047 menu->redraw = REDRAW_INDEX;
1048 /* No send2hook since this doesn't change the message. */
1051 case OP_COMPOSE_GET_ATTACHMENT:
1053 if (menu->tagprefix) {
1056 for (top = msg->content; top; top = top->next) {
1058 mutt_get_tmp_attachment (top);
1060 menu->redraw = REDRAW_FULL;
1062 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1063 menu->redraw = REDRAW_CURRENT;
1065 /* No send2hook since this doesn't change the message. */
1068 case OP_COMPOSE_RENAME_FILE:
1070 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
1071 mutt_pretty_mailbox (fname);
1072 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1074 if (stat (idx[menu->current]->content->filename, &st) == -1) {
1075 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1079 mutt_expand_path (fname, sizeof (fname));
1080 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1083 m_strreplace(&idx[menu->current]->content->filename, fname);
1084 menu->redraw = REDRAW_CURRENT;
1086 if (idx[menu->current]->content->stamp >= st.st_mtime)
1087 mutt_stamp_attachment (idx[menu->current]->content);
1090 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1093 case OP_COMPOSE_NEW_MIME:
1100 CLEARLINE (LINES - 1);
1102 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1105 mutt_expand_path (fname, sizeof (fname));
1107 /* Call to lookup_mime_type () ? maybe later */
1109 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1113 if (!(p = strchr (type, '/'))) {
1114 mutt_error _("Content-Type is of the form base/sub");
1119 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1120 mutt_error (_("Unknown Content-Type %s"), type);
1123 if (idxlen == idxmax) {
1124 p_realloc(&idx, idxmax += 5);
1128 idx[idxlen] = p_new(ATTACHPTR, 1);
1129 /* Touch the file */
1130 if (!(fp = safe_fopen (fname, "w"))) {
1131 mutt_error (_("Can't create file %s"), fname);
1132 p_delete(&idx[idxlen]);
1137 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1139 _("What we have here is a failure to make an attachment");
1142 update_idx (menu, idx, idxlen++);
1144 idx[menu->current]->content->type = itype;
1145 m_strreplace(&idx[menu->current]->content->subtype, p);
1146 idx[menu->current]->content->unlink = 1;
1147 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1149 if (mutt_compose_attachment (idx[menu->current]->content)) {
1150 mutt_update_encoding (idx[menu->current]->content);
1151 menu->redraw = REDRAW_FULL;
1154 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1157 case OP_COMPOSE_EDIT_MIME:
1159 if (mutt_edit_attachment (idx[menu->current]->content)) {
1160 mutt_update_encoding (idx[menu->current]->content);
1161 menu->redraw = REDRAW_FULL;
1163 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1166 case OP_VIEW_ATTACH:
1167 case OP_DISPLAY_HEADERS:
1169 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1171 menu->redraw = REDRAW_FULL;
1172 /* no send2hook, since this doesn't modify the message */
1177 mutt_save_attachment_list (NULL, menu->tagprefix,
1178 menu->tagprefix ? msg->content : idx[menu->
1180 content, NULL, menu);
1181 MAYBE_REDRAW (menu->redraw);
1182 /* no send2hook, since this doesn't modify the message */
1187 mutt_print_attachment_list (NULL, menu->tagprefix,
1188 menu->tagprefix ? msg->content : idx[menu->
1191 /* no send2hook, since this doesn't modify the message */
1197 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1198 menu->tagprefix ? msg->content : idx[menu->
1200 content, op == OP_FILTER);
1201 if (op == OP_FILTER) /* cte might have changed */
1202 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1203 menu->redraw |= REDRAW_STATUS;
1204 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1209 query_quadoption (OPT_POSTPONE,
1210 _("Postpone this message?"))) == M_NO) {
1211 while (idxlen-- > 0) {
1212 /* avoid freeing other attachments */
1213 idx[idxlen]->content->next = NULL;
1214 idx[idxlen]->content->parts = NULL;
1215 if (idx[idxlen]->unowned)
1216 idx[idxlen]->content->unlink = 0;
1217 body_list_wipe(&idx[idxlen]->content);
1218 p_delete(&idx[idxlen]->tree);
1219 p_delete(&idx[idxlen]);
1231 /* fall through to postpone! */
1233 case OP_COMPOSE_POSTPONE_MESSAGE:
1235 if (check_attachments (idx, idxlen) != 0) {
1236 menu->redraw = REDRAW_FULL;
1244 case OP_COMPOSE_ISPELL:
1246 snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1247 msg->content->filename);
1248 if (mutt_system (buf) == -1)
1249 mutt_error (_("Error running \"%s\"!"), buf);
1251 mutt_update_encoding (msg->content);
1252 menu->redraw |= REDRAW_STATUS;
1256 case OP_COMPOSE_WRITE_MESSAGE:
1260 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
1261 mutt_pretty_mailbox (fname);
1264 msg->content = idx[0]->content;
1265 if (mutt_enter_fname
1266 (_("Write message to mailbox"), fname, sizeof (fname),
1267 &menu->redraw, 1) != -1 && fname[0]) {
1268 mutt_message (_("Writing message to %s ..."), fname);
1269 mutt_expand_path (fname, sizeof (fname));
1271 if (msg->content->next)
1272 msg->content = mutt_make_multipart (msg->content);
1274 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1275 msg->content = mutt_remove_multipart (msg->content);
1277 mutt_message _("Message written.");
1283 case OP_COMPOSE_PGP_MENU:
1284 if (msg->security & APPLICATION_SMIME) {
1285 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1287 mutt_clear_error ();
1292 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1293 redraw_crypt_lines (msg);
1294 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1298 case OP_FORGET_PASSPHRASE:
1299 crypt_forget_passphrase ();
1303 case OP_COMPOSE_SMIME_MENU:
1304 if (msg->security & APPLICATION_PGP) {
1305 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1307 mutt_clear_error ();
1312 msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1313 redraw_crypt_lines (msg);
1314 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1317 case OP_COMPOSE_MIX:
1318 mix_make_chain (&msg->chain, &menu->redraw);
1319 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1323 /* Draw formated compose status line */
1324 if (menu->redraw & REDRAW_STATUS) {
1325 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1326 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1327 SETCOLOR (MT_COLOR_STATUS);
1328 move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
1329 printw ("%-*.*s", COLS-SW, COLS-SW, buf);
1330 SETCOLOR (MT_COLOR_NORMAL);
1331 menu->redraw &= ~REDRAW_STATUS;
1335 mutt_menuDestroy (&menu);
1338 msg->content = idx[0]->content;
1339 for (i = 0; i < idxlen; i++) {
1340 idx[i]->content->aptr = NULL;
1344 msg->content = NULL;