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