Andreas Krennmair:
[apps/madmutt.git] / compose.c
1 /*
2  * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
3  * Copyright (C) 2004 g10 Code GmbH
4  * 
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.
9  * 
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.
14  * 
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
18  */
19
20 #if HAVE_CONFIG_H
21 # include "config.h"
22 #endif
23
24 #include "mutt.h"
25 #include "mutt_curses.h"
26 #include "mutt_idna.h"
27 #include "mutt_menu.h"
28 #include "rfc1524.h"
29 #include "mime.h"
30 #include "attach.h"
31 #include "mapping.h"
32 #include "mailbox.h"
33 #include "sort.h"
34 #include "charset.h"
35 #include "mx.h"
36
37 #ifdef MIXMASTER
38 #include "remailer.h"
39 #endif
40
41 #ifdef USE_NNTP
42 #include "nntp.h"
43 #endif
44
45 #include <errno.h>
46 #include <string.h>
47 #include <sys/stat.h>
48 #include <sys/wait.h>
49 #include <unistd.h>
50 #include <stdlib.h>
51
52 static const char *There_are_no_attachments = N_("There are no attachments.");
53
54 #define CHECK_COUNT if (idxlen == 0) { mutt_error _(There_are_no_attachments); break; }
55
56
57
58 enum {
59   HDR_FROM = 1,
60   HDR_TO,
61   HDR_CC,
62   HDR_BCC,
63   HDR_SUBJECT,
64   HDR_REPLYTO,
65   HDR_FCC,
66
67 #ifdef MIXMASTER
68   HDR_MIX,
69 #endif
70
71   HDR_CRYPT,
72   HDR_CRYPTINFO,
73
74 #ifdef USE_NNTP
75   HDR_NEWSGROUPS,
76   HDR_FOLLOWUPTO,
77   HDR_XCOMMENTTO,
78 #endif
79
80 #ifndef USE_NNTP
81   HDR_ATTACH = (HDR_FCC + 5)    /* where to start printing the attachments */
82 #else
83   HDR_ATTACH = (HDR_FCC + 7)
84 #endif
85 };
86
87 #define HDR_XOFFSET 14
88 #define TITLE_FMT "%14s"        /* Used for Prompts, which are ASCII */
89 #define W (COLS - HDR_XOFFSET - SidebarWidth)
90
91 static char *Prompts[] = {
92   "From: ",
93   "To: ",
94   "Cc: ",
95   "Bcc: ",
96   "Subject: ",
97   "Reply-To: ",
98   "Fcc: "
99 #ifdef USE_NNTP
100 #ifdef MIXMASTER
101     , ""
102 #endif
103     , "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: "
104 #endif
105 };
106
107 static struct mapping_t ComposeHelp[] = {
108   {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
109   {N_("Abort"), OP_EXIT},
110   {"To", OP_COMPOSE_EDIT_TO},
111   {"CC", OP_COMPOSE_EDIT_CC},
112   {"Subj", OP_COMPOSE_EDIT_SUBJECT},
113   {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
114   {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
115   {N_("Help"), OP_HELP},
116   {NULL}
117 };
118
119 #ifdef USE_NNTP
120 static struct mapping_t ComposeNewsHelp[] = {
121   {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
122   {N_("Abort"), OP_EXIT},
123   {"Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS},
124   {"Subj", OP_COMPOSE_EDIT_SUBJECT},
125   {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
126   {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
127   {N_("Help"), OP_HELP},
128   {NULL}
129 };
130 #endif
131
132 static void snd_entry (char *b, size_t blen, MUTTMENU * menu, int num)
133 {
134   mutt_FormatString (b, blen, NONULL (AttachFormat), mutt_attach_fmt,
135                      (unsigned long) (((ATTACHPTR **) menu->data)[num]),
136                      M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
137 }
138
139
140
141 #include "mutt_crypt.h"
142
143 static void redraw_crypt_lines (HEADER * msg)
144 {
145   int off = 0;
146
147   if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME)) {
148     if (!msg->security)
149       mvaddstr (HDR_CRYPT, SidebarWidth, "    Security: ");
150     else if (msg->security & APPLICATION_SMIME)
151       mvaddstr (HDR_CRYPT, SidebarWidth, "      S/MIME: ");
152     else if (msg->security & APPLICATION_PGP)
153       mvaddstr (HDR_CRYPT, SidebarWidth, "         PGP: ");
154   }
155   else if ((WithCrypto & APPLICATION_SMIME))
156     mvaddstr (HDR_CRYPT, SidebarWidth, "      S/MIME: ");
157   else if ((WithCrypto & APPLICATION_PGP))
158     mvaddstr (HDR_CRYPT, SidebarWidth, "         PGP: ");
159   else
160     return;
161
162   if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
163     addstr (_("Sign, Encrypt"));
164   else if (msg->security & ENCRYPT)
165     addstr (_("Encrypt"));
166   else if (msg->security & SIGN)
167     addstr (_("Sign"));
168   else
169     addstr (_("Clear"));
170
171   if ((WithCrypto & APPLICATION_PGP))
172     if ((msg->security & APPLICATION_PGP)
173         && (msg->security & (ENCRYPT | SIGN))) {
174       if ((msg->security & INLINE))
175         addstr (_(" (inline)"));
176       else
177         addstr (_(" (PGP/MIME)"));
178     }
179   clrtoeol ();
180
181   move (HDR_CRYPTINFO, SidebarWidth);
182   clrtoeol ();
183   if ((WithCrypto & APPLICATION_PGP)
184       && msg->security & APPLICATION_PGP && msg->security & SIGN)
185     printw ("%s%s", _("     sign as: "),
186             PgpSignAs ? PgpSignAs : _("<default>"));
187
188   if ((WithCrypto & APPLICATION_SMIME)
189       && msg->security & APPLICATION_SMIME && msg->security & SIGN) {
190     printw ("%s%s", _("     sign as: "),
191             SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
192   }
193
194   if ((WithCrypto & APPLICATION_SMIME)
195       && (msg->security & APPLICATION_SMIME)
196       && (msg->security & ENCRYPT)
197       && SmimeCryptAlg && *SmimeCryptAlg) {
198     mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "),
199               NONULL (SmimeCryptAlg));
200     off = 20;
201   }
202 }
203
204
205 #ifdef MIXMASTER
206
207 static void redraw_mix_line (LIST * chain)
208 {
209   int c;
210   char *t;
211
212   mvaddstr (HDR_MIX, SidebarWidth, "         Mix: ");
213
214   if (!chain) {
215     addstr ("<no chain defined>");
216     clrtoeol ();
217     return;
218   }
219
220   for (c = 12; chain; chain = chain->next) {
221     t = chain->data;
222     if (t && t[0] == '0' && t[1] == '\0')
223       t = "<random>";
224
225     if (c + mutt_strlen (t) + 2 >= COLS - SidebarWidth)
226       break;
227
228     addstr (NONULL (t));
229     if (chain->next)
230       addstr (", ");
231
232     c += mutt_strlen (t) + 2;
233   }
234 }
235 #endif /* MIXMASTER */
236
237 static int check_attachments (ATTACHPTR ** idx, short idxlen)
238 {
239   int i, r;
240   struct stat st;
241   char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
242
243   for (i = 0; i < idxlen; i++) {
244     strfcpy (pretty, idx[i]->content->filename, sizeof (pretty));
245     if (stat (idx[i]->content->filename, &st) != 0) {
246       mutt_pretty_mailbox (pretty);
247       mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
248       return -1;
249     }
250
251     if (idx[i]->content->stamp < st.st_mtime) {
252       mutt_pretty_mailbox (pretty);
253       snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
254                 pretty, i + 1);
255
256       if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
257         mutt_update_encoding (idx[i]->content);
258       else if (r == -1)
259         return -1;
260     }
261   }
262
263   return 0;
264 }
265
266 static void draw_envelope_addr (int line, ADDRESS * addr)
267 {
268   char buf[STRING];
269
270   buf[0] = 0;
271   rfc822_write_address (buf, sizeof (buf), addr, 1);
272   mvprintw (line, SidebarWidth, TITLE_FMT, Prompts[line - 1]);
273   mutt_paddstr (W, buf);
274 }
275
276 static void draw_envelope (HEADER * msg, char *fcc)
277 {
278   draw_envelope_addr (HDR_FROM, msg->env->from);
279 #ifdef USE_NNTP
280   if (!option (OPTNEWSSEND)) {
281 #endif
282     draw_envelope_addr (HDR_TO, msg->env->to);
283     draw_envelope_addr (HDR_CC, msg->env->cc);
284     draw_envelope_addr (HDR_BCC, msg->env->bcc);
285 #ifdef USE_NNTP
286   }
287   else {
288     mvprintw (HDR_TO, SidebarWidth, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
289     mutt_paddstr (W, NONULL (msg->env->newsgroups));
290     mvprintw (HDR_CC, SidebarWidth, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
291     mutt_paddstr (W, NONULL (msg->env->followup_to));
292     if (option (OPTXCOMMENTTO)) {
293       mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]);
294       mutt_paddstr (W, NONULL (msg->env->x_comment_to));
295     }
296   }
297 #endif
298   mvprintw (HDR_SUBJECT, SidebarWidth, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
299   mutt_paddstr (W, NONULL (msg->env->subject));
300   draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
301   mvprintw (HDR_FCC, SidebarWidth, TITLE_FMT, Prompts[HDR_FCC - 1]);
302   mutt_paddstr (W, fcc);
303
304   if (WithCrypto)
305     redraw_crypt_lines (msg);
306
307 #ifdef MIXMASTER
308   redraw_mix_line (msg->chain);
309 #endif
310
311   SETCOLOR (MT_COLOR_STATUS);
312   mvaddstr (HDR_ATTACH - 1, SidebarWidth, _("-- Attachments"));
313   BKGDSET (MT_COLOR_STATUS);
314   clrtoeol ();
315
316   BKGDSET (MT_COLOR_NORMAL);
317   SETCOLOR (MT_COLOR_NORMAL);
318 }
319
320 static int edit_address_list (int line, ADDRESS ** addr)
321 {
322   char buf[HUGE_STRING] = "";   /* needs to be large for alias expansion */
323   char *err = NULL;
324
325   mutt_addrlist_to_local (*addr);
326   rfc822_write_address (buf, sizeof (buf), *addr, 0);
327   if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
328     rfc822_free_address (addr);
329     *addr = mutt_parse_adrlist (*addr, buf);
330     *addr = mutt_expand_aliases (*addr);
331   }
332
333   if (option (OPTNEEDREDRAW)) {
334     unset_option (OPTNEEDREDRAW);
335     return (REDRAW_FULL);
336   }
337
338   if (mutt_addrlist_to_idna (*addr, &err) != 0) {
339     mutt_error (_("Warning: '%s' is a bad IDN."), err);
340     mutt_refresh ();
341     FREE (&err);
342   }
343
344   /* redraw the expanded list so the user can see the result */
345   buf[0] = 0;
346   rfc822_write_address (buf, sizeof (buf), *addr, 1);
347   move (line, HDR_XOFFSET + SidebarWidth);
348   mutt_paddstr (W, buf);
349
350   return 0;
351 }
352
353 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
354 {
355   ATTACHPTR **idx = (ATTACHPTR **) menu->data;
356   int y;
357
358   menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
359
360   if (x == 0 && menu->max == 1) {
361     mutt_error _("You may not delete the only attachment.");
362
363     idx[x]->content->tagged = 0;
364     return (-1);
365   }
366
367   for (y = 0; y < *idxlen; y++) {
368     if (idx[y]->content->next == idx[x]->content) {
369       idx[y]->content->next = idx[x]->content->next;
370       break;
371     }
372   }
373
374   idx[x]->content->next = NULL;
375   idx[x]->content->parts = NULL;
376   mutt_free_body (&(idx[x]->content));
377   FREE (&idx[x]->tree);
378   FREE (&idx[x]);
379   for (; x < *idxlen - 1; x++)
380     idx[x] = idx[x + 1];
381   menu->max = --(*idxlen);
382
383   return (0);
384 }
385
386 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
387 {
388   idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
389   if (idxlen)
390     idx[idxlen - 1]->content->next = idx[idxlen]->content;
391   idx[idxlen]->content->aptr = idx[idxlen];
392   menu->current = idxlen++;
393   mutt_update_tree (idx, idxlen);
394   menu->max = idxlen;
395   return;
396 }
397
398
399 /* 
400  * cum_attachs_size: Cumulative Attachments Size
401  *
402  * Returns the total number of bytes used by the attachments in the
403  * attachment list _after_ content-transfer-encodings have been
404  * applied.
405  * 
406  */
407
408 static unsigned long cum_attachs_size (MUTTMENU * menu)
409 {
410   size_t s;
411   unsigned short i;
412   ATTACHPTR **idx = menu->data;
413   CONTENT *info;
414   BODY *b;
415
416   for (i = 0, s = 0; i < menu->max; i++) {
417     b = idx[i]->content;
418
419     if (!b->content)
420       b->content = mutt_get_content_info (b->filename, b);
421
422     if ((info = b->content)) {
423       switch (b->encoding) {
424       case ENCQUOTEDPRINTABLE:
425         s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
426         break;
427       case ENCBASE64:
428         s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
429         break;
430       default:
431         s += info->lobin + info->hibin + info->ascii + info->crlf;
432         break;
433       }
434     }
435   }
436
437   return s;
438 }
439
440 /* prototype for use below */
441 static void compose_status_line (char *buf, size_t buflen, MUTTMENU * menu,
442                                  const char *p);
443
444 /*
445  * compose_format_str()
446  *
447  * %a = total number of attachments 
448  * %h = hostname  [option]
449  * %l = approx. length of current message (in bytes) 
450  * %v = Mutt version 
451  *
452  * This function is similar to status_format_str().  Look at that function for
453  * help when modifying this function.
454  */
455
456 static const char *compose_format_str (char *buf, size_t buflen, char op,
457                                        const char *src, const char *prefix,
458                                        const char *ifstring,
459                                        const char *elsestring,
460                                        unsigned long data, format_flag flags)
461 {
462   char fmt[SHORT_STRING], tmp[SHORT_STRING];
463   int optional = (flags & M_FORMAT_OPTIONAL);
464   MUTTMENU *menu = (MUTTMENU *) data;
465
466   *buf = 0;
467   switch (op) {
468   case 'a':                    /* total number of attachments */
469     snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
470     snprintf (buf, buflen, fmt, menu->max);
471     break;
472
473   case 'h':                    /* hostname */
474     snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
475     snprintf (buf, buflen, fmt, NONULL (Hostname));
476     break;
477
478   case 'l':                    /* approx length of current message in bytes */
479     snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
480     mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
481     snprintf (buf, buflen, fmt, tmp);
482     break;
483
484   case 'v':
485     snprintf (fmt, sizeof (fmt), "Mutt-ng %%s");
486     snprintf (buf, buflen, fmt, MUTT_VERSION);
487     break;
488
489   case 0:
490     *buf = 0;
491     return (src);
492
493   default:
494     snprintf (buf, buflen, "%%%s%c", prefix, op);
495     break;
496   }
497
498   if (optional)
499     compose_status_line (buf, buflen, menu, ifstring);
500   else if (flags & M_FORMAT_OPTIONAL)
501     compose_status_line (buf, buflen, menu, elsestring);
502
503   return (src);
504 }
505
506 static void compose_status_line (char *buf, size_t buflen, MUTTMENU * menu,
507                                  const char *p)
508 {
509   mutt_FormatString (buf, buflen, p, compose_format_str,
510                      (unsigned long) menu, 0);
511 }
512
513
514 /* return values:
515  *
516  * 1    message should be postponed
517  * 0    normal exit
518  * -1   abort message
519  */
520 int mutt_compose_menu (HEADER * msg,    /* structure for new message */
521                        char *fcc,       /* where to save a copy of the message */
522                        size_t fcclen, HEADER * cur)
523 {                               /* current message */
524   char helpstr[SHORT_STRING];
525   char buf[LONG_STRING];
526   char fname[_POSIX_PATH_MAX];
527   MUTTMENU *menu;
528   ATTACHPTR **idx = NULL;
529   short idxlen = 0;
530   short idxmax = 0;
531   int i, close = 0;
532   int r = -1;                   /* return value */
533   int op = 0;
534   int loop = 1;
535   int fccSet = 0;               /* has the user edited the Fcc: field ? */
536   CONTEXT *ctx = NULL, *this = NULL;
537
538   /* Sort, SortAux could be changed in mutt_index_menu() */
539   int oldSort, oldSortAux;
540   struct stat st;
541
542 #ifdef USE_NNTP
543   int news = 0;                 /* is it a news article ? */
544
545   if (option (OPTNEWSSEND))
546     news++;
547 #endif
548
549   mutt_attach_init (msg->content);
550   idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
551
552   menu = mutt_new_menu ();
553   menu->menu = MENU_COMPOSE;
554   menu->offset = HDR_ATTACH;
555   menu->max = idxlen;
556   menu->make_entry = snd_entry;
557   menu->tag = mutt_tag_attach;
558   menu->data = idx;
559 #ifdef USE_NNTP
560   if (news)
561     menu->help =
562       mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
563                          ComposeNewsHelp);
564   else
565 #endif
566     menu->help =
567       mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
568                          ComposeHelp);
569
570   if (option (OPTMBOXPANE))
571     mutt_buffy_check (1);
572   while (loop) {
573 #ifdef USE_NNTP
574     unset_option (OPTNEWS);     /* for any case */
575 #endif
576     switch (op = mutt_menuLoop (menu)) {
577     case OP_REDRAW:
578       draw_envelope (msg, fcc);
579       menu->offset = HDR_ATTACH;
580       menu->pagelen = LINES - HDR_ATTACH - 2;
581       break;
582     case OP_COMPOSE_EDIT_FROM:
583       menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
584       mutt_message_hook (NULL, msg, M_SEND2HOOK);
585       break;
586     case OP_COMPOSE_EDIT_TO:
587 #ifdef USE_NNTP
588       if (!news) {
589 #endif
590         menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
591         mutt_message_hook (NULL, msg, M_SEND2HOOK);
592 #ifdef USE_NNTP
593       }
594 #endif
595       break;
596     case OP_COMPOSE_EDIT_BCC:
597 #ifdef USE_NNTP
598       if (!news) {
599 #endif
600         menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
601         mutt_message_hook (NULL, msg, M_SEND2HOOK);
602 #ifdef USE_NNTP
603       }
604 #endif
605       break;
606     case OP_COMPOSE_EDIT_CC:
607 #ifdef USE_NNTP
608       if (!news) {
609 #endif
610         menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
611         mutt_message_hook (NULL, msg, M_SEND2HOOK);
612 #ifdef USE_NNTP
613       }
614 #endif
615       break;
616 #ifdef USE_NNTP
617     case OP_COMPOSE_EDIT_NEWSGROUPS:
618       if (news) {
619         if (msg->env->newsgroups)
620           strfcpy (buf, msg->env->newsgroups, sizeof (buf));
621         else
622           buf[0] = 0;
623         if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
624             && buf[0]) {
625           FREE (&msg->env->newsgroups);
626           mutt_remove_trailing_ws (buf);
627           msg->env->newsgroups = safe_strdup (mutt_skip_whitespace (buf));
628           move (HDR_TO, HDR_XOFFSET);
629           clrtoeol ();
630           if (msg->env->newsgroups)
631             printw ("%-*.*s", W, W, msg->env->newsgroups);
632         }
633       }
634       break;
635
636     case OP_COMPOSE_EDIT_FOLLOWUP_TO:
637       if (news) {
638         buf[0] = 0;
639         if (msg->env->followup_to)
640           strfcpy (buf, msg->env->followup_to, sizeof (buf));
641         if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
642             && buf[0]) {
643           FREE (&msg->env->followup_to);
644           mutt_remove_trailing_ws (buf);
645           msg->env->followup_to = safe_strdup (mutt_skip_whitespace (buf));
646           move (HDR_CC, HDR_XOFFSET);
647           clrtoeol ();
648           if (msg->env->followup_to)
649             printw ("%-*.*s", W, W, msg->env->followup_to);
650         }
651       }
652       break;
653
654     case OP_COMPOSE_EDIT_X_COMMENT_TO:
655       if (news && option (OPTXCOMMENTTO)) {
656         buf[0] = 0;
657         if (msg->env->x_comment_to)
658           strfcpy (buf, msg->env->x_comment_to, sizeof (buf));
659         if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
660             && buf[0]) {
661           FREE (&msg->env->x_comment_to);
662           msg->env->x_comment_to = safe_strdup (buf);
663           move (HDR_BCC, HDR_XOFFSET);
664           clrtoeol ();
665           if (msg->env->x_comment_to)
666             printw ("%-*.*s", W, W, msg->env->x_comment_to);
667         }
668       }
669       break;
670 #endif
671     case OP_COMPOSE_EDIT_SUBJECT:
672       if (msg->env->subject)
673         strfcpy (buf, msg->env->subject, sizeof (buf));
674       else
675         buf[0] = 0;
676       if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
677         mutt_str_replace (&msg->env->subject, buf);
678         move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
679         clrtoeol ();
680         if (msg->env->subject)
681           mutt_paddstr (W, msg->env->subject);
682       }
683       mutt_message_hook (NULL, msg, M_SEND2HOOK);
684       break;
685     case OP_COMPOSE_EDIT_REPLY_TO:
686       menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
687       mutt_message_hook (NULL, msg, M_SEND2HOOK);
688       break;
689     case OP_COMPOSE_EDIT_FCC:
690       strfcpy (buf, fcc, sizeof (buf));
691       if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
692         strfcpy (fcc, buf, _POSIX_PATH_MAX);
693         mutt_pretty_mailbox (fcc);
694         move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
695         mutt_paddstr (W, fcc);
696         fccSet = 1;
697       }
698       MAYBE_REDRAW (menu->redraw);
699       mutt_message_hook (NULL, msg, M_SEND2HOOK);
700       break;
701     case OP_COMPOSE_EDIT_MESSAGE:
702       if (Editor && (mutt_strcmp ("builtin", Editor) != 0)
703           && !option (OPTEDITHDRS)) {
704         mutt_edit_file (Editor, msg->content->filename);
705         mutt_update_encoding (msg->content);
706         menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
707         mutt_message_hook (NULL, msg, M_SEND2HOOK);
708         break;
709       }
710       /* fall through */
711     case OP_COMPOSE_EDIT_HEADERS:
712       if (mutt_strcmp ("builtin", Editor) != 0 &&
713           (op == OP_COMPOSE_EDIT_HEADERS ||
714            (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
715         char *tag = NULL, *err = NULL;
716
717         mutt_env_to_local (msg->env);
718         mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
719                            fcc, fcclen);
720         if (mutt_env_to_idna (msg->env, &tag, &err)) {
721           mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
722           FREE (&err);
723         }
724       }
725       else {
726         /* this is grouped with OP_COMPOSE_EDIT_HEADERS because the
727            attachment list could change if the user invokes ~v to edit
728            the message with headers, in which we need to execute the
729            code below to regenerate the index array */
730         mutt_builtin_editor (msg->content->filename, msg, cur);
731       }
732       mutt_update_encoding (msg->content);
733
734       /* attachments may have been added */
735       if (idxlen && idx[idxlen - 1]->content->next) {
736         for (i = 0; i < idxlen; i++)
737           FREE (&idx[i]);
738         idxlen = 0;
739         idx =
740           mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
741                                 1);
742         menu->data = idx;
743         menu->max = idxlen;
744       }
745
746       menu->redraw = REDRAW_FULL;
747       mutt_message_hook (NULL, msg, M_SEND2HOOK);
748       break;
749
750
751
752     case OP_COMPOSE_ATTACH_KEY:
753       if (!(WithCrypto & APPLICATION_PGP))
754         break;
755       if (idxlen == idxmax) {
756         safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
757         menu->data = idx;
758       }
759
760       idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
761       if ((idx[idxlen]->content =
762            crypt_pgp_make_key_attachment (NULL)) != NULL) {
763         update_idx (menu, idx, idxlen++);
764         menu->redraw |= REDRAW_INDEX;
765       }
766       else
767         FREE (&idx[idxlen]);
768
769       menu->redraw |= REDRAW_STATUS;
770
771       if (option (OPTNEEDREDRAW)) {
772         menu->redraw = REDRAW_FULL;
773         unset_option (OPTNEEDREDRAW);
774       }
775
776       mutt_message_hook (NULL, msg, M_SEND2HOOK);
777       break;
778
779
780     case OP_COMPOSE_ATTACH_FILE:
781       {
782         char *prompt, **files;
783         int error, numfiles;
784
785         fname[0] = 0;
786         prompt = _("Attach file");
787         numfiles = 0;
788         files = NULL;
789
790         if (_mutt_enter_fname
791             (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
792              &numfiles) == -1 || *fname == '\0')
793           break;
794
795         if (idxlen + numfiles >= idxmax) {
796           safe_realloc (&idx,
797                         sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles));
798           menu->data = idx;
799         }
800
801         error = 0;
802         if (numfiles > 1)
803           mutt_message _("Attaching selected files...");
804
805         for (i = 0; i < numfiles; i++) {
806           char *att = files[i];
807
808           idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
809           idx[idxlen]->content = mutt_make_file_attach (att);
810           if (idx[idxlen]->content != NULL)
811             update_idx (menu, idx, idxlen++);
812           else {
813             error = 1;
814             mutt_error (_("Unable to attach %s!"), att);
815             FREE (&idx[idxlen]);
816           }
817         }
818
819         FREE (&files);
820         if (!error)
821           mutt_clear_error ();
822
823         menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
824       }
825       mutt_message_hook (NULL, msg, M_SEND2HOOK);
826       break;
827
828     case OP_COMPOSE_ATTACH_MESSAGE:
829 #ifdef USE_NNTP
830     case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
831 #endif
832       {
833         char *prompt;
834         HEADER *h;
835
836         fname[0] = 0;
837         prompt = _("Open mailbox to attach message from");
838
839 #ifdef USE_NNTP
840         unset_option (OPTNEWS);
841         if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
842           if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
843             break;
844
845           prompt = _("Open newsgroup to attach message from");
846           set_option (OPTNEWS);
847         }
848 #endif
849
850         if (Context)
851 #ifdef USE_NNTP
852           if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
853 #endif
854           {
855             strfcpy (fname, NONULL (Context->path), sizeof (fname));
856             mutt_pretty_mailbox (fname);
857           }
858
859         if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
860             == -1 || !fname[0])
861           break;
862
863 #ifdef USE_NNTP
864         if (option (OPTNEWS))
865           nntp_expand_path (fname, sizeof (fname),
866                             &CurrentNewsSrv->conn->account);
867         else
868 #endif
869           mutt_expand_path (fname, sizeof (fname));
870 #ifdef USE_IMAP
871         if (!mx_is_imap (fname))
872 #endif
873 #ifdef USE_POP
874           if (!mx_is_pop (fname))
875 #endif
876 #ifdef USE_NNTP
877             if (!mx_is_nntp (fname) && !option (OPTNEWS))
878 #endif
879               /* check to make sure the file exists and is readable */
880               if (access (fname, R_OK) == -1) {
881                 mutt_perror (fname);
882                 break;
883               }
884
885         menu->redraw = REDRAW_FULL;
886
887         ctx = mx_open_mailbox (fname, M_READONLY, NULL);
888         if (ctx == NULL) {
889           mutt_perror (fname);
890           break;
891         }
892
893         if (!ctx->msgcount) {
894           mx_close_mailbox (ctx, NULL);
895           FREE (&ctx);
896           mutt_error _("No messages in that folder.");
897
898           break;
899         }
900
901         this = Context;         /* remember current folder and sort methods */
902         oldSort = Sort;
903         oldSortAux = SortAux;
904
905         Context = ctx;
906         set_option (OPTATTACHMSG);
907         mutt_message _("Tag the messages you want to attach!");
908
909         close = mutt_index_menu ();
910         unset_option (OPTATTACHMSG);
911
912         if (!Context) {
913           /* go back to the folder we started from */
914           Context = this;
915           /* Restore old $sort and $sort_aux */
916           Sort = oldSort;
917           SortAux = oldSortAux;
918           menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
919           break;
920         }
921
922         if (idxlen + Context->tagged >= idxmax) {
923           safe_realloc (&idx,
924                         sizeof (ATTACHPTR *) * (idxmax +=
925                                                 5 + Context->tagged));
926           menu->data = idx;
927         }
928
929         for (i = 0; i < Context->msgcount; i++) {
930           h = Context->hdrs[i];
931           if (h->tagged) {
932             idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
933             idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
934             if (idx[idxlen]->content != NULL)
935               update_idx (menu, idx, idxlen++);
936             else {
937               mutt_error _("Unable to attach!");
938
939               FREE (&idx[idxlen]);
940             }
941           }
942         }
943         menu->redraw |= REDRAW_FULL;
944
945         if (close == OP_QUIT)
946           mx_close_mailbox (Context, NULL);
947         else
948           mx_fastclose_mailbox (Context);
949         FREE (&Context);
950
951         /* go back to the folder we started from */
952         Context = this;
953         /* Restore old $sort and $sort_aux */
954         Sort = oldSort;
955         SortAux = oldSortAux;
956       }
957       mutt_message_hook (NULL, msg, M_SEND2HOOK);
958       break;
959
960     case OP_DELETE:
961       CHECK_COUNT;
962       if (delete_attachment (menu, &idxlen, menu->current) == -1)
963         break;
964       mutt_update_tree (idx, idxlen);
965       if (idxlen) {
966         if (menu->current > idxlen - 1)
967           menu->current = idxlen - 1;
968       }
969       else
970         menu->current = 0;
971
972       if (menu->current == 0)
973         msg->content = idx[0]->content;
974
975       menu->redraw |= REDRAW_STATUS;
976       mutt_message_hook (NULL, msg, M_SEND2HOOK);
977       break;
978
979 #define CURRENT idx[menu->current]->content
980
981     case OP_COMPOSE_TOGGLE_RECODE:
982       {
983         CHECK_COUNT;
984         if (!mutt_is_text_part (CURRENT)) {
985           mutt_error (_("Recoding only affects text attachments."));
986           break;
987         }
988         CURRENT->noconv = !CURRENT->noconv;
989         if (CURRENT->noconv)
990           mutt_message (_("The current attachment won't be converted."));
991         else
992           mutt_message (_("The current attachment will be converted."));
993         menu->redraw = REDRAW_CURRENT;
994         mutt_message_hook (NULL, msg, M_SEND2HOOK);
995         break;
996       }
997 #undef CURRENT
998
999     case OP_COMPOSE_EDIT_DESCRIPTION:
1000       CHECK_COUNT;
1001       strfcpy (buf,
1002                idx[menu->current]->content->description ?
1003                idx[menu->current]->content->description : "", sizeof (buf));
1004       /* header names should not be translated */
1005       if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
1006         mutt_str_replace (&idx[menu->current]->content->description, buf);
1007         menu->redraw = REDRAW_CURRENT;
1008       }
1009       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1010       break;
1011
1012     case OP_COMPOSE_UPDATE_ENCODING:
1013       CHECK_COUNT;
1014       if (menu->tagprefix) {
1015         BODY *top;
1016
1017         for (top = msg->content; top; top = top->next) {
1018           if (top->tagged)
1019             mutt_update_encoding (top);
1020         }
1021         menu->redraw = REDRAW_FULL;
1022       }
1023       else {
1024         mutt_update_encoding (idx[menu->current]->content);
1025         menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1026       }
1027       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1028       break;
1029
1030     case OP_COMPOSE_TOGGLE_DISPOSITION:
1031       /* toggle the content-disposition between inline/attachment */
1032       idx[menu->current]->content->disposition =
1033         (idx[menu->current]->content->disposition ==
1034          DISPINLINE) ? DISPATTACH : DISPINLINE;
1035       menu->redraw = REDRAW_CURRENT;
1036       break;
1037
1038     case OP_EDIT_TYPE:
1039       CHECK_COUNT;
1040       {
1041         mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
1042
1043         /* this may have been a change to text/something */
1044         mutt_update_encoding (idx[menu->current]->content);
1045
1046         menu->redraw = REDRAW_CURRENT;
1047       }
1048       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1049       break;
1050
1051     case OP_COMPOSE_EDIT_ENCODING:
1052       CHECK_COUNT;
1053       strfcpy (buf, ENCODING (idx[menu->current]->content->encoding),
1054                sizeof (buf));
1055       if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
1056                           sizeof (buf), 0) == 0 && buf[0]) {
1057         if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
1058           idx[menu->current]->content->encoding = i;
1059           menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1060           mutt_clear_error ();
1061         }
1062         else
1063           mutt_error _("Invalid encoding.");
1064       }
1065       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1066       break;
1067
1068     case OP_COMPOSE_SEND_MESSAGE:
1069
1070       /* Note: We don't invoke send2-hook here, since we want to leave
1071        * users an opportunity to change settings from the ":" prompt.
1072        */
1073
1074       if (check_attachments (idx, idxlen) != 0) {
1075         menu->redraw = REDRAW_FULL;
1076         break;
1077       }
1078
1079
1080 #ifdef MIXMASTER
1081       if (msg->chain && mix_check_message (msg) != 0)
1082         break;
1083 #endif
1084
1085       if (!fccSet && *fcc) {
1086         if ((i = query_quadoption (OPT_COPY,
1087                                    _("Save a copy of this message?"))) == -1)
1088           break;
1089         else if (i == M_NO)
1090           *fcc = 0;
1091       }
1092
1093       loop = 0;
1094       r = 0;
1095       break;
1096
1097     case OP_COMPOSE_EDIT_FILE:
1098       CHECK_COUNT;
1099       mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename);
1100       mutt_update_encoding (idx[menu->current]->content);
1101       menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1102       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1103       break;
1104
1105     case OP_COMPOSE_TOGGLE_UNLINK:
1106       CHECK_COUNT;
1107       idx[menu->current]->content->unlink =
1108         !idx[menu->current]->content->unlink;
1109
1110 #if 0
1111       /* OPTRESOLVE is otherwise ignored on this menu.
1112        * Where's the bug?
1113        */
1114
1115       if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
1116         menu->current++;
1117 # endif
1118       menu->redraw = REDRAW_INDEX;
1119       /* No send2hook since this doesn't change the message. */
1120       break;
1121
1122     case OP_COMPOSE_GET_ATTACHMENT:
1123       CHECK_COUNT;
1124       if (menu->tagprefix) {
1125         BODY *top;
1126
1127         for (top = msg->content; top; top = top->next) {
1128           if (top->tagged)
1129             mutt_get_tmp_attachment (top);
1130         }
1131         menu->redraw = REDRAW_FULL;
1132       }
1133       else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1134         menu->redraw = REDRAW_CURRENT;
1135
1136       /* No send2hook since this doesn't change the message. */
1137       break;
1138
1139     case OP_COMPOSE_RENAME_FILE:
1140       CHECK_COUNT;
1141       strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname));
1142       mutt_pretty_mailbox (fname);
1143       if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1144           == 0 && fname[0]) {
1145         if (stat (idx[menu->current]->content->filename, &st) == -1) {
1146           mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1147           break;
1148         }
1149
1150         mutt_expand_path (fname, sizeof (fname));
1151         if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1152           break;
1153
1154         mutt_str_replace (&idx[menu->current]->content->filename, fname);
1155         menu->redraw = REDRAW_CURRENT;
1156
1157         if (idx[menu->current]->content->stamp >= st.st_mtime)
1158           mutt_stamp_attachment (idx[menu->current]->content);
1159
1160       }
1161       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1162       break;
1163
1164     case OP_COMPOSE_NEW_MIME:
1165       {
1166         char type[STRING];
1167         char *p;
1168         int itype;
1169         FILE *fp;
1170
1171         CLEARLINE (LINES - 1);
1172         fname[0] = 0;
1173         if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1174             != 0 || !fname[0])
1175           continue;
1176         mutt_expand_path (fname, sizeof (fname));
1177
1178         /* Call to lookup_mime_type () ?  maybe later */
1179         type[0] = 0;
1180         if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1181             || !type[0])
1182           continue;
1183
1184         if (!(p = strchr (type, '/'))) {
1185           mutt_error _("Content-Type is of the form base/sub");
1186
1187           continue;
1188         }
1189         *p++ = 0;
1190         if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1191           mutt_error (_("Unknown Content-Type %s"), type);
1192           continue;
1193         }
1194         if (idxlen == idxmax) {
1195           safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
1196           menu->data = idx;
1197         }
1198
1199         idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
1200         /* Touch the file */
1201         if (!(fp = safe_fopen (fname, "w"))) {
1202           mutt_error (_("Can't create file %s"), fname);
1203           FREE (&idx[idxlen]);
1204           continue;
1205         }
1206         fclose (fp);
1207
1208         if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1209           mutt_error
1210             _("What we have here is a failure to make an attachment");
1211           continue;
1212         }
1213         update_idx (menu, idx, idxlen++);
1214
1215         idx[menu->current]->content->type = itype;
1216         mutt_str_replace (&idx[menu->current]->content->subtype, p);
1217         idx[menu->current]->content->unlink = 1;
1218         menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1219
1220         if (mutt_compose_attachment (idx[menu->current]->content)) {
1221           mutt_update_encoding (idx[menu->current]->content);
1222           menu->redraw = REDRAW_FULL;
1223         }
1224       }
1225       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1226       break;
1227
1228     case OP_COMPOSE_EDIT_MIME:
1229       CHECK_COUNT;
1230       if (mutt_edit_attachment (idx[menu->current]->content)) {
1231         mutt_update_encoding (idx[menu->current]->content);
1232         menu->redraw = REDRAW_FULL;
1233       }
1234       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1235       break;
1236
1237     case OP_VIEW_ATTACH:
1238     case OP_DISPLAY_HEADERS:
1239       CHECK_COUNT;
1240       mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1241                                 NULL, 0);
1242       menu->redraw = REDRAW_FULL;
1243       /* no send2hook, since this doesn't modify the message */
1244       break;
1245
1246     case OP_SAVE:
1247       CHECK_COUNT;
1248       mutt_save_attachment_list (NULL, menu->tagprefix,
1249                                  menu->tagprefix ? msg->content : idx[menu->
1250                                                                       current]->
1251                                  content, NULL, menu);
1252       MAYBE_REDRAW (menu->redraw);
1253       /* no send2hook, since this doesn't modify the message */
1254       break;
1255
1256     case OP_PRINT:
1257       CHECK_COUNT;
1258       mutt_print_attachment_list (NULL, menu->tagprefix,
1259                                   menu->tagprefix ? msg->content : idx[menu->
1260                                                                        current]->
1261                                   content);
1262       /* no send2hook, since this doesn't modify the message */
1263       break;
1264
1265     case OP_PIPE:
1266     case OP_FILTER:
1267       CHECK_COUNT;
1268       mutt_pipe_attachment_list (NULL, menu->tagprefix,
1269                                  menu->tagprefix ? msg->content : idx[menu->
1270                                                                       current]->
1271                                  content, op == OP_FILTER);
1272       if (op == OP_FILTER)      /* cte might have changed */
1273         menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1274       menu->redraw |= REDRAW_STATUS;
1275       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1276       break;
1277
1278     case OP_EXIT:
1279       if ((i =
1280            query_quadoption (OPT_POSTPONE,
1281                              _("Postpone this message?"))) == M_NO) {
1282         while (idxlen-- > 0) {
1283           /* avoid freeing other attachments */
1284           idx[idxlen]->content->next = NULL;
1285           idx[idxlen]->content->parts = NULL;
1286           mutt_free_body (&idx[idxlen]->content);
1287           FREE (&idx[idxlen]->tree);
1288           FREE (&idx[idxlen]);
1289         }
1290         FREE (&idx);
1291         idxlen = 0;
1292         idxmax = 0;
1293         r = -1;
1294         loop = 0;
1295         break;
1296       }
1297       else if (i == -1)
1298         break;                  /* abort */
1299
1300       /* fall through to postpone! */
1301
1302     case OP_COMPOSE_POSTPONE_MESSAGE:
1303
1304       if (check_attachments (idx, idxlen) != 0) {
1305         menu->redraw = REDRAW_FULL;
1306         break;
1307       }
1308
1309       loop = 0;
1310       r = 1;
1311       break;
1312
1313     case OP_COMPOSE_ISPELL:
1314       endwin ();
1315       snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1316                 msg->content->filename);
1317       if (mutt_system (buf) == -1)
1318         mutt_error (_("Error running \"%s\"!"), buf);
1319       else {
1320         mutt_update_encoding (msg->content);
1321         menu->redraw |= REDRAW_STATUS;
1322       }
1323       break;
1324
1325     case OP_COMPOSE_WRITE_MESSAGE:
1326
1327       fname[0] = '\0';
1328       if (Context) {
1329         strfcpy (fname, NONULL (Context->path), sizeof (fname));
1330         mutt_pretty_mailbox (fname);
1331       }
1332       if (idxlen)
1333         msg->content = idx[0]->content;
1334       if (mutt_enter_fname
1335           (_("Write message to mailbox"), fname, sizeof (fname),
1336            &menu->redraw, 1) != -1 && fname[0]) {
1337         mutt_message (_("Writing message to %s ..."), fname);
1338         mutt_expand_path (fname, sizeof (fname));
1339
1340         if (msg->content->next)
1341           msg->content = mutt_make_multipart (msg->content);
1342
1343         if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1344           msg->content = mutt_remove_multipart (msg->content);
1345         else
1346           mutt_message _("Message written.");
1347       }
1348       break;
1349
1350
1351
1352     case OP_COMPOSE_PGP_MENU:
1353       if (!(WithCrypto & APPLICATION_PGP))
1354         break;
1355       if ((WithCrypto & APPLICATION_SMIME)
1356           && msg->security & APPLICATION_SMIME) {
1357         if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1358                           M_YES) != M_YES) {
1359           mutt_clear_error ();
1360           break;
1361         }
1362         msg->security = 0;
1363       }
1364       msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1365       redraw_crypt_lines (msg);
1366       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1367       break;
1368
1369
1370     case OP_FORGET_PASSPHRASE:
1371       crypt_forget_passphrase ();
1372       break;
1373
1374
1375     case OP_COMPOSE_SMIME_MENU:
1376       if (!(WithCrypto & APPLICATION_SMIME))
1377         break;
1378
1379       if ((WithCrypto & APPLICATION_PGP)
1380           && msg->security & APPLICATION_PGP) {
1381         if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1382                           M_YES) != M_YES) {
1383           mutt_clear_error ();
1384           break;
1385         }
1386         msg->security = 0;
1387       }
1388       msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1389       redraw_crypt_lines (msg);
1390       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1391       break;
1392
1393
1394 #ifdef MIXMASTER
1395     case OP_COMPOSE_MIX:
1396
1397       mix_make_chain (&msg->chain, &menu->redraw);
1398       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1399       break;
1400 #endif
1401
1402     }
1403
1404     /* Draw formated compose status line */
1405     if (menu->redraw & REDRAW_STATUS) {
1406       compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1407       CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1408       SETCOLOR (MT_COLOR_STATUS);
1409       printw ("%-*.*s", COLS, COLS, buf);
1410       SETCOLOR (MT_COLOR_NORMAL);
1411       menu->redraw &= ~REDRAW_STATUS;
1412     }
1413   }
1414
1415   mutt_menuDestroy (&menu);
1416
1417   if (idxlen) {
1418     msg->content = idx[0]->content;
1419     for (i = 0; i < idxlen; i++) {
1420       idx[i]->content->aptr = NULL;
1421       FREE (&idx[i]);
1422     }
1423   }
1424   else
1425     msg->content = NULL;
1426
1427   FREE (&idx);
1428
1429   return (r);
1430 }