2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
5 * Parts were written/modified by:
6 * Nico Golde <nico@ngolde.de>
8 * This file is part of mutt-ng, see http://www.muttng.org/.
9 * It's licensed under the GNU General Public License,
10 * please see the file GPL in the top level source directory.
18 #include "mutt_curses.h"
20 #include "mutt_menu.h"
23 #include "recvattach.h"
35 #include "imap_private.h"
38 #include "mutt_crypt.h"
47 #include "lib/debug.h"
57 static const char *No_mailbox_is_open = N_("No mailbox is open.");
58 static const char *There_are_no_messages = N_("There are no messages.");
59 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
60 static const char *Function_not_permitted_in_attach_message_mode =
61 N_("Function not permitted in attach-message mode.");
62 static const char *No_visible = N_("No visible messages.");
64 #define CHECK_MSGCOUNT if (!Context) \
67 mutt_error(_(No_mailbox_is_open)); \
70 else if (!Context->msgcount) \
73 mutt_error(_(There_are_no_messages)); \
77 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
80 mutt_error(_(No_visible)); \
85 #define CHECK_READONLY if (Context->readonly) \
88 mutt_error(_(Mailbox_is_read_only)); \
92 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
95 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
99 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
100 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
101 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
103 extern const char *ReleaseDate;
104 extern size_t UngetCount;
106 void index_make_entry (char *s, size_t l, MUTTMENU * menu, int num)
109 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
110 int edgemsgno, reverse = Sort & SORT_REVERSE;
111 HEADER *h = Context->hdrs[Context->v2r[num]];
114 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
115 flag |= M_FORMAT_TREE; /* display the thread tree */
116 if (h->display_subject)
117 flag |= M_FORMAT_FORCESUBJ;
120 if (menu->top + menu->pagelen > menu->max)
121 edgemsgno = Context->v2r[menu->max - 1];
123 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
126 edgemsgno = Context->v2r[menu->top];
128 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
132 /* if no ancestor is visible on current screen, provisionally force
134 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
136 flag |= M_FORMAT_FORCESUBJ;
139 else if (tmp->message->virtual >= 0)
142 if (flag & M_FORMAT_FORCESUBJ) {
143 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
147 /* ...but if a previous sibling is available, don't force it */
148 if (reverse ? tmp->message->msgno >
149 edgemsgno : tmp->message->msgno < edgemsgno)
151 else if (tmp->message->virtual >= 0) {
152 flag &= ~M_FORMAT_FORCESUBJ;
160 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
163 int index_color (int index_no)
165 HEADER *h = Context->hdrs[Context->v2r[index_no]];
170 mutt_set_header_color (Context, h);
174 static int ci_next_undeleted (int msgno)
178 for (i = msgno + 1; i < Context->vcount; i++)
179 if (!Context->hdrs[Context->v2r[i]]->deleted)
184 static int ci_previous_undeleted (int msgno)
188 for (i = msgno - 1; i >= 0; i--)
189 if (!Context->hdrs[Context->v2r[i]]->deleted)
194 /* Return the index of the first new message, or failing that, the first
197 static int ci_first_message (void)
201 if (Context && Context->msgcount) {
202 for (i = 0; i < Context->vcount; i++) {
203 if (!Context->hdrs[Context->v2r[i]]->read &&
204 !Context->hdrs[Context->v2r[i]]->deleted) {
205 if (!Context->hdrs[Context->v2r[i]]->old)
214 /* If Sort is reverse and not threaded, the latest message is first.
215 * If Sort is threaded, the latest message is first iff exactly one
216 * of Sort and SortAux are reverse.
218 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
219 ((Sort & SORT_MASK) == SORT_THREADS &&
220 ((Sort ^ SortAux) & SORT_REVERSE)))
223 return (Context->vcount ? Context->vcount - 1 : 0);
228 /* This should be in mx.c, but it only gets used here. */
229 static int mx_toggle_write (CONTEXT * ctx)
235 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
240 if (ctx->dontwrite) {
242 mutt_message (_("Changes to folder will be written on folder exit."));
246 mutt_message (_("Changes to folder will not be written."));
252 static void update_index (MUTTMENU * menu, CONTEXT * ctx, int check,
253 int oldcount, int index_hint)
255 /* store pointers to the newly added messages */
256 HEADER **save_new = NULL;
259 /* take note of the current message */
261 if (menu->current < Context->vcount)
262 menu->oldcurrent = index_hint;
264 oldcount = 0; /* invalid message number! */
267 /* We are in a limited view. Check if the new message(s) satisfy
268 * the limit criteria. If they do, set their virtual msgno so that
269 * they will be visible in the limited view */
270 if (Context->pattern) {
271 #define THIS_BODY Context->hdrs[j]->content
272 if (oldcount || check == M_REOPENED) {
273 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount;
275 if (mutt_pattern_exec
276 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
278 Context->hdrs[j]->virtual = Context->vcount;
279 Context->v2r[Context->vcount] = j;
280 Context->hdrs[j]->limited = 1;
283 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
290 /* save the list of new messages */
291 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
293 (HEADER **) mem_malloc (sizeof (HEADER *) *
294 (Context->msgcount - oldcount));
295 for (j = oldcount; j < Context->msgcount; j++)
296 save_new[j - oldcount] = Context->hdrs[j];
299 /* if the mailbox was reopened, need to rethread from scratch */
300 mutt_sort_headers (Context, (check == M_REOPENED));
302 /* uncollapse threads with new mail */
303 if ((Sort & SORT_MASK) == SORT_THREADS) {
304 if (check == M_REOPENED) {
307 Context->collapsed = 0;
309 for (h = Context->tree; h; h = h->next) {
310 for (j = h; !j->message; j = j->child);
311 mutt_uncollapse_thread (Context, j->message);
313 mutt_set_virtual (Context);
316 for (j = 0; j < Context->msgcount - oldcount; j++) {
319 for (k = 0; k < Context->msgcount; k++) {
320 HEADER *h = Context->hdrs[k];
322 if (h == save_new[j] && (!Context->pattern || h->limited))
323 mutt_uncollapse_thread (Context, h);
326 mem_free (&save_new);
327 mutt_set_virtual (Context);
333 /* restore the current message to the message it was pointing to */
334 for (j = 0; j < Context->vcount; j++) {
335 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
342 if (menu->current < 0)
343 menu->current = ci_first_message ();
346 static void resort_index (MUTTMENU * menu)
349 HEADER *current = CURHDR;
352 mutt_sort_headers (Context, 0);
353 /* Restore the current message */
355 for (i = 0; i < Context->vcount; i++) {
356 if (Context->hdrs[Context->v2r[i]] == current) {
362 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
363 menu->current = mutt_parent_message (Context, current);
365 if (menu->current < 0)
366 menu->current = ci_first_message ();
368 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
371 struct mapping_t IndexHelp[] = {
372 {N_("Quit"), OP_QUIT},
373 {N_("Del"), OP_DELETE},
374 {N_("Undel"), OP_UNDELETE},
375 {N_("Save"), OP_SAVE},
376 {N_("Mail"), OP_MAIL},
377 {N_("Reply"), OP_REPLY},
378 {N_("Group"), OP_GROUP_REPLY},
379 {N_("Help"), OP_HELP},
384 struct mapping_t IndexNewsHelp[] = {
385 {N_("Quit"), OP_QUIT},
386 {N_("Del"), OP_DELETE},
387 {N_("Undel"), OP_UNDELETE},
388 {N_("Save"), OP_SAVE},
389 {N_("Post"), OP_POST},
390 {N_("Followup"), OP_FOLLOWUP},
391 {N_("Catchup"), OP_CATCHUP},
392 {N_("Help"), OP_HELP},
397 /* This function handles the message index window as well as commands returned
398 * from the pager (MENU_PAGER).
400 int mutt_index_menu (void)
402 char buf[LONG_STRING], helpstr[SHORT_STRING];
405 int done = 0; /* controls when to exit the "event" loop */
407 int tag = 0; /* has the tag-prefix command been pressed? */
412 char *cp; /* temporary variable. */
413 int index_hint; /* used to restore cursor position */
414 int do_buffy_notify = 1;
415 int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
416 int attach_msg = option (OPTATTACHMSG);
418 menu = mutt_new_menu ();
419 menu->menu = MENU_MAIN;
421 menu->pagelen = LINES - 3;
422 menu->make_entry = index_make_entry;
423 menu->color = index_color;
424 menu->current = ci_first_message ();
425 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
428 && (Context->magic ==
429 M_NNTP)) ? IndexNewsHelp :
434 buffy_check (1); /* force the buffy check after we enter the folder */
435 /* record folder we open to place sidebar indicator properly */
436 if (Context && Context->path)
437 sidebar_set_current (Context->path);
441 tag = 0; /* clear the tag-prefix */
443 menu->max = Context ? Context->vcount : 0;
444 oldcount = Context ? Context->msgcount : 0;
446 /* check if we need to resort the index because just about
447 * any 'op' below could do mutt_enter_command(), either here or
448 * from any new menu launched, and change $sort/$sort_aux
450 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
453 if (option (OPTREDRAWTREE) && Context && Context->msgcount
454 && (Sort & SORT_MASK) == SORT_THREADS) {
455 mutt_draw_tree (Context);
456 menu->redraw |= REDRAW_STATUS;
457 unset_option (OPTREDRAWTREE);
460 if (Context && !attach_msg) {
463 /* check for new mail in the mailbox. If nonzero, then something has
464 * changed about the file (either we got new mail or the file was
465 * modified underneath us.)
469 imap_allow_reopen (Context);
472 index_hint = (Context->vcount && menu->current >= 0
473 && menu->current < Context->vcount) ? CURHDR->index : 0;
475 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
476 if (!Context->path) {
477 /* fatal error occurred */
479 menu->redraw = REDRAW_FULL;
481 set_option (OPTSEARCHINVALID);
483 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
484 update_index (menu, Context, check, oldcount, index_hint);
486 /* notify the user of new mail */
487 if (check == M_REOPENED)
489 ("Mailbox was externally modified. Flags may be wrong."));
490 else if (check == M_NEW_MAIL) {
491 /* on new mail: redraw sidebar */
492 sidebar_draw (CurrentMenu);
493 mutt_message (_("New mail in this mailbox."));
495 if (option (OPTBEEPNEW))
498 else if (check == M_FLAGS)
499 mutt_message (_("Mailbox was externally modified."));
501 /* avoid the message being overwritten by buffy */
504 menu->redraw = REDRAW_FULL;
505 menu->max = Context->vcount;
507 set_option (OPTSEARCHINVALID);
513 imap_disallow_reopen (Context);
517 /* check for new mail in the incoming folders */
519 if ((newcount = buffy_check (0)) != oldcount) {
520 menu->redraw |= REDRAW_STATUS;
521 menu->redraw |= REDRAW_SIDEBAR;
523 if (do_buffy_notify) {
524 if (buffy_notify () && option (OPTBEEPNEW))
533 if (menu->redraw & REDRAW_SIDEBAR)
534 sidebar_draw (menu->menu);
535 if (menu->redraw & REDRAW_FULL) {
536 menu_redraw_full (menu);
537 sidebar_draw (menu->menu);
541 if (menu->menu == MENU_MAIN) {
542 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
543 menu_check_recenter (menu);
545 if (menu->redraw & REDRAW_INDEX) {
546 menu_redraw_index (menu);
547 menu->redraw |= REDRAW_STATUS;
549 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
550 menu_redraw_motion (menu);
551 else if (menu->redraw & REDRAW_CURRENT)
552 menu_redraw_current (menu);
555 if (menu->redraw & REDRAW_STATUS) {
557 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
559 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
560 SETCOLOR (MT_COLOR_STATUS);
561 BKGDSET (MT_COLOR_STATUS);
562 mutt_paddstr (COLS, buf);
563 SETCOLOR (MT_COLOR_NORMAL);
564 BKGDSET (MT_COLOR_NORMAL);
565 sidebar_set_buffystats (Context);
566 menu->redraw &= ~REDRAW_STATUS;
567 if (option (OPTXTERMSETTITLES)) {
568 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
569 mutt_xterm_set_title (buf);
570 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
571 mutt_xterm_set_icon (buf);
576 if (menu->current < menu->max)
577 menu->oldcurrent = menu->current;
579 menu->oldcurrent = -1;
581 if (option (OPTARROWCURSOR))
582 move (menu->current - menu->top + menu->offset, 2);
583 else if (option (OPTBRAILLEFRIENDLY))
584 move (menu->current - menu->top + menu->offset, 0);
586 move (menu->current - menu->top + menu->offset, COLS - 1);
589 op = km_dokey (MENU_MAIN);
591 debug_print (4, ("Got op %d\n", op));
593 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
596 mutt_resize_screen ();
597 menu->redraw = REDRAW_FULL;
598 menu->menu = MENU_MAIN;
600 menu->top = 0; /* so we scroll the right amount */
602 * force a real complete redraw. clrtobot() doesn't seem to be able
603 * to handle every case without this.
605 clearok (stdscr, TRUE);
611 continue; /* either user abort or timeout */
615 /* special handling for the tag-prefix function */
616 if (op == OP_TAG_PREFIX) {
618 mutt_error (_("No mailbox is open."));
623 if (!Context->tagged) {
624 mutt_error (_("No tagged messages."));
630 /* give visual indication that the next command is a tag- command */
631 mvaddstr (LINES - 1, 0, "tag-");
634 /* get the real command */
635 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
636 /* abort tag sequence */
637 CLEARLINE (LINES - 1);
641 else if (option (OPTAUTOTAG) && Context && Context->tagged)
644 if (op == OP_TAG_PREFIX_COND) {
646 mutt_error (_("No mailbox is open."));
651 if (!Context->tagged) {
654 while (UngetCount > 0) {
656 if (tmp.op == OP_END_COND)
659 mutt_message (_("Nothing to do."));
665 /* give visual indication that the next command is a tag- command */
666 mvaddstr (LINES - 1, 0, "tag-");
669 /* get the real command */
670 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
671 /* abort tag sequence */
672 CLEARLINE (LINES - 1);
680 if (menu->current < menu->max)
681 menu->oldcurrent = menu->current;
683 menu->oldcurrent = -1;
685 mutt_curs_set (1); /* fallback from the pager */
689 unset_option (OPTNEWS); /* for any case */
694 /* ----------------------------------------------------------------------
699 menu_bottom_page (menu);
702 menu_first_entry (menu);
705 menu_middle_page (menu);
711 menu_half_down (menu);
714 menu_next_line (menu);
717 menu_prev_line (menu);
720 menu_next_page (menu);
723 menu_prev_page (menu);
726 menu_last_entry (menu);
729 menu_top_page (menu);
732 menu_current_top (menu);
734 case OP_CURRENT_MIDDLE:
735 menu_current_middle (menu);
737 case OP_CURRENT_BOTTOM:
738 menu_current_bottom (menu);
745 if (Context->magic == M_NNTP) {
748 if (op == OP_GET_MESSAGE) {
750 if (mutt_get_field (_("Enter Message-Id: "), buf, sizeof (buf), 0)
755 LIST *ref = CURHDR->env->references;
758 mutt_error (_("Article has no parent reference!"));
762 strfcpy (buf, ref->data, sizeof (buf));
764 if (!Context->id_hash)
765 Context->id_hash = mutt_make_id_hash (Context);
766 if ((h = hash_find (Context->id_hash, buf))) {
767 if (h->virtual != -1) {
768 menu->current = h->virtual;
769 menu->redraw = REDRAW_MOTION_RESYNCH;
771 else if (h->collapsed) {
772 mutt_uncollapse_thread (Context, h);
773 mutt_set_virtual (Context);
774 menu->current = h->virtual;
775 menu->redraw = REDRAW_MOTION_RESYNCH;
778 mutt_error (_("Message not visible in limited view."));
781 if (nntp_check_msgid (Context, buf) == 0) {
782 h = Context->hdrs[Context->msgcount - 1];
783 mutt_sort_headers (Context, 0);
784 menu->current = h->virtual;
785 menu->redraw = REDRAW_FULL;
788 mutt_error (_("Article %s not found on server"), buf);
793 case OP_GET_CHILDREN:
794 case OP_RECONSTRUCT_THREAD:
796 if (Context->magic == M_NNTP) {
798 int old = CURHDR->index, i;
800 if (!CURHDR->env->message_id) {
801 mutt_error (_("No Message-Id. Unable to perform operation"));
806 if (!Context->id_hash)
807 Context->id_hash = mutt_make_id_hash (Context);
808 strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
810 if (op == OP_RECONSTRUCT_THREAD) {
811 LIST *ref = CURHDR->env->references;
814 nntp_check_msgid (Context, ref->data);
815 /* the last msgid in References is the root message */
817 strfcpy (buf, ref->data, sizeof (buf));
821 mutt_message (_("Check for children of message..."));
823 if (nntp_check_children (Context, buf) == 0) {
824 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
825 h = hash_find (Context->id_hash, buf);
826 /* if the root message was retrieved, move to it */
828 menu->current = h->virtual;
829 else /* try to restore old position */
830 for (i = 0; i < Context->msgcount; i++)
831 if (Context->hdrs[i]->index == old) {
832 menu->current = Context->hdrs[i]->virtual;
833 /* As an added courtesy, recenter the menu
834 * with the current entry at the middle of the screen */
835 menu_check_recenter (menu);
836 menu_current_middle (menu);
839 menu->redraw = REDRAW_FULL;
849 if (isdigit (LastKey))
850 mutt_ungetch (LastKey, 0);
852 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
856 if (!isdigit ((unsigned char) buf[0])) {
857 mutt_error (_("Argument must be a message number."));
863 if (i > 0 && i <= Context->msgcount) {
864 for (j = i - 1; j < Context->msgcount; j++) {
865 if (Context->hdrs[j]->virtual != -1)
868 if (j >= Context->msgcount) {
869 for (j = i - 2; j >= 0; j--) {
870 if (Context->hdrs[j]->virtual != -1)
876 menu->current = Context->hdrs[j]->virtual;
877 if (menu->menu == MENU_PAGER) {
878 op = OP_DISPLAY_MESSAGE;
882 menu->redraw = REDRAW_MOTION;
885 mutt_error (_("That message is not visible."));
888 mutt_error (_("Invalid message number."));
892 /* --------------------------------------------------------------------
893 * `index' specific commands
896 case OP_MAIN_DELETE_PATTERN:
902 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
905 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
906 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
910 case OP_MAIN_FETCH_MAIL:
914 menu->redraw = REDRAW_FULL;
920 mutt_help (MENU_MAIN);
921 menu->redraw = REDRAW_FULL;
924 case OP_MAIN_SHOW_LIMIT:
926 if (!Context->pattern)
927 mutt_message (_("No limit pattern is in effect."));
932 /* i18n: ask for a limit to apply */
933 snprintf (buf, sizeof (buf), _("Limit: %s"), Context->pattern);
934 mutt_message ("%s", buf);
942 menu->oldcurrent = (Context->vcount && menu->current >= 0
944 Context->vcount) ? CURHDR->index : -1;
945 if (op == OP_TOGGLE_READ) {
946 char buf[LONG_STRING];
948 if (!Context->pattern
949 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
950 snprintf (buf, sizeof (buf), "!~R!~D~s%s",
951 Context->pattern ? Context->pattern : ".*");
952 set_option (OPTHIDEREAD);
955 strfcpy (buf, Context->pattern + 8, sizeof (buf));
956 if (!*buf || strncmp (buf, ".*", 2) == 0)
957 snprintf (buf, sizeof (buf), "~A");
958 unset_option (OPTHIDEREAD);
960 mem_free (&Context->pattern);
961 Context->pattern = str_dup (buf);
963 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
964 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
966 if (menu->oldcurrent >= 0) {
967 /* try to find what used to be the current message */
969 for (i = 0; i < Context->vcount; i++)
970 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
974 if (menu->current < 0)
979 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
980 if ((Sort & SORT_MASK) == SORT_THREADS)
981 mutt_draw_tree (Context);
982 menu->redraw = REDRAW_FULL;
994 if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == M_YES) {
997 oldcount = Context ? Context->msgcount : 0;
1000 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1003 if (check == M_NEW_MAIL || check == M_REOPENED)
1004 update_index (menu, Context, check, oldcount, index_hint);
1006 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1007 set_option (OPTSEARCHINVALID);
1014 clearok (stdscr, TRUE);
1015 menu->redraw = REDRAW_FULL;
1019 case OP_SEARCH_REVERSE:
1020 case OP_SEARCH_NEXT:
1021 case OP_SEARCH_OPPOSITE:
1025 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1026 menu->current = menu->oldcurrent;
1028 menu->redraw = REDRAW_MOTION;
1032 case OP_SORT_REVERSE:
1034 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1035 if (Context && Context->msgcount) {
1036 resort_index (menu);
1037 set_option (OPTSEARCHINVALID);
1046 if (tag && !option (OPTAUTOTAG)) {
1047 for (j = 0; j < Context->vcount; j++)
1048 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1049 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1052 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1053 Context->last_tag = CURHDR->tagged ? CURHDR :
1054 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1055 ? NULL : Context->last_tag);
1056 menu->redraw = REDRAW_STATUS;
1057 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1059 menu->redraw |= REDRAW_MOTION_RESYNCH;
1062 menu->redraw |= REDRAW_CURRENT;
1066 case OP_MAIN_TAG_PATTERN:
1070 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1071 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1074 case OP_MAIN_UNDELETE_PATTERN:
1080 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1082 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1084 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1087 case OP_MAIN_UNTAG_PATTERN:
1091 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1092 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1095 /* --------------------------------------------------------------------
1096 * The following operations can be performed inside of the pager.
1100 case OP_MAIN_IMAP_FETCH:
1101 if (Context->magic == M_IMAP)
1102 imap_check_mailbox (Context, &index_hint, 1);
1106 case OP_MAIN_SYNC_FOLDER:
1108 if (Context && !Context->msgcount)
1115 int oldvcount = Context->vcount;
1116 int oldcount = Context->msgcount;
1120 /* calculate the number of messages _above_ the cursor,
1121 * so we can keep the cursor on the current message
1123 for (j = 0; j <= menu->current; j++) {
1124 if (Context->hdrs[Context->v2r[j]]->deleted)
1128 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1129 if (Context->vcount != oldvcount)
1130 menu->current -= dcount;
1131 set_option (OPTSEARCHINVALID);
1133 else if (check == M_NEW_MAIL || check == M_REOPENED)
1134 update_index (menu, Context, check, oldcount, index_hint);
1137 * do a sanity check even if mx_sync_mailbox failed.
1140 if (menu->current < 0 || menu->current >= Context->vcount)
1141 menu->current = ci_first_message ();
1144 /* check for a fatal error, or all messages deleted */
1146 mem_free (&Context);
1148 /* if we were in the pager, redisplay the message */
1149 if (menu->menu == MENU_PAGER) {
1150 op = OP_DISPLAY_MESSAGE;
1154 menu->redraw = REDRAW_FULL;
1157 case OP_SIDEBAR_OPEN:
1158 case OP_MAIN_CHANGE_FOLDER:
1159 case OP_MAIN_CHANGE_FOLDER_READONLY:
1161 case OP_MAIN_CHANGE_GROUP:
1162 case OP_MAIN_CHANGE_GROUP_READONLY:
1164 if (attach_msg || option (OPTREADONLY) ||
1166 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1168 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1174 cp = _("Open mailbox in read-only mode");
1176 cp = _("Open mailbox");
1180 unset_option (OPTNEWS);
1181 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1182 set_option (OPTNEWS);
1183 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1186 cp = _("Open newsgroup in read-only mode");
1188 cp = _("Open newsgroup");
1189 nntp_buffy (buf, sizeof (buf));
1194 if (Context && Context->path)
1195 strncpy (buf, Context->path, sizeof (buf));
1196 if (op != OP_SIDEBAR_OPEN)
1197 buffy_next (buf, sizeof (buf));
1200 if (op == OP_SIDEBAR_OPEN) {
1201 strncpy (buf, NONULL(sidebar_get_current ()), sizeof (buf));
1203 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) ==
1207 CLEARLINE (LINES - 1);
1212 if (option (OPTNEWS)) {
1213 unset_option (OPTNEWS);
1214 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1218 mutt_expand_path (buf, sizeof (buf));
1219 if (mx_get_magic (buf) <= 0) {
1220 mutt_error (_("%s is not a mailbox."), buf);
1223 str_replace (&CurrentFolder, buf);
1228 #ifdef USE_COMPRESSED
1229 if (Context->compressinfo && Context->realpath)
1230 str_replace (&LastFolder, Context->realpath);
1234 str_replace (&LastFolder, Context->path);
1235 oldcount = Context ? Context->msgcount : 0;
1237 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1238 if (check == M_NEW_MAIL || check == M_REOPENED)
1239 update_index (menu, Context, check, oldcount, index_hint);
1241 set_option (OPTSEARCHINVALID);
1242 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1245 mem_free (&Context);
1250 /* Set CurrentMenu to MENU_MAIN before executing any folder
1251 * hooks so that all the index menu functions are available to
1255 CurrentMenu = MENU_MAIN;
1256 mutt_folder_hook (buf);
1258 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1259 menu->current = ci_first_message ();
1263 sidebar_set_current (buf);
1266 /* buffy_check() must be done with mail-reader mode! */
1267 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1269 && (Context->magic ==
1270 M_NNTP)) ? IndexNewsHelp :
1273 mutt_clear_error ();
1274 buffy_check (1); /* force the buffy check after we have changed
1276 menu->redraw = REDRAW_FULL;
1277 set_option (OPTSEARCHINVALID);
1280 case OP_DISPLAY_MESSAGE:
1281 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1286 * toggle the weeding of headers so that a user can press the key
1287 * again while reading the message.
1289 if (op == OP_DISPLAY_HEADERS)
1290 toggle_option (OPTWEED);
1292 unset_option (OPTNEEDRESORT);
1294 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1295 mutt_uncollapse_thread (Context, CURHDR);
1296 mutt_set_virtual (Context);
1297 if (option (OPTUNCOLLAPSEJUMP))
1298 menu->current = mutt_thread_next_unread (Context, CURHDR);
1301 if (option (OPTPGPAUTODEC) &&
1302 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1303 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1305 if ((op = mutt_display_message (CURHDR)) == -1) {
1306 unset_option (OPTNEEDRESORT);
1310 menu->menu = MENU_PAGER;
1311 menu->oldcurrent = menu->current;
1317 if (menu->menu == MENU_MAIN && attach_msg) {
1322 if ((menu->menu == MENU_MAIN)
1323 && (query_quadoption (OPT_QUIT,
1324 _("Exit Mutt-ng without saving?")) == M_YES))
1327 mx_fastclose_mailbox (Context);
1328 mem_free (&Context);
1339 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1340 /* if we were in the pager, redisplay the message */
1341 if (menu->menu == MENU_PAGER) {
1342 op = OP_DISPLAY_MESSAGE;
1346 menu->redraw = REDRAW_CURRENT;
1349 case OP_MAIN_BREAK_THREAD:
1355 if ((Sort & SORT_MASK) != SORT_THREADS)
1356 mutt_error (_("Threading is not enabled."));
1360 HEADER *oldcur = CURHDR;
1362 mutt_break_thread (CURHDR);
1363 mutt_sort_headers (Context, 1);
1364 menu->current = oldcur->virtual;
1367 Context->changed = 1;
1368 mutt_message _("Thread broken");
1370 if (menu->menu == MENU_PAGER) {
1371 op = OP_DISPLAY_MESSAGE;
1375 menu->redraw |= REDRAW_INDEX;
1379 case OP_MAIN_LINK_THREADS:
1385 if ((Sort & SORT_MASK) != SORT_THREADS)
1386 mutt_error (_("Threading is not enabled."));
1388 else if (!CURHDR->env->message_id)
1389 mutt_error (_("No Message-ID: header available to link thread"));
1391 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1392 mutt_error (_("First, please tag a message to be linked here"));
1395 HEADER *oldcur = CURHDR;
1397 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1399 mutt_sort_headers (Context, 1);
1400 menu->current = oldcur->virtual;
1402 Context->changed = 1;
1403 mutt_message _("Threads linked");
1406 mutt_error (_("No thread linked"));
1409 if (menu->menu == MENU_PAGER) {
1410 op = OP_DISPLAY_MESSAGE;
1414 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1417 case OP_MAIN_NEXT_UNDELETED:
1421 if (menu->current >= Context->vcount - 1) {
1422 if (menu->menu == MENU_MAIN)
1423 mutt_error (_("You are on the last message."));
1427 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1428 menu->current = menu->oldcurrent;
1429 if (menu->menu == MENU_MAIN)
1430 mutt_error (_("No undeleted messages."));
1432 else if (menu->menu == MENU_PAGER) {
1433 op = OP_DISPLAY_MESSAGE;
1437 menu->redraw = REDRAW_MOTION;
1444 if (menu->current >= Context->vcount - 1) {
1445 if (menu->menu == MENU_MAIN)
1446 mutt_error (_("You are on the last message."));
1451 if (menu->menu == MENU_PAGER) {
1452 op = OP_DISPLAY_MESSAGE;
1456 menu->redraw = REDRAW_MOTION;
1459 case OP_MAIN_PREV_UNDELETED:
1463 if (menu->current < 1) {
1464 mutt_error (_("You are on the first message."));
1468 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1469 menu->current = menu->oldcurrent;
1470 if (menu->menu == MENU_MAIN)
1471 mutt_error (_("No undeleted messages."));
1473 else if (menu->menu == MENU_PAGER) {
1474 op = OP_DISPLAY_MESSAGE;
1478 menu->redraw = REDRAW_MOTION;
1485 if (menu->current < 1) {
1486 if (menu->menu == MENU_MAIN)
1487 mutt_error (_("You are on the first message."));
1492 if (menu->menu == MENU_PAGER) {
1493 op = OP_DISPLAY_MESSAGE;
1497 menu->redraw = REDRAW_MOTION;
1500 case OP_DECRYPT_COPY:
1501 case OP_DECRYPT_SAVE:
1505 case OP_COPY_MESSAGE:
1507 case OP_DECODE_COPY:
1508 case OP_DECODE_SAVE:
1511 if (mutt_save_message (tag ? NULL : CURHDR,
1512 (op == OP_DECRYPT_SAVE) ||
1513 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1514 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1515 (op == OP_DECRYPT_SAVE)
1516 || (op == OP_DECRYPT_COPY)
1517 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1524 menu->redraw |= REDRAW_INDEX;
1525 else if (option (OPTRESOLVE)) {
1526 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1527 menu->current = menu->oldcurrent;
1528 menu->redraw |= REDRAW_CURRENT;
1531 menu->redraw |= REDRAW_MOTION_RESYNCH;
1534 menu->redraw |= REDRAW_CURRENT;
1538 case OP_MAIN_NEXT_NEW:
1539 case OP_MAIN_NEXT_UNREAD:
1540 case OP_MAIN_PREV_NEW:
1541 case OP_MAIN_PREV_UNREAD:
1542 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1543 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1546 int first_unread = -1;
1554 for (j = 0; j != Context->vcount; j++) {
1555 #define CURHDRi Context->hdrs[Context->v2r[i]]
1556 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1557 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1559 if (i > Context->vcount - 1) {
1560 mutt_message _("Search wrapped to top.");
1568 mutt_message _("Search wrapped to bottom.");
1570 i = Context->vcount - 1;
1574 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1575 if (UNREAD (CURHDRi) && first_unread == -1)
1577 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1580 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1581 if (first_unread == -1)
1583 if ((!CURHDRi->old) && first_new == -1)
1587 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1590 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1591 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1592 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1597 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1598 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1599 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1601 menu->current = first_new;
1602 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1603 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1604 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1605 && first_unread != -1)
1606 menu->current = first_unread;
1608 if (menu->current == -1) {
1609 menu->current = menu->oldcurrent;
1610 mutt_error ("%s%s.",
1611 (op == OP_MAIN_NEXT_NEW
1613 OP_MAIN_PREV_NEW) ? _("No new messages") :
1614 _("No unread messages"),
1615 Context->pattern ? _(" in this limited view") : "");
1617 else if (menu->menu == MENU_PAGER) {
1618 op = OP_DISPLAY_MESSAGE;
1622 menu->redraw = REDRAW_MOTION;
1625 case OP_FLAG_MESSAGE:
1631 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1634 for (j = 0; j < Context->vcount; j++) {
1635 if (Context->hdrs[Context->v2r[j]]->tagged)
1636 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1637 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1640 menu->redraw |= REDRAW_INDEX;
1643 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1644 if (option (OPTRESOLVE)) {
1645 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1646 menu->current = menu->oldcurrent;
1647 menu->redraw = REDRAW_CURRENT;
1650 menu->redraw = REDRAW_MOTION_RESYNCH;
1653 menu->redraw = REDRAW_CURRENT;
1655 menu->redraw |= REDRAW_STATUS;
1664 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1667 for (j = 0; j < Context->vcount; j++) {
1668 if (Context->hdrs[Context->v2r[j]]->tagged) {
1669 if (Context->hdrs[Context->v2r[j]]->read ||
1670 Context->hdrs[Context->v2r[j]]->old)
1671 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1674 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1678 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1681 if (CURHDR->read || CURHDR->old)
1682 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1684 mutt_set_flag (Context, CURHDR, M_READ, 1);
1686 if (option (OPTRESOLVE)) {
1687 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1688 menu->current = menu->oldcurrent;
1689 menu->redraw = REDRAW_CURRENT;
1692 menu->redraw = REDRAW_MOTION_RESYNCH;
1695 menu->redraw = REDRAW_CURRENT;
1696 menu->redraw |= REDRAW_STATUS;
1700 case OP_TOGGLE_WRITE:
1703 if (mx_toggle_write (Context) == 0)
1704 menu->redraw |= REDRAW_STATUS;
1707 case OP_MAIN_NEXT_THREAD:
1708 case OP_MAIN_NEXT_SUBTHREAD:
1709 case OP_MAIN_PREV_THREAD:
1710 case OP_MAIN_PREV_SUBTHREAD:
1715 case OP_MAIN_NEXT_THREAD:
1716 menu->current = mutt_next_thread (CURHDR);
1719 case OP_MAIN_NEXT_SUBTHREAD:
1720 menu->current = mutt_next_subthread (CURHDR);
1723 case OP_MAIN_PREV_THREAD:
1724 menu->current = mutt_previous_thread (CURHDR);
1727 case OP_MAIN_PREV_SUBTHREAD:
1728 menu->current = mutt_previous_subthread (CURHDR);
1732 if (menu->current < 0) {
1733 menu->current = menu->oldcurrent;
1734 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1735 mutt_error (_("No more threads."));
1738 mutt_error (_("You are on the first thread."));
1740 else if (menu->menu == MENU_PAGER) {
1741 op = OP_DISPLAY_MESSAGE;
1745 menu->redraw = REDRAW_MOTION;
1748 case OP_MAIN_PARENT_MESSAGE:
1753 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1754 menu->current = menu->oldcurrent;
1756 else if (menu->menu == MENU_PAGER) {
1757 op = OP_DISPLAY_MESSAGE;
1761 menu->redraw = REDRAW_MOTION;
1764 case OP_MAIN_SET_FLAG:
1765 case OP_MAIN_CLEAR_FLAG:
1771 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1773 menu->redraw = REDRAW_STATUS;
1775 menu->redraw |= REDRAW_INDEX;
1776 else if (option (OPTRESOLVE)) {
1777 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1778 menu->current = menu->oldcurrent;
1779 menu->redraw |= REDRAW_CURRENT;
1782 menu->redraw |= REDRAW_MOTION_RESYNCH;
1785 menu->redraw |= REDRAW_CURRENT;
1789 case OP_MAIN_COLLAPSE_THREAD:
1793 if ((Sort & SORT_MASK) != SORT_THREADS) {
1794 mutt_error (_("Threading is not enabled."));
1799 if (CURHDR->collapsed) {
1800 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1801 mutt_set_virtual (Context);
1802 if (option (OPTUNCOLLAPSEJUMP))
1803 menu->current = mutt_thread_next_unread (Context, CURHDR);
1805 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1806 menu->current = mutt_collapse_thread (Context, CURHDR);
1807 mutt_set_virtual (Context);
1810 mutt_error (_("Thread contains unread messages."));
1815 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1819 case OP_MAIN_COLLAPSE_ALL:
1823 if ((Sort & SORT_MASK) != SORT_THREADS) {
1824 mutt_error (_("Threading is not enabled."));
1831 THREAD *thread, *top;
1834 if (CURHDR->collapsed)
1835 final = mutt_uncollapse_thread (Context, CURHDR);
1836 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1837 final = mutt_collapse_thread (Context, CURHDR);
1839 final = CURHDR->virtual;
1841 base = Context->hdrs[Context->v2r[final]];
1843 top = Context->tree;
1844 Context->collapsed = !Context->collapsed;
1845 while ((thread = top) != NULL) {
1846 while (!thread->message)
1847 thread = thread->child;
1848 h = thread->message;
1850 if (h->collapsed != Context->collapsed) {
1852 mutt_uncollapse_thread (Context, h);
1853 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1854 mutt_collapse_thread (Context, h);
1859 mutt_set_virtual (Context);
1860 for (j = 0; j < Context->vcount; j++) {
1861 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1867 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1871 /* --------------------------------------------------------------------
1872 * These functions are invoked directly from the internal-pager
1875 case OP_BOUNCE_MESSAGE:
1880 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1883 case OP_CREATE_ALIAS:
1885 mutt_create_alias (Context
1886 && Context->vcount ? CURHDR->env : NULL, NULL);
1887 MAYBE_REDRAW (menu->redraw);
1888 menu->redraw |= REDRAW_CURRENT;
1893 mutt_query_menu (NULL, 0);
1894 MAYBE_REDRAW (menu->redraw);
1897 case OP_PURGE_MESSAGE:
1904 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1907 mutt_tag_set_flag (M_DELETE, 1);
1908 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1909 if (option (OPTDELETEUNTAG))
1910 mutt_tag_set_flag (M_TAG, 0);
1911 menu->redraw = REDRAW_INDEX;
1914 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1915 mutt_set_flag (Context, CURHDR, M_PURGED,
1916 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1917 if (option (OPTDELETEUNTAG))
1918 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1919 if (option (OPTRESOLVE)) {
1920 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1921 menu->current = menu->oldcurrent;
1922 menu->redraw = REDRAW_CURRENT;
1924 else if (menu->menu == MENU_PAGER) {
1925 op = OP_DISPLAY_MESSAGE;
1929 menu->redraw |= REDRAW_MOTION_RESYNCH;
1932 menu->redraw = REDRAW_CURRENT;
1934 menu->redraw |= REDRAW_STATUS;
1937 case OP_DELETE_THREAD:
1938 case OP_DELETE_SUBTHREAD:
1944 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1946 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1947 op == OP_DELETE_THREAD ? 0 : 1);
1950 if (option (OPTDELETEUNTAG))
1951 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1952 op == OP_DELETE_THREAD ? 0 : 1);
1953 if (option (OPTRESOLVE))
1954 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1955 menu->current = menu->oldcurrent;
1956 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1962 if (Context && Context->magic == M_NNTP) {
1963 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1964 ((NNTP_DATA *) Context->data)->group))
1965 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1970 case OP_DISPLAY_ADDRESS:
1974 mutt_display_address (CURHDR->env);
1977 case OP_ENTER_COMMAND:
1979 CurrentMenu = MENU_MAIN;
1980 mutt_enter_command ();
1981 mutt_check_rescore (Context);
1982 if (option (OPTFORCEREDRAWINDEX))
1983 menu->redraw = REDRAW_FULL;
1984 unset_option (OPTFORCEREDRAWINDEX);
1985 unset_option (OPTFORCEREDRAWPAGER);
1988 case OP_EDIT_MESSAGE:
1995 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
1997 if (option (OPTPGPAUTODEC)
1998 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1999 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2000 mutt_edit_message (Context, tag ? NULL : CURHDR);
2001 menu->redraw = REDRAW_FULL;
2005 case OP_FORWARD_MESSAGE:
2011 if (option (OPTPGPAUTODEC) &&
2012 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2013 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2014 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2015 menu->redraw = REDRAW_FULL;
2019 case OP_FORGET_PASSPHRASE:
2020 crypt_forget_passphrase ();
2023 case OP_GROUP_REPLY:
2029 if (option (OPTPGPAUTODEC) &&
2030 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2031 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2033 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2034 tag ? NULL : CURHDR);
2035 menu->redraw = REDRAW_FULL;
2044 if (option (OPTPGPAUTODEC) &&
2045 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2046 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2048 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2049 tag ? NULL : CURHDR);
2050 menu->redraw = REDRAW_FULL;
2056 ci_send_message (0, NULL, NULL, Context, NULL);
2057 menu->redraw = REDRAW_FULL;
2061 if (!(WithCrypto & APPLICATION_PGP))
2064 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2065 menu->redraw = REDRAW_FULL;
2069 case OP_EXTRACT_KEYS:
2074 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2075 menu->redraw = REDRAW_FULL;
2079 case OP_CHECK_TRADITIONAL:
2080 if (!(WithCrypto & APPLICATION_PGP))
2084 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2085 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2087 if (menu->menu == MENU_PAGER) {
2088 op = OP_DISPLAY_MESSAGE;
2097 mutt_pipe_message (tag ? NULL : CURHDR);
2098 MAYBE_REDRAW (menu->redraw);
2105 mutt_print_message (tag ? NULL : CURHDR);
2108 case OP_MAIN_READ_THREAD:
2109 case OP_MAIN_READ_SUBTHREAD:
2115 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2117 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2118 op == OP_MAIN_READ_THREAD ? 0 : 1);
2121 if (option (OPTRESOLVE)) {
2122 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2123 mutt_next_thread (CURHDR) :
2124 mutt_next_subthread (CURHDR))) == -1)
2125 menu->current = menu->oldcurrent;
2127 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2131 case OP_RECALL_MESSAGE:
2134 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2135 menu->redraw = REDRAW_FULL;
2145 for (j = 0; j < Context->vcount; j++) {
2146 if (Context->hdrs[Context->v2r[j]]->tagged)
2147 mutt_resend_message (NULL, Context,
2148 Context->hdrs[Context->v2r[j]]);
2152 mutt_resend_message (NULL, Context, CURHDR);
2154 menu->redraw = REDRAW_FULL;
2160 case OP_FORWARD_TO_GROUP:
2163 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2164 Context && Context->msgcount == 0) {
2165 mutt_error (_("There are no messages."));
2168 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2169 str_casecmp (CURHDR->env->followup_to, "poster") ||
2170 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2171 _("Reply by mail as poster prefers?")) !=
2173 if (Context && Context->magic == M_NNTP
2174 && !((NNTP_DATA *) Context->data)->allowed
2175 && query_quadoption (OPT_TOMODERATED,
2177 ("Posting to this group not allowed, may be moderated. Continue?"))
2181 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2184 if (op == OP_FOLLOWUP)
2185 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2186 tag ? NULL : CURHDR);
2188 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2189 tag ? NULL : CURHDR);
2191 menu->redraw = REDRAW_FULL;
2202 if (option (OPTPGPAUTODEC) &&
2203 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2204 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2206 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2207 menu->redraw = REDRAW_FULL;
2210 case OP_SHELL_ESCAPE:
2212 mutt_shell_escape ();
2213 MAYBE_REDRAW (menu->redraw);
2217 case OP_TAG_SUBTHREAD:
2221 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2222 op == OP_TAG_THREAD ? 0 : 1);
2225 if (option (OPTRESOLVE)) {
2226 menu->current = mutt_next_thread (CURHDR);
2228 if (menu->current == -1)
2229 menu->current = menu->oldcurrent;
2231 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2241 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2244 mutt_tag_set_flag (M_DELETE, 0);
2245 mutt_tag_set_flag (M_PURGED, 0);
2246 menu->redraw = REDRAW_INDEX;
2249 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2250 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2251 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2253 menu->redraw = REDRAW_MOTION_RESYNCH;
2256 menu->redraw = REDRAW_CURRENT;
2258 menu->redraw |= REDRAW_STATUS;
2261 case OP_UNDELETE_THREAD:
2262 case OP_UNDELETE_SUBTHREAD:
2268 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2270 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2271 op == OP_UNDELETE_THREAD ? 0 : 1)
2272 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2273 op == OP_UNDELETE_THREAD ? 0 : 1);
2276 if (option (OPTRESOLVE)) {
2277 if (op == OP_UNDELETE_THREAD)
2278 menu->current = mutt_next_thread (CURHDR);
2280 menu->current = mutt_next_subthread (CURHDR);
2282 if (menu->current == -1)
2283 menu->current = menu->oldcurrent;
2285 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2294 if (option (OPTFORCEBUFFYCHECK))
2297 menu->redraw = REDRAW_FULL;
2300 case OP_VIEW_ATTACHMENTS:
2303 mutt_view_attachments (CURHDR);
2304 if (CURHDR->attach_del)
2305 Context->changed = 1;
2306 menu->redraw = REDRAW_FULL;
2316 case OP_SIDEBAR_SCROLL_UP:
2317 case OP_SIDEBAR_SCROLL_DOWN:
2318 case OP_SIDEBAR_NEXT:
2319 case OP_SIDEBAR_PREV:
2320 case OP_SIDEBAR_NEXT_NEW:
2321 case OP_SIDEBAR_PREV_NEW:
2322 sidebar_scroll (op, menu->menu);
2325 if (menu->menu == MENU_MAIN)
2326 km_error_key (MENU_MAIN);
2329 if (menu->menu == MENU_PAGER) {
2330 menu->menu = MENU_MAIN;
2331 menu->redraw = REDRAW_FULL;
2333 set_option (OPTWEED); /* turn header weeding back on. */
2342 /* Close all open IMAP connections */
2347 /* Close all open NNTP connections */
2352 mutt_menuDestroy (&menu);
2356 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2363 for (color = ColorIndexList; color; color = color->next)
2364 if (mutt_pattern_exec
2365 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2366 curhdr->pair = color->pair;
2369 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];