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