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