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