2 * Copyright (C) 1996-2000 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);
221 mutt_error(_("%s [#%d] no longer exists!"),
226 if(idx[i]->content->stamp < st.st_mtime)
228 mutt_pretty_mailbox(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 ();
515 menu->menu = MENU_COMPOSE;
516 menu->offset = HDR_ATTACH;
518 menu->make_entry = snd_entry;
519 menu->tag = mutt_tag_attach;
521 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeHelp);
525 switch (op = mutt_menuLoop (menu))
528 draw_envelope (msg, fcc);
529 menu->offset = HDR_ATTACH;
530 menu->pagelen = LINES - HDR_ATTACH - 2;
532 case OP_COMPOSE_EDIT_FROM:
533 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
534 mutt_message_hook (NULL, msg, M_SEND2HOOK);
536 case OP_COMPOSE_EDIT_TO:
537 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
538 mutt_message_hook (NULL, msg, M_SEND2HOOK);
540 case OP_COMPOSE_EDIT_BCC:
541 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
542 mutt_message_hook (NULL, msg, M_SEND2HOOK);
544 case OP_COMPOSE_EDIT_CC:
545 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
546 mutt_message_hook (NULL, msg, M_SEND2HOOK);
548 case OP_COMPOSE_EDIT_SUBJECT:
549 if (msg->env->subject)
550 strfcpy (buf, msg->env->subject, sizeof (buf));
553 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
555 mutt_str_replace (&msg->env->subject, buf);
556 move (HDR_SUBJECT, HDR_XOFFSET);
558 if (msg->env->subject)
559 mutt_paddstr (W, msg->env->subject);
561 mutt_message_hook (NULL, msg, M_SEND2HOOK);
563 case OP_COMPOSE_EDIT_REPLY_TO:
564 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
565 mutt_message_hook (NULL, msg, M_SEND2HOOK);
567 case OP_COMPOSE_EDIT_FCC:
568 strfcpy (buf, fcc, sizeof (buf));
569 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0)
571 strfcpy (fcc, buf, _POSIX_PATH_MAX);
572 mutt_pretty_mailbox (fcc);
573 move (HDR_FCC, HDR_XOFFSET);
574 mutt_paddstr (W, fcc);
577 MAYBE_REDRAW (menu->redraw);
578 mutt_message_hook (NULL, msg, M_SEND2HOOK);
580 case OP_COMPOSE_EDIT_MESSAGE:
581 if (Editor && (mutt_strcmp ("builtin", Editor) != 0) && !option (OPTEDITHDRS))
583 mutt_edit_file (Editor, msg->content->filename);
584 mutt_update_encoding (msg->content);
585 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
586 mutt_message_hook (NULL, msg, M_SEND2HOOK);
590 case OP_COMPOSE_EDIT_HEADERS:
591 if (mutt_strcmp ("builtin", Editor) != 0 &&
592 (op == OP_COMPOSE_EDIT_HEADERS ||
593 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS))))
595 char *tag = NULL, *err = NULL;
596 mutt_env_to_local (msg->env);
597 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
599 if (mutt_env_to_idna (msg->env, &tag, &err))
601 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
607 /* this is grouped with OP_COMPOSE_EDIT_HEADERS because the
608 attachment list could change if the user invokes ~v to edit
609 the message with headers, in which we need to execute the
610 code below to regenerate the index array */
611 mutt_builtin_editor (msg->content->filename, msg, cur);
613 mutt_update_encoding (msg->content);
615 /* attachments may have been added */
616 if (idxlen && idx[idxlen - 1]->content->next)
618 for (i = 0; i < idxlen; i++)
621 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
626 menu->redraw = REDRAW_FULL;
627 mutt_message_hook (NULL, msg, M_SEND2HOOK);
632 case OP_COMPOSE_ATTACH_KEY:
633 if (!(WithCrypto & APPLICATION_PGP))
635 if (idxlen == idxmax)
637 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
641 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
642 if ((idx[idxlen]->content = crypt_pgp_make_key_attachment(NULL)) != NULL)
644 update_idx (menu, idx, idxlen++);
645 menu->redraw |= REDRAW_INDEX;
650 menu->redraw |= REDRAW_STATUS;
652 if (option(OPTNEEDREDRAW))
654 menu->redraw = REDRAW_FULL;
655 unset_option(OPTNEEDREDRAW);
658 mutt_message_hook (NULL, msg, M_SEND2HOOK);
662 case OP_COMPOSE_ATTACH_FILE:
664 char *prompt, **files;
668 prompt = _("Attach file");
672 if (_mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files, &numfiles) == -1 ||
676 if (idxlen + numfiles >= idxmax)
678 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles));
684 mutt_message _("Attaching selected files...");
685 for (i = 0; i < numfiles; i++)
687 char *att = files[i];
688 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
689 idx[idxlen]->unowned = 1;
690 idx[idxlen]->content = mutt_make_file_attach (att);
691 if (idx[idxlen]->content != NULL)
692 update_idx (menu, idx, idxlen++);
696 mutt_error (_("Unable to attach %s!"), att);
702 if (!error) mutt_clear_error ();
704 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
706 mutt_message_hook (NULL, msg, M_SEND2HOOK);
709 case OP_COMPOSE_ATTACH_MESSAGE:
715 prompt = _("Open mailbox to attach message from");
719 strfcpy (fname, NONULL (Context->path), sizeof (fname));
720 mutt_pretty_mailbox (fname);
723 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1) == -1 || !fname[0])
726 mutt_expand_path (fname, sizeof (fname));
728 if (!mx_is_imap (fname))
731 if (!mx_is_pop (fname))
733 /* check to make sure the file exists and is readable */
734 if (access (fname, R_OK) == -1)
740 menu->redraw = REDRAW_FULL;
742 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
751 mx_close_mailbox (ctx, NULL);
753 mutt_error _("No messages in that folder.");
757 this = Context; /* remember current folder and sort methods*/
758 oldSort = Sort; oldSortAux = SortAux;
761 set_option(OPTATTACHMSG);
762 mutt_message _("Tag the messages you want to attach!");
763 close = mutt_index_menu ();
764 unset_option(OPTATTACHMSG);
768 /* go back to the folder we started from */
770 /* Restore old $sort and $sort_aux */
772 SortAux = oldSortAux;
773 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
777 if (idxlen + Context->tagged >= idxmax)
779 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + Context->tagged));
783 for (i = 0; i < Context->msgcount; i++)
785 h = Context->hdrs[i];
788 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
789 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
790 if (idx[idxlen]->content != NULL)
791 update_idx (menu, idx, idxlen++);
794 mutt_error _("Unable to attach!");
799 menu->redraw |= REDRAW_FULL;
801 if (close == OP_QUIT)
802 mx_close_mailbox (Context, NULL);
804 mx_fastclose_mailbox (Context);
807 /* go back to the folder we started from */
809 /* Restore old $sort and $sort_aux */
811 SortAux = oldSortAux;
813 mutt_message_hook (NULL, msg, M_SEND2HOOK);
818 if (idx[menu->current]->unowned)
819 idx[menu->current]->content->unlink = 0;
820 if (delete_attachment (menu, &idxlen, menu->current) == -1)
822 mutt_update_tree (idx, idxlen);
825 if (menu->current > idxlen - 1)
826 menu->current = idxlen - 1;
831 if (menu->current == 0)
832 msg->content = idx[0]->content;
834 menu->redraw |= REDRAW_STATUS;
835 mutt_message_hook (NULL, msg, M_SEND2HOOK);
838 #define CURRENT idx[menu->current]->content
840 case OP_COMPOSE_TOGGLE_RECODE:
843 if (!mutt_is_text_part (CURRENT))
845 mutt_error (_("Recoding only affects text attachments."));
848 CURRENT->noconv = !CURRENT->noconv;
850 mutt_message (_("The current attachment won't be converted."));
852 mutt_message (_("The current attachment will be converted."));
853 menu->redraw = REDRAW_CURRENT;
854 mutt_message_hook (NULL, msg, M_SEND2HOOK);
859 case OP_COMPOSE_EDIT_DESCRIPTION:
862 idx[menu->current]->content->description ?
863 idx[menu->current]->content->description : "",
865 /* header names should not be translated */
866 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0)
868 mutt_str_replace (&idx[menu->current]->content->description, buf);
869 menu->redraw = REDRAW_CURRENT;
871 mutt_message_hook (NULL, msg, M_SEND2HOOK);
874 case OP_COMPOSE_UPDATE_ENCODING:
879 for (top = msg->content; top; top = top->next)
882 mutt_update_encoding (top);
884 menu->redraw = REDRAW_FULL;
888 mutt_update_encoding(idx[menu->current]->content);
889 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
891 mutt_message_hook (NULL, msg, M_SEND2HOOK);
894 case OP_COMPOSE_TOGGLE_DISPOSITION:
895 /* toggle the content-disposition between inline/attachment */
896 idx[menu->current]->content->disposition = (idx[menu->current]->content->disposition == DISPINLINE) ? DISPATTACH : DISPINLINE;
897 menu->redraw = REDRAW_CURRENT;
903 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
905 /* this may have been a change to text/something */
906 mutt_update_encoding (idx[menu->current]->content);
908 menu->redraw = REDRAW_CURRENT;
910 mutt_message_hook (NULL, msg, M_SEND2HOOK);
913 case OP_COMPOSE_EDIT_ENCODING:
915 strfcpy (buf, ENCODING (idx[menu->current]->content->encoding),
917 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
918 sizeof (buf), 0) == 0 && buf[0])
920 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED)
922 idx[menu->current]->content->encoding = i;
923 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
927 mutt_error _("Invalid encoding.");
929 mutt_message_hook (NULL, msg, M_SEND2HOOK);
932 case OP_COMPOSE_SEND_MESSAGE:
934 /* Note: We don't invoke send2-hook here, since we want to leave
935 * users an opportunity to change settings from the ":" prompt.
938 if(check_attachments(idx, idxlen) != 0)
940 menu->redraw = REDRAW_FULL;
946 if (msg->chain && mix_check_message (msg) != 0)
952 if ((i = query_quadoption (OPT_COPY,
953 _("Save a copy of this message?"))) == -1)
963 case OP_COMPOSE_EDIT_FILE:
965 mutt_edit_file (NONULL(Editor), idx[menu->current]->content->filename);
966 mutt_update_encoding (idx[menu->current]->content);
967 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
968 mutt_message_hook (NULL, msg, M_SEND2HOOK);
971 case OP_COMPOSE_TOGGLE_UNLINK:
973 idx[menu->current]->content->unlink = !idx[menu->current]->content->unlink;
976 /* OPTRESOLVE is otherwise ignored on this menu.
980 if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
983 menu->redraw = REDRAW_INDEX;
984 /* No send2hook since this doesn't change the message. */
987 case OP_COMPOSE_GET_ATTACHMENT:
992 for(top = msg->content; top; top = top->next)
995 mutt_get_tmp_attachment(top);
997 menu->redraw = REDRAW_FULL;
999 else if (mutt_get_tmp_attachment(idx[menu->current]->content) == 0)
1000 menu->redraw = REDRAW_CURRENT;
1002 /* No send2hook since this doesn't change the message. */
1005 case OP_COMPOSE_RENAME_FILE:
1007 strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname));
1008 mutt_pretty_mailbox (fname);
1009 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1012 if (stat(idx[menu->current]->content->filename, &st) == -1)
1014 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1018 mutt_expand_path (fname, sizeof (fname));
1019 if(mutt_rename_file (idx[menu->current]->content->filename, fname))
1022 mutt_str_replace (&idx[menu->current]->content->filename, fname);
1023 menu->redraw = REDRAW_CURRENT;
1025 if(idx[menu->current]->content->stamp >= st.st_mtime)
1026 mutt_stamp_attachment(idx[menu->current]->content);
1029 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1032 case OP_COMPOSE_NEW_MIME:
1039 CLEARLINE (LINES-1);
1041 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1044 mutt_expand_path (fname, sizeof (fname));
1046 /* Call to lookup_mime_type () ? maybe later */
1048 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1052 if (!(p = strchr (type, '/')))
1054 mutt_error _("Content-Type is of the form base/sub");
1058 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER)
1060 mutt_error (_("Unknown Content-Type %s"), type);
1063 if (idxlen == idxmax)
1065 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
1069 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
1070 /* Touch the file */
1071 if (!(fp = safe_fopen (fname, "w")))
1073 mutt_error (_("Can't create file %s"), fname);
1074 FREE (&idx[idxlen]);
1079 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL)
1081 mutt_error _("What we have here is a failure to make an attachment");
1084 update_idx (menu, idx, idxlen++);
1086 idx[menu->current]->content->type = itype;
1087 mutt_str_replace (&idx[menu->current]->content->subtype, p);
1088 idx[menu->current]->content->unlink = 1;
1089 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1091 if (mutt_compose_attachment (idx[menu->current]->content))
1093 mutt_update_encoding (idx[menu->current]->content);
1094 menu->redraw = REDRAW_FULL;
1097 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1100 case OP_COMPOSE_EDIT_MIME:
1102 if (mutt_edit_attachment (idx[menu->current]->content))
1104 mutt_update_encoding (idx[menu->current]->content);
1105 menu->redraw = REDRAW_FULL;
1107 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1110 case OP_VIEW_ATTACH:
1111 case OP_DISPLAY_HEADERS:
1113 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen, NULL, 0);
1114 menu->redraw = REDRAW_FULL;
1115 /* no send2hook, since this doesn't modify the message */
1120 mutt_save_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, NULL, menu);
1121 MAYBE_REDRAW (menu->redraw);
1122 /* no send2hook, since this doesn't modify the message */
1127 mutt_print_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content);
1128 /* no send2hook, since this doesn't modify the message */
1134 mutt_pipe_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, op == OP_FILTER);
1135 if (op == OP_FILTER) /* cte might have changed */
1136 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1137 menu->redraw |= REDRAW_STATUS;
1138 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1142 if ((i = query_quadoption (OPT_POSTPONE, _("Postpone this message?"))) == M_NO)
1144 while (idxlen-- > 0)
1146 /* avoid freeing other attachments */
1147 idx[idxlen]->content->next = NULL;
1148 idx[idxlen]->content->parts = NULL;
1149 if (idx[idxlen]->unowned)
1150 idx[idxlen]->content->unlink = 0;
1151 mutt_free_body (&idx[idxlen]->content);
1152 FREE (&idx[idxlen]->tree);
1153 FREE (&idx[idxlen]);
1165 /* fall through to postpone! */
1167 case OP_COMPOSE_POSTPONE_MESSAGE:
1169 if(check_attachments(idx, idxlen) != 0)
1171 menu->redraw = REDRAW_FULL;
1179 case OP_COMPOSE_ISPELL:
1181 snprintf (buf, sizeof (buf), "%s -x %s", NONULL(Ispell), msg->content->filename);
1182 if (mutt_system (buf) == -1)
1183 mutt_error (_("Error running \"%s\"!"), buf);
1186 mutt_update_encoding (msg->content);
1187 menu->redraw |= REDRAW_STATUS;
1191 case OP_COMPOSE_WRITE_MESSAGE:
1196 strfcpy (fname, NONULL (Context->path), sizeof (fname));
1197 mutt_pretty_mailbox (fname);
1200 msg->content = idx[0]->content;
1201 if (mutt_enter_fname (_("Write message to mailbox"), fname, sizeof (fname),
1202 &menu->redraw, 1) != -1 && fname[0])
1204 mutt_message (_("Writing message to %s ..."), fname);
1205 mutt_expand_path (fname, sizeof (fname));
1207 if (msg->content->next)
1208 msg->content = mutt_make_multipart (msg->content);
1210 if (mutt_write_fcc (fname, msg, NULL, 1, NULL) < 0)
1211 msg->content = mutt_remove_multipart (msg->content);
1213 mutt_message _("Message written.");
1219 case OP_COMPOSE_PGP_MENU:
1220 if (!(WithCrypto & APPLICATION_PGP))
1222 if ((WithCrypto & APPLICATION_SMIME)
1223 && msg->security & APPLICATION_SMIME)
1225 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1228 mutt_clear_error ();
1233 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1234 redraw_crypt_lines (msg);
1235 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1239 case OP_FORGET_PASSPHRASE:
1240 crypt_forget_passphrase ();
1244 case OP_COMPOSE_SMIME_MENU:
1245 if (!(WithCrypto & APPLICATION_SMIME))
1248 if ((WithCrypto & APPLICATION_PGP)
1249 && msg->security & APPLICATION_PGP)
1251 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1254 mutt_clear_error ();
1259 msg->security = crypt_smime_send_menu(msg, &menu->redraw);
1260 redraw_crypt_lines (msg);
1261 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1266 case OP_COMPOSE_MIX:
1268 mix_make_chain (&msg->chain, &menu->redraw);
1269 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1275 /* Draw formated compose status line */
1276 if (menu->redraw & REDRAW_STATUS)
1278 compose_status_line (buf, sizeof (buf), 0, menu, NONULL(ComposeFormat));
1279 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
1280 SETCOLOR (MT_COLOR_STATUS);
1281 BKGDSET (MT_COLOR_STATUS);
1282 mutt_paddstr (COLS, buf);
1283 SETCOLOR (MT_COLOR_NORMAL);
1284 BKGDSET (MT_COLOR_NORMAL);
1285 menu->redraw &= ~REDRAW_STATUS;
1289 mutt_menuDestroy (&menu);
1293 msg->content = idx[0]->content;
1294 for (i = 0; i < idxlen; i++)
1296 idx[i]->content->aptr = NULL;
1301 msg->content = NULL;