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