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