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