2 * Copyright (C) 1996-2000,2002,2007 Michael R. Elkins <me@mutt.org>
3 * Copyright (C) 2004 g10 Code GmbH
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "mutt_curses.h"
26 #include "mutt_idna.h"
27 #include "mutt_menu.h"
47 static const char* There_are_no_attachments = N_("There are no attachments.");
49 #define CHECK_COUNT if (idxlen == 0) { mutt_error _(There_are_no_attachments); break; }
70 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
73 #define HDR_XOFFSET 10
74 #define TITLE_FMT "%10s" /* Used for Prompts, which are ASCII */
75 #define W (COLS - HDR_XOFFSET)
77 static char *Prompts[] =
88 static struct mapping_t ComposeHelp[] = {
89 { N_("Send"), OP_COMPOSE_SEND_MESSAGE },
90 { N_("Abort"), OP_EXIT },
91 { "To", OP_COMPOSE_EDIT_TO },
92 { "CC", OP_COMPOSE_EDIT_CC },
93 { "Subj", OP_COMPOSE_EDIT_SUBJECT },
94 { N_("Attach file"), OP_COMPOSE_ATTACH_FILE },
95 { N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION },
96 { N_("Help"), OP_HELP },
100 static void snd_entry (char *b, size_t blen, MUTTMENU *menu, int num)
102 mutt_FormatString (b, blen, 0, NONULL (AttachFormat), mutt_attach_fmt,
103 (unsigned long)(((ATTACHPTR **) menu->data)[num]),
104 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
109 #include "mutt_crypt.h"
111 static void redraw_crypt_lines (HEADER *msg)
115 mvaddstr (HDR_CRYPT, 0, "Security: ");
117 if ((WithCrypto & (APPLICATION_PGP | APPLICATION_SMIME)) == 0)
119 addstr(_("Not supported"));
123 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
124 addstr (_("Sign, Encrypt"));
125 else if (msg->security & ENCRYPT)
126 addstr (_("Encrypt"));
127 else if (msg->security & SIGN)
132 if ((msg->security & (ENCRYPT | SIGN)))
134 if ((WithCrypto & APPLICATION_PGP) && (msg->security & APPLICATION_PGP))
136 if ((msg->security & INLINE))
137 addstr (_(" (inline PGP)"));
139 addstr (_(" (PGP/MIME)"));
141 else if ((WithCrypto & APPLICATION_SMIME) &&
142 (msg->security & APPLICATION_SMIME))
143 addstr (_(" (S/MIME)"));
147 move (HDR_CRYPTINFO, 0);
150 if ((WithCrypto & APPLICATION_PGP)
151 && msg->security & APPLICATION_PGP && msg->security & SIGN)
152 printw ("%s%s", _(" sign as: "), PgpSignAs ? PgpSignAs : _("<default>"));
154 if ((WithCrypto & APPLICATION_SMIME)
155 && msg->security & APPLICATION_SMIME && msg->security & SIGN) {
156 printw ("%s%s", _(" sign as: "), SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
159 if ((WithCrypto & APPLICATION_SMIME)
160 && (msg->security & APPLICATION_SMIME)
161 && (msg->security & ENCRYPT)
164 mvprintw (HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "),
165 NONULL(SmimeCryptAlg));
173 static void redraw_mix_line (LIST *chain)
178 mvaddstr (HDR_MIX, 0, " Mix: ");
182 addstr ("<no chain defined>");
187 for (c = 12; chain; chain = chain->next)
190 if (t && t[0] == '0' && t[1] == '\0')
193 if (c + mutt_strlen (t) + 2 >= COLS)
200 c += mutt_strlen (t) + 2;
203 #endif /* MIXMASTER */
206 check_attachments(ATTACHPTR **idx, short idxlen)
210 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
212 for (i = 0; i < idxlen; i++)
214 strfcpy(pretty, idx[i]->content->filename, sizeof(pretty));
215 if(stat(idx[i]->content->filename, &st) != 0)
217 mutt_pretty_mailbox(pretty, sizeof (pretty));
218 mutt_error(_("%s [#%d] no longer exists!"),
223 if(idx[i]->content->stamp < st.st_mtime)
225 mutt_pretty_mailbox(pretty, sizeof (pretty));
226 snprintf(msg, sizeof(msg), _("%s [#%d] modified. Update encoding?"),
229 if((r = mutt_yesorno(msg, M_YES)) == M_YES)
230 mutt_update_encoding(idx[i]->content);
239 static void draw_envelope_addr (int line, ADDRESS *addr)
241 char buf[LONG_STRING];
244 rfc822_write_address (buf, sizeof (buf), addr, 1);
245 mvprintw (line, 0, TITLE_FMT, Prompts[line - 1]);
246 mutt_paddstr (W, buf);
249 static void draw_envelope (HEADER *msg, char *fcc)
251 draw_envelope_addr (HDR_FROM, msg->env->from);
252 draw_envelope_addr (HDR_TO, msg->env->to);
253 draw_envelope_addr (HDR_CC, msg->env->cc);
254 draw_envelope_addr (HDR_BCC, msg->env->bcc);
255 mvprintw (HDR_SUBJECT, 0, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
256 mutt_paddstr (W, NONULL (msg->env->subject));
257 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
258 mvprintw (HDR_FCC, 0, TITLE_FMT, Prompts[HDR_FCC - 1]);
259 mutt_paddstr (W, fcc);
262 redraw_crypt_lines (msg);
265 redraw_mix_line (msg->chain);
268 SETCOLOR (MT_COLOR_STATUS);
269 mvaddstr (HDR_ATTACH - 1, 0, _("-- Attachments"));
270 BKGDSET (MT_COLOR_STATUS);
273 BKGDSET (MT_COLOR_NORMAL);
274 SETCOLOR (MT_COLOR_NORMAL);
277 static int edit_address_list (int line, ADDRESS **addr)
279 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
282 mutt_addrlist_to_local (*addr);
283 rfc822_write_address (buf, sizeof (buf), *addr, 0);
284 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0)
286 rfc822_free_address (addr);
287 *addr = mutt_parse_adrlist (*addr, buf);
288 *addr = mutt_expand_aliases (*addr);
291 if (option (OPTNEEDREDRAW))
293 unset_option (OPTNEEDREDRAW);
294 return (REDRAW_FULL);
297 if (mutt_addrlist_to_idna (*addr, &err) != 0)
299 mutt_error (_("Warning: '%s' is a bad IDN."), err);
304 /* redraw the expanded list so the user can see the result */
306 rfc822_write_address (buf, sizeof (buf), *addr, 1);
307 move (line, HDR_XOFFSET);
308 mutt_paddstr (W, buf);
313 static int delete_attachment (MUTTMENU *menu, short *idxlen, int x)
315 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
318 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
320 if (x == 0 && menu->max == 1)
322 mutt_error _("You may not delete the only attachment.");
323 idx[x]->content->tagged = 0;
327 for (y = 0; y < *idxlen; y++)
329 if (idx[y]->content->next == idx[x]->content)
331 idx[y]->content->next = idx[x]->content->next;
336 idx[x]->content->next = NULL;
337 idx[x]->content->parts = NULL;
338 mutt_free_body (&(idx[x]->content));
339 FREE (&idx[x]->tree);
341 for (; x < *idxlen - 1; x++)
343 menu->max = --(*idxlen);
348 static void update_idx (MUTTMENU *menu, ATTACHPTR **idx, short idxlen)
350 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen-1]->level : 0;
352 idx[idxlen - 1]->content->next = idx[idxlen]->content;
353 idx[idxlen]->content->aptr = idx[idxlen];
354 menu->current = idxlen++;
355 mutt_update_tree (idx, idxlen);
362 * cum_attachs_size: Cumulative Attachments Size
364 * Returns the total number of bytes used by the attachments in the
365 * attachment list _after_ content-transfer-encodings have been
370 static unsigned long cum_attachs_size (MUTTMENU *menu)
374 ATTACHPTR **idx = menu->data;
378 for (i = 0, s = 0; i < menu->max; i++)
383 b->content = mutt_get_content_info (b->filename, b);
385 if ((info = b->content))
389 case ENCQUOTEDPRINTABLE:
390 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
393 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
396 s += info->lobin + info->hibin + info->ascii + info->crlf;
405 /* prototype for use below */
406 static void compose_status_line (char *buf, size_t buflen, size_t col, MUTTMENU *menu,
410 * compose_format_str()
412 * %a = total number of attachments
413 * %h = hostname [option]
414 * %l = approx. length of current message (in bytes)
417 * This function is similar to status_format_str(). Look at that function for
418 * help when modifying this function.
422 compose_format_str (char *buf, size_t buflen, size_t col, char op, const char *src,
423 const char *prefix, const char *ifstring,
424 const char *elsestring,
425 unsigned long data, format_flag flags)
427 char fmt[SHORT_STRING], tmp[SHORT_STRING];
428 int optional = (flags & M_FORMAT_OPTIONAL);
429 MUTTMENU *menu = (MUTTMENU *) data;
434 case 'a': /* total number of attachments */
435 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
436 snprintf (buf, buflen, fmt, menu->max);
439 case 'h': /* hostname */
440 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
441 snprintf (buf, buflen, fmt, NONULL(Hostname));
444 case 'l': /* approx length of current message in bytes */
445 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
446 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size(menu) : 0);
447 snprintf (buf, buflen, fmt, tmp);
451 snprintf (fmt, sizeof (fmt), "Mutt %%s");
452 snprintf (buf, buflen, fmt, MUTT_VERSION);
460 snprintf (buf, buflen, "%%%s%c", prefix, op);
465 compose_status_line (buf, buflen, col, menu, ifstring);
466 else if (flags & M_FORMAT_OPTIONAL)
467 compose_status_line (buf, buflen, col, menu, elsestring);
472 static void compose_status_line (char *buf, size_t buflen, size_t col, MUTTMENU *menu,
475 mutt_FormatString (buf, buflen, col, p, compose_format_str,
476 (unsigned long) menu, 0);
482 * 1 message should be postponed
486 int mutt_compose_menu (HEADER *msg, /* structure for new message */
487 char *fcc, /* where to save a copy of the message */
489 HEADER *cur) /* current message */
491 char helpstr[LONG_STRING];
492 char buf[LONG_STRING];
493 char fname[_POSIX_PATH_MAX];
495 ATTACHPTR **idx = NULL;
499 int r = -1; /* return value */
502 int fccSet = 0; /* has the user edited the Fcc: field ? */
503 CONTEXT *ctx = NULL, *this = NULL;
504 /* Sort, SortAux could be changed in mutt_index_menu() */
505 int oldSort, oldSortAux;
508 mutt_attach_init (msg->content);
509 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
511 menu = mutt_new_menu (MENU_COMPOSE);
512 menu->offset = HDR_ATTACH;
514 menu->make_entry = snd_entry;
515 menu->tag = mutt_tag_attach;
517 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeHelp);
521 switch (op = mutt_menuLoop (menu))
524 draw_envelope (msg, fcc);
525 menu->offset = HDR_ATTACH;
526 menu->pagelen = LINES - HDR_ATTACH - 2;
528 case OP_COMPOSE_EDIT_FROM:
529 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
530 mutt_message_hook (NULL, msg, M_SEND2HOOK);
532 case OP_COMPOSE_EDIT_TO:
533 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
534 mutt_message_hook (NULL, msg, M_SEND2HOOK);
536 case OP_COMPOSE_EDIT_BCC:
537 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
538 mutt_message_hook (NULL, msg, M_SEND2HOOK);
540 case OP_COMPOSE_EDIT_CC:
541 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
542 mutt_message_hook (NULL, msg, M_SEND2HOOK);
544 case OP_COMPOSE_EDIT_SUBJECT:
545 if (msg->env->subject)
546 strfcpy (buf, msg->env->subject, sizeof (buf));
549 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
551 mutt_str_replace (&msg->env->subject, buf);
552 move (HDR_SUBJECT, HDR_XOFFSET);
554 if (msg->env->subject)
555 mutt_paddstr (W, msg->env->subject);
557 mutt_message_hook (NULL, msg, M_SEND2HOOK);
559 case OP_COMPOSE_EDIT_REPLY_TO:
560 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
561 mutt_message_hook (NULL, msg, M_SEND2HOOK);
563 case OP_COMPOSE_EDIT_FCC:
564 strfcpy (buf, fcc, sizeof (buf));
565 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0)
567 strfcpy (fcc, buf, fcclen);
568 mutt_pretty_mailbox (fcc, fcclen);
569 move (HDR_FCC, HDR_XOFFSET);
570 mutt_paddstr (W, fcc);
573 MAYBE_REDRAW (menu->redraw);
574 mutt_message_hook (NULL, msg, M_SEND2HOOK);
576 case OP_COMPOSE_EDIT_MESSAGE:
577 if (Editor && (mutt_strcmp ("builtin", Editor) != 0) && !option (OPTEDITHDRS))
579 mutt_edit_file (Editor, msg->content->filename);
580 mutt_update_encoding (msg->content);
581 menu->redraw = REDRAW_FULL;
582 mutt_message_hook (NULL, msg, M_SEND2HOOK);
586 case OP_COMPOSE_EDIT_HEADERS:
587 if (mutt_strcmp ("builtin", Editor) != 0 &&
588 (op == OP_COMPOSE_EDIT_HEADERS ||
589 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS))))
591 char *tag = NULL, *err = NULL;
592 mutt_env_to_local (msg->env);
593 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
595 if (mutt_env_to_idna (msg->env, &tag, &err))
597 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
603 /* this is grouped with OP_COMPOSE_EDIT_HEADERS because the
604 attachment list could change if the user invokes ~v to edit
605 the message with headers, in which we need to execute the
606 code below to regenerate the index array */
607 mutt_builtin_editor (msg->content->filename, msg, cur);
609 mutt_update_encoding (msg->content);
611 /* attachments may have been added */
612 if (idxlen && idx[idxlen - 1]->content->next)
614 for (i = 0; i < idxlen; i++)
617 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
622 menu->redraw = REDRAW_FULL;
623 mutt_message_hook (NULL, msg, M_SEND2HOOK);
628 case OP_COMPOSE_ATTACH_KEY:
629 if (!(WithCrypto & APPLICATION_PGP))
631 if (idxlen == idxmax)
633 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
637 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
638 if ((idx[idxlen]->content = crypt_pgp_make_key_attachment(NULL)) != NULL)
640 update_idx (menu, idx, idxlen++);
641 menu->redraw |= REDRAW_INDEX;
646 menu->redraw |= REDRAW_STATUS;
648 if (option(OPTNEEDREDRAW))
650 menu->redraw = REDRAW_FULL;
651 unset_option(OPTNEEDREDRAW);
654 mutt_message_hook (NULL, msg, M_SEND2HOOK);
658 case OP_COMPOSE_ATTACH_FILE:
660 char *prompt, **files;
664 prompt = _("Attach file");
668 if (_mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files, &numfiles) == -1 ||
672 if (idxlen + numfiles >= idxmax)
674 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles));
680 mutt_message _("Attaching selected files...");
681 for (i = 0; i < numfiles; i++)
683 char *att = files[i];
684 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
685 idx[idxlen]->unowned = 1;
686 idx[idxlen]->content = mutt_make_file_attach (att);
687 if (idx[idxlen]->content != NULL)
688 update_idx (menu, idx, idxlen++);
692 mutt_error (_("Unable to attach %s!"), att);
698 if (!error) mutt_clear_error ();
700 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
702 mutt_message_hook (NULL, msg, M_SEND2HOOK);
705 case OP_COMPOSE_ATTACH_MESSAGE:
711 prompt = _("Open mailbox to attach message from");
715 strfcpy (fname, NONULL (Context->path), sizeof (fname));
716 mutt_pretty_mailbox (fname, sizeof (fname));
719 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1) == -1 || !fname[0])
722 mutt_expand_path (fname, sizeof (fname));
724 if (!mx_is_imap (fname))
727 if (!mx_is_pop (fname))
729 /* check to make sure the file exists and is readable */
730 if (access (fname, R_OK) == -1)
736 menu->redraw = REDRAW_FULL;
738 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
747 mx_close_mailbox (ctx, NULL);
749 mutt_error _("No messages in that folder.");
753 this = Context; /* remember current folder and sort methods*/
754 oldSort = Sort; oldSortAux = SortAux;
757 set_option(OPTATTACHMSG);
758 mutt_message _("Tag the messages you want to attach!");
759 close = mutt_index_menu ();
760 unset_option(OPTATTACHMSG);
764 /* go back to the folder we started from */
766 /* Restore old $sort and $sort_aux */
768 SortAux = oldSortAux;
769 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
773 if (idxlen + Context->tagged >= idxmax)
775 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + Context->tagged));
779 for (i = 0; i < Context->msgcount; i++)
781 h = Context->hdrs[i];
784 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
785 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
786 if (idx[idxlen]->content != NULL)
787 update_idx (menu, idx, idxlen++);
790 mutt_error _("Unable to attach!");
795 menu->redraw |= REDRAW_FULL;
797 if (close == OP_QUIT)
798 mx_close_mailbox (Context, NULL);
800 mx_fastclose_mailbox (Context);
803 /* go back to the folder we started from */
805 /* Restore old $sort and $sort_aux */
807 SortAux = oldSortAux;
809 mutt_message_hook (NULL, msg, M_SEND2HOOK);
814 if (idx[menu->current]->unowned)
815 idx[menu->current]->content->unlink = 0;
816 if (delete_attachment (menu, &idxlen, menu->current) == -1)
818 mutt_update_tree (idx, idxlen);
821 if (menu->current > idxlen - 1)
822 menu->current = idxlen - 1;
827 if (menu->current == 0)
828 msg->content = idx[0]->content;
830 menu->redraw |= REDRAW_STATUS;
831 mutt_message_hook (NULL, msg, M_SEND2HOOK);
834 #define CURRENT idx[menu->current]->content
836 case OP_COMPOSE_TOGGLE_RECODE:
839 if (!mutt_is_text_part (CURRENT))
841 mutt_error (_("Recoding only affects text attachments."));
844 CURRENT->noconv = !CURRENT->noconv;
846 mutt_message (_("The current attachment won't be converted."));
848 mutt_message (_("The current attachment will be converted."));
849 menu->redraw = REDRAW_CURRENT;
850 mutt_message_hook (NULL, msg, M_SEND2HOOK);
855 case OP_COMPOSE_EDIT_DESCRIPTION:
858 idx[menu->current]->content->description ?
859 idx[menu->current]->content->description : "",
861 /* header names should not be translated */
862 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0)
864 mutt_str_replace (&idx[menu->current]->content->description, buf);
865 menu->redraw = REDRAW_CURRENT;
867 mutt_message_hook (NULL, msg, M_SEND2HOOK);
870 case OP_COMPOSE_UPDATE_ENCODING:
875 for (top = msg->content; top; top = top->next)
878 mutt_update_encoding (top);
880 menu->redraw = REDRAW_FULL;
884 mutt_update_encoding(idx[menu->current]->content);
885 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
887 mutt_message_hook (NULL, msg, M_SEND2HOOK);
890 case OP_COMPOSE_TOGGLE_DISPOSITION:
891 /* toggle the content-disposition between inline/attachment */
892 idx[menu->current]->content->disposition = (idx[menu->current]->content->disposition == DISPINLINE) ? DISPATTACH : DISPINLINE;
893 menu->redraw = REDRAW_CURRENT;
899 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
901 /* this may have been a change to text/something */
902 mutt_update_encoding (idx[menu->current]->content);
904 menu->redraw = REDRAW_CURRENT;
906 mutt_message_hook (NULL, msg, M_SEND2HOOK);
909 case OP_COMPOSE_EDIT_ENCODING:
911 strfcpy (buf, ENCODING (idx[menu->current]->content->encoding),
913 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
914 sizeof (buf), 0) == 0 && buf[0])
916 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED)
918 idx[menu->current]->content->encoding = i;
919 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
923 mutt_error _("Invalid encoding.");
925 mutt_message_hook (NULL, msg, M_SEND2HOOK);
928 case OP_COMPOSE_SEND_MESSAGE:
930 /* Note: We don't invoke send2-hook here, since we want to leave
931 * users an opportunity to change settings from the ":" prompt.
934 if(check_attachments(idx, idxlen) != 0)
936 menu->redraw = REDRAW_FULL;
942 if (msg->chain && mix_check_message (msg) != 0)
948 if ((i = query_quadoption (OPT_COPY,
949 _("Save a copy of this message?"))) == -1)
959 case OP_COMPOSE_EDIT_FILE:
961 mutt_edit_file (NONULL(Editor), idx[menu->current]->content->filename);
962 mutt_update_encoding (idx[menu->current]->content);
963 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
964 mutt_message_hook (NULL, msg, M_SEND2HOOK);
967 case OP_COMPOSE_TOGGLE_UNLINK:
969 idx[menu->current]->content->unlink = !idx[menu->current]->content->unlink;
972 /* OPTRESOLVE is otherwise ignored on this menu.
976 if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
979 menu->redraw = REDRAW_INDEX;
980 /* No send2hook since this doesn't change the message. */
983 case OP_COMPOSE_GET_ATTACHMENT:
988 for(top = msg->content; top; top = top->next)
991 mutt_get_tmp_attachment(top);
993 menu->redraw = REDRAW_FULL;
995 else if (mutt_get_tmp_attachment(idx[menu->current]->content) == 0)
996 menu->redraw = REDRAW_CURRENT;
998 /* No send2hook since this doesn't change the message. */
1001 case OP_COMPOSE_RENAME_FILE:
1003 strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname));
1004 mutt_pretty_mailbox (fname, sizeof (fname));
1005 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1008 if (stat(idx[menu->current]->content->filename, &st) == -1)
1010 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1014 mutt_expand_path (fname, sizeof (fname));
1015 if(mutt_rename_file (idx[menu->current]->content->filename, fname))
1018 mutt_str_replace (&idx[menu->current]->content->filename, fname);
1019 menu->redraw = REDRAW_CURRENT;
1021 if(idx[menu->current]->content->stamp >= st.st_mtime)
1022 mutt_stamp_attachment(idx[menu->current]->content);
1025 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1028 case OP_COMPOSE_NEW_MIME:
1035 CLEARLINE (LINES-1);
1037 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1040 mutt_expand_path (fname, sizeof (fname));
1042 /* Call to lookup_mime_type () ? maybe later */
1044 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1048 if (!(p = strchr (type, '/')))
1050 mutt_error _("Content-Type is of the form base/sub");
1054 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER)
1056 mutt_error (_("Unknown Content-Type %s"), type);
1059 if (idxlen == idxmax)
1061 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
1065 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
1066 /* Touch the file */
1067 if (!(fp = safe_fopen (fname, "w")))
1069 mutt_error (_("Can't create file %s"), fname);
1070 FREE (&idx[idxlen]);
1075 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL)
1077 mutt_error _("What we have here is a failure to make an attachment");
1080 update_idx (menu, idx, idxlen++);
1082 idx[menu->current]->content->type = itype;
1083 mutt_str_replace (&idx[menu->current]->content->subtype, p);
1084 idx[menu->current]->content->unlink = 1;
1085 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1087 if (mutt_compose_attachment (idx[menu->current]->content))
1089 mutt_update_encoding (idx[menu->current]->content);
1090 menu->redraw = REDRAW_FULL;
1093 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1096 case OP_COMPOSE_EDIT_MIME:
1098 if (mutt_edit_attachment (idx[menu->current]->content))
1100 mutt_update_encoding (idx[menu->current]->content);
1101 menu->redraw = REDRAW_FULL;
1103 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1106 case OP_VIEW_ATTACH:
1107 case OP_DISPLAY_HEADERS:
1109 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen, NULL, 0);
1110 menu->redraw = REDRAW_FULL;
1111 /* no send2hook, since this doesn't modify the message */
1116 mutt_save_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, NULL, menu);
1117 MAYBE_REDRAW (menu->redraw);
1118 /* no send2hook, since this doesn't modify the message */
1123 mutt_print_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content);
1124 /* no send2hook, since this doesn't modify the message */
1130 mutt_pipe_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, op == OP_FILTER);
1131 if (op == OP_FILTER) /* cte might have changed */
1132 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1133 menu->redraw |= REDRAW_STATUS;
1134 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1138 if ((i = query_quadoption (OPT_POSTPONE, _("Postpone this message?"))) == M_NO)
1140 while (idxlen-- > 0)
1142 /* avoid freeing other attachments */
1143 idx[idxlen]->content->next = NULL;
1144 idx[idxlen]->content->parts = NULL;
1145 if (idx[idxlen]->unowned)
1146 idx[idxlen]->content->unlink = 0;
1147 mutt_free_body (&idx[idxlen]->content);
1148 FREE (&idx[idxlen]->tree);
1149 FREE (&idx[idxlen]);
1161 /* fall through to postpone! */
1163 case OP_COMPOSE_POSTPONE_MESSAGE:
1165 if(check_attachments(idx, idxlen) != 0)
1167 menu->redraw = REDRAW_FULL;
1175 case OP_COMPOSE_ISPELL:
1177 snprintf (buf, sizeof (buf), "%s -x %s", NONULL(Ispell), msg->content->filename);
1178 if (mutt_system (buf) == -1)
1179 mutt_error (_("Error running \"%s\"!"), buf);
1182 mutt_update_encoding (msg->content);
1183 menu->redraw |= REDRAW_STATUS;
1187 case OP_COMPOSE_WRITE_MESSAGE:
1192 strfcpy (fname, NONULL (Context->path), sizeof (fname));
1193 mutt_pretty_mailbox (fname, sizeof (fname));
1196 msg->content = idx[0]->content;
1197 if (mutt_enter_fname (_("Write message to mailbox"), fname, sizeof (fname),
1198 &menu->redraw, 1) != -1 && fname[0])
1200 mutt_message (_("Writing message to %s ..."), fname);
1201 mutt_expand_path (fname, sizeof (fname));
1203 if (msg->content->next)
1204 msg->content = mutt_make_multipart (msg->content);
1206 if (mutt_write_fcc (fname, msg, NULL, 0, NULL) < 0)
1207 msg->content = mutt_remove_multipart (msg->content);
1209 mutt_message _("Message written.");
1215 case OP_COMPOSE_PGP_MENU:
1216 if (!(WithCrypto & APPLICATION_PGP))
1218 if ((WithCrypto & APPLICATION_SMIME)
1219 && msg->security & APPLICATION_SMIME)
1221 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1224 mutt_clear_error ();
1229 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1230 redraw_crypt_lines (msg);
1231 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1235 case OP_FORGET_PASSPHRASE:
1236 crypt_forget_passphrase ();
1240 case OP_COMPOSE_SMIME_MENU:
1241 if (!(WithCrypto & APPLICATION_SMIME))
1244 if ((WithCrypto & APPLICATION_PGP)
1245 && msg->security & APPLICATION_PGP)
1247 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1250 mutt_clear_error ();
1255 msg->security = crypt_smime_send_menu(msg, &menu->redraw);
1256 redraw_crypt_lines (msg);
1257 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1262 case OP_COMPOSE_MIX:
1264 mix_make_chain (&msg->chain, &menu->redraw);
1265 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1271 /* Draw formated compose status line */
1272 if (menu->redraw & REDRAW_STATUS)
1274 compose_status_line (buf, sizeof (buf), 0, menu, NONULL(ComposeFormat));
1275 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
1276 SETCOLOR (MT_COLOR_STATUS);
1277 BKGDSET (MT_COLOR_STATUS);
1278 mutt_paddstr (COLS, buf);
1279 SETCOLOR (MT_COLOR_NORMAL);
1280 BKGDSET (MT_COLOR_NORMAL);
1281 menu->redraw &= ~REDRAW_STATUS;
1285 mutt_menuDestroy (&menu);
1289 msg->content = idx[0]->content;
1290 for (i = 0; i < idxlen; i++)
1292 idx[i]->content->aptr = NULL;
1297 msg->content = NULL;