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 "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 "lib/mem.h"
40 #include "lib/intl.h"
41 #include "lib/str.h"
42
43 #include <errno.h>
44 #include <string.h>
45 #include <sys/stat.h>
46 #include <sys/wait.h>
47 #include <unistd.h>
48 #include <stdlib.h>
49
50 static const char *There_are_no_attachments = N_("There are no attachments.");
51
52 #define CHECK_COUNT if (idxlen == 0) { mutt_error _(There_are_no_attachments); break; }
53
54
55
56 enum {
57   HDR_FROM = 1,
58   HDR_TO,
59   HDR_CC,
60   HDR_BCC,
61   HDR_SUBJECT,
62   HDR_REPLYTO,
63   HDR_FCC,
64
65 #ifdef MIXMASTER
66   HDR_MIX,
67 #endif
68
69   HDR_CRYPT,
70   HDR_CRYPTINFO,
71
72 #ifdef USE_NNTP
73   HDR_NEWSGROUPS,
74   HDR_FOLLOWUPTO,
75   HDR_XCOMMENTTO,
76 #endif
77
78 #ifndef USE_NNTP
79   HDR_ATTACH = (HDR_FCC + 5)    /* where to start printing the attachments */
80 #else
81   HDR_ATTACH = (HDR_FCC + 7)
82 #endif
83 };
84
85 #define HDR_XOFFSET 14
86 #define TITLE_FMT "%14s"        /* Used for Prompts, which are ASCII */
87 #define W (COLS - HDR_XOFFSET - SidebarWidth)
88
89 static char *Prompts[] = {
90   "From: ",
91   "To: ",
92   "Cc: ",
93   "Bcc: ",
94   "Subject: ",
95   "Reply-To: ",
96   "Fcc: "
97 #ifdef USE_NNTP
98 #ifdef MIXMASTER
99     , ""
100 #endif
101     , "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: "
102 #endif
103 };
104
105 static struct mapping_t ComposeHelp[] = {
106   {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
107   {N_("Abort"), OP_EXIT},
108   {"To", OP_COMPOSE_EDIT_TO},
109   {"CC", OP_COMPOSE_EDIT_CC},
110   {"Subj", OP_COMPOSE_EDIT_SUBJECT},
111   {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
112   {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
113   {N_("Help"), OP_HELP},
114   {NULL}
115 };
116
117 #ifdef USE_NNTP
118 static struct mapping_t ComposeNewsHelp[] = {
119   {N_("Send"), OP_COMPOSE_SEND_MESSAGE},
120   {N_("Abort"), OP_EXIT},
121   {"Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS},
122   {"Subj", OP_COMPOSE_EDIT_SUBJECT},
123   {N_("Attach file"), OP_COMPOSE_ATTACH_FILE},
124   {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION},
125   {N_("Help"), OP_HELP},
126   {NULL}
127 };
128 #endif
129
130 static void snd_entry (char *b, size_t blen, MUTTMENU * menu, int num)
131 {
132   mutt_FormatString (b, blen, NONULL (AttachFormat), mutt_attach_fmt,
133                      (unsigned long) (((ATTACHPTR **) menu->data)[num]),
134                      M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
135 }
136
137
138
139 #include "mutt_crypt.h"
140
141 static void redraw_crypt_lines (HEADER * msg)
142 {
143   int off = 0;
144
145   if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME)) {
146     if (!msg->security)
147       mvaddstr (HDR_CRYPT, SidebarWidth, "    Security: ");
148     else if (msg->security & APPLICATION_SMIME)
149       mvaddstr (HDR_CRYPT, SidebarWidth, "      S/MIME: ");
150     else if (msg->security & APPLICATION_PGP)
151       mvaddstr (HDR_CRYPT, SidebarWidth, "         PGP: ");
152   }
153   else if ((WithCrypto & APPLICATION_SMIME))
154     mvaddstr (HDR_CRYPT, SidebarWidth, "      S/MIME: ");
155   else if ((WithCrypto & APPLICATION_PGP))
156     mvaddstr (HDR_CRYPT, SidebarWidth, "         PGP: ");
157   else
158     return;
159
160   if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
161     addstr (_("Sign, Encrypt"));
162   else if (msg->security & ENCRYPT)
163     addstr (_("Encrypt"));
164   else if (msg->security & SIGN)
165     addstr (_("Sign"));
166   else
167     addstr (_("Clear"));
168
169   if ((WithCrypto & APPLICATION_PGP))
170     if ((msg->security & APPLICATION_PGP)
171         && (msg->security & (ENCRYPT | SIGN))) {
172       if ((msg->security & INLINE))
173         addstr (_(" (inline)"));
174       else
175         addstr (_(" (PGP/MIME)"));
176     }
177   clrtoeol ();
178
179   move (HDR_CRYPTINFO, SidebarWidth);
180   clrtoeol ();
181   if ((WithCrypto & APPLICATION_PGP)
182       && msg->security & APPLICATION_PGP && msg->security & SIGN)
183     printw ("%s%s", _("     sign as: "),
184             PgpSignAs ? PgpSignAs : _("<default>"));
185
186   if ((WithCrypto & APPLICATION_SMIME)
187       && msg->security & APPLICATION_SMIME && msg->security & SIGN) {
188     printw ("%s%s", _("     sign as: "),
189             SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
190   }
191
192   if ((WithCrypto & APPLICATION_SMIME)
193       && (msg->security & APPLICATION_SMIME)
194       && (msg->security & ENCRYPT)
195       && SmimeCryptAlg && *SmimeCryptAlg) {
196     mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "),
197               NONULL (SmimeCryptAlg));
198     off = 20;
199   }
200 }
201
202
203 #ifdef MIXMASTER
204
205 static void redraw_mix_line (LIST * chain)
206 {
207   int c;
208   char *t;
209
210   mvaddstr (HDR_MIX, SidebarWidth, "         Mix: ");
211
212   if (!chain) {
213     addstr ("<no chain defined>");
214     clrtoeol ();
215     return;
216   }
217
218   for (c = 12; chain; chain = chain->next) {
219     t = chain->data;
220     if (t && t[0] == '0' && t[1] == '\0')
221       t = "<random>";
222
223     if (c + mutt_strlen (t) + 2 >= COLS - SidebarWidth)
224       break;
225
226     addstr (NONULL (t));
227     if (chain->next)
228       addstr (", ");
229
230     c += mutt_strlen (t) + 2;
231   }
232 }
233 #endif /* MIXMASTER */
234
235 static int check_attachments (ATTACHPTR ** idx, short idxlen)
236 {
237   int i, r;
238   struct stat st;
239   char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
240
241   for (i = 0; i < idxlen; i++) {
242     strfcpy (pretty, idx[i]->content->filename, sizeof (pretty));
243     if (stat (idx[i]->content->filename, &st) != 0) {
244       mutt_pretty_mailbox (pretty);
245       mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1);
246       return -1;
247     }
248
249     if (idx[i]->content->stamp < st.st_mtime) {
250       mutt_pretty_mailbox (pretty);
251       snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"),
252                 pretty, i + 1);
253
254       if ((r = mutt_yesorno (msg, M_YES)) == M_YES)
255         mutt_update_encoding (idx[i]->content);
256       else if (r == -1)
257         return -1;
258     }
259   }
260
261   return 0;
262 }
263
264 static void draw_envelope_addr (int line, ADDRESS * addr)
265 {
266   char buf[STRING];
267
268   buf[0] = 0;
269   rfc822_write_address (buf, sizeof (buf), addr, 1);
270   mvprintw (line, SidebarWidth, TITLE_FMT, Prompts[line - 1]);
271   mutt_paddstr (W, buf);
272 }
273
274 static void draw_envelope (HEADER * msg, char *fcc)
275 {
276   draw_envelope_addr (HDR_FROM, msg->env->from);
277 #ifdef USE_NNTP
278   if (!option (OPTNEWSSEND)) {
279 #endif
280     draw_envelope_addr (HDR_TO, msg->env->to);
281     draw_envelope_addr (HDR_CC, msg->env->cc);
282     draw_envelope_addr (HDR_BCC, msg->env->bcc);
283 #ifdef USE_NNTP
284   }
285   else {
286     mvprintw (HDR_TO, SidebarWidth, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]);
287     mutt_paddstr (W, NONULL (msg->env->newsgroups));
288     mvprintw (HDR_CC, SidebarWidth, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]);
289     mutt_paddstr (W, NONULL (msg->env->followup_to));
290     if (option (OPTXCOMMENTTO)) {
291       mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]);
292       mutt_paddstr (W, NONULL (msg->env->x_comment_to));
293     }
294   }
295 #endif
296   mvprintw (HDR_SUBJECT, SidebarWidth, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
297   mutt_paddstr (W, NONULL (msg->env->subject));
298   draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
299   mvprintw (HDR_FCC, SidebarWidth, TITLE_FMT, Prompts[HDR_FCC - 1]);
300   mutt_paddstr (W, fcc);
301
302   if (WithCrypto)
303     redraw_crypt_lines (msg);
304
305 #ifdef MIXMASTER
306   redraw_mix_line (msg->chain);
307 #endif
308
309   SETCOLOR (MT_COLOR_STATUS);
310   mvaddstr (HDR_ATTACH - 1, SidebarWidth, _("-- Attachments"));
311   BKGDSET (MT_COLOR_STATUS);
312   clrtoeol ();
313
314   BKGDSET (MT_COLOR_NORMAL);
315   SETCOLOR (MT_COLOR_NORMAL);
316 }
317
318 static int edit_address_list (int line, ADDRESS ** addr)
319 {
320   char buf[HUGE_STRING] = "";   /* needs to be large for alias expansion */
321   char *err = NULL;
322
323   mutt_addrlist_to_local (*addr);
324   rfc822_write_address (buf, sizeof (buf), *addr, 0);
325   if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) {
326     rfc822_free_address (addr);
327     *addr = mutt_parse_adrlist (*addr, buf);
328     *addr = mutt_expand_aliases (*addr);
329   }
330
331   if (option (OPTNEEDREDRAW)) {
332     unset_option (OPTNEEDREDRAW);
333     return (REDRAW_FULL);
334   }
335
336   if (mutt_addrlist_to_idna (*addr, &err) != 0) {
337     mutt_error (_("Warning: '%s' is a bad IDN."), err);
338     mutt_refresh ();
339     FREE (&err);
340   }
341
342   /* redraw the expanded list so the user can see the result */
343   buf[0] = 0;
344   rfc822_write_address (buf, sizeof (buf), *addr, 1);
345   move (line, HDR_XOFFSET + SidebarWidth);
346   mutt_paddstr (W, buf);
347
348   return 0;
349 }
350
351 static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
352 {
353   ATTACHPTR **idx = (ATTACHPTR **) menu->data;
354   int y;
355
356   menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
357
358   if (x == 0 && menu->max == 1) {
359     mutt_error _("You may not delete the only attachment.");
360
361     idx[x]->content->tagged = 0;
362     return (-1);
363   }
364
365   for (y = 0; y < *idxlen; y++) {
366     if (idx[y]->content->next == idx[x]->content) {
367       idx[y]->content->next = idx[x]->content->next;
368       break;
369     }
370   }
371
372   idx[x]->content->next = NULL;
373   idx[x]->content->parts = NULL;
374   mutt_free_body (&(idx[x]->content));
375   FREE (&idx[x]->tree);
376   FREE (&idx[x]);
377   for (; x < *idxlen - 1; x++)
378     idx[x] = idx[x + 1];
379   menu->max = --(*idxlen);
380
381   return (0);
382 }
383
384 static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen)
385 {
386   idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0;
387   if (idxlen)
388     idx[idxlen - 1]->content->next = idx[idxlen]->content;
389   idx[idxlen]->content->aptr = idx[idxlen];
390   menu->current = idxlen++;
391   mutt_update_tree (idx, idxlen);
392   menu->max = idxlen;
393   return;
394 }
395
396
397 /* 
398  * cum_attachs_size: Cumulative Attachments Size
399  *
400  * Returns the total number of bytes used by the attachments in the
401  * attachment list _after_ content-transfer-encodings have been
402  * applied.
403  * 
404  */
405
406 static unsigned long cum_attachs_size (MUTTMENU * menu)
407 {
408   size_t s;
409   unsigned short i;
410   ATTACHPTR **idx = menu->data;
411   CONTENT *info;
412   BODY *b;
413
414   for (i = 0, s = 0; i < menu->max; i++) {
415     b = idx[i]->content;
416
417     if (!b->content)
418       b->content = mutt_get_content_info (b->filename, b);
419
420     if ((info = b->content)) {
421       switch (b->encoding) {
422       case ENCQUOTEDPRINTABLE:
423         s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
424         break;
425       case ENCBASE64:
426         s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
427         break;
428       default:
429         s += info->lobin + info->hibin + info->ascii + info->crlf;
430         break;
431       }
432     }
433   }
434
435   return s;
436 }
437
438 /* prototype for use below */
439 static void compose_status_line (char *buf, size_t buflen, MUTTMENU * menu,
440                                  const char *p);
441
442 /*
443  * compose_format_str()
444  *
445  * %a = total number of attachments 
446  * %h = hostname  [option]
447  * %l = approx. length of current message (in bytes) 
448  * %v = Mutt version 
449  *
450  * This function is similar to status_format_str().  Look at that function for
451  * help when modifying this function.
452  */
453
454 static const char *compose_format_str (char *buf, size_t buflen, char op,
455                                        const char *src, const char *prefix,
456                                        const char *ifstring,
457                                        const char *elsestring,
458                                        unsigned long data, format_flag flags)
459 {
460   char fmt[SHORT_STRING], tmp[SHORT_STRING];
461   int optional = (flags & M_FORMAT_OPTIONAL);
462   MUTTMENU *menu = (MUTTMENU *) data;
463
464   *buf = 0;
465   switch (op) {
466   case 'a':                    /* total number of attachments */
467     snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
468     snprintf (buf, buflen, fmt, menu->max);
469     break;
470
471   case 'h':                    /* hostname */
472     snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
473     snprintf (buf, buflen, fmt, NONULL (Hostname));
474     break;
475
476   case 'l':                    /* approx length of current message in bytes */
477     snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
478     mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0);
479     snprintf (buf, buflen, fmt, tmp);
480     break;
481
482   case 'v':
483     snprintf (fmt, sizeof (fmt), "Mutt-ng %%s");
484     snprintf (buf, buflen, fmt, MUTT_VERSION);
485     break;
486
487   case 0:
488     *buf = 0;
489     return (src);
490
491   default:
492     snprintf (buf, buflen, "%%%s%c", prefix, op);
493     break;
494   }
495
496   if (optional)
497     compose_status_line (buf, buflen, menu, ifstring);
498   else if (flags & M_FORMAT_OPTIONAL)
499     compose_status_line (buf, buflen, menu, elsestring);
500
501   return (src);
502 }
503
504 static void compose_status_line (char *buf, size_t buflen, MUTTMENU * menu,
505                                  const char *p)
506 {
507   mutt_FormatString (buf, buflen, p, compose_format_str,
508                      (unsigned long) menu, 0);
509 }
510
511
512 /* return values:
513  *
514  * 1    message should be postponed
515  * 0    normal exit
516  * -1   abort message
517  */
518 int mutt_compose_menu (HEADER * msg,    /* structure for new message */
519                        char *fcc,       /* where to save a copy of the message */
520                        size_t fcclen, HEADER * cur)
521 {                               /* current message */
522   char helpstr[SHORT_STRING];
523   char buf[LONG_STRING];
524   char fname[_POSIX_PATH_MAX];
525   MUTTMENU *menu;
526   ATTACHPTR **idx = NULL;
527   short idxlen = 0;
528   short idxmax = 0;
529   int i, close = 0;
530   int r = -1;                   /* return value */
531   int op = 0;
532   int loop = 1;
533   int fccSet = 0;               /* has the user edited the Fcc: field ? */
534   CONTEXT *ctx = NULL, *this = NULL;
535
536   /* Sort, SortAux could be changed in mutt_index_menu() */
537   int oldSort, oldSortAux;
538   struct stat st;
539
540 #ifdef USE_NNTP
541   int news = 0;                 /* is it a news article ? */
542
543   if (option (OPTNEWSSEND))
544     news++;
545 #endif
546
547   mutt_attach_init (msg->content);
548   idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
549
550   menu = mutt_new_menu ();
551   menu->menu = MENU_COMPOSE;
552   menu->offset = HDR_ATTACH;
553   menu->max = idxlen;
554   menu->make_entry = snd_entry;
555   menu->tag = mutt_tag_attach;
556   menu->data = idx;
557 #ifdef USE_NNTP
558   if (news)
559     menu->help =
560       mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
561                          ComposeNewsHelp);
562   else
563 #endif
564     menu->help =
565       mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE,
566                          ComposeHelp);
567
568   if (option (OPTMBOXPANE))
569     mutt_buffy_check (1);
570   while (loop) {
571 #ifdef USE_NNTP
572     unset_option (OPTNEWS);     /* for any case */
573 #endif
574     switch (op = mutt_menuLoop (menu)) {
575     case OP_REDRAW:
576       draw_envelope (msg, fcc);
577       menu->offset = HDR_ATTACH;
578       menu->pagelen = LINES - HDR_ATTACH - 2;
579       break;
580     case OP_COMPOSE_EDIT_FROM:
581       menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
582       mutt_message_hook (NULL, msg, M_SEND2HOOK);
583       break;
584     case OP_COMPOSE_EDIT_TO:
585 #ifdef USE_NNTP
586       if (!news) {
587 #endif
588         menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
589         mutt_message_hook (NULL, msg, M_SEND2HOOK);
590 #ifdef USE_NNTP
591       }
592 #endif
593       break;
594     case OP_COMPOSE_EDIT_BCC:
595 #ifdef USE_NNTP
596       if (!news) {
597 #endif
598         menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
599         mutt_message_hook (NULL, msg, M_SEND2HOOK);
600 #ifdef USE_NNTP
601       }
602 #endif
603       break;
604     case OP_COMPOSE_EDIT_CC:
605 #ifdef USE_NNTP
606       if (!news) {
607 #endif
608         menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
609         mutt_message_hook (NULL, msg, M_SEND2HOOK);
610 #ifdef USE_NNTP
611       }
612 #endif
613       break;
614 #ifdef USE_NNTP
615     case OP_COMPOSE_EDIT_NEWSGROUPS:
616       if (news) {
617         if (msg->env->newsgroups)
618           strfcpy (buf, msg->env->newsgroups, sizeof (buf));
619         else
620           buf[0] = 0;
621         if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
622             && buf[0]) {
623           FREE (&msg->env->newsgroups);
624           mutt_remove_trailing_ws (buf);
625           msg->env->newsgroups = safe_strdup (mutt_skip_whitespace (buf));
626           move (HDR_TO, HDR_XOFFSET);
627           clrtoeol ();
628           if (msg->env->newsgroups)
629             printw ("%-*.*s", W, W, msg->env->newsgroups);
630         }
631       }
632       break;
633
634     case OP_COMPOSE_EDIT_FOLLOWUP_TO:
635       if (news) {
636         buf[0] = 0;
637         if (msg->env->followup_to)
638           strfcpy (buf, msg->env->followup_to, sizeof (buf));
639         if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
640             && buf[0]) {
641           FREE (&msg->env->followup_to);
642           mutt_remove_trailing_ws (buf);
643           msg->env->followup_to = safe_strdup (mutt_skip_whitespace (buf));
644           move (HDR_CC, HDR_XOFFSET);
645           clrtoeol ();
646           if (msg->env->followup_to)
647             printw ("%-*.*s", W, W, msg->env->followup_to);
648         }
649       }
650       break;
651
652     case OP_COMPOSE_EDIT_X_COMMENT_TO:
653       if (news && option (OPTXCOMMENTTO)) {
654         buf[0] = 0;
655         if (msg->env->x_comment_to)
656           strfcpy (buf, msg->env->x_comment_to, sizeof (buf));
657         if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
658             && buf[0]) {
659           FREE (&msg->env->x_comment_to);
660           msg->env->x_comment_to = safe_strdup (buf);
661           move (HDR_BCC, HDR_XOFFSET);
662           clrtoeol ();
663           if (msg->env->x_comment_to)
664             printw ("%-*.*s", W, W, msg->env->x_comment_to);
665         }
666       }
667       break;
668 #endif
669     case OP_COMPOSE_EDIT_SUBJECT:
670       if (msg->env->subject)
671         strfcpy (buf, msg->env->subject, sizeof (buf));
672       else
673         buf[0] = 0;
674       if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
675         mutt_str_replace (&msg->env->subject, buf);
676         move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
677         clrtoeol ();
678         if (msg->env->subject)
679           mutt_paddstr (W, msg->env->subject);
680       }
681       mutt_message_hook (NULL, msg, M_SEND2HOOK);
682       break;
683     case OP_COMPOSE_EDIT_REPLY_TO:
684       menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
685       mutt_message_hook (NULL, msg, M_SEND2HOOK);
686       break;
687     case OP_COMPOSE_EDIT_FCC:
688       strfcpy (buf, fcc, sizeof (buf));
689       if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
690         strfcpy (fcc, buf, _POSIX_PATH_MAX);
691         mutt_pretty_mailbox (fcc);
692         move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
693         mutt_paddstr (W, fcc);
694         fccSet = 1;
695       }
696       MAYBE_REDRAW (menu->redraw);
697       mutt_message_hook (NULL, msg, M_SEND2HOOK);
698       break;
699     case OP_COMPOSE_EDIT_MESSAGE:
700       if (Editor && (mutt_strcmp ("builtin", Editor) != 0)
701           && !option (OPTEDITHDRS)) {
702         mutt_edit_file (Editor, msg->content->filename);
703         mutt_update_encoding (msg->content);
704         menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
705         mutt_message_hook (NULL, msg, M_SEND2HOOK);
706         break;
707       }
708       /* fall through */
709     case OP_COMPOSE_EDIT_HEADERS:
710       if (mutt_strcmp ("builtin", Editor) != 0 &&
711           (op == OP_COMPOSE_EDIT_HEADERS ||
712            (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
713         char *tag = NULL, *err = NULL;
714
715         mutt_env_to_local (msg->env);
716         mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
717                            fcc, fcclen);
718         if (mutt_env_to_idna (msg->env, &tag, &err)) {
719           mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
720           FREE (&err);
721         }
722       }
723       else {
724         /* this is grouped with OP_COMPOSE_EDIT_HEADERS because the
725            attachment list could change if the user invokes ~v to edit
726            the message with headers, in which we need to execute the
727            code below to regenerate the index array */
728         mutt_builtin_editor (msg->content->filename, msg, cur);
729       }
730       mutt_update_encoding (msg->content);
731
732       /* attachments may have been added */
733       if (idxlen && idx[idxlen - 1]->content->next) {
734         for (i = 0; i < idxlen; i++)
735           FREE (&idx[i]);
736         idxlen = 0;
737         idx =
738           mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
739                                 1);
740         menu->data = idx;
741         menu->max = idxlen;
742       }
743
744       menu->redraw = REDRAW_FULL;
745       mutt_message_hook (NULL, msg, M_SEND2HOOK);
746       break;
747
748
749
750     case OP_COMPOSE_ATTACH_KEY:
751       if (!(WithCrypto & APPLICATION_PGP))
752         break;
753       if (idxlen == idxmax) {
754         safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
755         menu->data = idx;
756       }
757
758       idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
759       if ((idx[idxlen]->content =
760            crypt_pgp_make_key_attachment (NULL)) != NULL) {
761         update_idx (menu, idx, idxlen++);
762         menu->redraw |= REDRAW_INDEX;
763       }
764       else
765         FREE (&idx[idxlen]);
766
767       menu->redraw |= REDRAW_STATUS;
768
769       if (option (OPTNEEDREDRAW)) {
770         menu->redraw = REDRAW_FULL;
771         unset_option (OPTNEEDREDRAW);
772       }
773
774       mutt_message_hook (NULL, msg, M_SEND2HOOK);
775       break;
776
777
778     case OP_COMPOSE_ATTACH_FILE:
779       {
780         char *prompt, **files;
781         int error, numfiles;
782
783         fname[0] = 0;
784         prompt = _("Attach file");
785         numfiles = 0;
786         files = NULL;
787
788         if (_mutt_enter_fname
789             (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
790              &numfiles) == -1 || *fname == '\0')
791           break;
792
793         if (idxlen + numfiles >= idxmax) {
794           safe_realloc (&idx,
795                         sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles));
796           menu->data = idx;
797         }
798
799         error = 0;
800         if (numfiles > 1)
801           mutt_message _("Attaching selected files...");
802
803         for (i = 0; i < numfiles; i++) {
804           char *att = files[i];
805
806           idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
807           idx[idxlen]->content = mutt_make_file_attach (att);
808           if (idx[idxlen]->content != NULL)
809             update_idx (menu, idx, idxlen++);
810           else {
811             error = 1;
812             mutt_error (_("Unable to attach %s!"), att);
813             FREE (&idx[idxlen]);
814           }
815         }
816
817         FREE (&files);
818         if (!error)
819           mutt_clear_error ();
820
821         menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
822       }
823       mutt_message_hook (NULL, msg, M_SEND2HOOK);
824       break;
825
826     case OP_COMPOSE_ATTACH_MESSAGE:
827 #ifdef USE_NNTP
828     case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
829 #endif
830       {
831         char *prompt;
832         HEADER *h;
833
834         fname[0] = 0;
835         prompt = _("Open mailbox to attach message from");
836
837 #ifdef USE_NNTP
838         unset_option (OPTNEWS);
839         if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) {
840           if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
841             break;
842
843           prompt = _("Open newsgroup to attach message from");
844           set_option (OPTNEWS);
845         }
846 #endif
847
848         if (Context)
849 #ifdef USE_NNTP
850           if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
851 #endif
852           {
853             strfcpy (fname, NONULL (Context->path), sizeof (fname));
854             mutt_pretty_mailbox (fname);
855           }
856
857         if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
858             == -1 || !fname[0])
859           break;
860
861 #ifdef USE_NNTP
862         if (option (OPTNEWS))
863           nntp_expand_path (fname, sizeof (fname),
864                             &CurrentNewsSrv->conn->account);
865         else
866 #endif
867           mutt_expand_path (fname, sizeof (fname));
868 #ifdef USE_IMAP
869         if (!mx_is_imap (fname))
870 #endif
871 #ifdef USE_POP
872           if (!mx_is_pop (fname))
873 #endif
874 #ifdef USE_NNTP
875             if (!mx_is_nntp (fname) && !option (OPTNEWS))
876 #endif
877               /* check to make sure the file exists and is readable */
878               if (access (fname, R_OK) == -1) {
879                 mutt_perror (fname);
880                 break;
881               }
882
883         menu->redraw = REDRAW_FULL;
884
885         ctx = mx_open_mailbox (fname, M_READONLY, NULL);
886         if (ctx == NULL) {
887           mutt_perror (fname);
888           break;
889         }
890
891         if (!ctx->msgcount) {
892           mx_close_mailbox (ctx, NULL);
893           FREE (&ctx);
894           mutt_error _("No messages in that folder.");
895
896           break;
897         }
898
899         this = Context;         /* remember current folder and sort methods */
900         oldSort = Sort;
901         oldSortAux = SortAux;
902
903         Context = ctx;
904         set_option (OPTATTACHMSG);
905         mutt_message _("Tag the messages you want to attach!");
906
907         close = mutt_index_menu ();
908         unset_option (OPTATTACHMSG);
909
910         if (!Context) {
911           /* go back to the folder we started from */
912           Context = this;
913           /* Restore old $sort and $sort_aux */
914           Sort = oldSort;
915           SortAux = oldSortAux;
916           menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
917           break;
918         }
919
920         if (idxlen + Context->tagged >= idxmax) {
921           safe_realloc (&idx,
922                         sizeof (ATTACHPTR *) * (idxmax +=
923                                                 5 + Context->tagged));
924           menu->data = idx;
925         }
926
927         for (i = 0; i < Context->msgcount; i++) {
928           h = Context->hdrs[i];
929           if (h->tagged) {
930             idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
931             idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
932             if (idx[idxlen]->content != NULL)
933               update_idx (menu, idx, idxlen++);
934             else {
935               mutt_error _("Unable to attach!");
936
937               FREE (&idx[idxlen]);
938             }
939           }
940         }
941         menu->redraw |= REDRAW_FULL;
942
943         if (close == OP_QUIT)
944           mx_close_mailbox (Context, NULL);
945         else
946           mx_fastclose_mailbox (Context);
947         FREE (&Context);
948
949         /* go back to the folder we started from */
950         Context = this;
951         /* Restore old $sort and $sort_aux */
952         Sort = oldSort;
953         SortAux = oldSortAux;
954       }
955       mutt_message_hook (NULL, msg, M_SEND2HOOK);
956       break;
957
958     case OP_DELETE:
959       CHECK_COUNT;
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         mutt_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         mutt_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         mutt_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           mutt_free_body (&idx[idxlen]->content);
1285           FREE (&idx[idxlen]->tree);
1286           FREE (&idx[idxlen]);
1287         }
1288         FREE (&idx);
1289         idxlen = 0;
1290         idxmax = 0;
1291         r = -1;
1292         loop = 0;
1293         break;
1294       }
1295       else if (i == -1)
1296         break;                  /* abort */
1297
1298       /* fall through to postpone! */
1299
1300     case OP_COMPOSE_POSTPONE_MESSAGE:
1301
1302       if (check_attachments (idx, idxlen) != 0) {
1303         menu->redraw = REDRAW_FULL;
1304         break;
1305       }
1306
1307       loop = 0;
1308       r = 1;
1309       break;
1310
1311     case OP_COMPOSE_ISPELL:
1312       endwin ();
1313       snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell),
1314                 msg->content->filename);
1315       if (mutt_system (buf) == -1)
1316         mutt_error (_("Error running \"%s\"!"), buf);
1317       else {
1318         mutt_update_encoding (msg->content);
1319         menu->redraw |= REDRAW_STATUS;
1320       }
1321       break;
1322
1323     case OP_COMPOSE_WRITE_MESSAGE:
1324
1325       fname[0] = '\0';
1326       if (Context) {
1327         strfcpy (fname, NONULL (Context->path), sizeof (fname));
1328         mutt_pretty_mailbox (fname);
1329       }
1330       if (idxlen)
1331         msg->content = idx[0]->content;
1332       if (mutt_enter_fname
1333           (_("Write message to mailbox"), fname, sizeof (fname),
1334            &menu->redraw, 1) != -1 && fname[0]) {
1335         mutt_message (_("Writing message to %s ..."), fname);
1336         mutt_expand_path (fname, sizeof (fname));
1337
1338         if (msg->content->next)
1339           msg->content = mutt_make_multipart (msg->content);
1340
1341         if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1342           msg->content = mutt_remove_multipart (msg->content);
1343         else
1344           mutt_message _("Message written.");
1345       }
1346       break;
1347
1348
1349
1350     case OP_COMPOSE_PGP_MENU:
1351       if (!(WithCrypto & APPLICATION_PGP))
1352         break;
1353       if ((WithCrypto & APPLICATION_SMIME)
1354           && msg->security & APPLICATION_SMIME) {
1355         if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1356                           M_YES) != M_YES) {
1357           mutt_clear_error ();
1358           break;
1359         }
1360         msg->security = 0;
1361       }
1362       msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1363       redraw_crypt_lines (msg);
1364       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1365       break;
1366
1367
1368     case OP_FORGET_PASSPHRASE:
1369       crypt_forget_passphrase ();
1370       break;
1371
1372
1373     case OP_COMPOSE_SMIME_MENU:
1374       if (!(WithCrypto & APPLICATION_SMIME))
1375         break;
1376
1377       if ((WithCrypto & APPLICATION_PGP)
1378           && msg->security & APPLICATION_PGP) {
1379         if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1380                           M_YES) != M_YES) {
1381           mutt_clear_error ();
1382           break;
1383         }
1384         msg->security = 0;
1385       }
1386       msg->security = crypt_smime_send_menu (msg, &menu->redraw);
1387       redraw_crypt_lines (msg);
1388       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1389       break;
1390
1391
1392 #ifdef MIXMASTER
1393     case OP_COMPOSE_MIX:
1394
1395       mix_make_chain (&msg->chain, &menu->redraw);
1396       mutt_message_hook (NULL, msg, M_SEND2HOOK);
1397       break;
1398 #endif
1399
1400     }
1401
1402     /* Draw formated compose status line */
1403     if (menu->redraw & REDRAW_STATUS) {
1404       compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat));
1405       CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
1406       SETCOLOR (MT_COLOR_STATUS);
1407       printw ("%-*.*s", COLS, COLS, buf);
1408       SETCOLOR (MT_COLOR_NORMAL);
1409       menu->redraw &= ~REDRAW_STATUS;
1410     }
1411   }
1412
1413   mutt_menuDestroy (&menu);
1414
1415   if (idxlen) {
1416     msg->content = idx[0]->content;
1417     for (i = 0; i < idxlen; i++) {
1418       idx[i]->content->aptr = NULL;
1419       FREE (&idx[i]);
1420     }
1421   }
1422   else
1423     msg->content = NULL;
1424
1425   FREE (&idx);
1426
1427   return (r);
1428 }