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