2 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
20 #include "mutt_curses.h"
21 #include "mutt_idna.h"
22 #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; }
73 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
76 #define HDR_XOFFSET 14
77 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
78 #define W (COLS - HDR_XOFFSET - SidebarWidth)
80 static char *Prompts[] =
101 static struct mapping_t ComposeHelp[] = {
102 { N_("Send"), OP_COMPOSE_SEND_MESSAGE },
103 { N_("Abort"), OP_EXIT },
104 { "To", OP_COMPOSE_EDIT_TO },
105 { "CC", OP_COMPOSE_EDIT_CC },
106 { "Subj", OP_COMPOSE_EDIT_SUBJECT },
107 { N_("Attach file"), OP_COMPOSE_ATTACH_FILE },
108 { N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION },
109 { N_("Help"), OP_HELP },
114 static struct mapping_t ComposeNewsHelp[] = {
115 { N_("Send"), OP_COMPOSE_SEND_MESSAGE },
116 { N_("Abort"), OP_EXIT },
117 { "Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS },
118 { "Subj", OP_COMPOSE_EDIT_SUBJECT },
119 { N_("Attach file"), OP_COMPOSE_ATTACH_FILE },
120 { N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION },
121 { N_("Help"), OP_HELP },
126 static void snd_entry (char *b, size_t blen, MUTTMENU *menu, int num)
128 mutt_FormatString (b, blen, NONULL (AttachFormat), mutt_attach_fmt,
129 (unsigned long)(((ATTACHPTR **) menu->data)[num]),
130 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
135 #include "mutt_crypt.h"
137 static void redraw_crypt_lines (HEADER *msg)
141 if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME))
144 mvaddstr (HDR_CRYPT, SidebarWidth, " Security: ");
145 else if (msg->security & APPLICATION_SMIME)
146 mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
147 else if (msg->security & APPLICATION_PGP)
148 mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
150 else if ((WithCrypto & APPLICATION_SMIME))
151 mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
152 else if ((WithCrypto & APPLICATION_PGP))
153 mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
157 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
158 addstr (_("Sign, Encrypt"));
159 else if (msg->security & ENCRYPT)
160 addstr (_("Encrypt"));
161 else if (msg->security & SIGN)
167 move (HDR_CRYPTINFO, SidebarWidth);
169 if ((WithCrypto & APPLICATION_PGP)
170 && msg->security & APPLICATION_PGP && msg->security & SIGN)
171 printw ("%s%s", _(" sign as: "), PgpSignAs ? PgpSignAs : _("<default>"));
173 if ((WithCrypto & APPLICATION_SMIME)
174 && msg->security & APPLICATION_SMIME && msg->security & SIGN) {
175 printw ("%s%s", _(" sign as: "), SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
178 if ((WithCrypto & APPLICATION_SMIME)
179 && msg->security & APPLICATION_SMIME && (msg->security & ENCRYPT)) {
180 mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "),
181 NONULL(SmimeCryptAlg));
188 static int pgp_send_menu (HEADER *msg, int *redraw)
191 char input_signas[SHORT_STRING];
193 if (!(WithCrypto & APPLICATION_PGP))
194 return msg->security;
196 switch (mutt_multi_choice (_("PGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, or (f)orget it? "),
199 case 1: /* (e)ncrypt */
200 msg->security |= ENCRYPT;
204 msg->security |= SIGN;
207 case 3: /* sign (a)s */
208 unset_option(OPTPGPCHECKTRUST);
210 if ((p = crypt_pgp_ask_for_key (_("Sign as: "), NULL,
211 KEYFLAG_CANSIGN, PGP_PUBRING)))
213 snprintf (input_signas, sizeof (input_signas), "0x%s",
214 crypt_pgp_keyid (p));
215 mutt_str_replace (&PgpSignAs, input_signas);
216 crypt_pgp_free_key (&p);
218 msg->security |= SIGN;
220 crypt_pgp_void_passphrase (); /* probably need a different passphrase */
224 msg->security &= ~SIGN;
227 *redraw = REDRAW_FULL;
231 msg->security = ENCRYPT | SIGN;
234 case 5: /* (f)orget it */
239 if (msg->security && msg->security != APPLICATION_PGP)
240 msg->security |= APPLICATION_PGP;
245 redraw_crypt_lines (msg);
246 return (msg->security);
251 static int smime_send_menu (HEADER *msg, int *redraw)
255 if (!(WithCrypto & APPLICATION_SMIME))
256 return msg->security;
258 switch (mutt_multi_choice (_("S/MIME (e)ncrypt, (s)ign, encrypt (w)ith, sign (a)s, (b)oth, or (f)orget it? "),
261 case 1: /* (e)ncrypt */
262 msg->security |= ENCRYPT;
265 case 3: /* encrypt (w)ith */
266 msg->security |= ENCRYPT;
267 switch (mutt_multi_choice (_("1: DES, 2: Triple-DES, 3: RC2-40,"
268 " 4: RC2-64, 5: RC2-128, or (f)orget it? "),
271 mutt_str_replace (&SmimeCryptAlg, "des");
274 mutt_str_replace (&SmimeCryptAlg, "des3");
277 mutt_str_replace (&SmimeCryptAlg, "rc2-40");
280 mutt_str_replace (&SmimeCryptAlg, "rc2-64");
283 mutt_str_replace (&SmimeCryptAlg, "rc2-128");
285 case 6: /* forget it */
293 mutt_message("Can\'t sign: No key specified. use sign(as).");
295 msg->security |= SIGN;
298 case 4: /* sign (a)s */
300 if ((p = crypt_smime_ask_for_key (_("Sign as: "), NULL, 0))) {
301 p[mutt_strlen (p)-1] = '\0';
302 mutt_str_replace (&SmimeDefaultKey, p);
304 msg->security |= SIGN;
306 /* probably need a different passphrase */
307 crypt_smime_void_passphrase ();
310 msg->security &= ~SIGN;
312 *redraw = REDRAW_FULL;
316 msg->security = ENCRYPT | SIGN;
319 case 6: /* (f)orget it */
324 if (msg->security && msg->security != APPLICATION_SMIME)
325 msg->security |= APPLICATION_SMIME;
330 redraw_crypt_lines (msg);
331 return (msg->security);
337 static void redraw_mix_line (LIST *chain)
342 mvaddstr (HDR_MIX, SidebarWidth, " Mix: ");
346 addstr ("<no chain defined>");
351 for (c = 12; chain; chain = chain->next)
354 if (t && t[0] == '0' && t[1] == '\0')
357 if (c + mutt_strlen (t) + 2 >= COLS - SidebarWidth)
364 c += mutt_strlen (t) + 2;
367 #endif /* MIXMASTER */
370 check_attachments(ATTACHPTR **idx, short idxlen)
374 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
376 for (i = 0; i < idxlen; i++)
378 strfcpy(pretty, idx[i]->content->filename, sizeof(pretty));
379 if(stat(idx[i]->content->filename, &st) != 0)
381 mutt_pretty_mailbox(pretty);
382 mutt_error(_("%s [#%d] no longer exists!"),
387 if(idx[i]->content->stamp < st.st_mtime)
389 mutt_pretty_mailbox(pretty);
390 snprintf(msg, sizeof(msg), _("%s [#%d] modified. Update encoding?"),
393 if((r = mutt_yesorno(msg, M_YES)) == M_YES)
394 mutt_update_encoding(idx[i]->content);
403 static void draw_envelope_addr (int line, ADDRESS *addr)
408 rfc822_write_address (buf, sizeof (buf), addr, 1);
409 mvprintw (line, SidebarWidth, TITLE_FMT, Prompts[line - 1]);
410 mutt_paddstr (W, buf);
413 static void draw_envelope (HEADER *msg, char *fcc)
415 draw_envelope_addr (HDR_FROM, msg->env->from);
417 if (!option (OPTNEWSSEND))
420 draw_envelope_addr (HDR_TO, msg->env->to);
421 draw_envelope_addr (HDR_CC, msg->env->cc);
422 draw_envelope_addr (HDR_BCC, msg->env->bcc);
427 mvprintw (HDR_TO, 0, TITLE_FMT , Prompts[HDR_NEWSGROUPS - 1]);
428 mutt_paddstr (W, NONULL (msg->env->newsgroups));
429 mvprintw (HDR_CC, 0, TITLE_FMT , Prompts[HDR_FOLLOWUPTO - 1]);
430 mutt_paddstr (W, NONULL (msg->env->followup_to));
431 if (option (OPTXCOMMENTTO))
433 mvprintw (HDR_BCC, 0, TITLE_FMT , Prompts[HDR_XCOMMENTTO - 1]);
434 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
438 mvprintw (HDR_SUBJECT, SidebarWidth, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
439 mutt_paddstr (W, NONULL (msg->env->subject));
440 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
441 mvprintw (HDR_FCC, SidebarWidth, TITLE_FMT, Prompts[HDR_FCC - 1]);
442 mutt_paddstr (W, fcc);
445 redraw_crypt_lines (msg);
448 redraw_mix_line (msg->chain);
451 SETCOLOR (MT_COLOR_STATUS);
452 mvaddstr (HDR_ATTACH - 1, SidebarWidth, _("-- Attachments"));
453 BKGDSET (MT_COLOR_STATUS);
456 BKGDSET (MT_COLOR_NORMAL);
457 SETCOLOR (MT_COLOR_NORMAL);
460 static int edit_address_list (int line, ADDRESS **addr)
462 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
465 mutt_addrlist_to_local (*addr);
466 rfc822_write_address (buf, sizeof (buf), *addr, 0);
467 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0)
469 rfc822_free_address (addr);
470 *addr = mutt_parse_adrlist (*addr, buf);
471 *addr = mutt_expand_aliases (*addr);
474 if (option (OPTNEEDREDRAW))
476 unset_option (OPTNEEDREDRAW);
477 return (REDRAW_FULL);
480 if (mutt_addrlist_to_idna (*addr, &err) != 0)
482 mutt_error (_("Warning: '%s' is a bad IDN."), err);
487 /* redraw the expanded list so the user can see the result */
489 rfc822_write_address (buf, sizeof (buf), *addr, 1);
490 move (line, HDR_XOFFSET+SidebarWidth);
491 mutt_paddstr (W, buf);
496 static int delete_attachment (MUTTMENU *menu, short *idxlen, int x)
498 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
501 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
503 if (x == 0 && menu->max == 1)
505 mutt_error _("You may not delete the only attachment.");
506 idx[x]->content->tagged = 0;
510 for (y = 0; y < *idxlen; y++)
512 if (idx[y]->content->next == idx[x]->content)
514 idx[y]->content->next = idx[x]->content->next;
519 idx[x]->content->next = NULL;
520 idx[x]->content->parts = NULL;
521 mutt_free_body (&(idx[x]->content));
522 FREE (&idx[x]->tree);
524 for (; x < *idxlen - 1; x++)
526 menu->max = --(*idxlen);
531 static void update_idx (MUTTMENU *menu, ATTACHPTR **idx, short idxlen)
533 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen-1]->level : 0;
535 idx[idxlen - 1]->content->next = idx[idxlen]->content;
536 idx[idxlen]->content->aptr = idx[idxlen];
537 menu->current = idxlen++;
538 mutt_update_tree (idx, idxlen);
545 * cum_attachs_size: Cumulative Attachments Size
547 * Returns the total number of bytes used by the attachments in the
548 * attachment list _after_ content-transfer-encodings have been
553 static unsigned long cum_attachs_size (MUTTMENU *menu)
557 ATTACHPTR **idx = menu->data;
561 for (i = 0, s = 0; i < menu->max; i++)
566 b->content = mutt_get_content_info (b->filename, b);
568 if ((info = b->content))
572 case ENCQUOTEDPRINTABLE:
573 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
576 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
579 s += info->lobin + info->hibin + info->ascii + info->crlf;
588 /* prototype for use below */
589 void compose_status_line (char *buf, size_t buflen, MUTTMENU *menu,
593 * compose_format_str()
595 * %a = total number of attachments
596 * %h = hostname [option]
597 * %l = approx. length of current message (in bytes)
600 * This function is similar to status_format_str(). Look at that function for
601 * help when modifying this function.
605 compose_format_str (char *buf, size_t buflen, char op, const char *src,
606 const char *prefix, const char *ifstring,
607 const char *elsestring,
608 unsigned long data, format_flag flags)
610 char fmt[SHORT_STRING], tmp[SHORT_STRING];
611 int optional = (flags & M_FORMAT_OPTIONAL);
612 MUTTMENU *menu = (MUTTMENU *) data;
617 case 'a': /* total number of attachments */
618 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
619 snprintf (buf, buflen, fmt, menu->max);
622 case 'h': /* hostname */
623 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
624 snprintf (buf, buflen, fmt, NONULL(Hostname));
627 case 'l': /* approx length of current message in bytes */
628 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
629 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size(menu) : 0);
630 snprintf (buf, buflen, fmt, tmp);
634 snprintf (fmt, sizeof (fmt), "Mutt %%s");
635 snprintf (buf, buflen, fmt, MUTT_VERSION);
643 snprintf (buf, buflen, "%%%s%c", prefix, op);
648 compose_status_line (buf, buflen, menu, ifstring);
649 else if (flags & M_FORMAT_OPTIONAL)
650 compose_status_line (buf, buflen, menu, elsestring);
655 void compose_status_line (char *buf, size_t buflen, MUTTMENU *menu,
658 mutt_FormatString (buf, buflen, p, compose_format_str,
659 (unsigned long) menu, 0);
665 * 1 message should be postponed
669 int mutt_compose_menu (HEADER *msg, /* structure for new message */
670 char *fcc, /* where to save a copy of the message */
672 HEADER *cur) /* current message */
674 char helpstr[SHORT_STRING];
675 char buf[LONG_STRING];
676 char fname[_POSIX_PATH_MAX];
678 ATTACHPTR **idx = NULL;
682 int r = -1; /* return value */
685 int fccSet = 0; /* has the user edited the Fcc: field ? */
686 CONTEXT *ctx = NULL, *this = NULL;
687 /* Sort, SortAux could be changed in mutt_index_menu() */
688 int oldSort, oldSortAux;
691 int news = 0; /* is it a news article ? */
693 if (option (OPTNEWSSEND))
697 mutt_attach_init (msg->content);
698 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
700 menu = mutt_new_menu ();
701 menu->menu = MENU_COMPOSE;
702 menu->offset = HDR_ATTACH;
704 menu->make_entry = snd_entry;
705 menu->tag = mutt_tag_attach;
709 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeNewsHelp);
712 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeHelp);
717 unset_option (OPTNEWS); /* for any case */
719 switch (op = mutt_menuLoop (menu))
722 draw_envelope (msg, fcc);
723 menu->offset = HDR_ATTACH;
724 menu->pagelen = LINES - HDR_ATTACH - 2;
726 case OP_COMPOSE_EDIT_FROM:
727 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
729 case OP_COMPOSE_EDIT_TO:
733 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
735 case OP_COMPOSE_EDIT_BCC:
739 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
741 case OP_COMPOSE_EDIT_CC:
745 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
748 case OP_COMPOSE_EDIT_NEWSGROUPS:
751 if (msg->env->newsgroups)
752 strfcpy (buf, msg->env->newsgroups, sizeof (buf));
755 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0 && buf[0])
757 FREE (&msg->env->newsgroups);
758 mutt_remove_trailing_ws (buf);
759 msg->env->newsgroups = safe_strdup (mutt_skip_whitespace (buf));
760 move (HDR_TO, HDR_XOFFSET);
762 if (msg->env->newsgroups)
763 printw ("%-*.*s", W, W, msg->env->newsgroups);
768 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
772 if (msg->env->followup_to)
773 strfcpy (buf, msg->env->followup_to, sizeof (buf));
774 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0 && buf[0])
776 FREE (&msg->env->followup_to);
777 mutt_remove_trailing_ws (buf);
778 msg->env->followup_to = safe_strdup (mutt_skip_whitespace (buf));
779 move (HDR_CC, HDR_XOFFSET);
781 if (msg->env->followup_to)
782 printw ("%-*.*s", W, W, msg->env->followup_to);
787 case OP_COMPOSE_EDIT_X_COMMENT_TO:
788 if (news && option (OPTXCOMMENTTO))
791 if (msg->env->x_comment_to)
792 strfcpy (buf, msg->env->x_comment_to, sizeof (buf));
793 if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0 && buf[0])
795 FREE (&msg->env->x_comment_to);
796 msg->env->x_comment_to = safe_strdup (buf);
797 move (HDR_BCC, HDR_XOFFSET);
799 if (msg->env->x_comment_to)
800 printw ("%-*.*s", W, W, msg->env->x_comment_to);
805 case OP_COMPOSE_EDIT_SUBJECT:
806 if (msg->env->subject)
807 strfcpy (buf, msg->env->subject, sizeof (buf));
810 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
812 mutt_str_replace (&msg->env->subject, buf);
813 move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
815 if (msg->env->subject)
816 mutt_paddstr (W, msg->env->subject);
819 case OP_COMPOSE_EDIT_REPLY_TO:
820 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
822 case OP_COMPOSE_EDIT_FCC:
823 strfcpy (buf, fcc, sizeof (buf));
824 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0)
826 strfcpy (fcc, buf, _POSIX_PATH_MAX);
827 mutt_pretty_mailbox (fcc);
828 move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
829 mutt_paddstr (W, fcc);
832 MAYBE_REDRAW (menu->redraw);
834 case OP_COMPOSE_EDIT_MESSAGE:
835 if (Editor && (mutt_strcmp ("builtin", Editor) != 0) && !option (OPTEDITHDRS))
837 mutt_edit_file (Editor, msg->content->filename);
838 mutt_update_encoding (msg->content);
839 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
843 case OP_COMPOSE_EDIT_HEADERS:
844 if (op == OP_COMPOSE_EDIT_HEADERS ||
845 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))
847 char *tag = NULL, *err = NULL;
848 mutt_env_to_local (msg->env);
849 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
851 if (mutt_env_to_idna (msg->env, &tag, &err))
853 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
859 /* this is grouped with OP_COMPOSE_EDIT_HEADERS because the
860 attachment list could change if the user invokes ~v to edit
861 the message with headers, in which we need to execute the
862 code below to regenerate the index array */
863 mutt_builtin_editor (msg->content->filename, msg, cur);
865 mutt_update_encoding (msg->content);
867 /* attachments may have been added */
868 if (idxlen && idx[idxlen - 1]->content->next)
870 for (i = 0; i < idxlen; i++)
873 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
878 menu->redraw = REDRAW_FULL;
883 case OP_COMPOSE_ATTACH_KEY:
884 if (!(WithCrypto & APPLICATION_PGP))
886 if (idxlen == idxmax)
888 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
892 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
893 if ((idx[idxlen]->content = crypt_pgp_make_key_attachment(NULL)) != NULL)
895 update_idx (menu, idx, idxlen++);
896 menu->redraw |= REDRAW_INDEX;
901 menu->redraw |= REDRAW_STATUS;
903 if (option(OPTNEEDREDRAW))
905 menu->redraw = REDRAW_FULL;
906 unset_option(OPTNEEDREDRAW);
912 case OP_COMPOSE_ATTACH_FILE:
914 char *prompt, **files;
918 prompt = _("Attach file");
922 if (_mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files, &numfiles) == -1 ||
926 if (idxlen + numfiles >= idxmax)
928 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles));
934 mutt_message _("Attaching selected files...");
935 for (i = 0; i < numfiles; i++)
937 char *att = files[i];
938 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
939 idx[idxlen]->content = mutt_make_file_attach (att);
940 if (idx[idxlen]->content != NULL)
941 update_idx (menu, idx, idxlen++);
945 mutt_error (_("Unable to attach %s!"), att);
951 if (!error) mutt_clear_error ();
953 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
957 case OP_COMPOSE_ATTACH_MESSAGE:
959 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
966 prompt = _("Open mailbox to attach message from");
969 unset_option (OPTNEWS);
970 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE)
972 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
975 prompt = _("Open newsgroup to attach message from");
976 set_option (OPTNEWS);
982 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
985 strfcpy (fname, NONULL (Context->path), sizeof (fname));
986 mutt_pretty_mailbox (fname);
989 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1) == -1 || !fname[0])
993 if (option (OPTNEWS))
994 nntp_expand_path (fname, sizeof (fname), &CurrentNewsSrv->conn->account);
997 mutt_expand_path (fname, sizeof (fname));
999 if (!mx_is_imap (fname))
1002 if (!mx_is_pop (fname))
1005 if (!mx_is_nntp (fname) && !option (OPTNEWS))
1007 /* check to make sure the file exists and is readable */
1008 if (access (fname, R_OK) == -1)
1010 mutt_perror (fname);
1014 menu->redraw = REDRAW_FULL;
1016 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
1019 mutt_perror (fname);
1025 mx_close_mailbox (ctx, NULL);
1027 mutt_error _("No messages in that folder.");
1031 this = Context; /* remember current folder and sort methods*/
1032 oldSort = Sort; oldSortAux = SortAux;
1035 set_option(OPTATTACHMSG);
1036 mutt_message _("Tag the messages you want to attach!");
1037 close = mutt_index_menu ();
1038 unset_option(OPTATTACHMSG);
1042 /* go back to the folder we started from */
1044 /* Restore old $sort and $sort_aux */
1046 SortAux = oldSortAux;
1047 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1051 if (idxlen + Context->tagged >= idxmax)
1053 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + Context->tagged));
1057 for (i = 0; i < Context->msgcount; i++)
1059 h = Context->hdrs[i];
1062 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
1063 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
1064 if (idx[idxlen]->content != NULL)
1065 update_idx (menu, idx, idxlen++);
1068 mutt_error _("Unable to attach!");
1069 FREE (&idx[idxlen]);
1073 menu->redraw |= REDRAW_FULL;
1075 if (close == OP_QUIT)
1076 mx_close_mailbox (Context, NULL);
1078 mx_fastclose_mailbox (Context);
1081 /* go back to the folder we started from */
1083 /* Restore old $sort and $sort_aux */
1085 SortAux = oldSortAux;
1091 if (delete_attachment (menu, &idxlen, menu->current) == -1)
1093 mutt_update_tree (idx, idxlen);
1096 if (menu->current > idxlen - 1)
1097 menu->current = idxlen - 1;
1102 if (menu->current == 0)
1103 msg->content = idx[0]->content;
1105 menu->redraw |= REDRAW_STATUS;
1108 #define CURRENT idx[menu->current]->content
1110 case OP_COMPOSE_TOGGLE_RECODE:
1113 if (!mutt_is_text_part (CURRENT))
1115 mutt_error (_("Recoding only affects text attachments."));
1118 CURRENT->noconv = !CURRENT->noconv;
1119 if (CURRENT->noconv)
1120 mutt_message (_("The current attachment won't be converted."));
1122 mutt_message (_("The current attachment will be converted."));
1123 menu->redraw = REDRAW_CURRENT;
1128 case OP_COMPOSE_EDIT_DESCRIPTION:
1131 idx[menu->current]->content->description ?
1132 idx[menu->current]->content->description : "",
1134 /* header names should not be translated */
1135 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0)
1137 mutt_str_replace (&idx[menu->current]->content->description, buf);
1138 menu->redraw = REDRAW_CURRENT;
1142 case OP_COMPOSE_UPDATE_ENCODING:
1144 if (menu->tagprefix)
1147 for (top = msg->content; top; top = top->next)
1150 mutt_update_encoding (top);
1152 menu->redraw = REDRAW_FULL;
1156 mutt_update_encoding(idx[menu->current]->content);
1157 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1161 case OP_COMPOSE_TOGGLE_DISPOSITION:
1162 /* toggle the content-disposition between inline/attachment */
1163 idx[menu->current]->content->disposition = (idx[menu->current]->content->disposition == DISPINLINE) ? DISPATTACH : DISPINLINE;
1164 menu->redraw = REDRAW_CURRENT;
1170 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
1172 /* this may have been a change to text/something */
1173 mutt_update_encoding (idx[menu->current]->content);
1175 menu->redraw = REDRAW_CURRENT;
1179 case OP_COMPOSE_EDIT_ENCODING:
1181 strfcpy (buf, ENCODING (idx[menu->current]->content->encoding),
1183 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
1184 sizeof (buf), 0) == 0 && buf[0])
1186 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED)
1188 idx[menu->current]->content->encoding = i;
1189 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1193 mutt_error _("Invalid encoding.");
1197 case OP_COMPOSE_SEND_MESSAGE:
1199 if(check_attachments(idx, idxlen) != 0)
1201 menu->redraw = REDRAW_FULL;
1207 if (msg->chain && mix_check_message (msg) != 0)
1211 if (!fccSet && *fcc)
1213 if ((i = query_quadoption (OPT_COPY,
1214 _("Save a copy of this message?"))) == -1)
1224 case OP_COMPOSE_EDIT_FILE:
1226 mutt_edit_file (NONULL(Editor), idx[menu->current]->content->filename);
1227 mutt_update_encoding (idx[menu->current]->content);
1228 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1231 case OP_COMPOSE_TOGGLE_UNLINK:
1233 idx[menu->current]->content->unlink = !idx[menu->current]->content->unlink;
1236 /* OPTRESOLVE is otherwise ignored on this menu.
1240 if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
1243 menu->redraw = REDRAW_INDEX;
1246 case OP_COMPOSE_GET_ATTACHMENT:
1251 for(top = msg->content; top; top = top->next)
1254 mutt_get_tmp_attachment(top);
1256 menu->redraw = REDRAW_FULL;
1258 else if (mutt_get_tmp_attachment(idx[menu->current]->content) == 0)
1259 menu->redraw = REDRAW_CURRENT;
1263 case OP_COMPOSE_RENAME_FILE:
1265 strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname));
1266 mutt_pretty_mailbox (fname);
1267 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1270 if (stat(idx[menu->current]->content->filename, &st) == -1)
1272 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1276 mutt_expand_path (fname, sizeof (fname));
1277 if(mutt_rename_file (idx[menu->current]->content->filename, fname))
1280 mutt_str_replace (&idx[menu->current]->content->filename, fname);
1281 menu->redraw = REDRAW_CURRENT;
1283 if(idx[menu->current]->content->stamp >= st.st_mtime)
1284 mutt_stamp_attachment(idx[menu->current]->content);
1289 case OP_COMPOSE_NEW_MIME:
1296 CLEARLINE (LINES-1);
1298 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1301 mutt_expand_path (fname, sizeof (fname));
1303 /* Call to lookup_mime_type () ? maybe later */
1305 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1309 if (!(p = strchr (type, '/')))
1311 mutt_error _("Content-Type is of the form base/sub");
1315 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER)
1317 mutt_error (_("Unknown Content-Type %s"), type);
1320 if (idxlen == idxmax)
1322 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
1326 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
1327 /* Touch the file */
1328 if (!(fp = safe_fopen (fname, "w")))
1330 mutt_error (_("Can't create file %s"), fname);
1331 FREE (&idx[idxlen]);
1336 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL)
1338 mutt_error _("What we have here is a failure to make an attachment");
1341 update_idx (menu, idx, idxlen++);
1343 idx[menu->current]->content->type = itype;
1344 mutt_str_replace (&idx[menu->current]->content->subtype, p);
1345 idx[menu->current]->content->unlink = 1;
1346 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1348 if (mutt_compose_attachment (idx[menu->current]->content))
1350 mutt_update_encoding (idx[menu->current]->content);
1351 menu->redraw = REDRAW_FULL;
1356 case OP_COMPOSE_EDIT_MIME:
1358 if (mutt_edit_attachment (idx[menu->current]->content))
1360 mutt_update_encoding (idx[menu->current]->content);
1361 menu->redraw = REDRAW_FULL;
1365 case OP_VIEW_ATTACH:
1366 case OP_DISPLAY_HEADERS:
1368 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen, NULL, 0);
1369 menu->redraw = REDRAW_FULL;
1374 mutt_save_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, NULL, menu);
1375 MAYBE_REDRAW (menu->redraw);
1380 mutt_print_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content);
1386 mutt_pipe_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, op == OP_FILTER);
1387 if (op == OP_FILTER) /* cte might have changed */
1388 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1389 menu->redraw |= REDRAW_STATUS;
1393 if ((i = query_quadoption (OPT_POSTPONE, _("Postpone this message?"))) == M_NO)
1395 while (idxlen-- > 0)
1397 /* avoid freeing other attachments */
1398 idx[idxlen]->content->next = NULL;
1399 idx[idxlen]->content->parts = NULL;
1400 mutt_free_body (&idx[idxlen]->content);
1401 FREE (&idx[idxlen]->tree);
1402 FREE (&idx[idxlen]);
1414 /* fall through to postpone! */
1416 case OP_COMPOSE_POSTPONE_MESSAGE:
1418 if(check_attachments(idx, idxlen) != 0)
1420 menu->redraw = REDRAW_FULL;
1428 case OP_COMPOSE_ISPELL:
1430 snprintf (buf, sizeof (buf), "%s -x %s", NONULL(Ispell), msg->content->filename);
1431 if (mutt_system (buf) == -1)
1432 mutt_error (_("Error running \"%s\"!"), buf);
1435 mutt_update_encoding (msg->content);
1436 menu->redraw |= REDRAW_STATUS;
1440 case OP_COMPOSE_WRITE_MESSAGE:
1445 strfcpy (fname, NONULL (Context->path), sizeof (fname));
1446 mutt_pretty_mailbox (fname);
1449 msg->content = idx[0]->content;
1450 if (mutt_enter_fname (_("Write message to mailbox"), fname, sizeof (fname),
1451 &menu->redraw, 1) != -1 && fname[0])
1453 mutt_message (_("Writing message to %s ..."), fname);
1454 mutt_expand_path (fname, sizeof (fname));
1456 if (msg->content->next)
1457 msg->content = mutt_make_multipart (msg->content);
1459 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1460 msg->content = mutt_remove_multipart (msg->content);
1462 mutt_message _("Message written.");
1468 case OP_COMPOSE_PGP_MENU:
1469 if (!(WithCrypto & APPLICATION_PGP))
1471 if ((WithCrypto & APPLICATION_SMIME)
1472 && msg->security & APPLICATION_SMIME)
1474 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1477 mutt_clear_error ();
1482 msg->security = pgp_send_menu (msg, &menu->redraw);
1483 redraw_crypt_lines (msg);
1487 case OP_FORGET_PASSPHRASE:
1488 crypt_forget_passphrase ();
1492 case OP_COMPOSE_SMIME_MENU:
1493 if (!(WithCrypto & APPLICATION_SMIME))
1496 if ((WithCrypto & APPLICATION_PGP)
1497 && msg->security & APPLICATION_PGP)
1499 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1502 mutt_clear_error ();
1507 msg->security = smime_send_menu(msg, &menu->redraw);
1508 redraw_crypt_lines (msg);
1513 case OP_COMPOSE_MIX:
1515 mix_make_chain (&msg->chain, &menu->redraw);
1521 /* Draw formated compose status line */
1522 if (menu->redraw & REDRAW_STATUS)
1524 compose_status_line (buf, sizeof (buf), menu, NONULL(ComposeFormat));
1525 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
1526 SETCOLOR (MT_COLOR_STATUS);
1527 printw ("%-*.*s", COLS, COLS, buf);
1528 SETCOLOR (MT_COLOR_NORMAL);
1529 menu->redraw &= ~REDRAW_STATUS;
1533 mutt_menuDestroy (&menu);
1537 msg->content = idx[0]->content;
1538 for (i = 0; i < idxlen; i++)
1540 idx[i]->content->aptr = NULL;
1545 msg->content = NULL;