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