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 * This file is part of mutt-ng, see http://www.muttng.org/.
7 * It's licensed under the GNU General Public License,
8 * please see the file GPL in the top level source directory.
16 #include "mutt_curses.h"
17 #include "mutt_idna.h"
18 #include "mutt_menu.h"
43 static const char *There_are_no_attachments = N_("There are no attachments.");
45 #define CHECK_COUNT if (idxlen == 0) { mutt_error _(There_are_no_attachments); break; }
72 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
74 HDR_ATTACH = (HDR_FCC + 7)
78 #define HDR_XOFFSET 14
79 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
80 #define W (COLS - HDR_XOFFSET - SidebarWidth)
82 static char *Prompts[] = {
94 , "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: "
98 static struct mapping_t ComposeHelp[] = {
99 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
100 {N_("Abort"), OP_EXIT},
101 {"To", OP_COMPOSE_EDIT_TO},
102 {"CC", OP_COMPOSE_EDIT_CC},
103 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
104 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
105 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
106 {N_("Help"), OP_HELP},
111 static struct mapping_t ComposeNewsHelp[] = {
112 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
113 {N_("Abort"), OP_EXIT},
114 {"Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS},
115 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
116 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
117 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
118 {N_("Help"), OP_HELP},
123 static void snd_entry (char *b, size_t blen, MUTTMENU * menu, int num)
125 mutt_FormatString (b, blen, NONULL (AttachFormat), mutt_attach_fmt,
126 (unsigned long) (((ATTACHPTR **) menu->data)[num]),
127 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
132 #include "mutt_crypt.h"
134 static void redraw_crypt_lines (HEADER * msg)
138 if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME)) {
140 mvaddstr (HDR_CRYPT, SidebarWidth, " Security: ");
141 else if (msg->security & APPLICATION_SMIME)
142 mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
143 else if (msg->security & APPLICATION_PGP)
144 mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
146 else if ((WithCrypto & APPLICATION_SMIME))
147 mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
148 else if ((WithCrypto & APPLICATION_PGP))
149 mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
153 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
154 addstr (_("Sign, Encrypt"));
155 else if (msg->security & ENCRYPT)
156 addstr (_("Encrypt"));
157 else if (msg->security & SIGN)
162 if ((WithCrypto & APPLICATION_PGP))
163 if ((msg->security & APPLICATION_PGP)
164 && (msg->security & (ENCRYPT | SIGN))) {
165 if ((msg->security & INLINE))
166 addstr (_(" (inline)"));
168 addstr (_(" (PGP/MIME)"));
172 move (HDR_CRYPTINFO, SidebarWidth);
174 if ((WithCrypto & APPLICATION_PGP)
175 && msg->security & APPLICATION_PGP && msg->security & SIGN)
176 printw ("%s%s", _(" sign as: "),
177 PgpSignAs ? PgpSignAs : _("<default>"));
179 if ((WithCrypto & APPLICATION_SMIME)
180 && msg->security & APPLICATION_SMIME && msg->security & SIGN) {
181 printw ("%s%s", _(" sign as: "),
182 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
185 if ((WithCrypto & APPLICATION_SMIME)
186 && (msg->security & APPLICATION_SMIME)
187 && (msg->security & ENCRYPT)
188 && SmimeCryptAlg && *SmimeCryptAlg) {
189 mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "),
190 NONULL (SmimeCryptAlg));
198 static void redraw_mix_line (LIST * chain)
203 mvaddstr (HDR_MIX, SidebarWidth, " Mix: ");
206 addstr ("<no chain defined>");
211 for (c = 12; chain; chain = chain->next) {
213 if (t && t[0] == '0' && t[1] == '\0')
216 if (c + mutt_strlen (t) + 2 >= COLS - SidebarWidth)
223 c += mutt_strlen (t) + 2;
226 #endif /* MIXMASTER */
228 static int check_attachments (ATTACHPTR ** idx, short idxlen)
232 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
234 for (i = 0; i < idxlen; i++) {
235 strfcpy (pretty, idx[i]->content->filename, sizeof (pretty));
236 if (stat (idx[i]->content->filename, &st) != 0) {
237 mutt_pretty_mailbox (pretty);
238 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
242 if (idx[i]->content->stamp < st.st_mtime) {
243 mutt_pretty_mailbox (pretty);
244 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
247 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
248 mutt_update_encoding (idx[i]->content);
257 static void draw_envelope_addr (int line, ADDRESS * addr)
262 rfc822_write_address (buf, sizeof (buf), addr, 1);
263 mvprintw (line, SidebarWidth, TITLE_FMT, Prompts[line - 1]);
264 mutt_paddstr (W, buf);
267 static void draw_envelope (HEADER * msg, char *fcc)
269 draw_envelope_addr (HDR_FROM, msg->env->from);
271 if (!option (OPTNEWSSEND)) {
273 draw_envelope_addr (HDR_TO, msg->env->to);
274 draw_envelope_addr (HDR_CC, msg->env->cc);
275 draw_envelope_addr (HDR_BCC, msg->env->bcc);
279 mvprintw (HDR_TO, SidebarWidth, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
280 mutt_paddstr (W, NONULL (msg->env->newsgroups));
281 mvprintw (HDR_CC, SidebarWidth, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
282 mutt_paddstr (W, NONULL (msg->env->followup_to));
283 if (option (OPTXCOMMENTTO)) {
284 mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]);
285 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
289 mvprintw (HDR_SUBJECT, SidebarWidth, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
290 mutt_paddstr (W, NONULL (msg->env->subject));
291 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
292 mvprintw (HDR_FCC, SidebarWidth, TITLE_FMT, Prompts[HDR_FCC - 1]);
293 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, SidebarWidth, _("-- 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 ** 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 rfc822_free_address (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 + SidebarWidth);
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 FREE (&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;
431 /* prototype for use below */
432 static void compose_status_line (char *buf, size_t buflen, MUTTMENU * menu,
436 * compose_format_str()
438 * %a = total number of attachments
439 * %h = hostname [option]
440 * %l = approx. length of current message (in bytes)
443 * This function is similar to status_format_str(). Look at that function for
444 * help when modifying this function.
447 static const char *compose_format_str (char *buf, size_t buflen, char op,
448 const char *src, const char *prefix,
449 const char *ifstring,
450 const char *elsestring,
451 unsigned long data, format_flag flags)
453 char fmt[SHORT_STRING], tmp[SHORT_STRING];
454 int optional = (flags & M_FORMAT_OPTIONAL);
455 MUTTMENU *menu = (MUTTMENU *) data;
459 case 'a': /* total number of attachments */
460 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
461 snprintf (buf, buflen, fmt, menu->max);
464 case 'h': /* hostname */
465 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
466 snprintf (buf, buflen, fmt, NONULL (Hostname));
469 case 'l': /* approx length of current message in bytes */
470 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
471 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
472 snprintf (buf, buflen, fmt, tmp);
476 snprintf (fmt, sizeof (fmt), "Mutt-ng %%s");
477 snprintf (buf, buflen, fmt, MUTT_VERSION);
485 snprintf (buf, buflen, "%%%s%c", prefix, op);
490 compose_status_line (buf, buflen, menu, ifstring);
491 else if (flags & M_FORMAT_OPTIONAL)
492 compose_status_line (buf, buflen, menu, elsestring);
497 static void compose_status_line (char *buf, size_t buflen, MUTTMENU * menu,
500 mutt_FormatString (buf, buflen, p, compose_format_str,
501 (unsigned long) menu, 0);
507 * 1 message should be postponed
511 int mutt_compose_menu (HEADER * msg, /* structure for new message */
512 char *fcc, /* where to save a copy of the message */
513 size_t fcclen, HEADER * cur)
514 { /* current message */
515 char helpstr[SHORT_STRING];
516 char buf[LONG_STRING];
517 char fname[_POSIX_PATH_MAX];
519 ATTACHPTR **idx = NULL;
523 int r = -1; /* return value */
526 int fccSet = 0; /* has the user edited the Fcc: field ? */
527 CONTEXT *ctx = NULL, *this = NULL;
529 /* Sort, SortAux could be changed in mutt_index_menu() */
530 int oldSort, oldSortAux;
534 int news = 0; /* is it a news article ? */
536 if (option (OPTNEWSSEND))
540 mutt_attach_init (msg->content);
541 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
543 menu = mutt_new_menu ();
544 menu->menu = MENU_COMPOSE;
545 menu->offset = HDR_ATTACH;
547 menu->make_entry = snd_entry;
548 menu->tag = mutt_tag_attach;
553 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
558 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
561 if (option (OPTMBOXPANE))
562 mutt_buffy_check (1);
565 unset_option (OPTNEWS); /* for any case */
567 switch (op = mutt_menuLoop (menu)) {
569 draw_envelope (msg, fcc);
570 menu->offset = HDR_ATTACH;
571 menu->pagelen = LINES - HDR_ATTACH - 2;
573 case OP_COMPOSE_EDIT_FROM:
574 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
575 mutt_message_hook (NULL, msg, M_SEND2HOOK);
577 case OP_COMPOSE_EDIT_TO:
581 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
582 mutt_message_hook (NULL, msg, M_SEND2HOOK);
587 case OP_COMPOSE_EDIT_BCC:
591 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
592 mutt_message_hook (NULL, msg, M_SEND2HOOK);
597 case OP_COMPOSE_EDIT_CC:
601 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
602 mutt_message_hook (NULL, msg, M_SEND2HOOK);
608 case OP_COMPOSE_EDIT_NEWSGROUPS:
610 if (msg->env->newsgroups)
611 strfcpy (buf, msg->env->newsgroups, sizeof (buf));
614 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
616 FREE (&msg->env->newsgroups);
617 mutt_remove_trailing_ws (buf);
618 msg->env->newsgroups = safe_strdup (mutt_skip_whitespace (buf));
619 move (HDR_TO, HDR_XOFFSET);
621 if (msg->env->newsgroups)
622 printw ("%-*.*s", W, W, msg->env->newsgroups);
627 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
630 if (msg->env->followup_to)
631 strfcpy (buf, msg->env->followup_to, sizeof (buf));
632 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
634 FREE (&msg->env->followup_to);
635 mutt_remove_trailing_ws (buf);
636 msg->env->followup_to = safe_strdup (mutt_skip_whitespace (buf));
637 move (HDR_CC, HDR_XOFFSET);
639 if (msg->env->followup_to)
640 printw ("%-*.*s", W, W, msg->env->followup_to);
645 case OP_COMPOSE_EDIT_X_COMMENT_TO:
646 if (news && option (OPTXCOMMENTTO)) {
648 if (msg->env->x_comment_to)
649 strfcpy (buf, msg->env->x_comment_to, sizeof (buf));
650 if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
652 FREE (&msg->env->x_comment_to);
653 msg->env->x_comment_to = safe_strdup (buf);
654 move (HDR_BCC, HDR_XOFFSET);
656 if (msg->env->x_comment_to)
657 printw ("%-*.*s", W, W, msg->env->x_comment_to);
662 case OP_COMPOSE_EDIT_SUBJECT:
663 if (msg->env->subject)
664 strfcpy (buf, msg->env->subject, sizeof (buf));
667 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
668 mutt_str_replace (&msg->env->subject, buf);
669 move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
671 if (msg->env->subject)
672 mutt_paddstr (W, msg->env->subject);
674 mutt_message_hook (NULL, msg, M_SEND2HOOK);
676 case OP_COMPOSE_EDIT_REPLY_TO:
677 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
678 mutt_message_hook (NULL, msg, M_SEND2HOOK);
680 case OP_COMPOSE_EDIT_FCC:
681 strfcpy (buf, fcc, sizeof (buf));
682 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
683 strfcpy (fcc, buf, _POSIX_PATH_MAX);
684 mutt_pretty_mailbox (fcc);
685 move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
686 mutt_paddstr (W, fcc);
689 MAYBE_REDRAW (menu->redraw);
690 mutt_message_hook (NULL, msg, M_SEND2HOOK);
692 case OP_COMPOSE_EDIT_MESSAGE:
693 if (Editor && (mutt_strcmp ("builtin", Editor) != 0)
694 && !option (OPTEDITHDRS)) {
695 mutt_edit_file (Editor, msg->content->filename);
696 mutt_update_encoding (msg->content);
697 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
698 mutt_message_hook (NULL, msg, M_SEND2HOOK);
702 case OP_COMPOSE_EDIT_HEADERS:
703 if (mutt_strcmp ("builtin", Editor) != 0 &&
704 (op == OP_COMPOSE_EDIT_HEADERS ||
705 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
706 char *tag = NULL, *err = NULL;
708 mutt_env_to_local (msg->env);
709 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
711 if (mutt_env_to_idna (msg->env, &tag, &err)) {
712 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
717 /* this is grouped with OP_COMPOSE_EDIT_HEADERS because the
718 attachment list could change if the user invokes ~v to edit
719 the message with headers, in which we need to execute the
720 code below to regenerate the index array */
721 mutt_builtin_editor (msg->content->filename, msg, cur);
723 mutt_update_encoding (msg->content);
725 /* attachments may have been added */
726 if (idxlen && idx[idxlen - 1]->content->next) {
727 for (i = 0; i < idxlen; i++)
731 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
737 menu->redraw = REDRAW_FULL;
738 mutt_message_hook (NULL, msg, M_SEND2HOOK);
743 case OP_COMPOSE_ATTACH_KEY:
744 if (!(WithCrypto & APPLICATION_PGP))
746 if (idxlen == idxmax) {
747 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
751 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
752 if ((idx[idxlen]->content =
753 crypt_pgp_make_key_attachment (NULL)) != NULL) {
754 update_idx (menu, idx, idxlen++);
755 menu->redraw |= REDRAW_INDEX;
760 menu->redraw |= REDRAW_STATUS;
762 if (option (OPTNEEDREDRAW)) {
763 menu->redraw = REDRAW_FULL;
764 unset_option (OPTNEEDREDRAW);
767 mutt_message_hook (NULL, msg, M_SEND2HOOK);
771 case OP_COMPOSE_ATTACH_FILE:
773 char *prompt, **files;
777 prompt = _("Attach file");
781 if (_mutt_enter_fname
782 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
783 &numfiles) == -1 || *fname == '\0')
786 if (idxlen + numfiles >= idxmax) {
788 sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles));
794 mutt_message _("Attaching selected files...");
796 for (i = 0; i < numfiles; i++) {
797 char *att = files[i];
799 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
800 idx[idxlen]->content = mutt_make_file_attach (att);
801 if (idx[idxlen]->content != NULL)
802 update_idx (menu, idx, idxlen++);
805 mutt_error (_("Unable to attach %s!"), att);
814 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
816 mutt_message_hook (NULL, msg, M_SEND2HOOK);
819 case OP_COMPOSE_ATTACH_MESSAGE:
821 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
828 prompt = _("Open mailbox to attach message from");
831 unset_option (OPTNEWS);
832 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
833 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
836 prompt = _("Open newsgroup to attach message from");
837 set_option (OPTNEWS);
843 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
846 strfcpy (fname, NONULL (Context->path), sizeof (fname));
847 mutt_pretty_mailbox (fname);
850 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
855 if (option (OPTNEWS))
856 nntp_expand_path (fname, sizeof (fname),
857 &CurrentNewsSrv->conn->account);
860 mutt_expand_path (fname, sizeof (fname));
862 if (!mx_is_imap (fname))
865 if (!mx_is_pop (fname))
868 if (!mx_is_nntp (fname) && !option (OPTNEWS))
870 /* check to make sure the file exists and is readable */
871 if (access (fname, R_OK) == -1) {
876 menu->redraw = REDRAW_FULL;
878 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
884 if (!ctx->msgcount) {
885 mx_close_mailbox (ctx, NULL);
887 mutt_error _("No messages in that folder.");
892 this = Context; /* remember current folder and sort methods */
894 oldSortAux = SortAux;
897 set_option (OPTATTACHMSG);
898 mutt_message _("Tag the messages you want to attach!");
900 close = mutt_index_menu ();
901 unset_option (OPTATTACHMSG);
904 /* go back to the folder we started from */
906 /* Restore old $sort and $sort_aux */
908 SortAux = oldSortAux;
909 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
913 if (idxlen + Context->tagged >= idxmax) {
915 sizeof (ATTACHPTR *) * (idxmax +=
916 5 + Context->tagged));
920 for (i = 0; i < Context->msgcount; i++) {
921 h = Context->hdrs[i];
923 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
924 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
925 if (idx[idxlen]->content != NULL)
926 update_idx (menu, idx, idxlen++);
928 mutt_error _("Unable to attach!");
934 menu->redraw |= REDRAW_FULL;
936 if (close == OP_QUIT)
937 mx_close_mailbox (Context, NULL);
939 mx_fastclose_mailbox (Context);
942 /* go back to the folder we started from */
944 /* Restore old $sort and $sort_aux */
946 SortAux = oldSortAux;
948 mutt_message_hook (NULL, msg, M_SEND2HOOK);
953 if (delete_attachment (menu, &idxlen, menu->current) == -1)
955 mutt_update_tree (idx, idxlen);
957 if (menu->current > idxlen - 1)
958 menu->current = idxlen - 1;
963 if (menu->current == 0)
964 msg->content = idx[0]->content;
966 menu->redraw |= REDRAW_STATUS;
967 mutt_message_hook (NULL, msg, M_SEND2HOOK);
970 #define CURRENT idx[menu->current]->content
972 case OP_COMPOSE_TOGGLE_RECODE:
975 if (!mutt_is_text_part (CURRENT)) {
976 mutt_error (_("Recoding only affects text attachments."));
979 CURRENT->noconv = !CURRENT->noconv;
981 mutt_message (_("The current attachment won't be converted."));
983 mutt_message (_("The current attachment will be converted."));
984 menu->redraw = REDRAW_CURRENT;
985 mutt_message_hook (NULL, msg, M_SEND2HOOK);
990 case OP_COMPOSE_EDIT_DESCRIPTION:
993 idx[menu->current]->content->description ?
994 idx[menu->current]->content->description : "", sizeof (buf));
995 /* header names should not be translated */
996 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
997 mutt_str_replace (&idx[menu->current]->content->description, buf);
998 menu->redraw = REDRAW_CURRENT;
1000 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1003 case OP_COMPOSE_UPDATE_ENCODING:
1005 if (menu->tagprefix) {
1008 for (top = msg->content; top; top = top->next) {
1010 mutt_update_encoding (top);
1012 menu->redraw = REDRAW_FULL;
1015 mutt_update_encoding (idx[menu->current]->content);
1016 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1018 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1021 case OP_COMPOSE_TOGGLE_DISPOSITION:
1022 /* toggle the content-disposition between inline/attachment */
1023 idx[menu->current]->content->disposition =
1024 (idx[menu->current]->content->disposition ==
1025 DISPINLINE) ? DISPATTACH : DISPINLINE;
1026 menu->redraw = REDRAW_CURRENT;
1032 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
1034 /* this may have been a change to text/something */
1035 mutt_update_encoding (idx[menu->current]->content);
1037 menu->redraw = REDRAW_CURRENT;
1039 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1042 case OP_COMPOSE_EDIT_ENCODING:
1044 strfcpy (buf, ENCODING (idx[menu->current]->content->encoding),
1046 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
1047 sizeof (buf), 0) == 0 && buf[0]) {
1048 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
1049 idx[menu->current]->content->encoding = i;
1050 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1051 mutt_clear_error ();
1054 mutt_error _("Invalid encoding.");
1056 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1059 case OP_COMPOSE_SEND_MESSAGE:
1061 /* Note: We don't invoke send2-hook here, since we want to leave
1062 * users an opportunity to change settings from the ":" prompt.
1065 if (check_attachments (idx, idxlen) != 0) {
1066 menu->redraw = REDRAW_FULL;
1072 if (msg->chain && mix_check_message (msg) != 0)
1076 if (!fccSet && *fcc) {
1077 if ((i = query_quadoption (OPT_COPY,
1078 _("Save a copy of this message?"))) == -1)
1088 case OP_COMPOSE_EDIT_FILE:
1090 mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename);
1091 mutt_update_encoding (idx[menu->current]->content);
1092 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1093 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1096 case OP_COMPOSE_TOGGLE_UNLINK:
1098 idx[menu->current]->content->unlink =
1099 !idx[menu->current]->content->unlink;
1102 /* OPTRESOLVE is otherwise ignored on this menu.
1106 if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
1109 menu->redraw = REDRAW_INDEX;
1110 /* No send2hook since this doesn't change the message. */
1113 case OP_COMPOSE_GET_ATTACHMENT:
1115 if (menu->tagprefix) {
1118 for (top = msg->content; top; top = top->next) {
1120 mutt_get_tmp_attachment (top);
1122 menu->redraw = REDRAW_FULL;
1124 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1125 menu->redraw = REDRAW_CURRENT;
1127 /* No send2hook since this doesn't change the message. */
1130 case OP_COMPOSE_RENAME_FILE:
1132 strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname));
1133 mutt_pretty_mailbox (fname);
1134 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1136 if (stat (idx[menu->current]->content->filename, &st) == -1) {
1137 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1141 mutt_expand_path (fname, sizeof (fname));
1142 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1145 mutt_str_replace (&idx[menu->current]->content->filename, fname);
1146 menu->redraw = REDRAW_CURRENT;
1148 if (idx[menu->current]->content->stamp >= st.st_mtime)
1149 mutt_stamp_attachment (idx[menu->current]->content);
1152 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1155 case OP_COMPOSE_NEW_MIME:
1162 CLEARLINE (LINES - 1);
1164 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1167 mutt_expand_path (fname, sizeof (fname));
1169 /* Call to lookup_mime_type () ? maybe later */
1171 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1175 if (!(p = strchr (type, '/'))) {
1176 mutt_error _("Content-Type is of the form base/sub");
1181 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1182 mutt_error (_("Unknown Content-Type %s"), type);
1185 if (idxlen == idxmax) {
1186 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
1190 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
1191 /* Touch the file */
1192 if (!(fp = safe_fopen (fname, "w"))) {
1193 mutt_error (_("Can't create file %s"), fname);
1194 FREE (&idx[idxlen]);
1199 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1201 _("What we have here is a failure to make an attachment");
1204 update_idx (menu, idx, idxlen++);
1206 idx[menu->current]->content->type = itype;
1207 mutt_str_replace (&idx[menu->current]->content->subtype, p);
1208 idx[menu->current]->content->unlink = 1;
1209 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1211 if (mutt_compose_attachment (idx[menu->current]->content)) {
1212 mutt_update_encoding (idx[menu->current]->content);
1213 menu->redraw = REDRAW_FULL;
1216 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1219 case OP_COMPOSE_EDIT_MIME:
1221 if (mutt_edit_attachment (idx[menu->current]->content)) {
1222 mutt_update_encoding (idx[menu->current]->content);
1223 menu->redraw = REDRAW_FULL;
1225 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1228 case OP_VIEW_ATTACH:
1229 case OP_DISPLAY_HEADERS:
1231 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1233 menu->redraw = REDRAW_FULL;
1234 /* no send2hook, since this doesn't modify the message */
1239 mutt_save_attachment_list (NULL, menu->tagprefix,
1240 menu->tagprefix ? msg->content : idx[menu->
1242 content, NULL, menu);
1243 MAYBE_REDRAW (menu->redraw);
1244 /* no send2hook, since this doesn't modify the message */
1249 mutt_print_attachment_list (NULL, menu->tagprefix,
1250 menu->tagprefix ? msg->content : idx[menu->
1253 /* no send2hook, since this doesn't modify the message */
1259 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1260 menu->tagprefix ? msg->content : idx[menu->
1262 content, op == OP_FILTER);
1263 if (op == OP_FILTER) /* cte might have changed */
1264 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1265 menu->redraw |= REDRAW_STATUS;
1266 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1271 query_quadoption (OPT_POSTPONE,
1272 _("Postpone this message?"))) == M_NO) {
1273 while (idxlen-- > 0) {
1274 /* avoid freeing other attachments */
1275 idx[idxlen]->content->next = NULL;
1276 idx[idxlen]->content->parts = NULL;
1277 mutt_free_body (&idx[idxlen]->content);
1278 FREE (&idx[idxlen]->tree);
1279 FREE (&idx[idxlen]);
1291 /* fall through to postpone! */
1293 case OP_COMPOSE_POSTPONE_MESSAGE:
1295 if (check_attachments (idx, idxlen) != 0) {
1296 menu->redraw = REDRAW_FULL;
1304 case OP_COMPOSE_ISPELL:
1306 snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1307 msg->content->filename);
1308 if (mutt_system (buf) == -1)
1309 mutt_error (_("Error running \"%s\"!"), buf);
1311 mutt_update_encoding (msg->content);
1312 menu->redraw |= REDRAW_STATUS;
1316 case OP_COMPOSE_WRITE_MESSAGE:
1320 strfcpy (fname, NONULL (Context->path), sizeof (fname));
1321 mutt_pretty_mailbox (fname);
1324 msg->content = idx[0]->content;
1325 if (mutt_enter_fname
1326 (_("Write message to mailbox"), fname, sizeof (fname),
1327 &menu->redraw, 1) != -1 && fname[0]) {
1328 mutt_message (_("Writing message to %s ..."), fname);
1329 mutt_expand_path (fname, sizeof (fname));
1331 if (msg->content->next)
1332 msg->content = mutt_make_multipart (msg->content);
1334 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1335 msg->content = mutt_remove_multipart (msg->content);
1337 mutt_message _("Message written.");
1343 case OP_COMPOSE_PGP_MENU:
1344 if (!(WithCrypto & APPLICATION_PGP))
1346 if ((WithCrypto & APPLICATION_SMIME)
1347 && msg->security & APPLICATION_SMIME) {
1348 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1350 mutt_clear_error ();
1355 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1356 redraw_crypt_lines (msg);
1357 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1361 case OP_FORGET_PASSPHRASE:
1362 crypt_forget_passphrase ();
1366 case OP_COMPOSE_SMIME_MENU:
1367 if (!(WithCrypto & APPLICATION_SMIME))
1370 if ((WithCrypto & APPLICATION_PGP)
1371 && msg->security & APPLICATION_PGP) {
1372 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1374 mutt_clear_error ();
1379 msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1380 redraw_crypt_lines (msg);
1381 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1386 case OP_COMPOSE_MIX:
1388 mix_make_chain (&msg->chain, &menu->redraw);
1389 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1395 /* Draw formated compose status line */
1396 if (menu->redraw & REDRAW_STATUS) {
1397 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1398 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1399 SETCOLOR (MT_COLOR_STATUS);
1400 printw ("%-*.*s", COLS, COLS, buf);
1401 SETCOLOR (MT_COLOR_NORMAL);
1402 menu->redraw &= ~REDRAW_STATUS;
1406 mutt_menuDestroy (&menu);
1409 msg->content = idx[0]->content;
1410 for (i = 0; i < idxlen; i++) {
1411 idx[i]->content->aptr = NULL;
1416 msg->content = NULL;