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