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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 #include "mutt_curses.h"
22 #include "mutt_idna.h"
23 #include "mutt_menu.h"
48 static const char* There_are_no_attachments = N_("There are no attachments.");
50 #define CHECK_COUNT if (idxlen == 0) { mutt_error _(There_are_no_attachments); break; }
78 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
80 HDR_ATTACH = (HDR_FCC + 7)
84 #define HDR_XOFFSET 14
85 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
86 #define W (COLS - HDR_XOFFSET - SidebarWidth)
88 static char *Prompts[] =
109 static struct mapping_t ComposeHelp[] = {
110 { N_("Send"), OP_COMPOSE_SEND_MESSAGE },
111 { N_("Abort"), OP_EXIT },
112 { "To", OP_COMPOSE_EDIT_TO },
113 { "CC", OP_COMPOSE_EDIT_CC },
114 { "Subj", OP_COMPOSE_EDIT_SUBJECT },
115 { N_("Attach file"), OP_COMPOSE_ATTACH_FILE },
116 { N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION },
117 { N_("Help"), OP_HELP },
122 static struct mapping_t ComposeNewsHelp[] = {
123 { N_("Send"), OP_COMPOSE_SEND_MESSAGE },
124 { N_("Abort"), OP_EXIT },
125 { "Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS },
126 { "Subj", OP_COMPOSE_EDIT_SUBJECT },
127 { N_("Attach file"), OP_COMPOSE_ATTACH_FILE },
128 { N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION },
129 { N_("Help"), OP_HELP },
134 static void snd_entry (char *b, size_t blen, MUTTMENU *menu, int num)
136 mutt_FormatString (b, blen, NONULL (AttachFormat), mutt_attach_fmt,
137 (unsigned long)(((ATTACHPTR **) menu->data)[num]),
138 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
143 #include "mutt_crypt.h"
145 static void redraw_crypt_lines (HEADER *msg)
149 if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME))
152 mvaddstr (HDR_CRYPT, SidebarWidth, " Security: ");
153 else if (msg->security & APPLICATION_SMIME)
154 mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
155 else if (msg->security & APPLICATION_PGP)
156 mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
158 else if ((WithCrypto & APPLICATION_SMIME))
159 mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
160 else if ((WithCrypto & APPLICATION_PGP))
161 mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
165 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
166 addstr (_("Sign, Encrypt"));
167 else if (msg->security & ENCRYPT)
168 addstr (_("Encrypt"));
169 else if (msg->security & SIGN)
174 if ((WithCrypto & APPLICATION_PGP))
175 if ((msg->security & APPLICATION_PGP)
176 && (msg->security & (ENCRYPT | SIGN)))
178 if ((msg->security & INLINE))
179 addstr (_(" (inline)"));
181 addstr (_(" (PGP/MIME)"));
185 move (HDR_CRYPTINFO, SidebarWidth);
187 if ((WithCrypto & APPLICATION_PGP)
188 && msg->security & APPLICATION_PGP && msg->security & SIGN)
189 printw ("%s%s", _(" sign as: "), PgpSignAs ? PgpSignAs : _("<default>"));
191 if ((WithCrypto & APPLICATION_SMIME)
192 && msg->security & APPLICATION_SMIME && msg->security & SIGN) {
193 printw ("%s%s", _(" sign as: "), SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
196 if ((WithCrypto & APPLICATION_SMIME)
197 && (msg->security & APPLICATION_SMIME)
198 && (msg->security & ENCRYPT)
201 mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "),
202 NONULL(SmimeCryptAlg));
210 static void redraw_mix_line (LIST *chain)
215 mvaddstr (HDR_MIX, SidebarWidth, " Mix: ");
219 addstr ("<no chain defined>");
224 for (c = 12; chain; chain = chain->next)
227 if (t && t[0] == '0' && t[1] == '\0')
230 if (c + mutt_strlen (t) + 2 >= COLS - SidebarWidth)
237 c += mutt_strlen (t) + 2;
240 #endif /* MIXMASTER */
243 check_attachments(ATTACHPTR **idx, short idxlen)
247 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
249 for (i = 0; i < idxlen; i++)
251 strfcpy(pretty, idx[i]->content->filename, sizeof(pretty));
252 if(stat(idx[i]->content->filename, &st) != 0)
254 mutt_pretty_mailbox(pretty);
255 mutt_error(_("%s [#%d] no longer exists!"),
260 if(idx[i]->content->stamp < st.st_mtime)
262 mutt_pretty_mailbox(pretty);
263 snprintf(msg, sizeof(msg), _("%s [#%d] modified. Update encoding?"),
266 if((r = mutt_yesorno(msg, M_YES)) == M_YES)
267 mutt_update_encoding(idx[i]->content);
276 static void draw_envelope_addr (int line, ADDRESS *addr)
281 rfc822_write_address (buf, sizeof (buf), addr, 1);
282 mvprintw (line, SidebarWidth, TITLE_FMT, Prompts[line - 1]);
283 mutt_paddstr (W, buf);
286 static void draw_envelope (HEADER *msg, char *fcc)
288 draw_envelope_addr (HDR_FROM, msg->env->from);
290 if (!option (OPTNEWSSEND))
293 draw_envelope_addr (HDR_TO, msg->env->to);
294 draw_envelope_addr (HDR_CC, msg->env->cc);
295 draw_envelope_addr (HDR_BCC, msg->env->bcc);
300 mvprintw (HDR_TO, 0, TITLE_FMT , Prompts[HDR_NEWSGROUPS - 1]);
301 mutt_paddstr (W, NONULL (msg->env->newsgroups));
302 mvprintw (HDR_CC, 0, TITLE_FMT , Prompts[HDR_FOLLOWUPTO - 1]);
303 mutt_paddstr (W, NONULL (msg->env->followup_to));
304 if (option (OPTXCOMMENTTO))
306 mvprintw (HDR_BCC, 0, TITLE_FMT , Prompts[HDR_XCOMMENTTO - 1]);
307 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
311 mvprintw (HDR_SUBJECT, SidebarWidth, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
312 mutt_paddstr (W, NONULL (msg->env->subject));
313 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
314 mvprintw (HDR_FCC, SidebarWidth, TITLE_FMT, Prompts[HDR_FCC - 1]);
315 mutt_paddstr (W, fcc);
318 redraw_crypt_lines (msg);
321 redraw_mix_line (msg->chain);
324 SETCOLOR (MT_COLOR_STATUS);
325 mvaddstr (HDR_ATTACH - 1, SidebarWidth, _("-- Attachments"));
326 BKGDSET (MT_COLOR_STATUS);
329 BKGDSET (MT_COLOR_NORMAL);
330 SETCOLOR (MT_COLOR_NORMAL);
333 static int edit_address_list (int line, ADDRESS **addr)
335 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
338 mutt_addrlist_to_local (*addr);
339 rfc822_write_address (buf, sizeof (buf), *addr, 0);
340 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0)
342 rfc822_free_address (addr);
343 *addr = mutt_parse_adrlist (*addr, buf);
344 *addr = mutt_expand_aliases (*addr);
347 if (option (OPTNEEDREDRAW))
349 unset_option (OPTNEEDREDRAW);
350 return (REDRAW_FULL);
353 if (mutt_addrlist_to_idna (*addr, &err) != 0)
355 mutt_error (_("Warning: '%s' is a bad IDN."), err);
360 /* redraw the expanded list so the user can see the result */
362 rfc822_write_address (buf, sizeof (buf), *addr, 1);
363 move (line, HDR_XOFFSET+SidebarWidth);
364 mutt_paddstr (W, buf);
369 static int delete_attachment (MUTTMENU *menu, short *idxlen, int x)
371 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
374 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
376 if (x == 0 && menu->max == 1)
378 mutt_error _("You may not delete the only attachment.");
379 idx[x]->content->tagged = 0;
383 for (y = 0; y < *idxlen; y++)
385 if (idx[y]->content->next == idx[x]->content)
387 idx[y]->content->next = idx[x]->content->next;
392 idx[x]->content->next = NULL;
393 idx[x]->content->parts = NULL;
394 mutt_free_body (&(idx[x]->content));
395 FREE (&idx[x]->tree);
397 for (; x < *idxlen - 1; x++)
399 menu->max = --(*idxlen);
404 static void update_idx (MUTTMENU *menu, ATTACHPTR **idx, short idxlen)
406 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen-1]->level : 0;
408 idx[idxlen - 1]->content->next = idx[idxlen]->content;
409 idx[idxlen]->content->aptr = idx[idxlen];
410 menu->current = idxlen++;
411 mutt_update_tree (idx, idxlen);
418 * cum_attachs_size: Cumulative Attachments Size
420 * Returns the total number of bytes used by the attachments in the
421 * attachment list _after_ content-transfer-encodings have been
426 static unsigned long cum_attachs_size (MUTTMENU *menu)
430 ATTACHPTR **idx = menu->data;
434 for (i = 0, s = 0; i < menu->max; i++)
439 b->content = mutt_get_content_info (b->filename, b);
441 if ((info = b->content))
445 case ENCQUOTEDPRINTABLE:
446 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
449 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
452 s += info->lobin + info->hibin + info->ascii + info->crlf;
461 /* prototype for use below */
462 static void compose_status_line (char *buf, size_t buflen, MUTTMENU *menu,
466 * compose_format_str()
468 * %a = total number of attachments
469 * %h = hostname [option]
470 * %l = approx. length of current message (in bytes)
473 * This function is similar to status_format_str(). Look at that function for
474 * help when modifying this function.
478 compose_format_str (char *buf, size_t buflen, char op, const char *src,
479 const char *prefix, const char *ifstring,
480 const char *elsestring,
481 unsigned long data, format_flag flags)
483 char fmt[SHORT_STRING], tmp[SHORT_STRING];
484 int optional = (flags & M_FORMAT_OPTIONAL);
485 MUTTMENU *menu = (MUTTMENU *) data;
490 case 'a': /* total number of attachments */
491 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
492 snprintf (buf, buflen, fmt, menu->max);
495 case 'h': /* hostname */
496 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
497 snprintf (buf, buflen, fmt, NONULL(Hostname));
500 case 'l': /* approx length of current message in bytes */
501 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
502 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size(menu) : 0);
503 snprintf (buf, buflen, fmt, tmp);
507 snprintf (fmt, sizeof (fmt), "Mutt %%s");
508 snprintf (buf, buflen, fmt, MUTT_VERSION);
516 snprintf (buf, buflen, "%%%s%c", prefix, op);
521 compose_status_line (buf, buflen, menu, ifstring);
522 else if (flags & M_FORMAT_OPTIONAL)
523 compose_status_line (buf, buflen, menu, elsestring);
528 static void compose_status_line (char *buf, size_t buflen, MUTTMENU *menu,
531 mutt_FormatString (buf, buflen, p, compose_format_str,
532 (unsigned long) menu, 0);
538 * 1 message should be postponed
542 int mutt_compose_menu (HEADER *msg, /* structure for new message */
543 char *fcc, /* where to save a copy of the message */
545 HEADER *cur) /* current message */
547 char helpstr[SHORT_STRING];
548 char buf[LONG_STRING];
549 char fname[_POSIX_PATH_MAX];
551 ATTACHPTR **idx = NULL;
555 int r = -1; /* return value */
558 int fccSet = 0; /* has the user edited the Fcc: field ? */
559 CONTEXT *ctx = NULL, *this = NULL;
560 /* Sort, SortAux could be changed in mutt_index_menu() */
561 int oldSort, oldSortAux;
564 int news = 0; /* is it a news article ? */
566 if (option (OPTNEWSSEND))
570 mutt_attach_init (msg->content);
571 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
573 menu = mutt_new_menu ();
574 menu->menu = MENU_COMPOSE;
575 menu->offset = HDR_ATTACH;
577 menu->make_entry = snd_entry;
578 menu->tag = mutt_tag_attach;
582 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeNewsHelp);
585 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeHelp);
590 unset_option (OPTNEWS); /* for any case */
592 switch (op = mutt_menuLoop (menu))
595 draw_envelope (msg, fcc);
596 menu->offset = HDR_ATTACH;
597 menu->pagelen = LINES - HDR_ATTACH - 2;
599 case OP_COMPOSE_EDIT_FROM:
600 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
601 mutt_message_hook (NULL, msg, M_SEND2HOOK);
603 case OP_COMPOSE_EDIT_TO:
607 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
608 mutt_message_hook (NULL, msg, M_SEND2HOOK);
613 case OP_COMPOSE_EDIT_BCC:
617 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
618 mutt_message_hook (NULL, msg, M_SEND2HOOK);
623 case OP_COMPOSE_EDIT_CC:
627 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
628 mutt_message_hook (NULL, msg, M_SEND2HOOK);
634 case OP_COMPOSE_EDIT_NEWSGROUPS:
637 if (msg->env->newsgroups)
638 strfcpy (buf, msg->env->newsgroups, sizeof (buf));
641 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0 && buf[0])
643 FREE (&msg->env->newsgroups);
644 mutt_remove_trailing_ws (buf);
645 msg->env->newsgroups = safe_strdup (mutt_skip_whitespace (buf));
646 move (HDR_TO, HDR_XOFFSET);
648 if (msg->env->newsgroups)
649 printw ("%-*.*s", W, W, msg->env->newsgroups);
654 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
658 if (msg->env->followup_to)
659 strfcpy (buf, msg->env->followup_to, sizeof (buf));
660 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0 && buf[0])
662 FREE (&msg->env->followup_to);
663 mutt_remove_trailing_ws (buf);
664 msg->env->followup_to = safe_strdup (mutt_skip_whitespace (buf));
665 move (HDR_CC, HDR_XOFFSET);
667 if (msg->env->followup_to)
668 printw ("%-*.*s", W, W, msg->env->followup_to);
673 case OP_COMPOSE_EDIT_X_COMMENT_TO:
674 if (news && option (OPTXCOMMENTTO))
677 if (msg->env->x_comment_to)
678 strfcpy (buf, msg->env->x_comment_to, sizeof (buf));
679 if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0 && buf[0])
681 FREE (&msg->env->x_comment_to);
682 msg->env->x_comment_to = safe_strdup (buf);
683 move (HDR_BCC, HDR_XOFFSET);
685 if (msg->env->x_comment_to)
686 printw ("%-*.*s", W, W, msg->env->x_comment_to);
691 case OP_COMPOSE_EDIT_SUBJECT:
692 if (msg->env->subject)
693 strfcpy (buf, msg->env->subject, sizeof (buf));
696 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
698 mutt_str_replace (&msg->env->subject, buf);
699 move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
701 if (msg->env->subject)
702 mutt_paddstr (W, msg->env->subject);
704 mutt_message_hook (NULL, msg, M_SEND2HOOK);
706 case OP_COMPOSE_EDIT_REPLY_TO:
707 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
708 mutt_message_hook (NULL, msg, M_SEND2HOOK);
710 case OP_COMPOSE_EDIT_FCC:
711 strfcpy (buf, fcc, sizeof (buf));
712 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0)
714 strfcpy (fcc, buf, _POSIX_PATH_MAX);
715 mutt_pretty_mailbox (fcc);
716 move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
717 mutt_paddstr (W, fcc);
720 MAYBE_REDRAW (menu->redraw);
721 mutt_message_hook (NULL, msg, M_SEND2HOOK);
723 case OP_COMPOSE_EDIT_MESSAGE:
724 if (Editor && (mutt_strcmp ("builtin", Editor) != 0) && !option (OPTEDITHDRS))
726 mutt_edit_file (Editor, msg->content->filename);
727 mutt_update_encoding (msg->content);
728 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
729 mutt_message_hook (NULL, msg, M_SEND2HOOK);
733 case OP_COMPOSE_EDIT_HEADERS:
734 if (mutt_strcmp ("builtin", Editor) != 0 &&
735 (op == OP_COMPOSE_EDIT_HEADERS ||
736 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS))))
738 char *tag = NULL, *err = NULL;
739 mutt_env_to_local (msg->env);
740 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
742 if (mutt_env_to_idna (msg->env, &tag, &err))
744 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
750 /* this is grouped with OP_COMPOSE_EDIT_HEADERS because the
751 attachment list could change if the user invokes ~v to edit
752 the message with headers, in which we need to execute the
753 code below to regenerate the index array */
754 mutt_builtin_editor (msg->content->filename, msg, cur);
756 mutt_update_encoding (msg->content);
758 /* attachments may have been added */
759 if (idxlen && idx[idxlen - 1]->content->next)
761 for (i = 0; i < idxlen; i++)
764 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
769 menu->redraw = REDRAW_FULL;
770 mutt_message_hook (NULL, msg, M_SEND2HOOK);
775 case OP_COMPOSE_ATTACH_KEY:
776 if (!(WithCrypto & APPLICATION_PGP))
778 if (idxlen == idxmax)
780 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
784 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
785 if ((idx[idxlen]->content = crypt_pgp_make_key_attachment(NULL)) != NULL)
787 update_idx (menu, idx, idxlen++);
788 menu->redraw |= REDRAW_INDEX;
793 menu->redraw |= REDRAW_STATUS;
795 if (option(OPTNEEDREDRAW))
797 menu->redraw = REDRAW_FULL;
798 unset_option(OPTNEEDREDRAW);
801 mutt_message_hook (NULL, msg, M_SEND2HOOK);
805 case OP_COMPOSE_ATTACH_FILE:
807 char *prompt, **files;
811 prompt = _("Attach file");
815 if (_mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files, &numfiles) == -1 ||
819 if (idxlen + numfiles >= idxmax)
821 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles));
827 mutt_message _("Attaching selected files...");
828 for (i = 0; i < numfiles; i++)
830 char *att = files[i];
831 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
832 idx[idxlen]->content = mutt_make_file_attach (att);
833 if (idx[idxlen]->content != NULL)
834 update_idx (menu, idx, idxlen++);
838 mutt_error (_("Unable to attach %s!"), att);
844 if (!error) mutt_clear_error ();
846 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
848 mutt_message_hook (NULL, msg, M_SEND2HOOK);
851 case OP_COMPOSE_ATTACH_MESSAGE:
853 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
860 prompt = _("Open mailbox to attach message from");
863 unset_option (OPTNEWS);
864 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE)
866 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
869 prompt = _("Open newsgroup to attach message from");
870 set_option (OPTNEWS);
876 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
879 strfcpy (fname, NONULL (Context->path), sizeof (fname));
880 mutt_pretty_mailbox (fname);
883 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1) == -1 || !fname[0])
887 if (option (OPTNEWS))
888 nntp_expand_path (fname, sizeof (fname), &CurrentNewsSrv->conn->account);
891 mutt_expand_path (fname, sizeof (fname));
893 if (!mx_is_imap (fname))
896 if (!mx_is_pop (fname))
899 if (!mx_is_nntp (fname) && !option (OPTNEWS))
901 /* check to make sure the file exists and is readable */
902 if (access (fname, R_OK) == -1)
908 menu->redraw = REDRAW_FULL;
910 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
919 mx_close_mailbox (ctx, NULL);
921 mutt_error _("No messages in that folder.");
925 this = Context; /* remember current folder and sort methods*/
926 oldSort = Sort; oldSortAux = SortAux;
929 set_option(OPTATTACHMSG);
930 mutt_message _("Tag the messages you want to attach!");
931 close = mutt_index_menu ();
932 unset_option(OPTATTACHMSG);
936 /* go back to the folder we started from */
938 /* Restore old $sort and $sort_aux */
940 SortAux = oldSortAux;
941 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
945 if (idxlen + Context->tagged >= idxmax)
947 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + Context->tagged));
951 for (i = 0; i < Context->msgcount; i++)
953 h = Context->hdrs[i];
956 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
957 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
958 if (idx[idxlen]->content != NULL)
959 update_idx (menu, idx, idxlen++);
962 mutt_error _("Unable to attach!");
967 menu->redraw |= REDRAW_FULL;
969 if (close == OP_QUIT)
970 mx_close_mailbox (Context, NULL);
972 mx_fastclose_mailbox (Context);
975 /* go back to the folder we started from */
977 /* Restore old $sort and $sort_aux */
979 SortAux = oldSortAux;
981 mutt_message_hook (NULL, msg, M_SEND2HOOK);
986 if (delete_attachment (menu, &idxlen, menu->current) == -1)
988 mutt_update_tree (idx, idxlen);
991 if (menu->current > idxlen - 1)
992 menu->current = idxlen - 1;
997 if (menu->current == 0)
998 msg->content = idx[0]->content;
1000 menu->redraw |= REDRAW_STATUS;
1001 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1004 #define CURRENT idx[menu->current]->content
1006 case OP_COMPOSE_TOGGLE_RECODE:
1009 if (!mutt_is_text_part (CURRENT))
1011 mutt_error (_("Recoding only affects text attachments."));
1014 CURRENT->noconv = !CURRENT->noconv;
1015 if (CURRENT->noconv)
1016 mutt_message (_("The current attachment won't be converted."));
1018 mutt_message (_("The current attachment will be converted."));
1019 menu->redraw = REDRAW_CURRENT;
1020 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1025 case OP_COMPOSE_EDIT_DESCRIPTION:
1028 idx[menu->current]->content->description ?
1029 idx[menu->current]->content->description : "",
1031 /* header names should not be translated */
1032 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0)
1034 mutt_str_replace (&idx[menu->current]->content->description, buf);
1035 menu->redraw = REDRAW_CURRENT;
1037 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1040 case OP_COMPOSE_UPDATE_ENCODING:
1042 if (menu->tagprefix)
1045 for (top = msg->content; top; top = top->next)
1048 mutt_update_encoding (top);
1050 menu->redraw = REDRAW_FULL;
1054 mutt_update_encoding(idx[menu->current]->content);
1055 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1057 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1060 case OP_COMPOSE_TOGGLE_DISPOSITION:
1061 /* toggle the content-disposition between inline/attachment */
1062 idx[menu->current]->content->disposition = (idx[menu->current]->content->disposition == DISPINLINE) ? DISPATTACH : DISPINLINE;
1063 menu->redraw = REDRAW_CURRENT;
1069 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
1071 /* this may have been a change to text/something */
1072 mutt_update_encoding (idx[menu->current]->content);
1074 menu->redraw = REDRAW_CURRENT;
1076 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1079 case OP_COMPOSE_EDIT_ENCODING:
1081 strfcpy (buf, ENCODING (idx[menu->current]->content->encoding),
1083 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
1084 sizeof (buf), 0) == 0 && buf[0])
1086 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED)
1088 idx[menu->current]->content->encoding = i;
1089 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1093 mutt_error _("Invalid encoding.");
1095 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1098 case OP_COMPOSE_SEND_MESSAGE:
1100 /* Note: We don't invoke send2-hook here, since we want to leave
1101 * users an opportunity to change settings from the ":" prompt.
1104 if(check_attachments(idx, idxlen) != 0)
1106 menu->redraw = REDRAW_FULL;
1112 if (msg->chain && mix_check_message (msg) != 0)
1116 if (!fccSet && *fcc)
1118 if ((i = query_quadoption (OPT_COPY,
1119 _("Save a copy of this message?"))) == -1)
1129 case OP_COMPOSE_EDIT_FILE:
1131 mutt_edit_file (NONULL(Editor), idx[menu->current]->content->filename);
1132 mutt_update_encoding (idx[menu->current]->content);
1133 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1134 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1137 case OP_COMPOSE_TOGGLE_UNLINK:
1139 idx[menu->current]->content->unlink = !idx[menu->current]->content->unlink;
1142 /* OPTRESOLVE is otherwise ignored on this menu.
1146 if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
1149 menu->redraw = REDRAW_INDEX;
1150 /* No send2hook since this doesn't change the message. */
1153 case OP_COMPOSE_GET_ATTACHMENT:
1158 for(top = msg->content; top; top = top->next)
1161 mutt_get_tmp_attachment(top);
1163 menu->redraw = REDRAW_FULL;
1165 else if (mutt_get_tmp_attachment(idx[menu->current]->content) == 0)
1166 menu->redraw = REDRAW_CURRENT;
1168 /* No send2hook since this doesn't change the message. */
1171 case OP_COMPOSE_RENAME_FILE:
1173 strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname));
1174 mutt_pretty_mailbox (fname);
1175 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1178 if (stat(idx[menu->current]->content->filename, &st) == -1)
1180 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1184 mutt_expand_path (fname, sizeof (fname));
1185 if(mutt_rename_file (idx[menu->current]->content->filename, fname))
1188 mutt_str_replace (&idx[menu->current]->content->filename, fname);
1189 menu->redraw = REDRAW_CURRENT;
1191 if(idx[menu->current]->content->stamp >= st.st_mtime)
1192 mutt_stamp_attachment(idx[menu->current]->content);
1195 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1198 case OP_COMPOSE_NEW_MIME:
1205 CLEARLINE (LINES-1);
1207 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1210 mutt_expand_path (fname, sizeof (fname));
1212 /* Call to lookup_mime_type () ? maybe later */
1214 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1218 if (!(p = strchr (type, '/')))
1220 mutt_error _("Content-Type is of the form base/sub");
1224 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER)
1226 mutt_error (_("Unknown Content-Type %s"), type);
1229 if (idxlen == idxmax)
1231 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
1235 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
1236 /* Touch the file */
1237 if (!(fp = safe_fopen (fname, "w")))
1239 mutt_error (_("Can't create file %s"), fname);
1240 FREE (&idx[idxlen]);
1245 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL)
1247 mutt_error _("What we have here is a failure to make an attachment");
1250 update_idx (menu, idx, idxlen++);
1252 idx[menu->current]->content->type = itype;
1253 mutt_str_replace (&idx[menu->current]->content->subtype, p);
1254 idx[menu->current]->content->unlink = 1;
1255 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1257 if (mutt_compose_attachment (idx[menu->current]->content))
1259 mutt_update_encoding (idx[menu->current]->content);
1260 menu->redraw = REDRAW_FULL;
1263 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1266 case OP_COMPOSE_EDIT_MIME:
1268 if (mutt_edit_attachment (idx[menu->current]->content))
1270 mutt_update_encoding (idx[menu->current]->content);
1271 menu->redraw = REDRAW_FULL;
1273 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1276 case OP_VIEW_ATTACH:
1277 case OP_DISPLAY_HEADERS:
1279 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen, NULL, 0);
1280 menu->redraw = REDRAW_FULL;
1281 /* no send2hook, since this doesn't modify the message */
1286 mutt_save_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, NULL, menu);
1287 MAYBE_REDRAW (menu->redraw);
1288 /* no send2hook, since this doesn't modify the message */
1293 mutt_print_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content);
1294 /* no send2hook, since this doesn't modify the message */
1300 mutt_pipe_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, op == OP_FILTER);
1301 if (op == OP_FILTER) /* cte might have changed */
1302 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1303 menu->redraw |= REDRAW_STATUS;
1304 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1308 if ((i = query_quadoption (OPT_POSTPONE, _("Postpone this message?"))) == M_NO)
1310 while (idxlen-- > 0)
1312 /* avoid freeing other attachments */
1313 idx[idxlen]->content->next = NULL;
1314 idx[idxlen]->content->parts = NULL;
1315 mutt_free_body (&idx[idxlen]->content);
1316 FREE (&idx[idxlen]->tree);
1317 FREE (&idx[idxlen]);
1329 /* fall through to postpone! */
1331 case OP_COMPOSE_POSTPONE_MESSAGE:
1333 if(check_attachments(idx, idxlen) != 0)
1335 menu->redraw = REDRAW_FULL;
1343 case OP_COMPOSE_ISPELL:
1345 snprintf (buf, sizeof (buf), "%s -x %s", NONULL(Ispell), msg->content->filename);
1346 if (mutt_system (buf) == -1)
1347 mutt_error (_("Error running \"%s\"!"), buf);
1350 mutt_update_encoding (msg->content);
1351 menu->redraw |= REDRAW_STATUS;
1355 case OP_COMPOSE_WRITE_MESSAGE:
1360 strfcpy (fname, NONULL (Context->path), sizeof (fname));
1361 mutt_pretty_mailbox (fname);
1364 msg->content = idx[0]->content;
1365 if (mutt_enter_fname (_("Write message to mailbox"), fname, sizeof (fname),
1366 &menu->redraw, 1) != -1 && fname[0])
1368 mutt_message (_("Writing message to %s ..."), fname);
1369 mutt_expand_path (fname, sizeof (fname));
1371 if (msg->content->next)
1372 msg->content = mutt_make_multipart (msg->content);
1374 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1375 msg->content = mutt_remove_multipart (msg->content);
1377 mutt_message _("Message written.");
1383 case OP_COMPOSE_PGP_MENU:
1384 if (!(WithCrypto & APPLICATION_PGP))
1386 if ((WithCrypto & APPLICATION_SMIME)
1387 && msg->security & APPLICATION_SMIME)
1389 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1392 mutt_clear_error ();
1397 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1398 redraw_crypt_lines (msg);
1399 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1403 case OP_FORGET_PASSPHRASE:
1404 crypt_forget_passphrase ();
1408 case OP_COMPOSE_SMIME_MENU:
1409 if (!(WithCrypto & APPLICATION_SMIME))
1412 if ((WithCrypto & APPLICATION_PGP)
1413 && msg->security & APPLICATION_PGP)
1415 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1418 mutt_clear_error ();
1423 msg->security = crypt_smime_send_menu(msg, &menu->redraw);
1424 redraw_crypt_lines (msg);
1425 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1430 case OP_COMPOSE_MIX:
1432 mix_make_chain (&msg->chain, &menu->redraw);
1433 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1439 /* Draw formated compose status line */
1440 if (menu->redraw & REDRAW_STATUS)
1442 compose_status_line (buf, sizeof (buf), menu, NONULL(ComposeFormat));
1443 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
1444 SETCOLOR (MT_COLOR_STATUS);
1445 printw ("%-*.*s", COLS, COLS, buf);
1446 SETCOLOR (MT_COLOR_NORMAL);
1447 menu->redraw &= ~REDRAW_STATUS;
1451 mutt_menuDestroy (&menu);
1455 msg->content = idx[0]->content;
1456 for (i = 0; i < idxlen; i++)
1458 idx[i]->content->aptr = NULL;
1463 msg->content = NULL;