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>
19 #include <lib-ui/lib-ui.h>
20 #include <lib-ui/enter.h>
21 #include <lib-ui/menu.h>
22 #include <lib-mx/mx.h>
27 #include "mutt_idna.h"
29 #include "recvattach.h"
40 mutt_error _("There are no attachments."); \
63 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
65 HDR_ATTACH = (HDR_FCC + 7)
69 #define HDR_XOFFSET 14
70 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
71 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
72 #define W (COLS - HDR_XOFFSET - SW)
74 static const char *Prompts[] = {
83 "", "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: "
87 static void snd_entry (char *b, ssize_t blen, MUTTMENU * menu, int num) {
88 m_strformat(b, blen, COLS - SW, AttachFormat, mutt_attach_fmt,
89 ((ATTACHPTR **)menu->data)[num], M_FORMAT_STAT_FILE);
92 static void redraw_crypt_lines (HEADER * msg)
97 mvwaddstr (stdscr, HDR_CRYPT, SW, " Security: ");
98 else if (msg->security & APPLICATION_SMIME)
99 mvwaddstr (stdscr, HDR_CRYPT, SW, " S/MIME: ");
100 else if (msg->security & APPLICATION_PGP)
101 mvwaddstr (stdscr, HDR_CRYPT, SW, " PGP: ");
103 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
104 waddstr (stdscr, _("Sign, Encrypt"));
105 else if (msg->security & ENCRYPT)
106 waddstr (stdscr, _("Encrypt"));
107 else if (msg->security & SIGN)
108 waddstr (stdscr, _("Sign"));
110 waddstr (stdscr, _("Clear"));
112 if ((msg->security & APPLICATION_PGP)
113 && (msg->security & (ENCRYPT | SIGN))) {
114 if ((msg->security & INLINE))
115 waddstr (stdscr, _(" (inline)"));
117 waddstr (stdscr, _(" (PGP/MIME)"));
121 wmove (stdscr, HDR_CRYPTINFO, SW);
123 if (msg->security & APPLICATION_PGP && msg->security & SIGN)
124 wprintw (stdscr, "%s%s", _(" sign as: "),
125 PgpSignAs ? PgpSignAs : _("<default>"));
127 if (msg->security & APPLICATION_SMIME && msg->security & SIGN) {
128 wprintw (stdscr, "%s%s", _(" sign as: "),
129 SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
132 if ((msg->security & APPLICATION_SMIME)
133 && (msg->security & ENCRYPT)
134 && SmimeCryptAlg && *SmimeCryptAlg) {
135 mvwprintw (stdscr, HDR_CRYPTINFO, SW + 40, "%s%s", _("Encrypt with: "),
136 NONULL (SmimeCryptAlg));
141 static int check_attachments (ATTACHPTR ** idx, short idxlen)
145 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + STRING];
147 for (i = 0; i < idxlen; i++) {
148 m_strcpy(pretty, sizeof(pretty), idx[i]->content->filename);
149 if (stat (idx[i]->content->filename, &st) != 0) {
150 mutt_pretty_mailbox (pretty);
151 mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
155 if (idx[i]->content->stamp < st.st_mtime) {
156 mutt_pretty_mailbox (pretty);
157 snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
160 if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
161 mutt_update_encoding (idx[i]->content);
170 static void draw_envelope_addr (int line, address_t * addr)
175 rfc822_addrcat(buf, sizeof (buf), addr, 1);
176 mvwprintw (stdscr, line, SW, TITLE_FMT, Prompts[line - 1]);
177 mutt_paddstr (W, buf);
180 static void draw_envelope (HEADER * msg, char *fcc)
182 draw_envelope_addr (HDR_FROM, msg->env->from);
184 if (!option (OPTNEWSSEND)) {
186 draw_envelope_addr (HDR_TO, msg->env->to);
187 draw_envelope_addr (HDR_CC, msg->env->cc);
188 draw_envelope_addr (HDR_BCC, msg->env->bcc);
191 mvwprintw (stdscr, HDR_TO, SW, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
192 mutt_paddstr (W, NONULL (msg->env->newsgroups));
193 mvwprintw (stdscr, HDR_CC, SW, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
194 mutt_paddstr (W, NONULL (msg->env->followup_to));
197 mvwprintw (stdscr, HDR_SUBJECT, SW, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
198 mutt_paddstr (W, NONULL (msg->env->subject));
199 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
200 mvwprintw (stdscr, HDR_FCC, SW, TITLE_FMT, Prompts[HDR_FCC - 1]);
201 mutt_paddstr (W, fcc);
203 redraw_crypt_lines (msg);
205 SETCOLOR (MT_COLOR_STATUS);
206 mvwaddstr (stdscr, HDR_ATTACH - 1, SW, _("-- Attachments"));
207 BKGDSET (MT_COLOR_STATUS);
210 BKGDSET (MT_COLOR_NORMAL);
211 SETCOLOR (MT_COLOR_NORMAL);
214 static int edit_address_list (int line, address_t ** addr)
216 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
219 mutt_addrlist_to_local (*addr);
220 rfc822_addrcat(buf, sizeof (buf), *addr, 0);
221 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
222 address_list_wipe(addr);
223 *addr = mutt_parse_adrlist (*addr, buf);
224 *addr = mutt_expand_aliases (*addr);
227 if (option (OPTNEEDREDRAW)) {
228 unset_option (OPTNEEDREDRAW);
232 if (mutt_addrlist_to_idna (*addr, &err) != 0) {
233 mutt_error (_("Warning: '%s' is a bad IDN."), err);
238 /* redraw the expanded list so the user can see the result */
240 rfc822_addrcat(buf, sizeof (buf), *addr, 1);
241 wmove (stdscr, line, HDR_XOFFSET + SW);
242 mutt_paddstr (W, buf);
247 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
249 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
252 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
254 if (x == 0 && menu->max == 1) {
255 mutt_error _("You may not delete the only attachment.");
257 idx[x]->content->tagged = 0;
261 for (y = 0; y < *idxlen; y++) {
262 if (idx[y]->content->next == idx[x]->content) {
263 idx[y]->content->next = idx[x]->content->next;
268 idx[x]->content->next = NULL;
269 idx[x]->content->parts = NULL;
270 body_list_wipe(&(idx[x]->content));
271 p_delete(&idx[x]->tree);
273 for (; x < *idxlen - 1; x++)
275 menu->max = --(*idxlen);
280 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
282 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
284 idx[idxlen - 1]->content->next = idx[idxlen]->content;
285 idx[idxlen]->content->aptr = idx[idxlen];
286 menu->current = idxlen++;
287 mutt_update_tree (idx, idxlen);
294 * cum_attachs_size: Cumulative Attachments Size
296 * Returns the total number of bytes used by the attachments in the
297 * attachment list _after_ content-transfer-encodings have been
301 static unsigned long cum_attachs_size(MUTTMENU * menu)
305 ATTACHPTR **idx = menu->data;
309 for (i = 0, s = 0; i < menu->max; i++) {
313 b->content = mutt_get_content_info (b->filename, b);
315 if ((info = b->content)) {
316 switch (b->encoding) {
317 case ENCQUOTEDPRINTABLE:
318 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
321 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
324 s += info->lobin + info->hibin + info->ascii + info->crlf;
334 * compose_format_str()
336 * %a = total number of attachments
337 * %h = hostname [option]
338 * %l = approx. length of current message (in bytes)
341 * This function is similar to status_format_str(). Look at that function for
342 * help when modifying this function.
344 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
347 static const char *compose_format_str (char *buf, ssize_t buflen, char op,
348 const char *src, const char *prefix,
351 anytype data, format_flag flags)
353 char fmt[STRING], tmp[STRING];
354 int optional = (flags & M_FORMAT_OPTIONAL);
355 MUTTMENU *menu = data.ptr;
359 case 'a': /* total number of attachments */
360 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
361 snprintf (buf, buflen, fmt, menu->max);
364 case 'h': /* hostname */
365 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
366 snprintf (buf, buflen, fmt, NONULL(mod_core.shorthost));
369 case 'l': /* approx length of current message in bytes */
370 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
371 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
372 snprintf (buf, buflen, fmt, tmp);
376 m_strcpy(buf, buflen, mutt_make_version());
388 if (flags & M_FORMAT_OPTIONAL)
389 compose_status_line(buf, buflen, menu, optional ? ifstr : elstr);
394 static void compose_status_line (char *buf, ssize_t buflen, MUTTMENU * menu,
397 m_strformat(buf, buflen, COLS - SW, p, compose_format_str, menu, 0);
402 * 1 message should be postponed
406 int mutt_compose_menu (HEADER * msg, /* structure for new message */
407 char *fcc, /* where to save a copy of the message */
409 HEADER * cur __attribute__ ((unused)))
410 { /* current message */
411 char buf[LONG_STRING];
412 char fname[_POSIX_PATH_MAX];
414 ATTACHPTR **idx = NULL;
418 int r = -1; /* return value */
421 int fccSet = 0; /* has the user edited the Fcc: field ? */
422 CONTEXT *ctx = NULL, *this = NULL;
424 /* Sort, SortAux could be changed in mutt_index_menu() */
425 int oldSort, oldSortAux;
429 int news = 0; /* is it a news article ? */
431 if (option (OPTNEWSSEND))
435 mutt_attach_init (msg->content);
436 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
438 menu = mutt_new_menu ();
439 menu->menu = MENU_COMPOSE;
440 menu->offset = HDR_ATTACH;
442 menu->make_entry = snd_entry;
443 menu->tag = mutt_tag_attach;
446 if (option (OPTMBOXPANE))
450 unset_option (OPTNEWS); /* for any case */
452 switch (op = mutt_menuLoop (menu)) {
454 draw_envelope (msg, fcc);
455 menu->offset = HDR_ATTACH;
456 menu->pagelen = LINES - HDR_ATTACH - 2;
458 case OP_COMPOSE_EDIT_FROM:
459 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
460 mutt_message_hook (NULL, msg, M_SEND2HOOK);
462 case OP_COMPOSE_EDIT_TO:
466 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
467 mutt_message_hook (NULL, msg, M_SEND2HOOK);
472 case OP_COMPOSE_EDIT_BCC:
476 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
477 mutt_message_hook (NULL, msg, M_SEND2HOOK);
482 case OP_COMPOSE_EDIT_CC:
486 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
487 mutt_message_hook (NULL, msg, M_SEND2HOOK);
493 case OP_COMPOSE_EDIT_NEWSGROUPS:
495 if (msg->env->newsgroups)
496 m_strcpy(buf, sizeof(buf), msg->env->newsgroups);
499 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
501 p_delete(&msg->env->newsgroups);
503 msg->env->newsgroups = m_strdup(skipspaces(buf));
504 wmove (stdscr, HDR_TO, HDR_XOFFSET);
506 if (msg->env->newsgroups)
507 wprintw (stdscr, "%-*.*s", W, W, msg->env->newsgroups);
512 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
515 if (msg->env->followup_to)
516 m_strcpy(buf, sizeof(buf), msg->env->followup_to);
517 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
519 p_delete(&msg->env->followup_to);
521 msg->env->followup_to = m_strdup(skipspaces(buf));
522 wmove (stdscr, HDR_CC, HDR_XOFFSET);
524 if (msg->env->followup_to)
525 wprintw (stdscr, "%-*.*s", W, W, msg->env->followup_to);
531 case OP_COMPOSE_EDIT_SUBJECT:
532 if (msg->env->subject)
533 m_strcpy(buf, sizeof(buf), msg->env->subject);
536 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
537 m_strreplace(&msg->env->subject, buf);
538 wmove (stdscr, HDR_SUBJECT, HDR_XOFFSET + SW);
540 if (msg->env->subject)
541 mutt_paddstr (W, msg->env->subject);
543 mutt_message_hook (NULL, msg, M_SEND2HOOK);
545 case OP_COMPOSE_EDIT_REPLY_TO:
546 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
547 mutt_message_hook (NULL, msg, M_SEND2HOOK);
549 case OP_COMPOSE_EDIT_FCC:
550 m_strcpy(buf, sizeof(buf), fcc);
551 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
552 m_strcpy(fcc, _POSIX_PATH_MAX, buf);
553 mutt_pretty_mailbox (fcc);
554 wmove (stdscr, HDR_FCC, HDR_XOFFSET + SW);
555 mutt_paddstr (W, fcc);
558 MAYBE_REDRAW (menu->redraw);
559 mutt_message_hook (NULL, msg, M_SEND2HOOK);
561 case OP_COMPOSE_EDIT_MESSAGE:
562 if (!option (OPTEDITHDRS)) {
563 mutt_edit_file(msg->content->filename);
564 mutt_update_encoding (msg->content);
565 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
566 mutt_message_hook (NULL, msg, M_SEND2HOOK);
570 case OP_COMPOSE_EDIT_HEADERS:
571 if ((op == OP_COMPOSE_EDIT_HEADERS ||
572 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
573 const char *tag = NULL;
576 mutt_env_to_local (msg->env);
577 mutt_edit_headers(msg->content->filename, msg, fcc, fcclen);
578 if (mutt_env_to_idna (msg->env, &tag, &err)) {
579 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
583 mutt_update_encoding (msg->content);
585 /* attachments may have been added */
586 if (idxlen && idx[idxlen - 1]->content->next) {
587 for (i = 0; i < idxlen; i++)
591 mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
597 menu->redraw = REDRAW_FULL;
598 mutt_message_hook (NULL, msg, M_SEND2HOOK);
601 case OP_COMPOSE_ATTACH_FILE:
608 prompt = _("Attach file");
612 if (_mutt_enter_fname
613 (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
614 &numfiles) == -1 || *fname == '\0')
617 if (idxlen + numfiles >= idxmax) {
618 p_realloc(&idx, idxmax += 5 + numfiles);
624 mutt_message _("Attaching selected files...");
626 for (i = 0; i < numfiles; i++) {
627 char *att = files[i];
629 idx[idxlen] = p_new(ATTACHPTR, 1);
630 idx[idxlen]->unowned = 1;
631 idx[idxlen]->content = mutt_make_file_attach (att);
632 if (idx[idxlen]->content != NULL)
633 update_idx (menu, idx, idxlen++);
636 mutt_error (_("Unable to attach %s!"), att);
637 p_delete(&idx[idxlen]);
645 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
647 mutt_message_hook (NULL, msg, M_SEND2HOOK);
650 case OP_COMPOSE_ATTACH_MESSAGE:
652 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
659 prompt = _("Open mailbox to attach message from");
662 unset_option (OPTNEWS);
663 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
664 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
667 prompt = _("Open newsgroup to attach message from");
668 set_option (OPTNEWS);
674 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
677 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
678 mutt_pretty_mailbox (fname);
681 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
686 if (option (OPTNEWS))
687 nntp_expand_path (fname, sizeof (fname),
688 &CurrentNewsSrv->conn->account);
691 mutt_expand_path (fname, sizeof (fname));
692 if (mx_get_magic (fname) != M_IMAP)
693 if (mx_get_magic (fname) != M_POP)
695 if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
697 /* check to make sure the file exists and is readable */
698 if (access (fname, R_OK) == -1) {
703 menu->redraw = REDRAW_FULL;
705 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
711 if (!ctx->msgcount) {
712 mx_close_mailbox (ctx, NULL);
714 mutt_error _("No messages in that folder.");
719 this = Context; /* remember current folder and sort methods */
721 oldSortAux = SortAux;
724 set_option (OPTATTACHMSG);
725 mutt_message _("Tag the messages you want to attach!");
727 closed = mutt_index_menu ();
728 unset_option (OPTATTACHMSG);
731 /* go back to the folder we started from */
733 /* Restore old $sort and $sort_aux */
735 SortAux = oldSortAux;
736 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
740 if (idxlen + Context->tagged >= idxmax) {
741 p_realloc(&idx, idxmax += 5 + Context->tagged);
745 for (i = 0; i < Context->msgcount; i++) {
746 h = Context->hdrs[i];
748 idx[idxlen] = p_new(ATTACHPTR, 1);
749 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
750 if (idx[idxlen]->content != NULL)
751 update_idx (menu, idx, idxlen++);
753 mutt_error _("Unable to attach!");
755 p_delete(&idx[idxlen]);
759 menu->redraw |= REDRAW_FULL;
761 if (closed == OP_QUIT)
762 mx_close_mailbox (Context, NULL);
764 mx_fastclose_mailbox (Context);
767 /* go back to the folder we started from */
769 /* Restore old $sort and $sort_aux */
771 SortAux = oldSortAux;
773 mutt_message_hook (NULL, msg, M_SEND2HOOK);
778 if (idx[menu->current]->unowned)
779 idx[menu->current]->content->unlink = 0;
780 if (delete_attachment (menu, &idxlen, menu->current) == -1)
782 mutt_update_tree (idx, idxlen);
784 if (menu->current > idxlen - 1)
785 menu->current = idxlen - 1;
790 if (menu->current == 0)
791 msg->content = idx[0]->content;
793 menu->redraw |= REDRAW_STATUS;
794 mutt_message_hook (NULL, msg, M_SEND2HOOK);
797 #define CURRENT idx[menu->current]->content
799 case OP_COMPOSE_TOGGLE_RECODE:
802 if (!mutt_is_text_part (CURRENT)) {
803 mutt_error (_("Recoding only affects text attachments."));
806 CURRENT->noconv = !CURRENT->noconv;
808 mutt_message (_("The current attachment won't be converted."));
810 mutt_message (_("The current attachment will be converted."));
811 menu->redraw = REDRAW_CURRENT;
812 mutt_message_hook (NULL, msg, M_SEND2HOOK);
817 case OP_COMPOSE_EDIT_DESCRIPTION:
819 m_strcpy(buf, sizeof(buf),
820 NONULL(idx[menu->current]->content->description));
821 /* header names should not be translated */
822 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
823 m_strreplace(&idx[menu->current]->content->description, buf);
824 menu->redraw = REDRAW_CURRENT;
826 mutt_message_hook (NULL, msg, M_SEND2HOOK);
829 case OP_COMPOSE_UPDATE_ENCODING:
831 if (menu->tagprefix) {
834 for (top = msg->content; top; top = top->next) {
836 mutt_update_encoding (top);
838 menu->redraw = REDRAW_FULL;
841 mutt_update_encoding (idx[menu->current]->content);
842 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
844 mutt_message_hook (NULL, msg, M_SEND2HOOK);
847 case OP_COMPOSE_TOGGLE_DISPOSITION:
848 /* toggle the content-disposition between inline/attachment */
849 idx[menu->current]->content->disposition =
850 (idx[menu->current]->content->disposition ==
851 DISPINLINE) ? DISPATTACH : DISPINLINE;
852 menu->redraw = REDRAW_CURRENT;
858 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
860 /* this may have been a change to text/something */
861 mutt_update_encoding (idx[menu->current]->content);
863 menu->redraw = REDRAW_CURRENT;
865 mutt_message_hook (NULL, msg, M_SEND2HOOK);
868 case OP_COMPOSE_EDIT_ENCODING:
870 m_strcpy(buf, sizeof(buf),
871 ENCODING(idx[menu->current]->content->encoding));
872 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
873 sizeof (buf), 0) == 0 && buf[0]) {
874 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
875 idx[menu->current]->content->encoding = i;
876 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
880 mutt_error _("Invalid encoding.");
882 mutt_message_hook (NULL, msg, M_SEND2HOOK);
885 case OP_COMPOSE_SEND_MESSAGE:
887 /* Note: We don't invoke send2-hook here, since we want to leave
888 * users an opportunity to change settings from the ":" prompt.
891 if (check_attachments (idx, idxlen) != 0) {
892 menu->redraw = REDRAW_FULL;
896 if (!fccSet && *fcc) {
897 if ((i = query_quadoption (OPT_COPY,
898 _("Save a copy of this message?"))) == -1)
908 case OP_COMPOSE_EDIT_FILE:
910 mutt_edit_file(idx[menu->current]->content->filename);
911 mutt_update_encoding (idx[menu->current]->content);
912 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
913 mutt_message_hook (NULL, msg, M_SEND2HOOK);
916 case OP_COMPOSE_TOGGLE_UNLINK:
918 idx[menu->current]->content->unlink =
919 !idx[menu->current]->content->unlink;
921 menu->redraw = REDRAW_INDEX;
922 /* No send2hook since this doesn't change the message. */
925 case OP_COMPOSE_GET_ATTACHMENT:
927 if (menu->tagprefix) {
930 for (top = msg->content; top; top = top->next) {
932 mutt_get_tmp_attachment (top);
934 menu->redraw = REDRAW_FULL;
936 else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
937 menu->redraw = REDRAW_CURRENT;
939 /* No send2hook since this doesn't change the message. */
942 case OP_COMPOSE_RENAME_FILE:
944 m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
945 mutt_pretty_mailbox (fname);
946 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
948 if (stat (idx[menu->current]->content->filename, &st) == -1) {
949 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
953 mutt_expand_path (fname, sizeof (fname));
954 if (mutt_rename_file (idx[menu->current]->content->filename, fname))
957 m_strreplace(&idx[menu->current]->content->filename, fname);
958 menu->redraw = REDRAW_CURRENT;
960 if (idx[menu->current]->content->stamp >= st.st_mtime)
961 mutt_stamp_attachment (idx[menu->current]->content);
964 mutt_message_hook (NULL, msg, M_SEND2HOOK);
967 case OP_COMPOSE_NEW_MIME:
974 CLEARLINE (LINES - 1);
976 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
979 mutt_expand_path (fname, sizeof (fname));
981 /* Call to lookup_mime_type () ? maybe later */
983 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
987 if (!(p = strchr (type, '/'))) {
988 mutt_error _("Content-Type is of the form base/sub");
993 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
994 mutt_error (_("Unknown Content-Type %s"), type);
997 if (idxlen == idxmax) {
998 p_realloc(&idx, idxmax += 5);
1002 idx[idxlen] = p_new(ATTACHPTR, 1);
1003 /* Touch the file */
1004 if (!(fp = safe_fopen (fname, "w"))) {
1005 mutt_error (_("Can't create file %s"), fname);
1006 p_delete(&idx[idxlen]);
1011 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1013 _("What we have here is a failure to make an attachment");
1016 update_idx (menu, idx, idxlen++);
1018 idx[menu->current]->content->type = itype;
1019 m_strreplace(&idx[menu->current]->content->subtype, p);
1020 idx[menu->current]->content->unlink = 1;
1021 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1023 if (mutt_compose_attachment (idx[menu->current]->content)) {
1024 mutt_update_encoding (idx[menu->current]->content);
1025 menu->redraw = REDRAW_FULL;
1028 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1031 case OP_COMPOSE_EDIT_MIME:
1033 if (mutt_edit_attachment (idx[menu->current]->content)) {
1034 mutt_update_encoding (idx[menu->current]->content);
1035 menu->redraw = REDRAW_FULL;
1037 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1040 case OP_VIEW_ATTACH:
1041 case OP_DISPLAY_HEADERS:
1043 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1045 menu->redraw = REDRAW_FULL;
1046 /* no send2hook, since this doesn't modify the message */
1051 mutt_save_attachment_list (NULL, menu->tagprefix,
1052 menu->tagprefix ? msg->content : idx[menu->
1054 content, NULL, menu);
1055 MAYBE_REDRAW (menu->redraw);
1056 /* no send2hook, since this doesn't modify the message */
1061 mutt_print_attachment_list (NULL, menu->tagprefix,
1062 menu->tagprefix ? msg->content : idx[menu->
1065 /* no send2hook, since this doesn't modify the message */
1071 mutt_pipe_attachment_list (NULL, menu->tagprefix,
1072 menu->tagprefix ? msg->content : idx[menu->
1074 content, op == OP_FILTER);
1075 if (op == OP_FILTER) /* cte might have changed */
1076 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1077 menu->redraw |= REDRAW_STATUS;
1078 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1083 query_quadoption (OPT_POSTPONE,
1084 _("Postpone this message?"))) == M_NO) {
1085 while (idxlen-- > 0) {
1086 /* avoid freeing other attachments */
1087 idx[idxlen]->content->next = NULL;
1088 idx[idxlen]->content->parts = NULL;
1089 if (idx[idxlen]->unowned)
1090 idx[idxlen]->content->unlink = 0;
1091 body_list_wipe(&idx[idxlen]->content);
1092 p_delete(&idx[idxlen]->tree);
1093 p_delete(&idx[idxlen]);
1105 /* fall through to postpone! */
1107 case OP_COMPOSE_POSTPONE_MESSAGE:
1109 if (check_attachments (idx, idxlen) != 0) {
1110 menu->redraw = REDRAW_FULL;
1118 case OP_COMPOSE_WRITE_MESSAGE:
1121 m_strcpy(fname, sizeof(fname), NONULL(Context->path));
1122 mutt_pretty_mailbox (fname);
1125 msg->content = idx[0]->content;
1126 if (mutt_enter_fname
1127 (_("Write message to mailbox"), fname, sizeof (fname),
1128 &menu->redraw, 1) != -1 && fname[0]) {
1129 mutt_message (_("Writing message to %s ..."), fname);
1130 mutt_expand_path (fname, sizeof (fname));
1132 if (msg->content->next)
1133 msg->content = mutt_make_multipart (msg->content);
1135 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1136 msg->content = mutt_remove_multipart (msg->content);
1138 mutt_message _("Message written.");
1142 case OP_COMPOSE_PGP_MENU:
1143 if (msg->security & APPLICATION_SMIME) {
1144 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1146 mutt_clear_error ();
1151 msg->security = crypt_send_menu (msg, &menu->redraw, 0);
1152 redraw_crypt_lines (msg);
1153 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1156 case OP_COMPOSE_SMIME_MENU:
1157 if (msg->security & APPLICATION_PGP) {
1158 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1160 mutt_clear_error ();
1165 msg->security = crypt_send_menu(msg, &menu->redraw, 1);
1166 redraw_crypt_lines (msg);
1167 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1171 /* Draw formated compose status line */
1172 if (menu->redraw & REDRAW_STATUS) {
1173 compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1174 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1175 SETCOLOR (MT_COLOR_STATUS);
1176 wmove (stdscr, option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
1177 wprintw (stdscr, "%-*.*s", COLS-SW, COLS-SW, buf);
1178 SETCOLOR (MT_COLOR_NORMAL);
1179 menu->redraw &= ~REDRAW_STATUS;
1183 mutt_menuDestroy (&menu);
1186 msg->content = idx[0]->content;
1187 for (i = 0; i < idxlen; i++) {
1188 idx[i]->content->aptr = NULL;
1192 msg->content = NULL;