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