make some functions a bit shorter.
[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 "mutt_idna.h"
41 #include "rfc1524.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 (LIST * 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_delete (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   mutt_free_body (&(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   size_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, size_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                        size_t fcclen, HEADER * cur)
512 {                               /* current message */
513   char helpstr[SHORT_STRING];
514   char buf[LONG_STRING];
515   char fname[_POSIX_PATH_MAX];
516   MUTTMENU *menu;
517   ATTACHPTR **idx = NULL;
518   short idxlen = 0;
519   short idxmax = 0;
520   int i, closed = 0;
521   int r = -1;                   /* return value */
522   int op = 0;
523   int loop = 1;
524   int fccSet = 0;               /* has the user edited the Fcc: field ? */
525   CONTEXT *ctx = NULL, *this = NULL;
526
527   /* Sort, SortAux could be changed in mutt_index_menu() */
528   int oldSort, oldSortAux;
529   struct stat st;
530
531 #ifdef USE_NNTP
532   int news = 0;                 /* is it a news article ? */
533
534   if (option (OPTNEWSSEND))
535     news++;
536 #endif
537
538   mutt_attach_init (msg->content);
539   idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
540
541   menu = mutt_new_menu ();
542   menu->menu = MENU_COMPOSE;
543   menu->offset = HDR_ATTACH;
544   menu->max = idxlen;
545   menu->make_entry = snd_entry;
546   menu->tag = mutt_tag_attach;
547   menu->data = idx;
548 #ifdef USE_NNTP
549   if (news)
550     menu->help =
551       mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
552                          ComposeNewsHelp);
553   else
554 #endif
555     menu->help =
556       mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
557                          ComposeHelp);
558
559   if (option (OPTMBOXPANE))
560     buffy_check (0);
561   while (loop) {
562 #ifdef USE_NNTP
563     unset_option (OPTNEWS);     /* for any case */
564 #endif
565     switch (op = mutt_menuLoop (menu)) {
566     case OP_REDRAW:
567       draw_envelope (msg, fcc);
568       menu->offset = HDR_ATTACH;
569       menu->pagelen = LINES - HDR_ATTACH - 2;
570       break;
571     case OP_COMPOSE_EDIT_FROM:
572       menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
573       mutt_message_hook (NULL, msg, M_SEND2HOOK);
574       break;
575     case OP_COMPOSE_EDIT_TO:
576 #ifdef USE_NNTP
577       if (!news) {
578 #endif
579         menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
580         mutt_message_hook (NULL, msg, M_SEND2HOOK);
581 #ifdef USE_NNTP
582       }
583 #endif
584       break;
585     case OP_COMPOSE_EDIT_BCC:
586 #ifdef USE_NNTP
587       if (!news) {
588 #endif
589         menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
590         mutt_message_hook (NULL, msg, M_SEND2HOOK);
591 #ifdef USE_NNTP
592       }
593 #endif
594       break;
595     case OP_COMPOSE_EDIT_CC:
596 #ifdef USE_NNTP
597       if (!news) {
598 #endif
599         menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
600         mutt_message_hook (NULL, msg, M_SEND2HOOK);
601 #ifdef USE_NNTP
602       }
603 #endif
604       break;
605 #ifdef USE_NNTP
606     case OP_COMPOSE_EDIT_NEWSGROUPS:
607       if (news) {
608         if (msg->env->newsgroups)
609           m_strcpy(buf, sizeof(buf), msg->env->newsgroups);
610         else
611           buf[0] = 0;
612         if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
613             && buf[0]) {
614           p_delete(&msg->env->newsgroups);
615           m_strrtrim(buf);
616           msg->env->newsgroups = m_strdup(skipspaces(buf));
617           move (HDR_TO, HDR_XOFFSET);
618           clrtoeol ();
619           if (msg->env->newsgroups)
620             printw ("%-*.*s", W, W, msg->env->newsgroups);
621         }
622       }
623       break;
624
625     case OP_COMPOSE_EDIT_FOLLOWUP_TO:
626       if (news) {
627         buf[0] = 0;
628         if (msg->env->followup_to)
629           m_strcpy(buf, sizeof(buf), msg->env->followup_to);
630         if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
631             && buf[0]) {
632           p_delete(&msg->env->followup_to);
633           m_strrtrim(buf);
634           msg->env->followup_to = m_strdup(skipspaces(buf));
635           move (HDR_CC, HDR_XOFFSET);
636           clrtoeol ();
637           if (msg->env->followup_to)
638             printw ("%-*.*s", W, W, msg->env->followup_to);
639         }
640       }
641       break;
642
643     case OP_COMPOSE_EDIT_X_COMMENT_TO:
644       if (news && option (OPTXCOMMENTTO)) {
645         buf[0] = 0;
646         if (msg->env->x_comment_to)
647           m_strcpy(buf, sizeof(buf), msg->env->x_comment_to);
648         if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
649             && buf[0]) {
650           p_delete(&msg->env->x_comment_to);
651           msg->env->x_comment_to = m_strdup(buf);
652           move (HDR_BCC, HDR_XOFFSET);
653           clrtoeol ();
654           if (msg->env->x_comment_to)
655             printw ("%-*.*s", W, W, msg->env->x_comment_to);
656         }
657       }
658       break;
659 #endif
660     case OP_COMPOSE_EDIT_SUBJECT:
661       if (msg->env->subject)
662         m_strcpy(buf, sizeof(buf), msg->env->subject);
663       else
664         buf[0] = 0;
665       if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
666         m_strreplace(&msg->env->subject, buf);
667         move (HDR_SUBJECT, HDR_XOFFSET + SW);
668         clrtoeol ();
669         if (msg->env->subject)
670           mutt_paddstr (W, msg->env->subject);
671       }
672       mutt_message_hook (NULL, msg, M_SEND2HOOK);
673       break;
674     case OP_COMPOSE_EDIT_REPLY_TO:
675       menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
676       mutt_message_hook (NULL, msg, M_SEND2HOOK);
677       break;
678     case OP_COMPOSE_EDIT_FCC:
679       m_strcpy(buf, sizeof(buf), fcc);
680       if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
681         m_strcpy(fcc, _POSIX_PATH_MAX, buf);
682         mutt_pretty_mailbox (fcc);
683         move (HDR_FCC, HDR_XOFFSET + SW);
684         mutt_paddstr (W, fcc);
685         fccSet = 1;
686       }
687       MAYBE_REDRAW (menu->redraw);
688       mutt_message_hook (NULL, msg, M_SEND2HOOK);
689       break;
690     case OP_COMPOSE_EDIT_MESSAGE:
691       if (Editor && !option (OPTEDITHDRS)) {
692         mutt_edit_file (Editor, msg->content->filename);
693         mutt_update_encoding (msg->content);
694         menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
695         mutt_message_hook (NULL, msg, M_SEND2HOOK);
696         break;
697       }
698       /* fall through */
699     case OP_COMPOSE_EDIT_HEADERS:
700       if ((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       mutt_update_encoding (msg->content);
714
715       /* attachments may have been added */
716       if (idxlen && idx[idxlen - 1]->content->next) {
717         for (i = 0; i < idxlen; i++)
718           p_delete(&idx[i]);
719         idxlen = 0;
720         idx =
721           mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
722                                 1);
723         menu->data = idx;
724         menu->max = idxlen;
725       }
726
727       menu->redraw = REDRAW_FULL;
728       mutt_message_hook (NULL, msg, M_SEND2HOOK);
729       break;
730
731
732
733     case OP_COMPOSE_ATTACH_KEY:
734       if (idxlen == idxmax) {
735         p_realloc(&idx, idxmax += 5);
736         menu->data = idx;
737       }
738
739       idx[idxlen] = p_new(ATTACHPTR, 1);
740       if ((idx[idxlen]->content =
741            crypt_pgp_make_key_attachment (NULL)) != NULL) {
742         update_idx (menu, idx, idxlen++);
743         menu->redraw |= REDRAW_INDEX;
744       }
745       else
746         p_delete(&idx[idxlen]);
747
748       menu->redraw |= REDRAW_STATUS;
749
750       if (option (OPTNEEDREDRAW)) {
751         menu->redraw = REDRAW_FULL;
752         unset_option (OPTNEEDREDRAW);
753       }
754
755       mutt_message_hook (NULL, msg, M_SEND2HOOK);
756       break;
757
758
759     case OP_COMPOSE_ATTACH_FILE:
760       {
761         char *prompt, **files;
762         int error, numfiles;
763
764         fname[0] = 0;
765         prompt = _("Attach file");
766         numfiles = 0;
767         files = NULL;
768
769         if (_mutt_enter_fname
770             (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
771              &numfiles) == -1 || *fname == '\0')
772           break;
773
774         if (idxlen + numfiles >= idxmax) {
775           p_realloc(&idx, idxmax += 5 + numfiles);
776           menu->data = idx;
777         }
778
779         error = 0;
780         if (numfiles > 1)
781           mutt_message _("Attaching selected files...");
782
783         for (i = 0; i < numfiles; i++) {
784           char *att = files[i];
785
786           idx[idxlen] = p_new(ATTACHPTR, 1);
787           idx[idxlen]->unowned = 1;
788           idx[idxlen]->content = mutt_make_file_attach (att);
789           if (idx[idxlen]->content != NULL)
790             update_idx (menu, idx, idxlen++);
791           else {
792             error = 1;
793             mutt_error (_("Unable to attach %s!"), att);
794             p_delete(&idx[idxlen]);
795           }
796         }
797
798         p_delete(&files);
799         if (!error)
800           mutt_clear_error ();
801
802         menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
803       }
804       mutt_message_hook (NULL, msg, M_SEND2HOOK);
805       break;
806
807     case OP_COMPOSE_ATTACH_MESSAGE:
808 #ifdef USE_NNTP
809     case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
810 #endif
811       {
812         char *prompt;
813         HEADER *h;
814
815         fname[0] = 0;
816         prompt = _("Open mailbox to attach message from");
817
818 #ifdef USE_NNTP
819         unset_option (OPTNEWS);
820         if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
821           if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
822             break;
823
824           prompt = _("Open newsgroup to attach message from");
825           set_option (OPTNEWS);
826         }
827 #endif
828
829         if (Context)
830 #ifdef USE_NNTP
831           if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
832 #endif
833           {
834             m_strcpy(fname, sizeof(fname), NONULL(Context->path));
835             mutt_pretty_mailbox (fname);
836           }
837
838         if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
839             == -1 || !fname[0])
840           break;
841
842 #ifdef USE_NNTP
843         if (option (OPTNEWS))
844           nntp_expand_path (fname, sizeof (fname),
845                             &CurrentNewsSrv->conn->account);
846         else
847 #endif
848           mutt_expand_path (fname, sizeof (fname));
849         if (mx_get_magic (fname) != M_IMAP)
850           if (mx_get_magic (fname) != M_POP)
851 #ifdef USE_NNTP
852             if (mx_get_magic (fname) != M_NNTP && !option (OPTNEWS))
853 #endif
854               /* check to make sure the file exists and is readable */
855               if (access (fname, R_OK) == -1) {
856                 mutt_perror (fname);
857                 break;
858               }
859
860         menu->redraw = REDRAW_FULL;
861
862         ctx = mx_open_mailbox (fname, M_READONLY, NULL);
863         if (ctx == NULL) {
864           mutt_perror (fname);
865           break;
866         }
867
868         if (!ctx->msgcount) {
869           mx_close_mailbox (ctx, NULL);
870           p_delete(&ctx);
871           mutt_error _("No messages in that folder.");
872
873           break;
874         }
875
876         this = Context;         /* remember current folder and sort methods */
877         oldSort = Sort;
878         oldSortAux = SortAux;
879
880         Context = ctx;
881         set_option (OPTATTACHMSG);
882         mutt_message _("Tag the messages you want to attach!");
883
884         closed = mutt_index_menu ();
885         unset_option (OPTATTACHMSG);
886
887         if (!Context) {
888           /* go back to the folder we started from */
889           Context = this;
890           /* Restore old $sort and $sort_aux */
891           Sort = oldSort;
892           SortAux = oldSortAux;
893           menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
894           break;
895         }
896
897         if (idxlen + Context->tagged >= idxmax) {
898           p_realloc(&idx, idxmax += 5 + Context->tagged);
899           menu->data = idx;
900         }
901
902         for (i = 0; i < Context->msgcount; i++) {
903           h = Context->hdrs[i];
904           if (h->tagged) {
905             idx[idxlen] = p_new(ATTACHPTR, 1);
906             idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
907             if (idx[idxlen]->content != NULL)
908               update_idx (menu, idx, idxlen++);
909             else {
910               mutt_error _("Unable to attach!");
911
912               p_delete(&idx[idxlen]);
913             }
914           }
915         }
916         menu->redraw |= REDRAW_FULL;
917
918         if (closed == OP_QUIT)
919           mx_close_mailbox (Context, NULL);
920         else
921           mx_fastclose_mailbox (Context);
922         p_delete(&Context);
923
924         /* go back to the folder we started from */
925         Context = this;
926         /* Restore old $sort and $sort_aux */
927         Sort = oldSort;
928         SortAux = oldSortAux;
929       }
930       mutt_message_hook (NULL, msg, M_SEND2HOOK);
931       break;
932
933     case OP_DELETE:
934       CHECK_COUNT;
935       if (idx[menu->current]->unowned)
936         idx[menu->current]->content->unlink = 0;
937       if (delete_attachment (menu, &idxlen, menu->current) == -1)
938         break;
939       mutt_update_tree (idx, idxlen);
940       if (idxlen) {
941         if (menu->current > idxlen - 1)
942           menu->current = idxlen - 1;
943       }
944       else
945         menu->current = 0;
946
947       if (menu->current == 0)
948         msg->content = idx[0]->content;
949
950       menu->redraw |= REDRAW_STATUS;
951       mutt_message_hook (NULL, msg, M_SEND2HOOK);
952       break;
953
954 #define CURRENT idx[menu->current]->content
955
956     case OP_COMPOSE_TOGGLE_RECODE:
957       {
958         CHECK_COUNT;
959         if (!mutt_is_text_part (CURRENT)) {
960           mutt_error (_("Recoding only affects text attachments."));
961           break;
962         }
963         CURRENT->noconv = !CURRENT->noconv;
964         if (CURRENT->noconv)
965           mutt_message (_("The current attachment won't be converted."));
966         else
967           mutt_message (_("The current attachment will be converted."));
968         menu->redraw = REDRAW_CURRENT;
969         mutt_message_hook (NULL, msg, M_SEND2HOOK);
970         break;
971       }
972 #undef CURRENT
973
974     case OP_COMPOSE_EDIT_DESCRIPTION:
975       CHECK_COUNT;
976       m_strcpy(buf, sizeof(buf),
977                NONULL(idx[menu->current]->content->description));
978       /* header names should not be translated */
979       if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) {
980         m_strreplace(&idx[menu->current]->content->description, buf);
981         menu->redraw = REDRAW_CURRENT;
982       }
983       mutt_message_hook (NULL, msg, M_SEND2HOOK);
984       break;
985
986     case OP_COMPOSE_UPDATE_ENCODING:
987       CHECK_COUNT;
988       if (menu->tagprefix) {
989         BODY *top;
990
991         for (top = msg->content; top; top = top->next) {
992           if (top->tagged)
993             mutt_update_encoding (top);
994         }
995         menu->redraw = REDRAW_FULL;
996       }
997       else {
998         mutt_update_encoding (idx[menu->current]->content);
999         menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1000       }
1001       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1002       break;
1003
1004     case OP_COMPOSE_TOGGLE_DISPOSITION:
1005       /* toggle the content-disposition between inline/attachment */
1006       idx[menu->current]->content->disposition =
1007         (idx[menu->current]->content->disposition ==
1008          DISPINLINE) ? DISPATTACH : DISPINLINE;
1009       menu->redraw = REDRAW_CURRENT;
1010       break;
1011
1012     case OP_EDIT_TYPE:
1013       CHECK_COUNT;
1014       {
1015         mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
1016
1017         /* this may have been a change to text/something */
1018         mutt_update_encoding (idx[menu->current]->content);
1019
1020         menu->redraw = REDRAW_CURRENT;
1021       }
1022       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1023       break;
1024
1025     case OP_COMPOSE_EDIT_ENCODING:
1026       CHECK_COUNT;
1027       m_strcpy(buf, sizeof(buf),
1028                ENCODING(idx[menu->current]->content->encoding));
1029       if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
1030                           sizeof (buf), 0) == 0 && buf[0]) {
1031         if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) {
1032           idx[menu->current]->content->encoding = i;
1033           menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1034           mutt_clear_error ();
1035         }
1036         else
1037           mutt_error _("Invalid encoding.");
1038       }
1039       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1040       break;
1041
1042     case OP_COMPOSE_SEND_MESSAGE:
1043
1044       /* Note: We don't invoke send2-hook here, since we want to leave
1045        * users an opportunity to change settings from the ":" prompt.
1046        */
1047
1048       if (check_attachments (idx, idxlen) != 0) {
1049         menu->redraw = REDRAW_FULL;
1050         break;
1051       }
1052
1053
1054 #ifdef MIXMASTER
1055       if (msg->chain && mix_check_message (msg) != 0)
1056         break;
1057 #endif
1058
1059       if (!fccSet && *fcc) {
1060         if ((i = query_quadoption (OPT_COPY,
1061                                    _("Save a copy of this message?"))) == -1)
1062           break;
1063         else if (i == M_NO)
1064           *fcc = 0;
1065       }
1066
1067       loop = 0;
1068       r = 0;
1069       break;
1070
1071     case OP_COMPOSE_EDIT_FILE:
1072       CHECK_COUNT;
1073       mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename);
1074       mutt_update_encoding (idx[menu->current]->content);
1075       menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1076       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1077       break;
1078
1079     case OP_COMPOSE_TOGGLE_UNLINK:
1080       CHECK_COUNT;
1081       idx[menu->current]->content->unlink =
1082         !idx[menu->current]->content->unlink;
1083
1084 #if 0
1085       /* OPTRESOLVE is otherwise ignored on this menu.
1086        * Where's the bug?
1087        */
1088
1089       if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
1090         menu->current++;
1091 # endif
1092       menu->redraw = REDRAW_INDEX;
1093       /* No send2hook since this doesn't change the message. */
1094       break;
1095
1096     case OP_COMPOSE_GET_ATTACHMENT:
1097       CHECK_COUNT;
1098       if (menu->tagprefix) {
1099         BODY *top;
1100
1101         for (top = msg->content; top; top = top->next) {
1102           if (top->tagged)
1103             mutt_get_tmp_attachment (top);
1104         }
1105         menu->redraw = REDRAW_FULL;
1106       }
1107       else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0)
1108         menu->redraw = REDRAW_CURRENT;
1109
1110       /* No send2hook since this doesn't change the message. */
1111       break;
1112
1113     case OP_COMPOSE_RENAME_FILE:
1114       CHECK_COUNT;
1115       m_strcpy(fname, sizeof(fname), idx[menu->current]->content->filename);
1116       mutt_pretty_mailbox (fname);
1117       if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1118           == 0 && fname[0]) {
1119         if (stat (idx[menu->current]->content->filename, &st) == -1) {
1120           mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1121           break;
1122         }
1123
1124         mutt_expand_path (fname, sizeof (fname));
1125         if (mutt_rename_file (idx[menu->current]->content->filename, fname))
1126           break;
1127
1128         m_strreplace(&idx[menu->current]->content->filename, fname);
1129         menu->redraw = REDRAW_CURRENT;
1130
1131         if (idx[menu->current]->content->stamp >= st.st_mtime)
1132           mutt_stamp_attachment (idx[menu->current]->content);
1133
1134       }
1135       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1136       break;
1137
1138     case OP_COMPOSE_NEW_MIME:
1139       {
1140         char type[STRING];
1141         char *p;
1142         int itype;
1143         FILE *fp;
1144
1145         CLEARLINE (LINES - 1);
1146         fname[0] = 0;
1147         if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1148             != 0 || !fname[0])
1149           continue;
1150         mutt_expand_path (fname, sizeof (fname));
1151
1152         /* Call to lookup_mime_type () ?  maybe later */
1153         type[0] = 0;
1154         if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1155             || !type[0])
1156           continue;
1157
1158         if (!(p = strchr (type, '/'))) {
1159           mutt_error _("Content-Type is of the form base/sub");
1160
1161           continue;
1162         }
1163         *p++ = 0;
1164         if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) {
1165           mutt_error (_("Unknown Content-Type %s"), type);
1166           continue;
1167         }
1168         if (idxlen == idxmax) {
1169           p_realloc(&idx, idxmax += 5);
1170           menu->data = idx;
1171         }
1172
1173         idx[idxlen] = p_new(ATTACHPTR, 1);
1174         /* Touch the file */
1175         if (!(fp = safe_fopen (fname, "w"))) {
1176           mutt_error (_("Can't create file %s"), fname);
1177           p_delete(&idx[idxlen]);
1178           continue;
1179         }
1180         fclose (fp);
1181
1182         if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) {
1183           mutt_error
1184             _("What we have here is a failure to make an attachment");
1185           continue;
1186         }
1187         update_idx (menu, idx, idxlen++);
1188
1189         idx[menu->current]->content->type = itype;
1190         m_strreplace(&idx[menu->current]->content->subtype, p);
1191         idx[menu->current]->content->unlink = 1;
1192         menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1193
1194         if (mutt_compose_attachment (idx[menu->current]->content)) {
1195           mutt_update_encoding (idx[menu->current]->content);
1196           menu->redraw = REDRAW_FULL;
1197         }
1198       }
1199       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1200       break;
1201
1202     case OP_COMPOSE_EDIT_MIME:
1203       CHECK_COUNT;
1204       if (mutt_edit_attachment (idx[menu->current]->content)) {
1205         mutt_update_encoding (idx[menu->current]->content);
1206         menu->redraw = REDRAW_FULL;
1207       }
1208       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1209       break;
1210
1211     case OP_VIEW_ATTACH:
1212     case OP_DISPLAY_HEADERS:
1213       CHECK_COUNT;
1214       mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen,
1215                                 NULL, 0);
1216       menu->redraw = REDRAW_FULL;
1217       /* no send2hook, since this doesn't modify the message */
1218       break;
1219
1220     case OP_SAVE:
1221       CHECK_COUNT;
1222       mutt_save_attachment_list (NULL, menu->tagprefix,
1223                                  menu->tagprefix ? msg->content : idx[menu->
1224                                                                       current]->
1225                                  content, NULL, menu);
1226       MAYBE_REDRAW (menu->redraw);
1227       /* no send2hook, since this doesn't modify the message */
1228       break;
1229
1230     case OP_PRINT:
1231       CHECK_COUNT;
1232       mutt_print_attachment_list (NULL, menu->tagprefix,
1233                                   menu->tagprefix ? msg->content : idx[menu->
1234                                                                        current]->
1235                                   content);
1236       /* no send2hook, since this doesn't modify the message */
1237       break;
1238
1239     case OP_PIPE:
1240     case OP_FILTER:
1241       CHECK_COUNT;
1242       mutt_pipe_attachment_list (NULL, menu->tagprefix,
1243                                  menu->tagprefix ? msg->content : idx[menu->
1244                                                                       current]->
1245                                  content, op == OP_FILTER);
1246       if (op == OP_FILTER)      /* cte might have changed */
1247         menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1248       menu->redraw |= REDRAW_STATUS;
1249       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1250       break;
1251
1252     case OP_EXIT:
1253       if ((i =
1254            query_quadoption (OPT_POSTPONE,
1255                              _("Postpone this message?"))) == M_NO) {
1256         while (idxlen-- > 0) {
1257           /* avoid freeing other attachments */
1258           idx[idxlen]->content->next = NULL;
1259           idx[idxlen]->content->parts = NULL;
1260           if (idx[idxlen]->unowned)
1261             idx[idxlen]->content->unlink = 0;
1262           mutt_free_body (&idx[idxlen]->content);
1263           p_delete(&idx[idxlen]->tree);
1264           p_delete(&idx[idxlen]);
1265         }
1266         p_delete(&idx);
1267         idxlen = 0;
1268         idxmax = 0;
1269         r = -1;
1270         loop = 0;
1271         break;
1272       }
1273       else if (i == -1)
1274         break;                  /* abort */
1275
1276       /* fall through to postpone! */
1277
1278     case OP_COMPOSE_POSTPONE_MESSAGE:
1279
1280       if (check_attachments (idx, idxlen) != 0) {
1281         menu->redraw = REDRAW_FULL;
1282         break;
1283       }
1284
1285       loop = 0;
1286       r = 1;
1287       break;
1288
1289     case OP_COMPOSE_ISPELL:
1290       endwin ();
1291       snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1292                 msg->content->filename);
1293       if (mutt_system (buf) == -1)
1294         mutt_error (_("Error running \"%s\"!"), buf);
1295       else {
1296         mutt_update_encoding (msg->content);
1297         menu->redraw |= REDRAW_STATUS;
1298       }
1299       break;
1300
1301     case OP_COMPOSE_WRITE_MESSAGE:
1302
1303       fname[0] = '\0';
1304       if (Context) {
1305         m_strcpy(fname, sizeof(fname), NONULL(Context->path));
1306         mutt_pretty_mailbox (fname);
1307       }
1308       if (idxlen)
1309         msg->content = idx[0]->content;
1310       if (mutt_enter_fname
1311           (_("Write message to mailbox"), fname, sizeof (fname),
1312            &menu->redraw, 1) != -1 && fname[0]) {
1313         mutt_message (_("Writing message to %s ..."), fname);
1314         mutt_expand_path (fname, sizeof (fname));
1315
1316         if (msg->content->next)
1317           msg->content = mutt_make_multipart (msg->content);
1318
1319         if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1320           msg->content = mutt_remove_multipart (msg->content);
1321         else
1322           mutt_message _("Message written.");
1323       }
1324       break;
1325
1326
1327
1328     case OP_COMPOSE_PGP_MENU:
1329       if (msg->security & APPLICATION_SMIME) {
1330         if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1331                           M_YES) != M_YES) {
1332           mutt_clear_error ();
1333           break;
1334         }
1335         msg->security = 0;
1336       }
1337       msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1338       redraw_crypt_lines (msg);
1339       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1340       break;
1341
1342
1343     case OP_FORGET_PASSPHRASE:
1344       crypt_forget_passphrase ();
1345       break;
1346
1347
1348     case OP_COMPOSE_SMIME_MENU:
1349       if (msg->security & APPLICATION_PGP) {
1350         if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1351                           M_YES) != M_YES) {
1352           mutt_clear_error ();
1353           break;
1354         }
1355         msg->security = 0;
1356       }
1357       msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1358       redraw_crypt_lines (msg);
1359       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1360       break;
1361
1362
1363 #ifdef MIXMASTER
1364     case OP_COMPOSE_MIX:
1365
1366       mix_make_chain (&msg->chain, &menu->redraw);
1367       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1368       break;
1369 #endif
1370
1371     }
1372
1373     /* Draw formated compose status line */
1374     if (menu->redraw & REDRAW_STATUS) {
1375       compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1376       CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1377       SETCOLOR (MT_COLOR_STATUS);
1378       move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, SW);
1379       printw ("%-*.*s", COLS-SW, COLS-SW, buf);
1380       SETCOLOR (MT_COLOR_NORMAL);
1381       menu->redraw &= ~REDRAW_STATUS;
1382     }
1383   }
1384
1385   mutt_menuDestroy (&menu);
1386
1387   if (idxlen) {
1388     msg->content = idx[0]->content;
1389     for (i = 0; i < idxlen; i++) {
1390       idx[i]->content->aptr = NULL;
1391       p_delete(&idx[i]);
1392     }
1393   }
1394   else
1395     msg->content = NULL;
1396
1397   p_delete(&idx);
1398
1399   return (r);
1400 }