Nico Golde:
[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   mutt_buffy_check(1);
592   while (loop)
593   {
594 #ifdef USE_NNTP
595     unset_option (OPTNEWS);     /* for any case */
596 #endif
597     switch (op = mutt_menuLoop (menu))
598     {
599       case OP_REDRAW:
600         draw_envelope (msg, fcc);
601         menu->offset = HDR_ATTACH;
602         menu->pagelen = LINES - HDR_ATTACH - 2;
603         break;
604       case OP_COMPOSE_EDIT_FROM:
605         menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
606         mutt_message_hook (NULL, msg, M_SEND2HOOK);
607         break;
608       case OP_COMPOSE_EDIT_TO:
609 #ifdef USE_NNTP
610         if (!news) {
611 #endif
612           menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
613           mutt_message_hook (NULL, msg, M_SEND2HOOK);
614 #ifdef USE_NNTP
615         }
616 #endif
617         break;
618       case OP_COMPOSE_EDIT_BCC:
619 #ifdef USE_NNTP
620         if (!news) {
621 #endif
622           menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
623           mutt_message_hook (NULL, msg, M_SEND2HOOK);
624 #ifdef USE_NNTP
625         }
626 #endif
627         break;
628       case OP_COMPOSE_EDIT_CC:
629 #ifdef USE_NNTP
630         if (!news) {
631 #endif
632           menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
633           mutt_message_hook (NULL, msg, M_SEND2HOOK);   
634 #ifdef USE_NNTP
635         }
636 #endif
637         break;
638 #ifdef USE_NNTP
639       case OP_COMPOSE_EDIT_NEWSGROUPS:
640         if (news)
641         {
642           if (msg->env->newsgroups)
643             strfcpy (buf, msg->env->newsgroups, sizeof (buf));
644           else
645             buf[0] = 0;
646           if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0 && buf[0])
647           {
648             FREE (&msg->env->newsgroups);
649             mutt_remove_trailing_ws (buf);
650             msg->env->newsgroups = safe_strdup (mutt_skip_whitespace (buf));
651             move (HDR_TO, HDR_XOFFSET);
652             clrtoeol ();
653             if (msg->env->newsgroups)
654               printw ("%-*.*s", W, W, msg->env->newsgroups);
655           }
656         }
657         break;
658
659       case OP_COMPOSE_EDIT_FOLLOWUP_TO:
660         if (news)
661         {
662           buf[0] = 0;
663           if (msg->env->followup_to)
664             strfcpy (buf, msg->env->followup_to, sizeof (buf));
665           if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0 && buf[0])
666           {
667             FREE (&msg->env->followup_to);
668             mutt_remove_trailing_ws (buf);
669             msg->env->followup_to = safe_strdup (mutt_skip_whitespace (buf));
670             move (HDR_CC, HDR_XOFFSET);
671             clrtoeol();
672             if (msg->env->followup_to)
673               printw ("%-*.*s", W, W, msg->env->followup_to);
674           }
675         }
676         break;
677
678       case OP_COMPOSE_EDIT_X_COMMENT_TO:
679         if (news && option (OPTXCOMMENTTO))
680         {
681           buf[0] = 0;
682           if (msg->env->x_comment_to)
683             strfcpy (buf, msg->env->x_comment_to, sizeof (buf));
684           if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0 && buf[0])
685           {
686             FREE (&msg->env->x_comment_to);
687             msg->env->x_comment_to = safe_strdup (buf);
688             move (HDR_BCC, HDR_XOFFSET);
689             clrtoeol();
690             if (msg->env->x_comment_to)
691               printw ("%-*.*s", W, W, msg->env->x_comment_to);
692           }
693         }
694         break;
695 #endif
696       case OP_COMPOSE_EDIT_SUBJECT:
697         if (msg->env->subject)
698           strfcpy (buf, msg->env->subject, sizeof (buf));
699         else
700           buf[0] = 0;
701         if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
702         {
703           mutt_str_replace (&msg->env->subject, buf);
704           move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
705           clrtoeol ();
706           if (msg->env->subject)
707             mutt_paddstr (W, msg->env->subject);
708         }
709         mutt_message_hook (NULL, msg, M_SEND2HOOK);
710         break;
711       case OP_COMPOSE_EDIT_REPLY_TO:
712         menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
713         mutt_message_hook (NULL, msg, M_SEND2HOOK);
714         break;
715       case OP_COMPOSE_EDIT_FCC:
716         strfcpy (buf, fcc, sizeof (buf));
717         if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0)
718         {
719           strfcpy (fcc, buf, _POSIX_PATH_MAX);
720           mutt_pretty_mailbox (fcc);
721           move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
722           mutt_paddstr (W, fcc);
723           fccSet = 1;
724         }
725         MAYBE_REDRAW (menu->redraw);
726         mutt_message_hook (NULL, msg, M_SEND2HOOK);
727         break;
728       case OP_COMPOSE_EDIT_MESSAGE:
729         if (Editor && (mutt_strcmp ("builtin", Editor) != 0) && !option (OPTEDITHDRS))
730         {
731           mutt_edit_file (Editor, msg->content->filename);
732           mutt_update_encoding (msg->content);
733           menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
734           mutt_message_hook (NULL, msg, M_SEND2HOOK);
735           break;
736         }
737         /* fall through */
738       case OP_COMPOSE_EDIT_HEADERS:
739         if (mutt_strcmp ("builtin", Editor) != 0 &&
740             (op == OP_COMPOSE_EDIT_HEADERS ||
741             (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS))))
742         {
743           char *tag = NULL, *err = NULL;
744           mutt_env_to_local (msg->env);
745           mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
746                              fcc, fcclen);
747           if (mutt_env_to_idna (msg->env, &tag, &err))
748           {
749             mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
750             FREE (&err);
751           }
752         }
753         else
754         {
755           /* this is grouped with OP_COMPOSE_EDIT_HEADERS because the
756              attachment list could change if the user invokes ~v to edit
757              the message with headers, in which we need to execute the
758              code below to regenerate the index array */
759           mutt_builtin_editor (msg->content->filename, msg, cur);
760         }
761         mutt_update_encoding (msg->content);
762
763         /* attachments may have been added */
764         if (idxlen && idx[idxlen - 1]->content->next)
765         {
766           for (i = 0; i < idxlen; i++)
767             FREE (&idx[i]);
768           idxlen = 0;
769           idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
770           menu->data = idx;
771           menu->max = idxlen;
772         }
773
774         menu->redraw = REDRAW_FULL;
775         mutt_message_hook (NULL, msg, M_SEND2HOOK);
776         break;
777
778
779
780       case OP_COMPOSE_ATTACH_KEY:
781         if (!(WithCrypto & APPLICATION_PGP))
782           break;       
783         if (idxlen == idxmax)
784         {
785           safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
786           menu->data = idx;
787         }
788         
789         idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
790         if ((idx[idxlen]->content = crypt_pgp_make_key_attachment(NULL)) != NULL)
791         {
792           update_idx (menu, idx, idxlen++);
793           menu->redraw |= REDRAW_INDEX;
794         }
795         else
796           FREE (&idx[idxlen]);
797
798         menu->redraw |= REDRAW_STATUS;
799
800         if (option(OPTNEEDREDRAW))
801         {
802           menu->redraw = REDRAW_FULL;
803           unset_option(OPTNEEDREDRAW);
804         }
805         
806         mutt_message_hook (NULL, msg, M_SEND2HOOK);
807         break;
808
809
810       case OP_COMPOSE_ATTACH_FILE:
811         {
812           char *prompt, **files;
813           int error, numfiles;
814
815           fname[0] = 0;
816           prompt = _("Attach file");
817           numfiles = 0;
818           files = NULL;
819
820           if (_mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files, &numfiles) == -1 ||
821               *fname == '\0')
822             break;
823
824           if (idxlen + numfiles >= idxmax)
825           {
826             safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles));
827             menu->data = idx;
828           }
829
830           error = 0;
831           if (numfiles > 1)
832             mutt_message _("Attaching selected files...");
833           for (i = 0; i < numfiles; i++)
834           {
835             char *att = files[i];
836             idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
837             idx[idxlen]->content = mutt_make_file_attach (att);
838             if (idx[idxlen]->content != NULL)
839               update_idx (menu, idx, idxlen++);
840             else
841             {
842               error = 1;
843               mutt_error (_("Unable to attach %s!"), att);
844               FREE (&idx[idxlen]);
845             }
846           }
847           
848           FREE (&files);
849           if (!error) mutt_clear_error ();
850
851           menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
852         }
853         mutt_message_hook (NULL, msg, M_SEND2HOOK);
854         break;
855
856       case OP_COMPOSE_ATTACH_MESSAGE:
857 #ifdef USE_NNTP
858       case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
859 #endif
860         {
861           char *prompt;
862           HEADER *h;
863
864           fname[0] = 0;
865           prompt = _("Open mailbox to attach message from");
866
867 #ifdef USE_NNTP
868           unset_option (OPTNEWS);
869           if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE)
870           {
871             if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
872               break;
873
874             prompt = _("Open newsgroup to attach message from");
875             set_option (OPTNEWS);
876           }
877 #endif
878
879           if (Context)
880 #ifdef USE_NNTP
881           if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
882 #endif
883           {
884             strfcpy (fname, NONULL (Context->path), sizeof (fname));
885             mutt_pretty_mailbox (fname);
886           }
887
888           if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1) == -1 || !fname[0])
889             break;
890
891 #ifdef USE_NNTP
892           if (option (OPTNEWS))
893             nntp_expand_path (fname, sizeof (fname), &CurrentNewsSrv->conn->account);
894           else
895 #endif
896           mutt_expand_path (fname, sizeof (fname));
897 #ifdef USE_IMAP
898           if (!mx_is_imap (fname))
899 #endif
900 #ifdef USE_POP
901           if (!mx_is_pop (fname))
902 #endif
903 #ifdef USE_NNTP
904           if (!mx_is_nntp (fname) && !option (OPTNEWS))
905 #endif
906           /* check to make sure the file exists and is readable */
907           if (access (fname, R_OK) == -1)
908           {
909             mutt_perror (fname);
910             break;
911           }
912
913           menu->redraw = REDRAW_FULL;
914
915           ctx = mx_open_mailbox (fname, M_READONLY, NULL);
916           if (ctx == NULL)
917           {
918             mutt_perror (fname);
919             break;
920           }
921
922           if (!ctx->msgcount)
923           {
924             mx_close_mailbox (ctx, NULL);
925             FREE (&ctx);
926             mutt_error _("No messages in that folder.");
927             break;
928           }
929
930           this = Context; /* remember current folder and sort methods*/
931           oldSort = Sort; oldSortAux = SortAux;
932           
933           Context = ctx;
934           set_option(OPTATTACHMSG);
935           mutt_message _("Tag the messages you want to attach!");
936           close = mutt_index_menu ();
937           unset_option(OPTATTACHMSG);
938
939           if (!Context)
940           {
941             /* go back to the folder we started from */
942             Context = this;
943             /* Restore old $sort and $sort_aux */
944             Sort = oldSort;
945             SortAux = oldSortAux;
946             menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
947             break;
948           }
949
950           if (idxlen + Context->tagged >= idxmax)
951           {
952             safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + Context->tagged));
953             menu->data = idx;
954           }
955
956           for (i = 0; i < Context->msgcount; i++)
957           {
958             h = Context->hdrs[i];
959             if (h->tagged)
960             {
961               idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
962               idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
963               if (idx[idxlen]->content != NULL)
964                 update_idx (menu, idx, idxlen++);
965               else
966               {
967                 mutt_error _("Unable to attach!");
968                 FREE (&idx[idxlen]);
969               }
970             }
971           }
972           menu->redraw |= REDRAW_FULL;
973
974           if (close == OP_QUIT) 
975             mx_close_mailbox (Context, NULL);
976           else
977             mx_fastclose_mailbox (Context);
978           FREE (&Context);
979
980           /* go back to the folder we started from */
981           Context = this;
982           /* Restore old $sort and $sort_aux */
983           Sort = oldSort;
984           SortAux = oldSortAux;
985         }
986         mutt_message_hook (NULL, msg, M_SEND2HOOK);
987         break;
988
989       case OP_DELETE:
990         CHECK_COUNT;
991         if (delete_attachment (menu, &idxlen, menu->current) == -1)
992           break;
993         mutt_update_tree (idx, idxlen);
994         if (idxlen)
995         {
996           if (menu->current > idxlen - 1)
997             menu->current = idxlen - 1;
998         }
999         else
1000           menu->current = 0;
1001
1002         if (menu->current == 0)
1003           msg->content = idx[0]->content;
1004
1005         menu->redraw |= REDRAW_STATUS;
1006         mutt_message_hook (NULL, msg, M_SEND2HOOK);
1007         break;
1008
1009 #define CURRENT idx[menu->current]->content
1010       
1011       case OP_COMPOSE_TOGGLE_RECODE:
1012       {      
1013         CHECK_COUNT;
1014         if (!mutt_is_text_part (CURRENT))
1015         {
1016           mutt_error (_("Recoding only affects text attachments."));
1017           break;
1018         }
1019         CURRENT->noconv = !CURRENT->noconv;
1020         if (CURRENT->noconv)
1021           mutt_message (_("The current attachment won't be converted."));
1022         else
1023           mutt_message (_("The current attachment will be converted."));
1024         menu->redraw = REDRAW_CURRENT;
1025         mutt_message_hook (NULL, msg, M_SEND2HOOK);
1026         break;
1027       }
1028 #undef CURRENT
1029
1030       case OP_COMPOSE_EDIT_DESCRIPTION:
1031         CHECK_COUNT;
1032         strfcpy (buf,
1033                  idx[menu->current]->content->description ?
1034                  idx[menu->current]->content->description : "",
1035                  sizeof (buf));
1036         /* header names should not be translated */
1037         if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0)
1038         {
1039           mutt_str_replace (&idx[menu->current]->content->description, buf);
1040           menu->redraw = REDRAW_CURRENT;
1041         }
1042         mutt_message_hook (NULL, msg, M_SEND2HOOK);
1043         break;
1044
1045       case OP_COMPOSE_UPDATE_ENCODING:
1046         CHECK_COUNT;
1047         if (menu->tagprefix)
1048         {
1049           BODY *top;
1050           for (top = msg->content; top; top = top->next)
1051           {
1052             if (top->tagged)
1053               mutt_update_encoding (top);
1054           }
1055           menu->redraw = REDRAW_FULL;
1056         }
1057         else
1058         {
1059           mutt_update_encoding(idx[menu->current]->content);
1060           menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1061         }
1062         mutt_message_hook (NULL, msg, M_SEND2HOOK);
1063         break;
1064       
1065       case OP_COMPOSE_TOGGLE_DISPOSITION:
1066         /* toggle the content-disposition between inline/attachment */
1067         idx[menu->current]->content->disposition = (idx[menu->current]->content->disposition == DISPINLINE) ? DISPATTACH : DISPINLINE;
1068         menu->redraw = REDRAW_CURRENT;
1069         break;
1070
1071       case OP_EDIT_TYPE:
1072         CHECK_COUNT;
1073         {
1074           mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
1075
1076           /* this may have been a change to text/something */
1077           mutt_update_encoding (idx[menu->current]->content);
1078
1079           menu->redraw = REDRAW_CURRENT;
1080         }
1081         mutt_message_hook (NULL, msg, M_SEND2HOOK);
1082         break;
1083
1084       case OP_COMPOSE_EDIT_ENCODING:
1085         CHECK_COUNT;
1086         strfcpy (buf, ENCODING (idx[menu->current]->content->encoding),
1087                                                               sizeof (buf));
1088         if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
1089                                             sizeof (buf), 0) == 0 && buf[0])
1090         {
1091           if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED)
1092           {
1093             idx[menu->current]->content->encoding = i;
1094             menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1095             mutt_clear_error();
1096           }
1097           else
1098             mutt_error _("Invalid encoding.");
1099         }
1100         mutt_message_hook (NULL, msg, M_SEND2HOOK);
1101         break;
1102
1103       case OP_COMPOSE_SEND_MESSAGE:
1104
1105         /* Note: We don't invoke send2-hook here, since we want to leave
1106          * users an opportunity to change settings from the ":" prompt.
1107          */
1108       
1109         if(check_attachments(idx, idxlen) != 0)
1110         {
1111           menu->redraw = REDRAW_FULL;
1112           break;
1113         }
1114
1115       
1116 #ifdef MIXMASTER
1117         if (msg->chain && mix_check_message (msg) != 0)
1118           break;
1119 #endif
1120       
1121         if (!fccSet && *fcc)
1122         {
1123           if ((i = query_quadoption (OPT_COPY,
1124                                 _("Save a copy of this message?"))) == -1)
1125             break;
1126           else if (i == M_NO)
1127             *fcc = 0;
1128         }
1129
1130         loop = 0;
1131         r = 0;
1132         break;
1133
1134       case OP_COMPOSE_EDIT_FILE:
1135         CHECK_COUNT;
1136         mutt_edit_file (NONULL(Editor), idx[menu->current]->content->filename);
1137         mutt_update_encoding (idx[menu->current]->content);
1138         menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1139         mutt_message_hook (NULL, msg, M_SEND2HOOK);
1140         break;
1141
1142       case OP_COMPOSE_TOGGLE_UNLINK:
1143         CHECK_COUNT;
1144         idx[menu->current]->content->unlink = !idx[menu->current]->content->unlink;
1145
1146 #if 0
1147         /* OPTRESOLVE is otherwise ignored on this menu.
1148          * Where's the bug?
1149          */
1150
1151         if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
1152           menu->current++;
1153 # endif
1154         menu->redraw = REDRAW_INDEX;
1155         /* No send2hook since this doesn't change the message. */
1156         break;
1157
1158       case OP_COMPOSE_GET_ATTACHMENT:
1159         CHECK_COUNT;
1160         if(menu->tagprefix)
1161         {
1162           BODY *top;
1163           for(top = msg->content; top; top = top->next)
1164           {
1165             if(top->tagged)
1166               mutt_get_tmp_attachment(top);
1167           }
1168           menu->redraw = REDRAW_FULL;
1169         }
1170         else if (mutt_get_tmp_attachment(idx[menu->current]->content) == 0)
1171           menu->redraw = REDRAW_CURRENT;
1172
1173         /* No send2hook since this doesn't change the message. */
1174         break;
1175       
1176       case OP_COMPOSE_RENAME_FILE:
1177         CHECK_COUNT;
1178         strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname));
1179         mutt_pretty_mailbox (fname);
1180         if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1181                                                         == 0 && fname[0])
1182         {
1183           if (stat(idx[menu->current]->content->filename, &st) == -1)
1184           {
1185             mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1186             break;
1187           }
1188
1189           mutt_expand_path (fname, sizeof (fname));
1190           if(mutt_rename_file (idx[menu->current]->content->filename, fname))
1191             break;
1192           
1193           mutt_str_replace (&idx[menu->current]->content->filename, fname);
1194           menu->redraw = REDRAW_CURRENT;
1195
1196           if(idx[menu->current]->content->stamp >= st.st_mtime)
1197             mutt_stamp_attachment(idx[menu->current]->content);
1198           
1199         }
1200         mutt_message_hook (NULL, msg, M_SEND2HOOK);
1201         break;
1202
1203       case OP_COMPOSE_NEW_MIME:
1204         {
1205           char type[STRING];
1206           char *p;
1207           int itype;
1208           FILE *fp;
1209
1210           CLEARLINE (LINES-1);
1211           fname[0] = 0;
1212           if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1213               != 0 || !fname[0])
1214             continue;
1215           mutt_expand_path (fname, sizeof (fname));
1216
1217           /* Call to lookup_mime_type () ?  maybe later */
1218           type[0] = 0;
1219           if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0 
1220               || !type[0])
1221             continue;
1222
1223           if (!(p = strchr (type, '/')))
1224           {
1225             mutt_error _("Content-Type is of the form base/sub");
1226             continue;
1227           }
1228           *p++ = 0;
1229           if ((itype = mutt_check_mime_type (type)) == TYPEOTHER)
1230           {
1231             mutt_error (_("Unknown Content-Type %s"), type);
1232             continue;
1233           }
1234           if (idxlen == idxmax)
1235           {
1236             safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
1237             menu->data = idx;
1238           }
1239
1240           idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
1241           /* Touch the file */
1242           if (!(fp = safe_fopen (fname, "w")))
1243           {
1244             mutt_error (_("Can't create file %s"), fname);
1245             FREE (&idx[idxlen]);
1246             continue;
1247           }
1248           fclose (fp);
1249
1250           if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL)
1251           {
1252             mutt_error _("What we have here is a failure to make an attachment");
1253             continue;
1254           }
1255           update_idx (menu, idx, idxlen++);
1256
1257           idx[menu->current]->content->type = itype;
1258           mutt_str_replace (&idx[menu->current]->content->subtype, p);
1259           idx[menu->current]->content->unlink = 1;
1260           menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1261
1262           if (mutt_compose_attachment (idx[menu->current]->content))
1263           {
1264             mutt_update_encoding (idx[menu->current]->content);
1265             menu->redraw = REDRAW_FULL;
1266           }
1267         }
1268         mutt_message_hook (NULL, msg, M_SEND2HOOK);    
1269         break;
1270
1271       case OP_COMPOSE_EDIT_MIME:
1272         CHECK_COUNT;
1273         if (mutt_edit_attachment (idx[menu->current]->content))
1274         {
1275           mutt_update_encoding (idx[menu->current]->content);
1276           menu->redraw = REDRAW_FULL;
1277         }
1278         mutt_message_hook (NULL, msg, M_SEND2HOOK);
1279         break;
1280
1281       case OP_VIEW_ATTACH:
1282       case OP_DISPLAY_HEADERS:
1283         CHECK_COUNT;
1284         mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen, NULL, 0);
1285         menu->redraw = REDRAW_FULL;
1286         /* no send2hook, since this doesn't modify the message */
1287         break;
1288
1289       case OP_SAVE:
1290         CHECK_COUNT;
1291         mutt_save_attachment_list (NULL, menu->tagprefix, menu->tagprefix ?  msg->content : idx[menu->current]->content, NULL, menu);
1292         MAYBE_REDRAW (menu->redraw);
1293         /* no send2hook, since this doesn't modify the message */
1294         break;
1295
1296       case OP_PRINT:
1297         CHECK_COUNT;
1298         mutt_print_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content);
1299         /* no send2hook, since this doesn't modify the message */
1300         break;
1301
1302       case OP_PIPE:
1303       case OP_FILTER:
1304         CHECK_COUNT;
1305         mutt_pipe_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, op == OP_FILTER);
1306         if (op == OP_FILTER) /* cte might have changed */
1307           menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1308         menu->redraw |= REDRAW_STATUS;
1309         mutt_message_hook (NULL, msg, M_SEND2HOOK);
1310         break;
1311
1312       case OP_EXIT:
1313         if ((i = query_quadoption (OPT_POSTPONE, _("Postpone this message?"))) == M_NO)
1314         {
1315           while (idxlen-- > 0)
1316           {
1317             /* avoid freeing other attachments */
1318             idx[idxlen]->content->next = NULL;
1319             idx[idxlen]->content->parts = NULL;
1320             mutt_free_body (&idx[idxlen]->content);
1321             FREE (&idx[idxlen]->tree);
1322             FREE (&idx[idxlen]);
1323           }
1324           FREE (&idx);
1325           idxlen = 0;
1326           idxmax = 0;
1327           r = -1;
1328           loop = 0;
1329           break;
1330         }
1331         else if (i == -1)
1332           break; /* abort */
1333
1334         /* fall through to postpone! */
1335
1336       case OP_COMPOSE_POSTPONE_MESSAGE:
1337
1338         if(check_attachments(idx, idxlen) != 0)
1339         {
1340           menu->redraw = REDRAW_FULL;
1341           break;
1342         }
1343       
1344         loop = 0;
1345         r = 1;
1346         break;
1347
1348       case OP_COMPOSE_ISPELL:
1349         endwin ();
1350         snprintf (buf, sizeof (buf), "%s -x %s", NONULL(Ispell), msg->content->filename);
1351         if (mutt_system (buf) == -1)
1352           mutt_error (_("Error running \"%s\"!"), buf);
1353         else
1354         {
1355           mutt_update_encoding (msg->content);
1356           menu->redraw |= REDRAW_STATUS;
1357         }
1358         break;
1359
1360       case OP_COMPOSE_WRITE_MESSAGE:
1361
1362        fname[0] = '\0';
1363        if (Context)
1364        {
1365          strfcpy (fname, NONULL (Context->path), sizeof (fname));
1366          mutt_pretty_mailbox (fname);
1367        }
1368        if (idxlen)
1369          msg->content = idx[0]->content;
1370        if (mutt_enter_fname (_("Write message to mailbox"), fname, sizeof (fname),
1371                              &menu->redraw, 1) != -1 && fname[0])
1372        {
1373          mutt_message (_("Writing message to %s ..."), fname);
1374          mutt_expand_path (fname, sizeof (fname));
1375
1376          if (msg->content->next)
1377            msg->content = mutt_make_multipart (msg->content);
1378
1379          if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1380            msg->content = mutt_remove_multipart (msg->content);
1381          else
1382            mutt_message _("Message written.");
1383        }
1384        break;
1385
1386
1387
1388       case OP_COMPOSE_PGP_MENU:
1389         if (!(WithCrypto & APPLICATION_PGP))
1390           break;
1391         if ((WithCrypto & APPLICATION_SMIME)
1392             && msg->security & APPLICATION_SMIME)
1393         {
1394           if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1395                              M_YES) != M_YES)
1396           {
1397             mutt_clear_error ();
1398             break;
1399           }
1400           msg->security = 0;
1401         }
1402         msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1403         redraw_crypt_lines (msg);
1404         mutt_message_hook (NULL, msg, M_SEND2HOOK);
1405         break;
1406
1407
1408       case OP_FORGET_PASSPHRASE:
1409         crypt_forget_passphrase ();
1410         break;
1411
1412
1413       case OP_COMPOSE_SMIME_MENU:
1414         if (!(WithCrypto & APPLICATION_SMIME))
1415           break;
1416
1417         if ((WithCrypto & APPLICATION_PGP)
1418             && msg->security & APPLICATION_PGP)
1419         {
1420           if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1421                               M_YES) != M_YES)
1422           {
1423              mutt_clear_error ();
1424              break;
1425           }
1426           msg->security = 0;
1427         }
1428         msg->security = crypt_smime_send_menu(msg, &menu->redraw);
1429         redraw_crypt_lines (msg);
1430         mutt_message_hook (NULL, msg, M_SEND2HOOK);
1431         break;
1432
1433
1434 #ifdef MIXMASTER
1435       case OP_COMPOSE_MIX:
1436       
1437         mix_make_chain (&msg->chain, &menu->redraw);
1438         mutt_message_hook (NULL, msg, M_SEND2HOOK);
1439         break;
1440 #endif
1441
1442     }
1443
1444     /* Draw formated compose status line */
1445     if (menu->redraw & REDRAW_STATUS) 
1446     {
1447         compose_status_line (buf, sizeof (buf), menu, NONULL(ComposeFormat));
1448         CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
1449         SETCOLOR (MT_COLOR_STATUS);
1450         printw ("%-*.*s", COLS, COLS, buf);
1451         SETCOLOR (MT_COLOR_NORMAL);
1452         menu->redraw &= ~REDRAW_STATUS;
1453     }
1454   }
1455
1456   mutt_menuDestroy (&menu);
1457
1458   if (idxlen)
1459   {
1460     msg->content = idx[0]->content;
1461     for (i = 0; i < idxlen; i++)
1462     {
1463       idx[i]->content->aptr = NULL;
1464       FREE (&idx[i]);
1465     }
1466   }
1467   else
1468     msg->content = NULL;
1469
1470   FREE (&idx);
1471
1472   return (r);
1473 }
1474