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>
18 #include <lib-mime/mime.h>
20 #include <lib-ui/curses.h>
21 #include <lib-ui/enter.h>
22 #include <lib-ui/menu.h>
26 #include "mutt_idna.h"
28 #include "recvattach.h"
42 static const char *There_are_no_attachments = N_("There are no attachments.");
44 #define CHECK_COUNT if (idxlen == 0) { mutt_error _(There_are_no_attachments); break; }
71 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
73 HDR_ATTACH = (HDR_FCC + 7)
77 #define HDR_XOFFSET 14
78 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
79 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
80 #define W (COLS - HDR_XOFFSET - SW)
82 static const 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},
124 static void snd_entry (char *b, ssize_t blen, MUTTMENU * menu, int num) {
125 int w=(COLS-SW)>blen?blen:COLS-SW;
126 mutt_FormatString (b, w, NONULL (AttachFormat), mutt_attach_fmt,
127 (unsigned long) (((ATTACHPTR **) menu->data)[num]),
128 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
131 #include <lib-crypt/crypt.h>
133 static void redraw_crypt_lines (HEADER * msg)
138 mvaddstr (HDR_CRYPT, SW, " Security: ");
139 else if (msg->security & APPLICATION_SMIME)
140 mvaddstr (HDR_CRYPT, SW, " S/MIME: ");
141 else if (msg->security & APPLICATION_PGP)
142 mvaddstr (HDR_CRYPT, SW, " PGP: ");
144 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
145 addstr (_("Sign, Encrypt"));
146 else if (msg->security & ENCRYPT)
147 addstr (_("Encrypt"));
148 else if (msg->security & SIGN)
153 if ((msg->security & APPLICATION_PGP)
154 && (msg->security & (ENCRYPT | SIGN))) {
155 if ((msg->security & INLINE))
156 addstr (_(" (inline)"));
158 addstr (_(" (PGP/MIME)"));
162 move (HDR_CRYPTINFO, SW);
164 if (msg->security & APPLICATION_PGP && msg->security & SIGN)
165 printw ("%s%s", _(" sign as: "),
166 PgpSignAs ? PgpSignAs : _("<default>"));
168 if (msg->security & APPLICATION_SMIME && msg->security & SIGN) {
169 printw ("%s%s", _(" sign as: "),
170 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
173 if ((msg->security & APPLICATION_SMIME)
174 && (msg->security & ENCRYPT)
175 && SmimeCryptAlg && *SmimeCryptAlg) {
176 mvprintw (HDR_CRYPTINFO, SW + 40, "%s%s", _("Encrypt with: "),
177 NONULL (SmimeCryptAlg));
185 static void redraw_mix_line (string_list_t * chain)
190 mvaddstr (HDR_MIX, SW, " Mix: ");
193 addstr ("<no chain defined>");
198 for (c = 12; chain; chain = chain->next) {
200 if (t && t[0] == '0' && t[1] == '\0')
203 if (c + m_strlen(t) + 2 >= COLS - SW)
210 c += m_strlen(t) + 2;
213 #endif /* MIXMASTER */
215 static int check_attachments (ATTACHPTR ** idx, short idxlen)
219 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
221 for (i = 0; i < idxlen; i++) {
222 m_strcpy(pretty, sizeof(pretty), idx[i]->content->filename);
223 if (stat (idx[i]->content->filename, &st) != 0) {
224 mutt_pretty_mailbox (pretty);
225 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
229 if (idx[i]->content->stamp < st.st_mtime) {
230 mutt_pretty_mailbox (pretty);
231 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
234 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
235 mutt_update_encoding (idx[i]->content);
244 static void draw_envelope_addr (int line, address_t * addr)
249 rfc822_write_address (buf, sizeof (buf), addr, 1);
250 mvprintw (line, SW, TITLE_FMT, Prompts[line - 1]);
251 mutt_paddstr (W, buf);
254 static void draw_envelope (HEADER * msg, char *fcc)
256 draw_envelope_addr (HDR_FROM, msg->env->from);
258 if (!option (OPTNEWSSEND)) {
260 draw_envelope_addr (HDR_TO, msg->env->to);
261 draw_envelope_addr (HDR_CC, msg->env->cc);
262 draw_envelope_addr (HDR_BCC, msg->env->bcc);
266 mvprintw (HDR_TO, SW, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
267 mutt_paddstr (W, NONULL (msg->env->newsgroups));
268 mvprintw (HDR_CC, SW, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
269 mutt_paddstr (W, NONULL (msg->env->followup_to));
270 if (option (OPTXCOMMENTTO)) {
271 mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]);
272 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
276 mvprintw (HDR_SUBJECT, SW, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
277 mutt_paddstr (W, NONULL (msg->env->subject));
278 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
279 mvprintw (HDR_FCC, SW, TITLE_FMT, Prompts[HDR_FCC - 1]);
280 mutt_paddstr (W, fcc);
282 redraw_crypt_lines (msg);
285 redraw_mix_line (msg->chain);
288 SETCOLOR (MT_COLOR_STATUS);
289 mvaddstr (HDR_ATTACH - 1, SW, _("-- Attachments"));
290 BKGDSET (MT_COLOR_STATUS);
293 BKGDSET (MT_COLOR_NORMAL);
294 SETCOLOR (MT_COLOR_NORMAL);
297 static int edit_address_list (int line, address_t ** addr)
299 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
302 mutt_addrlist_to_local (*addr);
303 rfc822_write_address (buf, sizeof (buf), *addr, 0);
304 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
305 address_list_wipe(addr);
306 *addr = mutt_parse_adrlist (*addr, buf);
307 *addr = mutt_expand_aliases (*addr);
310 if (option (OPTNEEDREDRAW)) {
311 unset_option (OPTNEEDREDRAW);
312 return (REDRAW_FULL);
315 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
316 mutt_error (_("Warning: '%s' is a bad IDN."), err);
321 /* redraw the expanded list so the user can see the result */
323 rfc822_write_address (buf, sizeof (buf), *addr, 1);
324 move (line, HDR_XOFFSET + SW);
325 mutt_paddstr (W, buf);
330 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
332 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
335 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
337 if (x == 0 && menu->max == 1) {
338 mutt_error _("You may not delete the only attachment.");
340 idx[x]->content->tagged = 0;
344 for (y = 0; y < *idxlen; y++) {
345 if (idx[y]->content->next == idx[x]->content) {
346 idx[y]->content->next = idx[x]->content->next;
351 idx[x]->content->next = NULL;
352 idx[x]->content->parts = NULL;
353 body_list_wipe(&(idx[x]->content));
354 p_delete(&idx[x]->tree);
356 for (; x < *idxlen - 1; x++)
358 menu->max = --(*idxlen);
363 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
365 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
367 idx[idxlen - 1]->content->next = idx[idxlen]->content;
368 idx[idxlen]->content->aptr = idx[idxlen];
369 menu->current = idxlen++;
370 mutt_update_tree (idx, idxlen);
377 * cum_attachs_size: Cumulative Attachments Size
379 * Returns the total number of bytes used by the attachments in the
380 * attachment list _after_ content-transfer-encodings have been
385 static unsigned long cum_attachs_size (MUTTMENU * menu)
389 ATTACHPTR **idx = menu->data;
393 for (i = 0, s = 0; i < menu->max; i++) {
397 b->content = mutt_get_content_info (b->filename, b);
399 if ((info = b->content)) {
400 switch (b->encoding) {
401 case ENCQUOTEDPRINTABLE:
402 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
405 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
408 s += info->lobin + info->hibin + info->ascii + info->crlf;
418 * compose_format_str()
420 * %a = total number of attachments
421 * %h = hostname [option]
422 * %l = approx. length of current message (in bytes)
425 * This function is similar to status_format_str(). Look at that function for
426 * help when modifying this function.
429 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
432 static const char *compose_format_str (char *buf, ssize_t buflen, char op,
433 const char *src, const char *prefix,
434 const char *ifstring,
435 const char *elsestring,
436 unsigned long data, format_flag flags)
438 char fmt[SHORT_STRING], tmp[SHORT_STRING];
439 int optional = (flags & M_FORMAT_OPTIONAL);
440 MUTTMENU *menu = (MUTTMENU *) data;
444 case 'a': /* total number of attachments */
445 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
446 snprintf (buf, buflen, fmt, menu->max);
449 case 'h': /* hostname */
450 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
451 snprintf (buf, buflen, fmt, NONULL (Hostname));
454 case 'l': /* approx length of current message in bytes */
455 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
456 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
457 snprintf (buf, buflen, fmt, tmp);
461 m_strcpy(buf, buflen, mutt_make_version (0));
469 snprintf (buf, buflen, "%%%s%c", prefix, op);
474 compose_status_line (buf, buflen, menu, ifstring);
475 else if (flags & M_FORMAT_OPTIONAL)
476 compose_status_line (buf, buflen, menu, elsestring);
481 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
484 int w=(COLS-SW)>buflen?buflen:(COLS-SW);
485 mutt_FormatString (buf, w, p, compose_format_str,
486 (unsigned long) menu, 0);
492 * 1 message should be postponed
496 int mutt_compose_menu (HEADER * msg, /* structure for new message */
497 char *fcc, /* where to save a copy of the message */
499 HEADER * cur __attribute__ ((unused)))
500 { /* current message */
501 char helpstr[SHORT_STRING];
502 char buf[LONG_STRING];
503 char fname[_POSIX_PATH_MAX];
505 ATTACHPTR **idx = NULL;
509 int r = -1; /* return value */
512 int fccSet = 0; /* has the user edited the Fcc: field ? */
513 CONTEXT *ctx = NULL, *this = NULL;
515 /* Sort, SortAux could be changed in mutt_index_menu() */
516 int oldSort, oldSortAux;
520 int news = 0; /* is it a news article ? */
522 if (option (OPTNEWSSEND))
526 mutt_attach_init (msg->content);
527 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
529 menu = mutt_new_menu ();
530 menu->menu = MENU_COMPOSE;
531 menu->offset = HDR_ATTACH;
533 menu->make_entry = snd_entry;
534 menu->tag = mutt_tag_attach;
539 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
544 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
547 if (option (OPTMBOXPANE))
551 unset_option (OPTNEWS); /* for any case */
553 switch (op = mutt_menuLoop (menu)) {
555 draw_envelope (msg, fcc);
556 menu->offset = HDR_ATTACH;
557 menu->pagelen = LINES - HDR_ATTACH - 2;
559 case OP_COMPOSE_EDIT_FROM:
560 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
561 mutt_message_hook (NULL, msg, M_SEND2HOOK);
563 case OP_COMPOSE_EDIT_TO:
567 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
568 mutt_message_hook (NULL, msg, M_SEND2HOOK);
573 case OP_COMPOSE_EDIT_BCC:
577 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
578 mutt_message_hook (NULL, msg, M_SEND2HOOK);
583 case OP_COMPOSE_EDIT_CC:
587 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
588 mutt_message_hook (NULL, msg, M_SEND2HOOK);
594 case OP_COMPOSE_EDIT_NEWSGROUPS:
596 if (msg->env->newsgroups)
597 m_strcpy(buf, sizeof(buf), msg->env->newsgroups);
600 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
602 p_delete(&msg->env->newsgroups);
604 msg->env->newsgroups = m_strdup(skipspaces(buf));
605 move (HDR_TO, HDR_XOFFSET);
607 if (msg->env->newsgroups)
608 printw ("%-*.*s", W, W, msg->env->newsgroups);
613 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
616 if (msg->env->followup_to)
617 m_strcpy(buf, sizeof(buf), msg->env->followup_to);
618 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
620 p_delete(&msg->env->followup_to);
622 msg->env->followup_to = m_strdup(skipspaces(buf));
623 move (HDR_CC, HDR_XOFFSET);
625 if (msg->env->followup_to)
626 printw ("%-*.*s", W, W, msg->env->followup_to);
631 case OP_COMPOSE_EDIT_X_COMMENT_TO:
632 if (news && option (OPTXCOMMENTTO)) {
634 if (msg->env->x_comment_to)
635 m_strcpy(buf, sizeof(buf), msg->env->x_comment_to);
636 if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
638 p_delete(&msg->env->x_comment_to);
639 msg->env->x_comment_to = m_strdup(buf);
640 move (HDR_BCC, HDR_XOFFSET);
642 if (msg->env->x_comment_to)
643 printw ("%-*.*s", W, W, msg->env->x_comment_to);
648 case OP_COMPOSE_EDIT_SUBJECT:
649 if (msg->env->subject)
650 m_strcpy(buf, sizeof(buf), msg->env->subject);
653 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
654 m_strreplace(&msg->env->subject, buf);
655 move (HDR_SUBJECT, HDR_XOFFSET + SW);
657 if (msg->env->subject)
658 mutt_paddstr (W, msg->env->subject);
660 mutt_message_hook (NULL, msg, M_SEND2HOOK);
662 case OP_COMPOSE_EDIT_REPLY_TO:
663 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
664 mutt_message_hook (NULL, msg, M_SEND2HOOK);
666 case OP_COMPOSE_EDIT_FCC:
667 m_strcpy(buf, sizeof(buf), fcc);
668 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
669 m_strcpy(fcc, _POSIX_PATH_MAX, buf);
670 mutt_pretty_mailbox (fcc);
671 move (HDR_FCC, HDR_XOFFSET + SW);
672 mutt_paddstr (W, fcc);
675 MAYBE_REDRAW (menu->redraw);
676 mutt_message_hook (NULL, msg, M_SEND2HOOK);
678 case OP_COMPOSE_EDIT_MESSAGE:
679 if (Editor && !option (OPTEDITHDRS)) {
680 mutt_edit_file (Editor, msg->content->filename);
681 mutt_update_encoding (msg->content);
682 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
683 mutt_message_hook (NULL, msg, M_SEND2HOOK);
687 case OP_COMPOSE_EDIT_HEADERS:
688 if ((op == OP_COMPOSE_EDIT_HEADERS ||
689 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
690 const char *tag = NULL;
693 mutt_env_to_local (msg->env);
694 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
696 if (mutt_env_to_idna (msg->env, &tag, &err)) {
697 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
701 mutt_update_encoding (msg->content);
703 /* attachments may have been added */
704 if (idxlen && idx[idxlen - 1]->content->next) {
705 for (i = 0; i < idxlen; i++)
709 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
715 menu->redraw = REDRAW_FULL;
716 mutt_message_hook (NULL, msg, M_SEND2HOOK);
721 case OP_COMPOSE_ATTACH_KEY:
722 if (idxlen == idxmax) {
723 p_realloc(&idx, idxmax += 5);
727 idx[idxlen] = p_new(ATTACHPTR, 1);
728 if ((idx[idxlen]->content =
729 crypt_pgp_make_key_attachment (NULL)) != NULL) {
730 update_idx (menu, idx, idxlen++);
731 menu->redraw |= REDRAW_INDEX;
734 p_delete(&idx[idxlen]);
736 menu->redraw |= REDRAW_STATUS;
738 if (option (OPTNEEDREDRAW)) {
739 menu->redraw = REDRAW_FULL;
740 unset_option (OPTNEEDREDRAW);
743 mutt_message_hook (NULL, msg, M_SEND2HOOK);
747 case OP_COMPOSE_ATTACH_FILE:
749 char *prompt, **files;
753 prompt = _("Attach file");
757 if (_mutt_enter_fname
758 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
759 &numfiles) == -1 || *fname == '\0')
762 if (idxlen + numfiles >= idxmax) {
763 p_realloc(&idx, idxmax += 5 + numfiles);
769 mutt_message _("Attaching selected files...");
771 for (i = 0; i < numfiles; i++) {
772 char *att = files[i];
774 idx[idxlen] = p_new(ATTACHPTR, 1);
775 idx[idxlen]->unowned = 1;
776 idx[idxlen]->content = mutt_make_file_attach (att);
777 if (idx[idxlen]->content != NULL)
778 update_idx (menu, idx, idxlen++);
781 mutt_error (_("Unable to attach %s!"), att);
782 p_delete(&idx[idxlen]);
790 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
792 mutt_message_hook (NULL, msg, M_SEND2HOOK);
795 case OP_COMPOSE_ATTACH_MESSAGE:
797 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
804 prompt = _("Open mailbox to attach message from");
807 unset_option (OPTNEWS);
808 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
809 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
812 prompt = _("Open newsgroup to attach message from");
813 set_option (OPTNEWS);
819 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
822 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
823 mutt_pretty_mailbox (fname);
826 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
831 if (option (OPTNEWS))
832 nntp_expand_path (fname, sizeof (fname),
833 &CurrentNewsSrv->conn->account);
836 mutt_expand_path (fname, sizeof (fname));
837 if (mx_get_magic (fname) != M_IMAP)
838 if (mx_get_magic (fname) != M_POP)
840 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
842 /* check to make sure the file exists and is readable */
843 if (access (fname, R_OK) == -1) {
848 menu->redraw = REDRAW_FULL;
850 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
856 if (!ctx->msgcount) {
857 mx_close_mailbox (ctx, NULL);
859 mutt_error _("No messages in that folder.");
864 this = Context; /* remember current folder and sort methods */
866 oldSortAux = SortAux;
869 set_option (OPTATTACHMSG);
870 mutt_message _("Tag the messages you want to attach!");
872 closed = mutt_index_menu ();
873 unset_option (OPTATTACHMSG);
876 /* go back to the folder we started from */
878 /* Restore old $sort and $sort_aux */
880 SortAux = oldSortAux;
881 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
885 if (idxlen + Context->tagged >= idxmax) {
886 p_realloc(&idx, idxmax += 5 + Context->tagged);
890 for (i = 0; i < Context->msgcount; i++) {
891 h = Context->hdrs[i];
893 idx[idxlen] = p_new(ATTACHPTR, 1);
894 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
895 if (idx[idxlen]->content != NULL)
896 update_idx (menu, idx, idxlen++);
898 mutt_error _("Unable to attach!");
900 p_delete(&idx[idxlen]);
904 menu->redraw |= REDRAW_FULL;
906 if (closed == OP_QUIT)
907 mx_close_mailbox (Context, NULL);
909 mx_fastclose_mailbox (Context);
912 /* go back to the folder we started from */
914 /* Restore old $sort and $sort_aux */
916 SortAux = oldSortAux;
918 mutt_message_hook (NULL, msg, M_SEND2HOOK);
923 if (idx[menu->current]->unowned)
924 idx[menu->current]->content->unlink = 0;
925 if (delete_attachment (menu, &idxlen, menu->current) == -1)
927 mutt_update_tree (idx, idxlen);
929 if (menu->current > idxlen - 1)
930 menu->current = idxlen - 1;
935 if (menu->current == 0)
936 msg->content = idx[0]->content;
938 menu->redraw |= REDRAW_STATUS;
939 mutt_message_hook (NULL, msg, M_SEND2HOOK);
942 #define CURRENT idx[menu->current]->content
944 case OP_COMPOSE_TOGGLE_RECODE:
947 if (!mutt_is_text_part (CURRENT)) {
948 mutt_error (_("Recoding only affects text attachments."));
951 CURRENT->noconv = !CURRENT->noconv;
953 mutt_message (_("The current attachment won't be converted."));
955 mutt_message (_("The current attachment will be converted."));
956 menu->redraw = REDRAW_CURRENT;
957 mutt_message_hook (NULL, msg, M_SEND2HOOK);
962 case OP_COMPOSE_EDIT_DESCRIPTION:
964 m_strcpy(buf, sizeof(buf),
965 NONULL(idx[menu->current]->content->description));
966 /* header names should not be translated */
967 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
968 m_strreplace(&idx[menu->current]->content->description, buf);
969 menu->redraw = REDRAW_CURRENT;
971 mutt_message_hook (NULL, msg, M_SEND2HOOK);
974 case OP_COMPOSE_UPDATE_ENCODING:
976 if (menu->tagprefix) {
979 for (top = msg->content; top; top = top->next) {
981 mutt_update_encoding (top);
983 menu->redraw = REDRAW_FULL;
986 mutt_update_encoding (idx[menu->current]->content);
987 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
989 mutt_message_hook (NULL, msg, M_SEND2HOOK);
992 case OP_COMPOSE_TOGGLE_DISPOSITION:
993 /* toggle the content-disposition between inline/attachment */
994 idx[menu->current]->content->disposition =
995 (idx[menu->current]->content->disposition ==
996 DISPINLINE) ? DISPATTACH : DISPINLINE;
997 menu->redraw = REDRAW_CURRENT;
1003 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
1005 /* this may have been a change to text/something */
1006 mutt_update_encoding (idx[menu->current]->content);
1008 menu->redraw = REDRAW_CURRENT;
1010 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1013 case OP_COMPOSE_EDIT_ENCODING:
1015 m_strcpy(buf, sizeof(buf),
1016 ENCODING(idx[menu->current]->content->encoding));
1017 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
1018 sizeof (buf), 0) == 0 && buf[0]) {
1019 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
1020 idx[menu->current]->content->encoding = i;
1021 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1022 mutt_clear_error ();
1025 mutt_error _("Invalid encoding.");
1027 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1030 case OP_COMPOSE_SEND_MESSAGE:
1032 /* Note: We don't invoke send2-hook here, since we want to leave
1033 * users an opportunity to change settings from the ":" prompt.
1036 if (check_attachments (idx, idxlen) != 0) {
1037 menu->redraw = REDRAW_FULL;
1043 if (msg->chain && mix_check_message (msg) != 0)
1047 if (!fccSet && *fcc) {
1048 if ((i = query_quadoption (OPT_COPY,
1049 _("Save a copy of this message?"))) == -1)
1059 case OP_COMPOSE_EDIT_FILE:
1061 mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename);
1062 mutt_update_encoding (idx[menu->current]->content);
1063 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1064 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1067 case OP_COMPOSE_TOGGLE_UNLINK:
1069 idx[menu->current]->content->unlink =
1070 !idx[menu->current]->content->unlink;
1073 /* OPTRESOLVE is otherwise ignored on this menu.
1077 if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
1080 menu->redraw = REDRAW_INDEX;
1081 /* No send2hook since this doesn't change the message. */
1084 case OP_COMPOSE_GET_ATTACHMENT:
1086 if (menu->tagprefix) {
1089 for (top = msg->content; top; top = top->next) {
1091 mutt_get_tmp_attachment (top);
1093 menu->redraw = REDRAW_FULL;
1095 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1096 menu->redraw = REDRAW_CURRENT;
1098 /* No send2hook since this doesn't change the message. */
1101 case OP_COMPOSE_RENAME_FILE:
1103 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
1104 mutt_pretty_mailbox (fname);
1105 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1107 if (stat (idx[menu->current]->content->filename, &st) == -1) {
1108 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1112 mutt_expand_path (fname, sizeof (fname));
1113 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1116 m_strreplace(&idx[menu->current]->content->filename, fname);
1117 menu->redraw = REDRAW_CURRENT;
1119 if (idx[menu->current]->content->stamp >= st.st_mtime)
1120 mutt_stamp_attachment (idx[menu->current]->content);
1123 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1126 case OP_COMPOSE_NEW_MIME:
1133 CLEARLINE (LINES - 1);
1135 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1138 mutt_expand_path (fname, sizeof (fname));
1140 /* Call to lookup_mime_type () ? maybe later */
1142 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1146 if (!(p = strchr (type, '/'))) {
1147 mutt_error _("Content-Type is of the form base/sub");
1152 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1153 mutt_error (_("Unknown Content-Type %s"), type);
1156 if (idxlen == idxmax) {
1157 p_realloc(&idx, idxmax += 5);
1161 idx[idxlen] = p_new(ATTACHPTR, 1);
1162 /* Touch the file */
1163 if (!(fp = safe_fopen (fname, "w"))) {
1164 mutt_error (_("Can't create file %s"), fname);
1165 p_delete(&idx[idxlen]);
1170 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1172 _("What we have here is a failure to make an attachment");
1175 update_idx (menu, idx, idxlen++);
1177 idx[menu->current]->content->type = itype;
1178 m_strreplace(&idx[menu->current]->content->subtype, p);
1179 idx[menu->current]->content->unlink = 1;
1180 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1182 if (mutt_compose_attachment (idx[menu->current]->content)) {
1183 mutt_update_encoding (idx[menu->current]->content);
1184 menu->redraw = REDRAW_FULL;
1187 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1190 case OP_COMPOSE_EDIT_MIME:
1192 if (mutt_edit_attachment (idx[menu->current]->content)) {
1193 mutt_update_encoding (idx[menu->current]->content);
1194 menu->redraw = REDRAW_FULL;
1196 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1199 case OP_VIEW_ATTACH:
1200 case OP_DISPLAY_HEADERS:
1202 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1204 menu->redraw = REDRAW_FULL;
1205 /* no send2hook, since this doesn't modify the message */
1210 mutt_save_attachment_list (NULL, menu->tagprefix,
1211 menu->tagprefix ? msg->content : idx[menu->
1213 content, NULL, menu);
1214 MAYBE_REDRAW (menu->redraw);
1215 /* no send2hook, since this doesn't modify the message */
1220 mutt_print_attachment_list (NULL, menu->tagprefix,
1221 menu->tagprefix ? msg->content : idx[menu->
1224 /* no send2hook, since this doesn't modify the message */
1230 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1231 menu->tagprefix ? msg->content : idx[menu->
1233 content, op == OP_FILTER);
1234 if (op == OP_FILTER) /* cte might have changed */
1235 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1236 menu->redraw |= REDRAW_STATUS;
1237 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1242 query_quadoption (OPT_POSTPONE,
1243 _("Postpone this message?"))) == M_NO) {
1244 while (idxlen-- > 0) {
1245 /* avoid freeing other attachments */
1246 idx[idxlen]->content->next = NULL;
1247 idx[idxlen]->content->parts = NULL;
1248 if (idx[idxlen]->unowned)
1249 idx[idxlen]->content->unlink = 0;
1250 body_list_wipe(&idx[idxlen]->content);
1251 p_delete(&idx[idxlen]->tree);
1252 p_delete(&idx[idxlen]);
1264 /* fall through to postpone! */
1266 case OP_COMPOSE_POSTPONE_MESSAGE:
1268 if (check_attachments (idx, idxlen) != 0) {
1269 menu->redraw = REDRAW_FULL;
1277 case OP_COMPOSE_ISPELL:
1279 snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1280 msg->content->filename);
1281 if (mutt_system (buf) == -1)
1282 mutt_error (_("Error running \"%s\"!"), buf);
1284 mutt_update_encoding (msg->content);
1285 menu->redraw |= REDRAW_STATUS;
1289 case OP_COMPOSE_WRITE_MESSAGE:
1293 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
1294 mutt_pretty_mailbox (fname);
1297 msg->content = idx[0]->content;
1298 if (mutt_enter_fname
1299 (_("Write message to mailbox"), fname, sizeof (fname),
1300 &menu->redraw, 1) != -1 && fname[0]) {
1301 mutt_message (_("Writing message to %s ..."), fname);
1302 mutt_expand_path (fname, sizeof (fname));
1304 if (msg->content->next)
1305 msg->content = mutt_make_multipart (msg->content);
1307 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1308 msg->content = mutt_remove_multipart (msg->content);
1310 mutt_message _("Message written.");
1316 case OP_COMPOSE_PGP_MENU:
1317 if (msg->security & APPLICATION_SMIME) {
1318 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1320 mutt_clear_error ();
1325 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1326 redraw_crypt_lines (msg);
1327 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1331 case OP_FORGET_PASSPHRASE:
1332 crypt_forget_passphrase ();
1336 case OP_COMPOSE_SMIME_MENU:
1337 if (msg->security & APPLICATION_PGP) {
1338 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1340 mutt_clear_error ();
1345 msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1346 redraw_crypt_lines (msg);
1347 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1352 case OP_COMPOSE_MIX:
1354 mix_make_chain (&msg->chain, &menu->redraw);
1355 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1361 /* Draw formated compose status line */
1362 if (menu->redraw & REDRAW_STATUS) {
1363 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1364 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1365 SETCOLOR (MT_COLOR_STATUS);
1366 move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
1367 printw ("%-*.*s", COLS-SW, COLS-SW, buf);
1368 SETCOLOR (MT_COLOR_NORMAL);
1369 menu->redraw &= ~REDRAW_STATUS;
1373 mutt_menuDestroy (&menu);
1376 msg->content = idx[0]->content;
1377 for (i = 0; i < idxlen; i++) {
1378 idx[i]->content->aptr = NULL;
1383 msg->content = NULL;