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.
25 #include <lib-lib/mem.h>
26 #include <lib-lib/str.h>
27 #include <lib-lib/macros.h>
28 #include <lib-lib/file.h>
29 #include <lib-lib/mapping.h>
31 #include <lib-sys/unix.h>
33 #include <lib-mime/mime.h>
35 #include <lib-ui/curses.h>
36 #include <lib-ui/enter.h>
37 #include <lib-ui/menu.h>
41 #include "mutt_idna.h"
44 #include "recvattach.h"
59 static const char *There_are_no_attachments = N_("There are no attachments.");
61 #define CHECK_COUNT if (idxlen == 0) { mutt_error _(There_are_no_attachments); break; }
88 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
90 HDR_ATTACH = (HDR_FCC + 7)
94 #define HDR_XOFFSET 14
95 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
96 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
97 #define W (COLS - HDR_XOFFSET - SW)
99 static const char *Prompts[] = {
111 , "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: "
115 static struct mapping_t ComposeHelp[] = {
116 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
117 {N_("Abort"), OP_EXIT},
118 {"To", OP_COMPOSE_EDIT_TO},
119 {"CC", OP_COMPOSE_EDIT_CC},
120 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
121 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
122 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
123 {N_("Help"), OP_HELP},
128 static struct mapping_t ComposeNewsHelp[] = {
129 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
130 {N_("Abort"), OP_EXIT},
131 {"Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS},
132 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
133 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
134 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
135 {N_("Help"), OP_HELP},
141 static void snd_entry (char *b, ssize_t blen, MUTTMENU * menu, int num) {
142 int w=(COLS-SW)>blen?blen:COLS-SW;
143 mutt_FormatString (b, w, NONULL (AttachFormat), mutt_attach_fmt,
144 (unsigned long) (((ATTACHPTR **) menu->data)[num]),
145 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
148 #include <lib-crypt/crypt.h>
150 static void redraw_crypt_lines (HEADER * msg)
155 mvaddstr (HDR_CRYPT, SW, " Security: ");
156 else if (msg->security & APPLICATION_SMIME)
157 mvaddstr (HDR_CRYPT, SW, " S/MIME: ");
158 else if (msg->security & APPLICATION_PGP)
159 mvaddstr (HDR_CRYPT, SW, " 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 ((msg->security & APPLICATION_PGP)
171 && (msg->security & (ENCRYPT | SIGN))) {
172 if ((msg->security & INLINE))
173 addstr (_(" (inline)"));
175 addstr (_(" (PGP/MIME)"));
179 move (HDR_CRYPTINFO, SW);
181 if (msg->security & APPLICATION_PGP && msg->security & SIGN)
182 printw ("%s%s", _(" sign as: "),
183 PgpSignAs ? PgpSignAs : _("<default>"));
185 if (msg->security & APPLICATION_SMIME && msg->security & SIGN) {
186 printw ("%s%s", _(" sign as: "),
187 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
190 if ((msg->security & APPLICATION_SMIME)
191 && (msg->security & ENCRYPT)
192 && SmimeCryptAlg && *SmimeCryptAlg) {
193 mvprintw (HDR_CRYPTINFO, SW + 40, "%s%s", _("Encrypt with: "),
194 NONULL (SmimeCryptAlg));
202 static void redraw_mix_line (string_list_t * chain)
207 mvaddstr (HDR_MIX, SW, " Mix: ");
210 addstr ("<no chain defined>");
215 for (c = 12; chain; chain = chain->next) {
217 if (t && t[0] == '0' && t[1] == '\0')
220 if (c + m_strlen(t) + 2 >= COLS - SW)
227 c += m_strlen(t) + 2;
230 #endif /* MIXMASTER */
232 static int check_attachments (ATTACHPTR ** idx, short idxlen)
236 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
238 for (i = 0; i < idxlen; i++) {
239 m_strcpy(pretty, sizeof(pretty), idx[i]->content->filename);
240 if (stat (idx[i]->content->filename, &st) != 0) {
241 mutt_pretty_mailbox (pretty);
242 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
246 if (idx[i]->content->stamp < st.st_mtime) {
247 mutt_pretty_mailbox (pretty);
248 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
251 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
252 mutt_update_encoding (idx[i]->content);
261 static void draw_envelope_addr (int line, address_t * addr)
266 rfc822_write_address (buf, sizeof (buf), addr, 1);
267 mvprintw (line, SW, TITLE_FMT, Prompts[line - 1]);
268 mutt_paddstr (W, buf);
271 static void draw_envelope (HEADER * msg, char *fcc)
273 draw_envelope_addr (HDR_FROM, msg->env->from);
275 if (!option (OPTNEWSSEND)) {
277 draw_envelope_addr (HDR_TO, msg->env->to);
278 draw_envelope_addr (HDR_CC, msg->env->cc);
279 draw_envelope_addr (HDR_BCC, msg->env->bcc);
283 mvprintw (HDR_TO, SW, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
284 mutt_paddstr (W, NONULL (msg->env->newsgroups));
285 mvprintw (HDR_CC, SW, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
286 mutt_paddstr (W, NONULL (msg->env->followup_to));
287 if (option (OPTXCOMMENTTO)) {
288 mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]);
289 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
293 mvprintw (HDR_SUBJECT, SW, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
294 mutt_paddstr (W, NONULL (msg->env->subject));
295 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
296 mvprintw (HDR_FCC, SW, TITLE_FMT, Prompts[HDR_FCC - 1]);
297 mutt_paddstr (W, fcc);
299 redraw_crypt_lines (msg);
302 redraw_mix_line (msg->chain);
305 SETCOLOR (MT_COLOR_STATUS);
306 mvaddstr (HDR_ATTACH - 1, SW, _("-- Attachments"));
307 BKGDSET (MT_COLOR_STATUS);
310 BKGDSET (MT_COLOR_NORMAL);
311 SETCOLOR (MT_COLOR_NORMAL);
314 static int edit_address_list (int line, address_t ** addr)
316 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
317 const char *err = NULL;
319 mutt_addrlist_to_local (*addr);
320 rfc822_write_address (buf, sizeof (buf), *addr, 0);
321 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
322 address_list_wipe(addr);
323 *addr = mutt_parse_adrlist (*addr, buf);
324 *addr = mutt_expand_aliases (*addr);
327 if (option (OPTNEEDREDRAW)) {
328 unset_option (OPTNEEDREDRAW);
329 return (REDRAW_FULL);
332 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
333 mutt_error (_("Warning: '%s' is a bad IDN."), err);
338 /* redraw the expanded list so the user can see the result */
340 rfc822_write_address (buf, sizeof (buf), *addr, 1);
341 move (line, HDR_XOFFSET + SW);
342 mutt_paddstr (W, buf);
347 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
349 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
352 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
354 if (x == 0 && menu->max == 1) {
355 mutt_error _("You may not delete the only attachment.");
357 idx[x]->content->tagged = 0;
361 for (y = 0; y < *idxlen; y++) {
362 if (idx[y]->content->next == idx[x]->content) {
363 idx[y]->content->next = idx[x]->content->next;
368 idx[x]->content->next = NULL;
369 idx[x]->content->parts = NULL;
370 mutt_free_body (&(idx[x]->content));
371 p_delete(&idx[x]->tree);
373 for (; x < *idxlen - 1; x++)
375 menu->max = --(*idxlen);
380 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
382 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
384 idx[idxlen - 1]->content->next = idx[idxlen]->content;
385 idx[idxlen]->content->aptr = idx[idxlen];
386 menu->current = idxlen++;
387 mutt_update_tree (idx, idxlen);
394 * cum_attachs_size: Cumulative Attachments Size
396 * Returns the total number of bytes used by the attachments in the
397 * attachment list _after_ content-transfer-encodings have been
402 static unsigned long cum_attachs_size (MUTTMENU * menu)
406 ATTACHPTR **idx = menu->data;
410 for (i = 0, s = 0; i < menu->max; i++) {
414 b->content = mutt_get_content_info (b->filename, b);
416 if ((info = b->content)) {
417 switch (b->encoding) {
418 case ENCQUOTEDPRINTABLE:
419 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
422 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
425 s += info->lobin + info->hibin + info->ascii + info->crlf;
435 * compose_format_str()
437 * %a = total number of attachments
438 * %h = hostname [option]
439 * %l = approx. length of current message (in bytes)
442 * This function is similar to status_format_str(). Look at that function for
443 * help when modifying this function.
446 static const char *compose_format_str (char *buf, ssize_t buflen, char op,
447 const char *src, const char *prefix,
448 const char *ifstring,
449 const char *elsestring,
450 unsigned long data, format_flag flags)
452 char fmt[SHORT_STRING], tmp[SHORT_STRING];
453 int optional = (flags & M_FORMAT_OPTIONAL);
454 MUTTMENU *menu = (MUTTMENU *) data;
458 case 'a': /* total number of attachments */
459 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
460 snprintf (buf, buflen, fmt, menu->max);
463 case 'h': /* hostname */
464 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
465 snprintf (buf, buflen, fmt, NONULL (Hostname));
468 case 'l': /* approx length of current message in bytes */
469 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
470 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
471 snprintf (buf, buflen, fmt, tmp);
475 m_strcpy(buf, buflen, mutt_make_version (0));
483 snprintf (buf, buflen, "%%%s%c", prefix, op);
488 compose_status_line (buf, buflen, menu, ifstring);
489 else if (flags & M_FORMAT_OPTIONAL)
490 compose_status_line (buf, buflen, menu, elsestring);
495 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
498 int w=(COLS-SW)>buflen?buflen:(COLS-SW);
499 mutt_FormatString (buf, w, p, compose_format_str,
500 (unsigned long) menu, 0);
506 * 1 message should be postponed
510 int mutt_compose_menu (HEADER * msg, /* structure for new message */
511 char *fcc, /* where to save a copy of the message */
512 ssize_t fcclen, HEADER * cur)
513 { /* current message */
514 char helpstr[SHORT_STRING];
515 char buf[LONG_STRING];
516 char fname[_POSIX_PATH_MAX];
518 ATTACHPTR **idx = NULL;
522 int r = -1; /* return value */
525 int fccSet = 0; /* has the user edited the Fcc: field ? */
526 CONTEXT *ctx = NULL, *this = NULL;
528 /* Sort, SortAux could be changed in mutt_index_menu() */
529 int oldSort, oldSortAux;
533 int news = 0; /* is it a news article ? */
535 if (option (OPTNEWSSEND))
539 mutt_attach_init (msg->content);
540 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
542 menu = mutt_new_menu ();
543 menu->menu = MENU_COMPOSE;
544 menu->offset = HDR_ATTACH;
546 menu->make_entry = snd_entry;
547 menu->tag = mutt_tag_attach;
552 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
557 mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
560 if (option (OPTMBOXPANE))
564 unset_option (OPTNEWS); /* for any case */
566 switch (op = mutt_menuLoop (menu)) {
568 draw_envelope (msg, fcc);
569 menu->offset = HDR_ATTACH;
570 menu->pagelen = LINES - HDR_ATTACH - 2;
572 case OP_COMPOSE_EDIT_FROM:
573 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
574 mutt_message_hook (NULL, msg, M_SEND2HOOK);
576 case OP_COMPOSE_EDIT_TO:
580 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
581 mutt_message_hook (NULL, msg, M_SEND2HOOK);
586 case OP_COMPOSE_EDIT_BCC:
590 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
591 mutt_message_hook (NULL, msg, M_SEND2HOOK);
596 case OP_COMPOSE_EDIT_CC:
600 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
601 mutt_message_hook (NULL, msg, M_SEND2HOOK);
607 case OP_COMPOSE_EDIT_NEWSGROUPS:
609 if (msg->env->newsgroups)
610 m_strcpy(buf, sizeof(buf), msg->env->newsgroups);
613 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
615 p_delete(&msg->env->newsgroups);
617 msg->env->newsgroups = m_strdup(skipspaces(buf));
618 move (HDR_TO, HDR_XOFFSET);
620 if (msg->env->newsgroups)
621 printw ("%-*.*s", W, W, msg->env->newsgroups);
626 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
629 if (msg->env->followup_to)
630 m_strcpy(buf, sizeof(buf), msg->env->followup_to);
631 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
633 p_delete(&msg->env->followup_to);
635 msg->env->followup_to = m_strdup(skipspaces(buf));
636 move (HDR_CC, HDR_XOFFSET);
638 if (msg->env->followup_to)
639 printw ("%-*.*s", W, W, msg->env->followup_to);
644 case OP_COMPOSE_EDIT_X_COMMENT_TO:
645 if (news && option (OPTXCOMMENTTO)) {
647 if (msg->env->x_comment_to)
648 m_strcpy(buf, sizeof(buf), msg->env->x_comment_to);
649 if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
651 p_delete(&msg->env->x_comment_to);
652 msg->env->x_comment_to = m_strdup(buf);
653 move (HDR_BCC, HDR_XOFFSET);
655 if (msg->env->x_comment_to)
656 printw ("%-*.*s", W, W, msg->env->x_comment_to);
661 case OP_COMPOSE_EDIT_SUBJECT:
662 if (msg->env->subject)
663 m_strcpy(buf, sizeof(buf), msg->env->subject);
666 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
667 m_strreplace(&msg->env->subject, buf);
668 move (HDR_SUBJECT, HDR_XOFFSET + SW);
670 if (msg->env->subject)
671 mutt_paddstr (W, msg->env->subject);
673 mutt_message_hook (NULL, msg, M_SEND2HOOK);
675 case OP_COMPOSE_EDIT_REPLY_TO:
676 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
677 mutt_message_hook (NULL, msg, M_SEND2HOOK);
679 case OP_COMPOSE_EDIT_FCC:
680 m_strcpy(buf, sizeof(buf), fcc);
681 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
682 m_strcpy(fcc, _POSIX_PATH_MAX, buf);
683 mutt_pretty_mailbox (fcc);
684 move (HDR_FCC, HDR_XOFFSET + SW);
685 mutt_paddstr (W, fcc);
688 MAYBE_REDRAW (menu->redraw);
689 mutt_message_hook (NULL, msg, M_SEND2HOOK);
691 case OP_COMPOSE_EDIT_MESSAGE:
692 if (Editor && !option (OPTEDITHDRS)) {
693 mutt_edit_file (Editor, msg->content->filename);
694 mutt_update_encoding (msg->content);
695 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
696 mutt_message_hook (NULL, msg, M_SEND2HOOK);
700 case OP_COMPOSE_EDIT_HEADERS:
701 if ((op == OP_COMPOSE_EDIT_HEADERS ||
702 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
703 const char *tag = NULL;
704 const char *err = NULL;
706 mutt_env_to_local (msg->env);
707 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
709 if (mutt_env_to_idna (msg->env, &tag, &err)) {
710 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
714 mutt_update_encoding (msg->content);
716 /* attachments may have been added */
717 if (idxlen && idx[idxlen - 1]->content->next) {
718 for (i = 0; i < idxlen; i++)
722 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
728 menu->redraw = REDRAW_FULL;
729 mutt_message_hook (NULL, msg, M_SEND2HOOK);
734 case OP_COMPOSE_ATTACH_KEY:
735 if (idxlen == idxmax) {
736 p_realloc(&idx, idxmax += 5);
740 idx[idxlen] = p_new(ATTACHPTR, 1);
741 if ((idx[idxlen]->content =
742 crypt_pgp_make_key_attachment (NULL)) != NULL) {
743 update_idx (menu, idx, idxlen++);
744 menu->redraw |= REDRAW_INDEX;
747 p_delete(&idx[idxlen]);
749 menu->redraw |= REDRAW_STATUS;
751 if (option (OPTNEEDREDRAW)) {
752 menu->redraw = REDRAW_FULL;
753 unset_option (OPTNEEDREDRAW);
756 mutt_message_hook (NULL, msg, M_SEND2HOOK);
760 case OP_COMPOSE_ATTACH_FILE:
762 char *prompt, **files;
766 prompt = _("Attach file");
770 if (_mutt_enter_fname
771 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
772 &numfiles) == -1 || *fname == '\0')
775 if (idxlen + numfiles >= idxmax) {
776 p_realloc(&idx, idxmax += 5 + numfiles);
782 mutt_message _("Attaching selected files...");
784 for (i = 0; i < numfiles; i++) {
785 char *att = files[i];
787 idx[idxlen] = p_new(ATTACHPTR, 1);
788 idx[idxlen]->unowned = 1;
789 idx[idxlen]->content = mutt_make_file_attach (att);
790 if (idx[idxlen]->content != NULL)
791 update_idx (menu, idx, idxlen++);
794 mutt_error (_("Unable to attach %s!"), att);
795 p_delete(&idx[idxlen]);
803 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
805 mutt_message_hook (NULL, msg, M_SEND2HOOK);
808 case OP_COMPOSE_ATTACH_MESSAGE:
810 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
817 prompt = _("Open mailbox to attach message from");
820 unset_option (OPTNEWS);
821 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
822 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
825 prompt = _("Open newsgroup to attach message from");
826 set_option (OPTNEWS);
832 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
835 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
836 mutt_pretty_mailbox (fname);
839 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
844 if (option (OPTNEWS))
845 nntp_expand_path (fname, sizeof (fname),
846 &CurrentNewsSrv->conn->account);
849 mutt_expand_path (fname, sizeof (fname));
850 if (mx_get_magic (fname) != M_IMAP)
851 if (mx_get_magic (fname) != M_POP)
853 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
855 /* check to make sure the file exists and is readable */
856 if (access (fname, R_OK) == -1) {
861 menu->redraw = REDRAW_FULL;
863 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
869 if (!ctx->msgcount) {
870 mx_close_mailbox (ctx, NULL);
872 mutt_error _("No messages in that folder.");
877 this = Context; /* remember current folder and sort methods */
879 oldSortAux = SortAux;
882 set_option (OPTATTACHMSG);
883 mutt_message _("Tag the messages you want to attach!");
885 closed = mutt_index_menu ();
886 unset_option (OPTATTACHMSG);
889 /* go back to the folder we started from */
891 /* Restore old $sort and $sort_aux */
893 SortAux = oldSortAux;
894 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
898 if (idxlen + Context->tagged >= idxmax) {
899 p_realloc(&idx, idxmax += 5 + Context->tagged);
903 for (i = 0; i < Context->msgcount; i++) {
904 h = Context->hdrs[i];
906 idx[idxlen] = p_new(ATTACHPTR, 1);
907 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
908 if (idx[idxlen]->content != NULL)
909 update_idx (menu, idx, idxlen++);
911 mutt_error _("Unable to attach!");
913 p_delete(&idx[idxlen]);
917 menu->redraw |= REDRAW_FULL;
919 if (closed == OP_QUIT)
920 mx_close_mailbox (Context, NULL);
922 mx_fastclose_mailbox (Context);
925 /* go back to the folder we started from */
927 /* Restore old $sort and $sort_aux */
929 SortAux = oldSortAux;
931 mutt_message_hook (NULL, msg, M_SEND2HOOK);
936 if (idx[menu->current]->unowned)
937 idx[menu->current]->content->unlink = 0;
938 if (delete_attachment (menu, &idxlen, menu->current) == -1)
940 mutt_update_tree (idx, idxlen);
942 if (menu->current > idxlen - 1)
943 menu->current = idxlen - 1;
948 if (menu->current == 0)
949 msg->content = idx[0]->content;
951 menu->redraw |= REDRAW_STATUS;
952 mutt_message_hook (NULL, msg, M_SEND2HOOK);
955 #define CURRENT idx[menu->current]->content
957 case OP_COMPOSE_TOGGLE_RECODE:
960 if (!mutt_is_text_part (CURRENT)) {
961 mutt_error (_("Recoding only affects text attachments."));
964 CURRENT->noconv = !CURRENT->noconv;
966 mutt_message (_("The current attachment won't be converted."));
968 mutt_message (_("The current attachment will be converted."));
969 menu->redraw = REDRAW_CURRENT;
970 mutt_message_hook (NULL, msg, M_SEND2HOOK);
975 case OP_COMPOSE_EDIT_DESCRIPTION:
977 m_strcpy(buf, sizeof(buf),
978 NONULL(idx[menu->current]->content->description));
979 /* header names should not be translated */
980 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
981 m_strreplace(&idx[menu->current]->content->description, buf);
982 menu->redraw = REDRAW_CURRENT;
984 mutt_message_hook (NULL, msg, M_SEND2HOOK);
987 case OP_COMPOSE_UPDATE_ENCODING:
989 if (menu->tagprefix) {
992 for (top = msg->content; top; top = top->next) {
994 mutt_update_encoding (top);
996 menu->redraw = REDRAW_FULL;
999 mutt_update_encoding (idx[menu->current]->content);
1000 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1002 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1005 case OP_COMPOSE_TOGGLE_DISPOSITION:
1006 /* toggle the content-disposition between inline/attachment */
1007 idx[menu->current]->content->disposition =
1008 (idx[menu->current]->content->disposition ==
1009 DISPINLINE) ? DISPATTACH : DISPINLINE;
1010 menu->redraw = REDRAW_CURRENT;
1016 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
1018 /* this may have been a change to text/something */
1019 mutt_update_encoding (idx[menu->current]->content);
1021 menu->redraw = REDRAW_CURRENT;
1023 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1026 case OP_COMPOSE_EDIT_ENCODING:
1028 m_strcpy(buf, sizeof(buf),
1029 ENCODING(idx[menu->current]->content->encoding));
1030 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
1031 sizeof (buf), 0) == 0 && buf[0]) {
1032 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
1033 idx[menu->current]->content->encoding = i;
1034 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1035 mutt_clear_error ();
1038 mutt_error _("Invalid encoding.");
1040 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1043 case OP_COMPOSE_SEND_MESSAGE:
1045 /* Note: We don't invoke send2-hook here, since we want to leave
1046 * users an opportunity to change settings from the ":" prompt.
1049 if (check_attachments (idx, idxlen) != 0) {
1050 menu->redraw = REDRAW_FULL;
1056 if (msg->chain && mix_check_message (msg) != 0)
1060 if (!fccSet && *fcc) {
1061 if ((i = query_quadoption (OPT_COPY,
1062 _("Save a copy of this message?"))) == -1)
1072 case OP_COMPOSE_EDIT_FILE:
1074 mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename);
1075 mutt_update_encoding (idx[menu->current]->content);
1076 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1077 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1080 case OP_COMPOSE_TOGGLE_UNLINK:
1082 idx[menu->current]->content->unlink =
1083 !idx[menu->current]->content->unlink;
1086 /* OPTRESOLVE is otherwise ignored on this menu.
1090 if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
1093 menu->redraw = REDRAW_INDEX;
1094 /* No send2hook since this doesn't change the message. */
1097 case OP_COMPOSE_GET_ATTACHMENT:
1099 if (menu->tagprefix) {
1102 for (top = msg->content; top; top = top->next) {
1104 mutt_get_tmp_attachment (top);
1106 menu->redraw = REDRAW_FULL;
1108 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1109 menu->redraw = REDRAW_CURRENT;
1111 /* No send2hook since this doesn't change the message. */
1114 case OP_COMPOSE_RENAME_FILE:
1116 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
1117 mutt_pretty_mailbox (fname);
1118 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1120 if (stat (idx[menu->current]->content->filename, &st) == -1) {
1121 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1125 mutt_expand_path (fname, sizeof (fname));
1126 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1129 m_strreplace(&idx[menu->current]->content->filename, fname);
1130 menu->redraw = REDRAW_CURRENT;
1132 if (idx[menu->current]->content->stamp >= st.st_mtime)
1133 mutt_stamp_attachment (idx[menu->current]->content);
1136 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1139 case OP_COMPOSE_NEW_MIME:
1146 CLEARLINE (LINES - 1);
1148 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1151 mutt_expand_path (fname, sizeof (fname));
1153 /* Call to lookup_mime_type () ? maybe later */
1155 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1159 if (!(p = strchr (type, '/'))) {
1160 mutt_error _("Content-Type is of the form base/sub");
1165 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1166 mutt_error (_("Unknown Content-Type %s"), type);
1169 if (idxlen == idxmax) {
1170 p_realloc(&idx, idxmax += 5);
1174 idx[idxlen] = p_new(ATTACHPTR, 1);
1175 /* Touch the file */
1176 if (!(fp = safe_fopen (fname, "w"))) {
1177 mutt_error (_("Can't create file %s"), fname);
1178 p_delete(&idx[idxlen]);
1183 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1185 _("What we have here is a failure to make an attachment");
1188 update_idx (menu, idx, idxlen++);
1190 idx[menu->current]->content->type = itype;
1191 m_strreplace(&idx[menu->current]->content->subtype, p);
1192 idx[menu->current]->content->unlink = 1;
1193 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1195 if (mutt_compose_attachment (idx[menu->current]->content)) {
1196 mutt_update_encoding (idx[menu->current]->content);
1197 menu->redraw = REDRAW_FULL;
1200 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1203 case OP_COMPOSE_EDIT_MIME:
1205 if (mutt_edit_attachment (idx[menu->current]->content)) {
1206 mutt_update_encoding (idx[menu->current]->content);
1207 menu->redraw = REDRAW_FULL;
1209 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1212 case OP_VIEW_ATTACH:
1213 case OP_DISPLAY_HEADERS:
1215 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1217 menu->redraw = REDRAW_FULL;
1218 /* no send2hook, since this doesn't modify the message */
1223 mutt_save_attachment_list (NULL, menu->tagprefix,
1224 menu->tagprefix ? msg->content : idx[menu->
1226 content, NULL, menu);
1227 MAYBE_REDRAW (menu->redraw);
1228 /* no send2hook, since this doesn't modify the message */
1233 mutt_print_attachment_list (NULL, menu->tagprefix,
1234 menu->tagprefix ? msg->content : idx[menu->
1237 /* no send2hook, since this doesn't modify the message */
1243 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1244 menu->tagprefix ? msg->content : idx[menu->
1246 content, op == OP_FILTER);
1247 if (op == OP_FILTER) /* cte might have changed */
1248 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1249 menu->redraw |= REDRAW_STATUS;
1250 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1255 query_quadoption (OPT_POSTPONE,
1256 _("Postpone this message?"))) == M_NO) {
1257 while (idxlen-- > 0) {
1258 /* avoid freeing other attachments */
1259 idx[idxlen]->content->next = NULL;
1260 idx[idxlen]->content->parts = NULL;
1261 if (idx[idxlen]->unowned)
1262 idx[idxlen]->content->unlink = 0;
1263 mutt_free_body (&idx[idxlen]->content);
1264 p_delete(&idx[idxlen]->tree);
1265 p_delete(&idx[idxlen]);
1277 /* fall through to postpone! */
1279 case OP_COMPOSE_POSTPONE_MESSAGE:
1281 if (check_attachments (idx, idxlen) != 0) {
1282 menu->redraw = REDRAW_FULL;
1290 case OP_COMPOSE_ISPELL:
1292 snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1293 msg->content->filename);
1294 if (mutt_system (buf) == -1)
1295 mutt_error (_("Error running \"%s\"!"), buf);
1297 mutt_update_encoding (msg->content);
1298 menu->redraw |= REDRAW_STATUS;
1302 case OP_COMPOSE_WRITE_MESSAGE:
1306 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
1307 mutt_pretty_mailbox (fname);
1310 msg->content = idx[0]->content;
1311 if (mutt_enter_fname
1312 (_("Write message to mailbox"), fname, sizeof (fname),
1313 &menu->redraw, 1) != -1 && fname[0]) {
1314 mutt_message (_("Writing message to %s ..."), fname);
1315 mutt_expand_path (fname, sizeof (fname));
1317 if (msg->content->next)
1318 msg->content = mutt_make_multipart (msg->content);
1320 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1321 msg->content = mutt_remove_multipart (msg->content);
1323 mutt_message _("Message written.");
1329 case OP_COMPOSE_PGP_MENU:
1330 if (msg->security & APPLICATION_SMIME) {
1331 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1333 mutt_clear_error ();
1338 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1339 redraw_crypt_lines (msg);
1340 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1344 case OP_FORGET_PASSPHRASE:
1345 crypt_forget_passphrase ();
1349 case OP_COMPOSE_SMIME_MENU:
1350 if (msg->security & APPLICATION_PGP) {
1351 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1353 mutt_clear_error ();
1358 msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1359 redraw_crypt_lines (msg);
1360 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1365 case OP_COMPOSE_MIX:
1367 mix_make_chain (&msg->chain, &menu->redraw);
1368 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1374 /* Draw formated compose status line */
1375 if (menu->redraw & REDRAW_STATUS) {
1376 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1377 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1378 SETCOLOR (MT_COLOR_STATUS);
1379 move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
1380 printw ("%-*.*s", COLS-SW, COLS-SW, buf);
1381 SETCOLOR (MT_COLOR_NORMAL);
1382 menu->redraw &= ~REDRAW_STATUS;
1386 mutt_menuDestroy (&menu);
1389 msg->content = idx[0]->content;
1390 for (i = 0; i < idxlen; i++) {
1391 idx[i]->content->aptr = NULL;
1396 msg->content = NULL;