2 * Copyright (C) 1996-2000,2002,2007 Michael R. Elkins <me@mutt.org>
3 * Copyright (C) 2004 g10 Code GmbH
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "mutt_curses.h"
26 #include "mutt_idna.h"
27 #include "mutt_menu.h"
47 static const char* There_are_no_attachments = N_("There are no attachments.");
49 #define CHECK_COUNT if (idxlen == 0) { mutt_error _(There_are_no_attachments); break; }
70 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
73 #define HDR_XOFFSET 10
74 #define TITLE_FMT "%10s" /* Used for Prompts, which are ASCII */
75 #define W (COLS - HDR_XOFFSET)
77 static char *Prompts[] =
88 static struct mapping_t ComposeHelp[] = {
89 { N_("Send"), OP_COMPOSE_SEND_MESSAGE },
90 { N_("Abort"), OP_EXIT },
91 { "To", OP_COMPOSE_EDIT_TO },
92 { "CC", OP_COMPOSE_EDIT_CC },
93 { "Subj", OP_COMPOSE_EDIT_SUBJECT },
94 { N_("Attach file"), OP_COMPOSE_ATTACH_FILE },
95 { N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION },
96 { N_("Help"), OP_HELP },
100 static void snd_entry (char *b, size_t blen, MUTTMENU *menu, int num)
102 mutt_FormatString (b, blen, 0, NONULL (AttachFormat), mutt_attach_fmt,
103 (unsigned long)(((ATTACHPTR **) menu->data)[num]),
104 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
109 #include "mutt_crypt.h"
111 static void redraw_crypt_lines (HEADER *msg)
115 if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME))
118 mvaddstr (HDR_CRYPT, 0, "Security: ");
119 else if (msg->security & APPLICATION_SMIME)
120 mvaddstr (HDR_CRYPT, 0, " S/MIME: ");
121 else if (msg->security & APPLICATION_PGP)
122 mvaddstr (HDR_CRYPT, 0, " PGP: ");
124 else if ((WithCrypto & APPLICATION_SMIME))
125 mvaddstr (HDR_CRYPT, 0, " S/MIME: ");
126 else if ((WithCrypto & APPLICATION_PGP))
127 mvaddstr (HDR_CRYPT, 0, " PGP: ");
131 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
132 addstr (_("Sign, Encrypt"));
133 else if (msg->security & ENCRYPT)
134 addstr (_("Encrypt"));
135 else if (msg->security & SIGN)
140 if ((WithCrypto & APPLICATION_PGP))
141 if ((msg->security & APPLICATION_PGP)
142 && (msg->security & (ENCRYPT | SIGN)))
144 if ((msg->security & INLINE))
145 addstr (_(" (inline)"));
147 addstr (_(" (PGP/MIME)"));
151 move (HDR_CRYPTINFO, 0);
153 if ((WithCrypto & APPLICATION_PGP)
154 && msg->security & APPLICATION_PGP && msg->security & SIGN)
155 printw ("%s%s", _(" sign as: "), PgpSignAs ? PgpSignAs : _("<default>"));
157 if ((WithCrypto & APPLICATION_SMIME)
158 && msg->security & APPLICATION_SMIME && msg->security & SIGN) {
159 printw ("%s%s", _(" sign as: "), SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
162 if ((WithCrypto & APPLICATION_SMIME)
163 && (msg->security & APPLICATION_SMIME)
164 && (msg->security & ENCRYPT)
167 mvprintw (HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "),
168 NONULL(SmimeCryptAlg));
176 static void redraw_mix_line (LIST *chain)
181 mvaddstr (HDR_MIX, 0, " Mix: ");
185 addstr ("<no chain defined>");
190 for (c = 12; chain; chain = chain->next)
193 if (t && t[0] == '0' && t[1] == '\0')
196 if (c + mutt_strlen (t) + 2 >= COLS)
203 c += mutt_strlen (t) + 2;
206 #endif /* MIXMASTER */
209 check_attachments(ATTACHPTR **idx, short idxlen)
213 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
215 for (i = 0; i < idxlen; i++)
217 strfcpy(pretty, idx[i]->content->filename, sizeof(pretty));
218 if(stat(idx[i]->content->filename, &st) != 0)
220 mutt_pretty_mailbox(pretty, sizeof (pretty));
221 mutt_error(_("%s [#%d] no longer exists!"),
226 if(idx[i]->content->stamp < st.st_mtime)
228 mutt_pretty_mailbox(pretty, sizeof (pretty));
229 snprintf(msg, sizeof(msg), _("%s [#%d] modified. Update encoding?"),
232 if((r = mutt_yesorno(msg, M_YES)) == M_YES)
233 mutt_update_encoding(idx[i]->content);
242 static void draw_envelope_addr (int line, ADDRESS *addr)
247 rfc822_write_address (buf, sizeof (buf), addr, 1);
248 mvprintw (line, 0, TITLE_FMT, Prompts[line - 1]);
249 mutt_paddstr (W, buf);
252 static void draw_envelope (HEADER *msg, char *fcc)
254 draw_envelope_addr (HDR_FROM, msg->env->from);
255 draw_envelope_addr (HDR_TO, msg->env->to);
256 draw_envelope_addr (HDR_CC, msg->env->cc);
257 draw_envelope_addr (HDR_BCC, msg->env->bcc);
258 mvprintw (HDR_SUBJECT, 0, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
259 mutt_paddstr (W, NONULL (msg->env->subject));
260 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
261 mvprintw (HDR_FCC, 0, TITLE_FMT, Prompts[HDR_FCC - 1]);
262 mutt_paddstr (W, fcc);
265 redraw_crypt_lines (msg);
268 redraw_mix_line (msg->chain);
271 SETCOLOR (MT_COLOR_STATUS);
272 mvaddstr (HDR_ATTACH - 1, 0, _("-- Attachments"));
273 BKGDSET (MT_COLOR_STATUS);
276 BKGDSET (MT_COLOR_NORMAL);
277 SETCOLOR (MT_COLOR_NORMAL);
280 static int edit_address_list (int line, ADDRESS **addr)
282 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
285 mutt_addrlist_to_local (*addr);
286 rfc822_write_address (buf, sizeof (buf), *addr, 0);
287 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0)
289 rfc822_free_address (addr);
290 *addr = mutt_parse_adrlist (*addr, buf);
291 *addr = mutt_expand_aliases (*addr);
294 if (option (OPTNEEDREDRAW))
296 unset_option (OPTNEEDREDRAW);
297 return (REDRAW_FULL);
300 if (mutt_addrlist_to_idna (*addr, &err) != 0)
302 mutt_error (_("Warning: '%s' is a bad IDN."), err);
307 /* redraw the expanded list so the user can see the result */
309 rfc822_write_address (buf, sizeof (buf), *addr, 1);
310 move (line, HDR_XOFFSET);
311 mutt_paddstr (W, buf);
316 static int delete_attachment (MUTTMENU *menu, short *idxlen, int x)
318 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
321 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
323 if (x == 0 && menu->max == 1)
325 mutt_error _("You may not delete the only attachment.");
326 idx[x]->content->tagged = 0;
330 for (y = 0; y < *idxlen; y++)
332 if (idx[y]->content->next == idx[x]->content)
334 idx[y]->content->next = idx[x]->content->next;
339 idx[x]->content->next = NULL;
340 idx[x]->content->parts = NULL;
341 mutt_free_body (&(idx[x]->content));
342 FREE (&idx[x]->tree);
344 for (; x < *idxlen - 1; x++)
346 menu->max = --(*idxlen);
351 static void update_idx (MUTTMENU *menu, ATTACHPTR **idx, short idxlen)
353 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen-1]->level : 0;
355 idx[idxlen - 1]->content->next = idx[idxlen]->content;
356 idx[idxlen]->content->aptr = idx[idxlen];
357 menu->current = idxlen++;
358 mutt_update_tree (idx, idxlen);
365 * cum_attachs_size: Cumulative Attachments Size
367 * Returns the total number of bytes used by the attachments in the
368 * attachment list _after_ content-transfer-encodings have been
373 static unsigned long cum_attachs_size (MUTTMENU *menu)
377 ATTACHPTR **idx = menu->data;
381 for (i = 0, s = 0; i < menu->max; i++)
386 b->content = mutt_get_content_info (b->filename, b);
388 if ((info = b->content))
392 case ENCQUOTEDPRINTABLE:
393 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
396 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
399 s += info->lobin + info->hibin + info->ascii + info->crlf;
408 /* prototype for use below */
409 static void compose_status_line (char *buf, size_t buflen, size_t col, MUTTMENU *menu,
413 * compose_format_str()
415 * %a = total number of attachments
416 * %h = hostname [option]
417 * %l = approx. length of current message (in bytes)
420 * This function is similar to status_format_str(). Look at that function for
421 * help when modifying this function.
425 compose_format_str (char *buf, size_t buflen, size_t col, char op, const char *src,
426 const char *prefix, const char *ifstring,
427 const char *elsestring,
428 unsigned long data, format_flag flags)
430 char fmt[SHORT_STRING], tmp[SHORT_STRING];
431 int optional = (flags & M_FORMAT_OPTIONAL);
432 MUTTMENU *menu = (MUTTMENU *) data;
437 case 'a': /* total number of attachments */
438 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
439 snprintf (buf, buflen, fmt, menu->max);
442 case 'h': /* hostname */
443 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
444 snprintf (buf, buflen, fmt, NONULL(Hostname));
447 case 'l': /* approx length of current message in bytes */
448 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
449 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size(menu) : 0);
450 snprintf (buf, buflen, fmt, tmp);
454 snprintf (fmt, sizeof (fmt), "Mutt %%s");
455 snprintf (buf, buflen, fmt, MUTT_VERSION);
463 snprintf (buf, buflen, "%%%s%c", prefix, op);
468 compose_status_line (buf, buflen, col, menu, ifstring);
469 else if (flags & M_FORMAT_OPTIONAL)
470 compose_status_line (buf, buflen, col, menu, elsestring);
475 static void compose_status_line (char *buf, size_t buflen, size_t col, MUTTMENU *menu,
478 mutt_FormatString (buf, buflen, col, p, compose_format_str,
479 (unsigned long) menu, 0);
485 * 1 message should be postponed
489 int mutt_compose_menu (HEADER *msg, /* structure for new message */
490 char *fcc, /* where to save a copy of the message */
492 HEADER *cur) /* current message */
494 char helpstr[LONG_STRING];
495 char buf[LONG_STRING];
496 char fname[_POSIX_PATH_MAX];
498 ATTACHPTR **idx = NULL;
502 int r = -1; /* return value */
505 int fccSet = 0; /* has the user edited the Fcc: field ? */
506 CONTEXT *ctx = NULL, *this = NULL;
507 /* Sort, SortAux could be changed in mutt_index_menu() */
508 int oldSort, oldSortAux;
511 mutt_attach_init (msg->content);
512 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
514 menu = mutt_new_menu (MENU_COMPOSE);
515 menu->offset = HDR_ATTACH;
517 menu->make_entry = snd_entry;
518 menu->tag = mutt_tag_attach;
520 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeHelp);
524 switch (op = mutt_menuLoop (menu))
527 draw_envelope (msg, fcc);
528 menu->offset = HDR_ATTACH;
529 menu->pagelen = LINES - HDR_ATTACH - 2;
531 case OP_COMPOSE_EDIT_FROM:
532 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
533 mutt_message_hook (NULL, msg, M_SEND2HOOK);
535 case OP_COMPOSE_EDIT_TO:
536 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
537 mutt_message_hook (NULL, msg, M_SEND2HOOK);
539 case OP_COMPOSE_EDIT_BCC:
540 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
541 mutt_message_hook (NULL, msg, M_SEND2HOOK);
543 case OP_COMPOSE_EDIT_CC:
544 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
545 mutt_message_hook (NULL, msg, M_SEND2HOOK);
547 case OP_COMPOSE_EDIT_SUBJECT:
548 if (msg->env->subject)
549 strfcpy (buf, msg->env->subject, sizeof (buf));
552 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
554 mutt_str_replace (&msg->env->subject, buf);
555 move (HDR_SUBJECT, HDR_XOFFSET);
557 if (msg->env->subject)
558 mutt_paddstr (W, msg->env->subject);
560 mutt_message_hook (NULL, msg, M_SEND2HOOK);
562 case OP_COMPOSE_EDIT_REPLY_TO:
563 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
564 mutt_message_hook (NULL, msg, M_SEND2HOOK);
566 case OP_COMPOSE_EDIT_FCC:
567 strfcpy (buf, fcc, sizeof (buf));
568 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0)
570 strfcpy (fcc, buf, fcclen);
571 mutt_pretty_mailbox (fcc, fcclen);
572 move (HDR_FCC, HDR_XOFFSET);
573 mutt_paddstr (W, fcc);
576 MAYBE_REDRAW (menu->redraw);
577 mutt_message_hook (NULL, msg, M_SEND2HOOK);
579 case OP_COMPOSE_EDIT_MESSAGE:
580 if (Editor && (mutt_strcmp ("builtin", Editor) != 0) && !option (OPTEDITHDRS))
582 mutt_edit_file (Editor, msg->content->filename);
583 mutt_update_encoding (msg->content);
584 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
585 mutt_message_hook (NULL, msg, M_SEND2HOOK);
589 case OP_COMPOSE_EDIT_HEADERS:
590 if (mutt_strcmp ("builtin", Editor) != 0 &&
591 (op == OP_COMPOSE_EDIT_HEADERS ||
592 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS))))
594 char *tag = NULL, *err = NULL;
595 mutt_env_to_local (msg->env);
596 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
598 if (mutt_env_to_idna (msg->env, &tag, &err))
600 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
606 /* this is grouped with OP_COMPOSE_EDIT_HEADERS because the
607 attachment list could change if the user invokes ~v to edit
608 the message with headers, in which we need to execute the
609 code below to regenerate the index array */
610 mutt_builtin_editor (msg->content->filename, msg, cur);
612 mutt_update_encoding (msg->content);
614 /* attachments may have been added */
615 if (idxlen && idx[idxlen - 1]->content->next)
617 for (i = 0; i < idxlen; i++)
620 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
625 menu->redraw = REDRAW_FULL;
626 mutt_message_hook (NULL, msg, M_SEND2HOOK);
631 case OP_COMPOSE_ATTACH_KEY:
632 if (!(WithCrypto & APPLICATION_PGP))
634 if (idxlen == idxmax)
636 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
640 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
641 if ((idx[idxlen]->content = crypt_pgp_make_key_attachment(NULL)) != NULL)
643 update_idx (menu, idx, idxlen++);
644 menu->redraw |= REDRAW_INDEX;
649 menu->redraw |= REDRAW_STATUS;
651 if (option(OPTNEEDREDRAW))
653 menu->redraw = REDRAW_FULL;
654 unset_option(OPTNEEDREDRAW);
657 mutt_message_hook (NULL, msg, M_SEND2HOOK);
661 case OP_COMPOSE_ATTACH_FILE:
663 char *prompt, **files;
667 prompt = _("Attach file");
671 if (_mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files, &numfiles) == -1 ||
675 if (idxlen + numfiles >= idxmax)
677 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles));
683 mutt_message _("Attaching selected files...");
684 for (i = 0; i < numfiles; i++)
686 char *att = files[i];
687 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
688 idx[idxlen]->unowned = 1;
689 idx[idxlen]->content = mutt_make_file_attach (att);
690 if (idx[idxlen]->content != NULL)
691 update_idx (menu, idx, idxlen++);
695 mutt_error (_("Unable to attach %s!"), att);
701 if (!error) mutt_clear_error ();
703 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
705 mutt_message_hook (NULL, msg, M_SEND2HOOK);
708 case OP_COMPOSE_ATTACH_MESSAGE:
714 prompt = _("Open mailbox to attach message from");
718 strfcpy (fname, NONULL (Context->path), sizeof (fname));
719 mutt_pretty_mailbox (fname, sizeof (fname));
722 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1) == -1 || !fname[0])
725 mutt_expand_path (fname, sizeof (fname));
727 if (!mx_is_imap (fname))
730 if (!mx_is_pop (fname))
732 /* check to make sure the file exists and is readable */
733 if (access (fname, R_OK) == -1)
739 menu->redraw = REDRAW_FULL;
741 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
750 mx_close_mailbox (ctx, NULL);
752 mutt_error _("No messages in that folder.");
756 this = Context; /* remember current folder and sort methods*/
757 oldSort = Sort; oldSortAux = SortAux;
760 set_option(OPTATTACHMSG);
761 mutt_message _("Tag the messages you want to attach!");
762 close = mutt_index_menu ();
763 unset_option(OPTATTACHMSG);
767 /* go back to the folder we started from */
769 /* Restore old $sort and $sort_aux */
771 SortAux = oldSortAux;
772 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
776 if (idxlen + Context->tagged >= idxmax)
778 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + Context->tagged));
782 for (i = 0; i < Context->msgcount; i++)
784 h = Context->hdrs[i];
787 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
788 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
789 if (idx[idxlen]->content != NULL)
790 update_idx (menu, idx, idxlen++);
793 mutt_error _("Unable to attach!");
798 menu->redraw |= REDRAW_FULL;
800 if (close == OP_QUIT)
801 mx_close_mailbox (Context, NULL);
803 mx_fastclose_mailbox (Context);
806 /* go back to the folder we started from */
808 /* Restore old $sort and $sort_aux */
810 SortAux = oldSortAux;
812 mutt_message_hook (NULL, msg, M_SEND2HOOK);
817 if (idx[menu->current]->unowned)
818 idx[menu->current]->content->unlink = 0;
819 if (delete_attachment (menu, &idxlen, menu->current) == -1)
821 mutt_update_tree (idx, idxlen);
824 if (menu->current > idxlen - 1)
825 menu->current = idxlen - 1;
830 if (menu->current == 0)
831 msg->content = idx[0]->content;
833 menu->redraw |= REDRAW_STATUS;
834 mutt_message_hook (NULL, msg, M_SEND2HOOK);
837 #define CURRENT idx[menu->current]->content
839 case OP_COMPOSE_TOGGLE_RECODE:
842 if (!mutt_is_text_part (CURRENT))
844 mutt_error (_("Recoding only affects text attachments."));
847 CURRENT->noconv = !CURRENT->noconv;
849 mutt_message (_("The current attachment won't be converted."));
851 mutt_message (_("The current attachment will be converted."));
852 menu->redraw = REDRAW_CURRENT;
853 mutt_message_hook (NULL, msg, M_SEND2HOOK);
858 case OP_COMPOSE_EDIT_DESCRIPTION:
861 idx[menu->current]->content->description ?
862 idx[menu->current]->content->description : "",
864 /* header names should not be translated */
865 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0)
867 mutt_str_replace (&idx[menu->current]->content->description, buf);
868 menu->redraw = REDRAW_CURRENT;
870 mutt_message_hook (NULL, msg, M_SEND2HOOK);
873 case OP_COMPOSE_UPDATE_ENCODING:
878 for (top = msg->content; top; top = top->next)
881 mutt_update_encoding (top);
883 menu->redraw = REDRAW_FULL;
887 mutt_update_encoding(idx[menu->current]->content);
888 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
890 mutt_message_hook (NULL, msg, M_SEND2HOOK);
893 case OP_COMPOSE_TOGGLE_DISPOSITION:
894 /* toggle the content-disposition between inline/attachment */
895 idx[menu->current]->content->disposition = (idx[menu->current]->content->disposition == DISPINLINE) ? DISPATTACH : DISPINLINE;
896 menu->redraw = REDRAW_CURRENT;
902 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
904 /* this may have been a change to text/something */
905 mutt_update_encoding (idx[menu->current]->content);
907 menu->redraw = REDRAW_CURRENT;
909 mutt_message_hook (NULL, msg, M_SEND2HOOK);
912 case OP_COMPOSE_EDIT_ENCODING:
914 strfcpy (buf, ENCODING (idx[menu->current]->content->encoding),
916 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
917 sizeof (buf), 0) == 0 && buf[0])
919 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED)
921 idx[menu->current]->content->encoding = i;
922 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
926 mutt_error _("Invalid encoding.");
928 mutt_message_hook (NULL, msg, M_SEND2HOOK);
931 case OP_COMPOSE_SEND_MESSAGE:
933 /* Note: We don't invoke send2-hook here, since we want to leave
934 * users an opportunity to change settings from the ":" prompt.
937 if(check_attachments(idx, idxlen) != 0)
939 menu->redraw = REDRAW_FULL;
945 if (msg->chain && mix_check_message (msg) != 0)
951 if ((i = query_quadoption (OPT_COPY,
952 _("Save a copy of this message?"))) == -1)
962 case OP_COMPOSE_EDIT_FILE:
964 mutt_edit_file (NONULL(Editor), idx[menu->current]->content->filename);
965 mutt_update_encoding (idx[menu->current]->content);
966 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
967 mutt_message_hook (NULL, msg, M_SEND2HOOK);
970 case OP_COMPOSE_TOGGLE_UNLINK:
972 idx[menu->current]->content->unlink = !idx[menu->current]->content->unlink;
975 /* OPTRESOLVE is otherwise ignored on this menu.
979 if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
982 menu->redraw = REDRAW_INDEX;
983 /* No send2hook since this doesn't change the message. */
986 case OP_COMPOSE_GET_ATTACHMENT:
991 for(top = msg->content; top; top = top->next)
994 mutt_get_tmp_attachment(top);
996 menu->redraw = REDRAW_FULL;
998 else if (mutt_get_tmp_attachment(idx[menu->current]->content) == 0)
999 menu->redraw = REDRAW_CURRENT;
1001 /* No send2hook since this doesn't change the message. */
1004 case OP_COMPOSE_RENAME_FILE:
1006 strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname));
1007 mutt_pretty_mailbox (fname, sizeof (fname));
1008 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1011 if (stat(idx[menu->current]->content->filename, &st) == -1)
1013 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1017 mutt_expand_path (fname, sizeof (fname));
1018 if(mutt_rename_file (idx[menu->current]->content->filename, fname))
1021 mutt_str_replace (&idx[menu->current]->content->filename, fname);
1022 menu->redraw = REDRAW_CURRENT;
1024 if(idx[menu->current]->content->stamp >= st.st_mtime)
1025 mutt_stamp_attachment(idx[menu->current]->content);
1028 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1031 case OP_COMPOSE_NEW_MIME:
1038 CLEARLINE (LINES-1);
1040 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1043 mutt_expand_path (fname, sizeof (fname));
1045 /* Call to lookup_mime_type () ? maybe later */
1047 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1051 if (!(p = strchr (type, '/')))
1053 mutt_error _("Content-Type is of the form base/sub");
1057 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER)
1059 mutt_error (_("Unknown Content-Type %s"), type);
1062 if (idxlen == idxmax)
1064 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
1068 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
1069 /* Touch the file */
1070 if (!(fp = safe_fopen (fname, "w")))
1072 mutt_error (_("Can't create file %s"), fname);
1073 FREE (&idx[idxlen]);
1078 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL)
1080 mutt_error _("What we have here is a failure to make an attachment");
1083 update_idx (menu, idx, idxlen++);
1085 idx[menu->current]->content->type = itype;
1086 mutt_str_replace (&idx[menu->current]->content->subtype, p);
1087 idx[menu->current]->content->unlink = 1;
1088 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1090 if (mutt_compose_attachment (idx[menu->current]->content))
1092 mutt_update_encoding (idx[menu->current]->content);
1093 menu->redraw = REDRAW_FULL;
1096 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1099 case OP_COMPOSE_EDIT_MIME:
1101 if (mutt_edit_attachment (idx[menu->current]->content))
1103 mutt_update_encoding (idx[menu->current]->content);
1104 menu->redraw = REDRAW_FULL;
1106 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1109 case OP_VIEW_ATTACH:
1110 case OP_DISPLAY_HEADERS:
1112 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen, NULL, 0);
1113 menu->redraw = REDRAW_FULL;
1114 /* no send2hook, since this doesn't modify the message */
1119 mutt_save_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, NULL, menu);
1120 MAYBE_REDRAW (menu->redraw);
1121 /* no send2hook, since this doesn't modify the message */
1126 mutt_print_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content);
1127 /* no send2hook, since this doesn't modify the message */
1133 mutt_pipe_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, op == OP_FILTER);
1134 if (op == OP_FILTER) /* cte might have changed */
1135 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1136 menu->redraw |= REDRAW_STATUS;
1137 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1141 if ((i = query_quadoption (OPT_POSTPONE, _("Postpone this message?"))) == M_NO)
1143 while (idxlen-- > 0)
1145 /* avoid freeing other attachments */
1146 idx[idxlen]->content->next = NULL;
1147 idx[idxlen]->content->parts = NULL;
1148 if (idx[idxlen]->unowned)
1149 idx[idxlen]->content->unlink = 0;
1150 mutt_free_body (&idx[idxlen]->content);
1151 FREE (&idx[idxlen]->tree);
1152 FREE (&idx[idxlen]);
1164 /* fall through to postpone! */
1166 case OP_COMPOSE_POSTPONE_MESSAGE:
1168 if(check_attachments(idx, idxlen) != 0)
1170 menu->redraw = REDRAW_FULL;
1178 case OP_COMPOSE_ISPELL:
1180 snprintf (buf, sizeof (buf), "%s -x %s", NONULL(Ispell), msg->content->filename);
1181 if (mutt_system (buf) == -1)
1182 mutt_error (_("Error running \"%s\"!"), buf);
1185 mutt_update_encoding (msg->content);
1186 menu->redraw |= REDRAW_STATUS;
1190 case OP_COMPOSE_WRITE_MESSAGE:
1195 strfcpy (fname, NONULL (Context->path), sizeof (fname));
1196 mutt_pretty_mailbox (fname, sizeof (fname));
1199 msg->content = idx[0]->content;
1200 if (mutt_enter_fname (_("Write message to mailbox"), fname, sizeof (fname),
1201 &menu->redraw, 1) != -1 && fname[0])
1203 mutt_message (_("Writing message to %s ..."), fname);
1204 mutt_expand_path (fname, sizeof (fname));
1206 if (msg->content->next)
1207 msg->content = mutt_make_multipart (msg->content);
1209 if (mutt_write_fcc (fname, msg, NULL, 1, NULL) < 0)
1210 msg->content = mutt_remove_multipart (msg->content);
1212 mutt_message _("Message written.");
1218 case OP_COMPOSE_PGP_MENU:
1219 if (!(WithCrypto & APPLICATION_PGP))
1221 if ((WithCrypto & APPLICATION_SMIME)
1222 && msg->security & APPLICATION_SMIME)
1224 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1227 mutt_clear_error ();
1232 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1233 redraw_crypt_lines (msg);
1234 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1238 case OP_FORGET_PASSPHRASE:
1239 crypt_forget_passphrase ();
1243 case OP_COMPOSE_SMIME_MENU:
1244 if (!(WithCrypto & APPLICATION_SMIME))
1247 if ((WithCrypto & APPLICATION_PGP)
1248 && msg->security & APPLICATION_PGP)
1250 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1253 mutt_clear_error ();
1258 msg->security = crypt_smime_send_menu(msg, &menu->redraw);
1259 redraw_crypt_lines (msg);
1260 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1265 case OP_COMPOSE_MIX:
1267 mix_make_chain (&msg->chain, &menu->redraw);
1268 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1274 /* Draw formated compose status line */
1275 if (menu->redraw & REDRAW_STATUS)
1277 compose_status_line (buf, sizeof (buf), 0, menu, NONULL(ComposeFormat));
1278 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
1279 SETCOLOR (MT_COLOR_STATUS);
1280 BKGDSET (MT_COLOR_STATUS);
1281 mutt_paddstr (COLS, buf);
1282 SETCOLOR (MT_COLOR_NORMAL);
1283 BKGDSET (MT_COLOR_NORMAL);
1284 menu->redraw &= ~REDRAW_STATUS;
1288 mutt_menuDestroy (&menu);
1292 msg->content = idx[0]->content;
1293 for (i = 0; i < idxlen; i++)
1295 idx[i]->content->aptr = NULL;
1300 msg->content = NULL;