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; }
74 HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
77 #define HDR_XOFFSET 14
78 #define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
79 #define W (COLS - HDR_XOFFSET - SidebarWidth)
81 static char *Prompts[] =
102 static struct mapping_t ComposeHelp[] = {
103 { N_("Send"), OP_COMPOSE_SEND_MESSAGE },
104 { N_("Abort"), OP_EXIT },
105 { "To", OP_COMPOSE_EDIT_TO },
106 { "CC", OP_COMPOSE_EDIT_CC },
107 { "Subj", OP_COMPOSE_EDIT_SUBJECT },
108 { N_("Attach file"), OP_COMPOSE_ATTACH_FILE },
109 { N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION },
110 { N_("Help"), OP_HELP },
115 static struct mapping_t ComposeNewsHelp[] = {
116 { N_("Send"), OP_COMPOSE_SEND_MESSAGE },
117 { N_("Abort"), OP_EXIT },
118 { "Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS },
119 { "Subj", OP_COMPOSE_EDIT_SUBJECT },
120 { N_("Attach file"), OP_COMPOSE_ATTACH_FILE },
121 { N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION },
122 { N_("Help"), OP_HELP },
127 static void snd_entry (char *b, size_t blen, MUTTMENU *menu, int num)
129 mutt_FormatString (b, blen, NONULL (AttachFormat), mutt_attach_fmt,
130 (unsigned long)(((ATTACHPTR **) menu->data)[num]),
131 M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR);
136 #include "mutt_crypt.h"
138 static void redraw_crypt_lines (HEADER *msg)
142 if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME))
145 mvaddstr (HDR_CRYPT, SidebarWidth, " Security: ");
146 else if (msg->security & APPLICATION_SMIME)
147 mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
148 else if (msg->security & APPLICATION_PGP)
149 mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
151 else if ((WithCrypto & APPLICATION_SMIME))
152 mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
153 else if ((WithCrypto & APPLICATION_PGP))
154 mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
158 if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
159 addstr (_("Sign, Encrypt"));
160 else if (msg->security & ENCRYPT)
161 addstr (_("Encrypt"));
162 else if (msg->security & SIGN)
167 if ((WithCrypto & APPLICATION_PGP))
168 if ((msg->security & APPLICATION_PGP)
169 && (msg->security & (ENCRYPT | SIGN)))
171 if ((msg->security & INLINE))
172 addstr (_(" (inline)"));
174 addstr (_(" (PGP/MIME)"));
178 move (HDR_CRYPTINFO, SidebarWidth);
180 if ((WithCrypto & APPLICATION_PGP)
181 && msg->security & APPLICATION_PGP && msg->security & SIGN)
182 printw ("%s%s", _(" sign as: "), PgpSignAs ? PgpSignAs : _("<default>"));
184 if ((WithCrypto & APPLICATION_SMIME)
185 && msg->security & APPLICATION_SMIME && msg->security & SIGN) {
186 printw ("%s%s", _(" sign as: "), SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
189 if ((WithCrypto & APPLICATION_SMIME)
190 && (msg->security & APPLICATION_SMIME)
191 && (msg->security & ENCRYPT)
194 mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "),
195 NONULL(SmimeCryptAlg));
203 static void redraw_mix_line (LIST *chain)
208 mvaddstr (HDR_MIX, SidebarWidth, " Mix: ");
212 addstr ("<no chain defined>");
217 for (c = 12; chain; chain = chain->next)
220 if (t && t[0] == '0' && t[1] == '\0')
223 if (c + mutt_strlen (t) + 2 >= COLS - SidebarWidth)
230 c += mutt_strlen (t) + 2;
233 #endif /* MIXMASTER */
236 check_attachments(ATTACHPTR **idx, short idxlen)
240 char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING];
242 for (i = 0; i < idxlen; i++)
244 strfcpy(pretty, idx[i]->content->filename, sizeof(pretty));
245 if(stat(idx[i]->content->filename, &st) != 0)
247 mutt_pretty_mailbox(pretty);
248 mutt_error(_("%s [#%d] no longer exists!"),
253 if(idx[i]->content->stamp < st.st_mtime)
255 mutt_pretty_mailbox(pretty);
256 snprintf(msg, sizeof(msg), _("%s [#%d] modified. Update encoding?"),
259 if((r = mutt_yesorno(msg, M_YES)) == M_YES)
260 mutt_update_encoding(idx[i]->content);
269 static void draw_envelope_addr (int line, ADDRESS *addr)
274 rfc822_write_address (buf, sizeof (buf), addr, 1);
275 mvprintw (line, SidebarWidth, TITLE_FMT, Prompts[line - 1]);
276 mutt_paddstr (W, buf);
279 static void draw_envelope (HEADER *msg, char *fcc)
281 draw_envelope_addr (HDR_FROM, msg->env->from);
283 if (!option (OPTNEWSSEND))
286 draw_envelope_addr (HDR_TO, msg->env->to);
287 draw_envelope_addr (HDR_CC, msg->env->cc);
288 draw_envelope_addr (HDR_BCC, msg->env->bcc);
293 mvprintw (HDR_TO, 0, TITLE_FMT , Prompts[HDR_NEWSGROUPS - 1]);
294 mutt_paddstr (W, NONULL (msg->env->newsgroups));
295 mvprintw (HDR_CC, 0, TITLE_FMT , Prompts[HDR_FOLLOWUPTO - 1]);
296 mutt_paddstr (W, NONULL (msg->env->followup_to));
297 if (option (OPTXCOMMENTTO))
299 mvprintw (HDR_BCC, 0, TITLE_FMT , Prompts[HDR_XCOMMENTTO - 1]);
300 mutt_paddstr (W, NONULL (msg->env->x_comment_to));
304 mvprintw (HDR_SUBJECT, SidebarWidth, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
305 mutt_paddstr (W, NONULL (msg->env->subject));
306 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
307 mvprintw (HDR_FCC, SidebarWidth, TITLE_FMT, Prompts[HDR_FCC - 1]);
308 mutt_paddstr (W, fcc);
311 redraw_crypt_lines (msg);
314 redraw_mix_line (msg->chain);
317 SETCOLOR (MT_COLOR_STATUS);
318 mvaddstr (HDR_ATTACH - 1, SidebarWidth, _("-- Attachments"));
319 BKGDSET (MT_COLOR_STATUS);
322 BKGDSET (MT_COLOR_NORMAL);
323 SETCOLOR (MT_COLOR_NORMAL);
326 static int edit_address_list (int line, ADDRESS **addr)
328 char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
331 mutt_addrlist_to_local (*addr);
332 rfc822_write_address (buf, sizeof (buf), *addr, 0);
333 if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0)
335 rfc822_free_address (addr);
336 *addr = mutt_parse_adrlist (*addr, buf);
337 *addr = mutt_expand_aliases (*addr);
340 if (option (OPTNEEDREDRAW))
342 unset_option (OPTNEEDREDRAW);
343 return (REDRAW_FULL);
346 if (mutt_addrlist_to_idna (*addr, &err) != 0)
348 mutt_error (_("Warning: '%s' is a bad IDN."), err);
353 /* redraw the expanded list so the user can see the result */
355 rfc822_write_address (buf, sizeof (buf), *addr, 1);
356 move (line, HDR_XOFFSET+SidebarWidth);
357 mutt_paddstr (W, buf);
362 static int delete_attachment (MUTTMENU *menu, short *idxlen, int x)
364 ATTACHPTR **idx = (ATTACHPTR **) menu->data;
367 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
369 if (x == 0 && menu->max == 1)
371 mutt_error _("You may not delete the only attachment.");
372 idx[x]->content->tagged = 0;
376 for (y = 0; y < *idxlen; y++)
378 if (idx[y]->content->next == idx[x]->content)
380 idx[y]->content->next = idx[x]->content->next;
385 idx[x]->content->next = NULL;
386 idx[x]->content->parts = NULL;
387 mutt_free_body (&(idx[x]->content));
388 FREE (&idx[x]->tree);
390 for (; x < *idxlen - 1; x++)
392 menu->max = --(*idxlen);
397 static void update_idx (MUTTMENU *menu, ATTACHPTR **idx, short idxlen)
399 idx[idxlen]->level = (idxlen > 0) ? idx[idxlen-1]->level : 0;
401 idx[idxlen - 1]->content->next = idx[idxlen]->content;
402 idx[idxlen]->content->aptr = idx[idxlen];
403 menu->current = idxlen++;
404 mutt_update_tree (idx, idxlen);
411 * cum_attachs_size: Cumulative Attachments Size
413 * Returns the total number of bytes used by the attachments in the
414 * attachment list _after_ content-transfer-encodings have been
419 static unsigned long cum_attachs_size (MUTTMENU *menu)
423 ATTACHPTR **idx = menu->data;
427 for (i = 0, s = 0; i < menu->max; i++)
432 b->content = mutt_get_content_info (b->filename, b);
434 if ((info = b->content))
438 case ENCQUOTEDPRINTABLE:
439 s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf;
442 s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3;
445 s += info->lobin + info->hibin + info->ascii + info->crlf;
454 /* prototype for use below */
455 static void compose_status_line (char *buf, size_t buflen, MUTTMENU *menu,
459 * compose_format_str()
461 * %a = total number of attachments
462 * %h = hostname [option]
463 * %l = approx. length of current message (in bytes)
466 * This function is similar to status_format_str(). Look at that function for
467 * help when modifying this function.
471 compose_format_str (char *buf, size_t buflen, char op, const char *src,
472 const char *prefix, const char *ifstring,
473 const char *elsestring,
474 unsigned long data, format_flag flags)
476 char fmt[SHORT_STRING], tmp[SHORT_STRING];
477 int optional = (flags & M_FORMAT_OPTIONAL);
478 MUTTMENU *menu = (MUTTMENU *) data;
483 case 'a': /* total number of attachments */
484 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
485 snprintf (buf, buflen, fmt, menu->max);
488 case 'h': /* hostname */
489 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
490 snprintf (buf, buflen, fmt, NONULL(Hostname));
493 case 'l': /* approx length of current message in bytes */
494 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
495 mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size(menu) : 0);
496 snprintf (buf, buflen, fmt, tmp);
500 snprintf (fmt, sizeof (fmt), "Mutt %%s");
501 snprintf (buf, buflen, fmt, MUTT_VERSION);
509 snprintf (buf, buflen, "%%%s%c", prefix, op);
514 compose_status_line (buf, buflen, menu, ifstring);
515 else if (flags & M_FORMAT_OPTIONAL)
516 compose_status_line (buf, buflen, menu, elsestring);
521 static void compose_status_line (char *buf, size_t buflen, MUTTMENU *menu,
524 mutt_FormatString (buf, buflen, p, compose_format_str,
525 (unsigned long) menu, 0);
531 * 1 message should be postponed
535 int mutt_compose_menu (HEADER *msg, /* structure for new message */
536 char *fcc, /* where to save a copy of the message */
538 HEADER *cur) /* current message */
540 char helpstr[SHORT_STRING];
541 char buf[LONG_STRING];
542 char fname[_POSIX_PATH_MAX];
544 ATTACHPTR **idx = NULL;
548 int r = -1; /* return value */
551 int fccSet = 0; /* has the user edited the Fcc: field ? */
552 CONTEXT *ctx = NULL, *this = NULL;
553 /* Sort, SortAux could be changed in mutt_index_menu() */
554 int oldSort, oldSortAux;
557 int news = 0; /* is it a news article ? */
559 if (option (OPTNEWSSEND))
563 mutt_attach_init (msg->content);
564 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
566 menu = mutt_new_menu ();
567 menu->menu = MENU_COMPOSE;
568 menu->offset = HDR_ATTACH;
570 menu->make_entry = snd_entry;
571 menu->tag = mutt_tag_attach;
575 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeNewsHelp);
578 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeHelp);
583 unset_option (OPTNEWS); /* for any case */
585 switch (op = mutt_menuLoop (menu))
588 draw_envelope (msg, fcc);
589 menu->offset = HDR_ATTACH;
590 menu->pagelen = LINES - HDR_ATTACH - 2;
592 case OP_COMPOSE_EDIT_FROM:
593 menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
594 mutt_message_hook (NULL, msg, M_SEND2HOOK);
596 case OP_COMPOSE_EDIT_TO:
600 menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
601 mutt_message_hook (NULL, msg, M_SEND2HOOK);
606 case OP_COMPOSE_EDIT_BCC:
610 menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
611 mutt_message_hook (NULL, msg, M_SEND2HOOK);
616 case OP_COMPOSE_EDIT_CC:
620 menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
621 mutt_message_hook (NULL, msg, M_SEND2HOOK);
627 case OP_COMPOSE_EDIT_NEWSGROUPS:
630 if (msg->env->newsgroups)
631 strfcpy (buf, msg->env->newsgroups, sizeof (buf));
634 if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0 && buf[0])
636 FREE (&msg->env->newsgroups);
637 mutt_remove_trailing_ws (buf);
638 msg->env->newsgroups = safe_strdup (mutt_skip_whitespace (buf));
639 move (HDR_TO, HDR_XOFFSET);
641 if (msg->env->newsgroups)
642 printw ("%-*.*s", W, W, msg->env->newsgroups);
647 case OP_COMPOSE_EDIT_FOLLOWUP_TO:
651 if (msg->env->followup_to)
652 strfcpy (buf, msg->env->followup_to, sizeof (buf));
653 if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0 && buf[0])
655 FREE (&msg->env->followup_to);
656 mutt_remove_trailing_ws (buf);
657 msg->env->followup_to = safe_strdup (mutt_skip_whitespace (buf));
658 move (HDR_CC, HDR_XOFFSET);
660 if (msg->env->followup_to)
661 printw ("%-*.*s", W, W, msg->env->followup_to);
666 case OP_COMPOSE_EDIT_X_COMMENT_TO:
667 if (news && option (OPTXCOMMENTTO))
670 if (msg->env->x_comment_to)
671 strfcpy (buf, msg->env->x_comment_to, sizeof (buf));
672 if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0 && buf[0])
674 FREE (&msg->env->x_comment_to);
675 msg->env->x_comment_to = safe_strdup (buf);
676 move (HDR_BCC, HDR_XOFFSET);
678 if (msg->env->x_comment_to)
679 printw ("%-*.*s", W, W, msg->env->x_comment_to);
684 case OP_COMPOSE_EDIT_SUBJECT:
685 if (msg->env->subject)
686 strfcpy (buf, msg->env->subject, sizeof (buf));
689 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
691 mutt_str_replace (&msg->env->subject, buf);
692 move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
694 if (msg->env->subject)
695 mutt_paddstr (W, msg->env->subject);
697 mutt_message_hook (NULL, msg, M_SEND2HOOK);
699 case OP_COMPOSE_EDIT_REPLY_TO:
700 menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
701 mutt_message_hook (NULL, msg, M_SEND2HOOK);
703 case OP_COMPOSE_EDIT_FCC:
704 strfcpy (buf, fcc, sizeof (buf));
705 if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0)
707 strfcpy (fcc, buf, _POSIX_PATH_MAX);
708 mutt_pretty_mailbox (fcc);
709 move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
710 mutt_paddstr (W, fcc);
713 MAYBE_REDRAW (menu->redraw);
714 mutt_message_hook (NULL, msg, M_SEND2HOOK);
716 case OP_COMPOSE_EDIT_MESSAGE:
717 if (Editor && (mutt_strcmp ("builtin", Editor) != 0) && !option (OPTEDITHDRS))
719 mutt_edit_file (Editor, msg->content->filename);
720 mutt_update_encoding (msg->content);
721 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
722 mutt_message_hook (NULL, msg, M_SEND2HOOK);
726 case OP_COMPOSE_EDIT_HEADERS:
727 if (mutt_strcmp ("builtin", Editor) != 0 &&
728 (op == OP_COMPOSE_EDIT_HEADERS ||
729 (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS))))
731 char *tag = NULL, *err = NULL;
732 mutt_env_to_local (msg->env);
733 mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
735 if (mutt_env_to_idna (msg->env, &tag, &err))
737 mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
743 /* this is grouped with OP_COMPOSE_EDIT_HEADERS because the
744 attachment list could change if the user invokes ~v to edit
745 the message with headers, in which we need to execute the
746 code below to regenerate the index array */
747 mutt_builtin_editor (msg->content->filename, msg, cur);
749 mutt_update_encoding (msg->content);
751 /* attachments may have been added */
752 if (idxlen && idx[idxlen - 1]->content->next)
754 for (i = 0; i < idxlen; i++)
757 idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
762 menu->redraw = REDRAW_FULL;
763 mutt_message_hook (NULL, msg, M_SEND2HOOK);
768 case OP_COMPOSE_ATTACH_KEY:
769 if (!(WithCrypto & APPLICATION_PGP))
771 if (idxlen == idxmax)
773 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
777 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
778 if ((idx[idxlen]->content = crypt_pgp_make_key_attachment(NULL)) != NULL)
780 update_idx (menu, idx, idxlen++);
781 menu->redraw |= REDRAW_INDEX;
786 menu->redraw |= REDRAW_STATUS;
788 if (option(OPTNEEDREDRAW))
790 menu->redraw = REDRAW_FULL;
791 unset_option(OPTNEEDREDRAW);
794 mutt_message_hook (NULL, msg, M_SEND2HOOK);
798 case OP_COMPOSE_ATTACH_FILE:
800 char *prompt, **files;
804 prompt = _("Attach file");
808 if (_mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files, &numfiles) == -1 ||
812 if (idxlen + numfiles >= idxmax)
814 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles));
820 mutt_message _("Attaching selected files...");
821 for (i = 0; i < numfiles; i++)
823 char *att = files[i];
824 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
825 idx[idxlen]->content = mutt_make_file_attach (att);
826 if (idx[idxlen]->content != NULL)
827 update_idx (menu, idx, idxlen++);
831 mutt_error (_("Unable to attach %s!"), att);
837 if (!error) mutt_clear_error ();
839 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
841 mutt_message_hook (NULL, msg, M_SEND2HOOK);
844 case OP_COMPOSE_ATTACH_MESSAGE:
846 case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
853 prompt = _("Open mailbox to attach message from");
856 unset_option (OPTNEWS);
857 if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE)
859 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
862 prompt = _("Open newsgroup to attach message from");
863 set_option (OPTNEWS);
869 if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
872 strfcpy (fname, NONULL (Context->path), sizeof (fname));
873 mutt_pretty_mailbox (fname);
876 if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1) == -1 || !fname[0])
880 if (option (OPTNEWS))
881 nntp_expand_path (fname, sizeof (fname), &CurrentNewsSrv->conn->account);
884 mutt_expand_path (fname, sizeof (fname));
886 if (!mx_is_imap (fname))
889 if (!mx_is_pop (fname))
892 if (!mx_is_nntp (fname) && !option (OPTNEWS))
894 /* check to make sure the file exists and is readable */
895 if (access (fname, R_OK) == -1)
901 menu->redraw = REDRAW_FULL;
903 ctx = mx_open_mailbox (fname, M_READONLY, NULL);
912 mx_close_mailbox (ctx, NULL);
914 mutt_error _("No messages in that folder.");
918 this = Context; /* remember current folder and sort methods*/
919 oldSort = Sort; oldSortAux = SortAux;
922 set_option(OPTATTACHMSG);
923 mutt_message _("Tag the messages you want to attach!");
924 close = mutt_index_menu ();
925 unset_option(OPTATTACHMSG);
929 /* go back to the folder we started from */
931 /* Restore old $sort and $sort_aux */
933 SortAux = oldSortAux;
934 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
938 if (idxlen + Context->tagged >= idxmax)
940 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + Context->tagged));
944 for (i = 0; i < Context->msgcount; i++)
946 h = Context->hdrs[i];
949 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
950 idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
951 if (idx[idxlen]->content != NULL)
952 update_idx (menu, idx, idxlen++);
955 mutt_error _("Unable to attach!");
960 menu->redraw |= REDRAW_FULL;
962 if (close == OP_QUIT)
963 mx_close_mailbox (Context, NULL);
965 mx_fastclose_mailbox (Context);
968 /* go back to the folder we started from */
970 /* Restore old $sort and $sort_aux */
972 SortAux = oldSortAux;
974 mutt_message_hook (NULL, msg, M_SEND2HOOK);
979 if (delete_attachment (menu, &idxlen, menu->current) == -1)
981 mutt_update_tree (idx, idxlen);
984 if (menu->current > idxlen - 1)
985 menu->current = idxlen - 1;
990 if (menu->current == 0)
991 msg->content = idx[0]->content;
993 menu->redraw |= REDRAW_STATUS;
994 mutt_message_hook (NULL, msg, M_SEND2HOOK);
997 #define CURRENT idx[menu->current]->content
999 case OP_COMPOSE_TOGGLE_RECODE:
1002 if (!mutt_is_text_part (CURRENT))
1004 mutt_error (_("Recoding only affects text attachments."));
1007 CURRENT->noconv = !CURRENT->noconv;
1008 if (CURRENT->noconv)
1009 mutt_message (_("The current attachment won't be converted."));
1011 mutt_message (_("The current attachment will be converted."));
1012 menu->redraw = REDRAW_CURRENT;
1013 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1018 case OP_COMPOSE_EDIT_DESCRIPTION:
1021 idx[menu->current]->content->description ?
1022 idx[menu->current]->content->description : "",
1024 /* header names should not be translated */
1025 if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0)
1027 mutt_str_replace (&idx[menu->current]->content->description, buf);
1028 menu->redraw = REDRAW_CURRENT;
1030 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1033 case OP_COMPOSE_UPDATE_ENCODING:
1035 if (menu->tagprefix)
1038 for (top = msg->content; top; top = top->next)
1041 mutt_update_encoding (top);
1043 menu->redraw = REDRAW_FULL;
1047 mutt_update_encoding(idx[menu->current]->content);
1048 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1050 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1053 case OP_COMPOSE_TOGGLE_DISPOSITION:
1054 /* toggle the content-disposition between inline/attachment */
1055 idx[menu->current]->content->disposition = (idx[menu->current]->content->disposition == DISPINLINE) ? DISPATTACH : DISPINLINE;
1056 menu->redraw = REDRAW_CURRENT;
1062 mutt_edit_content_type (NULL, idx[menu->current]->content, NULL);
1064 /* this may have been a change to text/something */
1065 mutt_update_encoding (idx[menu->current]->content);
1067 menu->redraw = REDRAW_CURRENT;
1069 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1072 case OP_COMPOSE_EDIT_ENCODING:
1074 strfcpy (buf, ENCODING (idx[menu->current]->content->encoding),
1076 if (mutt_get_field ("Content-Transfer-Encoding: ", buf,
1077 sizeof (buf), 0) == 0 && buf[0])
1079 if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED)
1081 idx[menu->current]->content->encoding = i;
1082 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1086 mutt_error _("Invalid encoding.");
1088 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1091 case OP_COMPOSE_SEND_MESSAGE:
1093 /* Note: We don't invoke send2-hook here, since we want to leave
1094 * users an opportunity to change settings from the ":" prompt.
1097 if(check_attachments(idx, idxlen) != 0)
1099 menu->redraw = REDRAW_FULL;
1105 if (msg->chain && mix_check_message (msg) != 0)
1109 if (!fccSet && *fcc)
1111 if ((i = query_quadoption (OPT_COPY,
1112 _("Save a copy of this message?"))) == -1)
1122 case OP_COMPOSE_EDIT_FILE:
1124 mutt_edit_file (NONULL(Editor), idx[menu->current]->content->filename);
1125 mutt_update_encoding (idx[menu->current]->content);
1126 menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
1127 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1130 case OP_COMPOSE_TOGGLE_UNLINK:
1132 idx[menu->current]->content->unlink = !idx[menu->current]->content->unlink;
1135 /* OPTRESOLVE is otherwise ignored on this menu.
1139 if (option (OPTRESOLVE) && menu->current + 1 < menu->max)
1142 menu->redraw = REDRAW_INDEX;
1143 /* No send2hook since this doesn't change the message. */
1146 case OP_COMPOSE_GET_ATTACHMENT:
1151 for(top = msg->content; top; top = top->next)
1154 mutt_get_tmp_attachment(top);
1156 menu->redraw = REDRAW_FULL;
1158 else if (mutt_get_tmp_attachment(idx[menu->current]->content) == 0)
1159 menu->redraw = REDRAW_CURRENT;
1161 /* No send2hook since this doesn't change the message. */
1164 case OP_COMPOSE_RENAME_FILE:
1166 strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname));
1167 mutt_pretty_mailbox (fname);
1168 if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
1171 if (stat(idx[menu->current]->content->filename, &st) == -1)
1173 mutt_error (_("Can't stat %s: %s"), fname, strerror (errno));
1177 mutt_expand_path (fname, sizeof (fname));
1178 if(mutt_rename_file (idx[menu->current]->content->filename, fname))
1181 mutt_str_replace (&idx[menu->current]->content->filename, fname);
1182 menu->redraw = REDRAW_CURRENT;
1184 if(idx[menu->current]->content->stamp >= st.st_mtime)
1185 mutt_stamp_attachment(idx[menu->current]->content);
1188 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1191 case OP_COMPOSE_NEW_MIME:
1198 CLEARLINE (LINES-1);
1200 if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE)
1203 mutt_expand_path (fname, sizeof (fname));
1205 /* Call to lookup_mime_type () ? maybe later */
1207 if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0
1211 if (!(p = strchr (type, '/')))
1213 mutt_error _("Content-Type is of the form base/sub");
1217 if ((itype = mutt_check_mime_type (type)) == TYPEOTHER)
1219 mutt_error (_("Unknown Content-Type %s"), type);
1222 if (idxlen == idxmax)
1224 safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
1228 idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
1229 /* Touch the file */
1230 if (!(fp = safe_fopen (fname, "w")))
1232 mutt_error (_("Can't create file %s"), fname);
1233 FREE (&idx[idxlen]);
1238 if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL)
1240 mutt_error _("What we have here is a failure to make an attachment");
1243 update_idx (menu, idx, idxlen++);
1245 idx[menu->current]->content->type = itype;
1246 mutt_str_replace (&idx[menu->current]->content->subtype, p);
1247 idx[menu->current]->content->unlink = 1;
1248 menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
1250 if (mutt_compose_attachment (idx[menu->current]->content))
1252 mutt_update_encoding (idx[menu->current]->content);
1253 menu->redraw = REDRAW_FULL;
1256 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1259 case OP_COMPOSE_EDIT_MIME:
1261 if (mutt_edit_attachment (idx[menu->current]->content))
1263 mutt_update_encoding (idx[menu->current]->content);
1264 menu->redraw = REDRAW_FULL;
1266 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1269 case OP_VIEW_ATTACH:
1270 case OP_DISPLAY_HEADERS:
1272 mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen, NULL, 0);
1273 menu->redraw = REDRAW_FULL;
1274 /* no send2hook, since this doesn't modify the message */
1279 mutt_save_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, NULL, menu);
1280 MAYBE_REDRAW (menu->redraw);
1281 /* no send2hook, since this doesn't modify the message */
1286 mutt_print_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content);
1287 /* no send2hook, since this doesn't modify the message */
1293 mutt_pipe_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, op == OP_FILTER);
1294 if (op == OP_FILTER) /* cte might have changed */
1295 menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;
1296 menu->redraw |= REDRAW_STATUS;
1297 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1301 if ((i = query_quadoption (OPT_POSTPONE, _("Postpone this message?"))) == M_NO)
1303 while (idxlen-- > 0)
1305 /* avoid freeing other attachments */
1306 idx[idxlen]->content->next = NULL;
1307 idx[idxlen]->content->parts = NULL;
1308 mutt_free_body (&idx[idxlen]->content);
1309 FREE (&idx[idxlen]->tree);
1310 FREE (&idx[idxlen]);
1322 /* fall through to postpone! */
1324 case OP_COMPOSE_POSTPONE_MESSAGE:
1326 if(check_attachments(idx, idxlen) != 0)
1328 menu->redraw = REDRAW_FULL;
1336 case OP_COMPOSE_ISPELL:
1338 snprintf (buf, sizeof (buf), "%s -x %s", NONULL(Ispell), msg->content->filename);
1339 if (mutt_system (buf) == -1)
1340 mutt_error (_("Error running \"%s\"!"), buf);
1343 mutt_update_encoding (msg->content);
1344 menu->redraw |= REDRAW_STATUS;
1348 case OP_COMPOSE_WRITE_MESSAGE:
1353 strfcpy (fname, NONULL (Context->path), sizeof (fname));
1354 mutt_pretty_mailbox (fname);
1357 msg->content = idx[0]->content;
1358 if (mutt_enter_fname (_("Write message to mailbox"), fname, sizeof (fname),
1359 &menu->redraw, 1) != -1 && fname[0])
1361 mutt_message (_("Writing message to %s ..."), fname);
1362 mutt_expand_path (fname, sizeof (fname));
1364 if (msg->content->next)
1365 msg->content = mutt_make_multipart (msg->content);
1367 if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0)
1368 msg->content = mutt_remove_multipart (msg->content);
1370 mutt_message _("Message written.");
1376 case OP_COMPOSE_PGP_MENU:
1377 if (!(WithCrypto & APPLICATION_PGP))
1379 if ((WithCrypto & APPLICATION_SMIME)
1380 && msg->security & APPLICATION_SMIME)
1382 if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
1385 mutt_clear_error ();
1390 msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
1391 redraw_crypt_lines (msg);
1392 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1396 case OP_FORGET_PASSPHRASE:
1397 crypt_forget_passphrase ();
1401 case OP_COMPOSE_SMIME_MENU:
1402 if (!(WithCrypto & APPLICATION_SMIME))
1405 if ((WithCrypto & APPLICATION_PGP)
1406 && msg->security & APPLICATION_PGP)
1408 if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
1411 mutt_clear_error ();
1416 msg->security = crypt_smime_send_menu(msg, &menu->redraw);
1417 redraw_crypt_lines (msg);
1418 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1423 case OP_COMPOSE_MIX:
1425 mix_make_chain (&msg->chain, &menu->redraw);
1426 mutt_message_hook (NULL, msg, M_SEND2HOOK);
1432 /* Draw formated compose status line */
1433 if (menu->redraw & REDRAW_STATUS)
1435 compose_status_line (buf, sizeof (buf), menu, NONULL(ComposeFormat));
1436 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
1437 SETCOLOR (MT_COLOR_STATUS);
1438 printw ("%-*.*s", COLS, COLS, buf);
1439 SETCOLOR (MT_COLOR_NORMAL);
1440 menu->redraw &= ~REDRAW_STATUS;
1444 mutt_menuDestroy (&menu);
1448 msg->content = idx[0]->content;
1449 for (i = 0; i < idxlen; i++)
1451 idx[i]->content->aptr = NULL;
1456 msg->content = NULL;