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(MCore.shorthost));
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 (!option (OPTEDITHDRS)) {
651 mutt_edit_file(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(msg->content->filename, msg, fcc, fcclen);
666 if (mutt_env_to_idna (msg->env, &tag, &err)) {
667 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
671 mutt_update_encoding (msg->content);
673 /* attachments may have been added */
674 if (idxlen && idx[idxlen - 1]->content->next) {
675 for (i = 0; i < idxlen; i++)
679 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
685 menu->redraw = REDRAW_FULL;
686 mutt_message_hook (NULL, msg, M_SEND2HOOK);
689 case OP_COMPOSE_ATTACH_KEY:
690 if (idxlen == idxmax) {
691 p_realloc(&idx, idxmax += 5);
695 idx[idxlen] = p_new(ATTACHPTR, 1);
696 if ((idx[idxlen]->content =
697 crypt_pgp_make_key_attachment (NULL)) != NULL) {
698 update_idx (menu, idx, idxlen++);
699 menu->redraw |= REDRAW_INDEX;
702 p_delete(&idx[idxlen]);
704 menu->redraw |= REDRAW_STATUS;
706 if (option (OPTNEEDREDRAW)) {
707 menu->redraw = REDRAW_FULL;
708 unset_option (OPTNEEDREDRAW);
711 mutt_message_hook (NULL, msg, M_SEND2HOOK);
714 case OP_COMPOSE_ATTACH_FILE:
716 char *prompt, **files;
720 prompt = _("Attach file");
724 if (_mutt_enter_fname
725 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
726 &numfiles) == -1 || *fname == '\0')
729 if (idxlen + numfiles >= idxmax) {
730 p_realloc(&idx, idxmax += 5 + numfiles);
736 mutt_message _("Attaching selected files...");
738 for (i = 0; i < numfiles; i++) {
739 char *att = files[i];
741 idx[idxlen] = p_new(ATTACHPTR, 1);
742 idx[idxlen]->unowned = 1;
743 idx[idxlen]->content = mutt_make_file_attach (att);
744 if (idx[idxlen]->content != NULL)
745 update_idx (menu, idx, idxlen++);
748 mutt_error (_("Unable to attach %s!"), att);
749 p_delete(&idx[idxlen]);
757 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
759 mutt_message_hook (NULL, msg, M_SEND2HOOK);
762 case OP_COMPOSE_ATTACH_MESSAGE:
764 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
771 prompt = _("Open mailbox to attach message from");
774 unset_option (OPTNEWS);
775 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
776 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
779 prompt = _("Open newsgroup to attach message from");
780 set_option (OPTNEWS);
786 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
789 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
790 mutt_pretty_mailbox (fname);
793 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
798 if (option (OPTNEWS))
799 nntp_expand_path (fname, sizeof (fname),
800 &CurrentNewsSrv->conn->account);
803 mutt_expand_path (fname, sizeof (fname));
804 if (mx_get_magic (fname) != M_IMAP)
805 if (mx_get_magic (fname) != M_POP)
807 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
809 /* check to make sure the file exists and is readable */
810 if (access (fname, R_OK) == -1) {
815 menu->redraw = REDRAW_FULL;
817 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
823 if (!ctx->msgcount) {
824 mx_close_mailbox (ctx, NULL);
826 mutt_error _("No messages in that folder.");
831 this = Context; /* remember current folder and sort methods */
833 oldSortAux = SortAux;
836 set_option (OPTATTACHMSG);
837 mutt_message _("Tag the messages you want to attach!");
839 closed = mutt_index_menu ();
840 unset_option (OPTATTACHMSG);
843 /* go back to the folder we started from */
845 /* Restore old $sort and $sort_aux */
847 SortAux = oldSortAux;
848 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
852 if (idxlen + Context->tagged >= idxmax) {
853 p_realloc(&idx, idxmax += 5 + Context->tagged);
857 for (i = 0; i < Context->msgcount; i++) {
858 h = Context->hdrs[i];
860 idx[idxlen] = p_new(ATTACHPTR, 1);
861 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
862 if (idx[idxlen]->content != NULL)
863 update_idx (menu, idx, idxlen++);
865 mutt_error _("Unable to attach!");
867 p_delete(&idx[idxlen]);
871 menu->redraw |= REDRAW_FULL;
873 if (closed == OP_QUIT)
874 mx_close_mailbox (Context, NULL);
876 mx_fastclose_mailbox (Context);
879 /* go back to the folder we started from */
881 /* Restore old $sort and $sort_aux */
883 SortAux = oldSortAux;
885 mutt_message_hook (NULL, msg, M_SEND2HOOK);
890 if (idx[menu->current]->unowned)
891 idx[menu->current]->content->unlink = 0;
892 if (delete_attachment (menu, &idxlen, menu->current) == -1)
894 mutt_update_tree (idx, idxlen);
896 if (menu->current > idxlen - 1)
897 menu->current = idxlen - 1;
902 if (menu->current == 0)
903 msg->content = idx[0]->content;
905 menu->redraw |= REDRAW_STATUS;
906 mutt_message_hook (NULL, msg, M_SEND2HOOK);
909 #define CURRENT idx[menu->current]->content
911 case OP_COMPOSE_TOGGLE_RECODE:
914 if (!mutt_is_text_part (CURRENT)) {
915 mutt_error (_("Recoding only affects text attachments."));
918 CURRENT->noconv = !CURRENT->noconv;
920 mutt_message (_("The current attachment won't be converted."));
922 mutt_message (_("The current attachment will be converted."));
923 menu->redraw = REDRAW_CURRENT;
924 mutt_message_hook (NULL, msg, M_SEND2HOOK);
929 case OP_COMPOSE_EDIT_DESCRIPTION:
931 m_strcpy(buf, sizeof(buf),
932 NONULL(idx[menu->current]->content->description));
933 /* header names should not be translated */
934 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
935 m_strreplace(&idx[menu->current]->content->description, buf);
936 menu->redraw = REDRAW_CURRENT;
938 mutt_message_hook (NULL, msg, M_SEND2HOOK);
941 case OP_COMPOSE_UPDATE_ENCODING:
943 if (menu->tagprefix) {
946 for (top = msg->content; top; top = top->next) {
948 mutt_update_encoding (top);
950 menu->redraw = REDRAW_FULL;
953 mutt_update_encoding (idx[menu->current]->content);
954 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
956 mutt_message_hook (NULL, msg, M_SEND2HOOK);
959 case OP_COMPOSE_TOGGLE_DISPOSITION:
960 /* toggle the content-disposition between inline/attachment */
961 idx[menu->current]->content->disposition =
962 (idx[menu->current]->content->disposition ==
963 DISPINLINE) ? DISPATTACH : DISPINLINE;
964 menu->redraw = REDRAW_CURRENT;
970 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
972 /* this may have been a change to text/something */
973 mutt_update_encoding (idx[menu->current]->content);
975 menu->redraw = REDRAW_CURRENT;
977 mutt_message_hook (NULL, msg, M_SEND2HOOK);
980 case OP_COMPOSE_EDIT_ENCODING:
982 m_strcpy(buf, sizeof(buf),
983 ENCODING(idx[menu->current]->content->encoding));
984 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
985 sizeof (buf), 0) == 0 && buf[0]) {
986 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
987 idx[menu->current]->content->encoding = i;
988 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
992 mutt_error _("Invalid encoding.");
994 mutt_message_hook (NULL, msg, M_SEND2HOOK);
997 case OP_COMPOSE_SEND_MESSAGE:
999 /* Note: We don't invoke send2-hook here, since we want to leave
1000 * users an opportunity to change settings from the ":" prompt.
1003 if (check_attachments (idx, idxlen) != 0) {
1004 menu->redraw = REDRAW_FULL;
1008 if (msg->chain && mix_check_message (msg) != 0)
1011 if (!fccSet && *fcc) {
1012 if ((i = query_quadoption (OPT_COPY,
1013 _("Save a copy of this message?"))) == -1)
1023 case OP_COMPOSE_EDIT_FILE:
1025 mutt_edit_file(idx[menu->current]->content->filename);
1026 mutt_update_encoding (idx[menu->current]->content);
1027 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1028 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1031 case OP_COMPOSE_TOGGLE_UNLINK:
1033 idx[menu->current]->content->unlink =
1034 !idx[menu->current]->content->unlink;
1036 menu->redraw = REDRAW_INDEX;
1037 /* No send2hook since this doesn't change the message. */
1040 case OP_COMPOSE_GET_ATTACHMENT:
1042 if (menu->tagprefix) {
1045 for (top = msg->content; top; top = top->next) {
1047 mutt_get_tmp_attachment (top);
1049 menu->redraw = REDRAW_FULL;
1051 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1052 menu->redraw = REDRAW_CURRENT;
1054 /* No send2hook since this doesn't change the message. */
1057 case OP_COMPOSE_RENAME_FILE:
1059 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
1060 mutt_pretty_mailbox (fname);
1061 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1063 if (stat (idx[menu->current]->content->filename, &st) == -1) {
1064 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1068 mutt_expand_path (fname, sizeof (fname));
1069 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1072 m_strreplace(&idx[menu->current]->content->filename, fname);
1073 menu->redraw = REDRAW_CURRENT;
1075 if (idx[menu->current]->content->stamp >= st.st_mtime)
1076 mutt_stamp_attachment (idx[menu->current]->content);
1079 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1082 case OP_COMPOSE_NEW_MIME:
1089 CLEARLINE (LINES - 1);
1091 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1094 mutt_expand_path (fname, sizeof (fname));
1096 /* Call to lookup_mime_type () ? maybe later */
1098 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1102 if (!(p = strchr (type, '/'))) {
1103 mutt_error _("Content-Type is of the form base/sub");
1108 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1109 mutt_error (_("Unknown Content-Type %s"), type);
1112 if (idxlen == idxmax) {
1113 p_realloc(&idx, idxmax += 5);
1117 idx[idxlen] = p_new(ATTACHPTR, 1);
1118 /* Touch the file */
1119 if (!(fp = safe_fopen (fname, "w"))) {
1120 mutt_error (_("Can't create file %s"), fname);
1121 p_delete(&idx[idxlen]);
1126 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1128 _("What we have here is a failure to make an attachment");
1131 update_idx (menu, idx, idxlen++);
1133 idx[menu->current]->content->type = itype;
1134 m_strreplace(&idx[menu->current]->content->subtype, p);
1135 idx[menu->current]->content->unlink = 1;
1136 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1138 if (mutt_compose_attachment (idx[menu->current]->content)) {
1139 mutt_update_encoding (idx[menu->current]->content);
1140 menu->redraw = REDRAW_FULL;
1143 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1146 case OP_COMPOSE_EDIT_MIME:
1148 if (mutt_edit_attachment (idx[menu->current]->content)) {
1149 mutt_update_encoding (idx[menu->current]->content);
1150 menu->redraw = REDRAW_FULL;
1152 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1155 case OP_VIEW_ATTACH:
1156 case OP_DISPLAY_HEADERS:
1158 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1160 menu->redraw = REDRAW_FULL;
1161 /* no send2hook, since this doesn't modify the message */
1166 mutt_save_attachment_list (NULL, menu->tagprefix,
1167 menu->tagprefix ? msg->content : idx[menu->
1169 content, NULL, menu);
1170 MAYBE_REDRAW (menu->redraw);
1171 /* no send2hook, since this doesn't modify the message */
1176 mutt_print_attachment_list (NULL, menu->tagprefix,
1177 menu->tagprefix ? msg->content : idx[menu->
1180 /* no send2hook, since this doesn't modify the message */
1186 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1187 menu->tagprefix ? msg->content : idx[menu->
1189 content, op == OP_FILTER);
1190 if (op == OP_FILTER) /* cte might have changed */
1191 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1192 menu->redraw |= REDRAW_STATUS;
1193 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1198 query_quadoption (OPT_POSTPONE,
1199 _("Postpone this message?"))) == M_NO) {
1200 while (idxlen-- > 0) {
1201 /* avoid freeing other attachments */
1202 idx[idxlen]->content->next = NULL;
1203 idx[idxlen]->content->parts = NULL;
1204 if (idx[idxlen]->unowned)
1205 idx[idxlen]->content->unlink = 0;
1206 body_list_wipe(&idx[idxlen]->content);
1207 p_delete(&idx[idxlen]->tree);
1208 p_delete(&idx[idxlen]);
1220 /* fall through to postpone! */
1222 case OP_COMPOSE_POSTPONE_MESSAGE:
1224 if (check_attachments (idx, idxlen) != 0) {
1225 menu->redraw = REDRAW_FULL;
1233 case OP_COMPOSE_ISPELL:
1235 snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1236 msg->content->filename);
1237 if (mutt_system (buf) == -1)
1238 mutt_error (_("Error running \"%s\"!"), buf);
1240 mutt_update_encoding (msg->content);
1241 menu->redraw |= REDRAW_STATUS;
1245 case OP_COMPOSE_WRITE_MESSAGE:
1249 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
1250 mutt_pretty_mailbox (fname);
1253 msg->content = idx[0]->content;
1254 if (mutt_enter_fname
1255 (_("Write message to mailbox"), fname, sizeof (fname),
1256 &menu->redraw, 1) != -1 && fname[0]) {
1257 mutt_message (_("Writing message to %s ..."), fname);
1258 mutt_expand_path (fname, sizeof (fname));
1260 if (msg->content->next)
1261 msg->content = mutt_make_multipart (msg->content);
1263 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1264 msg->content = mutt_remove_multipart (msg->content);
1266 mutt_message _("Message written.");
1270 case OP_COMPOSE_PGP_MENU:
1271 if (msg->security & APPLICATION_SMIME) {
1272 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1274 mutt_clear_error ();
1279 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1280 redraw_crypt_lines (msg);
1281 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1284 case OP_FORGET_PASSPHRASE:
1285 crypt_forget_passphrase ();
1288 case OP_COMPOSE_SMIME_MENU:
1289 if (msg->security & APPLICATION_PGP) {
1290 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1292 mutt_clear_error ();
1297 msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1298 redraw_crypt_lines (msg);
1299 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1302 case OP_COMPOSE_MIX:
1303 mix_make_chain (&msg->chain, &menu->redraw);
1304 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1308 /* Draw formated compose status line */
1309 if (menu->redraw & REDRAW_STATUS) {
1310 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1311 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1312 SETCOLOR (MT_COLOR_STATUS);
1313 move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
1314 printw ("%-*.*s", COLS-SW, COLS-SW, buf);
1315 SETCOLOR (MT_COLOR_NORMAL);
1316 menu->redraw &= ~REDRAW_STATUS;
1320 mutt_menuDestroy (&menu);
1323 msg->content = idx[0]->content;
1324 for (i = 0; i < idxlen; i++) {
1325 idx[i]->content->aptr = NULL;
1329 msg->content = NULL;