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