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"
43 #include "recvattach.h"
58 static const char *There_are_no_attachments = N_("There are no attachments.");
60 #define CHECK_COUNT if (idxlen == 0) { mutt_error _(There_are_no_attachments); break; }
87 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
89 HDR_ATTACH = (HDR_FCC + 7)
93 #define HDR_XOFFSET 14
94 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
95 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
96 #define W (COLS - HDR_XOFFSET - SW)
98 static const char *Prompts[] = {
110 , "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: "
114 static struct mapping_t ComposeHelp[] = {
115 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
116 {N_("Abort"), OP_EXIT},
117 {"To", OP_COMPOSE_EDIT_TO},
118 {"CC", OP_COMPOSE_EDIT_CC},
119 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
120 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
121 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
122 {N_("Help"), OP_HELP},
127 static struct mapping_t ComposeNewsHelp[] = {
128 {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
129 {N_("Abort"), OP_EXIT},
130 {"Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS},
131 {"Subj", OP_COMPOSE_EDIT_SUBJECT},
132 {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
133 {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
134 {N_("Help"), OP_HELP},
140 static void snd_entry (char *b, ssize_t blen, MUTTMENU * menu, int num) {
141 int w=(COLS-SW)>blen?blen:COLS-SW;
142 mutt_FormatString (b, w, NONULL (AttachFormat), mutt_attach_fmt,
143 (unsigned long) (((ATTACHPTR **) menu->data)[num]),
144 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
147 #include <lib-crypt/crypt.h>
149 static void redraw_crypt_lines (HEADER * msg)
154 mvaddstr (HDR_CRYPT, SW, " Security: ");
155 else if (msg->security & APPLICATION_SMIME)
156 mvaddstr (HDR_CRYPT, SW, " S/MIME: ");
157 else if (msg->security & APPLICATION_PGP)
158 mvaddstr (HDR_CRYPT, SW, " PGP: ");
160 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
161 addstr (_("Sign, Encrypt"));
162 else if (msg->security & ENCRYPT)
163 addstr (_("Encrypt"));
164 else if (msg->security & SIGN)
169 if ((msg->security & APPLICATION_PGP)
170 && (msg->security & (ENCRYPT | SIGN))) {
171 if ((msg->security & INLINE))
172 addstr (_(" (inline)"));
174 addstr (_(" (PGP/MIME)"));
178 move (HDR_CRYPTINFO, SW);
180 if (msg->security & APPLICATION_PGP && msg->security & SIGN)
181 printw ("%s%s", _(" sign as: "),
182 PgpSignAs ? PgpSignAs : _("<default>"));
184 if (msg->security & APPLICATION_SMIME && msg->security & SIGN) {
185 printw ("%s%s", _(" sign as: "),
186 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
189 if ((msg->security & APPLICATION_SMIME)
190 && (msg->security & ENCRYPT)
191 && SmimeCryptAlg && *SmimeCryptAlg) {
192 mvprintw (HDR_CRYPTINFO, SW + 40, "%s%s", _("Encrypt with: "),
193 NONULL (SmimeCryptAlg));
201 static void redraw_mix_line (string_list_t * chain)
206 mvaddstr (HDR_MIX, SW, " Mix: ");
209 addstr ("<no chain defined>");
214 for (c = 12; chain; chain = chain->next) {
216 if (t && t[0] == '0' && t[1] == '\0')
219 if (c + m_strlen(t) + 2 >= COLS - SW)
226 c += m_strlen(t) + 2;
229 #endif /* MIXMASTER */
231 static int check_attachments (ATTACHPTR ** idx, short idxlen)
235 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
237 for (i = 0; i < idxlen; i++) {
238 m_strcpy(pretty, sizeof(pretty), idx[i]->content->filename);
239 if (stat (idx[i]->content->filename, &st) != 0) {
240 mutt_pretty_mailbox (pretty);
241 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
245 if (idx[i]->content->stamp < st.st_mtime) {
246 mutt_pretty_mailbox (pretty);
247 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
250 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
251 mutt_update_encoding (idx[i]->content);
260 static void draw_envelope_addr (int line, address_t * addr)
265 rfc822_write_address (buf, sizeof (buf), addr, 1);
266 mvprintw (line, SW, TITLE_FMT, Prompts[line - 1]);
267 mutt_paddstr (W, buf);
270 static void draw_envelope (HEADER * msg, char *fcc)
272 draw_envelope_addr (HDR_FROM, msg->env->from);
274 if (!option (OPTNEWSSEND)) {
276 draw_envelope_addr (HDR_TO, msg->env->to);
277 draw_envelope_addr (HDR_CC, msg->env->cc);
278 draw_envelope_addr (HDR_BCC, msg->env->bcc);
282 mvprintw (HDR_TO, SW, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
283 mutt_paddstr (W, NONULL (msg->env->newsgroups));
284 mvprintw (HDR_CC, SW, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
285 mutt_paddstr (W, NONULL (msg->env->followup_to));
286 if (option (OPTXCOMMENTTO)) {
287 mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]);
288 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
292 mvprintw (HDR_SUBJECT, SW, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
293 mutt_paddstr (W, NONULL (msg->env->subject));
294 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
295 mvprintw (HDR_FCC, SW, TITLE_FMT, Prompts[HDR_FCC - 1]);
296 mutt_paddstr (W, fcc);
298 redraw_crypt_lines (msg);
301 redraw_mix_line (msg->chain);
304 SETCOLOR (MT_COLOR_STATUS);
305 mvaddstr (HDR_ATTACH - 1, SW, _("-- Attachments"));
306 BKGDSET (MT_COLOR_STATUS);
309 BKGDSET (MT_COLOR_NORMAL);
310 SETCOLOR (MT_COLOR_NORMAL);
313 static int edit_address_list (int line, address_t ** addr)
315 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
316 const char *err = NULL;
318 mutt_addrlist_to_local (*addr);
319 rfc822_write_address (buf, sizeof (buf), *addr, 0);
320 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
321 address_list_wipe(addr);
322 *addr = mutt_parse_adrlist (*addr, buf);
323 *addr = mutt_expand_aliases (*addr);
326 if (option (OPTNEEDREDRAW)) {
327 unset_option (OPTNEEDREDRAW);
328 return (REDRAW_FULL);
331 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
332 mutt_error (_("Warning: '%s' is a bad IDN."), err);
337 /* redraw the expanded list so the user can see the result */
339 rfc822_write_address (buf, sizeof (buf), *addr, 1);
340 move (line, HDR_XOFFSET + SW);
341 mutt_paddstr (W, buf);
346 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
348 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
351 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
353 if (x == 0 && menu->max == 1) {
354 mutt_error _("You may not delete the only attachment.");
356 idx[x]->content->tagged = 0;
360 for (y = 0; y < *idxlen; y++) {
361 if (idx[y]->content->next == idx[x]->content) {
362 idx[y]->content->next = idx[x]->content->next;
367 idx[x]->content->next = NULL;
368 idx[x]->content->parts = NULL;
369 body_list_wipe(&(idx[x]->content));
370 p_delete(&idx[x]->tree);
372 for (; x < *idxlen - 1; x++)
374 menu->max = --(*idxlen);
379 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
381 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
383 idx[idxlen - 1]->content->next = idx[idxlen]->content;
384 idx[idxlen]->content->aptr = idx[idxlen];
385 menu->current = idxlen++;
386 mutt_update_tree (idx, idxlen);
393 * cum_attachs_size: Cumulative Attachments Size
395 * Returns the total number of bytes used by the attachments in the
396 * attachment list _after_ content-transfer-encodings have been
401 static unsigned long cum_attachs_size (MUTTMENU * menu)
405 ATTACHPTR **idx = menu->data;
409 for (i = 0, s = 0; i < menu->max; i++) {
413 b->content = mutt_get_content_info (b->filename, b);
415 if ((info = b->content)) {
416 switch (b->encoding) {
417 case ENCQUOTEDPRINTABLE:
418 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
421 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
424 s += info->lobin + info->hibin + info->ascii + info->crlf;
434 * compose_format_str()
436 * %a = total number of attachments
437 * %h = hostname [option]
438 * %l = approx. length of current message (in bytes)
441 * This function is similar to status_format_str(). Look at that function for
442 * help when modifying this function.
445 static const char *compose_format_str (char *buf, ssize_t buflen, char op,
446 const char *src, const char *prefix,
447 const char *ifstring,
448 const char *elsestring,
449 unsigned long data, format_flag flags)
451 char fmt[SHORT_STRING], tmp[SHORT_STRING];
452 int optional = (flags & M_FORMAT_OPTIONAL);
453 MUTTMENU *menu = (MUTTMENU *) data;
457 case 'a': /* total number of attachments */
458 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
459 snprintf (buf, buflen, fmt, menu->max);
462 case 'h': /* hostname */
463 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
464 snprintf (buf, buflen, fmt, NONULL (Hostname));
467 case 'l': /* approx length of current message in bytes */
468 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
469 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
470 snprintf (buf, buflen, fmt, tmp);
474 m_strcpy(buf, buflen, mutt_make_version (0));
482 snprintf (buf, buflen, "%%%s%c", prefix, op);
487 compose_status_line (buf, buflen, menu, ifstring);
488 else if (flags & M_FORMAT_OPTIONAL)
489 compose_status_line (buf, buflen, menu, elsestring);
494 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
497 int w=(COLS-SW)>buflen?buflen:(COLS-SW);
498 mutt_FormatString (buf, w, p, compose_format_str,
499 (unsigned long) menu, 0);
505 * 1 message should be postponed
509 int mutt_compose_menu (HEADER * msg, /* structure for new message */
510 char *fcc, /* where to save a copy of the message */
512 HEADER * cur __attribute__ ((unused)))
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 body_list_wipe(&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;