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