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>
17 #include <lib-mime/mime.h>
18 #include <lib-crypt/crypt.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 m_strformat(b, blen, COLS - SW, AttachFormat, mutt_attach_fmt,
117 ((ATTACHPTR **)menu->data)[num],
118 M_FORMAT_STAT_FILE | (option(OPTARROWCURSOR) ? M_FORMAT_ARROWCURSOR : 0));
121 static void redraw_crypt_lines (HEADER * msg)
126 mvaddstr (HDR_CRYPT, SW, " Security: ");
127 else if (msg->security & APPLICATION_SMIME)
128 mvaddstr (HDR_CRYPT, SW, " S/MIME: ");
129 else if (msg->security & APPLICATION_PGP)
130 mvaddstr (HDR_CRYPT, SW, " PGP: ");
132 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
133 addstr (_("Sign, Encrypt"));
134 else if (msg->security & ENCRYPT)
135 addstr (_("Encrypt"));
136 else if (msg->security & SIGN)
141 if ((msg->security & APPLICATION_PGP)
142 && (msg->security & (ENCRYPT | SIGN))) {
143 if ((msg->security & INLINE))
144 addstr (_(" (inline)"));
146 addstr (_(" (PGP/MIME)"));
150 move (HDR_CRYPTINFO, SW);
152 if (msg->security & APPLICATION_PGP && msg->security & SIGN)
153 printw ("%s%s", _(" sign as: "),
154 PgpSignAs ? PgpSignAs : _("<default>"));
156 if (msg->security & APPLICATION_SMIME && msg->security & SIGN) {
157 printw ("%s%s", _(" sign as: "),
158 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
161 if ((msg->security & APPLICATION_SMIME)
162 && (msg->security & ENCRYPT)
163 && SmimeCryptAlg && *SmimeCryptAlg) {
164 mvprintw (HDR_CRYPTINFO, SW + 40, "%s%s", _("Encrypt with: "),
165 NONULL (SmimeCryptAlg));
170 static void redraw_mix_line (string_list_t * chain)
175 mvaddstr (HDR_MIX, SW, " Mix: ");
178 addstr ("<no chain defined>");
183 for (c = 12; chain; chain = chain->next) {
185 if (t && t[0] == '0' && t[1] == '\0')
188 if (c + m_strlen(t) + 2 >= COLS - SW)
195 c += m_strlen(t) + 2;
199 static int check_attachments (ATTACHPTR ** idx, short idxlen)
203 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + STRING];
205 for (i = 0; i < idxlen; i++) {
206 m_strcpy(pretty, sizeof(pretty), idx[i]->content->filename);
207 if (stat (idx[i]->content->filename, &st) != 0) {
208 mutt_pretty_mailbox (pretty);
209 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
213 if (idx[i]->content->stamp < st.st_mtime) {
214 mutt_pretty_mailbox (pretty);
215 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
218 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
219 mutt_update_encoding (idx[i]->content);
228 static void draw_envelope_addr (int line, address_t * addr)
233 rfc822_addrcat(buf, sizeof (buf), addr, 1);
234 mvprintw (line, SW, TITLE_FMT, Prompts[line - 1]);
235 mutt_paddstr (W, buf);
238 static void draw_envelope (HEADER * msg, char *fcc)
240 draw_envelope_addr (HDR_FROM, msg->env->from);
242 if (!option (OPTNEWSSEND)) {
244 draw_envelope_addr (HDR_TO, msg->env->to);
245 draw_envelope_addr (HDR_CC, msg->env->cc);
246 draw_envelope_addr (HDR_BCC, msg->env->bcc);
249 mvprintw (HDR_TO, SW, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
250 mutt_paddstr (W, NONULL (msg->env->newsgroups));
251 mvprintw (HDR_CC, SW, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
252 mutt_paddstr (W, NONULL (msg->env->followup_to));
253 if (option (OPTXCOMMENTTO)) {
254 mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]);
255 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
259 mvprintw (HDR_SUBJECT, SW, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
260 mutt_paddstr (W, NONULL (msg->env->subject));
261 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
262 mvprintw (HDR_FCC, SW, TITLE_FMT, Prompts[HDR_FCC - 1]);
263 mutt_paddstr (W, fcc);
265 redraw_crypt_lines (msg);
266 redraw_mix_line (msg->chain);
268 SETCOLOR (MT_COLOR_STATUS);
269 mvaddstr (HDR_ATTACH - 1, SW, _("-- Attachments"));
270 BKGDSET (MT_COLOR_STATUS);
273 BKGDSET (MT_COLOR_NORMAL);
274 SETCOLOR (MT_COLOR_NORMAL);
277 static int edit_address_list (int line, address_t ** addr)
279 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
282 mutt_addrlist_to_local (*addr);
283 rfc822_addrcat(buf, sizeof (buf), *addr, 0);
284 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
285 address_list_wipe(addr);
286 *addr = mutt_parse_adrlist (*addr, buf);
287 *addr = mutt_expand_aliases (*addr);
290 if (option (OPTNEEDREDRAW)) {
291 unset_option (OPTNEEDREDRAW);
295 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
296 mutt_error (_("Warning: '%s' is a bad IDN."), err);
301 /* redraw the expanded list so the user can see the result */
303 rfc822_addrcat(buf, sizeof (buf), *addr, 1);
304 move (line, HDR_XOFFSET + SW);
305 mutt_paddstr (W, buf);
310 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
312 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
315 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
317 if (x == 0 && menu->max == 1) {
318 mutt_error _("You may not delete the only attachment.");
320 idx[x]->content->tagged = 0;
324 for (y = 0; y < *idxlen; y++) {
325 if (idx[y]->content->next == idx[x]->content) {
326 idx[y]->content->next = idx[x]->content->next;
331 idx[x]->content->next = NULL;
332 idx[x]->content->parts = NULL;
333 body_list_wipe(&(idx[x]->content));
334 p_delete(&idx[x]->tree);
336 for (; x < *idxlen - 1; x++)
338 menu->max = --(*idxlen);
343 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
345 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
347 idx[idxlen - 1]->content->next = idx[idxlen]->content;
348 idx[idxlen]->content->aptr = idx[idxlen];
349 menu->current = idxlen++;
350 mutt_update_tree (idx, idxlen);
357 * cum_attachs_size: Cumulative Attachments Size
359 * Returns the total number of bytes used by the attachments in the
360 * attachment list _after_ content-transfer-encodings have been
364 static unsigned long cum_attachs_size(MUTTMENU * menu)
368 ATTACHPTR **idx = menu->data;
372 for (i = 0, s = 0; i < menu->max; i++) {
376 b->content = mutt_get_content_info (b->filename, b);
378 if ((info = b->content)) {
379 switch (b->encoding) {
380 case ENCQUOTEDPRINTABLE:
381 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
384 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
387 s += info->lobin + info->hibin + info->ascii + info->crlf;
397 * compose_format_str()
399 * %a = total number of attachments
400 * %h = hostname [option]
401 * %l = approx. length of current message (in bytes)
404 * This function is similar to status_format_str(). Look at that function for
405 * help when modifying this function.
407 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
410 static const char *compose_format_str (char *buf, ssize_t buflen, char op,
411 const char *src, const char *prefix,
414 anytype data, format_flag flags)
416 char fmt[STRING], tmp[STRING];
417 int optional = (flags & M_FORMAT_OPTIONAL);
418 MUTTMENU *menu = data.ptr;
422 case 'a': /* total number of attachments */
423 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
424 snprintf (buf, buflen, fmt, menu->max);
427 case 'h': /* hostname */
428 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
429 snprintf (buf, buflen, fmt, NONULL (Hostname));
432 case 'l': /* approx length of current message in bytes */
433 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
434 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
435 snprintf (buf, buflen, fmt, tmp);
439 m_strcpy(buf, buflen, mutt_make_version());
451 if (flags & M_FORMAT_OPTIONAL)
452 compose_status_line(buf, buflen, menu, optional ? ifstr : elstr);
457 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
460 m_strformat(buf, buflen, COLS - SW, p, compose_format_str, menu, 0);
465 * 1 message should be postponed
469 int mutt_compose_menu (HEADER * msg, /* structure for new message */
470 char *fcc, /* where to save a copy of the message */
472 HEADER * cur __attribute__ ((unused)))
473 { /* current message */
474 char helpstr[STRING];
475 char buf[LONG_STRING];
476 char fname[_POSIX_PATH_MAX];
478 ATTACHPTR **idx = NULL;
482 int r = -1; /* return value */
485 int fccSet = 0; /* has the user edited the Fcc: field ? */
486 CONTEXT *ctx = NULL, *this = NULL;
488 /* Sort, SortAux could be changed in mutt_index_menu() */
489 int oldSort, oldSortAux;
493 int news = 0; /* is it a news article ? */
495 if (option (OPTNEWSSEND))
499 mutt_attach_init (msg->content);
500 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
502 menu = mutt_new_menu ();
503 menu->menu = MENU_COMPOSE;
504 menu->offset = HDR_ATTACH;
506 menu->make_entry = snd_entry;
507 menu->tag = mutt_tag_attach;
511 menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_COMPOSE,
515 menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_COMPOSE,
518 if (option (OPTMBOXPANE))
522 unset_option (OPTNEWS); /* for any case */
524 switch (op = mutt_menuLoop (menu)) {
526 draw_envelope (msg, fcc);
527 menu->offset = HDR_ATTACH;
528 menu->pagelen = LINES - HDR_ATTACH - 2;
530 case OP_COMPOSE_EDIT_FROM:
531 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
532 mutt_message_hook (NULL, msg, M_SEND2HOOK);
534 case OP_COMPOSE_EDIT_TO:
538 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
539 mutt_message_hook (NULL, msg, M_SEND2HOOK);
544 case OP_COMPOSE_EDIT_BCC:
548 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
549 mutt_message_hook (NULL, msg, M_SEND2HOOK);
554 case OP_COMPOSE_EDIT_CC:
558 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
559 mutt_message_hook (NULL, msg, M_SEND2HOOK);
565 case OP_COMPOSE_EDIT_NEWSGROUPS:
567 if (msg->env->newsgroups)
568 m_strcpy(buf, sizeof(buf), msg->env->newsgroups);
571 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
573 p_delete(&msg->env->newsgroups);
575 msg->env->newsgroups = m_strdup(skipspaces(buf));
576 move (HDR_TO, HDR_XOFFSET);
578 if (msg->env->newsgroups)
579 printw ("%-*.*s", W, W, msg->env->newsgroups);
584 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
587 if (msg->env->followup_to)
588 m_strcpy(buf, sizeof(buf), msg->env->followup_to);
589 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
591 p_delete(&msg->env->followup_to);
593 msg->env->followup_to = m_strdup(skipspaces(buf));
594 move (HDR_CC, HDR_XOFFSET);
596 if (msg->env->followup_to)
597 printw ("%-*.*s", W, W, msg->env->followup_to);
602 case OP_COMPOSE_EDIT_X_COMMENT_TO:
603 if (news && option (OPTXCOMMENTTO)) {
605 if (msg->env->x_comment_to)
606 m_strcpy(buf, sizeof(buf), msg->env->x_comment_to);
607 if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
609 p_delete(&msg->env->x_comment_to);
610 msg->env->x_comment_to = m_strdup(buf);
611 move (HDR_BCC, HDR_XOFFSET);
613 if (msg->env->x_comment_to)
614 printw ("%-*.*s", W, W, msg->env->x_comment_to);
619 case OP_COMPOSE_EDIT_SUBJECT:
620 if (msg->env->subject)
621 m_strcpy(buf, sizeof(buf), msg->env->subject);
624 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
625 m_strreplace(&msg->env->subject, buf);
626 move (HDR_SUBJECT, HDR_XOFFSET + SW);
628 if (msg->env->subject)
629 mutt_paddstr (W, msg->env->subject);
631 mutt_message_hook (NULL, msg, M_SEND2HOOK);
633 case OP_COMPOSE_EDIT_REPLY_TO:
634 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
635 mutt_message_hook (NULL, msg, M_SEND2HOOK);
637 case OP_COMPOSE_EDIT_FCC:
638 m_strcpy(buf, sizeof(buf), fcc);
639 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
640 m_strcpy(fcc, _POSIX_PATH_MAX, buf);
641 mutt_pretty_mailbox (fcc);
642 move (HDR_FCC, HDR_XOFFSET + SW);
643 mutt_paddstr (W, fcc);
646 MAYBE_REDRAW (menu->redraw);
647 mutt_message_hook (NULL, msg, M_SEND2HOOK);
649 case OP_COMPOSE_EDIT_MESSAGE:
650 if (Editor && !option (OPTEDITHDRS)) {
651 mutt_edit_file (Editor, msg->content->filename);
652 mutt_update_encoding (msg->content);
653 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
654 mutt_message_hook (NULL, msg, M_SEND2HOOK);
658 case OP_COMPOSE_EDIT_HEADERS:
659 if ((op == OP_COMPOSE_EDIT_HEADERS ||
660 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
661 const char *tag = NULL;
664 mutt_env_to_local (msg->env);
665 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
667 if (mutt_env_to_idna (msg->env, &tag, &err)) {
668 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
672 mutt_update_encoding (msg->content);
674 /* attachments may have been added */
675 if (idxlen && idx[idxlen - 1]->content->next) {
676 for (i = 0; i < idxlen; i++)
680 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
686 menu->redraw = REDRAW_FULL;
687 mutt_message_hook (NULL, msg, M_SEND2HOOK);
690 case OP_COMPOSE_ATTACH_KEY:
691 if (idxlen == idxmax) {
692 p_realloc(&idx, idxmax += 5);
696 idx[idxlen] = p_new(ATTACHPTR, 1);
697 if ((idx[idxlen]->content =
698 crypt_pgp_make_key_attachment (NULL)) != NULL) {
699 update_idx (menu, idx, idxlen++);
700 menu->redraw |= REDRAW_INDEX;
703 p_delete(&idx[idxlen]);
705 menu->redraw |= REDRAW_STATUS;
707 if (option (OPTNEEDREDRAW)) {
708 menu->redraw = REDRAW_FULL;
709 unset_option (OPTNEEDREDRAW);
712 mutt_message_hook (NULL, msg, M_SEND2HOOK);
715 case OP_COMPOSE_ATTACH_FILE:
717 char *prompt, **files;
721 prompt = _("Attach file");
725 if (_mutt_enter_fname
726 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
727 &numfiles) == -1 || *fname == '\0')
730 if (idxlen + numfiles >= idxmax) {
731 p_realloc(&idx, idxmax += 5 + numfiles);
737 mutt_message _("Attaching selected files...");
739 for (i = 0; i < numfiles; i++) {
740 char *att = files[i];
742 idx[idxlen] = p_new(ATTACHPTR, 1);
743 idx[idxlen]->unowned = 1;
744 idx[idxlen]->content = mutt_make_file_attach (att);
745 if (idx[idxlen]->content != NULL)
746 update_idx (menu, idx, idxlen++);
749 mutt_error (_("Unable to attach %s!"), att);
750 p_delete(&idx[idxlen]);
758 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
760 mutt_message_hook (NULL, msg, M_SEND2HOOK);
763 case OP_COMPOSE_ATTACH_MESSAGE:
765 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
772 prompt = _("Open mailbox to attach message from");
775 unset_option (OPTNEWS);
776 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
777 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
780 prompt = _("Open newsgroup to attach message from");
781 set_option (OPTNEWS);
787 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
790 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
791 mutt_pretty_mailbox (fname);
794 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
799 if (option (OPTNEWS))
800 nntp_expand_path (fname, sizeof (fname),
801 &CurrentNewsSrv->conn->account);
804 mutt_expand_path (fname, sizeof (fname));
805 if (mx_get_magic (fname) != M_IMAP)
806 if (mx_get_magic (fname) != M_POP)
808 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
810 /* check to make sure the file exists and is readable */
811 if (access (fname, R_OK) == -1) {
816 menu->redraw = REDRAW_FULL;
818 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
824 if (!ctx->msgcount) {
825 mx_close_mailbox (ctx, NULL);
827 mutt_error _("No messages in that folder.");
832 this = Context; /* remember current folder and sort methods */
834 oldSortAux = SortAux;
837 set_option (OPTATTACHMSG);
838 mutt_message _("Tag the messages you want to attach!");
840 closed = mutt_index_menu ();
841 unset_option (OPTATTACHMSG);
844 /* go back to the folder we started from */
846 /* Restore old $sort and $sort_aux */
848 SortAux = oldSortAux;
849 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
853 if (idxlen + Context->tagged >= idxmax) {
854 p_realloc(&idx, idxmax += 5 + Context->tagged);
858 for (i = 0; i < Context->msgcount; i++) {
859 h = Context->hdrs[i];
861 idx[idxlen] = p_new(ATTACHPTR, 1);
862 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
863 if (idx[idxlen]->content != NULL)
864 update_idx (menu, idx, idxlen++);
866 mutt_error _("Unable to attach!");
868 p_delete(&idx[idxlen]);
872 menu->redraw |= REDRAW_FULL;
874 if (closed == OP_QUIT)
875 mx_close_mailbox (Context, NULL);
877 mx_fastclose_mailbox (Context);
880 /* go back to the folder we started from */
882 /* Restore old $sort and $sort_aux */
884 SortAux = oldSortAux;
886 mutt_message_hook (NULL, msg, M_SEND2HOOK);
891 if (idx[menu->current]->unowned)
892 idx[menu->current]->content->unlink = 0;
893 if (delete_attachment (menu, &idxlen, menu->current) == -1)
895 mutt_update_tree (idx, idxlen);
897 if (menu->current > idxlen - 1)
898 menu->current = idxlen - 1;
903 if (menu->current == 0)
904 msg->content = idx[0]->content;
906 menu->redraw |= REDRAW_STATUS;
907 mutt_message_hook (NULL, msg, M_SEND2HOOK);
910 #define CURRENT idx[menu->current]->content
912 case OP_COMPOSE_TOGGLE_RECODE:
915 if (!mutt_is_text_part (CURRENT)) {
916 mutt_error (_("Recoding only affects text attachments."));
919 CURRENT->noconv = !CURRENT->noconv;
921 mutt_message (_("The current attachment won't be converted."));
923 mutt_message (_("The current attachment will be converted."));
924 menu->redraw = REDRAW_CURRENT;
925 mutt_message_hook (NULL, msg, M_SEND2HOOK);
930 case OP_COMPOSE_EDIT_DESCRIPTION:
932 m_strcpy(buf, sizeof(buf),
933 NONULL(idx[menu->current]->content->description));
934 /* header names should not be translated */
935 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
936 m_strreplace(&idx[menu->current]->content->description, buf);
937 menu->redraw = REDRAW_CURRENT;
939 mutt_message_hook (NULL, msg, M_SEND2HOOK);
942 case OP_COMPOSE_UPDATE_ENCODING:
944 if (menu->tagprefix) {
947 for (top = msg->content; top; top = top->next) {
949 mutt_update_encoding (top);
951 menu->redraw = REDRAW_FULL;
954 mutt_update_encoding (idx[menu->current]->content);
955 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
957 mutt_message_hook (NULL, msg, M_SEND2HOOK);
960 case OP_COMPOSE_TOGGLE_DISPOSITION:
961 /* toggle the content-disposition between inline/attachment */
962 idx[menu->current]->content->disposition =
963 (idx[menu->current]->content->disposition ==
964 DISPINLINE) ? DISPATTACH : DISPINLINE;
965 menu->redraw = REDRAW_CURRENT;
971 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
973 /* this may have been a change to text/something */
974 mutt_update_encoding (idx[menu->current]->content);
976 menu->redraw = REDRAW_CURRENT;
978 mutt_message_hook (NULL, msg, M_SEND2HOOK);
981 case OP_COMPOSE_EDIT_ENCODING:
983 m_strcpy(buf, sizeof(buf),
984 ENCODING(idx[menu->current]->content->encoding));
985 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
986 sizeof (buf), 0) == 0 && buf[0]) {
987 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
988 idx[menu->current]->content->encoding = i;
989 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
993 mutt_error _("Invalid encoding.");
995 mutt_message_hook (NULL, msg, M_SEND2HOOK);
998 case OP_COMPOSE_SEND_MESSAGE:
1000 /* Note: We don't invoke send2-hook here, since we want to leave
1001 * users an opportunity to change settings from the ":" prompt.
1004 if (check_attachments (idx, idxlen) != 0) {
1005 menu->redraw = REDRAW_FULL;
1009 if (msg->chain && mix_check_message (msg) != 0)
1012 if (!fccSet && *fcc) {
1013 if ((i = query_quadoption (OPT_COPY,
1014 _("Save a copy of this message?"))) == -1)
1024 case OP_COMPOSE_EDIT_FILE:
1026 mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename);
1027 mutt_update_encoding (idx[menu->current]->content);
1028 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1029 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1032 case OP_COMPOSE_TOGGLE_UNLINK:
1034 idx[menu->current]->content->unlink =
1035 !idx[menu->current]->content->unlink;
1037 menu->redraw = REDRAW_INDEX;
1038 /* No send2hook since this doesn't change the message. */
1041 case OP_COMPOSE_GET_ATTACHMENT:
1043 if (menu->tagprefix) {
1046 for (top = msg->content; top; top = top->next) {
1048 mutt_get_tmp_attachment (top);
1050 menu->redraw = REDRAW_FULL;
1052 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1053 menu->redraw = REDRAW_CURRENT;
1055 /* No send2hook since this doesn't change the message. */
1058 case OP_COMPOSE_RENAME_FILE:
1060 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
1061 mutt_pretty_mailbox (fname);
1062 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1064 if (stat (idx[menu->current]->content->filename, &st) == -1) {
1065 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1069 mutt_expand_path (fname, sizeof (fname));
1070 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1073 m_strreplace(&idx[menu->current]->content->filename, fname);
1074 menu->redraw = REDRAW_CURRENT;
1076 if (idx[menu->current]->content->stamp >= st.st_mtime)
1077 mutt_stamp_attachment (idx[menu->current]->content);
1080 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1083 case OP_COMPOSE_NEW_MIME:
1090 CLEARLINE (LINES - 1);
1092 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1095 mutt_expand_path (fname, sizeof (fname));
1097 /* Call to lookup_mime_type () ? maybe later */
1099 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1103 if (!(p = strchr (type, '/'))) {
1104 mutt_error _("Content-Type is of the form base/sub");
1109 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1110 mutt_error (_("Unknown Content-Type %s"), type);
1113 if (idxlen == idxmax) {
1114 p_realloc(&idx, idxmax += 5);
1118 idx[idxlen] = p_new(ATTACHPTR, 1);
1119 /* Touch the file */
1120 if (!(fp = safe_fopen (fname, "w"))) {
1121 mutt_error (_("Can't create file %s"), fname);
1122 p_delete(&idx[idxlen]);
1127 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1129 _("What we have here is a failure to make an attachment");
1132 update_idx (menu, idx, idxlen++);
1134 idx[menu->current]->content->type = itype;
1135 m_strreplace(&idx[menu->current]->content->subtype, p);
1136 idx[menu->current]->content->unlink = 1;
1137 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1139 if (mutt_compose_attachment (idx[menu->current]->content)) {
1140 mutt_update_encoding (idx[menu->current]->content);
1141 menu->redraw = REDRAW_FULL;
1144 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1147 case OP_COMPOSE_EDIT_MIME:
1149 if (mutt_edit_attachment (idx[menu->current]->content)) {
1150 mutt_update_encoding (idx[menu->current]->content);
1151 menu->redraw = REDRAW_FULL;
1153 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1156 case OP_VIEW_ATTACH:
1157 case OP_DISPLAY_HEADERS:
1159 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1161 menu->redraw = REDRAW_FULL;
1162 /* no send2hook, since this doesn't modify the message */
1167 mutt_save_attachment_list (NULL, menu->tagprefix,
1168 menu->tagprefix ? msg->content : idx[menu->
1170 content, NULL, menu);
1171 MAYBE_REDRAW (menu->redraw);
1172 /* no send2hook, since this doesn't modify the message */
1177 mutt_print_attachment_list (NULL, menu->tagprefix,
1178 menu->tagprefix ? msg->content : idx[menu->
1181 /* no send2hook, since this doesn't modify the message */
1187 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1188 menu->tagprefix ? msg->content : idx[menu->
1190 content, op == OP_FILTER);
1191 if (op == OP_FILTER) /* cte might have changed */
1192 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1193 menu->redraw |= REDRAW_STATUS;
1194 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1199 query_quadoption (OPT_POSTPONE,
1200 _("Postpone this message?"))) == M_NO) {
1201 while (idxlen-- > 0) {
1202 /* avoid freeing other attachments */
1203 idx[idxlen]->content->next = NULL;
1204 idx[idxlen]->content->parts = NULL;
1205 if (idx[idxlen]->unowned)
1206 idx[idxlen]->content->unlink = 0;
1207 body_list_wipe(&idx[idxlen]->content);
1208 p_delete(&idx[idxlen]->tree);
1209 p_delete(&idx[idxlen]);
1221 /* fall through to postpone! */
1223 case OP_COMPOSE_POSTPONE_MESSAGE:
1225 if (check_attachments (idx, idxlen) != 0) {
1226 menu->redraw = REDRAW_FULL;
1234 case OP_COMPOSE_ISPELL:
1236 snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1237 msg->content->filename);
1238 if (mutt_system (buf) == -1)
1239 mutt_error (_("Error running \"%s\"!"), buf);
1241 mutt_update_encoding (msg->content);
1242 menu->redraw |= REDRAW_STATUS;
1246 case OP_COMPOSE_WRITE_MESSAGE:
1250 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
1251 mutt_pretty_mailbox (fname);
1254 msg->content = idx[0]->content;
1255 if (mutt_enter_fname
1256 (_("Write message to mailbox"), fname, sizeof (fname),
1257 &menu->redraw, 1) != -1 && fname[0]) {
1258 mutt_message (_("Writing message to %s ..."), fname);
1259 mutt_expand_path (fname, sizeof (fname));
1261 if (msg->content->next)
1262 msg->content = mutt_make_multipart (msg->content);
1264 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1265 msg->content = mutt_remove_multipart (msg->content);
1267 mutt_message _("Message written.");
1271 case OP_COMPOSE_PGP_MENU:
1272 if (msg->security & APPLICATION_SMIME) {
1273 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1275 mutt_clear_error ();
1280 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1281 redraw_crypt_lines (msg);
1282 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1285 case OP_FORGET_PASSPHRASE:
1286 crypt_forget_passphrase ();
1289 case OP_COMPOSE_SMIME_MENU:
1290 if (msg->security & APPLICATION_PGP) {
1291 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1293 mutt_clear_error ();
1298 msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1299 redraw_crypt_lines (msg);
1300 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1303 case OP_COMPOSE_MIX:
1304 mix_make_chain (&msg->chain, &menu->redraw);
1305 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1309 /* Draw formated compose status line */
1310 if (menu->redraw & REDRAW_STATUS) {
1311 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1312 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1313 SETCOLOR (MT_COLOR_STATUS);
1314 move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
1315 printw ("%-*.*s", COLS-SW, COLS-SW, buf);
1316 SETCOLOR (MT_COLOR_NORMAL);
1317 menu->redraw &= ~REDRAW_STATUS;
1321 mutt_menuDestroy (&menu);
1324 msg->content = idx[0]->content;
1325 for (i = 0; i < idxlen; i++) {
1326 idx[i]->content->aptr = NULL;
1330 msg->content = NULL;