-#ifdef USE_NNTP
- if (news)
- menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeNewsHelp);
- else
-#endif
- menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeHelp);
-
- while (loop)
- {
-#ifdef USE_NNTP
- unset_option (OPTNEWS); /* for any case */
-#endif
- switch (op = mutt_menuLoop (menu))
- {
- case OP_REDRAW:
- draw_envelope (msg, fcc);
- menu->offset = HDR_ATTACH;
- menu->pagelen = LINES - HDR_ATTACH - 2;
- break;
- case OP_COMPOSE_EDIT_FROM:
- menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
- break;
- case OP_COMPOSE_EDIT_TO:
-#ifdef USE_NNTP
- if (!news)
-#endif
- menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
- break;
- case OP_COMPOSE_EDIT_BCC:
-#ifdef USE_NNTP
- if (!news)
-#endif
- menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
- break;
- case OP_COMPOSE_EDIT_CC:
-#ifdef USE_NNTP
- if (!news)
-#endif
- menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
- break;
-#ifdef USE_NNTP
- case OP_COMPOSE_EDIT_NEWSGROUPS:
- if (news)
- {
- if (msg->env->newsgroups)
- strfcpy (buf, msg->env->newsgroups, sizeof (buf));
- else
- buf[0] = 0;
- if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0 && buf[0])
- {
- FREE (&msg->env->newsgroups);
- mutt_remove_trailing_ws (buf);
- msg->env->newsgroups = safe_strdup (mutt_skip_whitespace (buf));
- move (HDR_TO, HDR_XOFFSET);
- clrtoeol ();
- if (msg->env->newsgroups)
- printw ("%-*.*s", W, W, msg->env->newsgroups);
- }
- }
- break;
-
- case OP_COMPOSE_EDIT_FOLLOWUP_TO:
- if (news)
- {
- buf[0] = 0;
- if (msg->env->followup_to)
- strfcpy (buf, msg->env->followup_to, sizeof (buf));
- if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0 && buf[0])
- {
- FREE (&msg->env->followup_to);
- mutt_remove_trailing_ws (buf);
- msg->env->followup_to = safe_strdup (mutt_skip_whitespace (buf));
- move (HDR_CC, HDR_XOFFSET);
- clrtoeol();
- if (msg->env->followup_to)
- printw ("%-*.*s", W, W, msg->env->followup_to);
- }
- }
- break;
-
- case OP_COMPOSE_EDIT_X_COMMENT_TO:
- if (news && option (OPTXCOMMENTTO))
- {
- buf[0] = 0;
- if (msg->env->x_comment_to)
- strfcpy (buf, msg->env->x_comment_to, sizeof (buf));
- if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0 && buf[0])
- {
- FREE (&msg->env->x_comment_to);
- msg->env->x_comment_to = safe_strdup (buf);
- move (HDR_BCC, HDR_XOFFSET);
- clrtoeol();
- if (msg->env->x_comment_to)
- printw ("%-*.*s", W, W, msg->env->x_comment_to);
- }
- }
- break;
-#endif
- case OP_COMPOSE_EDIT_SUBJECT:
- if (msg->env->subject)
- strfcpy (buf, msg->env->subject, sizeof (buf));
- else
- buf[0] = 0;
- if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
- {
- mutt_str_replace (&msg->env->subject, buf);
- move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
- clrtoeol ();
- if (msg->env->subject)
- mutt_paddstr (W, msg->env->subject);
- }
- break;
- case OP_COMPOSE_EDIT_REPLY_TO:
- menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
- break;
- case OP_COMPOSE_EDIT_FCC:
- strfcpy (buf, fcc, sizeof (buf));
- if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0)
- {
- strfcpy (fcc, buf, _POSIX_PATH_MAX);
- mutt_pretty_mailbox (fcc);
- move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
- mutt_paddstr (W, fcc);
- fccSet = 1;
- }
- MAYBE_REDRAW (menu->redraw);
- break;
- case OP_COMPOSE_EDIT_MESSAGE:
- if (Editor && (mutt_strcmp ("builtin", Editor) != 0) && !option (OPTEDITHDRS))
- {
- mutt_edit_file (Editor, msg->content->filename);
- mutt_update_encoding (msg->content);
- menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
- break;
- }
- /* fall through */
- case OP_COMPOSE_EDIT_HEADERS:
- if (op == OP_COMPOSE_EDIT_HEADERS ||
- (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))
- {
- char *tag = NULL, *err = NULL;
- mutt_env_to_local (msg->env);
- mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
- fcc, fcclen);
- if (mutt_env_to_idna (msg->env, &tag, &err))
- {
- mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
- FREE (&err);
- }
- }
- else
- {
- /* this is grouped with OP_COMPOSE_EDIT_HEADERS because the
- attachment list could change if the user invokes ~v to edit
- the message with headers, in which we need to execute the
- code below to regenerate the index array */
- mutt_builtin_editor (msg->content->filename, msg, cur);
- }
- mutt_update_encoding (msg->content);
-
- /* attachments may have been added */
- if (idxlen && idx[idxlen - 1]->content->next)
- {
- for (i = 0; i < idxlen; i++)
- FREE (&idx[i]);
- idxlen = 0;
- idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
- menu->data = idx;
- menu->max = idxlen;
- }
-
- menu->redraw = REDRAW_FULL;
- break;
-
-
-
- case OP_COMPOSE_ATTACH_KEY:
- if (!(WithCrypto & APPLICATION_PGP))
- break;
- if (idxlen == idxmax)
- {
- safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5));
- menu->data = idx;
- }
-
- idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
- if ((idx[idxlen]->content = crypt_pgp_make_key_attachment(NULL)) != NULL)
- {
- update_idx (menu, idx, idxlen++);
- menu->redraw |= REDRAW_INDEX;
- }
- else
- FREE (&idx[idxlen]);
-
- menu->redraw |= REDRAW_STATUS;
-
- if (option(OPTNEEDREDRAW))
- {
- menu->redraw = REDRAW_FULL;
- unset_option(OPTNEEDREDRAW);
- }
-
- break;
-
-
- case OP_COMPOSE_ATTACH_FILE:
- {
- char *prompt, **files;
- int error, numfiles;
-
- fname[0] = 0;
- prompt = _("Attach file");
- numfiles = 0;
- files = NULL;
-
- if (_mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files, &numfiles) == -1 ||
- *fname == '\0')
- break;
-
- if (idxlen + numfiles >= idxmax)
- {
- safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles));
- menu->data = idx;
- }
-
- error = 0;
- if (numfiles > 1)
- mutt_message _("Attaching selected files...");
- for (i = 0; i < numfiles; i++)
- {
- char *att = files[i];
- idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
- idx[idxlen]->content = mutt_make_file_attach (att);
- if (idx[idxlen]->content != NULL)
- update_idx (menu, idx, idxlen++);
- else
- {
- error = 1;
- mutt_error (_("Unable to attach %s!"), att);
- FREE (&idx[idxlen]);
- }
- }
-
- FREE (&files);
- if (!error) mutt_clear_error ();
-
- menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
- }
- break;
-
- case OP_COMPOSE_ATTACH_MESSAGE:
-#ifdef USE_NNTP
- case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
-#endif
- {
- char *prompt;
- HEADER *h;
-
- fname[0] = 0;
- prompt = _("Open mailbox to attach message from");
-
-#ifdef USE_NNTP
- unset_option (OPTNEWS);
- if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE)
- {
- if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
- break;
-
- prompt = _("Open newsgroup to attach message from");
- set_option (OPTNEWS);
- }
-#endif
-
- if (Context)
-#ifdef USE_NNTP
- if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
-#endif
- {
- strfcpy (fname, NONULL (Context->path), sizeof (fname));
- mutt_pretty_mailbox (fname);
- }
-
- if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1) == -1 || !fname[0])
- break;
-
-#ifdef USE_NNTP
- if (option (OPTNEWS))
- nntp_expand_path (fname, sizeof (fname), &CurrentNewsSrv->conn->account);
- else
-#endif
- mutt_expand_path (fname, sizeof (fname));
-#ifdef USE_IMAP
- if (!mx_is_imap (fname))
-#endif
-#ifdef USE_POP
- if (!mx_is_pop (fname))
-#endif
-#ifdef USE_NNTP
- if (!mx_is_nntp (fname) && !option (OPTNEWS))
-#endif
- /* check to make sure the file exists and is readable */
- if (access (fname, R_OK) == -1)
- {
- mutt_perror (fname);
- break;
- }
-
- menu->redraw = REDRAW_FULL;
-
- ctx = mx_open_mailbox (fname, M_READONLY, NULL);
- if (ctx == NULL)
- {
- mutt_perror (fname);
- break;
- }
-
- if (!ctx->msgcount)
- {
- mx_close_mailbox (ctx, NULL);
- FREE (&ctx);
- mutt_error _("No messages in that folder.");
- break;
- }
-
- this = Context; /* remember current folder and sort methods*/
- oldSort = Sort; oldSortAux = SortAux;
-
- Context = ctx;
- set_option(OPTATTACHMSG);
- mutt_message _("Tag the messages you want to attach!");
- close = mutt_index_menu ();
- unset_option(OPTATTACHMSG);
-
- if (!Context)
- {
- /* go back to the folder we started from */
- Context = this;
- /* Restore old $sort and $sort_aux */
- Sort = oldSort;
- SortAux = oldSortAux;
- menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
- break;
- }
-
- if (idxlen + Context->tagged >= idxmax)
- {
- safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + Context->tagged));
- menu->data = idx;
- }
-
- for (i = 0; i < Context->msgcount; i++)
- {
- h = Context->hdrs[i];
- if (h->tagged)
- {
- idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
- idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
- if (idx[idxlen]->content != NULL)
- update_idx (menu, idx, idxlen++);
- else
- {
- mutt_error _("Unable to attach!");
- FREE (&idx[idxlen]);
- }
- }
- }
- menu->redraw |= REDRAW_FULL;
-
- if (close == OP_QUIT)
- mx_close_mailbox (Context, NULL);
- else
- mx_fastclose_mailbox (Context);
- FREE (&Context);
-
- /* go back to the folder we started from */
- Context = this;
- /* Restore old $sort and $sort_aux */
- Sort = oldSort;
- SortAux = oldSortAux;
- }
- break;
-
- case OP_DELETE:
- CHECK_COUNT;
- if (delete_attachment (menu, &idxlen, menu->current) == -1)
- break;
- mutt_update_tree (idx, idxlen);
- if (idxlen)
- {
- if (menu->current > idxlen - 1)
- menu->current = idxlen - 1;
- }
- else
- menu->current = 0;
-
- if (menu->current == 0)
- msg->content = idx[0]->content;
-
- menu->redraw |= REDRAW_STATUS;
- break;
+
+ while (loop) {
+ switch (op = mutt_menuLoop (menu)) {
+ case OP_REDRAW:
+ draw_envelope (msg, fcc);
+ menu->offset = HDR_ATTACH;
+ menu->pagelen = LINES - HDR_ATTACH - 2;
+ break;
+ case OP_COMPOSE_EDIT_FROM:
+ menu->redraw = edit_address_list (HDR_FROM, &msg->env->from);
+ mutt_message_hook (NULL, msg, M_SEND2HOOK);
+ break;
+ case OP_COMPOSE_EDIT_TO:
+ menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
+ mutt_message_hook (NULL, msg, M_SEND2HOOK);
+ break;
+ case OP_COMPOSE_EDIT_BCC:
+ menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
+ mutt_message_hook (NULL, msg, M_SEND2HOOK);
+ break;
+ case OP_COMPOSE_EDIT_CC:
+ menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
+ mutt_message_hook (NULL, msg, M_SEND2HOOK);
+ break;
+ case OP_COMPOSE_EDIT_SUBJECT:
+ if (msg->env->subject)
+ m_strcpy(buf, sizeof(buf), msg->env->subject);
+ else
+ buf[0] = 0;
+ if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) {
+ m_strreplace(&msg->env->subject, buf);
+ wmove (main_w, HDR_SUBJECT, HDR_XOFFSET);
+ wclrtoeol (main_w);
+ if (msg->env->subject)
+ mutt_paddstr (main_w, W, msg->env->subject);
+ }
+ mutt_message_hook (NULL, msg, M_SEND2HOOK);
+ break;
+ case OP_COMPOSE_EDIT_REPLY_TO:
+ menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to);
+ mutt_message_hook (NULL, msg, M_SEND2HOOK);
+ break;
+ case OP_COMPOSE_EDIT_FCC:
+ m_strcpy(buf, sizeof(buf), fcc);
+ if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) {
+ m_strcpy(fcc, _POSIX_PATH_MAX, buf);
+ mutt_pretty_mailbox (fcc);
+ wmove (main_w, HDR_FCC, HDR_XOFFSET);
+ mutt_paddstr (main_w, W, fcc);
+ fccSet = 1;
+ }
+ MAYBE_REDRAW (menu->redraw);
+ mutt_message_hook (NULL, msg, M_SEND2HOOK);
+ break;
+ case OP_COMPOSE_EDIT_MESSAGE:
+ if (!option (OPTEDITHDRS)) {
+ mutt_edit_file(msg->content->filename);
+ mutt_update_encoding (msg->content);
+ menu->redraw = REDRAW_CURRENT | REDRAW_STATUS;
+ mutt_message_hook (NULL, msg, M_SEND2HOOK);
+ break;
+ }
+ /* fall through */
+ case OP_COMPOSE_EDIT_HEADERS:
+ if ((op == OP_COMPOSE_EDIT_HEADERS ||
+ (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) {
+ const char *tag = NULL;
+ char *err = NULL;
+
+ mutt_env_to_local (msg->env);
+ mutt_edit_headers(msg->content->filename, msg, fcc, fcclen);
+ if (mutt_env_to_idna (msg->env, &tag, &err)) {
+ mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
+ p_delete(&err);
+ }
+ }
+ mutt_update_encoding (msg->content);
+
+ /* attachments may have been added */
+ if (idxlen && idx[idxlen - 1]->content->next) {
+ for (i = 0; i < idxlen; i++)
+ p_delete(&idx[i]);
+ idxlen = 0;
+ idx =
+ mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
+ 1);
+ menu->data = idx;
+ menu->max = idxlen;
+ }
+
+ menu->redraw = REDRAW_FULL;
+ mutt_message_hook (NULL, msg, M_SEND2HOOK);
+ break;
+
+ case OP_COMPOSE_ATTACH_FILE:
+ {
+ const char *prompt;
+ char **files;
+ int error, numfiles;
+
+ fname[0] = 0;
+ prompt = _("Attach file");
+ numfiles = 0;
+ files = NULL;
+
+ if (_mutt_enter_fname
+ (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files,
+ &numfiles) == -1 || *fname == '\0')
+ break;
+
+ if (idxlen + numfiles >= idxmax) {
+ p_realloc(&idx, idxmax += 5 + numfiles);
+ menu->data = idx;
+ }
+
+ error = 0;
+ if (numfiles > 1)
+ mutt_message _("Attaching selected files...");
+
+ for (i = 0; i < numfiles; i++) {
+ char *att = files[i];
+
+ idx[idxlen] = p_new(ATTACHPTR, 1);
+ idx[idxlen]->unowned = 1;
+ idx[idxlen]->content = mutt_make_file_attach (att);
+ if (idx[idxlen]->content != NULL)
+ update_idx (menu, idx, idxlen++);
+ else {
+ error = 1;
+ mutt_error (_("Unable to attach %s!"), att);
+ p_delete(&idx[idxlen]);
+ }
+ }
+
+ p_delete(&files);
+ if (!error)
+ mutt_clear_error ();
+
+ menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
+ }
+ mutt_message_hook (NULL, msg, M_SEND2HOOK);
+ break;
+
+ case OP_COMPOSE_ATTACH_MESSAGE:
+ {
+ const char *prompt;
+ HEADER *h;
+
+ fname[0] = 0;
+ prompt = _("Open mailbox to attach message from");
+
+
+ if (Context)
+ {
+ m_strcpy(fname, sizeof(fname), NONULL(Context->path));
+ mutt_pretty_mailbox (fname);
+ }
+
+ if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1)
+ == -1 || !fname[0])
+ break;
+
+ mutt_expand_path (fname, sizeof (fname));
+ if (mx_get_magic (fname) != M_IMAP && mx_get_magic (fname) != M_POP) {
+ /* check to make sure the file exists and is readable */
+ if (access (fname, R_OK) == -1) {
+ mutt_perror (fname);
+ break;
+ }
+ }
+
+ menu->redraw = REDRAW_FULL;
+
+ ctx = mx_open_mailbox (fname, M_READONLY, NULL);
+ if (ctx == NULL) {
+ mutt_perror (fname);
+ break;
+ }
+
+ if (!ctx->msgcount) {
+ mx_close_mailbox (ctx, NULL);
+ p_delete(&ctx);
+ mutt_error _("No messages in that folder.");
+ break;
+ }
+
+ this = Context; /* remember current folder and sort methods */
+ oldSort = Sort;
+ oldSortAux = SortAux;
+
+ Context = ctx;
+ set_option (OPTATTACHMSG);
+ mutt_message _("Tag the messages you want to attach!");
+
+ closed = mutt_index_menu ();
+ unset_option (OPTATTACHMSG);
+
+ if (!Context) {
+ /* go back to the folder we started from */
+ Context = this;
+ /* Restore old $sort and $sort_aux */
+ Sort = oldSort;
+ SortAux = oldSortAux;
+ menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
+ break;
+ }
+
+ if (idxlen + Context->tagged >= idxmax) {
+ p_realloc(&idx, idxmax += 5 + Context->tagged);
+ menu->data = idx;
+ }
+
+ for (i = 0; i < Context->msgcount; i++) {
+ h = Context->hdrs[i];
+ if (h->tagged) {
+ idx[idxlen] = p_new(ATTACHPTR, 1);
+ idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
+ if (idx[idxlen]->content != NULL)
+ update_idx (menu, idx, idxlen++);
+ else {
+ mutt_error _("Unable to attach!");
+ p_delete(&idx[idxlen]);
+ }
+ }
+ }
+ menu->redraw |= REDRAW_FULL;
+
+ if (closed == OP_QUIT)
+ mx_close_mailbox (Context, NULL);
+ else
+ mx_fastclose_mailbox (Context);
+ p_delete(&Context);
+
+ /* go back to the folder we started from */
+ Context = this;
+ /* Restore old $sort and $sort_aux */
+ Sort = oldSort;
+ SortAux = oldSortAux;
+ mutt_message_hook (NULL, msg, M_SEND2HOOK);
+ }
+ break;
+
+ case OP_DELETE:
+ CHECK_COUNT;
+ if (idx[menu->current]->unowned)
+ idx[menu->current]->content->unlink = 0;
+ if (delete_attachment (menu, &idxlen, menu->current) == -1)
+ break;
+ mutt_update_tree (idx, idxlen);
+ if (idxlen) {
+ if (menu->current > idxlen - 1)
+ menu->current = idxlen - 1;
+ }
+ else
+ menu->current = 0;
+
+ if (menu->current == 0)
+ msg->content = idx[0]->content;
+
+ menu->redraw |= REDRAW_STATUS;
+ mutt_message_hook (NULL, msg, M_SEND2HOOK);
+ break;