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 int w=(COLS-SW)>blen?blen:COLS-SW;
117 m_strformat (b, w, NONULL (AttachFormat), mutt_attach_fmt,
118 ((ATTACHPTR **)menu->data)[num],
119 M_FORMAT_STAT_FILE | (option(OPTARROWCURSOR) ? M_FORMAT_ARROWCURSOR : 0));
122 static void redraw_crypt_lines (HEADER * msg)
127 mvaddstr (HDR_CRYPT, SW, " Security: ");
128 else if (msg->security & APPLICATION_SMIME)
129 mvaddstr (HDR_CRYPT, SW, " S/MIME: ");
130 else if (msg->security & APPLICATION_PGP)
131 mvaddstr (HDR_CRYPT, SW, " PGP: ");
133 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
134 addstr (_("Sign, Encrypt"));
135 else if (msg->security & ENCRYPT)
136 addstr (_("Encrypt"));
137 else if (msg->security & SIGN)
142 if ((msg->security & APPLICATION_PGP)
143 && (msg->security & (ENCRYPT | SIGN))) {
144 if ((msg->security & INLINE))
145 addstr (_(" (inline)"));
147 addstr (_(" (PGP/MIME)"));
151 move (HDR_CRYPTINFO, SW);
153 if (msg->security & APPLICATION_PGP && msg->security & SIGN)
154 printw ("%s%s", _(" sign as: "),
155 PgpSignAs ? PgpSignAs : _("<default>"));
157 if (msg->security & APPLICATION_SMIME && msg->security & SIGN) {
158 printw ("%s%s", _(" sign as: "),
159 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
162 if ((msg->security & APPLICATION_SMIME)
163 && (msg->security & ENCRYPT)
164 && SmimeCryptAlg && *SmimeCryptAlg) {
165 mvprintw (HDR_CRYPTINFO, SW + 40, "%s%s", _("Encrypt with: "),
166 NONULL (SmimeCryptAlg));
171 static void redraw_mix_line (string_list_t * chain)
176 mvaddstr (HDR_MIX, SW, " Mix: ");
179 addstr ("<no chain defined>");
184 for (c = 12; chain; chain = chain->next) {
186 if (t && t[0] == '0' && t[1] == '\0')
189 if (c + m_strlen(t) + 2 >= COLS - SW)
196 c += m_strlen(t) + 2;
200 static int check_attachments (ATTACHPTR ** idx, short idxlen)
204 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + STRING];
206 for (i = 0; i < idxlen; i++) {
207 m_strcpy(pretty, sizeof(pretty), idx[i]->content->filename);
208 if (stat (idx[i]->content->filename, &st) != 0) {
209 mutt_pretty_mailbox (pretty);
210 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
214 if (idx[i]->content->stamp < st.st_mtime) {
215 mutt_pretty_mailbox (pretty);
216 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
219 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
220 mutt_update_encoding (idx[i]->content);
229 static void draw_envelope_addr (int line, address_t * addr)
234 rfc822_addrcat(buf, sizeof (buf), addr, 1);
235 mvprintw (line, SW, TITLE_FMT, Prompts[line - 1]);
236 mutt_paddstr (W, buf);
239 static void draw_envelope (HEADER * msg, char *fcc)
241 draw_envelope_addr (HDR_FROM, msg->env->from);
243 if (!option (OPTNEWSSEND)) {
245 draw_envelope_addr (HDR_TO, msg->env->to);
246 draw_envelope_addr (HDR_CC, msg->env->cc);
247 draw_envelope_addr (HDR_BCC, msg->env->bcc);
250 mvprintw (HDR_TO, SW, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
251 mutt_paddstr (W, NONULL (msg->env->newsgroups));
252 mvprintw (HDR_CC, SW, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
253 mutt_paddstr (W, NONULL (msg->env->followup_to));
254 if (option (OPTXCOMMENTTO)) {
255 mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]);
256 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
260 mvprintw (HDR_SUBJECT, SW, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
261 mutt_paddstr (W, NONULL (msg->env->subject));
262 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
263 mvprintw (HDR_FCC, SW, TITLE_FMT, Prompts[HDR_FCC - 1]);
264 mutt_paddstr (W, fcc);
266 redraw_crypt_lines (msg);
267 redraw_mix_line (msg->chain);
269 SETCOLOR (MT_COLOR_STATUS);
270 mvaddstr (HDR_ATTACH - 1, SW, _("-- Attachments"));
271 BKGDSET (MT_COLOR_STATUS);
274 BKGDSET (MT_COLOR_NORMAL);
275 SETCOLOR (MT_COLOR_NORMAL);
278 static int edit_address_list (int line, address_t ** addr)
280 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
283 mutt_addrlist_to_local (*addr);
284 rfc822_addrcat(buf, sizeof (buf), *addr, 0);
285 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
286 address_list_wipe(addr);
287 *addr = mutt_parse_adrlist (*addr, buf);
288 *addr = mutt_expand_aliases (*addr);
291 if (option (OPTNEEDREDRAW)) {
292 unset_option (OPTNEEDREDRAW);
296 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
297 mutt_error (_("Warning: '%s' is a bad IDN."), err);
302 /* redraw the expanded list so the user can see the result */
304 rfc822_addrcat(buf, sizeof (buf), *addr, 1);
305 move (line, HDR_XOFFSET + SW);
306 mutt_paddstr (W, buf);
311 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
313 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
316 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
318 if (x == 0 && menu->max == 1) {
319 mutt_error _("You may not delete the only attachment.");
321 idx[x]->content->tagged = 0;
325 for (y = 0; y < *idxlen; y++) {
326 if (idx[y]->content->next == idx[x]->content) {
327 idx[y]->content->next = idx[x]->content->next;
332 idx[x]->content->next = NULL;
333 idx[x]->content->parts = NULL;
334 body_list_wipe(&(idx[x]->content));
335 p_delete(&idx[x]->tree);
337 for (; x < *idxlen - 1; x++)
339 menu->max = --(*idxlen);
344 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
346 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
348 idx[idxlen - 1]->content->next = idx[idxlen]->content;
349 idx[idxlen]->content->aptr = idx[idxlen];
350 menu->current = idxlen++;
351 mutt_update_tree (idx, idxlen);
358 * cum_attachs_size: Cumulative Attachments Size
360 * Returns the total number of bytes used by the attachments in the
361 * attachment list _after_ content-transfer-encodings have been
365 static unsigned long cum_attachs_size(MUTTMENU * menu)
369 ATTACHPTR **idx = menu->data;
373 for (i = 0, s = 0; i < menu->max; i++) {
377 b->content = mutt_get_content_info (b->filename, b);
379 if ((info = b->content)) {
380 switch (b->encoding) {
381 case ENCQUOTEDPRINTABLE:
382 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
385 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
388 s += info->lobin + info->hibin + info->ascii + info->crlf;
398 * compose_format_str()
400 * %a = total number of attachments
401 * %h = hostname [option]
402 * %l = approx. length of current message (in bytes)
405 * This function is similar to status_format_str(). Look at that function for
406 * help when modifying this function.
408 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
411 static const char *compose_format_str (char *buf, ssize_t buflen, char op,
412 const char *src, const char *prefix,
415 anytype data, format_flag flags)
417 char fmt[STRING], tmp[STRING];
418 int optional = (flags & M_FORMAT_OPTIONAL);
419 MUTTMENU *menu = data.ptr;
423 case 'a': /* total number of attachments */
424 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
425 snprintf (buf, buflen, fmt, menu->max);
428 case 'h': /* hostname */
429 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
430 snprintf (buf, buflen, fmt, NONULL (Hostname));
433 case 'l': /* approx length of current message in bytes */
434 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
435 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
436 snprintf (buf, buflen, fmt, tmp);
440 m_strcpy(buf, buflen, mutt_make_version (0));
453 compose_status_line (buf, buflen, menu, ifstr);
454 else if (flags & M_FORMAT_OPTIONAL)
455 compose_status_line (buf, buflen, menu, elstr);
460 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
463 int w=(COLS-SW)>buflen?buflen:(COLS-SW);
464 m_strformat(buf, w, p, compose_format_str, menu, 0);
469 * 1 message should be postponed
473 int mutt_compose_menu (HEADER * msg, /* structure for new message */
474 char *fcc, /* where to save a copy of the message */
476 HEADER * cur __attribute__ ((unused)))
477 { /* current message */
478 char helpstr[STRING];
479 char buf[LONG_STRING];
480 char fname[_POSIX_PATH_MAX];
482 ATTACHPTR **idx = NULL;
486 int r = -1; /* return value */
489 int fccSet = 0; /* has the user edited the Fcc: field ? */
490 CONTEXT *ctx = NULL, *this = NULL;
492 /* Sort, SortAux could be changed in mutt_index_menu() */
493 int oldSort, oldSortAux;
497 int news = 0; /* is it a news article ? */
499 if (option (OPTNEWSSEND))
503 mutt_attach_init (msg->content);
504 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
506 menu = mutt_new_menu ();
507 menu->menu = MENU_COMPOSE;
508 menu->offset = HDR_ATTACH;
510 menu->make_entry = snd_entry;
511 menu->tag = mutt_tag_attach;
515 menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_COMPOSE,
519 menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_COMPOSE,
522 if (option (OPTMBOXPANE))
526 unset_option (OPTNEWS); /* for any case */
528 switch (op = mutt_menuLoop (menu)) {
530 draw_envelope (msg, fcc);
531 menu->offset = HDR_ATTACH;
532 menu->pagelen = LINES - HDR_ATTACH - 2;
534 case OP_COMPOSE_EDIT_FROM:
535 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
536 mutt_message_hook (NULL, msg, M_SEND2HOOK);
538 case OP_COMPOSE_EDIT_TO:
542 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
543 mutt_message_hook (NULL, msg, M_SEND2HOOK);
548 case OP_COMPOSE_EDIT_BCC:
552 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
553 mutt_message_hook (NULL, msg, M_SEND2HOOK);
558 case OP_COMPOSE_EDIT_CC:
562 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
563 mutt_message_hook (NULL, msg, M_SEND2HOOK);
569 case OP_COMPOSE_EDIT_NEWSGROUPS:
571 if (msg->env->newsgroups)
572 m_strcpy(buf, sizeof(buf), msg->env->newsgroups);
575 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
577 p_delete(&msg->env->newsgroups);
579 msg->env->newsgroups = m_strdup(skipspaces(buf));
580 move (HDR_TO, HDR_XOFFSET);
582 if (msg->env->newsgroups)
583 printw ("%-*.*s", W, W, msg->env->newsgroups);
588 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
591 if (msg->env->followup_to)
592 m_strcpy(buf, sizeof(buf), msg->env->followup_to);
593 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
595 p_delete(&msg->env->followup_to);
597 msg->env->followup_to = m_strdup(skipspaces(buf));
598 move (HDR_CC, HDR_XOFFSET);
600 if (msg->env->followup_to)
601 printw ("%-*.*s", W, W, msg->env->followup_to);
606 case OP_COMPOSE_EDIT_X_COMMENT_TO:
607 if (news && option (OPTXCOMMENTTO)) {
609 if (msg->env->x_comment_to)
610 m_strcpy(buf, sizeof(buf), msg->env->x_comment_to);
611 if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
613 p_delete(&msg->env->x_comment_to);
614 msg->env->x_comment_to = m_strdup(buf);
615 move (HDR_BCC, HDR_XOFFSET);
617 if (msg->env->x_comment_to)
618 printw ("%-*.*s", W, W, msg->env->x_comment_to);
623 case OP_COMPOSE_EDIT_SUBJECT:
624 if (msg->env->subject)
625 m_strcpy(buf, sizeof(buf), msg->env->subject);
628 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
629 m_strreplace(&msg->env->subject, buf);
630 move (HDR_SUBJECT, HDR_XOFFSET + SW);
632 if (msg->env->subject)
633 mutt_paddstr (W, msg->env->subject);
635 mutt_message_hook (NULL, msg, M_SEND2HOOK);
637 case OP_COMPOSE_EDIT_REPLY_TO:
638 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
639 mutt_message_hook (NULL, msg, M_SEND2HOOK);
641 case OP_COMPOSE_EDIT_FCC:
642 m_strcpy(buf, sizeof(buf), fcc);
643 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
644 m_strcpy(fcc, _POSIX_PATH_MAX, buf);
645 mutt_pretty_mailbox (fcc);
646 move (HDR_FCC, HDR_XOFFSET + SW);
647 mutt_paddstr (W, fcc);
650 MAYBE_REDRAW (menu->redraw);
651 mutt_message_hook (NULL, msg, M_SEND2HOOK);
653 case OP_COMPOSE_EDIT_MESSAGE:
654 if (Editor && !option (OPTEDITHDRS)) {
655 mutt_edit_file (Editor, msg->content->filename);
656 mutt_update_encoding (msg->content);
657 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
658 mutt_message_hook (NULL, msg, M_SEND2HOOK);
662 case OP_COMPOSE_EDIT_HEADERS:
663 if ((op == OP_COMPOSE_EDIT_HEADERS ||
664 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
665 const char *tag = NULL;
668 mutt_env_to_local (msg->env);
669 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
671 if (mutt_env_to_idna (msg->env, &tag, &err)) {
672 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
676 mutt_update_encoding (msg->content);
678 /* attachments may have been added */
679 if (idxlen && idx[idxlen - 1]->content->next) {
680 for (i = 0; i < idxlen; i++)
684 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
690 menu->redraw = REDRAW_FULL;
691 mutt_message_hook (NULL, msg, M_SEND2HOOK);
694 case OP_COMPOSE_ATTACH_KEY:
695 if (idxlen == idxmax) {
696 p_realloc(&idx, idxmax += 5);
700 idx[idxlen] = p_new(ATTACHPTR, 1);
701 if ((idx[idxlen]->content =
702 crypt_pgp_make_key_attachment (NULL)) != NULL) {
703 update_idx (menu, idx, idxlen++);
704 menu->redraw |= REDRAW_INDEX;
707 p_delete(&idx[idxlen]);
709 menu->redraw |= REDRAW_STATUS;
711 if (option (OPTNEEDREDRAW)) {
712 menu->redraw = REDRAW_FULL;
713 unset_option (OPTNEEDREDRAW);
716 mutt_message_hook (NULL, msg, M_SEND2HOOK);
719 case OP_COMPOSE_ATTACH_FILE:
721 char *prompt, **files;
725 prompt = _("Attach file");
729 if (_mutt_enter_fname
730 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
731 &numfiles) == -1 || *fname == '\0')
734 if (idxlen + numfiles >= idxmax) {
735 p_realloc(&idx, idxmax += 5 + numfiles);
741 mutt_message _("Attaching selected files...");
743 for (i = 0; i < numfiles; i++) {
744 char *att = files[i];
746 idx[idxlen] = p_new(ATTACHPTR, 1);
747 idx[idxlen]->unowned = 1;
748 idx[idxlen]->content = mutt_make_file_attach (att);
749 if (idx[idxlen]->content != NULL)
750 update_idx (menu, idx, idxlen++);
753 mutt_error (_("Unable to attach %s!"), att);
754 p_delete(&idx[idxlen]);
762 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
764 mutt_message_hook (NULL, msg, M_SEND2HOOK);
767 case OP_COMPOSE_ATTACH_MESSAGE:
769 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
776 prompt = _("Open mailbox to attach message from");
779 unset_option (OPTNEWS);
780 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
781 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
784 prompt = _("Open newsgroup to attach message from");
785 set_option (OPTNEWS);
791 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
794 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
795 mutt_pretty_mailbox (fname);
798 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
803 if (option (OPTNEWS))
804 nntp_expand_path (fname, sizeof (fname),
805 &CurrentNewsSrv->conn->account);
808 mutt_expand_path (fname, sizeof (fname));
809 if (mx_get_magic (fname) != M_IMAP)
810 if (mx_get_magic (fname) != M_POP)
812 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
814 /* check to make sure the file exists and is readable */
815 if (access (fname, R_OK) == -1) {
820 menu->redraw = REDRAW_FULL;
822 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
828 if (!ctx->msgcount) {
829 mx_close_mailbox (ctx, NULL);
831 mutt_error _("No messages in that folder.");
836 this = Context; /* remember current folder and sort methods */
838 oldSortAux = SortAux;
841 set_option (OPTATTACHMSG);
842 mutt_message _("Tag the messages you want to attach!");
844 closed = mutt_index_menu ();
845 unset_option (OPTATTACHMSG);
848 /* go back to the folder we started from */
850 /* Restore old $sort and $sort_aux */
852 SortAux = oldSortAux;
853 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
857 if (idxlen + Context->tagged >= idxmax) {
858 p_realloc(&idx, idxmax += 5 + Context->tagged);
862 for (i = 0; i < Context->msgcount; i++) {
863 h = Context->hdrs[i];
865 idx[idxlen] = p_new(ATTACHPTR, 1);
866 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
867 if (idx[idxlen]->content != NULL)
868 update_idx (menu, idx, idxlen++);
870 mutt_error _("Unable to attach!");
872 p_delete(&idx[idxlen]);
876 menu->redraw |= REDRAW_FULL;
878 if (closed == OP_QUIT)
879 mx_close_mailbox (Context, NULL);
881 mx_fastclose_mailbox (Context);
884 /* go back to the folder we started from */
886 /* Restore old $sort and $sort_aux */
888 SortAux = oldSortAux;
890 mutt_message_hook (NULL, msg, M_SEND2HOOK);
895 if (idx[menu->current]->unowned)
896 idx[menu->current]->content->unlink = 0;
897 if (delete_attachment (menu, &idxlen, menu->current) == -1)
899 mutt_update_tree (idx, idxlen);
901 if (menu->current > idxlen - 1)
902 menu->current = idxlen - 1;
907 if (menu->current == 0)
908 msg->content = idx[0]->content;
910 menu->redraw |= REDRAW_STATUS;
911 mutt_message_hook (NULL, msg, M_SEND2HOOK);
914 #define CURRENT idx[menu->current]->content
916 case OP_COMPOSE_TOGGLE_RECODE:
919 if (!mutt_is_text_part (CURRENT)) {
920 mutt_error (_("Recoding only affects text attachments."));
923 CURRENT->noconv = !CURRENT->noconv;
925 mutt_message (_("The current attachment won't be converted."));
927 mutt_message (_("The current attachment will be converted."));
928 menu->redraw = REDRAW_CURRENT;
929 mutt_message_hook (NULL, msg, M_SEND2HOOK);
934 case OP_COMPOSE_EDIT_DESCRIPTION:
936 m_strcpy(buf, sizeof(buf),
937 NONULL(idx[menu->current]->content->description));
938 /* header names should not be translated */
939 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
940 m_strreplace(&idx[menu->current]->content->description, buf);
941 menu->redraw = REDRAW_CURRENT;
943 mutt_message_hook (NULL, msg, M_SEND2HOOK);
946 case OP_COMPOSE_UPDATE_ENCODING:
948 if (menu->tagprefix) {
951 for (top = msg->content; top; top = top->next) {
953 mutt_update_encoding (top);
955 menu->redraw = REDRAW_FULL;
958 mutt_update_encoding (idx[menu->current]->content);
959 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
961 mutt_message_hook (NULL, msg, M_SEND2HOOK);
964 case OP_COMPOSE_TOGGLE_DISPOSITION:
965 /* toggle the content-disposition between inline/attachment */
966 idx[menu->current]->content->disposition =
967 (idx[menu->current]->content->disposition ==
968 DISPINLINE) ? DISPATTACH : DISPINLINE;
969 menu->redraw = REDRAW_CURRENT;
975 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
977 /* this may have been a change to text/something */
978 mutt_update_encoding (idx[menu->current]->content);
980 menu->redraw = REDRAW_CURRENT;
982 mutt_message_hook (NULL, msg, M_SEND2HOOK);
985 case OP_COMPOSE_EDIT_ENCODING:
987 m_strcpy(buf, sizeof(buf),
988 ENCODING(idx[menu->current]->content->encoding));
989 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
990 sizeof (buf), 0) == 0 && buf[0]) {
991 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
992 idx[menu->current]->content->encoding = i;
993 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
997 mutt_error _("Invalid encoding.");
999 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1002 case OP_COMPOSE_SEND_MESSAGE:
1004 /* Note: We don't invoke send2-hook here, since we want to leave
1005 * users an opportunity to change settings from the ":" prompt.
1008 if (check_attachments (idx, idxlen) != 0) {
1009 menu->redraw = REDRAW_FULL;
1013 if (msg->chain && mix_check_message (msg) != 0)
1016 if (!fccSet && *fcc) {
1017 if ((i = query_quadoption (OPT_COPY,
1018 _("Save a copy of this message?"))) == -1)
1028 case OP_COMPOSE_EDIT_FILE:
1030 mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename);
1031 mutt_update_encoding (idx[menu->current]->content);
1032 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1033 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1036 case OP_COMPOSE_TOGGLE_UNLINK:
1038 idx[menu->current]->content->unlink =
1039 !idx[menu->current]->content->unlink;
1041 menu->redraw = REDRAW_INDEX;
1042 /* No send2hook since this doesn't change the message. */
1045 case OP_COMPOSE_GET_ATTACHMENT:
1047 if (menu->tagprefix) {
1050 for (top = msg->content; top; top = top->next) {
1052 mutt_get_tmp_attachment (top);
1054 menu->redraw = REDRAW_FULL;
1056 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1057 menu->redraw = REDRAW_CURRENT;
1059 /* No send2hook since this doesn't change the message. */
1062 case OP_COMPOSE_RENAME_FILE:
1064 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
1065 mutt_pretty_mailbox (fname);
1066 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1068 if (stat (idx[menu->current]->content->filename, &st) == -1) {
1069 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1073 mutt_expand_path (fname, sizeof (fname));
1074 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1077 m_strreplace(&idx[menu->current]->content->filename, fname);
1078 menu->redraw = REDRAW_CURRENT;
1080 if (idx[menu->current]->content->stamp >= st.st_mtime)
1081 mutt_stamp_attachment (idx[menu->current]->content);
1084 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1087 case OP_COMPOSE_NEW_MIME:
1094 CLEARLINE (LINES - 1);
1096 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1099 mutt_expand_path (fname, sizeof (fname));
1101 /* Call to lookup_mime_type () ? maybe later */
1103 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1107 if (!(p = strchr (type, '/'))) {
1108 mutt_error _("Content-Type is of the form base/sub");
1113 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1114 mutt_error (_("Unknown Content-Type %s"), type);
1117 if (idxlen == idxmax) {
1118 p_realloc(&idx, idxmax += 5);
1122 idx[idxlen] = p_new(ATTACHPTR, 1);
1123 /* Touch the file */
1124 if (!(fp = safe_fopen (fname, "w"))) {
1125 mutt_error (_("Can't create file %s"), fname);
1126 p_delete(&idx[idxlen]);
1131 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1133 _("What we have here is a failure to make an attachment");
1136 update_idx (menu, idx, idxlen++);
1138 idx[menu->current]->content->type = itype;
1139 m_strreplace(&idx[menu->current]->content->subtype, p);
1140 idx[menu->current]->content->unlink = 1;
1141 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1143 if (mutt_compose_attachment (idx[menu->current]->content)) {
1144 mutt_update_encoding (idx[menu->current]->content);
1145 menu->redraw = REDRAW_FULL;
1148 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1151 case OP_COMPOSE_EDIT_MIME:
1153 if (mutt_edit_attachment (idx[menu->current]->content)) {
1154 mutt_update_encoding (idx[menu->current]->content);
1155 menu->redraw = REDRAW_FULL;
1157 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1160 case OP_VIEW_ATTACH:
1161 case OP_DISPLAY_HEADERS:
1163 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1165 menu->redraw = REDRAW_FULL;
1166 /* no send2hook, since this doesn't modify the message */
1171 mutt_save_attachment_list (NULL, menu->tagprefix,
1172 menu->tagprefix ? msg->content : idx[menu->
1174 content, NULL, menu);
1175 MAYBE_REDRAW (menu->redraw);
1176 /* no send2hook, since this doesn't modify the message */
1181 mutt_print_attachment_list (NULL, menu->tagprefix,
1182 menu->tagprefix ? msg->content : idx[menu->
1185 /* no send2hook, since this doesn't modify the message */
1191 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1192 menu->tagprefix ? msg->content : idx[menu->
1194 content, op == OP_FILTER);
1195 if (op == OP_FILTER) /* cte might have changed */
1196 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1197 menu->redraw |= REDRAW_STATUS;
1198 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1203 query_quadoption (OPT_POSTPONE,
1204 _("Postpone this message?"))) == M_NO) {
1205 while (idxlen-- > 0) {
1206 /* avoid freeing other attachments */
1207 idx[idxlen]->content->next = NULL;
1208 idx[idxlen]->content->parts = NULL;
1209 if (idx[idxlen]->unowned)
1210 idx[idxlen]->content->unlink = 0;
1211 body_list_wipe(&idx[idxlen]->content);
1212 p_delete(&idx[idxlen]->tree);
1213 p_delete(&idx[idxlen]);
1225 /* fall through to postpone! */
1227 case OP_COMPOSE_POSTPONE_MESSAGE:
1229 if (check_attachments (idx, idxlen) != 0) {
1230 menu->redraw = REDRAW_FULL;
1238 case OP_COMPOSE_ISPELL:
1240 snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1241 msg->content->filename);
1242 if (mutt_system (buf) == -1)
1243 mutt_error (_("Error running \"%s\"!"), buf);
1245 mutt_update_encoding (msg->content);
1246 menu->redraw |= REDRAW_STATUS;
1250 case OP_COMPOSE_WRITE_MESSAGE:
1254 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
1255 mutt_pretty_mailbox (fname);
1258 msg->content = idx[0]->content;
1259 if (mutt_enter_fname
1260 (_("Write message to mailbox"), fname, sizeof (fname),
1261 &menu->redraw, 1) != -1 && fname[0]) {
1262 mutt_message (_("Writing message to %s ..."), fname);
1263 mutt_expand_path (fname, sizeof (fname));
1265 if (msg->content->next)
1266 msg->content = mutt_make_multipart (msg->content);
1268 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1269 msg->content = mutt_remove_multipart (msg->content);
1271 mutt_message _("Message written.");
1275 case OP_COMPOSE_PGP_MENU:
1276 if (msg->security & APPLICATION_SMIME) {
1277 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1279 mutt_clear_error ();
1284 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1285 redraw_crypt_lines (msg);
1286 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1289 case OP_FORGET_PASSPHRASE:
1290 crypt_forget_passphrase ();
1293 case OP_COMPOSE_SMIME_MENU:
1294 if (msg->security & APPLICATION_PGP) {
1295 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1297 mutt_clear_error ();
1302 msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1303 redraw_crypt_lines (msg);
1304 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1307 case OP_COMPOSE_MIX:
1308 mix_make_chain (&msg->chain, &menu->redraw);
1309 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1313 /* Draw formated compose status line */
1314 if (menu->redraw & REDRAW_STATUS) {
1315 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1316 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1317 SETCOLOR (MT_COLOR_STATUS);
1318 move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
1319 printw ("%-*.*s", COLS-SW, COLS-SW, buf);
1320 SETCOLOR (MT_COLOR_NORMAL);
1321 menu->redraw &= ~REDRAW_STATUS;
1325 mutt_menuDestroy (&menu);
1328 msg->content = idx[0]->content;
1329 for (i = 0; i < idxlen; i++) {
1330 idx[i]->content->aptr = NULL;
1334 msg->content = NULL;