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.
18 #include <lib-lib/mem.h>
19 #include <lib-lib/str.h>
20 #include <lib-lib/macros.h>
21 #include <lib-lib/file.h>
22 #include <lib-lib/mapping.h>
24 #include <lib-mime/mime.h>
28 #include "mutt_curses.h"
29 #include "mutt_idna.h"
30 #include "mutt_menu.h"
33 #include "recvattach.h"
56 static const char *There_are_no_attachments = N_("There are no attachments.");
58 #define CHECK_COUNT if (idxlen == 0) { mutt_error _(There_are_no_attachments); break; }
85 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
87 HDR_ATTACH = (HDR_FCC + 7)
91 #define HDR_XOFFSET 14
92 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
93 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
94 #define W (COLS - HDR_XOFFSET - SW)
96 static const char *Prompts[] = {
108 , "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: "
112 static struct mapping_t ComposeHelp[] = {
113 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
114 {N_("Abort"), OP_EXIT},
115 {"To", OP_COMPOSE_EDIT_TO},
116 {"CC", OP_COMPOSE_EDIT_CC},
117 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
118 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
119 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
120 {N_("Help"), OP_HELP},
125 static struct mapping_t ComposeNewsHelp[] = {
126 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
127 {N_("Abort"), OP_EXIT},
128 {"Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS},
129 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
130 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
131 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
132 {N_("Help"), OP_HELP},
138 static void snd_entry (char *b, ssize_t blen, MUTTMENU * menu, int num) {
139 int w=(COLS-SW)>blen?blen:COLS-SW;
140 mutt_FormatString (b, w, NONULL (AttachFormat), mutt_attach_fmt,
141 (unsigned long) (((ATTACHPTR **) menu->data)[num]),
142 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
145 #include <lib-crypt/crypt.h>
147 static void redraw_crypt_lines (HEADER * msg)
152 mvaddstr (HDR_CRYPT, SW, " Security: ");
153 else if (msg->security & APPLICATION_SMIME)
154 mvaddstr (HDR_CRYPT, SW, " S/MIME: ");
155 else if (msg->security & APPLICATION_PGP)
156 mvaddstr (HDR_CRYPT, SW, " PGP: ");
158 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
159 addstr (_("Sign, Encrypt"));
160 else if (msg->security & ENCRYPT)
161 addstr (_("Encrypt"));
162 else if (msg->security & SIGN)
167 if ((msg->security & APPLICATION_PGP)
168 && (msg->security & (ENCRYPT | SIGN))) {
169 if ((msg->security & INLINE))
170 addstr (_(" (inline)"));
172 addstr (_(" (PGP/MIME)"));
176 move (HDR_CRYPTINFO, SW);
178 if (msg->security & APPLICATION_PGP && msg->security & SIGN)
179 printw ("%s%s", _(" sign as: "),
180 PgpSignAs ? PgpSignAs : _("<default>"));
182 if (msg->security & APPLICATION_SMIME && msg->security & SIGN) {
183 printw ("%s%s", _(" sign as: "),
184 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
187 if ((msg->security & APPLICATION_SMIME)
188 && (msg->security & ENCRYPT)
189 && SmimeCryptAlg && *SmimeCryptAlg) {
190 mvprintw (HDR_CRYPTINFO, SW + 40, "%s%s", _("Encrypt with: "),
191 NONULL (SmimeCryptAlg));
199 static void redraw_mix_line (LIST * chain)
204 mvaddstr (HDR_MIX, SW, " Mix: ");
207 addstr ("<no chain defined>");
212 for (c = 12; chain; chain = chain->next) {
214 if (t && t[0] == '0' && t[1] == '\0')
217 if (c + m_strlen(t) + 2 >= COLS - SW)
224 c += m_strlen(t) + 2;
227 #endif /* MIXMASTER */
229 static int check_attachments (ATTACHPTR ** idx, short idxlen)
233 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
235 for (i = 0; i < idxlen; i++) {
236 m_strcpy(pretty, sizeof(pretty), idx[i]->content->filename);
237 if (stat (idx[i]->content->filename, &st) != 0) {
238 mutt_pretty_mailbox (pretty);
239 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
243 if (idx[i]->content->stamp < st.st_mtime) {
244 mutt_pretty_mailbox (pretty);
245 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
248 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
249 mutt_update_encoding (idx[i]->content);
258 static void draw_envelope_addr (int line, address_t * addr)
263 rfc822_write_address (buf, sizeof (buf), addr, 1);
264 mvprintw (line, SW, TITLE_FMT, Prompts[line - 1]);
265 mutt_paddstr (W, buf);
268 static void draw_envelope (HEADER * msg, char *fcc)
270 draw_envelope_addr (HDR_FROM, msg->env->from);
272 if (!option (OPTNEWSSEND)) {
274 draw_envelope_addr (HDR_TO, msg->env->to);
275 draw_envelope_addr (HDR_CC, msg->env->cc);
276 draw_envelope_addr (HDR_BCC, msg->env->bcc);
280 mvprintw (HDR_TO, SW, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
281 mutt_paddstr (W, NONULL (msg->env->newsgroups));
282 mvprintw (HDR_CC, SW, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
283 mutt_paddstr (W, NONULL (msg->env->followup_to));
284 if (option (OPTXCOMMENTTO)) {
285 mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]);
286 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
290 mvprintw (HDR_SUBJECT, SW, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
291 mutt_paddstr (W, NONULL (msg->env->subject));
292 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
293 mvprintw (HDR_FCC, SW, TITLE_FMT, Prompts[HDR_FCC - 1]);
294 mutt_paddstr (W, fcc);
296 redraw_crypt_lines (msg);
299 redraw_mix_line (msg->chain);
302 SETCOLOR (MT_COLOR_STATUS);
303 mvaddstr (HDR_ATTACH - 1, SW, _("-- Attachments"));
304 BKGDSET (MT_COLOR_STATUS);
307 BKGDSET (MT_COLOR_NORMAL);
308 SETCOLOR (MT_COLOR_NORMAL);
311 static int edit_address_list (int line, address_t ** addr)
313 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
316 mutt_addrlist_to_local (*addr);
317 rfc822_write_address (buf, sizeof (buf), *addr, 0);
318 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
319 address_delete (addr);
320 *addr = mutt_parse_adrlist (*addr, buf);
321 *addr = mutt_expand_aliases (*addr);
324 if (option (OPTNEEDREDRAW)) {
325 unset_option (OPTNEEDREDRAW);
326 return (REDRAW_FULL);
329 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
330 mutt_error (_("Warning: '%s' is a bad IDN."), err);
335 /* redraw the expanded list so the user can see the result */
337 rfc822_write_address (buf, sizeof (buf), *addr, 1);
338 move (line, HDR_XOFFSET + SW);
339 mutt_paddstr (W, buf);
344 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
346 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
349 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
351 if (x == 0 && menu->max == 1) {
352 mutt_error _("You may not delete the only attachment.");
354 idx[x]->content->tagged = 0;
358 for (y = 0; y < *idxlen; y++) {
359 if (idx[y]->content->next == idx[x]->content) {
360 idx[y]->content->next = idx[x]->content->next;
365 idx[x]->content->next = NULL;
366 idx[x]->content->parts = NULL;
367 mutt_free_body (&(idx[x]->content));
368 p_delete(&idx[x]->tree);
370 for (; x < *idxlen - 1; x++)
372 menu->max = --(*idxlen);
377 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
379 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
381 idx[idxlen - 1]->content->next = idx[idxlen]->content;
382 idx[idxlen]->content->aptr = idx[idxlen];
383 menu->current = idxlen++;
384 mutt_update_tree (idx, idxlen);
391 * cum_attachs_size: Cumulative Attachments Size
393 * Returns the total number of bytes used by the attachments in the
394 * attachment list _after_ content-transfer-encodings have been
399 static unsigned long cum_attachs_size (MUTTMENU * menu)
403 ATTACHPTR **idx = menu->data;
407 for (i = 0, s = 0; i < menu->max; i++) {
411 b->content = mutt_get_content_info (b->filename, b);
413 if ((info = b->content)) {
414 switch (b->encoding) {
415 case ENCQUOTEDPRINTABLE:
416 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
419 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
422 s += info->lobin + info->hibin + info->ascii + info->crlf;
432 * compose_format_str()
434 * %a = total number of attachments
435 * %h = hostname [option]
436 * %l = approx. length of current message (in bytes)
439 * This function is similar to status_format_str(). Look at that function for
440 * help when modifying this function.
443 static const char *compose_format_str (char *buf, size_t buflen, char op,
444 const char *src, const char *prefix,
445 const char *ifstring,
446 const char *elsestring,
447 unsigned long data, format_flag flags)
449 char fmt[SHORT_STRING], tmp[SHORT_STRING];
450 int optional = (flags & M_FORMAT_OPTIONAL);
451 MUTTMENU *menu = (MUTTMENU *) data;
455 case 'a': /* total number of attachments */
456 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
457 snprintf (buf, buflen, fmt, menu->max);
460 case 'h': /* hostname */
461 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
462 snprintf (buf, buflen, fmt, NONULL (Hostname));
465 case 'l': /* approx length of current message in bytes */
466 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
467 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
468 snprintf (buf, buflen, fmt, tmp);
472 m_strcpy(buf, buflen, mutt_make_version (0));
480 snprintf (buf, buflen, "%%%s%c", prefix, op);
485 compose_status_line (buf, buflen, menu, ifstring);
486 else if (flags & M_FORMAT_OPTIONAL)
487 compose_status_line (buf, buflen, menu, elsestring);
492 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
495 int w=(COLS-SW)>buflen?buflen:(COLS-SW);
496 mutt_FormatString (buf, w, p, compose_format_str,
497 (unsigned long) menu, 0);
503 * 1 message should be postponed
507 int mutt_compose_menu (HEADER * msg, /* structure for new message */
508 char *fcc, /* where to save a copy of the message */
509 size_t fcclen, HEADER * cur)
510 { /* current message */
511 char helpstr[SHORT_STRING];
512 char buf[LONG_STRING];
513 char fname[_POSIX_PATH_MAX];
515 ATTACHPTR **idx = NULL;
519 int r = -1; /* return value */
522 int fccSet = 0; /* has the user edited the Fcc: field ? */
523 CONTEXT *ctx = NULL, *this = NULL;
525 /* Sort, SortAux could be changed in mutt_index_menu() */
526 int oldSort, oldSortAux;
530 int news = 0; /* is it a news article ? */
532 if (option (OPTNEWSSEND))
536 mutt_attach_init (msg->content);
537 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
539 menu = mutt_new_menu ();
540 menu->menu = MENU_COMPOSE;
541 menu->offset = HDR_ATTACH;
543 menu->make_entry = snd_entry;
544 menu->tag = mutt_tag_attach;
549 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
554 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
557 if (option (OPTMBOXPANE))
561 unset_option (OPTNEWS); /* for any case */
563 switch (op = mutt_menuLoop (menu)) {
565 draw_envelope (msg, fcc);
566 menu->offset = HDR_ATTACH;
567 menu->pagelen = LINES - HDR_ATTACH - 2;
569 case OP_COMPOSE_EDIT_FROM:
570 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
571 mutt_message_hook (NULL, msg, M_SEND2HOOK);
573 case OP_COMPOSE_EDIT_TO:
577 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
578 mutt_message_hook (NULL, msg, M_SEND2HOOK);
583 case OP_COMPOSE_EDIT_BCC:
587 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
588 mutt_message_hook (NULL, msg, M_SEND2HOOK);
593 case OP_COMPOSE_EDIT_CC:
597 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
598 mutt_message_hook (NULL, msg, M_SEND2HOOK);
604 case OP_COMPOSE_EDIT_NEWSGROUPS:
606 if (msg->env->newsgroups)
607 m_strcpy(buf, sizeof(buf), msg->env->newsgroups);
610 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
612 p_delete(&msg->env->newsgroups);
614 msg->env->newsgroups = m_strdup(skipspaces(buf));
615 move (HDR_TO, HDR_XOFFSET);
617 if (msg->env->newsgroups)
618 printw ("%-*.*s", W, W, msg->env->newsgroups);
623 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
626 if (msg->env->followup_to)
627 m_strcpy(buf, sizeof(buf), msg->env->followup_to);
628 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
630 p_delete(&msg->env->followup_to);
632 msg->env->followup_to = m_strdup(skipspaces(buf));
633 move (HDR_CC, HDR_XOFFSET);
635 if (msg->env->followup_to)
636 printw ("%-*.*s", W, W, msg->env->followup_to);
641 case OP_COMPOSE_EDIT_X_COMMENT_TO:
642 if (news && option (OPTXCOMMENTTO)) {
644 if (msg->env->x_comment_to)
645 m_strcpy(buf, sizeof(buf), msg->env->x_comment_to);
646 if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
648 p_delete(&msg->env->x_comment_to);
649 msg->env->x_comment_to = m_strdup(buf);
650 move (HDR_BCC, HDR_XOFFSET);
652 if (msg->env->x_comment_to)
653 printw ("%-*.*s", W, W, msg->env->x_comment_to);
658 case OP_COMPOSE_EDIT_SUBJECT:
659 if (msg->env->subject)
660 m_strcpy(buf, sizeof(buf), msg->env->subject);
663 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
664 m_strreplace(&msg->env->subject, buf);
665 move (HDR_SUBJECT, HDR_XOFFSET + SW);
667 if (msg->env->subject)
668 mutt_paddstr (W, msg->env->subject);
670 mutt_message_hook (NULL, msg, M_SEND2HOOK);
672 case OP_COMPOSE_EDIT_REPLY_TO:
673 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
674 mutt_message_hook (NULL, msg, M_SEND2HOOK);
676 case OP_COMPOSE_EDIT_FCC:
677 m_strcpy(buf, sizeof(buf), fcc);
678 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
679 m_strcpy(fcc, _POSIX_PATH_MAX, buf);
680 mutt_pretty_mailbox (fcc);
681 move (HDR_FCC, HDR_XOFFSET + SW);
682 mutt_paddstr (W, fcc);
685 MAYBE_REDRAW (menu->redraw);
686 mutt_message_hook (NULL, msg, M_SEND2HOOK);
688 case OP_COMPOSE_EDIT_MESSAGE:
689 if (Editor && !option (OPTEDITHDRS)) {
690 mutt_edit_file (Editor, msg->content->filename);
691 mutt_update_encoding (msg->content);
692 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
693 mutt_message_hook (NULL, msg, M_SEND2HOOK);
697 case OP_COMPOSE_EDIT_HEADERS:
698 if ((op == OP_COMPOSE_EDIT_HEADERS ||
699 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
700 const char *tag = NULL;
701 const char *err = NULL;
703 mutt_env_to_local (msg->env);
704 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
706 if (mutt_env_to_idna (msg->env, &tag, &err)) {
707 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
711 mutt_update_encoding (msg->content);
713 /* attachments may have been added */
714 if (idxlen && idx[idxlen - 1]->content->next) {
715 for (i = 0; i < idxlen; i++)
719 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
725 menu->redraw = REDRAW_FULL;
726 mutt_message_hook (NULL, msg, M_SEND2HOOK);
731 case OP_COMPOSE_ATTACH_KEY:
732 if (idxlen == idxmax) {
733 p_realloc(&idx, idxmax += 5);
737 idx[idxlen] = p_new(ATTACHPTR, 1);
738 if ((idx[idxlen]->content =
739 crypt_pgp_make_key_attachment (NULL)) != NULL) {
740 update_idx (menu, idx, idxlen++);
741 menu->redraw |= REDRAW_INDEX;
744 p_delete(&idx[idxlen]);
746 menu->redraw |= REDRAW_STATUS;
748 if (option (OPTNEEDREDRAW)) {
749 menu->redraw = REDRAW_FULL;
750 unset_option (OPTNEEDREDRAW);
753 mutt_message_hook (NULL, msg, M_SEND2HOOK);
757 case OP_COMPOSE_ATTACH_FILE:
759 char *prompt, **files;
763 prompt = _("Attach file");
767 if (_mutt_enter_fname
768 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
769 &numfiles) == -1 || *fname == '\0')
772 if (idxlen + numfiles >= idxmax) {
773 p_realloc(&idx, idxmax += 5 + numfiles);
779 mutt_message _("Attaching selected files...");
781 for (i = 0; i < numfiles; i++) {
782 char *att = files[i];
784 idx[idxlen] = p_new(ATTACHPTR, 1);
785 idx[idxlen]->unowned = 1;
786 idx[idxlen]->content = mutt_make_file_attach (att);
787 if (idx[idxlen]->content != NULL)
788 update_idx (menu, idx, idxlen++);
791 mutt_error (_("Unable to attach %s!"), att);
792 p_delete(&idx[idxlen]);
800 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
802 mutt_message_hook (NULL, msg, M_SEND2HOOK);
805 case OP_COMPOSE_ATTACH_MESSAGE:
807 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
814 prompt = _("Open mailbox to attach message from");
817 unset_option (OPTNEWS);
818 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
819 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
822 prompt = _("Open newsgroup to attach message from");
823 set_option (OPTNEWS);
829 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
832 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
833 mutt_pretty_mailbox (fname);
836 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
841 if (option (OPTNEWS))
842 nntp_expand_path (fname, sizeof (fname),
843 &CurrentNewsSrv->conn->account);
846 mutt_expand_path (fname, sizeof (fname));
847 if (mx_get_magic (fname) != M_IMAP)
848 if (mx_get_magic (fname) != M_POP)
850 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
852 /* check to make sure the file exists and is readable */
853 if (access (fname, R_OK) == -1) {
858 menu->redraw = REDRAW_FULL;
860 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
866 if (!ctx->msgcount) {
867 mx_close_mailbox (ctx, NULL);
869 mutt_error _("No messages in that folder.");
874 this = Context; /* remember current folder and sort methods */
876 oldSortAux = SortAux;
879 set_option (OPTATTACHMSG);
880 mutt_message _("Tag the messages you want to attach!");
882 closed = mutt_index_menu ();
883 unset_option (OPTATTACHMSG);
886 /* go back to the folder we started from */
888 /* Restore old $sort and $sort_aux */
890 SortAux = oldSortAux;
891 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
895 if (idxlen + Context->tagged >= idxmax) {
896 p_realloc(&idx, idxmax += 5 + Context->tagged);
900 for (i = 0; i < Context->msgcount; i++) {
901 h = Context->hdrs[i];
903 idx[idxlen] = p_new(ATTACHPTR, 1);
904 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
905 if (idx[idxlen]->content != NULL)
906 update_idx (menu, idx, idxlen++);
908 mutt_error _("Unable to attach!");
910 p_delete(&idx[idxlen]);
914 menu->redraw |= REDRAW_FULL;
916 if (closed == OP_QUIT)
917 mx_close_mailbox (Context, NULL);
919 mx_fastclose_mailbox (Context);
922 /* go back to the folder we started from */
924 /* Restore old $sort and $sort_aux */
926 SortAux = oldSortAux;
928 mutt_message_hook (NULL, msg, M_SEND2HOOK);
933 if (idx[menu->current]->unowned)
934 idx[menu->current]->content->unlink = 0;
935 if (delete_attachment (menu, &idxlen, menu->current) == -1)
937 mutt_update_tree (idx, idxlen);
939 if (menu->current > idxlen - 1)
940 menu->current = idxlen - 1;
945 if (menu->current == 0)
946 msg->content = idx[0]->content;
948 menu->redraw |= REDRAW_STATUS;
949 mutt_message_hook (NULL, msg, M_SEND2HOOK);
952 #define CURRENT idx[menu->current]->content
954 case OP_COMPOSE_TOGGLE_RECODE:
957 if (!mutt_is_text_part (CURRENT)) {
958 mutt_error (_("Recoding only affects text attachments."));
961 CURRENT->noconv = !CURRENT->noconv;
963 mutt_message (_("The current attachment won't be converted."));
965 mutt_message (_("The current attachment will be converted."));
966 menu->redraw = REDRAW_CURRENT;
967 mutt_message_hook (NULL, msg, M_SEND2HOOK);
972 case OP_COMPOSE_EDIT_DESCRIPTION:
974 m_strcpy(buf, sizeof(buf),
975 NONULL(idx[menu->current]->content->description));
976 /* header names should not be translated */
977 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
978 m_strreplace(&idx[menu->current]->content->description, buf);
979 menu->redraw = REDRAW_CURRENT;
981 mutt_message_hook (NULL, msg, M_SEND2HOOK);
984 case OP_COMPOSE_UPDATE_ENCODING:
986 if (menu->tagprefix) {
989 for (top = msg->content; top; top = top->next) {
991 mutt_update_encoding (top);
993 menu->redraw = REDRAW_FULL;
996 mutt_update_encoding (idx[menu->current]->content);
997 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
999 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1002 case OP_COMPOSE_TOGGLE_DISPOSITION:
1003 /* toggle the content-disposition between inline/attachment */
1004 idx[menu->current]->content->disposition =
1005 (idx[menu->current]->content->disposition ==
1006 DISPINLINE) ? DISPATTACH : DISPINLINE;
1007 menu->redraw = REDRAW_CURRENT;
1013 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
1015 /* this may have been a change to text/something */
1016 mutt_update_encoding (idx[menu->current]->content);
1018 menu->redraw = REDRAW_CURRENT;
1020 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1023 case OP_COMPOSE_EDIT_ENCODING:
1025 m_strcpy(buf, sizeof(buf),
1026 ENCODING(idx[menu->current]->content->encoding));
1027 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
1028 sizeof (buf), 0) == 0 && buf[0]) {
1029 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
1030 idx[menu->current]->content->encoding = i;
1031 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1032 mutt_clear_error ();
1035 mutt_error _("Invalid encoding.");
1037 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1040 case OP_COMPOSE_SEND_MESSAGE:
1042 /* Note: We don't invoke send2-hook here, since we want to leave
1043 * users an opportunity to change settings from the ":" prompt.
1046 if (check_attachments (idx, idxlen) != 0) {
1047 menu->redraw = REDRAW_FULL;
1053 if (msg->chain && mix_check_message (msg) != 0)
1057 if (!fccSet && *fcc) {
1058 if ((i = query_quadoption (OPT_COPY,
1059 _("Save a copy of this message?"))) == -1)
1069 case OP_COMPOSE_EDIT_FILE:
1071 mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename);
1072 mutt_update_encoding (idx[menu->current]->content);
1073 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1074 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1077 case OP_COMPOSE_TOGGLE_UNLINK:
1079 idx[menu->current]->content->unlink =
1080 !idx[menu->current]->content->unlink;
1083 /* OPTRESOLVE is otherwise ignored on this menu.
1087 if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
1090 menu->redraw = REDRAW_INDEX;
1091 /* No send2hook since this doesn't change the message. */
1094 case OP_COMPOSE_GET_ATTACHMENT:
1096 if (menu->tagprefix) {
1099 for (top = msg->content; top; top = top->next) {
1101 mutt_get_tmp_attachment (top);
1103 menu->redraw = REDRAW_FULL;
1105 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1106 menu->redraw = REDRAW_CURRENT;
1108 /* No send2hook since this doesn't change the message. */
1111 case OP_COMPOSE_RENAME_FILE:
1113 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
1114 mutt_pretty_mailbox (fname);
1115 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1117 if (stat (idx[menu->current]->content->filename, &st) == -1) {
1118 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1122 mutt_expand_path (fname, sizeof (fname));
1123 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1126 m_strreplace(&idx[menu->current]->content->filename, fname);
1127 menu->redraw = REDRAW_CURRENT;
1129 if (idx[menu->current]->content->stamp >= st.st_mtime)
1130 mutt_stamp_attachment (idx[menu->current]->content);
1133 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1136 case OP_COMPOSE_NEW_MIME:
1143 CLEARLINE (LINES - 1);
1145 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1148 mutt_expand_path (fname, sizeof (fname));
1150 /* Call to lookup_mime_type () ? maybe later */
1152 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1156 if (!(p = strchr (type, '/'))) {
1157 mutt_error _("Content-Type is of the form base/sub");
1162 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1163 mutt_error (_("Unknown Content-Type %s"), type);
1166 if (idxlen == idxmax) {
1167 p_realloc(&idx, idxmax += 5);
1171 idx[idxlen] = p_new(ATTACHPTR, 1);
1172 /* Touch the file */
1173 if (!(fp = safe_fopen (fname, "w"))) {
1174 mutt_error (_("Can't create file %s"), fname);
1175 p_delete(&idx[idxlen]);
1180 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1182 _("What we have here is a failure to make an attachment");
1185 update_idx (menu, idx, idxlen++);
1187 idx[menu->current]->content->type = itype;
1188 m_strreplace(&idx[menu->current]->content->subtype, p);
1189 idx[menu->current]->content->unlink = 1;
1190 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1192 if (mutt_compose_attachment (idx[menu->current]->content)) {
1193 mutt_update_encoding (idx[menu->current]->content);
1194 menu->redraw = REDRAW_FULL;
1197 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1200 case OP_COMPOSE_EDIT_MIME:
1202 if (mutt_edit_attachment (idx[menu->current]->content)) {
1203 mutt_update_encoding (idx[menu->current]->content);
1204 menu->redraw = REDRAW_FULL;
1206 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1209 case OP_VIEW_ATTACH:
1210 case OP_DISPLAY_HEADERS:
1212 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1214 menu->redraw = REDRAW_FULL;
1215 /* no send2hook, since this doesn't modify the message */
1220 mutt_save_attachment_list (NULL, menu->tagprefix,
1221 menu->tagprefix ? msg->content : idx[menu->
1223 content, NULL, menu);
1224 MAYBE_REDRAW (menu->redraw);
1225 /* no send2hook, since this doesn't modify the message */
1230 mutt_print_attachment_list (NULL, menu->tagprefix,
1231 menu->tagprefix ? msg->content : idx[menu->
1234 /* no send2hook, since this doesn't modify the message */
1240 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1241 menu->tagprefix ? msg->content : idx[menu->
1243 content, op == OP_FILTER);
1244 if (op == OP_FILTER) /* cte might have changed */
1245 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1246 menu->redraw |= REDRAW_STATUS;
1247 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1252 query_quadoption (OPT_POSTPONE,
1253 _("Postpone this message?"))) == M_NO) {
1254 while (idxlen-- > 0) {
1255 /* avoid freeing other attachments */
1256 idx[idxlen]->content->next = NULL;
1257 idx[idxlen]->content->parts = NULL;
1258 if (idx[idxlen]->unowned)
1259 idx[idxlen]->content->unlink = 0;
1260 mutt_free_body (&idx[idxlen]->content);
1261 p_delete(&idx[idxlen]->tree);
1262 p_delete(&idx[idxlen]);
1274 /* fall through to postpone! */
1276 case OP_COMPOSE_POSTPONE_MESSAGE:
1278 if (check_attachments (idx, idxlen) != 0) {
1279 menu->redraw = REDRAW_FULL;
1287 case OP_COMPOSE_ISPELL:
1289 snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1290 msg->content->filename);
1291 if (mutt_system (buf) == -1)
1292 mutt_error (_("Error running \"%s\"!"), buf);
1294 mutt_update_encoding (msg->content);
1295 menu->redraw |= REDRAW_STATUS;
1299 case OP_COMPOSE_WRITE_MESSAGE:
1303 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
1304 mutt_pretty_mailbox (fname);
1307 msg->content = idx[0]->content;
1308 if (mutt_enter_fname
1309 (_("Write message to mailbox"), fname, sizeof (fname),
1310 &menu->redraw, 1) != -1 && fname[0]) {
1311 mutt_message (_("Writing message to %s ..."), fname);
1312 mutt_expand_path (fname, sizeof (fname));
1314 if (msg->content->next)
1315 msg->content = mutt_make_multipart (msg->content);
1317 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1318 msg->content = mutt_remove_multipart (msg->content);
1320 mutt_message _("Message written.");
1326 case OP_COMPOSE_PGP_MENU:
1327 if (msg->security & APPLICATION_SMIME) {
1328 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1330 mutt_clear_error ();
1335 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1336 redraw_crypt_lines (msg);
1337 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1341 case OP_FORGET_PASSPHRASE:
1342 crypt_forget_passphrase ();
1346 case OP_COMPOSE_SMIME_MENU:
1347 if (msg->security & APPLICATION_PGP) {
1348 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1350 mutt_clear_error ();
1355 msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1356 redraw_crypt_lines (msg);
1357 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1362 case OP_COMPOSE_MIX:
1364 mix_make_chain (&msg->chain, &menu->redraw);
1365 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1371 /* Draw formated compose status line */
1372 if (menu->redraw & REDRAW_STATUS) {
1373 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1374 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1375 SETCOLOR (MT_COLOR_STATUS);
1376 move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
1377 printw ("%-*.*s", COLS-SW, COLS-SW, buf);
1378 SETCOLOR (MT_COLOR_NORMAL);
1379 menu->redraw &= ~REDRAW_STATUS;
1383 mutt_menuDestroy (&menu);
1386 msg->content = idx[0]->content;
1387 for (i = 0; i < idxlen; i++) {
1388 idx[i]->content->aptr = NULL;
1393 msg->content = NULL;