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.
19 #include "mutt_curses.h"
20 #include "mutt_idna.h"
21 #include "mutt_menu.h"
51 static const char *There_are_no_attachments = N_("There are no attachments.");
53 #define CHECK_COUNT if (idxlen == 0) { mutt_error _(There_are_no_attachments); break; }
80 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
82 HDR_ATTACH = (HDR_FCC + 7)
86 #define HDR_XOFFSET 14
87 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
88 #define W (COLS - HDR_XOFFSET - SidebarWidth)
90 static char *Prompts[] = {
102 , "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: "
106 static struct mapping_t ComposeHelp[] = {
107 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
108 {N_("Abort"), OP_EXIT},
109 {"To", OP_COMPOSE_EDIT_TO},
110 {"CC", OP_COMPOSE_EDIT_CC},
111 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
112 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
113 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
114 {N_("Help"), OP_HELP},
119 static struct mapping_t ComposeNewsHelp[] = {
120 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
121 {N_("Abort"), OP_EXIT},
122 {"Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS},
123 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
124 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
125 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
126 {N_("Help"), OP_HELP},
131 static void snd_entry (char *b, size_t blen, MUTTMENU * menu, int num)
133 mutt_FormatString (b, blen, NONULL (AttachFormat), mutt_attach_fmt,
134 (unsigned long) (((ATTACHPTR **) menu->data)[num]),
135 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
140 #include "mutt_crypt.h"
142 static void redraw_crypt_lines (HEADER * msg)
146 if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME)) {
148 mvaddstr (HDR_CRYPT, SidebarWidth, " Security: ");
149 else if (msg->security & APPLICATION_SMIME)
150 mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
151 else if (msg->security & APPLICATION_PGP)
152 mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
154 else if ((WithCrypto & APPLICATION_SMIME))
155 mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
156 else if ((WithCrypto & APPLICATION_PGP))
157 mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
161 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
162 addstr (_("Sign, Encrypt"));
163 else if (msg->security & ENCRYPT)
164 addstr (_("Encrypt"));
165 else if (msg->security & SIGN)
170 if ((WithCrypto & APPLICATION_PGP))
171 if ((msg->security & APPLICATION_PGP)
172 && (msg->security & (ENCRYPT | SIGN))) {
173 if ((msg->security & INLINE))
174 addstr (_(" (inline)"));
176 addstr (_(" (PGP/MIME)"));
180 move (HDR_CRYPTINFO, SidebarWidth);
182 if ((WithCrypto & APPLICATION_PGP)
183 && msg->security & APPLICATION_PGP && msg->security & SIGN)
184 printw ("%s%s", _(" sign as: "),
185 PgpSignAs ? PgpSignAs : _("<default>"));
187 if ((WithCrypto & APPLICATION_SMIME)
188 && msg->security & APPLICATION_SMIME && msg->security & SIGN) {
189 printw ("%s%s", _(" sign as: "),
190 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
193 if ((WithCrypto & APPLICATION_SMIME)
194 && (msg->security & APPLICATION_SMIME)
195 && (msg->security & ENCRYPT)
196 && SmimeCryptAlg && *SmimeCryptAlg) {
197 mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "),
198 NONULL (SmimeCryptAlg));
206 static void redraw_mix_line (LIST * chain)
211 mvaddstr (HDR_MIX, SidebarWidth, " Mix: ");
214 addstr ("<no chain defined>");
219 for (c = 12; chain; chain = chain->next) {
221 if (t && t[0] == '0' && t[1] == '\0')
224 if (c + safe_strlen (t) + 2 >= COLS - SidebarWidth)
231 c += safe_strlen (t) + 2;
234 #endif /* MIXMASTER */
236 static int check_attachments (ATTACHPTR ** idx, short idxlen)
240 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
242 for (i = 0; i < idxlen; i++) {
243 strfcpy (pretty, idx[i]->content->filename, sizeof (pretty));
244 if (stat (idx[i]->content->filename, &st) != 0) {
245 mutt_pretty_mailbox (pretty);
246 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
250 if (idx[i]->content->stamp < st.st_mtime) {
251 mutt_pretty_mailbox (pretty);
252 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
255 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
256 mutt_update_encoding (idx[i]->content);
265 static void draw_envelope_addr (int line, ADDRESS * addr)
270 rfc822_write_address (buf, sizeof (buf), addr, 1);
271 mvprintw (line, SidebarWidth, TITLE_FMT, Prompts[line - 1]);
272 mutt_paddstr (W, buf);
275 static void draw_envelope (HEADER * msg, char *fcc)
277 draw_envelope_addr (HDR_FROM, msg->env->from);
279 if (!option (OPTNEWSSEND)) {
281 draw_envelope_addr (HDR_TO, msg->env->to);
282 draw_envelope_addr (HDR_CC, msg->env->cc);
283 draw_envelope_addr (HDR_BCC, msg->env->bcc);
287 mvprintw (HDR_TO, SidebarWidth, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
288 mutt_paddstr (W, NONULL (msg->env->newsgroups));
289 mvprintw (HDR_CC, SidebarWidth, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
290 mutt_paddstr (W, NONULL (msg->env->followup_to));
291 if (option (OPTXCOMMENTTO)) {
292 mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]);
293 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
297 mvprintw (HDR_SUBJECT, SidebarWidth, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
298 mutt_paddstr (W, NONULL (msg->env->subject));
299 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
300 mvprintw (HDR_FCC, SidebarWidth, TITLE_FMT, Prompts[HDR_FCC - 1]);
301 mutt_paddstr (W, fcc);
304 redraw_crypt_lines (msg);
307 redraw_mix_line (msg->chain);
310 SETCOLOR (MT_COLOR_STATUS);
311 mvaddstr (HDR_ATTACH - 1, SidebarWidth, _("-- Attachments"));
312 BKGDSET (MT_COLOR_STATUS);
315 BKGDSET (MT_COLOR_NORMAL);
316 SETCOLOR (MT_COLOR_NORMAL);
319 static int edit_address_list (int line, ADDRESS ** addr)
321 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
324 mutt_addrlist_to_local (*addr);
325 rfc822_write_address (buf, sizeof (buf), *addr, 0);
326 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
327 rfc822_free_address (addr);
328 *addr = mutt_parse_adrlist (*addr, buf);
329 *addr = mutt_expand_aliases (*addr);
332 if (option (OPTNEEDREDRAW)) {
333 unset_option (OPTNEEDREDRAW);
334 return (REDRAW_FULL);
337 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
338 mutt_error (_("Warning: '%s' is a bad IDN."), err);
343 /* redraw the expanded list so the user can see the result */
345 rfc822_write_address (buf, sizeof (buf), *addr, 1);
346 move (line, HDR_XOFFSET + SidebarWidth);
347 mutt_paddstr (W, buf);
352 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
354 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
357 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
359 if (x == 0 && menu->max == 1) {
360 mutt_error _("You may not delete the only attachment.");
362 idx[x]->content->tagged = 0;
366 for (y = 0; y < *idxlen; y++) {
367 if (idx[y]->content->next == idx[x]->content) {
368 idx[y]->content->next = idx[x]->content->next;
373 idx[x]->content->next = NULL;
374 idx[x]->content->parts = NULL;
375 mutt_free_body (&(idx[x]->content));
376 FREE (&idx[x]->tree);
378 for (; x < *idxlen - 1; x++)
380 menu->max = --(*idxlen);
385 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
387 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
389 idx[idxlen - 1]->content->next = idx[idxlen]->content;
390 idx[idxlen]->content->aptr = idx[idxlen];
391 menu->current = idxlen++;
392 mutt_update_tree (idx, idxlen);
399 * cum_attachs_size: Cumulative Attachments Size
401 * Returns the total number of bytes used by the attachments in the
402 * attachment list _after_ content-transfer-encodings have been
407 static unsigned long cum_attachs_size (MUTTMENU * menu)
411 ATTACHPTR **idx = menu->data;
415 for (i = 0, s = 0; i < menu->max; i++) {
419 b->content = mutt_get_content_info (b->filename, b);
421 if ((info = b->content)) {
422 switch (b->encoding) {
423 case ENCQUOTEDPRINTABLE:
424 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
427 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
430 s += info->lobin + info->hibin + info->ascii + info->crlf;
440 * compose_format_str()
442 * %a = total number of attachments
443 * %h = hostname [option]
444 * %l = approx. length of current message (in bytes)
447 * This function is similar to status_format_str(). Look at that function for
448 * help when modifying this function.
451 static const char *compose_format_str (char *buf, size_t buflen, char op,
452 const char *src, const char *prefix,
453 const char *ifstring,
454 const char *elsestring,
455 unsigned long data, format_flag flags)
457 char fmt[SHORT_STRING], tmp[SHORT_STRING];
458 int optional = (flags & M_FORMAT_OPTIONAL);
459 MUTTMENU *menu = (MUTTMENU *) data;
463 case 'a': /* total number of attachments */
464 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
465 snprintf (buf, buflen, fmt, menu->max);
468 case 'h': /* hostname */
469 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
470 snprintf (buf, buflen, fmt, NONULL (Hostname));
473 case 'l': /* approx length of current message in bytes */
474 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
475 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
476 snprintf (buf, buflen, fmt, tmp);
480 snprintf (fmt, sizeof (fmt), "Mutt-ng %%s");
481 snprintf (buf, buflen, fmt, MUTT_VERSION);
489 snprintf (buf, buflen, "%%%s%c", prefix, op);
494 compose_status_line (buf, buflen, menu, ifstring);
495 else if (flags & M_FORMAT_OPTIONAL)
496 compose_status_line (buf, buflen, menu, elsestring);
501 static void compose_status_line (char *buf, size_t buflen, MUTTMENU * menu,
504 mutt_FormatString (buf, buflen, p, compose_format_str,
505 (unsigned long) menu, 0);
511 * 1 message should be postponed
515 int mutt_compose_menu (HEADER * msg, /* structure for new message */
516 char *fcc, /* where to save a copy of the message */
517 size_t fcclen, HEADER * cur)
518 { /* current message */
519 char helpstr[SHORT_STRING];
520 char buf[LONG_STRING];
521 char fname[_POSIX_PATH_MAX];
523 ATTACHPTR **idx = NULL;
527 int r = -1; /* return value */
530 int fccSet = 0; /* has the user edited the Fcc: field ? */
531 CONTEXT *ctx = NULL, *this = NULL;
533 /* Sort, SortAux could be changed in mutt_index_menu() */
534 int oldSort, oldSortAux;
538 int news = 0; /* is it a news article ? */
540 if (option (OPTNEWSSEND))
544 mutt_attach_init (msg->content);
545 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
547 menu = mutt_new_menu ();
548 menu->menu = MENU_COMPOSE;
549 menu->offset = HDR_ATTACH;
551 menu->make_entry = snd_entry;
552 menu->tag = mutt_tag_attach;
557 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
562 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
565 if (option (OPTMBOXPANE))
569 unset_option (OPTNEWS); /* for any case */
571 switch (op = mutt_menuLoop (menu)) {
573 draw_envelope (msg, fcc);
574 menu->offset = HDR_ATTACH;
575 menu->pagelen = LINES - HDR_ATTACH - 2;
577 case OP_COMPOSE_EDIT_FROM:
578 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
579 mutt_message_hook (NULL, msg, M_SEND2HOOK);
581 case OP_COMPOSE_EDIT_TO:
585 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
586 mutt_message_hook (NULL, msg, M_SEND2HOOK);
591 case OP_COMPOSE_EDIT_BCC:
595 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
596 mutt_message_hook (NULL, msg, M_SEND2HOOK);
601 case OP_COMPOSE_EDIT_CC:
605 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
606 mutt_message_hook (NULL, msg, M_SEND2HOOK);
612 case OP_COMPOSE_EDIT_NEWSGROUPS:
614 if (msg->env->newsgroups)
615 strfcpy (buf, msg->env->newsgroups, sizeof (buf));
618 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
620 FREE (&msg->env->newsgroups);
621 mutt_remove_trailing_ws (buf);
622 msg->env->newsgroups = safe_strdup (mutt_skip_whitespace (buf));
623 move (HDR_TO, HDR_XOFFSET);
625 if (msg->env->newsgroups)
626 printw ("%-*.*s", W, W, msg->env->newsgroups);
631 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
634 if (msg->env->followup_to)
635 strfcpy (buf, msg->env->followup_to, sizeof (buf));
636 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
638 FREE (&msg->env->followup_to);
639 mutt_remove_trailing_ws (buf);
640 msg->env->followup_to = safe_strdup (mutt_skip_whitespace (buf));
641 move (HDR_CC, HDR_XOFFSET);
643 if (msg->env->followup_to)
644 printw ("%-*.*s", W, W, msg->env->followup_to);
649 case OP_COMPOSE_EDIT_X_COMMENT_TO:
650 if (news && option (OPTXCOMMENTTO)) {
652 if (msg->env->x_comment_to)
653 strfcpy (buf, msg->env->x_comment_to, sizeof (buf));
654 if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
656 FREE (&msg->env->x_comment_to);
657 msg->env->x_comment_to = safe_strdup (buf);
658 move (HDR_BCC, HDR_XOFFSET);
660 if (msg->env->x_comment_to)
661 printw ("%-*.*s", W, W, msg->env->x_comment_to);
666 case OP_COMPOSE_EDIT_SUBJECT:
667 if (msg->env->subject)
668 strfcpy (buf, msg->env->subject, sizeof (buf));
671 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
672 str_replace (&msg->env->subject, buf);
673 move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
675 if (msg->env->subject)
676 mutt_paddstr (W, msg->env->subject);
678 mutt_message_hook (NULL, msg, M_SEND2HOOK);
680 case OP_COMPOSE_EDIT_REPLY_TO:
681 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
682 mutt_message_hook (NULL, msg, M_SEND2HOOK);
684 case OP_COMPOSE_EDIT_FCC:
685 strfcpy (buf, fcc, sizeof (buf));
686 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
687 strfcpy (fcc, buf, _POSIX_PATH_MAX);
688 mutt_pretty_mailbox (fcc);
689 move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
690 mutt_paddstr (W, fcc);
693 MAYBE_REDRAW (menu->redraw);
694 mutt_message_hook (NULL, msg, M_SEND2HOOK);
696 case OP_COMPOSE_EDIT_MESSAGE:
697 if (Editor && (safe_strcmp ("builtin", Editor) != 0)
698 && !option (OPTEDITHDRS)) {
699 mutt_edit_file (Editor, msg->content->filename);
700 mutt_update_encoding (msg->content);
701 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
702 mutt_message_hook (NULL, msg, M_SEND2HOOK);
706 case OP_COMPOSE_EDIT_HEADERS:
707 if (safe_strcmp ("builtin", Editor) != 0 &&
708 (op == OP_COMPOSE_EDIT_HEADERS ||
709 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
710 char *tag = NULL, *err = NULL;
712 mutt_env_to_local (msg->env);
713 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
715 if (mutt_env_to_idna (msg->env, &tag, &err)) {
716 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
721 /* this is grouped with OP_COMPOSE_EDIT_HEADERS because the
722 attachment list could change if the user invokes ~v to edit
723 the message with headers, in which we need to execute the
724 code below to regenerate the index array */
725 mutt_builtin_editor (msg->content->filename, msg, cur);
727 mutt_update_encoding (msg->content);
729 /* attachments may have been added */
730 if (idxlen && idx[idxlen - 1]->content->next) {
731 for (i = 0; i < idxlen; i++)
735 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
741 menu->redraw = REDRAW_FULL;
742 mutt_message_hook (NULL, msg, M_SEND2HOOK);
747 case OP_COMPOSE_ATTACH_KEY:
748 if (!(WithCrypto & APPLICATION_PGP))
750 if (idxlen == idxmax) {
751 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
755 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
756 if ((idx[idxlen]->content =
757 crypt_pgp_make_key_attachment (NULL)) != NULL) {
758 update_idx (menu, idx, idxlen++);
759 menu->redraw |= REDRAW_INDEX;
764 menu->redraw |= REDRAW_STATUS;
766 if (option (OPTNEEDREDRAW)) {
767 menu->redraw = REDRAW_FULL;
768 unset_option (OPTNEEDREDRAW);
771 mutt_message_hook (NULL, msg, M_SEND2HOOK);
775 case OP_COMPOSE_ATTACH_FILE:
777 char *prompt, **files;
781 prompt = _("Attach file");
785 if (_mutt_enter_fname
786 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
787 &numfiles) == -1 || *fname == '\0')
790 if (idxlen + numfiles >= idxmax) {
792 sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles));
798 mutt_message _("Attaching selected files...");
800 for (i = 0; i < numfiles; i++) {
801 char *att = files[i];
803 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
804 idx[idxlen]->content = mutt_make_file_attach (att);
805 if (idx[idxlen]->content != NULL)
806 update_idx (menu, idx, idxlen++);
809 mutt_error (_("Unable to attach %s!"), att);
818 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
820 mutt_message_hook (NULL, msg, M_SEND2HOOK);
823 case OP_COMPOSE_ATTACH_MESSAGE:
825 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
832 prompt = _("Open mailbox to attach message from");
835 unset_option (OPTNEWS);
836 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
837 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
840 prompt = _("Open newsgroup to attach message from");
841 set_option (OPTNEWS);
847 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
850 strfcpy (fname, NONULL (Context->path), sizeof (fname));
851 mutt_pretty_mailbox (fname);
854 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
859 if (option (OPTNEWS))
860 nntp_expand_path (fname, sizeof (fname),
861 &CurrentNewsSrv->conn->account);
864 mutt_expand_path (fname, sizeof (fname));
866 if (mx_get_magic (fname) != M_IMAP)
869 if (mx_get_magic (fname) != M_POP)
872 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
874 /* check to make sure the file exists and is readable */
875 if (access (fname, R_OK) == -1) {
880 menu->redraw = REDRAW_FULL;
882 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
888 if (!ctx->msgcount) {
889 mx_close_mailbox (ctx, NULL);
891 mutt_error _("No messages in that folder.");
896 this = Context; /* remember current folder and sort methods */
898 oldSortAux = SortAux;
901 set_option (OPTATTACHMSG);
902 mutt_message _("Tag the messages you want to attach!");
904 close = mutt_index_menu ();
905 unset_option (OPTATTACHMSG);
908 /* go back to the folder we started from */
910 /* Restore old $sort and $sort_aux */
912 SortAux = oldSortAux;
913 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
917 if (idxlen + Context->tagged >= idxmax) {
919 sizeof (ATTACHPTR *) * (idxmax +=
920 5 + Context->tagged));
924 for (i = 0; i < Context->msgcount; i++) {
925 h = Context->hdrs[i];
927 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
928 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
929 if (idx[idxlen]->content != NULL)
930 update_idx (menu, idx, idxlen++);
932 mutt_error _("Unable to attach!");
938 menu->redraw |= REDRAW_FULL;
940 if (close == OP_QUIT)
941 mx_close_mailbox (Context, NULL);
943 mx_fastclose_mailbox (Context);
946 /* go back to the folder we started from */
948 /* Restore old $sort and $sort_aux */
950 SortAux = oldSortAux;
952 mutt_message_hook (NULL, msg, M_SEND2HOOK);
957 if (delete_attachment (menu, &idxlen, menu->current) == -1)
959 mutt_update_tree (idx, idxlen);
961 if (menu->current > idxlen - 1)
962 menu->current = idxlen - 1;
967 if (menu->current == 0)
968 msg->content = idx[0]->content;
970 menu->redraw |= REDRAW_STATUS;
971 mutt_message_hook (NULL, msg, M_SEND2HOOK);
974 #define CURRENT idx[menu->current]->content
976 case OP_COMPOSE_TOGGLE_RECODE:
979 if (!mutt_is_text_part (CURRENT)) {
980 mutt_error (_("Recoding only affects text attachments."));
983 CURRENT->noconv = !CURRENT->noconv;
985 mutt_message (_("The current attachment won't be converted."));
987 mutt_message (_("The current attachment will be converted."));
988 menu->redraw = REDRAW_CURRENT;
989 mutt_message_hook (NULL, msg, M_SEND2HOOK);
994 case OP_COMPOSE_EDIT_DESCRIPTION:
997 idx[menu->current]->content->description ?
998 idx[menu->current]->content->description : "", sizeof (buf));
999 /* header names should not be translated */
1000 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
1001 str_replace (&idx[menu->current]->content->description, buf);
1002 menu->redraw = REDRAW_CURRENT;
1004 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1007 case OP_COMPOSE_UPDATE_ENCODING:
1009 if (menu->tagprefix) {
1012 for (top = msg->content; top; top = top->next) {
1014 mutt_update_encoding (top);
1016 menu->redraw = REDRAW_FULL;
1019 mutt_update_encoding (idx[menu->current]->content);
1020 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1022 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1025 case OP_COMPOSE_TOGGLE_DISPOSITION:
1026 /* toggle the content-disposition between inline/attachment */
1027 idx[menu->current]->content->disposition =
1028 (idx[menu->current]->content->disposition ==
1029 DISPINLINE) ? DISPATTACH : DISPINLINE;
1030 menu->redraw = REDRAW_CURRENT;
1036 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
1038 /* this may have been a change to text/something */
1039 mutt_update_encoding (idx[menu->current]->content);
1041 menu->redraw = REDRAW_CURRENT;
1043 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1046 case OP_COMPOSE_EDIT_ENCODING:
1048 strfcpy (buf, ENCODING (idx[menu->current]->content->encoding),
1050 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
1051 sizeof (buf), 0) == 0 && buf[0]) {
1052 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
1053 idx[menu->current]->content->encoding = i;
1054 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1055 mutt_clear_error ();
1058 mutt_error _("Invalid encoding.");
1060 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1063 case OP_COMPOSE_SEND_MESSAGE:
1065 /* Note: We don't invoke send2-hook here, since we want to leave
1066 * users an opportunity to change settings from the ":" prompt.
1069 if (check_attachments (idx, idxlen) != 0) {
1070 menu->redraw = REDRAW_FULL;
1076 if (msg->chain && mix_check_message (msg) != 0)
1080 if (!fccSet && *fcc) {
1081 if ((i = query_quadoption (OPT_COPY,
1082 _("Save a copy of this message?"))) == -1)
1092 case OP_COMPOSE_EDIT_FILE:
1094 mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename);
1095 mutt_update_encoding (idx[menu->current]->content);
1096 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1097 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1100 case OP_COMPOSE_TOGGLE_UNLINK:
1102 idx[menu->current]->content->unlink =
1103 !idx[menu->current]->content->unlink;
1106 /* OPTRESOLVE is otherwise ignored on this menu.
1110 if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
1113 menu->redraw = REDRAW_INDEX;
1114 /* No send2hook since this doesn't change the message. */
1117 case OP_COMPOSE_GET_ATTACHMENT:
1119 if (menu->tagprefix) {
1122 for (top = msg->content; top; top = top->next) {
1124 mutt_get_tmp_attachment (top);
1126 menu->redraw = REDRAW_FULL;
1128 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1129 menu->redraw = REDRAW_CURRENT;
1131 /* No send2hook since this doesn't change the message. */
1134 case OP_COMPOSE_RENAME_FILE:
1136 strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname));
1137 mutt_pretty_mailbox (fname);
1138 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1140 if (stat (idx[menu->current]->content->filename, &st) == -1) {
1141 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1145 mutt_expand_path (fname, sizeof (fname));
1146 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1149 str_replace (&idx[menu->current]->content->filename, fname);
1150 menu->redraw = REDRAW_CURRENT;
1152 if (idx[menu->current]->content->stamp >= st.st_mtime)
1153 mutt_stamp_attachment (idx[menu->current]->content);
1156 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1159 case OP_COMPOSE_NEW_MIME:
1166 CLEARLINE (LINES - 1);
1168 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1171 mutt_expand_path (fname, sizeof (fname));
1173 /* Call to lookup_mime_type () ? maybe later */
1175 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1179 if (!(p = strchr (type, '/'))) {
1180 mutt_error _("Content-Type is of the form base/sub");
1185 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1186 mutt_error (_("Unknown Content-Type %s"), type);
1189 if (idxlen == idxmax) {
1190 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
1194 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
1195 /* Touch the file */
1196 if (!(fp = safe_fopen (fname, "w"))) {
1197 mutt_error (_("Can't create file %s"), fname);
1198 FREE (&idx[idxlen]);
1203 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1205 _("What we have here is a failure to make an attachment");
1208 update_idx (menu, idx, idxlen++);
1210 idx[menu->current]->content->type = itype;
1211 str_replace (&idx[menu->current]->content->subtype, p);
1212 idx[menu->current]->content->unlink = 1;
1213 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1215 if (mutt_compose_attachment (idx[menu->current]->content)) {
1216 mutt_update_encoding (idx[menu->current]->content);
1217 menu->redraw = REDRAW_FULL;
1220 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1223 case OP_COMPOSE_EDIT_MIME:
1225 if (mutt_edit_attachment (idx[menu->current]->content)) {
1226 mutt_update_encoding (idx[menu->current]->content);
1227 menu->redraw = REDRAW_FULL;
1229 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1232 case OP_VIEW_ATTACH:
1233 case OP_DISPLAY_HEADERS:
1235 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1237 menu->redraw = REDRAW_FULL;
1238 /* no send2hook, since this doesn't modify the message */
1243 mutt_save_attachment_list (NULL, menu->tagprefix,
1244 menu->tagprefix ? msg->content : idx[menu->
1246 content, NULL, menu);
1247 MAYBE_REDRAW (menu->redraw);
1248 /* no send2hook, since this doesn't modify the message */
1253 mutt_print_attachment_list (NULL, menu->tagprefix,
1254 menu->tagprefix ? msg->content : idx[menu->
1257 /* no send2hook, since this doesn't modify the message */
1263 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1264 menu->tagprefix ? msg->content : idx[menu->
1266 content, op == OP_FILTER);
1267 if (op == OP_FILTER) /* cte might have changed */
1268 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1269 menu->redraw |= REDRAW_STATUS;
1270 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1275 query_quadoption (OPT_POSTPONE,
1276 _("Postpone this message?"))) == M_NO) {
1277 while (idxlen-- > 0) {
1278 /* avoid freeing other attachments */
1279 idx[idxlen]->content->next = NULL;
1280 idx[idxlen]->content->parts = NULL;
1281 mutt_free_body (&idx[idxlen]->content);
1282 FREE (&idx[idxlen]->tree);
1283 FREE (&idx[idxlen]);
1295 /* fall through to postpone! */
1297 case OP_COMPOSE_POSTPONE_MESSAGE:
1299 if (check_attachments (idx, idxlen) != 0) {
1300 menu->redraw = REDRAW_FULL;
1308 case OP_COMPOSE_ISPELL:
1310 snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1311 msg->content->filename);
1312 if (mutt_system (buf) == -1)
1313 mutt_error (_("Error running \"%s\"!"), buf);
1315 mutt_update_encoding (msg->content);
1316 menu->redraw |= REDRAW_STATUS;
1320 case OP_COMPOSE_WRITE_MESSAGE:
1324 strfcpy (fname, NONULL (Context->path), sizeof (fname));
1325 mutt_pretty_mailbox (fname);
1328 msg->content = idx[0]->content;
1329 if (mutt_enter_fname
1330 (_("Write message to mailbox"), fname, sizeof (fname),
1331 &menu->redraw, 1) != -1 && fname[0]) {
1332 mutt_message (_("Writing message to %s ..."), fname);
1333 mutt_expand_path (fname, sizeof (fname));
1335 if (msg->content->next)
1336 msg->content = mutt_make_multipart (msg->content);
1338 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1339 msg->content = mutt_remove_multipart (msg->content);
1341 mutt_message _("Message written.");
1347 case OP_COMPOSE_PGP_MENU:
1348 if (!(WithCrypto & APPLICATION_PGP))
1350 if ((WithCrypto & APPLICATION_SMIME)
1351 && msg->security & APPLICATION_SMIME) {
1352 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1354 mutt_clear_error ();
1359 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1360 redraw_crypt_lines (msg);
1361 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1365 case OP_FORGET_PASSPHRASE:
1366 crypt_forget_passphrase ();
1370 case OP_COMPOSE_SMIME_MENU:
1371 if (!(WithCrypto & APPLICATION_SMIME))
1374 if ((WithCrypto & APPLICATION_PGP)
1375 && msg->security & APPLICATION_PGP) {
1376 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1378 mutt_clear_error ();
1383 msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1384 redraw_crypt_lines (msg);
1385 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1390 case OP_COMPOSE_MIX:
1392 mix_make_chain (&msg->chain, &menu->redraw);
1393 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1399 /* Draw formated compose status line */
1400 if (menu->redraw & REDRAW_STATUS) {
1401 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1402 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1403 SETCOLOR (MT_COLOR_STATUS);
1404 printw ("%-*.*s", COLS, COLS, buf);
1405 SETCOLOR (MT_COLOR_NORMAL);
1406 menu->redraw &= ~REDRAW_STATUS;
1410 mutt_menuDestroy (&menu);
1413 msg->content = idx[0]->content;
1414 for (i = 0; i < idxlen; i++) {
1415 idx[i]->content->aptr = NULL;
1420 msg->content = NULL;